whatever

Dependencies:   C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed

Fork of PONY_Ph0-uAXIS by Sean McBeath

Committer:
sgmcb
Date:
Tue Dec 29 06:56:52 2015 +0000
Revision:
41:f603d76dc6fe
Parent:
40:82b70b92169e
Child:
42:8e6e647cb7d5
pre-Bend return test

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 //------------------------------------------------------------------------------------
mazgch 11:b8505cbbd55c 4 /* This example was tested on C027-U20 and C027-G35 with the on board modem.
mazgch 11:b8505cbbd55c 5
mazgch 18:50e6c4ed8a4a 6 Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON
mazgch 11:b8505cbbd55c 7 is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this
mazgch 11:b8505cbbd55c 8 configuration the following platforms were tested (it is likely that others
mazgch 11:b8505cbbd55c 9 will work as well)
mazgch 19:f022ff746eb8 10 - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD)
mazgch 18:50e6c4ed8a4a 11 - NXP: LPC1549v2, LPC4088qsb
mazgch 18:50e6c4ed8a4a 12 - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F
mazgch 12:96c7b62c7aaf 13 - STM: NUCLEO-F401RE, NUCLEO-F030R8
mazgch 18:50e6c4ed8a4a 14 mount resistors SB13/14 1k, SB62/63 0R
mazgch 11:b8505cbbd55c 15 */
sgmcb 36:258f3bb1c6a4 16
sgmcb 38:d86e744166b6 17 // C027 Support Libraries
mazgch 19:f022ff746eb8 18 #include "GPS.h"
mazgch 19:f022ff746eb8 19 #include "MDM.h"
sgmcb 36:258f3bb1c6a4 20
sgmcb 38:d86e744166b6 21 #include <jsonlite.h>
sgmcb 38:d86e744166b6 22 #include "M2XStreamClient.h"
sgmcb 37:71ab32b61dfb 23
sgmcb 41:f603d76dc6fe 24 #include "LIS331.h"
sgmcb 41:f603d76dc6fe 25 #include "PONY_sense.h"
lawliet 0:4e3cb26f6019 26
sgmcb 36:258f3bb1c6a4 27
sgmcb 36:258f3bb1c6a4 28
sgmcb 41:f603d76dc6fe 29 //----
sgmcb 41:f603d76dc6fe 30 // DEBUG DEFINITIONS
sgmcb 36:258f3bb1c6a4 31
sgmcb 41:f603d76dc6fe 32 #define THROWAWAY
sgmcb 36:258f3bb1c6a4 33
sgmcb 41:f603d76dc6fe 34 //#define MDMDEBUG
sgmcb 37:71ab32b61dfb 35
sgmcb 37:71ab32b61dfb 36
sgmcb 37:71ab32b61dfb 37
sgmcb 36:258f3bb1c6a4 38
sgmcb 38:d86e744166b6 39 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 40 // Cellular modem/SIM parameters
sgmcb 38:d86e744166b6 41 #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs.
sgmcb 38:d86e744166b6 42 #define APN "m2m.com.attz" // Defined AT&T M2M APN
sgmcb 38:d86e744166b6 43 #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 38:d86e744166b6 44 #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 38:d86e744166b6 45
sgmcb 38:d86e744166b6 46
sgmcb 38:d86e744166b6 47
sgmcb 38:d86e744166b6 48 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 49 // AT&T M2X Kekys
sgmcb 38:d86e744166b6 50
sgmcb 41:f603d76dc6fe 51
sgmcb 41:f603d76dc6fe 52 #ifdef THROWAWAY
sgmcb 41:f603d76dc6fe 53 // Codes for a throwaway M2X device
sgmcb 39:c14aff678b25 54 #define M2XAPIKEY "54c6bbf11012f34830bd23cc091ca250"
sgmcb 39:c14aff678b25 55 #define DEVID "b9c57667ee0495dc0b3cddd890f8d2df"
sgmcb 41:f603d76dc6fe 56 #endif
sgmcb 41:f603d76dc6fe 57
sgmcb 41:f603d76dc6fe 58 #ifndef THROWAWAY
sgmcb 41:f603d76dc6fe 59 // v1.2 codes
sgmcb 41:f603d76dc6fe 60 #define M2XAPIKEY "bbc483492238dc76f7d12f0cd6e13a4b"
sgmcb 41:f603d76dc6fe 61 #define DEVID "3764db38b6c9ec4045a38e0125b14b4c"
sgmcb 41:f603d76dc6fe 62 #endif
sgmcb 41:f603d76dc6fe 63
sgmcb 38:d86e744166b6 64
sgmcb 38:d86e744166b6 65 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 66
sgmcb 38:d86e744166b6 67 #include "PONY_Loc.h" // PONY Location Code
sgmcb 39:c14aff678b25 68 #include "H3LIS331DL.h" // Accelerometer library
sgmcb 39:c14aff678b25 69
sgmcb 39:c14aff678b25 70
sgmcb 39:c14aff678b25 71
sgmcb 39:c14aff678b25 72
sgmcb 39:c14aff678b25 73 // PIN Config
sgmcb 39:c14aff678b25 74 DigitalIn jostle(P2_13);
sgmcb 39:c14aff678b25 75
sgmcb 41:f603d76dc6fe 76 DigitalOut led1(LED1);
sgmcb 41:f603d76dc6fe 77 DigitalOut led2(LED2);
sgmcb 39:c14aff678b25 78
sgmcb 41:f603d76dc6fe 79 AnalogIn tempPin(P0_23);
sgmcb 41:f603d76dc6fe 80 AnalogIn tempGnd(P0_24);
sgmcb 38:d86e744166b6 81
sgmcb 41:f603d76dc6fe 82 //I2C axis(P0_0, P0_1); // SDA, SCL
sgmcb 41:f603d76dc6fe 83 LIS331 axle(P0_0, P0_1); // Library object
sgmcb 38:d86e744166b6 84
sgmcb 38:d86e744166b6 85
sgmcb 38:d86e744166b6 86
sgmcb 38:d86e744166b6 87 // GLOBALS
sgmcb 38:d86e744166b6 88
sgmcb 41:f603d76dc6fe 89 Ticker flipper;
sgmcb 38:d86e744166b6 90
sgmcb 38:d86e744166b6 91
sgmcb 38:d86e744166b6 92 Client client;
sgmcb 38:d86e744166b6 93 M2XStreamClient m2xClient(&client, M2XAPIKEY);
sgmcb 40:82b70b92169e 94 int M2X_response; // For m2x message responses
sgmcb 38:d86e744166b6 95
sgmcb 40:82b70b92169e 96 char statusBuf[145] = "";
sgmcb 40:82b70b92169e 97
sgmcb 40:82b70b92169e 98
sgmcb 40:82b70b92169e 99 unsigned int kReadingDelay = 3 * 60 * 1000; // How many seconds to wait between reads
sgmcb 39:c14aff678b25 100 unsigned int kReadingDelayClimb = 15000; // How many seconds to add to the wait period when sitting idle
sgmcb 39:c14aff678b25 101 unsigned int kReadingDelayMax = 5 * 60000; // What's the maximum time between readings?
sgmcb 38:d86e744166b6 102
sgmcb 38:d86e744166b6 103
sgmcb 38:d86e744166b6 104 double kLaLoDiffMin = 0.01;
sgmcb 38:d86e744166b6 105 double kAltDiffMin = 2.00;
sgmcb 38:d86e744166b6 106
sgmcb 41:f603d76dc6fe 107 float kTemp;
sgmcb 41:f603d76dc6fe 108
sgmcb 39:c14aff678b25 109 unsigned int kIdleSpins = 0;
sgmcb 39:c14aff678b25 110
sgmcb 41:f603d76dc6fe 111 //uint16_t kSysSeconds;
sgmcb 41:f603d76dc6fe 112 time_t kSysSeconds = time(NULL);
sgmcb 41:f603d76dc6fe 113 bool kSysClockSet = false;
sgmcb 41:f603d76dc6fe 114 tm kFormatTime;
sgmcb 39:c14aff678b25 115
sgmcb 39:c14aff678b25 116
sgmcb 39:c14aff678b25 117
sgmcb 39:c14aff678b25 118 void parseM2XLocation2(const char* name, double latitude, double longitude, double elevation, const char* timestamp, int index, void* context) {
sgmcb 39:c14aff678b25 119 printf("\n\n\n\n\n\n\n\n\n\n\n\n\nparseM2XLocation2\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
sgmcb 39:c14aff678b25 120 }
sgmcb 38:d86e744166b6 121
sgmcb 41:f603d76dc6fe 122 void flip() {
sgmcb 41:f603d76dc6fe 123 led1 = !led1;
sgmcb 41:f603d76dc6fe 124 }
sgmcb 41:f603d76dc6fe 125
sgmcb 38:d86e744166b6 126
sgmcb 38:d86e744166b6 127 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 128 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 129 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 130 int main(void)
sgmcb 38:d86e744166b6 131 {
sgmcb 38:d86e744166b6 132
sgmcb 41:f603d76dc6fe 133 printf("\r\n\n\n\n-----\r\nI'm alive - vers. uA\r\n\n");
sgmcb 41:f603d76dc6fe 134 #ifdef THROWAWAY
sgmcb 41:f603d76dc6fe 135 printf("Using THROWAWAY M2X device\r\n");
sgmcb 41:f603d76dc6fe 136 #endif
sgmcb 38:d86e744166b6 137
sgmcb 41:f603d76dc6fe 138 //int ret = 0;
sgmcb 41:f603d76dc6fe 139 //int len = 0;
sgmcb 41:f603d76dc6fe 140 //char buf[2048] = "";
sgmcb 41:f603d76dc6fe 141
sgmcb 38:d86e744166b6 142
sgmcb 38:d86e744166b6 143 MDMSerial mdm;
sgmcb 39:c14aff678b25 144 MDMParser::DevStatus devStatus = {};
sgmcb 39:c14aff678b25 145 MDMParser::NetStatus netStatus = {};
sgmcb 39:c14aff678b25 146 bool mdmOk = mdm.init(SIMPIN, &devStatus);
sgmcb 41:f603d76dc6fe 147 #ifdef MDMDEBUG
sgmcb 39:c14aff678b25 148 //mdm.setDebug(4);
sgmcb 41:f603d76dc6fe 149 #endif
sgmcb 41:f603d76dc6fe 150
sgmcb 41:f603d76dc6fe 151 //------------------------------------------------
sgmcb 41:f603d76dc6fe 152 //------------------------------------------------
sgmcb 41:f603d76dc6fe 153 // I2C TESTING
sgmcb 41:f603d76dc6fe 154 // Acceleromter object
sgmcb 41:f603d76dc6fe 155 //char ax[2];
sgmcb 39:c14aff678b25 156
sgmcb 39:c14aff678b25 157
sgmcb 39:c14aff678b25 158
sgmcb 41:f603d76dc6fe 159 //printf("Set up accelerometer\r\n");
sgmcb 41:f603d76dc6fe 160
sgmcb 41:f603d76dc6fe 161 printf("I2C write address ID: %01x\r\n",(LIS331_I2C_ADDRESS << 1) & 0xFE );
sgmcb 41:f603d76dc6fe 162 printf("I2C read address ID: %01x\r\n",(LIS331_I2C_ADDRESS << 1) | 0x01 );
sgmcb 41:f603d76dc6fe 163
sgmcb 41:f603d76dc6fe 164 printf("axleID=%01x\r\n", axle.getWhoAmI());
sgmcb 41:f603d76dc6fe 165
sgmcb 41:f603d76dc6fe 166 // Set and read power mode
sgmcb 41:f603d76dc6fe 167 axle.setPowerMode(NORMAL_400HZ);
sgmcb 41:f603d76dc6fe 168 printf("axle Power Mode = %01x\r\n",axle.getPowerMode());
sgmcb 41:f603d76dc6fe 169
sgmcb 41:f603d76dc6fe 170 printf("axle AccelStatus = %01x\r\n", axle.getAccelStatus());
sgmcb 41:f603d76dc6fe 171
sgmcb 41:f603d76dc6fe 172 //float axleAccelZ = ();
sgmcb 41:f603d76dc6fe 173
sgmcb 39:c14aff678b25 174
sgmcb 41:f603d76dc6fe 175
sgmcb 41:f603d76dc6fe 176 printf("Begin accel loop\r\n\n");
sgmcb 41:f603d76dc6fe 177 while(true){
sgmcb 41:f603d76dc6fe 178 printf("Z accel = %02f\r\n", axle.getAccelZ());
sgmcb 41:f603d76dc6fe 179 printf("X accel = %02f\r\n", axle.getAccelX());
sgmcb 41:f603d76dc6fe 180 printf("Y accel = %02f\r\n", axle.getAccelY());
sgmcb 41:f603d76dc6fe 181
sgmcb 41:f603d76dc6fe 182
sgmcb 41:f603d76dc6fe 183 delay(5000);
sgmcb 41:f603d76dc6fe 184 };
sgmcb 39:c14aff678b25 185
sgmcb 41:f603d76dc6fe 186
sgmcb 41:f603d76dc6fe 187
sgmcb 41:f603d76dc6fe 188
sgmcb 41:f603d76dc6fe 189
sgmcb 41:f603d76dc6fe 190
sgmcb 41:f603d76dc6fe 191
sgmcb 39:c14aff678b25 192
sgmcb 38:d86e744166b6 193
sgmcb 38:d86e744166b6 194 // Open modem connection
sgmcb 38:d86e744166b6 195 if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD))
sgmcb 38:d86e744166b6 196 return -1;
sgmcb 38:d86e744166b6 197
sgmcb 38:d86e744166b6 198
sgmcb 40:82b70b92169e 199
sgmcb 40:82b70b92169e 200 // Cell location call variables
sgmcb 40:82b70b92169e 201 const int sensorMask = 2; // 1 = GNSS, 2 = CellLocate, 3 = Hybrid: GNSS + CellLocate
sgmcb 41:f603d76dc6fe 202 //const int timeout = 55; // in seconds
sgmcb 40:82b70b92169e 203 const int targetAccuracy = 1; // meters
sgmcb 40:82b70b92169e 204
sgmcb 40:82b70b92169e 205 // Cell location data
sgmcb 41:f603d76dc6fe 206 MDMSerial::CellLocData ponyLoc, thisLoc;
sgmcb 40:82b70b92169e 207
sgmcb 40:82b70b92169e 208
sgmcb 40:82b70b92169e 209 printf("Configure deep scan mode\r\n");
sgmcb 40:82b70b92169e 210 int locConf = mdm.cellLocConfigSensor(1); // Set deep scan mode
sgmcb 40:82b70b92169e 211
sgmcb 41:f603d76dc6fe 212 // Set CellLocate server connection
sgmcb 41:f603d76dc6fe 213 //printf("\033[33mConnect to CellLocate server...\033[39m\r\n");
sgmcb 41:f603d76dc6fe 214 //if (!mdm.cellLocSrvHttp("tFpJ8NlWXUa8keKu3UY4AQ"))
sgmcb 41:f603d76dc6fe 215 // mdm.cellLocSrvUdp();
sgmcb 41:f603d76dc6fe 216
sgmcb 41:f603d76dc6fe 217 // Set URCs?
sgmcb 41:f603d76dc6fe 218 //printf("Congifure URCs\r\n");
sgmcb 41:f603d76dc6fe 219 //mdm.cellLocUnsolIndication(1);
sgmcb 41:f603d76dc6fe 220
sgmcb 40:82b70b92169e 221 // Loop driving variables
sgmcb 40:82b70b92169e 222 bool locLock;
sgmcb 41:f603d76dc6fe 223 int submitPeriod = 30;
sgmcb 41:f603d76dc6fe 224 int timeoutMargin = 5;
sgmcb 41:f603d76dc6fe 225 int readLoopMax = 100;
sgmcb 40:82b70b92169e 226 int loopIter = 0;
sgmcb 40:82b70b92169e 227 int locAccLower = 50; // Immediately accept locations with uncertainty lower than this
sgmcb 40:82b70b92169e 228 int locAccUpper = 5000; // Don't accept locations with uncertainty greater than this
sgmcb 40:82b70b92169e 229
sgmcb 41:f603d76dc6fe 230 // NO DIFF
sgmcb 41:f603d76dc6fe 231 //printf("Waiting one minute for cell location to lock.\r\n");
sgmcb 41:f603d76dc6fe 232 //delay(60000); // Wait one minute after booting to see if that makes our first cell loc calls give better data
sgmcb 41:f603d76dc6fe 233
sgmcb 41:f603d76dc6fe 234
sgmcb 39:c14aff678b25 235
sgmcb 40:82b70b92169e 236 // Location reporting loop
sgmcb 40:82b70b92169e 237 while(true) {
sgmcb 40:82b70b92169e 238
sgmcb 41:f603d76dc6fe 239 M2X_response = 0;
sgmcb 40:82b70b92169e 240 locLock = false;
sgmcb 40:82b70b92169e 241 loopIter++;
sgmcb 40:82b70b92169e 242
sgmcb 41:f603d76dc6fe 243
sgmcb 41:f603d76dc6fe 244 //M2X_response = logTemp(&tempPin, &m2xClient);
sgmcb 41:f603d76dc6fe 245 printf("tick\r\n");
sgmcb 41:f603d76dc6fe 246
sgmcb 41:f603d76dc6fe 247
sgmcb 41:f603d76dc6fe 248 /*
sgmcb 41:f603d76dc6fe 249 while(!M2X_response) {
sgmcb 41:f603d76dc6fe 250 printf("Waiting on temperature log\r\n");
sgmcb 41:f603d76dc6fe 251 delay(1000);
sgmcb 41:f603d76dc6fe 252 }
sgmcb 41:f603d76dc6fe 253 */
sgmcb 41:f603d76dc6fe 254
sgmcb 41:f603d76dc6fe 255 delay(5000); // Delay to ensure that the modem isn't talking over itself transmitting temp and requesting location
sgmcb 41:f603d76dc6fe 256
sgmcb 40:82b70b92169e 257 //printf("Cell location Request; deep scan=%i, mask=%i, accuracy=%i\r\n", locConf, sensorMask, targetAccuracy);
sgmcb 41:f603d76dc6fe 258 //mdm.setDebug(4);
sgmcb 41:f603d76dc6fe 259 mdm.cellLocRequest(sensorMask, submitPeriod - timeoutMargin, targetAccuracy);
sgmcb 41:f603d76dc6fe 260
sgmcb 40:82b70b92169e 261
sgmcb 41:f603d76dc6fe 262
sgmcb 40:82b70b92169e 263 // Have location data
sgmcb 40:82b70b92169e 264 if ( mdm.cellLocGet(&thisLoc) ){
sgmcb 41:f603d76dc6fe 265 //printf("CellLocate position rec'd with uncertainty= %d, sensor= %d\r\n", thisLoc.uncertainty, thisLoc.sensorUsed );
sgmcb 40:82b70b92169e 266
sgmcb 40:82b70b92169e 267
sgmcb 41:f603d76dc6fe 268 if(thisLoc.sensorUsed == 2) { // thisLoc.uncertainty < ponyLoc.uncertainty) { //Basing test for validity on uncertainty and having a new position lock
sgmcb 41:f603d76dc6fe 269 printf(" NEW-latitude: %0.5f, longitude: %0.5f, altitute: %d, uncertainty: %d, sensor: %d\r\n", thisLoc.latitude, thisLoc.longitude, thisLoc.altitude, thisLoc.uncertainty, thisLoc.sensorUsed);
sgmcb 40:82b70b92169e 270 ponyLoc.latitude = thisLoc.latitude;
sgmcb 40:82b70b92169e 271 ponyLoc.longitude = thisLoc.longitude;
sgmcb 40:82b70b92169e 272 ponyLoc.altitude = thisLoc.altitude;
sgmcb 40:82b70b92169e 273 ponyLoc.uncertainty = thisLoc.uncertainty;
sgmcb 41:f603d76dc6fe 274
sgmcb 41:f603d76dc6fe 275
sgmcb 41:f603d76dc6fe 276 if(!kSysClockSet) {
sgmcb 41:f603d76dc6fe 277 printf("\033[31mSet system clock time.\033[39m\r\n");
sgmcb 41:f603d76dc6fe 278
sgmcb 41:f603d76dc6fe 279 // TODO: Get the local time zone
sgmcb 41:f603d76dc6fe 280 //mdm.setDebug(4);
sgmcb 41:f603d76dc6fe 281 //mdm.sendFormated("AT+CTZR=1");
sgmcb 41:f603d76dc6fe 282
sgmcb 41:f603d76dc6fe 283 // Adjust year because it's reporting the absolute year
sgmcb 41:f603d76dc6fe 284 // mbed expects the year to be "since 1900" (https://developer.mbed.org/handbook/Time?action=view&revision=11592)
sgmcb 41:f603d76dc6fe 285 (thisLoc.time).tm_year -= 1900;
sgmcb 41:f603d76dc6fe 286
sgmcb 41:f603d76dc6fe 287 kSysSeconds = mktime( &(thisLoc.time) );
sgmcb 41:f603d76dc6fe 288 set_time(kSysSeconds);
sgmcb 41:f603d76dc6fe 289 printf("System time set to: %s\r\n", ctime(&kSysSeconds) );
sgmcb 41:f603d76dc6fe 290
sgmcb 41:f603d76dc6fe 291 kSysClockSet=true;
sgmcb 41:f603d76dc6fe 292 }
sgmcb 41:f603d76dc6fe 293
sgmcb 41:f603d76dc6fe 294 // Print the timestamp
sgmcb 41:f603d76dc6fe 295
sgmcb 41:f603d76dc6fe 296
sgmcb 41:f603d76dc6fe 297 time_t newTime = time(NULL);
sgmcb 41:f603d76dc6fe 298 printf("System time at: %s\r\n", ctime(&newTime) );
sgmcb 40:82b70b92169e 299 }
sgmcb 40:82b70b92169e 300
sgmcb 40:82b70b92169e 301
sgmcb 40:82b70b92169e 302 // Check location data
sgmcb 40:82b70b92169e 303 if( ( 0 < ponyLoc.uncertainty && ponyLoc.uncertainty < locAccLower ) || ( 0 < ponyLoc.uncertainty && ponyLoc.uncertainty < locAccUpper && loopIter > readLoopMax ) ) {
sgmcb 40:82b70b92169e 304
sgmcb 40:82b70b92169e 305 printf("\r\nTRANSMIT LOCATION DATA:\r\nla=%0.5f, lo=%0.5f, alt=%d\r\n", ponyLoc.latitude, ponyLoc.longitude, ponyLoc.altitude);
sgmcb 40:82b70b92169e 306 M2X_response = m2xClient.updateLocation(DEVID, "pony-spot", (double) ponyLoc.latitude, (double) ponyLoc.longitude, (double) ponyLoc.altitude);
sgmcb 40:82b70b92169e 307
sgmcb 40:82b70b92169e 308 if(M2X_response == 202)
sgmcb 40:82b70b92169e 309 printf("Location POST successful\r\n");
sgmcb 40:82b70b92169e 310
sgmcb 40:82b70b92169e 311
sgmcb 40:82b70b92169e 312 // Report uncertainty
sgmcb 40:82b70b92169e 313 M2X_response = m2xClient.updateStreamValue(DEVID, "locacc", ponyLoc.uncertainty);
sgmcb 40:82b70b92169e 314
sgmcb 40:82b70b92169e 315 if(M2X_response == 202)
sgmcb 40:82b70b92169e 316 printf("Location Confidence (%d) POST successful\r\n", ponyLoc.uncertainty);
sgmcb 40:82b70b92169e 317
sgmcb 41:f603d76dc6fe 318 // Report temperature
sgmcb 41:f603d76dc6fe 319 M2X_response = logTemp(&tempPin, &kTemp, &m2xClient);
sgmcb 41:f603d76dc6fe 320
sgmcb 41:f603d76dc6fe 321 if(M2X_response == 202)
sgmcb 41:f603d76dc6fe 322 printf("Temperature POST successful\r\n");
sgmcb 41:f603d76dc6fe 323
sgmcb 41:f603d76dc6fe 324
sgmcb 40:82b70b92169e 325 locLock = true;
sgmcb 40:82b70b92169e 326 }
sgmcb 40:82b70b92169e 327 }
sgmcb 40:82b70b92169e 328
sgmcb 40:82b70b92169e 329 // No location data
sgmcb 40:82b70b92169e 330 else {
sgmcb 40:82b70b92169e 331 printf("cellLocGet failed.\r\n");
sgmcb 40:82b70b92169e 332 //
sgmcb 40:82b70b92169e 333 }
sgmcb 40:82b70b92169e 334
sgmcb 40:82b70b92169e 335 // Wait only if we've received a good location reading
sgmcb 40:82b70b92169e 336 if(locLock) {
sgmcb 40:82b70b92169e 337 printf("Begin %i second delay\r\n",kReadingDelay/1000); loopIter = 0; delay(kReadingDelay);
sgmcb 40:82b70b92169e 338 ponyLoc.uncertainty = locAccUpper + 1;
sgmcb 40:82b70b92169e 339 continue;
sgmcb 40:82b70b92169e 340 }
sgmcb 40:82b70b92169e 341 else if (loopIter > readLoopMax) {
sgmcb 40:82b70b92169e 342 sprintf(statusBuf, "CellLoc location not found after %i loops.\r\n", loopIter);
sgmcb 40:82b70b92169e 343 printf(statusBuf);
sgmcb 40:82b70b92169e 344 M2X_response = m2xClient.updateStreamValue(DEVID, "status", statusBuf);
sgmcb 40:82b70b92169e 345 if(M2X_response == 202)
sgmcb 40:82b70b92169e 346 printf("Status POST successful\r\n");
sgmcb 40:82b70b92169e 347
sgmcb 40:82b70b92169e 348 ponyLoc.uncertainty = locAccUpper + 1;
sgmcb 40:82b70b92169e 349 printf("Begin %i second delay\r\n",kReadingDelay/1000); loopIter = 0; delay(kReadingDelay);
sgmcb 40:82b70b92169e 350 continue;
sgmcb 40:82b70b92169e 351 }
sgmcb 41:f603d76dc6fe 352
sgmcb 40:82b70b92169e 353 else {
sgmcb 41:f603d76dc6fe 354 printf("Bad data delay = submitPeriod...\r\n");
sgmcb 41:f603d76dc6fe 355 delay(submitPeriod * 1000); // Delay between CellLoc requests when not getting good data
sgmcb 41:f603d76dc6fe 356 flipper.attach(&flip, 0.5); // the address of the function to be attached (flip) and the interval (2 seconds)
sgmcb 40:82b70b92169e 357 }
sgmcb 41:f603d76dc6fe 358 led1 = 0;
sgmcb 40:82b70b92169e 359 }
sgmcb 38:d86e744166b6 360
sgmcb 39:c14aff678b25 361
sgmcb 40:82b70b92169e 362 //mdm.disconnect();
sgmcb 40:82b70b92169e 363 //mdm.powerOff();
msinig 35:16f1037626e3 364
lawliet 0:4e3cb26f6019 365 }