Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MQTT between Raspberry Pi, Arduino and JavaScript

A mate and I are doing a project at the moment that hosts a webpage on a raspberry pi which I would like to send a message via MQTT to the arduino which reads sensors and then sends the values back to the pi to be displayed on the web page.

I am hoping to use Mosquito on the pi as a broker and treat the arduino and the webpage as clients.

I am just having a lot of trouble working out how it all fits together.

A lot of examples I have seen use web sockets and node.js and MQTT.io and I'm just so confused..

Could someone please help me piece it all together and explain how everything fits and what it does?

Thanks in advance!

like image 752
Lee Wiggins Avatar asked Oct 23 '25 08:10

Lee Wiggins


1 Answers

Websockets allows a web browser to open a bi-directional communication pipe to a server.

For websockets to work you need a websocket enabled mqtt broker. At the moment you have to install this seperately, some examples of what is out there are here. Mosquitto will have websockets enabled in the next version, 1.4, you can compile it if you wish.

An example of what can be done, and what I am doing atm with mqtt and websockets is;

  1. publish temperature data to mqtt broker from an arduino.
  2. subscribe to the topic that the arduino is publishing to and populate the data into a mysql database using python scripts.
  3. have a live website subscribe to the topic and show the current temperature as a line graph.
like image 149
Matt. Avatar answered Oct 25 '25 20:10

Matt.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!