Christopher Wu / Mbed 2 deprecated Trail

Dependencies:   Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork

Fork of IoT_LED_demo by MBED_DEMOS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Temp.h Source File

Temp.h

00001 /**
00002  * @file    LightResource.h
00003  * @brief   mbed CoAP Endpoint Light resource supporting CoAP GET and PUT
00004  * @author  Doug Anson, Michael Koster
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022 
00023 #ifndef __TEMP_RESOURCE_H__
00024 #define __TEMP_RESOURCE_H__
00025 
00026 
00027 // Base class
00028 #include "DynamicResource.h"
00029 #include "mbed.h"
00030 
00031 
00032 AnalogIn sensorTemp(A0);
00033 
00034 
00035 /** LightResource class
00036  */
00037 class TempResource : public DynamicResource
00038 {
00039 
00040 public:
00041     /**
00042     Default constructor
00043     @param logger input logger instance for this resource
00044     @param name input the Light resource name
00045     @param observable input the resource is Observable (default: FALSE)
00046     */
00047     TempResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Temp",SN_GRS_GET_ALLOWED,observable) {
00048     }
00049 
00050     /**
00051     Get the value of the LED
00052     @returns string containing the last setting
00053     */
00054     virtual string get() {
00055         int B=3975;
00056         float a = sensorTemp * 1000;
00057         float resistance = (float) (1023-a) * 10000/a; //get the resistance of the sensor;
00058         float temperature= 1.0f / (logf(resistance/10000)/B + 1/298.15) - 273.15;//convert to temperature via datasheet ;
00059         char result[8];
00060         sprintf(result, "%f", temperature);
00061         return(result);
00062     };
00063 };
00064 
00065 #endif // __TEMP_RESOURCE_H__