Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Wed May 20 09:57:55 2015 +0000
Revision:
117:e831cdb799ab
Parent:
100:dbcd3bc51758
Child:
123:311fa85af2b3
remove useless debug for measurement timeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xinlei 100:dbcd3bc51758 1 #include <stdio.h>
xinlei 100:dbcd3bc51758 2 #include "Temperature.h"
xinlei 100:dbcd3bc51758 3 #include "SmartRestConf.h"
xinlei 100:dbcd3bc51758 4 #include "logging.h"
xinlei 100:dbcd3bc51758 5
xinlei 100:dbcd3bc51758 6 // Cut-off for avoiding sending similar sensor reading.
xinlei 100:dbcd3bc51758 7 #define THRESHOLD_PERCENT_TEMP 0.02
xinlei 100:dbcd3bc51758 8 // Timeout for forcing a sending even if readings are similar [seconds].
xinlei 100:dbcd3bc51758 9 #define TIME_LIMIT_TEMP 900
xinlei 100:dbcd3bc51758 10
xinlei 100:dbcd3bc51758 11 size_t Temperature::read(char *buf, size_t maxLen, char *status, size_t num)
xinlei 100:dbcd3bc51758 12 {
xinlei 100:dbcd3bc51758 13 static const char *fmt = "105,%ld,%f\r\n";
xinlei 100:dbcd3bc51758 14 if (!deviceReady)
xinlei 100:dbcd3bc51758 15 return 0;
xinlei 100:dbcd3bc51758 16
xinlei 100:dbcd3bc51758 17 float data = sensor.temp();
xinlei 100:dbcd3bc51758 18 if (abs(oldValue-data) <= abs(oldValue)*THRESHOLD_PERCENT_TEMP) {
xinlei 100:dbcd3bc51758 19 time_t t_interval = time(NULL) - t_start;
xinlei 100:dbcd3bc51758 20 if (t_interval < TIME_LIMIT_TEMP) {
xinlei 100:dbcd3bc51758 21 return 0;
xinlei 100:dbcd3bc51758 22 }
xinlei 100:dbcd3bc51758 23 }
xinlei 100:dbcd3bc51758 24 size_t l = snprintf(buf, maxLen, fmt, deviceID, data);
xinlei 100:dbcd3bc51758 25 if (status) {
xinlei 100:dbcd3bc51758 26 snprintf(status, num, "Send Temp %.2f", data);
xinlei 100:dbcd3bc51758 27 }
xinlei 100:dbcd3bc51758 28 oldValue = data;
xinlei 100:dbcd3bc51758 29 t_start = time(NULL);
xinlei 100:dbcd3bc51758 30 return l;
xinlei 100:dbcd3bc51758 31 }