MQTT Server for BeagleBone
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.6 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. # Introduction
  2. This reposity includes the basic information to mount a server using **Node-RED** as a Dashboard and also working as a MQTT server using **Mosquitto**. The MQTT server is tested with a ESP32 client to publish random numbers every two seconds.
  3. The general scheme is shown below, the complete environment requires a client, mqtt server or broker, and a mqtt client that works like a user interface (dashboard).
  4. The basic communication scheme could work like:
  5. 1. The ESP32 starts the communication chain by sending a text message to the broker, the broker can be public or local.
  6. 2. Depending on the code, the sending message can be replicated to all the connected clients in the *topic*.
  7. 3. Finally, a web server based on *Node-RED* will read the publicated data in the broker to be displayed in the *UI*.
  8. ![mqttesp32](./Imagenes/mqttesp32.PNG)
  9. The client code to test the environment is hosted in the [mqtt-client-esp32-v2](https://github.com/ss-jade/mqtt-client-esp32-v2).
  10. *Thanks to Andrés Perez for the first version.*
  11. # MQTT Server
  12. ## Installing Mosquitto
  13. For the Raspberry pi, based on Debian's distribution, we can use:
  14. ```bash
  15. sudo apt update
  16. sudo apt upgrade
  17. sudo apt install mosquitto
  18. ```
  19. To execute *mosquitto* and enable every time the system starts:
  20. ```
  21. sudo systemctl enable mosquitto.service
  22. ```
  23. ## Configuring the Mosquitto server
  24. First replace the default configuration file by the file providing in this repository:
  25. ```
  26. sudo cp ./mosquitto.conf /etc/mosquitto/mosquitto.conf
  27. ```
  28. then, create the password file instanced on the `mosquitto.conf` file
  29. ```
  30. sudo touch /etc/mosquitto/passwd
  31. ```
  32. finally, restart the service:
  33. sudo systemctl restart mosquitto
  34. ## Node-RED installation
  35. To install **nodejs** write in terminal:
  36. ```
  37. sudo apt update
  38. sudo apt install nodejs
  39. sudo apt install npm
  40. ```
  41. Then, let us install the *Node-RED* app and the *Dashboard* complement by using the *Node Package Manager*:
  42. ```
  43. sudo npm install -g --unsafe-perm node-red
  44. node-red-stop
  45. npm install node-red-dashboard
  46. ```
  47. now, we require to run in background the app and verify that *node-RED* is running:
  48. ```
  49. node-red &
  50. sudo netstat -plnt
  51. ```
  52. then, to get access to *node-RED* go to your web browser at `rasp-hostname.local:1880` or `rasp-ip:18080`.
  53. ## A flow process in Node-RED
  54. A basic process is implemented on *Node-RED* to test the mqtt protocol. Thus, add the next blocks:
  55. 1. `mqtt in` from network group
  56. 2. `debug` from common
  57. 3. `text`from dashboard
  58. then, double-click on `mqtt-in` to open and edit the node:
  59. ![](./mqtt-node.png)
  60. click on *Add new mqtt-brocker*, then, in the *Connection* tab: set *Name* to Rasp, point the server to the raspberry's ip or hostname and port 1883. Leave unchanged the *Security* and *Message* tabs and click on the **Add** button.
  61. ![](./add-broker.png)
  62. Finally, set the topic to `data/esp32` and the output to `a String` in the mqtt properties' node:
  63. ![](./topic.png)
  64. Next, connect the blocks as shows in the image and click on the `Deploy` button to check if the process can connect to the Broker:
  65. ![](./deploy.png)
  66. ## Creating the UI
  67. Next, make double-click on the `dashboard-text` node and add a new `Group` by click on the pencil icon:
  68. ![](./group.png)
  69. set the name *Project*, and add also a new `Dashboard tab`, do not change the default names:
  70. ![](./add-tab.png)
  71. once the parameters have been configured click the add button twice; for the tabs and for the node properties. Next, click on the `Deploy` button and visit the `hostname-or-ip/ui` to see the output generated by the MQTT client:
  72. ![](./ui.png)
  73. **Note: you can also check the generated data on the Arduino IDE serial tools.**