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: EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue
Diff: main.cpp
- Revision:
- 4:0bab12a0cc9a
- Parent:
- 3:71b090ec5c69
- Child:
- 5:ffef0c7a70a1
- Child:
- 6:92ddc620a78f
--- a/main.cpp Mon Dec 15 00:19:48 2014 +0000
+++ b/main.cpp Mon Dec 15 12:50:26 2014 +0000
@@ -51,10 +51,15 @@
pc.printf("[MAIN] Got sensor data...\r\n");
snail::sensordata& d = static_cast<snail::sensordata&>(message);
-// MbedJSONValue j;
-// j["timestamp"] = (int)time(NULL);
-// j["value"] = value;
-// pc.printf(h.post("178.62.84.55", 8888, "/field/testfield/testnode/testsensor/", j.serialize()).c_str());
+ int value = 0;
+ value += d.payload[0];
+ value = value << 8;
+ value += d.payload[1];
+
+ MbedJSONValue j;
+ j["timestamp"] = (int)time(NULL);
+ j["value"] = value;
+ pc.printf(h.post("178.62.84.55", 8888, "/field/testfield/testnode/testsensor/", j.serialize()).c_str());
}
void handleNetworkParametersTimeout()
@@ -202,7 +207,7 @@
//TODO: if xbee interrupt has woken us up
//transmit 10 latest readings
- //check if it's time to poll TODO: add check to see if sensorinterface is ready
+ //check if it's time to poll
if (time(NULL) - lastPollTime > pollInterval)
{
#ifdef DEBUG
@@ -222,10 +227,20 @@
d_reply data = sensors.readData();
#ifdef DEBUG
+ pc.printf("[MAIN] Got data: ");
for (int i = 0; i < data.readings.size(); i++)
pc.printf("0x%.2X|", data.readings[i]);
+ pc.printf("\r\n");
#endif
+ string readings_str(data.readings.begin(), data.readings.end());
+ char readings[sizeof(snail::sensordata().payload)];
+ memcpy(readings, readings_str.c_str(), sizeof(readings));
+
+ snail::sensordata message(baseNodeAddress, data.type, data.type, time(NULL), readings, data.readings.size());
+
+ xbee.send(message, sizeof(message));
+
//log
//sd.write(static_cast<long int>(time(NULL)), data);
}
