MQTT Communication Protocol with BeagleBone

I. Flash eMMC from SD card on Beagle Bone Black (BBB):

  1. Download the latest Debian image from beagleboard.org/latest-imagesLink to the image for BeagleBone Black: AM3358 Debian 10.3 2020-04-06 4GB SD IoT 
  2. Download and install balenaEtcher: https://www.balena.io/etcher/ 
  3. Use your computer’s SD slot or a USB adapter to connect the SD card to your computer.
  4. Format the SD card if necessary 
  5. Use Etcher to write the image to your SD card. Etcher will transparently decompress the image on-the-fly before writing it to the SD card.
  6.  
  7. Eject the newly programmed SD card. 
  8. Insert the SD card into powered-down board, hold down the USER/BOOT (S2) button and apply power by USB cable (stop pressing the button after the LEDs have been blinking for a few seconds) 
  9. Access the board terminal by typing its IP address into the browser. Because I powered to board by connecting it directly to the computer, I typed 192.168.7.2 
  10. Type the following command into the terminal: sudo nano /boot/uEnv.txt 
  11. Enter the password of the Debian 
  12. Use Nano text Editor to modify the following line:
##enable BBB: eMMC Flasher: 
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh 

into

##enable BBB: eMMC Flasher: cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh 

13. Press the power button to power off the board.
14. While holding the user boot button, press the power button on your board. When the board is powered up, you should continue to hold the user boot button for 5 to 7 seconds and then release it. The USR LEDs blink during this process. Flashing can take about 30 to 40 minutes. When this process is finished, all four USR LEDs will be off.  

Note: I flashed the board’s eMMC 3 times, and it took me around 7 – 10 mins to flash it each time. 


II. Set up mosquitto-clients on BeagleBone Black’s Cloud9:

  1. Open the terminal on Cloud9 of board 1 [192.168.1.2] (can be any board of your choice) 
  2. You should see debian@beaglebone:/var/lib/cloud9$ 
  3. Type in: debian@beaglebone:/var/lib/cloud9$ sudo apt update 
  4. Then, type: debian@beaglebone:/var/lib/cloud9$ sudo apt install mosquitto 
  5. Next: debian@beaglebone:/var/lib/cloud9$ sudo apt install mosquitto-clients net-tools 
  6. As of now, the board has become its own broker, subscriber, and publisher

You can verify it by doing the following test: 
  • Open the 2nd terminal. You can do it by clicking “+” and then “New Terminal” 
  • Type the following in one of the 2 terminals: 
debian@beaglebone:/var/lib/cloud9$ mosquitto_sub -v -t 'bbb/board1' -h 192.168.1.2 

Notes: Now, board 1’s subscriber has subscribed to all messages (-m) with topic (-t) ‘bbb/board1’ from broker with IP address: 192.168.1.2. However, typing in the IP address of the broker is redundant because the board serves as its own broker and clients (subscriber and publisher) in this case. Therefore, you can just type in: debian@beaglebone:/var/lib/cloud9$ mosquitto_sub -v -t ‘bbb/board1’ , and it should work similarly. An alternative way is to replace the IP address with ‘-h localhost’. If the subscriber needs to get messages from a publisher located on another board, the IP address should be that of the board where the publisher locates. 

  • Type the following to the other terminals: 
debian@beaglebone:/var/lib/cloud9$ mosquitto_pub -t 'bbb/board1' -m 'This message is sent from board 1’  
  • You will get the following in the subscriber’s terminal 

Notes: If you wish to get the message (-m) only, you can remove “-v” from the command in the subscriber’s terminal. In that case, you’ll get: 


8. Repeat the previous 6 steps on the second board (or as many boards as you wish) 

Notes: The broker is with the publisher all the time, so remember to use the IP address of the publisher whenever you need the IP address of the broker.  

9. You can also ssh into the board from your device terminal as follows: 

III. Move data from eMMC to SD card 

  1. You will need to connect your BeagleBone Black to your network and power it on 
  2. Access the terminal of the board either via your system terminal or via cloud 9 (by typing the IP address of the board into the browser search bar). To access the terminal through Windows command prompt, we type in “sshdebian@192.168.1.2” followed by the password “temppwd” 
  3. Insert your micro SD card into the BeagleBone Black. 
  4. Execute The Backup. By default BeagleBone Black comes pre loaded with a few tools that you can use to preform various different tasks, one of which is to allow you to create a backup of the onboard eMMC chip. Type the following command into the terminal:  
debian@beaglebone:/var/lib/cloud9$ sudo /opt/scripts/tools/eMMC/beaglebone-black-make-microSD-flasher-from-eMMC.sh 

You will see a lot going on in the terminal, eventually you will see the cylon lights go into action on your device, this means that the backup is in process, after the backup procedure is finished you will see that SSH has disconnected and your BeagleBone Black should power itself down. Make sure you remove the Micro SD card before restarting your device. 

  1. There you have it: an SD card with backed-up information from eMMC.  

IV. Move backed up information/eMMC from SD card to a BeagleBone Black

  1. Insert the SD card into powered-down board, hold down the USER/BOOT (S2) button and apply power by USB cable (stop pressing the button after the LEDs have been blinking for a few seconds ~10 secs) 
  2. After a while you will start seeing the cylon lights go into action on your BeagleBone black
  3. After roughly 10 mins (it could take longer), all the USR LEDs will turn off notifying that the process is done. 
  4. Now, you can eject the SD card and restart the board by press on the power button (Note you don’t have to press the boot button anymore) 

V. Specify clients and broker 

  1. To remove all mosquitto packages like mosquitto, mosquitto-clients and mosquitto-dev below command will be used: 
debian@beaglebone:/var/lib/cloud9$ sudo apt-get purge --remove mosquitto* 

Or

debian@beaglebone:/var/lib/cloud9$ sudo apt purge net-tools mosquitto*  

(We have installed net-tools and mosquitto packages to the board in II, so it is reasonable to remove both net-tools and mosquitto packages for now and reinstall them later based on our needs) 

After the uninstallation, all connections to board 1 will be refused 

  1. To install broker only, use the below command:  
debian@beaglebone:/var/lib/cloud9$ sudo apt install mosquitto net-tools 

Now, the board will serve as a broker solely 

  1. Similarly, to install clients (subscriber and publisher) only, then use the following command 
debian@beaglebone:/var/lib/cloud9$ sudo apt install mosquitto-clients net-tools 
  • Command to publish a message: 
debian@beaglebone:/var/lib/cloud9$ mosquitto_pub -t 'bbb/board1' -m 'This message is sent from board 1' -h 192.168.1.2 
  • Command to subscribe to a topic: 
debian@beaglebone:/var/lib/cloud9$ mosquitto_sub -v -t 'bbb/board1' -h 192.168.1.2 

Notes: Since we are separating the broker from the clients, we need to clearly specify the IP address of the broker by adding ‘-h 192.168.1.2’ to our command. In our case, 192.168.1.2 is the IP address of the broker (board 1).  

1 thought on “MQTT Communication Protocol with BeagleBone

  1. Brittany says:

    Hi, it’s Brittany! Let me know if you have any questions!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *