Michael Koster / Mbed 2 deprecated ipso_interop_mbed1

Dependencies:   Chainable_RGB_LED DHT LED_Bar mbed mbedConnectorInterface mbedEndpointNetwork_mjk_regfix

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TempResource.h Source File

TempResource.h

Go to the documentation of this file.
00001 /**
00002  * @file    TempResource.h
00003  * @brief   mbed CoAP Endpoint
00004  * @author  Michael Koster
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2015
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 // Base class
00027 #include "DynamicResource.h"
00028 
00029 // Temp Sensor connected to A0
00030 AnalogIn temp_in(A0);
00031 
00032 /** TempResource class
00033  */
00034 class TempResource : public DynamicResource
00035 {
00036 public:
00037     /**
00038     Default constructor
00039     @param logger input logger instance for this resource
00040     @param name input the resource name
00041     @param observable input the resource is Observable (default: FALSE)
00042     */
00043     TempResource(const Logger *logger,const char *name,const bool observable = false) : 
00044         DynamicResource(logger,name,"Temperature", SN_GRS_GET_ALLOWED,observable) {
00045     }
00046 
00047     /**
00048     Get the value of the Temperature Sensor
00049     @returns string containing the temperature value in Fahrenheit
00050     */
00051     virtual string get() {
00052         char temp_str[8];
00053         int B = 3975;
00054         memset(temp_str,0,8);
00055         float temp_read = temp_in.read();
00056         float resistance = (1-temp_read) * 10000/temp_read; //get the resistance of the sensor;
00057         float temp_c = 1/ ( logf(resistance/10000)/B + 1/298.15) -273.15;//convert to temperature via datasheet ;
00058         float temp_f = (1.8 * (double) temp_c) + 32;
00059         sprintf(temp_str,"%8.2f", temp_f);
00060         return string(temp_str);
00061     }
00062 };
00063 
00064 #endif // __TEMP_RESOURCE_H__