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
measurement/Temperature.cpp
- Committer:
- xinlei
- Date:
- 2015-05-20
- Revision:
- 118:e831cdb799ab
- Parent:
- 101:dbcd3bc51758
- Child:
- 124:311fa85af2b3
File content as of revision 118:e831cdb799ab:
#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;
}
}
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;
}

Cumulocity