CoAP Device Server Client mit leshan Server

Dependencies:   EthernetInterface mbed-rtos mbed nsdl_lib

Fork of COAPmbed by smd.iotkit2.ch

Sandbox Server

Eclipse stellt einen Testserver unter http://leshan.eclipse.org/ zur Verfügung. Das Programm verbindet sich mit diesem und ist unter mbed-k64f... erreichbar.

Installation lokale Version leshan

wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar
java -jar ./leshan-server-demo.jar

cURL

Die Funktionen können mittels cURL oder Browser wie folgt getestet werden:

# Alle Clients abfragen (Antwort im JSON Format)
curl -X GET  http://localhost:8080/api/clients
                         
# Wert von LED2 abfragen (Antwort im text/plain Format)                      
curl -X GET  http://localhost:8080/api/clients/mbed-k64f-1234/10/0/2 
 
# Wert für LED2 setzen
curl -X GET -vvv http://localhost:8080/api/clients/mbed-k64f-1234/10/0/2 -H "Content-Type: text/plain" -d "10"
Revision:
16:b27c9d2b1a98
Parent:
15:fba25b7e63cd
Child:
17:8ee737f79492
--- a/main.cpp	Sun Jun 21 12:12:34 2015 +0000
+++ b/main.cpp	Sun Jun 21 12:42:38 2015 +0000
@@ -5,29 +5,24 @@
 #include "EthernetInterface.h"
 #include "nsdl_support.h"
 #include "dbg.h"
+
 // Include various resources
-//#include "temperature.h"
-#include "light.h"
-//#include "gps.h"
-//#include "relay.h"
 #include "PwmOutResource.h"
 
 PwmOutResource led1( D11, "led1", "10/0/0" );
 PwmOutResource led2( D12, "led2", "10/0/1" );
 PwmOutResource led3( D13, "led3", "10/0/2" );
 
+char *staticResources[2] [3] = { { "3/0/0", "Manufacturer", "mc-b" },
+                                 { "3/0/1", "Model Number", "CoAP mbed device" },
+                               };
+
 Serial pc(USBTX, USBRX); // tx, rx
 
 // ****************************************************************************
-// Configuration section
-
-// Ethernet configuration
-/* Define this to enable DHCP, otherwise manual address configuration is used */
-#define DHCP
-
-// NSP configuration
+// Server configuration
 /* Change this IP address to that of your NanoService Platform installation */
-static const char* NSP_ADDRESS = "192.168.178.23"; /* Lokale Installation - leshan Server (gepatcht) */ 
+static const char* NSP_ADDRESS = "192.168.178.23"; /* Lokale Installation - leshan Server */ 
 static const int NSP_PORT = 5683;
 char endpoint_name[] = "mbed-k64f-1234"; // aendern pro Node
 uint8_t ep_type[] = {"mbed_device"};
@@ -102,14 +97,12 @@
     memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
 
     // Static resources
-    nsdl_create_static_resource(resource_ptr, sizeof("3/0/0")-1, (uint8_t*) "3/0/0", 0, 0,  (uint8_t*) "mc-b", sizeof("mc-b")-1);
-    nsdl_create_static_resource(resource_ptr, sizeof("3/0/1")-1, (uint8_t*) "3/0/1", 0, 0,  (uint8_t*) "CoAP mbed device", sizeof("CoAP mbed device")-1);
+    nsdl_create_static_resource( resource_ptr, strlen(staticResources[0] [0]), (uint8_t*) staticResources[0] [0], 0, 0, 
+                                               (uint8_t*) staticResources[0] [2], strlen(staticResources[0] [2]) );
+    nsdl_create_static_resource( resource_ptr, strlen(staticResources[1] [0]), (uint8_t*) staticResources[1] [0], 0, 0, 
+                                               (uint8_t*) staticResources[1] [2], strlen(staticResources[1] [2]) );
 
     // Dynamic resources
-    //create_temperature_resource(resource_ptr);
-    create_light_resource(resource_ptr);
-    //create_gps_resource(resource_ptr);
-    //create_relay_resource(resource_ptr);
     led1.create( resource_ptr );
     led2.create( resource_ptr );
     led3.create( resource_ptr );