This shows you the differences between two versions of the page.
iothings:laboratoare:lab7 [2022/04/20 18:38] cosmin.chenaru [Exerciții] |
iothings:laboratoare:lab7 [2024/07/15 22:03] (current) cosmin.chenaru Change IP hardcoding |
||
---|---|---|---|
Line 9: | Line 9: | ||
Există o sumedenie de implementări software a protocolului CoAP ([[https://en.wikipedia.org/wiki/Constrained_Application_Protocol#Implementations|Implementations]]), dar în acest laborator vom folosi biblioteca "[[https://github.com/hirotakaster/CoAP-simple-library|CoAP simple library]]" pentru Arduino IDE pentru a rula un server CoAP, și implementarea [[https://github.com/Tanganelli/CoAPthon|CoAPthon]] din Python pentru a rula un client CoAP. | Există o sumedenie de implementări software a protocolului CoAP ([[https://en.wikipedia.org/wiki/Constrained_Application_Protocol#Implementations|Implementations]]), dar în acest laborator vom folosi biblioteca "[[https://github.com/hirotakaster/CoAP-simple-library|CoAP simple library]]" pentru Arduino IDE pentru a rula un server CoAP, și implementarea [[https://github.com/Tanganelli/CoAPthon|CoAPthon]] din Python pentru a rula un client CoAP. | ||
+ | O captură Wireshark arată cum protocolul CoAP rulează peste protocolul UDP: | ||
+ | |||
+ | {{:iothings:laboratoare:lab7-coap-capture.png?600|}} | ||
==== MQTT ==== | ==== MQTT ==== | ||
Line 43: | Line 46: | ||
<code> | <code> | ||
- | /usr/local/bin/coapclient.py -o PUT -p "coap://192.168.1.151/light" -P "1" | + | /usr/local/bin/coapclient.py -o PUT -p "coap://$ESP32_BOARD_IP/light" -P "1" |
</code> | </code> | ||
- | === Ex. 2 - MQTT === | + | === Ex. 2 (Opțional) - Android "IoT CoAP" application === |
+ | |||
+ | Instalați aplicația "IoT CoAP" pentru a trimite mesaje către plăcuța ESP32. | ||
+ | |||
+ | {{:iothings:laboratoare:lab7-iot-coap-app.png|}} | ||
+ | |||
+ | === Ex. 3 - MQTT === | ||
După ce instalați biblioteca "PubSubClient" din Library Manager al Arduino IDE, deschideți exemplul "mqtt_esp8266". | După ce instalați biblioteca "PubSubClient" din Library Manager al Arduino IDE, deschideți exemplul "mqtt_esp8266". | ||
Line 57: | Line 66: | ||
- #include <ESP8266WiFi.h> | - #include <ESP8266WiFi.h> | ||
+ #include <WiFi.h> | + #include <WiFi.h> | ||
- | </code> | ||
- | |||
- | Nu uitați să schimbați numele clientului din "ESP8266Client" în alt nume, spre exemplu: | ||
- | |||
- | <code> | ||
- | String clientId = "IoT-lab7-"; | ||
- | Serial.println(clientId); | ||
</code> | </code> | ||
Line 74: | Line 76: | ||
Folosiți {{:iothings:laboratoare:mypythonmqttclient.py.txt|acest}} program Python pentru a stinge/aprinde LED-ul de pe plăcuța ESP32. | Folosiți {{:iothings:laboratoare:mypythonmqttclient.py.txt|acest}} program Python pentru a stinge/aprinde LED-ul de pe plăcuța ESP32. | ||
- | Vom folosi un broker de MQTT public, la adresa "test.mosquitto.org", atât pentru clientul MQTT de pe ESP32 cât și pentru clientul Python. | + | Vom folosi un broker de MQTT public, la adresa "test.mosquitto.org", atât pentru clientul MQTT de pe ESP32 cât și pentru clientul Python. Din acest motiv, este important să schimbăm numele topic-urilor pentru a nu primi mesaje de la alte device-uri din Internet, care folosesc același server public. |
+ | |||
+ | <note important> | ||
+ | Din topicul "inTopic" puteți schimba in "iot-lab7-myLED-inTopic", iar din topicul "outTopic" in "iot-lab7-myTemperature-outTopic". | ||
+ | </note> | ||
===== Resurse ===== | ===== Resurse ===== | ||
Line 80: | Line 86: | ||
* https://github.com/hirotakaster/CoAP-simple-library | * https://github.com/hirotakaster/CoAP-simple-library | ||
* https://en.wikipedia.org/wiki/Constrained_Application_Protocol | * https://en.wikipedia.org/wiki/Constrained_Application_Protocol | ||
+ | * https://play.google.com/store/apps/details?id=ch.buedev.iot_coap&hl=en&gl=US | ||
+ | * https://www.digikey.de/en/maker/blogs/2019/how-to-use-mqtt-with-the-raspberry-pi |