Example program to connect to the internet via Ublox Cellular Shield and post MEMS sensor readings to M2X.
Dependencies: C027_Support M2XStreamClient Nucleo_Sensor_Shield jsonlite mbed-rtos mbed
Fork of Cellular_m2x-demo-all by
Diff: main.cpp
- Revision:
- 14:b756e26ac6bf
- Parent:
- 13:b04452198625
- Child:
- 16:fab4ed40e6ea
--- a/main.cpp Wed Oct 01 09:23:57 2014 +0000 +++ b/main.cpp Thu Dec 11 22:33:16 2014 +0000 @@ -1,5 +1,6 @@ #include <jsonlite.h> #include "M2XStreamClient.h" +#include "x_cube_mems.h" #include "mbed.h" #include "GPS.h" //GPS @@ -21,15 +22,20 @@ #define PASSWORD NULL //------------------------------------------------------------------------------------ -char feedId[] = "81b9fcc5a8585c55ae622488f50d8de0"; // Feed you want to post to -char m2xKey[] = "1e1133cd475954868602c0f7503d4f22"; // Your M2X access key +char feedId[] = "0c76bf26149c9c01d8eec11553d1a6f2"; // Feed you want to post to +char m2xKey[] = "76ee6b8414970d7ade8c75829d0cf879"; // Your M2X access key char name[] = "<location name>"; // Name of current location of datasource double latitude = 33.007872; double longitude = -96.751614; // You can also read those values from a GPS double elevation = 697.00; bool location_valid = false; - +volatile float TEMPERATURE_Value, TEMPERATURE_Value_f; +volatile float HUMIDITY_Value; +volatile float PRESSURE_Value; +volatile AxesRaw_TypeDef MAG_Value; +volatile AxesRaw_TypeDef ACC_Value; +volatile AxesRaw_TypeDef GYR_Value; Client client; M2XStreamClient m2xClient(&client, m2xKey); @@ -51,7 +57,8 @@ } int main() { - MDMSerial mdm; + uint8_t hts221_id; + MDMSerial mdm(D8,D2); GPSI2C gps; //mdm.setDebug(4); // enable this for debugging issues if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) @@ -59,6 +66,13 @@ char buf[256]; + printf("M2X MEMS U-Blox Cellular Demo \r\n"); + + static X_CUBE_MEMS *mems_expansion_board = X_CUBE_MEMS::Instance(); + + hts221_id = mems_expansion_board->hts221.ReadID(); + printf("HTS221_ID = 0x%x\n\t\r", hts221_id); + Timer tmr; tmr.reset(); tmr.start(); @@ -85,14 +99,31 @@ tmr.reset(); tmr.start(); int response; + + /* Read sensors */ + mems_expansion_board->hts221.GetTemperature((float *)&TEMPERATURE_Value); + mems_expansion_board->hts221.GetHumidity((float *)&HUMIDITY_Value); + //mems_expansion_board->lps25h.GetPressure((float *)&PRESSURE_Value); + //mems_expansion_board->lis3mdl.GetAxes((AxesRaw_TypeDef *)&MAG_Value); + //mems_expansion_board->lsm6ds0.Acc_GetAxes((AxesRaw_TypeDef *)&ACC_Value); + //mems_expansion_board->lsm6ds0.Gyro_GetAxes((AxesRaw_TypeDef *)&GYR_Value); MDMParser::NetStatus status; - if (mdm.checkNetStatus(&status)) { - sprintf(buf, "%d", status.rssi); - response = m2xClient.put(feedId, "rssi", buf); + if (mdm.checkNetStatus(&status)) { + /* Post Temperature to M2X */ + TEMPERATURE_Value_f =(1.8 * TEMPERATURE_Value) + 32.0; + printf("TEMP: %f C %f F \r\n", TEMPERATURE_Value, TEMPERATURE_Value_f); + response = m2xClient.put(feedId, "temperature", TEMPERATURE_Value_f); printf("Put response code: %d\r\n", response); if (response == -1) while (true) ; + + /* Post Humidity to M2X */ + printf("HUMIDITY: %f \r\n", HUMIDITY_Value); + response = m2xClient.put(feedId, "humidity", HUMIDITY_Value); + printf("Put response code: %d\r\n", response); + if (response == -1) while (true) ; } + //#define READING #ifdef READING // read signal strength @@ -112,6 +143,7 @@ printf("readLocation response code: %d\r\n", response); if (response == -1) while (true) ; #endif + printf("\r\n"); } else { delay(100);