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_6 [2024/05/07 12:28] – [Start] pczekalski | en:iot-open:practical:hardware:sut:esp32:iot_6 [2024/06/29 15:52] (current) – [Prerequisites] pczekalski | ||
---|---|---|---|
Line 15: | Line 15: | ||
<code ini> | <code ini> | ||
lib_deps = | lib_deps = | ||
- | hirotakaster/ | + | hirotakaster/ |
</ | </ | ||
Line 53: | Line 53: | ||
</ | </ | ||
WiFi UDP is part of the Arduino for the ESP32 framework, so you do not need to add it explicitly to the '' | WiFi UDP is part of the Arduino for the ESP32 framework, so you do not need to add it explicitly to the '' | ||
- | |||
- | |||
- | <todo @pczekalski> | ||
- | |||
=== Step 3 === | === Step 3 === | ||
+ | Declare an IP address of the CoAP server endpoint. Adjust '' | ||
+ | <code c> | ||
+ | #define CoAPport 5683 | ||
+ | #define CoAPpath "< | ||
+ | IPAddress coapExtSeviceIP(a, | ||
+ | </ | ||
+ | <note tip>The '' | ||
+ | < | ||
+ | coap:// | ||
+ | </ | ||
+ | then your '' | ||
+ | <code c> | ||
+ | #define CoAPpath " | ||
+ | </ | ||
+ | === Step 4 === | ||
Declate communication objects: | Declate communication objects: | ||
<code c> | <code c> | ||
Line 64: | Line 75: | ||
</ | </ | ||
- | === Step 4 === | + | === Step 5 === |
+ | Declare function prototypes (not necessary if you implement them in the correct order): | ||
+ | <code c> | ||
+ | void callback_response(CoapPacket & | ||
+ | </ | ||
=== Step 5 === | === Step 5 === | ||
+ | Implement response handler for '' | ||
+ | <code c> | ||
+ | void callback_response(CoapPacket & | ||
+ | char p[packet.payloadlen + 1]; | ||
+ | memcpy(p, packet.payload, | ||
+ | p[packet.payloadlen] = NULL; | ||
+ | //Add your code to represent information on the selected display | ||
+ | } | ||
+ | </ | ||
=== Step 6 === | === Step 6 === | ||
+ | Register response callback and start CoAP client: | ||
+ | <code c> | ||
+ | coap.response(callback_response); | ||
+ | coap.start(); | ||
+ | </ | ||
=== Step 7 === | === Step 7 === | ||
+ | Make a call (GET) request to the service. Remember to provide the correct URI part.\\ | ||
+ | Mind that the last argument of the function is a " | ||
+ | The laboratory technical documentation provides a list of the services, their URIs (including paths), methods, and IP ports. | ||
+ | <code c> | ||
+ | int msgid = coap.get(coapExtSeviceIP, | ||
+ | </ | ||
- | + | === Step 8 === | |
- | === Setup 8 === | + | |
Process CoAP services in the '' | Process CoAP services in the '' | ||
<code c> | <code c> |