M2X demo using the Freescale FRDM-KL46Z and Multitech Socketmodem MTSMS-H5
Dependencies: M2XStreamClient MMA8451Q SocketModem jsonlite mbed
Fork of MTS_M2x_Example by
Diff: main.cpp
- Revision:
- 8:54f32950dab2
- Parent:
- 6:0dbcf434679b
diff -r b90e8119f3cd -r 54f32950dab2 main.cpp --- a/main.cpp Wed Jan 22 23:26:47 2014 +0000 +++ b/main.cpp Tue Apr 29 21:15:00 2014 +0000 @@ -1,12 +1,29 @@ #include "mbed.h" +#include "MMA8451Q.h" #include "M2XStreamClient.h" #include "include_me.h" + +#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) + PinName const SDA = PTE25; + PinName const SCL = PTE24; +#elif defined (TARGET_KL05Z) + PinName const SDA = PTB4; + PinName const SCL = PTB3; +#else + #error TARGET NOT DEFINED +#endif + +#define MMA8451_I2C_ADDRESS (0x1d<<1) + using namespace mts; const char key[] = ""; // enter your m2x user account master key const char feed[] = ""; // enter your blueprint feed id -const char stream[] = "amb-temp"; // Create a stream name +const char* names[] = { "x", "y", "z" }; // user will need to create these Streams manually in the Dev Portal +int counts[] = { 1, 1, 1 }; + + // set to 1 for cellular shield board // set to 0 for wifi shield board @@ -28,7 +45,7 @@ int max_tries = 5; int i; - std::string apn = "wap.cingular"; + std::string apn = "m2m.com.attz"; i = 0; while (i++ < max_tries) { @@ -91,12 +108,26 @@ Client client; M2XStreamClient m2xClient(&client, key); int ret; - int num; + int streamNum = 3; + + MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); + PwmOut rled(LED1); + PwmOut gled(LED2); + PwmOut bled(LED3); + + printf("MMA8451 ID: %d\n", acc.getWhoAmI()); + while (true) { - num = rand(); - printf("sending %d\r\n", num); - ret = m2xClient.send(feed, stream, num); + float x, y, z; + x = rled = 1.0 - abs(acc.getAccX()); + y = gled = 1.0 - abs(acc.getAccY()); + z = bled = 1.0 - abs(acc.getAccZ()); + printf("Sending X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); + double values[] = { x, y, z }; + ret = m2xClient.postMultiple(feed, streamNum, names, counts, NULL, values); printf("send() returned %d\r\n", ret); wait(5); } + + } \ No newline at end of file