Custom MQTT Broker, Client and Dashboard Demo (Analog )

This week I developed a solution to send data up and down to a broker using a custom MQTT implementaltion using Mosquitto MQTT on a Raspberry PI 4. I used the code from the microbit cloud gateway board as a starting off point. I substituted the green DFRobot extension board block to a 'serial write line' block and the rest of the code had been left untouched. This means that the gateway microbit forwards radio messages from the client microbits to the Raspberry Pi.


On the Raspberry Pi side of things, a python script has to run in order to log serial messages from the microbit gateway. The messages are logged and the raw numerical values are extracted and stored as a variable. The script then forwards that stored variable and inserts it into a shell command: 

$ mqtt_pub raspberrypi.local -t "test/demo" -m $VAR

The script runs in an infinite loop, logging serial and repeating shell commands to the self-hosted MQTT broker running on the raspberry pi.


This broker can now be accessed by other devices on the same local network as long as the IP address of the raspberry pi (192.168.0.222) is enetered as the broker. The client device must also specify that the broker is using the websockets protocol to communicate with the broker or else the connection will fail. The raspberry pi was configured to use websockets because I wanted a React-based webapp to interact with the broker. The goal is to have a fully custom, self hosted and open source monitoring solution compatable with the Microbits

I was able to create an configure a react-based web application to subscribe to the custom broker using the MQTT.js NPM package.

The web application was initialised by running the following in the terminal:

        npx create vite@latest


 


Comments

Popular posts from this blog

Iteration 2 | Jack | HRV Micro:bit Research

Iteration 5.2 | Lock In | Jack

Week 1: HRV Review