Loading...
Searching...
No Matches
com.navigine.idl.java.internal.MqttSessionBinding Class Reference
+ Inheritance diagram for com.navigine.idl.java.internal.MqttSessionBinding:

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).
 

Protected Member Functions

 MqttSessionBinding (NativeObject nativeObject)
 

Protected Attributes

Subscription< MqttSessionListenerweakMqttSessionListenerSubscription
 

Detailed Description

Definition at line 12 of file MqttSessionBinding.java.

Constructor & Destructor Documentation

◆ MqttSessionBinding()

com.navigine.idl.java.internal.MqttSessionBinding.MqttSessionBinding ( NativeObject nativeObject)
inlineprotected

Invoked only from native code.

Definition at line 19 of file MqttSessionBinding.java.

Member Function Documentation

◆ addListener()

void com.navigine.idl.java.internal.MqttSessionBinding.addListener ( MqttSessionListener listener)
inline

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
listenerCorresponding MqttSessionListener class.

Java code snippet:

// Add MQTT session listener
mqttSession.addListener(mqttSessionListener);

Kotlin code snippet:

// Add MQTT session listener
session.addListener(listener)

Reimplemented from com.navigine.idl.java.MqttSession.

Definition at line 49 of file MqttSessionBinding.java.

◆ connect()

void com.navigine.idl.java.internal.MqttSessionBinding.connect ( String server,
int port,
String username,
String password )
inline

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.

Java code snippet:

// Connect to MQTT broker
// Server: MQTT broker hostname or IP address
// Port: MQTT broker port (typically 1883 for non-SSL, 8883 for SSL)
// Username: MQTT broker username for authentication
// Password: MQTT broker password for authentication
mqttSession.connect("mqtt.example.com", 1883, "username", "password");

Kotlin code snippet:

// Connect to MQTT broker
// Server: MQTT broker hostname or IP address
// Port: MQTT broker port (typically 1883 for non-SSL, 8883 for SSL)
// Username: MQTT broker username for authentication
// Password: MQTT broker password for authentication
session.connect("mqtt.example.com", 1883, "username", "password")

Reimplemented from com.navigine.idl.java.MqttSession.

Definition at line 35 of file MqttSessionBinding.java.

◆ disconnect()

void com.navigine.idl.java.internal.MqttSessionBinding.disconnect ( )
inline

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

Java code snippet:

// Disconnect from MQTT broker
mqttSession.disconnect();

Kotlin code snippet:

// Disconnect from MQTT broker
session.disconnect()

Reimplemented from com.navigine.idl.java.MqttSession.

Definition at line 63 of file MqttSessionBinding.java.

◆ publish()

void com.navigine.idl.java.internal.MqttSessionBinding.publish ( String topic,
String message )
inline

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.).

Java code snippet:

// Publish a custom message to a specific MQTT topic
// The message will be sent asynchronously and the result will be notified through listener callbacks
String customTopic = "custom/device/status";
String customMessage = "{\"status\": \"online\", \"timestamp\": " + System.currentTimeMillis() + "}";
mqttSession.publish(customTopic, customMessage);

Kotlin code snippet:

// Publish a custom message to a specific MQTT topic
// The message will be sent asynchronously and the result will be notified through listener callbacks
val customTopic = "custom/device/status"
val customMessage = """{"status": "online", "timestamp": ${System.currentTimeMillis()}}"""
session.publish(customTopic, customMessage)

Reimplemented from com.navigine.idl.java.MqttSession.

Definition at line 70 of file MqttSessionBinding.java.

◆ removeListener()

void com.navigine.idl.java.internal.MqttSessionBinding.removeListener ( MqttSessionListener listener)
inline

Method is used for removing previously added MqttSessionListener class element.

Parameters
listenerCorresponding MqttSessionListener class to remove.

Java code snippet:

// Remove first listener
mqttSession.removeListener(listener1);

Kotlin code snippet:

// Remove first listener
session.removeListener(listener1)

Reimplemented from com.navigine.idl.java.MqttSession.

Definition at line 56 of file MqttSessionBinding.java.

◆ setSubTopic()

void com.navigine.idl.java.internal.MqttSessionBinding.setSubTopic ( String subTopic)
inline

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.

Java code snippet:

// Set MQTT sub-topic for publishing position data
// Final topic will be "navigine/mobile/positions/" + subTopic + "/" + deviceId
mqttSession.setSubTopic("location1");

Kotlin code snippet:

// Set MQTT sub-topic for publishing position data
// Final topic will be "navigine/mobile/positions/" + subTopic + "/" + deviceId
session.setSubTopic("location1")

Reimplemented from com.navigine.idl.java.MqttSession.

Definition at line 42 of file MqttSessionBinding.java.

Member Data Documentation

◆ weakMqttSessionListenerSubscription

Subscription<MqttSessionListener> com.navigine.idl.java.internal.MqttSessionBinding.weakMqttSessionListenerSubscription
protected
Initial value:
= new Subscription<MqttSessionListener>() {
@Override
public NativeObject createNativeListener(MqttSessionListener listener) {
return createMqttSessionListener(listener);
}
}

Definition at line 24 of file MqttSessionBinding.java.


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