GDP group 24 node core
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue
Revision 23:b57a47c7862a, committed 2015-01-27
- Comitter:
- jakehodges
- Date:
- Tue Jan 27 22:20:46 2015 +0000
- Parent:
- 22:835a6c6dcfbb
- Child:
- 25:fe273397ebb2
- Commit message:
- Update JSON message to server to include int array. Update sensordata message to reflect changes in SNAIL. Fix SD card location string. Fix I2C id conflict.
Changed in this revision
--- a/http.cpp Tue Jan 13 23:53:24 2015 +0000
+++ b/http.cpp Tue Jan 27 22:20:46 2015 +0000
@@ -133,7 +133,6 @@
string http::parse(string httpReply)
{
int payloadBegin = httpReply.find("\r\n\r\n");
-
if (payloadBegin > -1)
{
string payload(httpReply.begin() + payloadBegin + 4, httpReply.end());
--- a/main.cpp Tue Jan 13 23:53:24 2015 +0000
+++ b/main.cpp Tue Jan 27 22:20:46 2015 +0000
@@ -12,7 +12,7 @@
time_t pollInterval = 30;
-bool isBasenode = true;
+bool isBasenode = false;
string fieldID = "testfield";
http h = http();
@@ -88,17 +88,14 @@
pc.printf("[MAIN] Got sensor data...\r\n");
snail::sensordata& d = static_cast<snail::sensordata&>(message);
- int value = 0;
- value += d.payload[0];
- value = value << 8;
- value += d.payload[1];
-
char sensorID[3];
sprintf(sensorID, "%i", d.i2cAddress);
MbedJSONValue j;
j["timestamp"] = (int)time(NULL);
- j["value"] = value;
+
+ for (int i = 0; i < d.payloadSize; i++)
+ j["value"][i] = d.payload[i];
#ifdef DEBUG
pc.printf( ("[MAIN] POSTing sensor reading: " + j.serialize() + "\r\n").c_str() );
@@ -164,7 +161,7 @@
while (cs != sif->sensors.end() && i < 32)
{
localSensors[i].type = cs->second.type;
- localSensors[i].id = cs->first;
+ localSensors[i].id = cs->second.type;
i++;
cs++;
}
@@ -226,7 +223,7 @@
pc.printf("\r\n");
pc.printf("\r\n");
#endif
- //sdcard sd = sdcard();
+ sdcard sd = sdcard();
//TODO: read basenode pin
#ifdef DEBUG
@@ -310,17 +307,17 @@
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));
+ int readings[16];
+ for (int i = 0; i < data.readings.size(); i++)
+ readings[i] = data.readings[i];
//TODO: Get real I2C address
- snail::sensordata message(baseNodeAddress, data.type, data.type, time(NULL), readings, readings_str.size());
+ snail::sensordata message(baseNodeAddress, data.type, data.type, time(NULL), readings, data.readings.size());
messageQueue.push(message);
//log
- //sd.write(static_cast<long int>(time(NULL)), data);
+ sd.write(static_cast<long int>(time(NULL)), data);
}
}
}
--- a/sdcard.cpp Tue Jan 13 23:53:24 2015 +0000
+++ b/sdcard.cpp Tue Jan 27 22:20:46 2015 +0000
@@ -16,8 +16,12 @@
string sd_name = "/sd/";
string sd_location ="";
char time_s[64];
-
- sd_location = sd_name + data.type;
+
+ char buffer[20];
+ sprintf(buffer, "%i", data.type);
+ string dataTypeStr = string(buffer);
+
+ sd_location = sd_name + dataTypeStr;
mkdir(sd_location.c_str(), 0777);
sprintf(time_s, "%d", time);
@@ -27,13 +31,13 @@
if (fp == NULL)
{
- printf("File pointer null, failed to open file\r\n");
+ printf("[SD] File pointer null, failed to open file\r\n");
}
string serializedData;
for (int i = 0; i < data.readings.size(); i++)
- fprintf(fp, "%i", data.readings[i]);
+ fprintf(fp, "%i\r\n", data.readings[i]);
fclose(fp);
--- a/snail.lib Tue Jan 13 23:53:24 2015 +0000 +++ b/snail.lib Tue Jan 27 22:20:46 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/Trumple/code/snail/#73668097572a +http://developer.mbed.org/users/Trumple/code/snail/#e5fcfc97001f
