Demo starter application to connect WiGo to NSP and expose on-board sensors

Dependencies:   NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed nsdl_lib TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger

This is the mbed project for the IoT World Hackathon event, June 17th and 18th in Palo Also.

The setup instructions for participants are at the Setup page of this wiki:

http://mbed.org/teams/MBED_DEMOS/code/IoT_World_Hackathon_WiGo_NSP_Demo/wiki/Setup-Guide-for-the-IoT-World-Hackathon

Files at this revision

API Documentation at this revision

Comitter:
michaeljkoster
Date:
Sat Jun 14 08:00:41 2014 +0000
Parent:
4:727f1aeb717a
Child:
6:b542b2a759e8
Commit message:
Added more resources

Changed in this revision

nsdl_run.cpp Show annotated file Show diff for this revision Revisions of this file
resources/altitude.cpp Show annotated file Show diff for this revision Revisions of this file
resources/altitude.h Show annotated file Show diff for this revision Revisions of this file
resources/battery.cpp Show annotated file Show diff for this revision Revisions of this file
resources/light.cpp Show annotated file Show diff for this revision Revisions of this file
resources/light.h Show annotated file Show diff for this revision Revisions of this file
resources/temperature.cpp Show annotated file Show diff for this revision Revisions of this file
resources/temperature.h Show annotated file Show diff for this revision Revisions of this file
--- a/nsdl_run.cpp	Sat Jun 14 07:01:56 2014 +0000
+++ b/nsdl_run.cpp	Sat Jun 14 08:00:41 2014 +0000
@@ -5,6 +5,9 @@
 #include "UDPSocket.h"
 #include "Endpoint.h"
 #include "battery.h"
+#include "light.h"
+#include "temperature.h"
+#include "altitude.h"
 
 extern Serial pc;
 
@@ -28,7 +31,7 @@
 uint8_t lifetime_ptr[] = {"120000"}; //30+ hours 
 
 uint8_t myMAC[8];
-char MACstr[20];
+char MAC[20];
 
 // ****************************************************************************
 // Ethernet initialization
@@ -46,12 +49,12 @@
 //    make a unique name from the MAC address
       wifi.get_mac_address(myMAC);
       printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x \r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]);
-      sprintf(MACstr, "%02X%02X%02X%02X%02X%02X", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]);
-      pc.printf("MAC: %s", MACstr);
+      sprintf(MAC, "%02X%02X%02X%02X%02X%02X", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]);
+      pc.printf("MAC: %s", MAC);
     
 //    mbed_uid[32] = '\0';
-//    strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
-      strncat(endpoint_name, MACstr, 12);
+//    strncat(endpoint_name, mbed_uid + 27, 15 - len(endpoint_name));
+      strncat(endpoint_name, MAC, 12);
       pc.printf("EP NAME: %s\r\n",endpoint_name);
 
     NSDL_DEBUG("IP Address:%s ", wifi.getIPAddress());
@@ -103,7 +106,10 @@
     nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0,  (uint8_t*) "WiGoSystem", sizeof("WiGiSystem")-1);
 
     // Dynamic resources
-    create_battery_resource(resource_ptr);
+    create_battery_resource(resource_ptr); 
+    create_light_resource(resource_ptr); 
+    create_temp_resource(resource_ptr); 
+    create_alt_resource(resource_ptr); 
 
         /* Register with NSP */
     endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/altitude.cpp	Sat Jun 14 08:00:41 2014 +0000
@@ -0,0 +1,39 @@
+// battery resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+
+#define ALT_RES_ID    "3307/0/5700"
+
+extern Serial pc;
+extern axis6_t axis6;
+char alt[7];
+
+/* Only GET method allowed */
+static uint8_t alt_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
+{
+    sn_coap_hdr_s *coap_res_ptr = 0;
+    sprintf(alt,"%d", axis6.alt);
+    pc.printf("altitude callback\r\n");
+    pc.printf("altitude %s\r\n", alt);
+
+    if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
+    {
+        coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
+
+        coap_res_ptr->payload_len = strlen(alt);
+        coap_res_ptr->payload_ptr = (uint8_t*)alt;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+    
+    return 0;
+}
+
+int create_alt_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(ALT_RES_ID)-1, (uint8_t*)ALT_RES_ID, 0, 0, 0, &alt_resource_cb, (SN_GRS_GET_ALLOWED));
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/altitude.h	Sat Jun 14 08:00:41 2014 +0000
@@ -0,0 +1,10 @@
+// Battery resource implementation
+
+#ifndef ALTITUDE_H
+#define ALTITUDE_H
+
+#include "nsdl_support.h"
+
+int create_alt_resource(sn_nsdl_resource_info_s *resource_ptr);
+
+#endif
--- a/resources/battery.cpp	Sat Jun 14 07:01:56 2014 +0000
+++ b/resources/battery.cpp	Sat Jun 14 08:00:41 2014 +0000
@@ -15,7 +15,7 @@
     sn_coap_hdr_s *coap_res_ptr = 0;
     sprintf(battPct,"%d",adc_sample3);
     pc.printf("battery callback\r\n");
-    pc.printf("battery voltage %s\r\n", battPct);
+    pc.printf("battery percent %s\r\n", battPct);
 
     if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
     {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/light.cpp	Sat Jun 14 08:00:41 2014 +0000
@@ -0,0 +1,39 @@
+// battery resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+
+#define LIGHT_RES_ID    "3301/0/5700"
+
+extern Serial pc;
+extern axis6_t axis6;
+char lightPct[5];
+
+/* Only GET method allowed */
+static uint8_t light_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
+{
+    sn_coap_hdr_s *coap_res_ptr = 0;
+    sprintf(lightPct,"%d", (axis6.light * 100) / 4096);
+    pc.printf("light callback\r\n");
+    pc.printf("light level %s\r\n", lightPct);
+
+    if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
+    {
+        coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
+
+        coap_res_ptr->payload_len = strlen(lightPct);
+        coap_res_ptr->payload_ptr = (uint8_t*)lightPct;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+
+    return 0;
+}
+
+int create_light_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(LIGHT_RES_ID)-1, (uint8_t*)LIGHT_RES_ID, 0, 0, 0, &light_resource_cb, (SN_GRS_GET_ALLOWED));
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/light.h	Sat Jun 14 08:00:41 2014 +0000
@@ -0,0 +1,10 @@
+// Battery resource implementation
+
+#ifndef LIGHT_H
+#define LIGHT_H
+
+#include "nsdl_support.h"
+
+int create_light_resource(sn_nsdl_resource_info_s *resource_ptr);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/temperature.cpp	Sat Jun 14 08:00:41 2014 +0000
@@ -0,0 +1,39 @@
+// battery resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+
+#define TEMP_RES_ID    "3303/0/5700"
+
+extern Serial pc;
+extern axis6_t axis6;
+char temp[7];
+
+/* Only GET method allowed */
+static uint8_t temp_resource_cb(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto)
+{
+    sn_coap_hdr_s *coap_res_ptr = 0;
+    sprintf(temp,"%d", axis6.temp);
+    pc.printf("temperature callback\r\n");
+    pc.printf("temperature %s\r\n", temp);
+
+    if(received_coap_ptr->msg_code == COAP_MSG_CODE_REQUEST_GET)
+    {
+        coap_res_ptr = sn_coap_build_response(received_coap_ptr, COAP_MSG_CODE_RESPONSE_CONTENT);
+
+        coap_res_ptr->payload_len = strlen(temp);
+        coap_res_ptr->payload_ptr = (uint8_t*)temp;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+    
+    return 0;
+}
+
+int create_temp_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(TEMP_RES_ID)-1, (uint8_t*)TEMP_RES_ID, 0, 0, 0, &temp_resource_cb, (SN_GRS_GET_ALLOWED));
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resources/temperature.h	Sat Jun 14 08:00:41 2014 +0000
@@ -0,0 +1,10 @@
+// Battery resource implementation
+
+#ifndef TEMPERATURE_H
+#define TEMPERATURE_H
+
+#include "nsdl_support.h"
+
+int create_temp_resource(sn_nsdl_resource_info_s *resource_ptr);
+
+#endif