Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: measurement/Temperature.cpp
- Revision:
- 101:dbcd3bc51758
- Child:
- 118:e831cdb799ab
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/measurement/Temperature.cpp Fri May 08 12:19:57 2015 +0000
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include "Temperature.h"
+#include "SmartRestConf.h"
+#include "logging.h"
+
+// Cut-off for avoiding sending similar sensor reading.
+#define THRESHOLD_PERCENT_TEMP 0.02
+// Timeout for forcing a sending even if readings are similar [seconds].
+#define TIME_LIMIT_TEMP 900
+
+size_t Temperature::read(char *buf, size_t maxLen, char *status, size_t num)
+{
+ static const char *fmt = "105,%ld,%f\r\n";
+ if (!deviceReady)
+ return 0;
+
+ float data = sensor.temp();
+ if (abs(oldValue-data) <= abs(oldValue)*THRESHOLD_PERCENT_TEMP) {
+ time_t t_interval = time(NULL) - t_start;
+ if (t_interval < TIME_LIMIT_TEMP) {
+ return 0;
+ } else {
+ aDebug("Temp: Timeout at %d s.\n", t_interval);
+ }
+ }
+ size_t l = snprintf(buf, maxLen, fmt, deviceID, data);
+ if (status) {
+ snprintf(status, num, "Send Temp %.2f", data);
+ }
+ oldValue = data;
+ t_start = time(NULL);
+ return l;
+}
\ No newline at end of file

Cumulocity