You are here
Home > BBGW >

BBGW And MQTT Broker Using Desktop

In the previous post we have seen different ways to connect BBGW – BeagleBone Green Wireless board with Wi-Fi and unboxing BBGW for the fist time. This post is about how to test BBGW and MQTT Broker using desktop or laptop.

When building IoT applications it is good practice to send test data using your desktop or laptop. This makes sure that your IoT application built using either flutter or android works fine. This will also help to reduce the waiting time for actual firmware and hardware getting ready. The mobile application developer can test and run his application without actual hardware. This technique can save you a lot of time and energy for the rest of your project development.

Contents

MQTT Setup On Desktop

To perform this test driven development of your IoT product using MQTT we need some MQTT broker. I have installed MQTTLense a chrome extension for testing MQTT applications.

Install MQTTLense

MQTTLense is Google Chrome application, which connects to a MQTT broker and is able to subscribe and publish to MQTT topics. This will help for using the MQTT Monitor to view messages to the MQTT broker.

MQTTLense Installed

After installing and launching the MQTTLense application, click on the “+” button to add a new connection. Fill in the connection name as BBGW. This name can be anything of your choice. Fill in the IP address of beaglebone green wireless board.

Create Connection in MQTTLnese With BBGW

Use ifconfig to find your BBGW network address.

beaglebone# ifconfig 

In my case BBGW IP address is “192.168.0.106” this might be different in your case. Rest other details are not required to update, click on the “CREATE CONNECTION” button.

MQTT Lense Create connection for BBGW

This will create new connection with BBGW and if it is success MQTT Lense will show it as Connection established to 192.168.0.106. Here 192.168.0.106 is my BBGW IP address.

MQTT Lense Connection established to BBGW

MQTT Setup On BBGW

On your BBGW board install mosquitto service and confirm if its running. I assume you have already installed mosquitto broker on your BBGW. If not follow below instructions.

Connect to BBGW using SSH.

$ ssh debian@beaglebone.local

This command will work if you have updated BBGW to latest image.

Install mosquitto on BBGW

Next install mosquitto broker and its supporting client program to send and receive message from MQTTLense.

$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
$ sudo apt-get update
$ sudo apt-get install mosquitto
$ sudo apt-get install mosquitto-clients

Test Mosquitto Status on BBGW

Now check the status of mosquitto service, it should show as active(running) status.

t@beaglebone:~# sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto)
Active: active (running) since Sat 2021-07-03 02:20:34 UTC; 12h ago
CGroup: /system.slice/mosquitto.service
└─340 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Jul 03 02:20:33 beaglebone mosquitto[318]: Starting network daemon:: mosquitto.

Send And Receive Message

Now connection is successfully established to MQTT broker running on BBGW, I can send (publish) data to BBGW device. On BBGW side I have subscribed to “test” topic. From MQTT Lense send message on this topic. This will receive message to BBGW device side.

@beaglebone:~# mosquitto_sub -h localhost -t "test" -v
mosquitto received message on BBGW

To send data from BeagleBone Green Wireless device to MQTTLense, First MQTTLense should subscribe to topic from BBGW board. Here I have created new topic as “test_bbgw” on MQTTLense and click on subscribe. On BBGW side publish message on this topic.

beaglebone:~# mosquitto_pub -h localhost -t "test_bbgw" -m "testing from BBGW"
From BBGW to MqttLense

The message payload and topic can be complex, in this example I have used simple topic name and message payload. Now you are sure that your application modules setup works fine over mqtt. This method helps you to debug MQTT programs and test it. Hope you have enjoyed this post on BBGW And MQTT Broker Using Desktop.

Troubleshooting

mosquitto version 2.0.11 Not Accepting MQTT New connection

If you are using Mosquitto version 2.0.11 then by default mosquitto will start in local only mode, and you couldn’t connect from remote client.  Mosquitto v1.5.7, or previous version will support remote connection by default and mosquitto 2.00 and above versions will start in local only mode by default. To fix this error add following two lines at the end of the file “/etc/mosquitto/mosquitto.conf

listener 1883
allow_anonymous true

After this restart mosquitto service,

 # sudo service mosquitto restart 

Note :- Some of the online sources mention to add these changes in default.conf

/etc/mosquitto/conf.d/default.conf

If you take this approach then you are bound to get following error

Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2021-09-24 08:59:39 UTC; 30s ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 2613 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 2614 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
Process: 2615 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 2616 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 2617 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=3)
Main PID: 2617 (code=exited, status=3)
Sep 24 08:59:39 beaglebone systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
Sep 24 08:59:39 beaglebone systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Sep 24 08:59:39 beaglebone systemd[1]: Stopped Mosquitto MQTT Broker.
Sep 24 08:59:39 beaglebone systemd[1]: mosquitto.service: Start request repeated too quickly.

So we recommend updating in “/etc/mosquitto/mosquitto.conf

Leave a Reply

Top