mqtt_helper 1.0.1 mqtt_helper: ^1.0.1 copied to clipboard
mqtt_helper is a Flutter package that simplifies MQTT integration, reducing boilerplate code and providing a convenient layer on top of mqtt_client.
A wrapper package for mqtt_client that provides a simpler and more intuitive API for working with MQTT in Flutter.
Features #
- Wrapper class covering everything for mqtt_client
- Provides listeners on events and other callbacks for
mqtt_client
- Simplifies the usage of
mqtt_client
with a wrapper class- Provides listeners for connection changes and events
- Supports subscribing and unsubscribing to single or multiple topics
- Allows publishing messages to MQTT topics
Getting started #
Add it to your pubspec.yaml
dependencies:
mqtt_helper: <latest-version>
Usage #
- Create one instance of the helper class
MqttHelper
var helper = MqttHelper();
- Initialize and Connect to the MqttClient with the helper
var config = MqttConfig(); // You'll need to pass your creds and configs inside MqttConfig
helper.initialize(config);
Additional Information #
Listeners #
- Use
onConnectionChange()
listener to listen to connection changes whether Mqtt is connected or not - Use
onEvent()
listener to listen to events that will come.
Subscribing and Unsubscribing #
- Use
subscribeTopic()
to subscribe to single topic. - Use
subscribeTopics()
to subscribe to multiple topics at once. - Use
unsubscribeTopic()
to unsubscribe to single topic. - Use
unsubscribeTopics()
to unsubscribe to multiple topics at once.
Publishing #
- Use
publishMessage()
to publish a message to a topic.