Loading...
Searching...
No Matches
MqttSession Class Referenceabstract

Class is used for managing MQTT session and publishing position data to MQTT broker. More...

Inherits Finalizable.

Public Member Functions

void connect (String server, int port, String username, String password)
 Method is used to connect to MQTT broker and start publishing position data.
 
void setSubTopic (String subTopic)
 Method is used to set MQTT sub-topic for publishing position data. The final topic will be "navigine/mobile/positions/" + subTopic + "/" + deviceId.
 
void addListener (MqttSessionListener listener)
 Method is used to add MqttSessionListener class element which will notify about MQTT session connection state changes.
 
void removeListener (MqttSessionListener listener)
 Method is used for removing previously added MqttSessionListener class element.
 
void disconnect ()
 Method is used to disconnect from MQTT broker and stop publishing position data.
 
void publish (String topic, String message)
 Method is used to publish a custom message to a specified MQTT topic. The message will be sent asynchronously and the result will be notified through MqttSessionListener callbacks (onMessagePublished for success, onError for failure).
 

Detailed Description

Class is used for managing MQTT session and publishing position data to MQTT broker.

Referenced from NavigineSdk.

Definition at line 20 of file mqtt_session.dart.

Member Function Documentation

◆ addListener()

void MqttSession.addListener ( MqttSessionListener listener)

Method is used to add MqttSessionListener class element which will notify about MQTT session connection state changes.

Note
Do not forget to remove listener if it is no longer needed!
Parameters
listenerСorresponding MqttSessionListener class.

Dart code snippet:

◆ connect()

void MqttSession.connect ( String server,
int port,
String username,
String password )

Method is used to connect to MQTT broker and start publishing position data.

Parameters
serverMQTT broker server hostname or IP address.
portMQTT broker server port.
usernameMQTT broker username for authentication.
passwordMQTT broker password for authentication.

Dart code snippet:

◆ disconnect()

void MqttSession.disconnect ( )

Method is used to disconnect from MQTT broker and stop publishing position data.

Dart code snippet:

◆ publish()

void MqttSession.publish ( String topic,
String message )

Method is used to publish a custom message to a specified MQTT topic. The message will be sent asynchronously and the result will be notified through MqttSessionListener callbacks (onMessagePublished for success, onError for failure).

Note
The MQTT session must be connected before calling this method. Use connect method first.
Parameters
topicMQTT topic to publish the message to. Can be any valid MQTT topic string.
messageMessage content to publish. Can be any string (JSON, plain text, etc.).

Dart code snippet:

◆ removeListener()

void MqttSession.removeListener ( MqttSessionListener listener)

Method is used for removing previously added MqttSessionListener class element.

Parameters
listenerСorresponding MqttSessionListener class to remove.

Dart code snippet:

◆ setSubTopic()

void MqttSession.setSubTopic ( String subTopic)

Method is used to set MQTT sub-topic for publishing position data. The final topic will be "navigine/mobile/positions/" + subTopic + "/" + deviceId.

Parameters
subTopicMQTT sub-topic for publishing position data. Must match pattern [0-9a-zA-Z_-]+ and cannot be empty.

Dart code snippet:


The documentation for this class was generated from the following file: