Proof of concept for distance and temperature monitoring

Dependencies:   mbed mbedConnectorInterface mbedEndpointNetwork

Files at this revision

API Documentation at this revision

Comitter:
coyotebush
Date:
Tue May 05 05:18:03 2015 +0000
Parent:
5:069c0a1f1080
Child:
7:939fdc8df95b
Commit message:
Add TemperatureResource

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbedEndpointResources/LightResource.h Show diff for this revision Revisions of this file
mbedEndpointResources/OnBoardLED.h Show diff for this revision Revisions of this file
resource/OnBoardLED.h Show annotated file Show diff for this revision Revisions of this file
resource/TemperatureResource.cpp Show annotated file Show diff for this revision Revisions of this file
resource/TemperatureResource.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat May 02 01:37:36 2015 +0000
+++ b/main.cpp	Tue May 05 05:18:03 2015 +0000
@@ -5,7 +5,9 @@
 
 #include "hcsr04.h"
 #include "GroveTemp.h"
+
 #include "OnBoardLED.h"
+#include "TemperatureResource.h"
 
 #include "StaticResource.h"
 
@@ -26,8 +28,8 @@
 
 /*
 DistanceResource distR(&logger, "3302/0/5600", distS);
-TemperatureResource tempR(&logger, "3303/0/5700", tempS);
 */
+TemperatureResource tempR(&logger, "3303/0/5700", &tempS, true);
 LEDResource led(&logger, "3311/1/5706");
 
 /* invoked through linker magic via Endpoint::start() */
@@ -35,10 +37,11 @@
 {
     /* NSP configuration is in nsp_configuration.h */
     logger.log("configure_endpoint: building endpoint configuration...");
+    tempR.setMaxAge(0);
     return config.addResource(&mfg)
                  .addResource(&model)
                  /* .addResource(&distR) */
-                 /* .addResource(&tempR) */
+                 .addResource(&tempR)
                  .addResource(&led)
                  .build();
 }
--- a/mbedEndpointResources/LightResource.h	Sat May 02 01:37:36 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-/**
- * @file    LightResource.h
- * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
- * @author  Doug Anson, Michael Koster
- * @version 1.0
- * @see
- *
- * Copyright (c) 2014
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LIGHT_RESOURCE_H__
-#define __LIGHT_RESOURCE_H__
-
-
-// Base class
-#include "DynamicResource.h"
-
-// our Light
-#include "ChainableLED.h"
-#define LED_COUNT 1
-
-ChainableLED led_chain(D4, D5, LED_COUNT);
-
-static char * led_value = {"0000000"}; //RRGGBBII
-
-void set_led_array(char * color_string)
-{
-    static uint8_t red, green, blue, index;
-    int color_int;
-
-    sscanf(color_string, "%X", &color_int);
-    
-    index = color_int & 255;
-    blue = color_int >> 8 & 255;
-    green = color_int >> 16 & 255;
-    red = color_int >> 24 & 255;
-        
-    if(index > 0 and index <= LED_COUNT) {
-        led_chain.setColorRGB(index-1, red, green, blue);    
-    }
-    else if(index == 0){
-        for(int i = 0; i < LED_COUNT; i++){
-            led_chain.setColorRGB(i, red, green, blue);    
-        }
-    }    
-}
-
-/** LightResource class
- */
-class LightResource : public DynamicResource
-{
-
-public:
-    /**
-    Default constructor
-    @param logger input logger instance for this resource
-    @param name input the Light resource name
-    @param observable input the resource is Observable (default: FALSE)
-    */
-    LightResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Light",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
-    set_led_array("00000000");
-    wait(0.5);
-    set_led_array("FF000000");
-    wait(0.5);
-    set_led_array("00FF0000");
-    wait(0.5);
-    set_led_array("0000FF00");
-    wait(0.5);
-    set_led_array(led_value);
-    }
-
-    /**
-    Get the value of the Light
-    @returns string containing either "0" (light off) or "1" (light on)
-    */
-    virtual string get() {
-        return(led_value);
-    }
-
-    /**
-    Set the value of the Light
-    @param string input the string containing "0" (light off) or "1" (light on)
-    */
-    virtual void put(const string value) {
-        if( sizeof(value) == sizeof(led_value) ){
-            led_value = (char *)value.c_str();
-            set_led_array(led_value);
-        }
-    }
-};
-
-#endif // __LIGHT_RESOURCE_H__
--- a/mbedEndpointResources/OnBoardLED.h	Sat May 02 01:37:36 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/**
- * @file    LightResource.h
- * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
- * @author  Doug Anson, Michael Koster
- * @version 1.0
- * @see
- *
- * Copyright (c) 2014
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LED_RESOURCE_H__
-#define __LED_RESOURCE_H__
-
-
-// Base class
-#include "DynamicResource.h"
-
-// our Light
-DigitalOut LED_red(LED1);
-DigitalOut LED_green(LED2);
-DigitalOut LED_blue(LED3);
-
-static char * LED_color_value = {"0000000"}; //RRGGBBII
-
-void LED_set_color(char * color_string)
-{
-    static uint8_t red, green, blue, index;
-    int color_int;
-
-    sscanf(color_string, "%X", &color_int);
-    
-    index = color_int & 255;
-    blue = color_int >> 8 & 255;
-    green = color_int >> 16 & 255;
-    red = color_int >> 24 & 255;
-        
-    if(index == 0) {
-        LED_red = !(red & 1);    
-        LED_green = !(green & 1);    
-        LED_blue = !(blue & 1);    
-    }
-}
-
-/** LightResource class
- */
-class LEDResource : public DynamicResource
-{
-
-public:
-    /**
-    Default constructor
-    @param logger input logger instance for this resource
-    @param name input the Light resource name
-    @param observable input the resource is Observable (default: FALSE)
-    */
-    LEDResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"OnBoardLED",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
-    LED_set_color("00000000");
-    wait(0.5);
-    LED_set_color("FF000000");
-    wait(0.5);
-    LED_set_color("00FF0000");
-    wait(0.5);
-    LED_set_color("0000FF00");
-    wait(0.5);
-    LED_set_color(LED_color_value);
-    }
-
-    /**
-    Get the value of the LED
-    @returns string containing the last setting
-    */
-    virtual string get() {
-        return(LED_color_value);
-    }
-
-    /**
-    Set the value of the LED
-    @param string input the string containing the desired setting
-    */
-    virtual void put(const string value) {
-        if( sizeof(value) == sizeof(LED_color_value) ){
-            LED_color_value = (char *)value.c_str();
-            LED_set_color(LED_color_value);
-        }
-    }
-};
-
-#endif // __LED_RESOURCE_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resource/OnBoardLED.h	Tue May 05 05:18:03 2015 +0000
@@ -0,0 +1,100 @@
+/**
+ * @file    LightResource.h
+ * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
+ * @author  Doug Anson, Michael Koster
+ * @version 1.0
+ * @see
+ *
+ * Copyright (c) 2014
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LED_RESOURCE_H__
+#define __LED_RESOURCE_H__
+
+
+// Base class
+#include "DynamicResource.h"
+
+// our Light
+DigitalOut LED_red(LED1);
+DigitalOut LED_green(LED2);
+DigitalOut LED_blue(LED3);
+
+static char * LED_color_value = {"0000000"}; //RRGGBBII
+
+void LED_set_color(char * color_string)
+{
+    static uint8_t red, green, blue, index;
+    int color_int;
+
+    sscanf(color_string, "%X", &color_int);
+    
+    index = color_int & 255;
+    blue = color_int >> 8 & 255;
+    green = color_int >> 16 & 255;
+    red = color_int >> 24 & 255;
+        
+    if(index == 0) {
+        LED_red = !(red & 1);    
+        LED_green = !(green & 1);    
+        LED_blue = !(blue & 1);    
+    }
+}
+
+/** LightResource class
+ */
+class LEDResource : public DynamicResource
+{
+
+public:
+    /**
+    Default constructor
+    @param logger input logger instance for this resource
+    @param name input the Light resource name
+    @param observable input the resource is Observable (default: FALSE)
+    */
+    LEDResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"OnBoardLED",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
+    LED_set_color("00000000");
+    wait(0.5);
+    LED_set_color("FF000000");
+    wait(0.5);
+    LED_set_color("00FF0000");
+    wait(0.5);
+    LED_set_color("0000FF00");
+    wait(0.5);
+    LED_set_color(LED_color_value);
+    }
+
+    /**
+    Get the value of the LED
+    @returns string containing the last setting
+    */
+    virtual string get() {
+        return(LED_color_value);
+    }
+
+    /**
+    Set the value of the LED
+    @param string input the string containing the desired setting
+    */
+    virtual void put(const string value) {
+        if( sizeof(value) == sizeof(LED_color_value) ){
+            LED_color_value = (char *)value.c_str();
+            LED_set_color(LED_color_value);
+        }
+    }
+};
+
+#endif // __LED_RESOURCE_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resource/TemperatureResource.cpp	Tue May 05 05:18:03 2015 +0000
@@ -0,0 +1,7 @@
+#include "TemperatureResource.h"
+
+string TemperatureResource::get() {
+    char buf[10];
+    snprintf(buf, 10, "%0.2f", sensor->getTemp());
+    return string(buf);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resource/TemperatureResource.h	Tue May 05 05:18:03 2015 +0000
@@ -0,0 +1,18 @@
+#ifndef TEMPERATURE_RESOURCE_H
+#define TEMPERATURE_RESOURCE_H
+
+#include "DynamicResource.h"
+#include "GroveTemp.h"
+
+class TemperatureResource : public DynamicResource {
+public:
+    TemperatureResource(const Logger *logger, const char *name, GroveTempSensor *sensor, const bool observable = false)
+     : DynamicResource(logger, name, "TemperatureResource", SN_GRS_GET_ALLOWED, observable), sensor(sensor)
+    {}
+    
+    virtual string get();
+private:
+    GroveTempSensor *sensor;
+};
+
+#endif
\ No newline at end of file