publish method

  1. @override
void publish(
  1. String topic,
  2. String message
)
override

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 Note: The MQTT session must be connected before calling this method. Use connect method first. MqttSessionListener callbacks (onMessagePublished for success, onError for failure). topic MQTT topic to publish the message to. Can be any valid MQTT topic string. message Message content to publish. Can be any string (JSON, plain text, etc.).

Example:

// 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": ${DateTime.now().millisecondsSinceEpoch}}';
_mqttSession!.publish(customTopic, customMessage);

Implementation

@override
void publish(String topic, String message) {
    final _publishFfi = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction<
        Void Function(Pointer<Void>, Pointer<Void>, Pointer<Void>),
        void Function(Pointer<Void>, Pointer<Void>, Pointer<Void>)
      >('navigine_sdk_flutter_MqttSession_publish__Topic_Message'));
    final _topicHandle = navigine_sdk_flutter_String_ToFfi(topic);
    final _messageHandle = navigine_sdk_flutter_String_ToFfi(message);
    final _handle = this.handle;
    _publishFfi(_handle, _topicHandle, _messageHandle);
    navigine_sdk_flutter_String_ReleaseFfiHandle(_topicHandle);
    navigine_sdk_flutter_String_ReleaseFfiHandle(_messageHandle);
}