Both sides previous revisionPrevious revisionNext revision | Previous revision |
en:iot-open:practical:hardware:sut:esp32:iot_3 [2024/04/21 15:03] – [Steps] pczekalski | en:iot-open:practical:hardware:sut:esp32:iot_3 [2024/04/28 16:45] (current) – [Suggested Readings and Knowledge Resources] pczekalski |
---|
<todo @pczekalski>Dokończyć</todo> | |
====== IOT3: Connecting to the MQTT and publishing data ====== | ====== IOT3: Connecting to the MQTT and publishing data ====== |
In the following scenario, you will learn how to connect to the MQTT broker and publish a message. | In the following scenario, you will learn how to connect to the MQTT broker and publish a message. |
* [[en:iot-open:hardware2:esp32|]], | * [[en:iot-open:hardware2:esp32|]], |
* [[en:iot-open:practical:hardware:sut:esp32|]], | * [[en:iot-open:practical:hardware:sut:esp32|]], |
* [[en:iot-open:iotprogramming2:espressif_networking|]]. | * [[en:iot-open:iotprogramming2:espressif_networking|]] |
| * [[en:iot-open:networking2:applicationnetworkprotocols|]]. |
| |
===== Hands-on Lab Scenario ===== | ===== Hands-on Lab Scenario ===== |
| Note - this scenario can be used in pair with [[[en:iot-open:practical:hardware:sut:esp32:iot_4|]] to build a publish-subscribe solution using two devices (sender and receiver). You need to book two devices then and develop them in parallel. |
| |
==== Task to be implemented ==== | ==== Task to be implemented ==== |
</code> | </code> |
| |
<note tip>In many samples (including samples included along with this MQTT client library, there is a ''client.loop();'' function executed in the main ''void loop()'' body. While it is obligatory in the case of the use of asynchronous sending and receiving of the MQTT messages, in the simple case as above, it can be abandoned because ''client.publish(topic,payload);'' makes a blocking call and ensures sending of the message to the MQTT broker.</note> | <note tip>In many code samples, including those provided along with this MQTT client library, there is a ''client.loop();'' function executed in the main ''void loop()'' body. While it is obligatory in the case of the use of asynchronous sending and receiving of the MQTT messages, in the simple case as above, it can be abandoned because ''client.publish(topic,payload);'' makes a blocking call and ensures sending of the message to the MQTT broker.</note> |
==== Result validation ==== | ==== Result validation ==== |
You should be able to connect to the WiFi and MQTT broker (verified by the status present on the selected display) and then publish a message (once or periodically). Depending on whether you're fully remote or able to access our networks with an additional device, you need to implement a subscriber (as present in the scenario [[[en:iot-open:practical:hardware:sut:esp32:iot_4|]]) or use MQTT Explorer (or any other application capable of connecting to our MQTT Broker) to observe messages that you publish. | You should be able to connect to the WiFi and MQTT broker (verified by the status present on the selected display) and then publish a message (once or periodically). Depending on whether you're fully remote or able to access our networks with an additional device, you need to implement a subscriber (as present in the scenario [[[en:iot-open:practical:hardware:sut:esp32:iot_4|]]) or use MQTT Explorer (or any other application capable of connecting to our MQTT Broker) to observe messages that you publish. |
===== FAQ ===== | ===== FAQ ===== |
**My MQTT client disconnects randomly**: The most common reason is you're using a non-unique MQTT client name. Please change it to some other (even random generated) and give it another try.\\ | **My MQTT client disconnects randomly**: The most common reason is you're using a non-unique MQTT client name. Please change it to some other (even random generated) and give it another try.\\ |
**How do I observe messages that I send?**: Use a software client, such as [[http://mqtt-explorer.com/| MQTT Explorer]], if you're able to access the "internal IoT" network (you're in the range of the network). If you're remote, the only way is to book another device and implement a client subscribing to your message, as presented in the scenario [[[en:iot-open:practical:hardware:sut:esp32:iot_3|]]. Our MQTT broker is also visible in the campus network on the wired interfaces so that you can access it, e.g. via EduVPN or from the laboratory computers. Refer to the supervisor for IP and credentials.\\ | **How do I observe messages that I send?**: Use a software client, such as [[http://mqtt-explorer.com/| MQTT Explorer]], if you're able to access the "internal IoT" network (you're in the range of the network). If you're remote, the only way is to book another device and implement a client subscribing to your message, as presented in the scenario [[[en:iot-open:practical:hardware:sut:esp32:iot_4|]]. Our MQTT broker is also visible in the campus network on the wired interfaces so that you can access it, e.g. via EduVPN or from the laboratory computers. Refer to the supervisor for IP and credentials.\\ |
**Do I need to authorise to publish and subscribe?**: Yes, you do. The supervisor provides the user and password on demand, also presented in the Node's technical documentation. | **Do I need to authorise to publish and subscribe?**: Yes, you do. The supervisor provides the user and password on demand, also presented in the Node's technical documentation. |
| |