![]() |
Helper Class Reference
1.3
HomeGenie - Automation Programs' Engine API
|
MQTT client helper. Class instance accessor: MqttClient More...
Public Member Functions | |
| MqttClientHelper | Service (string server) |
| Sets the MQTT server to use. More... | |
| MqttClientHelper | Connect (string clientId) |
| Connects to the MQTT server using the default port (1883) and the specified client identifier. More... | |
| MqttClientHelper | Connect (int port, string clientId) |
| Connects to the MQTT server using the specified port and client identifier. More... | |
| MqttClientHelper | Connect (int port, string clientId, Action< bool > callback=null) |
| Connects to the MQTT server using the specified port and client identifier. More... | |
| MqttClientHelper | Connect (int port, string clientId, Action< MqttClientOptionsBuilder > clientOptionsCallback, Action< bool > callback=null) |
| Connects to the MQTT server using the specified port / client identifier and the specified client options. More... | |
| MqttClientHelper | Disconnect () |
| Disconnects from the MQTT server. More... | |
| MqttClientHelper | Subscribe (string topic, Action< string, byte[]> callback) |
| Subscribe the specified topic. More... | |
| MqttClientHelper | Unsubscribe (string topic) |
| Unsubscribe the specified topic. More... | |
| MqttClientHelper | Publish (string topic, string message) |
| Publish a message to the specified topic. More... | |
| MqttClientHelper | Publish (string topic, byte[] message) |
| Publish a message to the specified topic. More... | |
| MqttClientHelper | Publish (MqttApplicationMessage applicationMessage) |
| Publish a message using advanced options. More... | |
| MqttClientHelper | UsingWebSockets (bool useWebSocket) |
| Connect over WebSocket (default = false). More... | |
| MqttClientHelper | WithCredentials (string user, string pass) |
| Use provided credentials when connecting. More... | |
| MqttClientHelper | WithTls (bool useTls) |
| Set whether to connect using TLS/SSL or not. More... | |
MQTT client helper. Class instance accessor: MqttClient
| MqttClientHelper Service | ( | string | server | ) |
Sets the MQTT server to use.
| server | MQTT server address. |
| MqttClientHelper Connect | ( | string | clientId | ) |
Connects to the MQTT server using the default port (1883) and the specified client identifier.
| clientId | The client identifier. |
| MqttClientHelper Connect | ( | int | port, |
| string | clientId | ||
| ) |
Connects to the MQTT server using the specified port and client identifier.
| port | MQTT server port. |
| clientId | The client identifier. |
| MqttClientHelper Connect | ( | int | port, |
| string | clientId, | ||
| Action< bool > | callback = null |
||
| ) |
Connects to the MQTT server using the specified port and client identifier.
| port | MQTT server port. |
| clientId | The client identifier. |
| callback | Optional callback Action<bool> invoked when the connection status changed (the argument value will be true if connected, false otherwise) |
MqttClient .Service(server) .UsingWebSockets(useWebSockets) .Connect(port, clientid, (connected) => { MqttIsConnected = connected; if (connected) { Program.Notify("Connected!"); } else { Program.Notify("Disconnected!"); } });
| MqttClientHelper Connect | ( | int | port, |
| string | clientId, | ||
| Action< MqttClientOptionsBuilder > | clientOptionsCallback, | ||
| Action< bool > | callback = null |
||
| ) |
Connects to the MQTT server using the specified port / client identifier and the specified client options.
| port | MQTT server port. |
| clientId | The client identifier. |
| clientOptionsCallback | Callback Action<MqttClientOptionsBuilder> invoked before the connection is established to allow setting advanced connection options. See https://github.com/chkr1011/MQTTnet/wiki/Client for all available options. |
| callback | Optional callback Action<bool> invoked when the connection status changed (the argument value will be true if connected, false otherwise) |
Example:
| MqttClientHelper Disconnect | ( | ) |
Disconnects from the MQTT server.
| MqttClientHelper Subscribe | ( | string | topic, |
| Action< string, byte[]> | callback | ||
| ) |
Subscribe the specified topic.
| topic | Topic name. |
| callback | Callback for receiving the subscribed topic messages. |
| MqttClientHelper Unsubscribe | ( | string | topic | ) |
Unsubscribe the specified topic.
| topic | Topic name. |
| MqttClientHelper Publish | ( | string | topic, |
| string | message | ||
| ) |
Publish a message to the specified topic.
| topic | Topic name. |
| message | Message text. |
| MqttClientHelper Publish | ( | string | topic, |
| byte[] | message | ||
| ) |
Publish a message to the specified topic.
| topic | Topic name. |
| message | Message text as byte array. |
| MqttClientHelper Publish | ( | MqttApplicationMessage | applicationMessage | ) |
Publish a message using advanced options.
| applicationMessage | MqttApplicationMessage instance (See https://github.com/chkr1011/MQTTnet/wiki/Client#publishing-messages for documentation). |
| MqttClientHelper UsingWebSockets | ( | bool | useWebSocket | ) |
| MqttClientHelper WithCredentials | ( | string | user, |
| string | pass | ||
| ) |
| MqttClientHelper WithTls | ( | bool | useTls | ) |
Set whether to connect using TLS/SSL or not.
| useTls | Use TLS/SSL. |
1.8.17