This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:esp32:iot_5 [2024/04/28 17:03] – [Task to be implemented] pczekalski | en:iot-open:practical:hardware:sut:esp32:iot_5 [2024/05/01 13:28] (current) – [Start] pczekalski | ||
---|---|---|---|
Line 39: | Line 39: | ||
* method PUT - should set the LED on and off, with the expected payload being " | * method PUT - should set the LED on and off, with the expected payload being " | ||
- | <todo @pczekalski>Skończyć</todo> | + | ==== Start ==== |
+ | Check if you can clearly see a full display (of your choice) in your video stream. Book a device and create a dummy Arduino file with '' | ||
+ | Implement a connection to the " | ||
+ | |||
+ | === Step 1 === | ||
+ | Refer to the hardware documentation and ensure an understanding of the network infrastructure you're interfacing with.\\ | ||
+ | Implement the code to display on the selected device.\\ | ||
+ | Connect to the WiFi in the STA mode (as a client) and ensure the connection is OK and you got an IP from the DHCP server.\\ | ||
+ | It is essential to note and present (using a display of your choice) the node's IP address, as you will later need to refer to it with a client to use your service. | ||
+ | |||
+ | === Step 2 === | ||
+ | Include the WiFi UDP and CoAP implementation libraries headers in your code: | ||
+ | <code c> | ||
+ | #include < | ||
+ | #include < | ||
+ | </ | ||
+ | WiFi UDP is part of the Arduino for the ESP32 framework, so you do not need to add it explicitly to the '' | ||
+ | |||
+ | === Step 3 === | ||
+ | Declare necessary constants, etc.: | ||
+ | <code c> | ||
+ | bool LEDSTATE; //Keep LED's state. | ||
+ | </ | ||
+ | |||
+ | === Step 4 === | ||
+ | Declare communication objects: | ||
+ | <code c> | ||
+ | WiFiUDP udp; //UDP Communication class | ||
+ | Coap coap(udp); | ||
+ | </ | ||
+ | |||
+ | === Step 5 === | ||
+ | Declare function prototypes (not necessary if you implement them in the correct order): | ||
+ | <code c> | ||
+ | void callback_response(CoapPacket & | ||
+ | // CoAP server endpoint URL callback for GET and PUT methods | ||
+ | void callback_led(CoapPacket & | ||
+ | </ | ||
+ | |||
+ | === Step 6 === | ||
+ | Implement them: | ||
+ | <code c> | ||
+ | void callback_led(CoapPacket & | ||
+ | // send response | ||
+ | char p[packet.payloadlen + 1]; | ||
+ | memcpy(p, packet.payload, | ||
+ | p[packet.payloadlen] = NULL; | ||
+ | |||
+ | String message(p); | ||
+ | //for GET | ||
+ | if (message.equals(" | ||
+ | LEDSTATE = false; | ||
+ | else if(message.equals(" | ||
+ | LEDSTATE = true; | ||
+ | //for PUT | ||
+ | if (LEDSTATE) { | ||
+ | coap.sendResponse(ip, | ||
+ | } else { | ||
+ | digitalWrite(RGBLED_R_PIN, | ||
+ | coap.sendResponse(ip, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | <code c> | ||
+ | void callback_response(CoapPacket & | ||
+ | char p[packet.payloadlen + 1]; | ||
+ | memcpy(p, packet.payload, | ||
+ | p[packet.payloadlen] = NULL; | ||
+ | //Do something with payload, e.g. print it to the display | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Step 7 === | ||
+ | Setup CoAP services: | ||
+ | <code c> | ||
+ | coap.server(callback_led, | ||
+ | coap.response(callback_response); | ||
+ | coap.start(); | ||
+ | </ | ||
+ | |||
+ | === Setup 8 === | ||
+ | Process CoAP services in the '' | ||
+ | <code c> | ||
+ | delay(1000); | ||
+ | coap.loop(); | ||
+ | </ | ||
+ | < | ||
+ | |||
+ | ==== Result validation ==== | ||
+ | You should be able to connect to the WiFi and set up a CoAP service. Depending on whether you're fully remote or able to access our networks with an additional device, you need to implement a CoAP client on another laboratory node (as present in the scenario [[[en: | ||
+ | |||
+ | <note tip> | ||
+ | <code bash> | ||
+ | $ coap-client -e " | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <note tip> | ||
+ | <code bash> | ||
+ | $ coap-client -m get coap:// | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== FAQ ===== | ||
+ | **How do I implement a client to my CoAP service?**: If you're fully remote, the only option is to implement a client on your own - use another laboratory node and scenario [[[en: | ||
+ | |||
+ | <WRAP noprint> | ||
+ | ===== Project information ===== | ||
+ | {{: | ||
+ | This Intellectual Output was implemented under the Erasmus+ KA2.\\ | ||
+ | Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, | ||
+ | Project number: 2022-1-PL01-KA220-HED-000085090. | ||
+ | |||
+ | **__Erasmus+ Disclaimer__**\\ | ||
+ | This project has been funded with support from the European Commission. \\ | ||
+ | This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein. | ||
+ | |||
+ | **__Copyright Notice__**\\ | ||
+ | This content was created by the IOT-OPEN.EU Reloaded consortium, 2022, | ||
+ | The content is Copyrighted and distributed under CC BY-NC [[https:// | ||
+ | <figure label> | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | </WRAP> |