About The Application
To illustrate the use of the MQTT library, we have created two simple Tibbo BASIC applications called “mqtt publisher” and “mqtt subscriber”.
In our MQTT demo, the publisher device is monitoring three buttons (Tibbits #38). This is done through the keypad (kp.) object.
The three buttons on the publisher device correspond to the red, yellow, and green LEDs (Tibbits #39) on the subscriber device.
As buttons are pushed and released, the publisher device calls mqtt publish() with topics “LED/Red”, “LED/Green”, and “LED/Yellow”. Each topic’s data is either 0 for “button released” or 1 for “button pressed”. The related code is in the on kp () event handler.
The subscriber device subscribes to all three topics with a single call to mqtt sub() and the line “LED/#”. This is done once, inside callback mqtt connect ok().
With every notification message received from the server, the subscriber device gets callback_ mqtt_ notif () invoked. The LEDs are turned on and off inside this functions’ body.
Testing the MQTT demo
The demo was designed to run on our TPS3 boards, but you can easily modify it for other devices.
The easiest way to get the test hardware is to order “MQTTPublisher” and “MQTTSubscriber” TPS configurations.
You can also order all the parts separately:
- On the publisher side:
- On the subscriber side:
- Install a suitable MQTT server. We suggest Hive MQ (www.hivemq.com):
- Download the software here: www.hivemq.com/downloads/ (you will be asked to register).
- Unzip the downloaded file.
- Go to the “windows-service” folder and execute “installService.bat”.
- Go to the “bin” folder and launch “run.bat”.
- You do not need to configure any user names or passwords.
Read More: Tibbo – MQTT Library Demo