ATT_SMS_System for home security system
Dependencies: FXOS8700CQ MODSERIAL mbed-rtos mbed
Fork of ATT_Cellular_IOT_Button by
Diff: main.cpp
- Revision:
- 3:26b3cc155f39
- Parent:
- 2:0e2ef866af95
- Child:
- 4:f83bedd9cab4
diff -r 0e2ef866af95 -r 26b3cc155f39 main.cpp --- a/main.cpp Sun Jul 10 00:52:49 2016 +0000 +++ b/main.cpp Sun Jul 10 09:12:33 2016 +0000 @@ -233,6 +233,50 @@ #define CTOF(x) ((x)*1.8+32) +#include "Flow_parameters.h" +//******************************************************************************************************************************************** +//* Create string that can be sent to flow as an HTTP get +//******************************************************************************************************************************************** +static K64F_Sensors_t SENSOR_DATA = +{ + .Temperature = "0", + .Humidity = "0", + .AccelX = "0", + .AccelY = "0", + .AccelZ = "0", + .AmbientLight = "0", + .UVindex = "0", + .Proximity = "0" +}; +static Flow_datapoint_t FLOW_DATAPOINT = +{ + .URL_start = FLOW_CALLBACK_URL_START, + .URL_end = FLOW_CALLBACK_URL_END, + .Device_ID = FLOW_DEVICE_ID +}; +void GenerateModemString(char * modem_string) +{ + sprintf(modem_string, "%s?deviceID=%s&temp=%s&humidity=%s %s", FLOW_DATAPOINT.URL_start, FLOW_DATAPOINT.Device_ID, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, FLOW_DATAPOINT.URL_end); +} //GenerateModemString + + +//Periodic timer +Ticker OneMsTicker; +volatile bool bTimerExpiredFlag = false; +int OneMsTicks = 0; +int iTimer1Interval_ms = 1000; +//******************************************************************************************************************************************** +//* Periodic 1ms timer tick +//******************************************************************************************************************************************** +void OneMsFunction() +{ + OneMsTicks++; + if ((OneMsTicks % iTimer1Interval_ms) == 0) + { + bTimerExpiredFlag = true; + } +} //OneMsFunction() + int main() { int i; HTS221 hts221; @@ -266,13 +310,30 @@ // Resolve URL to IP address to connect to resolve_mdm(); + //Create a 1ms timer tick function: + OneMsTicker.attach(OneMsFunction, 0.001f) ; + iTimer1Interval_ms = 5000; //5 seconds + // Send and receive data perpetually while(1) { - sockopen_mdm(); - sockwrite_mdm("GET /f653d97537235/a31c2684a02c/d35e42196968fd6/in/flow/climate?deviceID=e5ee19804bd500c8fe69a809342384c2&temp=41.0&humidity=87.33 HTTP/1.1 Host: run-east.att.io:80 Accept: */*\r\n\r\n"); - sockread_mdm(&MySocketData, 1024, 20); - sockclose_mdm(); - } + if (bTimerExpiredFlag) + { + bTimerExpiredFlag = false; + sprintf(SENSOR_DATA.Temperature, "%0.2f", CTOF(hts221.readTemperature())); + sprintf(SENSOR_DATA.Humidity, "%02d", hts221.readHumidity()); + + sockopen_mdm(); + + char modem_string[512]; + GenerateModemString(&modem_string[0]); + printf(DEF "Sending to modem : %s\n", modem_string); + //sockwrite_mdm("GET /f653d97537235/a31c2684a02c/d35e42196968fd6/in/flow/climate?deviceID=e5ee19804bd500c8fe69a809342384c2&temp=41.0&humidity=87.33 HTTP/1.1 Host: run-east.att.io:80 Accept: */*\r\n\r\n"); + + sockwrite_mdm(modem_string); + sockread_mdm(&MySocketData, 1024, 20); + sockclose_mdm(); + } //bTimerExpiredFlag + } //forever loop string * pStr; while (1)