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.

112 lines
3.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years 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. npm install node-red
  44. npm install node-red-dashboard
  45. ```
  46. now, we require to run in background the app and verify that *node-RED* is running:
  47. ```
  48. node-red &
  49. sudo netstat -plnt
  50. ```
  51. then, to get access to *node-RED* go to your web browser at `rasp-hostname.local:1880` or `rasp-ip:18080`.
  52. ## A flow process in Node-RED
  53. A basic process is implemented on *Node-RED* to test the mqtt protocol. Thus, add the next blocks:
  54. 1. `mqtt in` from network group
  55. 2. `debug` from common
  56. 3. `text`from dashboard
  57. then, double-click on `mqtt-in` to open and edit the node:
  58. ![](./mqtt-node.png)
  59. 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.
  60. ![](./add-broker.png)
  61. Finally, set the topic to `data/esp32` and the output to `a String` in the mqtt properties' node:
  62. ![](./topic.png)
  63. 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:
  64. ![](./deploy.png)
  65. ## Creating the UI
  66. Next, make double-click on the `dashboard-text` node and add a new `Group` by click on the pencil icon:
  67. ![](./group.png)
  68. set the name *Project*, and add also a new `Dashboard tab`, do not change the default names:
  69. ![](./add-tab.png)
  70. 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:
  71. ![](./ui.png)
  72. **Note: you can also check the generated data on the Arduino IDE serial tools.**