mbedConnectorInterface sample endpoint utilizing 3g cellular radio as the underlying connection transport.
Dependencies: LM75B mbed mbedConnectorInterface mbedEndpointNetwork_Ublox
mbedEndpointResources/TemperatureResource.h@0:a507bbd93e47, 2015-04-28 (annotated)
- Committer:
- ansond
- Date:
- Tue Apr 28 05:04:20 2015 +0000
- Revision:
- 0:a507bbd93e47
initial checkin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:a507bbd93e47 | 1 | /** |
ansond | 0:a507bbd93e47 | 2 | * @file TemperatureResource.h |
ansond | 0:a507bbd93e47 | 3 | * @brief mbed CoAP Endpoint Temperature sensor resource supporting CoAP GET |
ansond | 0:a507bbd93e47 | 4 | * @author Doug Anson |
ansond | 0:a507bbd93e47 | 5 | * @version 1.0 |
ansond | 0:a507bbd93e47 | 6 | * @see |
ansond | 0:a507bbd93e47 | 7 | * |
ansond | 0:a507bbd93e47 | 8 | * Copyright (c) 2014 |
ansond | 0:a507bbd93e47 | 9 | * |
ansond | 0:a507bbd93e47 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:a507bbd93e47 | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:a507bbd93e47 | 12 | * You may obtain a copy of the License at |
ansond | 0:a507bbd93e47 | 13 | * |
ansond | 0:a507bbd93e47 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:a507bbd93e47 | 15 | * |
ansond | 0:a507bbd93e47 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:a507bbd93e47 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:a507bbd93e47 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:a507bbd93e47 | 19 | * See the License for the specific language governing permissions and |
ansond | 0:a507bbd93e47 | 20 | * limitations under the License. |
ansond | 0:a507bbd93e47 | 21 | */ |
ansond | 0:a507bbd93e47 | 22 | |
ansond | 0:a507bbd93e47 | 23 | #ifndef __TEMPERATURE_RESOURCE_H__ |
ansond | 0:a507bbd93e47 | 24 | #define __TEMPERATURE_RESOURCE_H__ |
ansond | 0:a507bbd93e47 | 25 | |
ansond | 0:a507bbd93e47 | 26 | // Base class |
ansond | 0:a507bbd93e47 | 27 | #include "DynamicResource.h" |
ansond | 0:a507bbd93e47 | 28 | |
ansond | 0:a507bbd93e47 | 29 | // our Temperature sensor |
ansond | 0:a507bbd93e47 | 30 | #include "LM75B.h" |
ansond | 0:a507bbd93e47 | 31 | LM75B temp_sensor(D14,D15); |
ansond | 0:a507bbd93e47 | 32 | |
ansond | 0:a507bbd93e47 | 33 | /** TemperatureResource class |
ansond | 0:a507bbd93e47 | 34 | */ |
ansond | 0:a507bbd93e47 | 35 | class TemperatureResource : public DynamicResource |
ansond | 0:a507bbd93e47 | 36 | { |
ansond | 0:a507bbd93e47 | 37 | public: |
ansond | 0:a507bbd93e47 | 38 | /** |
ansond | 0:a507bbd93e47 | 39 | Default constructor |
ansond | 0:a507bbd93e47 | 40 | @param logger input logger instance for this resource |
ansond | 0:a507bbd93e47 | 41 | @param name input the Temperature resource name |
ansond | 0:a507bbd93e47 | 42 | @param observable input the resource is Observable (default: FALSE) |
ansond | 0:a507bbd93e47 | 43 | */ |
ansond | 0:a507bbd93e47 | 44 | TemperatureResource(const Logger *logger,const char *name,const bool observable = false) : DynamicResource(logger,name,"Temperature",SN_GRS_GET_ALLOWED,observable) { |
ansond | 0:a507bbd93e47 | 45 | } |
ansond | 0:a507bbd93e47 | 46 | |
ansond | 0:a507bbd93e47 | 47 | /** |
ansond | 0:a507bbd93e47 | 48 | Get the value of the Temperature sensor |
ansond | 0:a507bbd93e47 | 49 | @returns string containing the temperature sensor value |
ansond | 0:a507bbd93e47 | 50 | */ |
ansond | 0:a507bbd93e47 | 51 | virtual string get() { |
ansond | 0:a507bbd93e47 | 52 | char temp[7]; |
ansond | 0:a507bbd93e47 | 53 | memset(temp,0,7); |
ansond | 0:a507bbd93e47 | 54 | sprintf(temp,"%3.2f", temp_sensor.temp()); |
ansond | 0:a507bbd93e47 | 55 | return string(temp); |
ansond | 0:a507bbd93e47 | 56 | } |
ansond | 0:a507bbd93e47 | 57 | }; |
ansond | 0:a507bbd93e47 | 58 | |
ansond | 0:a507bbd93e47 | 59 | #endif // __TEMPERATURE_RESOURCE_H__ |