TrailTraffic

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of IoT_LED_demo by MBED_DEMOS

Committer:
cjwu15
Date:
Fri May 22 00:39:20 2015 +0000
Revision:
1:b96a11b680dc
Share;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cjwu15 1:b96a11b680dc 1 /**
cjwu15 1:b96a11b680dc 2 * @file LightResource.h
cjwu15 1:b96a11b680dc 3 * @brief mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
cjwu15 1:b96a11b680dc 4 * @author Doug Anson, Michael Koster
cjwu15 1:b96a11b680dc 5 * @version 1.0
cjwu15 1:b96a11b680dc 6 * @see
cjwu15 1:b96a11b680dc 7 *
cjwu15 1:b96a11b680dc 8 * Copyright (c) 2014
cjwu15 1:b96a11b680dc 9 *
cjwu15 1:b96a11b680dc 10 * Licensed under the Apache License, Version 2.0 (the "License");
cjwu15 1:b96a11b680dc 11 * you may not use this file except in compliance with the License.
cjwu15 1:b96a11b680dc 12 * You may obtain a copy of the License at
cjwu15 1:b96a11b680dc 13 *
cjwu15 1:b96a11b680dc 14 * http://www.apache.org/licenses/LICENSE-2.0
cjwu15 1:b96a11b680dc 15 *
cjwu15 1:b96a11b680dc 16 * Unless required by applicable law or agreed to in writing, software
cjwu15 1:b96a11b680dc 17 * distributed under the License is distributed on an "AS IS" BASIS,
cjwu15 1:b96a11b680dc 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cjwu15 1:b96a11b680dc 19 * See the License for the specific language governing permissions and
cjwu15 1:b96a11b680dc 20 * limitations under the License.
cjwu15 1:b96a11b680dc 21 */
cjwu15 1:b96a11b680dc 22
cjwu15 1:b96a11b680dc 23 #ifndef __TEMP_RESOURCE_H__
cjwu15 1:b96a11b680dc 24 #define __TEMP_RESOURCE_H__
cjwu15 1:b96a11b680dc 25
cjwu15 1:b96a11b680dc 26
cjwu15 1:b96a11b680dc 27 // Base class
cjwu15 1:b96a11b680dc 28 #include "DynamicResource.h"
cjwu15 1:b96a11b680dc 29 #include "mbed.h"
cjwu15 1:b96a11b680dc 30
cjwu15 1:b96a11b680dc 31
cjwu15 1:b96a11b680dc 32 AnalogIn sensorTemp(A0);
cjwu15 1:b96a11b680dc 33
cjwu15 1:b96a11b680dc 34
cjwu15 1:b96a11b680dc 35 /** LightResource class
cjwu15 1:b96a11b680dc 36 */
cjwu15 1:b96a11b680dc 37 class TempResource : public DynamicResource
cjwu15 1:b96a11b680dc 38 {
cjwu15 1:b96a11b680dc 39
cjwu15 1:b96a11b680dc 40 public:
cjwu15 1:b96a11b680dc 41 /**
cjwu15 1:b96a11b680dc 42 Default constructor
cjwu15 1:b96a11b680dc 43 @param logger input logger instance for this resource
cjwu15 1:b96a11b680dc 44 @param name input the Light resource name
cjwu15 1:b96a11b680dc 45 @param observable input the resource is Observable (default: FALSE)
cjwu15 1:b96a11b680dc 46 */
cjwu15 1:b96a11b680dc 47 TempResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Temp",SN_GRS_GET_ALLOWED,observable) {
cjwu15 1:b96a11b680dc 48 }
cjwu15 1:b96a11b680dc 49
cjwu15 1:b96a11b680dc 50 /**
cjwu15 1:b96a11b680dc 51 Get the value of the LED
cjwu15 1:b96a11b680dc 52 @returns string containing the last setting
cjwu15 1:b96a11b680dc 53 */
cjwu15 1:b96a11b680dc 54 virtual string get() {
cjwu15 1:b96a11b680dc 55 int B=3975;
cjwu15 1:b96a11b680dc 56 float a = sensorTemp * 1000;
cjwu15 1:b96a11b680dc 57 float resistance = (float) (1023-a) * 10000/a; //get the resistance of the sensor;
cjwu15 1:b96a11b680dc 58 float temperature= 1.0f / (logf(resistance/10000)/B + 1/298.15) - 273.15;//convert to temperature via datasheet ;
cjwu15 1:b96a11b680dc 59 char result[8];
cjwu15 1:b96a11b680dc 60 sprintf(result, "%f", temperature);
cjwu15 1:b96a11b680dc 61 return(result);
cjwu15 1:b96a11b680dc 62 };
cjwu15 1:b96a11b680dc 63 };
cjwu15 1:b96a11b680dc 64
cjwu15 1:b96a11b680dc 65 #endif // __TEMP_RESOURCE_H__