AT&T IoT hackster.io contest entry: Carpal2
Dependencies: FXOS8700CQ Pubnub_mbed2_sync WNCInterface mbed-rtos mbed
Revision 2:fe8e935b9342, committed 2016-12-24
- Comitter:
- cswiger
- Date:
- Sat Dec 24 17:31:00 2016 +0000
- Parent:
- 1:610520d32d22
- Commit message:
- added Ignition awareness so Carpal2 will resume working after car has been turned off and back on.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Dec 21 20:24:23 2016 +0000 +++ b/main.cpp Sat Dec 24 17:31:00 2016 +0000 @@ -216,63 +216,72 @@ if (bTimerExpiredFlag) { bTimerExpiredFlag = false; - rled = 1; pc.printf("Refresh...\n\r"); Refresh(); - pc.printf("Get coolant temp...\n\r"); - get_pid(COOLANT_TEMP,&coolant_temp); - pc.printf("Get rpm...\n\r"); - get_pid(ENGINE_RPM,&engine_rpm); - get_pid(LOAD_VALUE,&engine_load); - get_pid(VEHICLE_SPEED,&vehicle_speed); - pc.printf("Coolant: %d\n\rRPM: %d\n\r",coolant_temp,engine_rpm); - // short keys to keep air co$t$ down - // oc or os ol - obd2 coolant temp, rpm, speed, load - // la lo - gps latitude, longitude - // ax ay - accelarometer X,Y - pc.printf("Read sensors\n\r"); - read_sensors(); - snprintf(data,256,"{\"la\":%s,\"lo\":%s,\"ax\":%s,\"ay\":%s,\"oc\":%d,\"or\":%d,\"ol\":%d,\"os\":%d}",SENSOR_DATA.GPS_Latitude,SENSOR_DATA.GPS_Longitude,SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,coolant_temp,engine_rpm,engine_load,vehicle_speed); - // publish json and wait for result - pubnub_res rslt = pubnub_publish(pbp, "carpal2", data); - if (rslt != PNR_STARTED) { - pc.printf("Failed to start publishing, rslt=%d"CRLF, rslt); - rled = 1; - gled = 0; - } else { - rslt = pubnub_await(pbp); - if (rslt != PNR_OK) { - pc.printf("Failed to finished publishing, rslt=%d"CRLF, rslt); + pc.printf("Ignition on: %d\n\r",isIgnitionOn); + pc.printf("Engine on: %d\n\r",isEngineOn); + if(isIgnitionOn) { + rled = 1; + pc.printf("Get coolant temp...\n\r"); + get_pid(COOLANT_TEMP,&coolant_temp); + pc.printf("Get rpm...\n\r"); + get_pid(ENGINE_RPM,&engine_rpm); + get_pid(LOAD_VALUE,&engine_load); + get_pid(VEHICLE_SPEED,&vehicle_speed); + pc.printf("Coolant: %d\n\rRPM: %d\n\r",coolant_temp,engine_rpm); + // short keys to keep air co$t$ down + // oc or os ol - obd2 coolant temp, rpm, speed, load + // la lo - gps latitude, longitude + // ax ay - accelarometer X,Y + pc.printf("Read sensors\n\r"); + read_sensors(); + snprintf(data,256,"{\"la\":%s,\"lo\":%s,\"ax\":%s,\"ay\":%s,\"oc\":%d,\"or\":%d,\"ol\":%d,\"os\":%d}",SENSOR_DATA.GPS_Latitude,SENSOR_DATA.GPS_Longitude,SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,coolant_temp,engine_rpm,engine_load,vehicle_speed); + // publish json and wait for result + pubnub_res rslt = pubnub_publish(pbp, "carpal2", data); + if (rslt != PNR_STARTED) { + pc.printf("Failed to start publishing, rslt=%d"CRLF, rslt); rled = 1; gled = 0; } else { - pc.printf("Published! Response from Pubnub: %s"CRLF, pubnub_last_publish_result(pbp)); - rled = 0; - gled = 1; + rslt = pubnub_await(pbp); + if (rslt != PNR_OK) { + pc.printf("Failed to finished publishing, rslt=%d"CRLF, rslt); + rled = 1; + gled = 0; + } else { + pc.printf("Published! Response from Pubnub: %s"CRLF, pubnub_last_publish_result(pbp)); + rled = 0; + gled = 1; + } } - } - rslt = pubnub_subscribe(pbp, "carpal2", 0); - if (rslt != PNR_STARTED) { - pc.printf("Failed to start subscribing, rslt=%d"CRLF, rslt); - rled = 1; - gled = 0; - } else { - rslt = pubnub_await(pbp); - if (rslt != PNR_OK) { - pc.printf("Failed to finished subscribing, rslt=%d"CRLF, rslt);\ + rslt = pubnub_subscribe(pbp, "carpal2", 0); + if (rslt != PNR_STARTED) { + pc.printf("Failed to start subscribing, rslt=%d"CRLF, rslt); rled = 1; gled = 0; } else { - pc.printf("Subscribed! Received messages follow:"CRLF); - while (char const *msg = pubnub_get(pbp)) { - pc.printf("subscribe got: %s"CRLF, msg); - parse_JSON(msg); - } - } - rled = 0; - gled = 1; - } // subscribe result + rslt = pubnub_await(pbp); + if (rslt != PNR_OK) { + pc.printf("Failed to finished subscribing, rslt=%d"CRLF, rslt);\ + rled = 1; + gled = 0; + } else { + pc.printf("Subscribed! Received messages follow:"CRLF); + while (char const *msg = pubnub_get(pbp)) { + pc.printf("subscribe got: %s"CRLF, msg); + parse_JSON(msg); + } + } + rled = 0; + gled = 1; + } // subscribe result + } else { + rled = 1; + gled = 0; + pc.printf("Ignition off... attempting Init()\n\r"); + Init(); + } // end isIgnitionOn } // end timer expired } // end infinite loop } @@ -445,7 +454,9 @@ reslen=pid_reslen[pid]; sprintf(cmd_str, "01%02X\r", pid); + pc.printf("get_pid - stn1110_write\n\r"); stn1110_write(cmd_str); + pc.printf("get_pid - stn1110_read\n\r"); stn1110_read(str, STRLEN); if(stn1110_check_response(cmd_str, str)!=0)