publish method

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

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

Dart code snippet: @snippet mqtt_session_example.dart dart_MqttSession_publish

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);
}