TrailTraffic

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of IoT_LED_demo by MBED_DEMOS

Revision:
1:b96a11b680dc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedEndpointResources/Temp.h	Fri May 22 00:39:20 2015 +0000
@@ -0,0 +1,65 @@
+/**
+ * @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 __TEMP_RESOURCE_H__
+#define __TEMP_RESOURCE_H__
+
+
+// Base class
+#include "DynamicResource.h"
+#include "mbed.h"
+
+
+AnalogIn sensorTemp(A0);
+
+
+/** LightResource class
+ */
+class TempResource : 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)
+    */
+    TempResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Temp",SN_GRS_GET_ALLOWED,observable) {
+    }
+
+    /**
+    Get the value of the LED
+    @returns string containing the last setting
+    */
+    virtual string get() {
+        int B=3975;
+        float a = sensorTemp * 1000;
+        float resistance = (float) (1023-a) * 10000/a; //get the resistance of the sensor;
+        float temperature= 1.0f / (logf(resistance/10000)/B + 1/298.15) - 273.15;//convert to temperature via datasheet ;
+        char result[8];
+        sprintf(result, "%f", temperature);
+        return(result);
+    };
+};
+
+#endif // __TEMP_RESOURCE_H__