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:
9:18f4959c2bac
Parent:
8:cdf868ccae03
Child:
10:57352d0c287c
diff -r cdf868ccae03 -r 18f4959c2bac main.cpp
--- a/main.cpp	Mon Aug 04 17:00:58 2014 +0000
+++ b/main.cpp	Sun Jan 18 15:41:27 2015 +0000
@@ -1,15 +1,13 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
-#include "C12832_lcd.h"
 #include "nsdl_support.h"
 #include "dbg.h"
 // Include various resources
-#include "temperature.h"
+//#include "temperature.h"
 #include "light.h"
-#include "gps.h"
-#include "relay.h"
+//#include "gps.h"
+//#include "relay.h"
 
-static C12832_LCD lcd;
 Serial pc(USBTX, USBRX); // tx, rx
 
 // ****************************************************************************
@@ -19,16 +17,11 @@
 /* Define this to enable DHCP, otherwise manual address configuration is used */
 #define DHCP
 
-/* Manual IP configurations, if DHCP not defined */
-#define IP      "10.45.0.206"
-#define MASK    "255.255.255.0"
-#define GW      "10.45.0.1"
-
 // NSP configuration
 /* Change this IP address to that of your NanoService Platform installation */
-static const char* NSP_ADDRESS = "217.140.101.20"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org */ 
+static const char* NSP_ADDRESS = "23.97.178.38"; /* demo NSP, web interface at http://nsp.cloudapp.net:8083/, User/PW = demo */ 
 static const int NSP_PORT = 5683;
-char endpoint_name[16] = "mbed-";
+char endpoint_name[16] = "mbed-k64f-1234"; // aendern pro Node
 uint8_t ep_type[] = {"mbed_device"};
 uint8_t lifetime_ptr[] = {"1200"};
 
@@ -39,24 +32,21 @@
 
 static void ethernet_init()
 {
-    char mbed_uid[33]; // for creating unique name for the board
+    //char mbed_uid[33]; // for creating unique name for the board
 
     /* Initialize network */
-#ifdef DHCP
     NSDL_DEBUG("DHCP in use\r\n");
     eth.init();
-#else
-    eth.init(IP, MASK, GW);
-#endif
+    
     if(eth.connect(30000) == 0)
         pc.printf("Connect OK\n\r");
 
-    mbed_interface_uid(mbed_uid);
-    mbed_uid[32] = '\0';
-    strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
+    //mbed_interface_uid(mbed_uid); // -> Fehlt fuer K64F
+    //strcpy( mbed_uid, "k64f-1234" );
+    //mbed_uid[32] = '\0';
+    //strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
 
-    lcd.locate(0,11);
-    lcd.printf("IP:%s", eth.getIPAddress());
+    printf("IP:%s", eth.getIPAddress());
 
     NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
 }
@@ -77,8 +67,7 @@
     NSDL_DEBUG("name: %s", endpoint_name);
     NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
 
-    lcd.locate(0,22);
-    lcd.printf("EP name:%s\n", endpoint_name);
+    printf("EP name:%s\n", endpoint_name);
 }
 
 // ****************************************************************************
@@ -110,10 +99,10 @@
     nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0,  (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1);
 
     // Dynamic resources
-    create_temperature_resource(resource_ptr);
+    //create_temperature_resource(resource_ptr);
     create_light_resource(resource_ptr);
-    create_gps_resource(resource_ptr);
-    create_relay_resource(resource_ptr);
+    //create_gps_resource(resource_ptr);
+    //create_relay_resource(resource_ptr);
 
         /* Register with NSP */
     endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
@@ -133,9 +122,7 @@
 
 int main()
 {
-    lcd.cls();
-    lcd.locate(0,0);
-    lcd.printf("mbed NanoService demo");
+    printf("mbed NanoService demo");
     NSDL_DEBUG("mbed NanoService Example App 0.1\n");
     
     // Initialize Ethernet interface first