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:
Sun Jun 15 06:31:21 2014 +0000
Parent:
8:3926a80af3e0
Child:
10:948f99b285c4
Commit message:
Accelerometer object with 3 resources

Changed in this revision

nsdl_run.cpp Show annotated file Show diff for this revision Revisions of this file
resources/accelerometer.cpp Show annotated file Show diff for this revision Revisions of this file
resources/accelerometer.h 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/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/slider.cpp Show annotated file Show diff for this revision Revisions of this file
resources/slider.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	Sun Jun 15 02:00:39 2014 +0000
+++ b/nsdl_run.cpp	Sun Jun 15 06:31:21 2014 +0000
@@ -9,6 +9,7 @@
 #include "temperature.h"
 #include "altitude.h"
 #include "slider.h"
+#include "accelerometer.h"
 
 extern Serial pc;
 
@@ -24,8 +25,8 @@
 
 // NSP configuration
 /* Change this IP address to that of your NanoService Platform installation */
-//static const char* NSP_ADDRESS = "192.168.1.220"; /* Arndale board running NSP on local network for Hackathon */ 
-static const char* NSP_ADDRESS = "217.140.101.20"; /* public mbed demo server */ 
+static const char* NSP_ADDRESS = "192.168.1.220"; /* Arndale board running NSP on local network for Hackathon */ 
+//static const char* NSP_ADDRESS = "217.140.101.20"; /* public mbed demo server */ 
 static const int NSP_PORT = 5683;
 char endpoint_name[24] = "mbed-";
 uint8_t ep_type[] = {"mbed_device"};
@@ -112,6 +113,7 @@
     create_temp_resource(resource_ptr); 
     create_alt_resource(resource_ptr); 
     create_slider_resource(resource_ptr); 
+    create_accel_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/accelerometer.cpp	Sun Jun 15 06:31:21 2014 +0000
@@ -0,0 +1,88 @@
+// accelerometer resource implementation
+
+#include "mbed.h"
+#include "nsdl_support.h"
+#include "Wi-Go_eCompass_Lib_V3.h"
+
+#define ACCEL_X_RES_ID    "3313/0/0"
+#define ACCEL_Y_RES_ID    "3313/0/1"
+#define ACCEL_Z_RES_ID    "3313/0/2"
+
+extern Serial pc;
+extern axis6_t axis6;
+char x[7];
+char y[7];
+char z[7];
+
+/* Only GET method allowed */
+
+static uint8_t accel_x_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(x,"%1.2f", axis6.fGax);
+    pc.printf("accel x callback\r\n");
+    pc.printf("accel x %s\r\n", x);
+
+    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(x);
+        coap_res_ptr->payload_ptr = (uint8_t*)x;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+    
+    return 0;
+}
+
+static uint8_t accel_y_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(y,"%1.2f", axis6.fGay);
+    pc.printf("accel y callback\r\n");
+    pc.printf("accel y %s\r\n", y);
+
+    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(y);
+        coap_res_ptr->payload_ptr = (uint8_t*)y;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+    
+    return 0;
+}
+
+static uint8_t accel_z_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(z,"%1.2f", axis6.fGaz);
+    pc.printf("accel z callback\r\n");
+    pc.printf("accel z %s\r\n", z);
+
+    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(z);
+        coap_res_ptr->payload_ptr = (uint8_t*)z;
+        sn_nsdl_send_coap_message(address, coap_res_ptr);
+    }
+
+    sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
+    
+    return 0;
+}
+
+int create_accel_resource(sn_nsdl_resource_info_s *resource_ptr)
+{
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(ACCEL_X_RES_ID)-1, (uint8_t*)ACCEL_X_RES_ID, 0, 0, 0, &accel_x_resource_cb, (SN_GRS_GET_ALLOWED));
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(ACCEL_Y_RES_ID)-1, (uint8_t*)ACCEL_Y_RES_ID, 0, 0, 0, &accel_y_resource_cb, (SN_GRS_GET_ALLOWED));
+    nsdl_create_dynamic_resource(resource_ptr, sizeof(ACCEL_Z_RES_ID)-1, (uint8_t*)ACCEL_Z_RES_ID, 0, 0, 0, &accel_z_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/accelerometer.h	Sun Jun 15 06:31:21 2014 +0000
@@ -0,0 +1,10 @@
+// Accelerometer resource implementation
+
+#ifndef ACCELEROMETER_H
+#define ACCELEROMETER_H
+
+#include "nsdl_support.h"
+
+int create_accel_resource(sn_nsdl_resource_info_s *resource_ptr);
+
+#endif
--- a/resources/altitude.cpp	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/altitude.cpp	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// battery resource implementation
+// altitude sensor resource implementation
 
 #include "mbed.h"
 #include "nsdl_support.h"
--- a/resources/altitude.h	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/altitude.h	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// Battery resource implementation
+// Altimeter resource implementation
 
 #ifndef ALTITUDE_H
 #define ALTITUDE_H
--- a/resources/light.cpp	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/light.cpp	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// battery resource implementation
+// luminosity resource implementation
 
 #include "mbed.h"
 #include "nsdl_support.h"
--- a/resources/light.h	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/light.h	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// Battery resource implementation
+// Luminosity resource implementation
 
 #ifndef LIGHT_H
 #define LIGHT_H
--- a/resources/slider.cpp	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/slider.cpp	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// battery resource implementation
+// slide selector resource implementation
 
 #include "mbed.h"
 #include "nsdl_support.h"
--- a/resources/slider.h	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/slider.h	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// Battery resource implementation
+// slide selector resource implementation
 
 #ifndef SLIDER_H
 #define SLIDER_H
--- a/resources/temperature.cpp	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/temperature.cpp	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// battery resource implementation
+// temperature resource implementation
 
 #include "mbed.h"
 #include "nsdl_support.h"
--- a/resources/temperature.h	Sun Jun 15 02:00:39 2014 +0000
+++ b/resources/temperature.h	Sun Jun 15 06:31:21 2014 +0000
@@ -1,4 +1,4 @@
-// Battery resource implementation
+// Temperature resource implementation
 
 #ifndef TEMPERATURE_H
 #define TEMPERATURE_H