Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 15:0ccf0f530a05, committed 2014-02-18
- Comitter:
- vwochnik
- Date:
- Tue Feb 18 15:36:12 2014 +0000
- Parent:
- 14:56da550a1baa
- Child:
- 16:94d6eae3195a
- Commit message:
- fix
Changed in this revision
--- a/io.cpp Tue Feb 18 13:59:21 2014 +0000 +++ b/io.cpp Tue Feb 18 15:36:12 2014 +0000 @@ -1,11 +1,7 @@ #include "io.h" #include "rtos.h" -#define S_INIT 0 -#define S_OPEN 1 -#define S_GONE 2 - -void thread_callback(void const*); +void timer_callback(void const*); // Using Arduino pin notation LM75B tempSensor(SDA, SCL); @@ -13,23 +9,26 @@ DigitalIn button(p14); //C12832 lcdDisplay(D11, D13, D12, D7, D10); -Thread worker(thread_callback); +RtosTimer *timer; + +bool tempFound = false, accFound = false; +uint32_t count = 0; +bool btnPressed = false; -uint8_t tempState = S_INIT; -uint8_t accState = S_INIT; -uint32_t count = 0; +void io_init(void) +{ + timer = new RtosTimer(&timer_callback, osTimerPeriodic); + timer->start(50); + tempFound = tempSensor.open(); + accFound = accSensor.testConnection(); +} float temperature() { - if ((tempState == S_INIT) && (tempSensor.open())) - tempState = S_OPEN; - else - tempState = S_GONE; - - if (tempState == S_OPEN) - return tempSensor.temp(); + if (!tempFound) + return 0.0; - return 0.0; + return tempSensor.temp(); } acceleration_t acceleration() @@ -37,12 +36,7 @@ float data[3]; acceleration_t ret = { 0.0, 0.0, 0.0 }; - if ((accState == S_INIT) && (accSensor.testConnection())) - accState = S_OPEN; - else - accState = S_GONE; - - if (accState == S_OPEN) { + if (accFound) { accSensor.readData(data); ret.x = data[0]; ret.y = data[1]; @@ -57,13 +51,9 @@ return count; } -void thread_callback(void const*) +void timer_callback(void const*) { - bool pressed = false; - - while (true) { - if ((!pressed) && (button)) - count++; - pressed = button; - } + if ((!btnPressed) && (button)) + count++; + btnPressed = button; }
--- a/io.h Tue Feb 18 13:59:21 2014 +0000 +++ b/io.h Tue Feb 18 15:36:12 2014 +0000 @@ -22,6 +22,7 @@ float x, y, z; } acceleration_t; +void io_init(void); float temperature(); acceleration_t acceleration(); uint32_t counter();
--- a/main.cpp Tue Feb 18 13:59:21 2014 +0000 +++ b/main.cpp Tue Feb 18 15:36:12 2014 +0000 @@ -1,4 +1,5 @@ #include "common.h" +#include "io.h" #include "ATResultBuffer.h" C027 c027; @@ -13,6 +14,9 @@ int ret; puts("Started..."); + io_init(); + puts("IO initialized."); + c027.mdmWakeup(); c027.mdmReset(); c027.mdmPower(true);
--- a/program.cpp Tue Feb 18 13:59:21 2014 +0000 +++ b/program.cpp Tue Feb 18 15:36:12 2014 +0000 @@ -44,18 +44,18 @@ "10,105,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_TemperatureMeasurement\"\",\"\"c8y_TemperatureMeasurement\"\":{\"\"T\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"C\"\"}}}\"\r\n" // Insert measurement // USAGE: 105,<DEVICE/ID>,<COUNTER> -"10,106,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_CountMeasurement\"\",\"c8y_CountMeasurement\":{\"n\":{\"value\":%%,\"unit\":\"\"}}}\"\r\n" +"10,106,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_CountMeasurement\"\",\"\"c8y_CountMeasurement\"\":{\"\"n\"\":{\"\"value\"\":%%,\"\"unit\":\"\"\"\"}}}\"\r\n" // Insert measurement // USAGE: 105,<DEVICE/ID>,<X>,<Y>,<Z> "10,107,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER NUMBER NUMBER,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_MotionMeasurement\"\",\"\"c8y_MotionMeasurement\"\":{\"\"x\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"m^2/s\"\"},\"\"y\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"m^2/s\"\"},\"\"z\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"m^2/s\"\"}}}\"\r\n" ); float interval = 120.0; // send measurements every two minutes -MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.8"); +MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.9"); int program(void) { - long deviceId; Timer timer; + long deviceId = 0; Timer timer; puts("Hello!"); @@ -248,14 +248,23 @@ Aggregator aggr(5, false, true); signalMeasurement(deviceId, aggr); + if (client.send(aggr) != SMARTREST_SUCCESS) { + puts("Send failed."); + } + client.stop(); + aggr.clear(); temperatureMeasurement(deviceId, aggr); countMeasurement(deviceId, aggr); + if (client.send(aggr) != SMARTREST_SUCCESS) { + puts("Send failed."); + } + client.stop(); + aggr.clear(); motionMeasurement(deviceId, aggr); if (client.send(aggr) != SMARTREST_SUCCESS) { puts("Send failed."); } - client.stop(); }