Red Hat Summit NanoService Demo for LPC1768 App Board using OMA Lightweight Objects

Dependencies:   Beep C12832_lcd EthernetInterface LM75B MMA7660 mbed-rtos mbed nsdl_lib

Fork of LWM2M_NanoService_Ethernet by MBED_DEMOS

Revision:
13:b52d83adc1ab
Parent:
12:b695198175ee
Child:
14:5acd59fec679
diff -r b695198175ee -r b52d83adc1ab main.cpp
--- a/main.cpp	Fri Mar 21 06:46:10 2014 +0000
+++ b/main.cpp	Wed Mar 26 22:16:52 2014 +0000
@@ -29,8 +29,14 @@
 static const char* NSP_ADDRESS = "137.135.13.28"; /* demo NSP, web interface at http://red-hat-summit.cloudapp.net*/ 
 static const int NSP_PORT = 5683;
 char endpoint_name[20] = "mbed-ethernet-";
+char mbed_uid[33]; // for creating unique name for the board
 uint8_t ep_type[] = {"mbed_lpc1768_appboard"};
 uint8_t lifetime_ptr[] = {"60"};
+static const char* FIRMWARE_VER = "0.91"; // Used in static resource
+char* mac;
+char* ipAddr;
+char* gateway;
+char* nmask;
 
 // ****************************************************************************
 // Ethernet initialization
@@ -39,23 +45,22 @@
 
 static void ethernet_init()
 {
-    char mbed_uid[33]; // for creating unique name for the board
 
     /* Initialize network */
 #ifdef DHCP
-    NSDL_DEBUG("DHCP in use\r\n");
+    NSDL_DEBUG("DHCP in use");
     eth.init();
 #else
     eth.init(IP, MASK, GW);
 #endif
     if(eth.connect(30000) == 0)
-        pc.printf("Connect OK\n\r");
+        NSDL_DEBUG("Ethernet up");
 
-    char* mac = eth.getMACAddress();
-    char* ipAddr = eth.getIPAddress();
-    char* gateway = eth.getGateway();
-    char* nmask = eth.getNetworkMask();
-    printf("mac=%s, ip=%s, gateway=%s, mask=%s\n", mac, ipAddr, gateway, nmask);
+    mac = eth.getMACAddress();
+    ipAddr = eth.getIPAddress();
+    gateway = eth.getGateway();
+    nmask = eth.getNetworkMask();
+    NSDL_DEBUG("Network: mac=%s, ip=%s, gateway=%s, mask=%s", mac, ipAddr, gateway, nmask);
 
     mbed_interface_uid(mbed_uid);
     mbed_uid[32] = '\0';
@@ -64,7 +69,6 @@
     lcd.locate(0,11);
     lcd.printf("IP:%s", eth.getIPAddress());
 
-    NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
 }
 
 // ****************************************************************************
@@ -114,7 +118,13 @@
     // Static resources
     nsdl_create_static_resource(resource_ptr, sizeof("3/0/0")-1, (uint8_t*) "3/0/0", 0, 0,  (uint8_t*) "ARM", sizeof("ARM")-1);
     nsdl_create_static_resource(resource_ptr, sizeof("3/0/1")-1, (uint8_t*) "3/0/1", 0, 0,  (uint8_t*) "LPC1768 App Board", sizeof("LPC1768 App Board")-1);
-    nsdl_create_static_resource(resource_ptr, sizeof("3/0/16")-1, (uint8_t*) "3/0/16", 0, 0,  (uint8_t*) "U", sizeof("U")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("3/0/2")-1, (uint8_t*) "3/0/2", 0, 0,  (uint8_t*) mbed_uid, sizeof(mbed_uid)-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("3/0/3")-1, (uint8_t*) "3/0/3", 0, 0,  (uint8_t*) FIRMWARE_VER, sizeof(FIRMWARE_VER));
+    nsdl_create_static_resource(resource_ptr, sizeof("4/0/0")-1, (uint8_t*) "4/0/0", 0, 0,  (uint8_t*) "Ethernet", sizeof("Ethernet")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("4/0/1")-1, (uint8_t*) "4/0/1", 0, 0,  (uint8_t*) "Ethernet", sizeof("Ethernet")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("4/0/4")-1, (uint8_t*) "4/0/4", 0, 0,  (uint8_t*) ipAddr, 15);
+    nsdl_create_static_resource(resource_ptr, sizeof("4/0/5")-1, (uint8_t*) "4/0/5", 0, 0,  (uint8_t*) gateway, 15);
+    nsdl_create_static_resource(resource_ptr, sizeof("3/0/16")-1, (uint8_t*) "3/0/16", 0, 0,  (uint8_t*) "UDP", sizeof("UDP")-1);
 
     // Dynamic resources
     create_temperature_resource(resource_ptr);
@@ -142,7 +152,7 @@
 {
     lcd.cls();
     lcd.locate(0,0);
-    lcd.printf("NanoService LWM2M");
+    lcd.printf("NanoService LWM2M %s", FIRMWARE_VER);
     NSDL_DEBUG("NanoService LWM2M Demo for LPC1768 App Board\n");
     
     // Initialize Ethernet interface first