whatever
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
main.cpp@38:d86e744166b6, 2015-12-09 (annotated)
- Committer:
- sgmcb
- Date:
- Wed Dec 09 00:55:23 2015 +0000
- Revision:
- 38:d86e744166b6
- Parent:
- 37:71ab32b61dfb
- Child:
- 39:c14aff678b25
All Timers commented out
Who changed what in which revision?
User | Revision | Line number | New 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 | |
lawliet | 0:4e3cb26f6019 | 24 | |
sgmcb | 36:258f3bb1c6a4 | 25 | |
sgmcb | 36:258f3bb1c6a4 | 26 | |
sgmcb | 36:258f3bb1c6a4 | 27 | |
sgmcb | 36:258f3bb1c6a4 | 28 | |
sgmcb | 37:71ab32b61dfb | 29 | |
sgmcb | 37:71ab32b61dfb | 30 | |
sgmcb | 37:71ab32b61dfb | 31 | |
sgmcb | 36:258f3bb1c6a4 | 32 | |
sgmcb | 38:d86e744166b6 | 33 | //------------------------------------------------------------------------------------ |
sgmcb | 38:d86e744166b6 | 34 | // Cellular modem/SIM parameters |
sgmcb | 38:d86e744166b6 | 35 | #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs. |
sgmcb | 38:d86e744166b6 | 36 | #define APN "m2m.com.attz" // Defined AT&T M2M APN |
sgmcb | 38:d86e744166b6 | 37 | #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't) |
sgmcb | 38:d86e744166b6 | 38 | #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't) |
sgmcb | 38:d86e744166b6 | 39 | |
sgmcb | 38:d86e744166b6 | 40 | |
sgmcb | 38:d86e744166b6 | 41 | |
sgmcb | 38:d86e744166b6 | 42 | //------------------------------------------------------------------------------------ |
sgmcb | 38:d86e744166b6 | 43 | // AT&T M2X Kekys |
sgmcb | 38:d86e744166b6 | 44 | |
sgmcb | 38:d86e744166b6 | 45 | #define M2XAPIKEY "295d76119ddac541c4e8c51bc3a45497" |
sgmcb | 38:d86e744166b6 | 46 | #define DEVID "8066dc4be6828638af1a62521f61f6e3" |
sgmcb | 38:d86e744166b6 | 47 | |
sgmcb | 38:d86e744166b6 | 48 | //------------------------------------------------------------------------------------ |
sgmcb | 38:d86e744166b6 | 49 | |
sgmcb | 38:d86e744166b6 | 50 | #include "PONY_Loc.h" // PONY Location Code |
sgmcb | 38:d86e744166b6 | 51 | |
sgmcb | 38:d86e744166b6 | 52 | |
sgmcb | 38:d86e744166b6 | 53 | |
sgmcb | 38:d86e744166b6 | 54 | |
sgmcb | 38:d86e744166b6 | 55 | // GLOBALS |
sgmcb | 38:d86e744166b6 | 56 | |
sgmcb | 38:d86e744166b6 | 57 | |
sgmcb | 38:d86e744166b6 | 58 | |
sgmcb | 38:d86e744166b6 | 59 | Client client; |
sgmcb | 38:d86e744166b6 | 60 | M2XStreamClient m2xClient(&client, M2XAPIKEY); |
sgmcb | 38:d86e744166b6 | 61 | |
sgmcb | 38:d86e744166b6 | 62 | |
sgmcb | 38:d86e744166b6 | 63 | |
sgmcb | 38:d86e744166b6 | 64 | unsigned int kReadingDelay = 30000; |
sgmcb | 38:d86e744166b6 | 65 | |
sgmcb | 38:d86e744166b6 | 66 | double kLaLoDiffMin = 0.01; |
sgmcb | 38:d86e744166b6 | 67 | double kAltDiffMin = 2.00; |
sgmcb | 38:d86e744166b6 | 68 | |
sgmcb | 38:d86e744166b6 | 69 | |
sgmcb | 38:d86e744166b6 | 70 | //#define CELLOCATE |
sgmcb | 38:d86e744166b6 | 71 | |
sgmcb | 38:d86e744166b6 | 72 | //------------------------------------------------------------------------------------ |
sgmcb | 38:d86e744166b6 | 73 | //------------------------------------------------------------------------------------ |
sgmcb | 38:d86e744166b6 | 74 | //------------------------------------------------------------------------------------ |
sgmcb | 38:d86e744166b6 | 75 | int main(void) |
sgmcb | 38:d86e744166b6 | 76 | { |
sgmcb | 38:d86e744166b6 | 77 | |
sgmcb | 38:d86e744166b6 | 78 | printf("\r\n\n\n\n-----\r\nI'm alive - u8!\r\n\n"); |
sgmcb | 36:258f3bb1c6a4 | 79 | |
sgmcb | 38:d86e744166b6 | 80 | int ret = 0; |
sgmcb | 38:d86e744166b6 | 81 | int len = 0; |
sgmcb | 38:d86e744166b6 | 82 | char buf[2048] = ""; |
sgmcb | 38:d86e744166b6 | 83 | |
sgmcb | 38:d86e744166b6 | 84 | // Create the GPS object |
sgmcb | 38:d86e744166b6 | 85 | GPSI2C gpsInst; |
sgmcb | 38:d86e744166b6 | 86 | |
sgmcb | 38:d86e744166b6 | 87 | // Struct for our GPS sentence info |
sgmcb | 38:d86e744166b6 | 88 | struct GPSbundle GPSone; |
sgmcb | 38:d86e744166b6 | 89 | GPSone.bGPS = gpsInst; |
sgmcb | 38:d86e744166b6 | 90 | GPSone.bRet = ret; |
sgmcb | 38:d86e744166b6 | 91 | GPSone.bLen = len; |
sgmcb | 38:d86e744166b6 | 92 | GPSone.bBuf = &buf[0]; |
sgmcb | 38:d86e744166b6 | 93 | GPSone.bBufLen = sizeof(buf); |
sgmcb | 38:d86e744166b6 | 94 | |
sgmcb | 38:d86e744166b6 | 95 | // Struct for item location |
sgmcb | 38:d86e744166b6 | 96 | //double timestamp = 0, lat = 0, lon = 0, alt = 0, vel = 0; |
sgmcb | 38:d86e744166b6 | 97 | struct GPSloc PONYspot; |
sgmcb | 38:d86e744166b6 | 98 | MDMSerial mdm; |
sgmcb | 38:d86e744166b6 | 99 | |
sgmcb | 38:d86e744166b6 | 100 | // Open modem connection |
sgmcb | 38:d86e744166b6 | 101 | if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) |
sgmcb | 38:d86e744166b6 | 102 | return -1; |
sgmcb | 38:d86e744166b6 | 103 | |
sgmcb | 38:d86e744166b6 | 104 | //Timer tmr; |
sgmcb | 38:d86e744166b6 | 105 | //tmr.reset(); |
sgmcb | 38:d86e744166b6 | 106 | //tmr.start(); |
sgmcb | 38:d86e744166b6 | 107 | |
sgmcb | 38:d86e744166b6 | 108 | |
sgmcb | 38:d86e744166b6 | 109 | // Ready the GPS |
sgmcb | 38:d86e744166b6 | 110 | readyGPS(&GPSone, 5); |
sgmcb | 38:d86e744166b6 | 111 | |
sgmcb | 38:d86e744166b6 | 112 | |
sgmcb | 38:d86e744166b6 | 113 | |
sgmcb | 38:d86e744166b6 | 114 | while(true) { |
sgmcb | 38:d86e744166b6 | 115 | |
sgmcb | 38:d86e744166b6 | 116 | // Get coordinates |
sgmcb | 38:d86e744166b6 | 117 | if ( fetchLocBundle(&GPSone, &PONYspot, 30) == 7 ) |
sgmcb | 38:d86e744166b6 | 118 | printf("Filled bundle!\r\n"); |
sgmcb | 38:d86e744166b6 | 119 | |
sgmcb | 38:d86e744166b6 | 120 | printf("Lat=%f, Long=%f, Elev=%f, Time=%f\r\n",PONYspot.lat, PONYspot.lon, PONYspot.alt, PONYspot.tmstmp); |
sgmcb | 38:d86e744166b6 | 121 | |
sgmcb | 38:d86e744166b6 | 122 | //tmr.reset(); |
sgmcb | 38:d86e744166b6 | 123 | //tmr.start(); |
sgmcb | 38:d86e744166b6 | 124 | int response; |
sgmcb | 38:d86e744166b6 | 125 | |
sgmcb | 38:d86e744166b6 | 126 | response = m2xClient.updateLocation(DEVID, "Igor-spot", PONYspot.lat, PONYspot.lon, PONYspot.alt); |
sgmcb | 38:d86e744166b6 | 127 | |
sgmcb | 38:d86e744166b6 | 128 | if(response == 202) |
sgmcb | 38:d86e744166b6 | 129 | printf("POST success\r\n"); |
sgmcb | 38:d86e744166b6 | 130 | |
sgmcb | 38:d86e744166b6 | 131 | |
sgmcb | 38:d86e744166b6 | 132 | delay(kReadingDelay); |
sgmcb | 38:d86e744166b6 | 133 | } |
sgmcb | 38:d86e744166b6 | 134 | |
sgmcb | 38:d86e744166b6 | 135 | mdm.disconnect(); |
sgmcb | 38:d86e744166b6 | 136 | mdm.powerOff(); |
sgmcb | 36:258f3bb1c6a4 | 137 | |
sgmcb | 36:258f3bb1c6a4 | 138 | |
sgmcb | 36:258f3bb1c6a4 | 139 | |
sgmcb | 38:d86e744166b6 | 140 | |
sgmcb | 38:d86e744166b6 | 141 | |
sgmcb | 37:71ab32b61dfb | 142 | |
msinig | 35:16f1037626e3 | 143 | |
lawliet | 0:4e3cb26f6019 | 144 | } |