Skip to content

The repository contains a GUI application on dart, which demonstrates the capabilities of the MQTT client, implemented as a hierarchical state machine.

Notifications You must be signed in to change notification settings

mk590901/MQTT-Client-Dart-Flutter

Repository files navigation

MQTT-Client-Dart

MQTT Client Flutter demo app.

Introduction

The application uses package https://pub.dev/packages/mqtt_client to implement access, communication, subscription, and sending and receiving data via the MQTT bridge host. The package isn't used directly, but indirectly, through the hierarchical state machine by sending events and receiving messages about the end of operations. This allows for simplified sending and receiving data and error handling.

MQTT Client State Machine

Below is some information about the created hierarchical state machine.

Scheme

The Hierarchical state machine diagram describing the behavior of the MQTT client is shown below in the figure. There are three main states: disconnected, connected and subscribed and several intermediate states: connecting, subscribing and publishing. The state machine is controlled via events: connect, subscribe, publish, unsubscribe and disconnect.

output1

Implementation

State machine was automatically generated by the graphical editor and is presented in the module MqttHelper (mqtt_cs_8_helper.dart) as a class with set of transfer functions that interact with the pub dev mqtt_client package via the custom MQTTClient object. The responses in the form of events succeeded and failed are sent back to the state machine, causing a change in its states. Threaded code interpretation is used. This approach is simple, compact and transparent.

Description of the application

The screen is divided into two parts. At the top is a set of buttons corresponding to the operations that the mqtt client can perform, at the bottom is the result of performing these operations. Don't be afraid to mix operations up by performing them in a different order than the logic suggests: the state machine will respond to the error with messages. Pay attention to the publish operation. In the list of messages, after the word publish, a line of random characters appears: this is the message that the client sends to cloud. Note that sometimes lines of random characters appear without any connection with the execution of the publish command. This is not an error. It's just that the same application was launched in parallel on the second phone, we just see the data sent by this second application. Actually, this is the whole point of the demo: using the mqtt client, you can easily exchange data between applications.

Note. The application uses the free host test.mosquitto.org as an MQTT broker. You can also use broker.hivemq.com (mqtt_service.dart). Just keep in mind that sometimes during the day the excessive load on these sites creates problems when connecting.

Movie

mqtt.mp4

About

The repository contains a GUI application on dart, which demonstrates the capabilities of the MQTT client, implemented as a hierarchical state machine.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages