Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:esp32:iot_6 [2024/05/07 12:28] – [Start] pczekalskien: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/CoAP simple library+    hirotakaster/CoAP simple library@1.3.28
 </code> </code>
  
Line 53: Line 53:
 </code> </code>
 WiFi UDP is part of the Arduino for the ESP32 framework, so you do not need to add it explicitly to the ''platformio.ini'' file. WiFi UDP is part of the Arduino for the ESP32 framework, so you do not need to add it explicitly to the ''platformio.ini'' file.
- 
- 
-<todo @pczekalski>Implement a service on NodeRed and check if it is accessible in the WiFi network.</todo> 
- 
 === Step 3 === === Step 3 ===
 +Declare an IP address of the CoAP server endpoint. Adjust ''a, b, c d'' as needed for your context; see node's technical documentation for integration services details:
 +<code c>
 +#define CoAPport 5683
 +#define CoAPpath "<here comes CoAP service path, without header, IP and port>"
 +IPAddress coapExtSeviceIP(a,b,c,d);
 +</code>
 +<note tip>The ''CoAPpath'' is just a path part of the URI, e.g. if your CoAP service URI is:
 +<code>
 +coap://your_coap_server:9876/path_to_the_service/and_another_path
 +</code>
 +then your ''CoAPpath'' should be declared as:
 +<code c>
 +#define CoAPpath "path_to_the_service/and_another_path"
 +</code></note>
 +=== Step 4 ===
 Declate communication objects: Declate communication objects:
 <code c> <code c>
Line 64: Line 75:
 </code> </code>
  
-=== Step === +=== Step === 
 +Declare function prototypes (not necessary if you implement them in the correct order): 
 +<code c> 
 +void callback_response(CoapPacket &packet, IPAddress ip, int port); // CoAP client response callback 
 +</code>
  
 === Step 5 === === Step 5 ===
 +Implement response handler for ''GET'' method: 
 +<code c> 
 +void callback_response(CoapPacket &packet, IPAddress ip, int port) {  
 +  char p[packet.payloadlen + 1]; 
 +  memcpy(p, packet.payload, packet.payloadlen); 
 +  p[packet.payloadlen] = NULL; 
 +  //Add your code to represent information on the selected display 
 +
 +</code>
  
 === Step 6 === === Step 6 ===
 +Register response callback and start CoAP client: 
 +<code c> 
 +  coap.response(callback_response); 
 +  coap.start(); 
 +</code>
  
 === 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 "path" part of the URI.
 +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,CoAPport,CoAPpath);
 +</code>
  
- +=== Step 8 ===
-=== Setup 8 ===+
 Process CoAP services in the ''void loop()'': Process CoAP services in the ''void loop()'':
 <code c> <code c>
en/iot-open/practical/hardware/sut/esp32/iot_6.1715084900.txt.gz · Last modified: 2024/05/07 12:28 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0