mbed Ethernet-based CoAP heartrate endpoint for Dreamforce 2015

Dependencies:   GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Sun Sep 06 22:11:18 2015 +0000
Parent:
6:8a1cd40faf30
Commit message:
updates and fixes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/HeartrateResource.h Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/LocationResource.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Sep 06 03:26:21 2015 +0000
+++ b/main.cpp	Sun Sep 06 22:11:18 2015 +0000
@@ -44,7 +44,7 @@
 LightResource light(&logger,"311/0/5850");
 
 // My Endpoint Name
-#define MY_ENDPOINT_NAME                        "mbed-eth-hrm-XX"       // replace "XX" with your number
+#define MY_ENDPOINT_NAME                        "mbed-eth-hrm-X"       // replace "XX" with your number
 
 // My NSP Domain
 #define MY_NSP_DOMAIN                           "dfbridgeXX"            // replace "XX" with your number
@@ -75,8 +75,8 @@
                  
                  // add the heartrate resource
                  .addResource(&light)
-                 .addResource(&hr,7100)             // observe every 7.1 seconds            
-                 .addResource(&location,45000)      // observe every 45 seconds (its currently static...)
+                 .addResource(&hr,4765)             // observe every 4.765 seconds           
+                 .addResource(&location,11316)      // observe every 11.316 seconds (its currently static...)
                                       
                  // finalize the configuration...
                  .build();
--- a/mbed.bld	Sun Sep 06 03:26:21 2015 +0000
+++ b/mbed.bld	Sun Sep 06 22:11:18 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file
--- a/mbedEndpointResources/HeartrateResource.h	Sun Sep 06 03:26:21 2015 +0000
+++ b/mbedEndpointResources/HeartrateResource.h	Sun Sep 06 22:11:18 2015 +0000
@@ -42,11 +42,11 @@
 
 // Grove Earbud Sensor
 #include "GroveEarbudSensor.h"
-//extern RawSerial pc;                                    // declared in main.cpp for logger... just reference here...     
+extern RawSerial pc;                                    // declared in main.cpp for logger... just reference here...     
 GroveEarbudSensor __earbud(ENDPOINT_INTERRUPT_PIN,&pc);
 
 // HRM sensor value
-static char __hrm[10] = {0};
+static char __hrm[10];
 
 // forward declaration
 extern void __hrm_callback(float value,void *instance);
@@ -64,12 +64,12 @@
     @param observable input the resource is Observable (default: FALSE)
     */
     HeartrateResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Heartrate",SN_GRS_GET_ALLOWED,observable) {
-        // finish setup of the earbud sensor
-        __earbud.registerCallback(&__hrm_callback,this);
+        // init... 
+        memset(__hrm,0,10);
+        sprintf(__hrm,"0.0");
         
-        // this resource implements its own observation handler...
-        // Wont used this in K64F - use Threaded time observation instead
-        // this->m_implements_observation = true;
+        // finish setup of the earbud sensor
+        __earbud.registerCallback(&__hrm_callback,this);        
     }
 
     /**
@@ -85,14 +85,6 @@
 void __hrm_callback(float heartrate,void *data) {
     memset(__hrm,0,10);
     sprintf(__hrm,"%.1f",heartrate);
-    
-    // observation handler implementation
-    if (data != NULL) {
-        HeartrateResource *res = (HeartrateResource *)data;
-        if (res->isObservable() && res->implementsObservation() == true) {
-            res->observe();
-        }
-    }
 }
 
 #endif // __HEARTRATE_RESOURCE_H__
\ No newline at end of file
--- a/mbedEndpointResources/LocationResource.h	Sun Sep 06 03:26:21 2015 +0000
+++ b/mbedEndpointResources/LocationResource.h	Sun Sep 06 22:11:18 2015 +0000
@@ -25,7 +25,6 @@
 
 // Base class
 #include "DynamicResource.h"
-extern RawSerial pc;               // main.cpp
 
 // We have a static location by default - Moscone West - 37.783879,-122.4012538
 #define MY_LATITUDE     37.783879
@@ -35,6 +34,7 @@
 
 // Maximum Location JSON Length : {"latitude":XXX.YYYYYY, "longitude":XXX.YYYYYY, "msl":XXXXXX, "speed":XXXXXX}
 #define LOCATION_JSON_LENGTH  256
+char __location_json[LOCATION_JSON_LENGTH+1];
 
 /** LocationResource class
  */
@@ -48,6 +48,7 @@
     @param observable input the resource is Observable (default: FALSE)
     */
     LocationResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Location",SN_GRS_GET_ALLOWED,observable) {
+        memset(__location_json,0,LOCATION_JSON_LENGTH+1);
     }
 
     /**
@@ -55,14 +56,13 @@
     @returns string containing the location value
     */
     virtual string get() {
-        char json[LOCATION_JSON_LENGTH+1];
-        memset(json,0,LOCATION_JSON_LENGTH+1);
-        sprintf(json,"{\"latitude\":%.6f,\"longitude\":%.6f,\"msl\":%.1f,\"speed\":%.1f}",
+        memset(__location_json,0,LOCATION_JSON_LENGTH);
+        sprintf(__location_json,"{\"latitude\":%.6f,\"longitude\":%.6f,\"msl\":%.1f,\"speed\":%.1f}",
                     MY_LATITUDE,
                     MY_LONGITUDE,
                     MY_ALTITUDE,        // in meters
                     MY_SPEED);          // in meters/second
-        return string(json);
+        return string(__location_json);
     }
 };