This shows you the differences between two versions of the page.
|
iothings:laboratoare:2025:lab3 [2025/10/11 12:44] dan.tudose [QoS, Retain & LWT] |
iothings:laboratoare:2025:lab3 [2025/10/13 17:20] (current) dan.tudose [Platformio.ini] |
||
|---|---|---|---|
| Line 48: | Line 48: | ||
| * ''sensors/room1'' | * ''sensors/room1'' | ||
| * ''sensors/temperature/office/room1'' | * ''sensors/temperature/office/room1'' | ||
| + | {{ :iothings:laboratoare:2025:single-level-wild-card--1-.png?600 |}} | ||
| == # (Multi-Level Wildcard) == | == # (Multi-Level Wildcard) == | ||
| Line 61: | Line 62: | ||
| * ''#'' alone matches **all topics**. | * ''#'' alone matches **all topics**. | ||
| + | |||
| + | {{ :iothings:laboratoare:2025:single-level-wild-card--1--1.png?600 |}} | ||
| == Rules and Constraints == | == Rules and Constraints == | ||
| Line 112: | Line 115: | ||
| adafruit/Adafruit BME680 Library | adafruit/Adafruit BME680 Library | ||
| bblanchon/ArduinoJson @ ^7 | bblanchon/ArduinoJson @ ^7 | ||
| - | 256dpi/MQTT @ ^2.5.2 | + | 256dpi/MQTT @ ^2.5.2 |
| + | knolleary/PubSubClient @ ^2.8 | ||
| </code> | </code> | ||
| Line 124: | Line 128: | ||
| Once connected, the ESP32 enters a loop where it continuously maintains the MQTT session, reconnects if needed, and publishes a heartbeat message every five seconds containing its uptime in milliseconds. This heartbeat acts as a regular signal that the device is alive. The code’s use of non-blocking MQTT functions keeps the system responsive, while the combination of retained status messages and the Last Will feature ensures other clients always know the ESP32’s current state — whether it’s online, offline, or actively sending updates. | Once connected, the ESP32 enters a loop where it continuously maintains the MQTT session, reconnects if needed, and publishes a heartbeat message every five seconds containing its uptime in milliseconds. This heartbeat acts as a regular signal that the device is alive. The code’s use of non-blocking MQTT functions keeps the system responsive, while the combination of retained status messages and the Last Will feature ensures other clients always know the ESP32’s current state — whether it’s online, offline, or actively sending updates. | ||
| - | [[iothings:laboratoare:2025:lab3_code1| Click here to get the code for this example.]] | + | [[iothings:laboratoare:2025_code:lab3_1|Click here to get the code for this example.]] |
| After building and uploading to your Sparrow node, test it out using [[https://dantudose.github.io/labs/lab3_1.html | this link]]. | After building and uploading to your Sparrow node, test it out using [[https://dantudose.github.io/labs/lab3_1.html | this link]]. | ||
| Line 138: | Line 141: | ||
| After setting the LED color, the device publishes an acknowledgment message to a separate MQTT topic, confirming the values it received and applied. This acknowledgment lets any remote controller or dashboard know that the LED update was successful. The whole process uses the non-blocking, event-driven design of the 256dpi library, meaning it can handle MQTT communication efficiently without freezing the microcontroller’s main loop. In essence, this sketch turns the ESP32 into a small, networked RGB controller that listens for MQTT commands and reports its actions back to the broker. | After setting the LED color, the device publishes an acknowledgment message to a separate MQTT topic, confirming the values it received and applied. This acknowledgment lets any remote controller or dashboard know that the LED update was successful. The whole process uses the non-blocking, event-driven design of the 256dpi library, meaning it can handle MQTT communication efficiently without freezing the microcontroller’s main loop. In essence, this sketch turns the ESP32 into a small, networked RGB controller that listens for MQTT commands and reports its actions back to the broker. | ||
| - | [[iothings:laboratoare:2025:lab3_code2| Click here to get the code for this example.]] | + | [[iothings:laboratoare:2025_code:lab3_2| Click here to get the code for this example.]] |
| Test it out using [[https://dantudose.github.io/labs/lab3_2.html | this link]]. | Test it out using [[https://dantudose.github.io/labs/lab3_2.html | this link]]. | ||
| Line 148: | Line 151: | ||
| Every ten seconds, the ESP32 reads environmental data from the on-board BME680 sensor—including temperature, humidity, pressure, and gas resistance—and packages those readings into a JSON message. It then publishes this JSON payload to an MQTT topic dedicated to that device’s sensor data. Any other MQTT clients subscribed to that topic can instantly receive and process the latest environmental information, such as for logging, visualization, or automation. In short, this code makes the ESP32 function as a small, networked environmental node that continuously streams live sensor data to the MQTT ecosystem while maintaining reliable connection status reporting. | Every ten seconds, the ESP32 reads environmental data from the on-board BME680 sensor—including temperature, humidity, pressure, and gas resistance—and packages those readings into a JSON message. It then publishes this JSON payload to an MQTT topic dedicated to that device’s sensor data. Any other MQTT clients subscribed to that topic can instantly receive and process the latest environmental information, such as for logging, visualization, or automation. In short, this code makes the ESP32 function as a small, networked environmental node that continuously streams live sensor data to the MQTT ecosystem while maintaining reliable connection status reporting. | ||
| - | [[iothings:laboratoare:2025:lab3_code3|Click here to get the code for this example.]] | + | [[iothings:laboratoare:2025_code:lab3_3|Click here to get the code for this example.]] |
| Test it out using [[https://dantudose.github.io/labs/lab3_3.html | this link]]. | Test it out using [[https://dantudose.github.io/labs/lab3_3.html | this link]]. | ||
| Line 160: | Line 163: | ||
| At the same time, the ESP32 regularly publishes telemetry data through MQTT. It sends heartbeat messages with uptime, signal strength, and network information, and it transmits environmental sensor readings from the BME680 to a designated topic as JSON data. All MQTT communication uses Quality of Service level 1 to ensure that messages are delivered at least once, providing reliable data exchange between the device and the broker. The code also manages automatic reconnection with exponential backoff, meaning it gracefully retries connecting to the MQTT broker when disconnected without flooding the network. In essence, from the MQTT point of view, this device behaves as a resilient, bidirectional IoT client that reports data, accepts remote commands, and maintains a persistent, reliable session with the broker. | At the same time, the ESP32 regularly publishes telemetry data through MQTT. It sends heartbeat messages with uptime, signal strength, and network information, and it transmits environmental sensor readings from the BME680 to a designated topic as JSON data. All MQTT communication uses Quality of Service level 1 to ensure that messages are delivered at least once, providing reliable data exchange between the device and the broker. The code also manages automatic reconnection with exponential backoff, meaning it gracefully retries connecting to the MQTT broker when disconnected without flooding the network. In essence, from the MQTT point of view, this device behaves as a resilient, bidirectional IoT client that reports data, accepts remote commands, and maintains a persistent, reliable session with the broker. | ||
| - | [[iothings:laboratoare:2025:lab3_code4|Click here to access your code for this example.]] | + | [[iothings:laboratoare:2025_code:lab3_4|Click here to access your code for this example.]] |
| Test it out using [[https://dantudose.github.io/labs/lab3_4.html | this link]]. | Test it out using [[https://dantudose.github.io/labs/lab3_4.html | this link]]. | ||