whatever

Dependencies:   C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed

Fork of PONY_Ph0-uAXIS by Sean McBeath

Committer:
sgmcb
Date:
Thu Jan 07 23:03:22 2016 +0000
Revision:
49:a8c40c816199
Parent:
48:3512b3c7a5ae
Child:
50:bba466f093a4
About to change device keys

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lawliet 0:4e3cb26f6019 1 #include "mbed.h"
mazgch 9:26f694bc31b4 2
mazgch 19:f022ff746eb8 3 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 4 // C027 Support Libraries
mazgch 19:f022ff746eb8 5 #include "GPS.h"
mazgch 19:f022ff746eb8 6 #include "MDM.h"
sgmcb 36:258f3bb1c6a4 7
sgmcb 42:8e6e647cb7d5 8 // M2X Support Libraries
sgmcb 38:d86e744166b6 9 #include <jsonlite.h>
sgmcb 38:d86e744166b6 10 #include "M2XStreamClient.h"
sgmcb 37:71ab32b61dfb 11
sgmcb 42:8e6e647cb7d5 12 // PONY-specific config support libraries
sgmcb 41:f603d76dc6fe 13 #include "LIS331.h"
sgmcb 42:8e6e647cb7d5 14 #include "PONY_Loc.h" // PONY Location Code
sgmcb 41:f603d76dc6fe 15 #include "PONY_sense.h"
lawliet 0:4e3cb26f6019 16
sgmcb 41:f603d76dc6fe 17 //----
sgmcb 41:f603d76dc6fe 18 // DEBUG DEFINITIONS
sgmcb 48:3512b3c7a5ae 19 //#define THROWAWAY
sgmcb 47:d9180474fa1e 20 //#define MDMDEBUG
sgmcb 45:0d8cb417a9e2 21 #define LOCDEBUG
sgmcb 37:71ab32b61dfb 22
sgmcb 38:d86e744166b6 23 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 24 // Cellular modem/SIM parameters
sgmcb 38:d86e744166b6 25 #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs.
sgmcb 38:d86e744166b6 26 #define APN "m2m.com.attz" // Defined AT&T M2M APN
sgmcb 38:d86e744166b6 27 #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 38:d86e744166b6 28 #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 38:d86e744166b6 29
sgmcb 38:d86e744166b6 30 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 31 // AT&T M2X Kekys
sgmcb 38:d86e744166b6 32
sgmcb 41:f603d76dc6fe 33
sgmcb 41:f603d76dc6fe 34 #ifdef THROWAWAY
sgmcb 41:f603d76dc6fe 35 // Codes for a throwaway M2X device
sgmcb 39:c14aff678b25 36 #define M2XAPIKEY "54c6bbf11012f34830bd23cc091ca250"
sgmcb 39:c14aff678b25 37 #define DEVID "b9c57667ee0495dc0b3cddd890f8d2df"
sgmcb 41:f603d76dc6fe 38 #endif
sgmcb 41:f603d76dc6fe 39
sgmcb 41:f603d76dc6fe 40 #ifndef THROWAWAY
sgmcb 48:3512b3c7a5ae 41 // v1.4 codes
sgmcb 48:3512b3c7a5ae 42 #define M2XAPIKEY "537d09e921aa6589523e10aecde17a44"
sgmcb 48:3512b3c7a5ae 43 #define DEVID "59a85c486aaf8dd427945320f4f779eb"
sgmcb 41:f603d76dc6fe 44 #endif
sgmcb 41:f603d76dc6fe 45
sgmcb 38:d86e744166b6 46
sgmcb 38:d86e744166b6 47 //------------------------------------------------------------------------------------
sgmcb 39:c14aff678b25 48 // PIN Config
sgmcb 41:f603d76dc6fe 49 DigitalOut led1(LED1);
sgmcb 41:f603d76dc6fe 50 DigitalOut led2(LED2);
sgmcb 39:c14aff678b25 51
sgmcb 41:f603d76dc6fe 52 AnalogIn tempPin(P0_23);
sgmcb 49:a8c40c816199 53 //AnalogIn tempGnd(P0_24);
sgmcb 38:d86e744166b6 54
sgmcb 41:f603d76dc6fe 55 //I2C axis(P0_0, P0_1); // SDA, SCL
sgmcb 44:bd259a4c83bb 56 //LIS331 axle(P0_0, P0_1); // Library object
sgmcb 38:d86e744166b6 57
sgmcb 38:d86e744166b6 58
sgmcb 42:8e6e647cb7d5 59 //------------------------------------------------------------------------------------
sgmcb 42:8e6e647cb7d5 60 // GLOBAL VARIABLES
sgmcb 38:d86e744166b6 61
sgmcb 41:f603d76dc6fe 62 Ticker flipper;
sgmcb 38:d86e744166b6 63
sgmcb 42:8e6e647cb7d5 64 // M2X Drivers
sgmcb 38:d86e744166b6 65 Client client;
sgmcb 38:d86e744166b6 66 M2XStreamClient m2xClient(&client, M2XAPIKEY);
sgmcb 40:82b70b92169e 67 int M2X_response; // For m2x message responses
sgmcb 38:d86e744166b6 68
sgmcb 42:8e6e647cb7d5 69
sgmcb 40:82b70b92169e 70 char statusBuf[145] = "";
sgmcb 40:82b70b92169e 71
sgmcb 42:8e6e647cb7d5 72 // Location reading
sgmcb 48:3512b3c7a5ae 73 unsigned int kLocLoopDelayDef = 30 * 1000; // The default loop waiting time for location reads
sgmcb 48:3512b3c7a5ae 74 unsigned int kLocLoopDelay = kLocLoopDelayDef;
sgmcb 47:d9180474fa1e 75
sgmcb 47:d9180474fa1e 76
sgmcb 40:82b70b92169e 77 unsigned int kReadingDelay = 3 * 60 * 1000; // How many seconds to wait between reads
sgmcb 39:c14aff678b25 78 unsigned int kReadingDelayClimb = 15000; // How many seconds to add to the wait period when sitting idle
sgmcb 39:c14aff678b25 79 unsigned int kReadingDelayMax = 5 * 60000; // What's the maximum time between readings?
sgmcb 38:d86e744166b6 80
sgmcb 39:c14aff678b25 81
sgmcb 42:8e6e647cb7d5 82 // System time
sgmcb 41:f603d76dc6fe 83 time_t kSysSeconds = time(NULL);
sgmcb 47:d9180474fa1e 84 time_t thisTime = time(NULL);
sgmcb 41:f603d76dc6fe 85 bool kSysClockSet = false;
sgmcb 41:f603d76dc6fe 86 tm kFormatTime;
sgmcb 39:c14aff678b25 87
sgmcb 39:c14aff678b25 88
sgmcb 47:d9180474fa1e 89
sgmcb 42:8e6e647cb7d5 90 // Global function definitions
sgmcb 38:d86e744166b6 91
sgmcb 41:f603d76dc6fe 92 void flip() {
sgmcb 41:f603d76dc6fe 93 led1 = !led1;
sgmcb 41:f603d76dc6fe 94 }
sgmcb 41:f603d76dc6fe 95
sgmcb 38:d86e744166b6 96
sgmcb 38:d86e744166b6 97 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 98 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 99 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 100 int main(void)
sgmcb 38:d86e744166b6 101 {
sgmcb 38:d86e744166b6 102
sgmcb 49:a8c40c816199 103 printf("\r\n\n\n\n-----\r\nI'm alive - vers. uA - device codes PONY_v1.4\r\n\n");
sgmcb 41:f603d76dc6fe 104 #ifdef THROWAWAY
sgmcb 41:f603d76dc6fe 105 printf("Using THROWAWAY M2X device\r\n");
sgmcb 41:f603d76dc6fe 106 #endif
sgmcb 49:a8c40c816199 107
sgmcb 49:a8c40c816199 108 #ifndef THROWAWAY
sgmcb 49:a8c40c816199 109 printf("Using PONY_v1.4 M2X device\r\n");
sgmcb 49:a8c40c816199 110 #endif
sgmcb 49:a8c40c816199 111
sgmcb 41:f603d76dc6fe 112
sgmcb 38:d86e744166b6 113 MDMSerial mdm;
sgmcb 39:c14aff678b25 114 MDMParser::DevStatus devStatus = {};
sgmcb 44:bd259a4c83bb 115 MDMParser::NetStatus netStatus = {};
sgmcb 39:c14aff678b25 116 bool mdmOk = mdm.init(SIMPIN, &devStatus);
sgmcb 46:ab4cccab10c9 117
sgmcb 41:f603d76dc6fe 118 #ifdef MDMDEBUG
sgmcb 46:ab4cccab10c9 119 mdm.setDebug(4);
sgmcb 41:f603d76dc6fe 120 #endif
sgmcb 41:f603d76dc6fe 121
sgmcb 43:80aa0c933e1a 122 // ----------------
sgmcb 42:8e6e647cb7d5 123 // LOCATION READING
sgmcb 39:c14aff678b25 124
sgmcb 38:d86e744166b6 125
sgmcb 44:bd259a4c83bb 126 // OPEN MODEM CONNECTION
sgmcb 38:d86e744166b6 127 if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD))
sgmcb 44:bd259a4c83bb 128 return -1;
sgmcb 44:bd259a4c83bb 129
sgmcb 44:bd259a4c83bb 130 // SET DEEP SCAN MODE
sgmcb 44:bd259a4c83bb 131 printf("Configure deep scan mode\r\n");
sgmcb 44:bd259a4c83bb 132 int locConf = mdm.cellLocConfigSensor(1);
sgmcb 44:bd259a4c83bb 133
sgmcb 38:d86e744166b6 134
sgmcb 40:82b70b92169e 135 // Cell location data
sgmcb 49:a8c40c816199 136 MDMSerial::CellLocData thisLoc;
sgmcb 44:bd259a4c83bb 137
sgmcb 48:3512b3c7a5ae 138 // Location loop driving variables
sgmcb 45:0d8cb417a9e2 139 int loopIter = 0;
sgmcb 48:3512b3c7a5ae 140 bool sendStatus = false;
sgmcb 45:0d8cb417a9e2 141
sgmcb 45:0d8cb417a9e2 142 // Loop timing variables
sgmcb 45:0d8cb417a9e2 143 Timer cellLocDelay;
sgmcb 45:0d8cb417a9e2 144
sgmcb 45:0d8cb417a9e2 145 int cellLocPeriod = 30; // in seconds
sgmcb 45:0d8cb417a9e2 146 int timeoutMargin = 5; // in seconds
sgmcb 45:0d8cb417a9e2 147
sgmcb 45:0d8cb417a9e2 148
sgmcb 45:0d8cb417a9e2 149 // Location data filter variables
sgmcb 40:82b70b92169e 150 int locAccLower = 50; // Immediately accept locations with uncertainty lower than this
sgmcb 40:82b70b92169e 151 int locAccUpper = 5000; // Don't accept locations with uncertainty greater than this
sgmcb 46:ab4cccab10c9 152
sgmcb 46:ab4cccab10c9 153 // Filter counters
sgmcb 47:d9180474fa1e 154 int fail1count = 0;
sgmcb 47:d9180474fa1e 155 int fail2count = 0;
sgmcb 47:d9180474fa1e 156 int fail3count = 0;
sgmcb 41:f603d76dc6fe 157
sgmcb 41:f603d76dc6fe 158
sgmcb 45:0d8cb417a9e2 159 // Cell location call variables
sgmcb 45:0d8cb417a9e2 160 const int sensorMask = 2; // 1 = GNSS, 2 = CellLocate (aka cell grid position info), 3 = Hybrid: GNSS + CellLocate
sgmcb 45:0d8cb417a9e2 161 int cellLocReqTimeout = cellLocPeriod - timeoutMargin; // in seconds
sgmcb 45:0d8cb417a9e2 162 const int targetAccuracy = 1; // in meters
sgmcb 45:0d8cb417a9e2 163
sgmcb 45:0d8cb417a9e2 164
sgmcb 42:8e6e647cb7d5 165 // -----------------------
sgmcb 40:82b70b92169e 166 // Location reporting loop
sgmcb 40:82b70b92169e 167 while(true) {
sgmcb 40:82b70b92169e 168
sgmcb 44:bd259a4c83bb 169 // Set some important variables
sgmcb 41:f603d76dc6fe 170 M2X_response = 0;
sgmcb 48:3512b3c7a5ae 171 sendStatus = 0;
sgmcb 40:82b70b92169e 172 loopIter++;
sgmcb 40:82b70b92169e 173
sgmcb 45:0d8cb417a9e2 174 //printf("tick\r\n");
sgmcb 45:0d8cb417a9e2 175
sgmcb 45:0d8cb417a9e2 176 // Request to fill cell-location buffer
sgmcb 45:0d8cb417a9e2 177 cellLocDelay.start();
sgmcb 47:d9180474fa1e 178 #ifdef LOCDEBUG
sgmcb 47:d9180474fa1e 179 printf("Initiate cellLocRequest call...\r\n");
sgmcb 47:d9180474fa1e 180 #endif
sgmcb 45:0d8cb417a9e2 181 mdm.cellLocRequest(sensorMask, cellLocReqTimeout, targetAccuracy);
sgmcb 41:f603d76dc6fe 182
sgmcb 47:d9180474fa1e 183
sgmcb 47:d9180474fa1e 184 // Hold next functions until we give cellLocRequest time to execute.
sgmcb 46:ab4cccab10c9 185 while((cellLocDelay.read() < cellLocReqTimeout) && (!mdm.cellLocGet(&thisLoc)) ) {
sgmcb 45:0d8cb417a9e2 186 // Nothin much
sgmcb 45:0d8cb417a9e2 187 };
sgmcb 47:d9180474fa1e 188
sgmcb 45:0d8cb417a9e2 189 // Stop and reset cellLocDelay timer
sgmcb 47:d9180474fa1e 190 cellLocDelay.stop();cellLocDelay.reset();
sgmcb 45:0d8cb417a9e2 191
sgmcb 45:0d8cb417a9e2 192 // We've either got SOME location data or we've timed out. There are three filters:
sgmcb 45:0d8cb417a9e2 193 // 1. Does it exist?
sgmcb 45:0d8cb417a9e2 194 // 2. Is it new, or extrapolated from old info?
sgmcb 45:0d8cb417a9e2 195 // 3. Is the uncertainty within our accepted range?
sgmcb 45:0d8cb417a9e2 196
sgmcb 45:0d8cb417a9e2 197 /* N.B.
sgmcb 45:0d8cb417a9e2 198 Right now I'm conducting these tests serially in the loop in ancitipation of behavior that will modify itself based on whether we're seeing lots of highly uncertain or extrapolated readings;
sgmcb 45:0d8cb417a9e2 199 not sure what that behavior is yet, but we're not optimizing enough that I care about nesting conditionals yet.
sgmcb 45:0d8cb417a9e2 200 */
sgmcb 41:f603d76dc6fe 201
sgmcb 45:0d8cb417a9e2 202 // 1. Does the location data exist?
sgmcb 47:d9180474fa1e 203 if( thisLoc.validData ) {//if( (mdm.cellLocGet(&thisLoc)) ) {
sgmcb 46:ab4cccab10c9 204 fail1count = 0;
sgmcb 45:0d8cb417a9e2 205 #ifdef LOCDEBUG
sgmcb 45:0d8cb417a9e2 206 printf("LOC uncertainty= %d, sensor= %d\r\n", thisLoc.uncertainty, thisLoc.sensorUsed );
sgmcb 45:0d8cb417a9e2 207 printf("LOC = latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", thisLoc.latitude, thisLoc.longitude, thisLoc.altitude);
sgmcb 45:0d8cb417a9e2 208 #endif
sgmcb 45:0d8cb417a9e2 209
sgmcb 47:d9180474fa1e 210
sgmcb 47:d9180474fa1e 211 (thisLoc.time).tm_year -= 1900;
sgmcb 47:d9180474fa1e 212 kSysSeconds = mktime( &(thisLoc.time) );
sgmcb 47:d9180474fa1e 213
sgmcb 47:d9180474fa1e 214 // Set the system clock, if it's not already
sgmcb 47:d9180474fa1e 215 if(!kSysClockSet) {
sgmcb 47:d9180474fa1e 216 set_time(kSysSeconds);
sgmcb 47:d9180474fa1e 217 printf("\033[31mSet system clock time.\033[39m\r\n");
sgmcb 47:d9180474fa1e 218 kSysClockSet=true;
sgmcb 47:d9180474fa1e 219 }
sgmcb 49:a8c40c816199 220 #ifdef LOCDEBUG
sgmcb 49:a8c40c816199 221 printf("LOC read at: %s\r", ctime(&kSysSeconds) );
sgmcb 49:a8c40c816199 222 #endif
sgmcb 47:d9180474fa1e 223
sgmcb 47:d9180474fa1e 224
sgmcb 47:d9180474fa1e 225
sgmcb 45:0d8cb417a9e2 226 // 2. Is this new position data, or extrapolated from an old reading?
sgmcb 45:0d8cb417a9e2 227 if(thisLoc.sensorUsed == 2) {
sgmcb 46:ab4cccab10c9 228 fail2count = 0;
sgmcb 45:0d8cb417a9e2 229 #ifdef LOCDEBUG
sgmcb 45:0d8cb417a9e2 230 printf("LOC has new information (non-extrapolation)\r\n");
sgmcb 45:0d8cb417a9e2 231 #endif
sgmcb 45:0d8cb417a9e2 232
sgmcb 45:0d8cb417a9e2 233 // 3. Is this data acceptably accurate (e.g. low enough reported uncertainty)?
sgmcb 45:0d8cb417a9e2 234 if( (thisLoc.uncertainty < locAccUpper) && (thisLoc.uncertainty > 0) ) {
sgmcb 46:ab4cccab10c9 235 fail3count = 0;
sgmcb 45:0d8cb417a9e2 236 #ifdef LOCDEBUG
sgmcb 45:0d8cb417a9e2 237 printf("LOC has suitable uncertainty (<%i).\r\n", locAccUpper);
sgmcb 45:0d8cb417a9e2 238 #endif
sgmcb 45:0d8cb417a9e2 239
sgmcb 45:0d8cb417a9e2 240
sgmcb 47:d9180474fa1e 241 // PASSSES ALL 3 TESTS => REPORT TO M2X
sgmcb 45:0d8cb417a9e2 242
sgmcb 45:0d8cb417a9e2 243 // Report position
sgmcb 48:3512b3c7a5ae 244 printf("\r\n\033[34mTRANSMIT LOCATION DATA:\033[39m\r\nla=%0.5f, lo=%0.5f, alt=%d\r\n", thisLoc.latitude, thisLoc.longitude, thisLoc.altitude);
sgmcb 45:0d8cb417a9e2 245 M2X_response = m2xClient.updateLocation(DEVID, "pony-spot", (double) thisLoc.latitude, (double) thisLoc.longitude, (double) thisLoc.altitude);
sgmcb 45:0d8cb417a9e2 246 if(M2X_response == 202)
sgmcb 45:0d8cb417a9e2 247 printf("Location POST successful\r\n");
sgmcb 45:0d8cb417a9e2 248
sgmcb 45:0d8cb417a9e2 249 // Report uncertainty
sgmcb 45:0d8cb417a9e2 250 M2X_response = m2xClient.updateStreamValue(DEVID, "locacc", thisLoc.uncertainty);
sgmcb 45:0d8cb417a9e2 251 if(M2X_response == 202)
sgmcb 47:d9180474fa1e 252 printf("Location Confidence (%d) POST successful\r\n", thisLoc.uncertainty);
sgmcb 47:d9180474fa1e 253
sgmcb 49:a8c40c816199 254
sgmcb 49:a8c40c816199 255 // Report temperature
sgmcb 49:a8c40c816199 256 float thisTemp = getTemp(&tempPin);
sgmcb 49:a8c40c816199 257 printf("temp=%.1fC\r\n",thisTemp);
sgmcb 49:a8c40c816199 258
sgmcb 49:a8c40c816199 259 M2X_response = m2xClient.updateStreamValue(DEVID, "kegtemp", thisTemp);
sgmcb 49:a8c40c816199 260 if(M2X_response == 202)
sgmcb 49:a8c40c816199 261 printf("Temperature (%.2f) POST successful\r\n", thisTemp);
sgmcb 49:a8c40c816199 262
sgmcb 49:a8c40c816199 263
sgmcb 47:d9180474fa1e 264 // Report system time
sgmcb 47:d9180474fa1e 265 thisTime = time(NULL);
sgmcb 47:d9180474fa1e 266 M2X_response = m2xClient.updateStreamValue(DEVID, "systime", ctime(&thisTime) );
sgmcb 47:d9180474fa1e 267 if(M2X_response == 202)
sgmcb 48:3512b3c7a5ae 268 printf("Systime POST successful - %s \r", ctime(&thisTime) );
sgmcb 47:d9180474fa1e 269
sgmcb 47:d9180474fa1e 270
sgmcb 45:0d8cb417a9e2 271 }
sgmcb 45:0d8cb417a9e2 272 // Fails 3:
sgmcb 45:0d8cb417a9e2 273 else {
sgmcb 49:a8c40c816199 274 fail3count++;
sgmcb 45:0d8cb417a9e2 275 #ifdef LOCDEBUG
sgmcb 45:0d8cb417a9e2 276 printf("LOC has high uncertainty (<%i); will not report.\r\n", thisLoc.uncertainty);
sgmcb 45:0d8cb417a9e2 277 #endif
sgmcb 45:0d8cb417a9e2 278 }
sgmcb 45:0d8cb417a9e2 279 }
sgmcb 45:0d8cb417a9e2 280 // Fails 2:
sgmcb 45:0d8cb417a9e2 281 else {
sgmcb 49:a8c40c816199 282 fail2count++;
sgmcb 45:0d8cb417a9e2 283 #ifdef LOCDEBUG
sgmcb 47:d9180474fa1e 284 printf("LOC is extrapolated information; disregard.\r\n");
sgmcb 46:ab4cccab10c9 285 #endif
sgmcb 46:ab4cccab10c9 286
sgmcb 45:0d8cb417a9e2 287 }
sgmcb 45:0d8cb417a9e2 288 }
sgmcb 49:a8c40c816199 289
sgmcb 46:ab4cccab10c9 290 // Fails 1 and timer is up:
sgmcb 45:0d8cb417a9e2 291 else {
sgmcb 46:ab4cccab10c9 292 ++fail1count;
sgmcb 45:0d8cb417a9e2 293 printf("CellLocRequest timeout; no location data available.\r\n");
sgmcb 47:d9180474fa1e 294 }
sgmcb 47:d9180474fa1e 295
sgmcb 49:a8c40c816199 296
sgmcb 49:a8c40c816199 297
sgmcb 49:a8c40c816199 298
sgmcb 49:a8c40c816199 299
sgmcb 49:a8c40c816199 300 // --------------------
sgmcb 47:d9180474fa1e 301 // DETERMINE LOOP DELAY
sgmcb 47:d9180474fa1e 302
sgmcb 47:d9180474fa1e 303
sgmcb 47:d9180474fa1e 304
sgmcb 47:d9180474fa1e 305 // TODO: Add conditionals to handle successful location and unsuccessful communication with M2X
sgmcb 46:ab4cccab10c9 306
sgmcb 48:3512b3c7a5ae 307 // ACTIONS BASED ON LOCATION READ SUCCESS/FAILURE
sgmcb 48:3512b3c7a5ae 308
sgmcb 47:d9180474fa1e 309 // Successful read
sgmcb 49:a8c40c816199 310 if( (!fail1count) && (!fail2count) && (!fail3count) ) {
sgmcb 49:a8c40c816199 311 kLocLoopDelay = 1 * (60 * 1000); // Set # minute wait before next read
sgmcb 47:d9180474fa1e 312 printf("Successful LOC read; ");
sgmcb 45:0d8cb417a9e2 313 }
sgmcb 48:3512b3c7a5ae 314 // Too many invalid location reads
sgmcb 48:3512b3c7a5ae 315 else if (fail1count > 10) {
sgmcb 48:3512b3c7a5ae 316 sprintf(statusBuf, "Fail1count exceeds 10.\r\n");
sgmcb 48:3512b3c7a5ae 317 printf(statusBuf);
sgmcb 48:3512b3c7a5ae 318 fail1count = 0;
sgmcb 48:3512b3c7a5ae 319 sendStatus = true;
sgmcb 47:d9180474fa1e 320 }
sgmcb 48:3512b3c7a5ae 321
sgmcb 48:3512b3c7a5ae 322 else if (fail2count > 10) {
sgmcb 48:3512b3c7a5ae 323 sprintf(statusBuf, "Fail2count exceeds 10.\r\n");
sgmcb 48:3512b3c7a5ae 324 printf(statusBuf);
sgmcb 48:3512b3c7a5ae 325 fail2count = 0;
sgmcb 48:3512b3c7a5ae 326 sendStatus = true;
sgmcb 48:3512b3c7a5ae 327 }
sgmcb 48:3512b3c7a5ae 328
sgmcb 48:3512b3c7a5ae 329 else if (fail3count > 10) {
sgmcb 48:3512b3c7a5ae 330 sprintf(statusBuf, "Fail3Count exceeds 10.\r\n");
sgmcb 48:3512b3c7a5ae 331 printf(statusBuf);
sgmcb 48:3512b3c7a5ae 332 fail3count = 0;
sgmcb 48:3512b3c7a5ae 333 sendStatus = true;
sgmcb 48:3512b3c7a5ae 334 }
sgmcb 48:3512b3c7a5ae 335
sgmcb 47:d9180474fa1e 336 else {
sgmcb 48:3512b3c7a5ae 337 kLocLoopDelay = kLocLoopDelayDef;
sgmcb 47:d9180474fa1e 338 printf("Failed LOC loop; ");
sgmcb 47:d9180474fa1e 339 }
sgmcb 47:d9180474fa1e 340
sgmcb 49:a8c40c816199 341 // If we have no status update to send, send one every 10 loops just cause.
sgmcb 49:a8c40c816199 342 if (!sendStatus && (loopIter % 10 == 0) ) {
sgmcb 49:a8c40c816199 343 sprintf(statusBuf, "Periodic status update check-in.\r\n");
sgmcb 49:a8c40c816199 344 printf(statusBuf);
sgmcb 49:a8c40c816199 345 sendStatus = true;
sgmcb 49:a8c40c816199 346 }
sgmcb 49:a8c40c816199 347
sgmcb 48:3512b3c7a5ae 348 // Transmit a status response?
sgmcb 48:3512b3c7a5ae 349 if(sendStatus) {
sgmcb 48:3512b3c7a5ae 350 M2X_response = m2xClient.updateStreamValue(DEVID, "status", statusBuf);
sgmcb 48:3512b3c7a5ae 351 if(M2X_response == 202)
sgmcb 48:3512b3c7a5ae 352 printf("Status POST successful\r\n");
sgmcb 48:3512b3c7a5ae 353 }
sgmcb 47:d9180474fa1e 354
sgmcb 47:d9180474fa1e 355 // Set loop delay (i.e. period)
sgmcb 47:d9180474fa1e 356 printf("loop waiting for %i seconds...\r\n---\n\r\n", (kLocLoopDelay / 1000) );
sgmcb 47:d9180474fa1e 357
sgmcb 48:3512b3c7a5ae 358 flipper.attach(&flip, 0.5); // LED toggle! // the address of the function to be attached (flip) and the interval (2 seconds)
sgmcb 48:3512b3c7a5ae 359 delay(kLocLoopDelay);
sgmcb 48:3512b3c7a5ae 360 led1 = 0; // Turn that LED off!
sgmcb 40:82b70b92169e 361
sgmcb 40:82b70b92169e 362 }
sgmcb 38:d86e744166b6 363
sgmcb 39:c14aff678b25 364
sgmcb 40:82b70b92169e 365 //mdm.disconnect();
sgmcb 40:82b70b92169e 366 //mdm.powerOff();
msinig 35:16f1037626e3 367
lawliet 0:4e3cb26f6019 368 }