FRDM-K64F, Avnet M14A2A, Grove Shield, to create smart home system. In use with AT&Ts M2x & Flow.
Dependencies: mbed FXOS8700CQ MODSERIAL
Revision 85:0cf65ceb4492, committed 2019-04-29
- Comitter:
- jwhammel
- Date:
- Mon Apr 29 04:24:38 2019 +0000
- Parent:
- 84:fc8c9b39723a
- Commit message:
- We have added an alarm trigger that gets sent to AT&T Flow.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
wnc_control.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r fc8c9b39723a -r 0cf65ceb4492 main.cpp --- a/main.cpp Wed Mar 06 21:11:49 2019 +0000 +++ b/main.cpp Mon Apr 29 04:24:38 2019 +0000 @@ -85,7 +85,7 @@ } case TEMP_HUMIDITY_ACCELEROMETER: { - sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,SENSOR_DATA.AccelZ, FLOW_URL_TYPE, MY_SERVER_URL); + sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&alarm=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,SENSOR_DATA.AccelZ,SENSOR_DATA.Proximity, FLOW_URL_TYPE, MY_SERVER_URL); break; } case TEMP_HUMIDITY_ACCELEROMETER_GPS: @@ -210,21 +210,25 @@ //DigitalIn btn_temp_up(D4); //DigitalIn btn_temp_down(D8); -DigitalIn btn_silence(D7); +DigitalIn btn_silence(D4); DigitalIn motion(D3); DigitalOut buzzer(D5); -AnalogIn pot_temp_set(A3); -DHT sensor(D4, DHT11); +AnalogIn pot_temp_set(A2); +AnalogIn Alarm_Off(A3); +//DHT sensor(D4, DHT11); int main() { static unsigned ledOnce = 0; int error = 0; float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; float value = 0.0f; + float alm_off; float temp_setting = 0.0f, diff = 0.0f; int mycolor = 0x0; - bool alarm = false; + bool alarms = false; + int mycounter = 0; + int movement; //delay so that the debug terminal can open after power-on reset: wait (5.0); @@ -280,9 +284,13 @@ //parse_JSON(&myJsonResponse[0]); } } //bTimerExpiredFlag - - //--------------------------------begin new code-------------------------------- - error = sensor.readData(); + //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ + //-------------------------------BEGIN NEW CODE--------------------------------- + //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ + /* error = sensor.readData(); if (0 == error) { c = sensor.ReadTemperature(CELCIUS); @@ -298,15 +306,15 @@ { //printf("Error: %d\n", error); } - + */ value = pot_temp_set; //printf("Slide location %3.6f\r\n", value); temp_setting = value * 40.0f + 50.0f; - printf(WHT "Thermostat is set to %3.2f degrees.\r\n", temp_setting); + // printf(WHT "Thermostat is set to %3.2f degrees.\r\n", temp_setting); //current_temp and rel_humid are assigned in sensors.cpp - printf(WHT "Current temperature is %3.2f degrees.\r\n", current_temp); - printf(WHT "Relative humidity is %3.2f percent.\r\n", rel_humid); + // printf(WHT "Current temperature is %3.2f degrees.\r\n", current_temp); + // printf(WHT "Relative humidity is %3.2f percent.\r\n", rel_humid); printf(WHT "\r\n"); @@ -333,27 +341,46 @@ } //if motion sensor detects motion, sound an alarm - if ((motion == 1) && !alarm) + + if (motion && !alarms) { - alarm = true; + alarms = true; + strcpy(SENSOR_DATA.Proximity, "1"); printf(WHT "--------------------------------\r\n"); printf(WHT "Alert! Home intrusion detected!\r\n"); printf(WHT "--------------------------------\r\n"); printf(WHT "\r\n"); } - if ((btn_silence == 1) && alarm) + alm_off = Alarm_Off;//Switching to integer because AnalogIn acts weird in If statement + if((alm_off > 0.5f) && alarms) { - alarm = false; + alarms = false; + strcpy(SENSOR_DATA.Proximity, "0"); buzzer = 0; printf(WHT "Alarm disengaged. Resuming normal operation.\r\n"); printf(WHT "\r\n"); } - if (alarm) + if (alarms) { buzzer = !buzzer; } - wait(1.0); + + /*wait(1.0); + + mycounter = mycounter + 1; + if (mycounter >= 20) + { + mycounter = 0; + } + if (mycounter >= 15) + { + strcpy(SENSOR_DATA.Proximity, "1"); + } + else + { + strcpy(SENSOR_DATA.Proximity, "0"); + } */ } //forever loop }
diff -r fc8c9b39723a -r 0cf65ceb4492 wnc_control.cpp --- a/wnc_control.cpp Wed Mar 06 21:11:49 2019 +0000 +++ b/wnc_control.cpp Mon Apr 29 04:24:38 2019 +0000 @@ -53,7 +53,7 @@ // Temp put here to fix new boards needing init, // the check for on the cellular network was preventing the PDNSET from happening!!!! { - //PUTS("SET APN STRING!\r\n"); + PUTS("SET APN STRING!\r\n"); string * pRespStr; string cmd_str("AT%PDNSET=1,"); cmd_str += MY_APN_STR; @@ -64,12 +64,12 @@ static bool reportStatus = true; do { - //PUTS("------------ software_init_mdm! --------->\r\n"); + PUTS("------------ software_init_mdm! --------->\r\n"); if (check_wnc_ready() == 0) { if (reportStatus == false) { - //PUTS("Re-connected to cellular network!\n\r"); + PUTS("Re-connected to cellular network!\n\r"); reportStatus = true; } @@ -89,7 +89,7 @@ { if (reportStatus == true) { - //PUTS("Not connected to cellular network!\n\r"); + PUTS("Not connected to cellular network!\n\r"); reportStatus = false; } // Atempt to re-register @@ -108,11 +108,11 @@ { string * pRespStr; - //PUTS("<-------- WNC Firmware Revision --------\r\n"); + PUTS("<-------- WNC Firmware Revision --------\r\n"); at_send_wnc_cmd("ATI", &pRespStr, WNC_TIMEOUT_MS); - //PUTS(pRespStr->c_str()); - //PUTS("\r\n"); - //PUTS("--------------------------------------->\r\n"); + PUTS(pRespStr->c_str()); + PUTS("\r\n"); + PUTS("--------------------------------------->\r\n"); } void resolve_mdm(void) @@ -127,11 +127,11 @@ } else if (WNC_MDM_ERR == WNC_CMD_ERR) { - //PUTS("Bad URL!!!!!!\r\n"); + PUTS("Bad URL!!!!!!\r\n"); } } while (WNC_MDM_ERR != WNC_OK); - //PRINTF("My Server IP: %s\r\n", MyServerIpAddress.c_str()); + PRINTF("My Server IP: %s\r\n", MyServerIpAddress.c_str()); } void sockopen_mdm(void) @@ -144,8 +144,8 @@ { software_init_mdm(); } - else if (WNC_MDM_ERR == WNC_CMD_ERR); - //PUTS("Socket open fail!!!!\r\n"); + else if (WNC_MDM_ERR == WNC_CMD_ERR) + PUTS("Socket open fail!!!!\r\n"); else socketOpen = 1; } while (WNC_MDM_ERR != WNC_OK); @@ -161,24 +161,24 @@ at_sockwrite_wnc(s); if (WNC_MDM_ERR == WNC_NO_RESPONSE) { - //PUTS("Sock write no response!\r\n"); + PUTS("Sock write no response!\r\n"); software_init_mdm(); } else if (WNC_MDM_ERR == WNC_CMD_ERR) { - //PUTS("Socket Write fail!!!\r\n"); + PUTS("Socket Write fail!!!\r\n"); software_init_mdm(); }else if (WNC_MDM_ERR == WNC_EXTERR) { - //PUTS("Socket Disconnected (broken) !!!\r\n"); + PUTS("Socket Disconnected (broken) !!!\r\n"); sockclose_mdm(); sockopen_mdm(); //software_init_mdm(); } } while (WNC_MDM_ERR != WNC_OK); } - else; - //PUTS("Socket is closed for write!\r\n"); + else + PUTS("Socket is closed for write!\r\n"); } unsigned sockread_mdm(string * sockData, int len, int retries) @@ -195,16 +195,16 @@ { if (n == 0) software_init_mdm(); - else; - //PUTS("Sock read partial data!!!\r\n"); + else + PUTS("Sock read partial data!!!\r\n"); } - else if (WNC_MDM_ERR == WNC_CMD_ERR); - //PUTS("Sock read fail!!!!\r\n"); + else if (WNC_MDM_ERR == WNC_CMD_ERR) + PUTS("Sock read fail!!!!\r\n"); } while (WNC_MDM_ERR == WNC_NO_RESPONSE); } else { - //PUTS("Socket is closed for read\r\n"); + PUTS("Socket is closed for read\r\n"); sockData->erase(); } @@ -225,8 +225,8 @@ { software_init_mdm(); } - else if (WNC_MDM_ERR == WNC_CMD_ERR); - //PUTS("Sock close fail!!!\r\n"); + else if (WNC_MDM_ERR == WNC_CMD_ERR) + PUTS("Sock close fail!!!\r\n"); } while (WNC_MDM_ERR != WNC_OK); } @@ -277,7 +277,7 @@ int cmdRes1, cmdRes2; #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("<-------- Begin Cell Status ------------\r\n"); + PUTS("<-------- Begin Cell Status ------------\r\n"); #endif cmdRes1 = at_send_wnc_cmd("AT+CSQ", &pRespStr, WNC_TIMEOUT_MS); // Check RSSI,BER cmdRes2 = at_send_wnc_cmd("AT+CPIN?", &pRespStr, WNC_TIMEOUT_MS); // Check if SIM locked @@ -285,7 +285,7 @@ if ((cmdRes1 != 0) && (cmdRes2 != 0)) { #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("------------ WNC No Response! --------->\r\n"); + PUTS("------------ WNC No Response! --------->\r\n"); #endif return (-2); } @@ -294,7 +294,7 @@ if (pRespStr->find("CPIN: READY") == string::npos) { #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("------------ WNC SIM Problem! --------->\r\n"); + PUTS("------------ WNC SIM Problem! --------->\r\n"); #endif return (-1); } @@ -313,20 +313,20 @@ if ((regSts != 1) && (regSts != 5)) { #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("------------ WNC Cell Link Down! ------>\r\n"); + PUTS("------------ WNC Cell Link Down! ------>\r\n"); #endif return (-2); } } #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("------------ WNC Ready ---------------->\r\n"); + PUTS("------------ WNC Ready ---------------->\r\n"); #endif } else { #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("------------ CREG No Reply !----------->\r\n"); + PUTS("------------ CREG No Reply !----------->\r\n"); #endif return (-2); } @@ -344,17 +344,17 @@ static string noRespStr; #ifdef WNC_CMD_DEBUG_ON - //PUTS("FAIL send cmd: "); + PUTS("FAIL send cmd: "); #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS(s); - //PUTS("\r\n"); + PUTS(s); + PUTS("\r\n"); #else string truncStr(s, 50); truncStr += "\r\n"; - //PUTS(truncStr.c_str()); + PUTS(truncStr.c_str()); #endif #else - //PUTS("FAIL send cmd!\r\n"); + PUTS("FAIL send cmd!\r\n"); #endif WNC_MDM_ERR = WNC_CELL_LINK_DOWN; @@ -365,12 +365,12 @@ #ifdef WNC_CMD_DEBUG_ON #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("[---------- Network Status -------------\r\n"); + PUTS("[---------- Network Status -------------\r\n"); #endif string * pRespStr; at_send_wnc_cmd("AT@SOCKDIAL?", &pRespStr, 5000); #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS("---------------------------------------]\r\n"); + PUTS("---------------------------------------]\r\n"); #endif #endif @@ -385,7 +385,7 @@ if (cmdRes == -3) { WNC_MDM_ERR = WNC_EXTERR; - //PRINTF("[[WNC_MDM_ERR = WNC_EXTERR]] \r\n"); + PRINTF("[[WNC_MDM_ERR = WNC_EXTERR]] \r\n"); } if (cmdRes == 0) @@ -408,11 +408,11 @@ { string truncStr(s,57); truncStr += "..."; - //PRINTF("Send: <<%s>>\r\n",truncStr.c_str()); + PRINTF("Send: <<%s>>\r\n",truncStr.c_str()); } - else; + else #endif - //PRINTF("Send: <<%s>>\r\n",s); + PRINTF("Send: <<%s>>\r\n",s); #endif int res = mdm_sendAtCmdRsp(s, rsp_lst, ms_timeout, &wncStr, &len); @@ -422,19 +422,19 @@ { #ifdef WNC_CMD_DEBUG_ON - //PUTS("["); + PUTS("["); #ifdef WNC_CMD_DEBUG_ON_VERBOSE - //PUTS(wncStr.c_str()); - //PUTS("]\r\n"); + PUTS(wncStr.c_str()); + PUTS("]\r\n"); #else - if (wncStr.size() < 51); - //PUTS(wncStr.c_str()); + if (wncStr.size() < 51) + PUTS(wncStr.c_str()); else { string truncStr = wncStr.substr(0,50) + "..."; - //PUTS(truncStr.c_str()); + PUTS(truncStr.c_str()); } - //PUTS("]\r\n"); + PUTS("]\r\n"); #endif #endif @@ -450,7 +450,7 @@ return 0; } else if (res == 2) { /* @EXTERR */ - //PRINTF("@EXTERR and res = %d \r\n", res); + PRINTF("@EXTERR and res = %d \r\n", res); return -3; } else return -1; @@ -458,7 +458,7 @@ } else { - //PUTS("No response from WNC!\n\r"); + PUTS("No response from WNC!\n\r"); return -2; } } @@ -480,13 +480,13 @@ if (hardReset == true) { - //PUTS("Hard Reset!\r\n"); + PUTS("Hard Reset!\r\n"); pdnSet = false; intSet = false; sockDialSet = false; } - //PUTS("Start AT init of WNC:\r\n"); + PUTS("Start AT init of WNC:\r\n"); // Quick commands below do not need to check cellular connectivity cmdRes = at_send_wnc_cmd("AT", &pRespStr, WNC_TIMEOUT_MS); // Heartbeat? cmdRes += at_send_wnc_cmd("ATE0", &pRespStr, WNC_TIMEOUT_MS); // Echo Off @@ -540,7 +540,7 @@ else return ; - //PUTS("SUCCESS: AT init of WNC!\r\n"); + PUTS("SUCCESS: AT init of WNC!\r\n"); } void at_sockopen_wnc(const string & ipStr, const char * port ) @@ -590,14 +590,14 @@ *ipStr = pRespStr->substr(pos_start, pos_end - pos_start + 1); return 1; } - else; - //PUTS("URL Resolve fail, substr Err\r\n"); + else + PUTS("URL Resolve fail, substr Err\r\n"); } - else; - //PUTS("URL Resolve fail, no quotes\r\n"); + else + PUTS("URL Resolve fail, no quotes\r\n"); } else - //PUTS("URL Resolve fail, WNC cmd fail\r\n"); + PUTS("URL Resolve fail, WNC cmd fail\r\n"); *ipStr = "192.168.0.1"; @@ -630,11 +630,11 @@ } cmd_str += "\""; res = send_wnc_cmd(cmd_str.c_str(), &pRespStr, 120000); - if (res == -3); - //PUTS("sockwrite is disconnect \r\n"); + if (res == -3) + PUTS("sockwrite is disconnect \r\n"); } - else; - //PUTS("sockwrite Err, string to long\r\n"); + else + PUTS("sockwrite Err, string to long\r\n"); } unsigned at_sockread_wnc(string * pS, unsigned n, unsigned retries = 0) @@ -687,13 +687,13 @@ } else { - //PUTS("no readsock reply!\r\n"); + PUTS("no readsock reply!\r\n"); return (0); } } } else - //PUTS("sockread Err, to many to read\r\n"); + PUTS("sockread Err, to many to read\r\n"); return (numBytes); }