FYP: Sorting out the Webapp, MQTT
Well this blogging thing hasn't been anywhere near as regular as I hoped it would be. Anyway at this point solid radio communication had been established and it was time to connect it up to the webapp. I decided to use MQTT as a communication protocol between the webapp and the Arduino with the transmitter on it, the master. My VPS, Hazel, has an MQTT broker running on it currently.
Hooking up the webapp to publish was pretty easy using the mqttws library, a library for sending and receiving MQTT messages over web sockets. I set up the webapp so that it published the contents of the form with an identifier and the value for the respective form element. At this point I wanted as much logic to be handled by the webapp as possible. I wanted the transmitter to be completely dumb. This meant that if I wanted to change how the data string worked I could do it on the webapp and not have to touch the master Arduino.
So the webapp was pretty functional. It sent values through an MQTT channel to Hazel, my VPS. The values were as follows:
- Volume: 2000 - 2170
- The first digit was the identifier, and the remaining three was the required angle value for the servo.
- Colour: 3000000000 - 3255255255
- The first digit was the identifier, and the remaining nine digits were the R, G and B values respectively. Each colour value was three characters ranging between 0 to 225
The values were pushed through MQTT whenever the user changed any value on the frontend form. Naturally the webapp was completely responsive so it could be used on a mobile phone.