Official reference client implementation for Cumulocity SmartREST on u-blox C027.

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Temperature.cpp Source File

Temperature.cpp

00001 #include <stdio.h>
00002 #include "Temperature.h"
00003 #include "SmartRestConf.h"
00004 #include "logging.h"
00005 
00006 // Cut-off for avoiding sending similar sensor reading.
00007 #define THRESHOLD_PERCENT_TEMP 0.02
00008 // Timeout for forcing a sending even if readings are similar [seconds].
00009 #define TIME_LIMIT_TEMP 900
00010 
00011 static inline bool valueChanged(float V0, float V1)
00012 {
00013         if (abs(V0-V1) <= abs(V0)*THRESHOLD_PERCENT_TEMP)
00014                 return false;
00015         else
00016                 return true;
00017 }
00018 
00019 int Temperature::read(char *buf, size_t maxLen, char *status, size_t num)
00020 {
00021         static const char *fmt = "105,%ld,%f\r\n";
00022         if (!deviceReady)
00023                 return 0;
00024 
00025         float data = sensor.temp();
00026         float t_interval = timer.read();
00027         if (!valueChanged(oldValue, data) && t_interval < TIME_LIMIT_TEMP) {
00028                 return 0;
00029         }
00030         size_t l = snprintf(buf, maxLen, fmt, deviceID, data);
00031         if (status) {
00032                 snprintf(status, num, "Send Temp %.2f", data);
00033         }
00034         oldValue = data;
00035         timer.reset();
00036         return l;
00037 }