![]() |
Helper Class Reference 1.4
HomeGenie - Automation Programs API
|
MQTT client helper. Class instance accessor: MqttClient More...
Public Member Functions | |
MqttClientHelper | Service (string server) |
Sets the MQTT server to use. | |
MqttClientHelper | Connect (string clientId) |
Connects to the MQTT server using the default port (1883) and the specified client identifier. | |
MqttClientHelper | Connect (int port, string clientId) |
Connects to the MQTT server using the specified port and client identifier. | |
MqttClientHelper | Connect (int port, string clientId, Action< bool > callback=null) |
Connects to the MQTT server using the specified port and client identifier. | |
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. | |
MqttClientHelper | Disconnect () |
Disconnects from the MQTT server. | |
MqttClientHelper | Subscribe (string topic, Action< string, byte[]> callback) |
Subscribes the specified topic. | |
MqttClientHelper | Unsubscribe (string topic) |
Unsubscribes the specified topic. | |
MqttClientHelper | Publish (string topic, string message) |
Publish a message to the specified topic. | |
MqttClientHelper | Publish (string topic, byte[] message) |
Publish a message to the specified topic. | |
MqttClientHelper | Publish (MqttApplicationMessage applicationMessage) |
Publish a message using advanced options. | |
MqttClientHelper | UsingWebSockets (bool useWebSocket) |
Connect over WebSocket (default = false). | |
MqttClientHelper | WithCredentials (string user, string pass) |
Use provided credentials when connecting. | |
MqttClientHelper | WithTls (bool useTls) |
Sets whether to connect using TLS/SSL or not. | |
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 Subscribe | ( | string | topic, |
Action< string, byte[]> | callback | ||
) |
Subscribes the specified topic.
topic | Topic name. |
callback | Callback for receiving the subscribed topic messages. |
MqttClientHelper Unsubscribe | ( | string | topic | ) |
Unsubscribes 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 | ) |
Connect over WebSocket (default = false).
useWebSocket | true/false |
MqttClientHelper WithCredentials | ( | string | user, |
string | pass | ||
) |
Use provided credentials when connecting.
user | Username. |
pass | Password. |
MqttClientHelper WithTls | ( | bool | useTls | ) |
Sets whether to connect using TLS/SSL or not.
useTls | Use TLS/SSL. |