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 07:01:56 2014 +0000
Parent:
3:4cfa5d26f35e
Child:
5:bacf25e9419b
Commit message:
battery resource created and registered with NSP

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
nsdl_run.cpp 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/battery.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jun 14 02:37:08 2014 +0000
+++ b/main.cpp	Sat Jun 14 07:01:56 2014 +0000
@@ -596,12 +596,15 @@
         compass_type = NED_COMPASS;
         init_eCompass();
         seconds = 0;
+        server_running = 1;
         nsdl_run();
     }
-    init_eCompass();
-    seconds = 0;
-    // Run TCP/IP Connection to host - Sensor Fusion App
-    runTCPIPserver();
-
+    if(temp <= 20)
+    {
+        init_eCompass();
+        seconds = 0;
+        // Run TCP/IP Connection to host - Sensor Fusion App
+        runTCPIPserver();
+    }
 }
 
--- a/nsdl_run.cpp	Sat Jun 14 02:37:08 2014 +0000
+++ b/nsdl_run.cpp	Sat Jun 14 07:01:56 2014 +0000
@@ -4,6 +4,7 @@
 #include "dbg.h"
 #include "UDPSocket.h"
 #include "Endpoint.h"
+#include "battery.h"
 
 extern Serial pc;
 
@@ -102,10 +103,7 @@
     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_temperature_resource(resource_ptr);
-//    create_light_resource(resource_ptr);
-//    create_gps_resource(resource_ptr);
-//    create_relay_resource(resource_ptr);
+    create_battery_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/battery.cpp	Sat Jun 14 07:01:56 2014 +0000
@@ -0,0 +1,38 @@
+// battery resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+
+#define BATTERY_RES_ID    "3300/0/5700"
+
+extern Serial pc;
+char battPct[5];
+extern unsigned short adc_sample3;
+
+/* Only GET method allowed */
+static uint8_t battery_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(battPct,"%d",adc_sample3);
+    pc.printf("battery callback\r\n");
+    pc.printf("battery voltage %s\r\n", battPct);
+
+    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(battPct);
+        coap_res_ptr->payload_ptr = (uint8_t*)battPct;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+
+    return 0;
+}
+
+int create_battery_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(BATTERY_RES_ID)-1, (uint8_t*)BATTERY_RES_ID, 0, 0, 0, &battery_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/battery.h	Sat Jun 14 07:01:56 2014 +0000
@@ -0,0 +1,10 @@
+// Battery resource implementation
+
+#ifndef BATTERY_H
+#define BATTERY_H
+
+#include "nsdl_support.h"
+
+int create_battery_resource(sn_nsdl_resource_info_s *resource_ptr);
+
+#endif