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:
- 16:fab4ed40e6ea
- Parent:
- 14:b756e26ac6bf
--- a/main.cpp Tue Dec 16 22:14:01 2014 +0000 +++ b/main.cpp Thu Dec 18 20:42:33 2014 +0000 @@ -30,7 +30,7 @@ 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 TEMPERATURE_Value_C, TEMPERATURE_Value_F; volatile float HUMIDITY_Value; volatile float PRESSURE_Value; volatile AxesRaw_TypeDef MAG_Value; @@ -101,27 +101,51 @@ int response; /* Read sensors */ - mems_expansion_board->hts221.GetTemperature((float *)&TEMPERATURE_Value); + mems_expansion_board->hts221.GetTemperature((float *)&TEMPERATURE_Value_C); 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); + 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); + + /* Convert temperature to degrees Farhenheit. */ + TEMPERATURE_Value_F = (1.8f * TEMPERATURE_Value_C) + 32.0f; + + printf("Temperature:\t\t %f C / %f F\r\n", TEMPERATURE_Value_C, TEMPERATURE_Value_F); + printf("Humidity:\t\t %f%%\r\n", HUMIDITY_Value); + printf("Pressure:\t\t %f hPa\r\n", PRESSURE_Value); + printf("Magnetometer (mGauss):\t X: %d, Y: %d, Z: %d\r\n", MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z); + printf("Accelerometer (mg):\t X: %d, Y: %d, Z: %d\r\n", ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z); + printf("Gyroscope (mdps):\t X: %d, Y: %d, Z: %d\r\n", GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z); + printf("\r\n"); + MDMParser::NetStatus status; 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 Temperature to M2X */ + response = m2xClient.updateStreamValue(feedId, "temperature", TEMPERATURE_Value_F); + printf("Temperature updateStreamValue response code: %d\r\n", response); + if (response == -1) + { + printf("Temperature data update error\n"); + } /* 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) ; + response = m2xClient.updateStreamValue(feedId, "humidity", HUMIDITY_Value); + printf("Humidity updateStreamValue response code: %d\r\n", response); + if (response == -1) + { + printf("Humidity data update error\n"); + } + + /* Post acceleration (x-axis) to the m2x stream. */ + response = m2xClient.updateStreamValue(feedId, "acceleration", ACC_Value.AXIS_X); + printf("Acceleration updateStreamValue response code: %d\r\n", response); + if (response == -1) + { + printf("Acceleration data update error\n"); + } + } //#define READING @@ -143,6 +167,7 @@ printf("readLocation response code: %d\r\n", response); if (response == -1) while (true) ; #endif + wait(30); // 30 s printf("\r\n"); } else {