SmartREST client reference implementation for the u-blox C027 mbed compatible device.
Dependencies: C027 C027_Support mbed mbed-rtos MbedSmartRest LM75B MMA7660 C12832
Fork of MbedSmartRestTest by
Revision 12:beb64aa0da86, committed 2014-02-14
- Comitter:
- vwochnik
- Date:
- Fri Feb 14 12:28:41 2014 +0000
- Parent:
- 11:6f8f70a6dd46
- Child:
- 13:4045b6ac448d
- Commit message:
- fix
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Fri Feb 14 12:28:41 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/neilt6/code/LM75B/#3a44310726fe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Fri Feb 14 12:28:41 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MMA7660/#a8e20db7901e
--- a/common.h Wed Feb 12 13:40:16 2014 +0000 +++ b/common.h Fri Feb 14 12:28:41 2014 +0000 @@ -1,3 +1,6 @@ +#ifndef COMMON_H +#define COMMON_H + #include <stdint.h> #include <stddef.h> #include "mbed.h" @@ -21,4 +24,6 @@ const char * cellId(); const char * iccid(); sigq_t * signalQuality(); -int program(void); \ No newline at end of file +int program(void); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/io.cpp Fri Feb 14 12:28:41 2014 +0000 @@ -0,0 +1,68 @@ +#include "io.h" +#include "rtos.h" + +#define S_INIT 0 +#define S_OPEN 1 +#define S_GONE 2 + +void thread_callback(void const*); + +// adjust pin numbers +LM75B tempSensor(p28, p27); +MMA7660 accSensor(p28, p27); +DigitalIn button(p14); + +Thread worker(thread_callback); + +uint8_t tempState = S_INIT; +uint8_t accState = S_INIT; +uint32_t count = 0; + +float temperature() +{ + if ((tempState == S_INIT) && (tempSensor.open())) + tempState = S_OPEN; + else + tempState = S_GONE; + + if (tempState == S_OPEN) + return tempSensor.temp(); + + return 0.0; +} + +acceleration_t acceleration() +{ + 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) { + accSensor.readData(data); + ret.x = data[0]; + ret.y = data[1]; + ret.z = data[2]; + } + + return ret; +} + +uint32_t counter() +{ + return count; +} + +void thread_callback(void const*) +{ + bool pressed = false; + + while (true) { + if ((!pressed) && (button)) + count++; + pressed = button; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/io.h Fri Feb 14 12:28:41 2014 +0000 @@ -0,0 +1,17 @@ +#ifndef IO_H +#define IO_H + +#include "common.h" +#include "LM75B.h" +#include "MMA7660.h" + +typedef struct +{ + float x, y, z; +} acceleration_t; + +float temperature(); +acceleration_t acceleration(); +uint32_t counter(); + +#endif \ No newline at end of file
--- a/main.cpp Wed Feb 12 13:40:16 2014 +0000 +++ b/main.cpp Fri Feb 14 12:28:41 2014 +0000 @@ -26,13 +26,18 @@ } // get before starting program as they're permanent - imei(); iccid(); + if (!strlen(imei())) || (!strlen(iccid()))) { + puts("Couldn't read IMEI or ICCID."); + return 2; + } puts("Starting program..."); // restart program upon failure do { ret = program(); + if (ret) + puts("Restarting program..."); } while (ret); modem.disconnect();
--- a/program.cpp Wed Feb 12 13:40:16 2014 +0000 +++ b/program.cpp Fri Feb 14 12:28:41 2014 +0000 @@ -1,4 +1,5 @@ #include "common.h" +#include "io.h" #include "StaticData.h" #include "ComposedRecord.h" #include "CharValue.h" @@ -36,7 +37,6 @@ "10,104,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_SignalStrength\"\",\"\"c8y_SignalStrength\"\":{\"\"rssi\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"dBm\"\"},\"\"ber\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"%\"\"}}}\"\r\n" ); -const char * const serialNumber = "ublox-a123bd"; 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.7"); //MbedSmartRest client("http://nocore.info:8888/", "vaillant/admin", "klanpi", "com_cumulocity_MbedTestDevice_2.0"); @@ -84,7 +84,7 @@ puts("Checking for device existance..."); - newMoRec.add(IntegerValue(100)).add(CharValue(serialNumber)); + newMoRec.add(IntegerValue(100)).add(CharValue(imei())); if (client.send(newMoRec) != SMARTREST_SUCCESS) { puts("Send failed."); @@ -126,7 +126,7 @@ puts("Creating device..."); - newMoRec.add(IntegerValue(101)).add(CharValue(serialNumber)); + newMoRec.add(IntegerValue(101)).add(CharValue(imei())); if (client.send(newMoRec) != SMARTREST_SUCCESS) { puts("Send failed."); @@ -163,7 +163,7 @@ puts("Adding global identifier..."); - newMoRec.add(IntegerValue(102)).add(IntegerValue(deviceId)).add(CharValue(serialNumber)); + newMoRec.add(IntegerValue(102)).add(IntegerValue(deviceId)).add(CharValue(imei())); if (client.send(newMoRec) != SMARTREST_SUCCESS) { puts("Sending failed.");