Using MQTT Between Raspberry Pi, Arduino and JavaScript

We and I are doing a project the moment we host a web page on a raspberry pi that I would like to send a message via MQTT to arduino, which reads the sensors and then sends the values ​​back to the displayed pi on the web page.

I hope to use Mosquito on pi as broker and treat arduino and webpage as clients.

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

Lots of examples I've seen use websockets and node.js and MQTT.io and I'm just so confused.

Can someone please help me put it all together and explain how everything fits and what it does?

Thanks in advance!

+3


source to share


2 answers


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

For web folders to work, you need a mqtt broker with websocket support. At the moment you need to install this separately, some examples of what is there are here . The next version of Mosquitto will include web descriptors, 1.4 , you can compile it if you like.



An example of what can be done and what I am doing atm with mqtt and websockets:

  • post temperature data to mqtt broker from arduino.
  • subscribe to a topic arduino publishes and populates data in mysql database using python scripts .
  • host a website live and sign the current temperature as a line graph.
+4


source


In the past, we have provided tutorials on building applications with MQTT and websockets. The slides (+ code) can be found on Slideshare .



If you're wondering how MQTT over websockets works in detail, this blog post might help you. Also, a complete sample website / MQTT application example can be found in this blog post .

+4


source







All Articles