whatever
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
main.cpp@34:f28937f7657d, 2015-12-01 (annotated)
- Committer:
- sgmcb
- Date:
- Tue Dec 01 00:35:55 2015 +0000
- Revision:
- 34:f28937f7657d
- Parent:
- 33:4ed19bed18c0
Remove commented-out cruft
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 | |
sgmcb | 31:f94b8f987b62 | 3 | #include <string.h> |
sgmcb | 31:f94b8f987b62 | 4 | |
sgmcb | 31:f94b8f987b62 | 5 | // ublox C027 support libraries |
sgmcb | 31:f94b8f987b62 | 6 | #include "GPS.h" // GPS support |
sgmcb | 31:f94b8f987b62 | 7 | #include "MDM.h" // Modem support |
sgmcb | 31:f94b8f987b62 | 8 | |
sgmcb | 32:4b94cb22d338 | 9 | |
sgmcb | 32:4b94cb22d338 | 10 | |
sgmcb | 32:4b94cb22d338 | 11 | |
sgmcb | 32:4b94cb22d338 | 12 | |
sgmcb | 31:f94b8f987b62 | 13 | // AT&T Support |
sgmcb | 31:f94b8f987b62 | 14 | |
mazgch | 19:f022ff746eb8 | 15 | //------------------------------------------------------------------------------------ |
sgmcb | 31:f94b8f987b62 | 16 | // Cellular modem/SIM parameters |
sgmcb | 31:f94b8f987b62 | 17 | #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs. |
sgmcb | 31:f94b8f987b62 | 18 | #define APN "m2m.com.attz" // Defined AT&T M2M APN |
sgmcb | 31:f94b8f987b62 | 19 | #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't) |
sgmcb | 31:f94b8f987b62 | 20 | #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't) |
mazgch | 19:f022ff746eb8 | 21 | //------------------------------------------------------------------------------------ |
lawliet | 0:4e3cb26f6019 | 22 | |
sgmcb | 32:4b94cb22d338 | 23 | // PONY refactored code |
sgmcb | 32:4b94cb22d338 | 24 | #include "PonyLoc.h" |
sgmcb | 32:4b94cb22d338 | 25 | |
sgmcb | 32:4b94cb22d338 | 26 | |
sgmcb | 32:4b94cb22d338 | 27 | |
sgmcb | 32:4b94cb22d338 | 28 | |
sgmcb | 32:4b94cb22d338 | 29 | |
sgmcb | 30:f9bb5aba1155 | 30 | // Set pinout for LED |
sgmcb | 30:f9bb5aba1155 | 31 | DigitalOut myled(LED); |
sgmcb | 30:f9bb5aba1155 | 32 | |
sgmcb | 32:4b94cb22d338 | 33 | extern const char* NMEA_talkers[]; |
sgmcb | 32:4b94cb22d338 | 34 | |
sgmcb | 32:4b94cb22d338 | 35 | |
sgmcb | 32:4b94cb22d338 | 36 | |
sgmcb | 32:4b94cb22d338 | 37 | |
sgmcb | 32:4b94cb22d338 | 38 | // MAIN |
sgmcb | 32:4b94cb22d338 | 39 | |
sgmcb | 30:f9bb5aba1155 | 40 | int main(void) { |
sgmcb | 31:f94b8f987b62 | 41 | printf("\n\n\r----------\r\nI'm alive!\r\n"); |
sgmcb | 30:f9bb5aba1155 | 42 | |
sgmcb | 31:f94b8f987b62 | 43 | // Loading wait |
sgmcb | 31:f94b8f987b62 | 44 | for(int i = 0; i < 10; i++) { |
sgmcb | 31:f94b8f987b62 | 45 | myled = !myled;; |
sgmcb | 30:f9bb5aba1155 | 46 | wait(0.2); |
sgmcb | 30:f9bb5aba1155 | 47 | } |
sgmcb | 30:f9bb5aba1155 | 48 | |
sgmcb | 33:4ed19bed18c0 | 49 | //int ret; // Integer returns |
sgmcb | 33:4ed19bed18c0 | 50 | //int len; // The length of the ret integer |
sgmcb | 33:4ed19bed18c0 | 51 | |
sgmcb | 33:4ed19bed18c0 | 52 | double la = 0, lo = 0; // Declare latitude and longitude variables |
sgmcb | 33:4ed19bed18c0 | 53 | double UTCtime = 0; |
sgmcb | 31:f94b8f987b62 | 54 | |
sgmcb | 31:f94b8f987b62 | 55 | // Not 100% sure where this LARGE_DATA flag is being set, but I think we might be using it... (SGM) |
sgmcb | 31:f94b8f987b62 | 56 | #ifdef LARGE_DATA |
sgmcb | 31:f94b8f987b62 | 57 | char buf[2048] = ""; |
sgmcb | 31:f94b8f987b62 | 58 | #else |
sgmcb | 31:f94b8f987b62 | 59 | char buf[512] = ""; |
sgmcb | 31:f94b8f987b62 | 60 | #endif |
sgmcb | 31:f94b8f987b62 | 61 | |
sgmcb | 33:4ed19bed18c0 | 62 | ////////////////////////////////// |
sgmcb | 31:f94b8f987b62 | 63 | |
sgmcb | 31:f94b8f987b62 | 64 | GPSI2C gps; // Initialize GPS object |
sgmcb | 31:f94b8f987b62 | 65 | printf("GPS initialized...\r\n"); |
sgmcb | 31:f94b8f987b62 | 66 | |
sgmcb | 32:4b94cb22d338 | 67 | /* |
sgmcb | 31:f94b8f987b62 | 68 | while( (ret = gps.getMessage(buf, sizeof(buf))) < 1 ) { |
sgmcb | 31:f94b8f987b62 | 69 | if (ret<0) |
sgmcb | 31:f94b8f987b62 | 70 | printf("WAIT received from GPS\r\n"); |
sgmcb | 31:f94b8f987b62 | 71 | if (ret==0) |
sgmcb | 31:f94b8f987b62 | 72 | printf("NOT FOUND received from GPS\r\n"); |
sgmcb | 31:f94b8f987b62 | 73 | myled = !myled; |
sgmcb | 31:f94b8f987b62 | 74 | wait(1.0); |
sgmcb | 32:4b94cb22d338 | 75 | }*/ |
sgmcb | 33:4ed19bed18c0 | 76 | |
sgmcb | 33:4ed19bed18c0 | 77 | |
sgmcb | 33:4ed19bed18c0 | 78 | |
sgmcb | 33:4ed19bed18c0 | 79 | |
sgmcb | 33:4ed19bed18c0 | 80 | |
sgmcb | 33:4ed19bed18c0 | 81 | |
sgmcb | 33:4ed19bed18c0 | 82 | // How long will we wait before we accept ANY location value? |
sgmcb | 33:4ed19bed18c0 | 83 | float locationLoopWait = 0.25; |
sgmcb | 31:f94b8f987b62 | 84 | |
sgmcb | 32:4b94cb22d338 | 85 | int locationLoopTimeout = 30; |
sgmcb | 32:4b94cb22d338 | 86 | int locationLoopCountout = (float) locationLoopTimeout / locationLoopWait; |
sgmcb | 33:4ed19bed18c0 | 87 | |
sgmcb | 33:4ed19bed18c0 | 88 | // Ready the GPS |
sgmcb | 33:4ed19bed18c0 | 89 | if ( gpsReady(&gps, 5) ) { |
sgmcb | 32:4b94cb22d338 | 90 | |
sgmcb | 33:4ed19bed18c0 | 91 | if ( getGLL(&gps, locationLoopCountout, &la, &lo, &UTCtime) ) { |
sgmcb | 33:4ed19bed18c0 | 92 | printf("Have GLL data:\r\n%s", buf); |
sgmcb | 33:4ed19bed18c0 | 93 | } |
sgmcb | 33:4ed19bed18c0 | 94 | else { |
sgmcb | 33:4ed19bed18c0 | 95 | printf("Timeout; no valid GLL data received"); |
sgmcb | 33:4ed19bed18c0 | 96 | } |
sgmcb | 32:4b94cb22d338 | 97 | |
sgmcb | 33:4ed19bed18c0 | 98 | } |
sgmcb | 31:f94b8f987b62 | 99 | |
sgmcb | 33:4ed19bed18c0 | 100 | printf("Latitude: %G\r\nLongitude: %G\r\nUTC Time:%f\r\n\n", la, lo, UTCtime); |
sgmcb | 33:4ed19bed18c0 | 101 | |
sgmcb | 32:4b94cb22d338 | 102 | |
sgmcb | 32:4b94cb22d338 | 103 | //----- MODEM UP!!! |
sgmcb | 32:4b94cb22d338 | 104 | // Now that we know where we are, let's do something with it (modem-wise...) |
sgmcb | 32:4b94cb22d338 | 105 | |
sgmcb | 32:4b94cb22d338 | 106 | printf("Open modem object mdm\r\n"); |
sgmcb | 32:4b94cb22d338 | 107 | |
sgmcb | 32:4b94cb22d338 | 108 | MDMSerial mdm; |
sgmcb | 32:4b94cb22d338 | 109 | mdm.setDebug(4); // enable this for debugging issues |
sgmcb | 32:4b94cb22d338 | 110 | |
sgmcb | 32:4b94cb22d338 | 111 | |
sgmcb | 32:4b94cb22d338 | 112 | // Create status objects |
sgmcb | 32:4b94cb22d338 | 113 | MDMParser::DevStatus devStatus = {}; |
sgmcb | 32:4b94cb22d338 | 114 | MDMParser::NetStatus netStatus = {}; |
sgmcb | 32:4b94cb22d338 | 115 | |
sgmcb | 32:4b94cb22d338 | 116 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
sgmcb | 32:4b94cb22d338 | 117 | |
sgmcb | 32:4b94cb22d338 | 118 | // How we doing so far? |
sgmcb | 32:4b94cb22d338 | 119 | printf("\r\n-- mdm.init status dump\r\n"); |
sgmcb | 32:4b94cb22d338 | 120 | mdm.dumpDevStatus(&devStatus); |
sgmcb | 32:4b94cb22d338 | 121 | |
sgmcb | 32:4b94cb22d338 | 122 | if (mdmOk) { |
sgmcb | 32:4b94cb22d338 | 123 | // wait until we are connected (SGM: Not sure what this means, since this isn't a loop... |
sgmcb | 32:4b94cb22d338 | 124 | mdmOk = mdm.registerNet(&netStatus); |
sgmcb | 32:4b94cb22d338 | 125 | mdm.dumpNetStatus(&netStatus); |
sgmcb | 32:4b94cb22d338 | 126 | |
sgmcb | 32:4b94cb22d338 | 127 | } |
sgmcb | 32:4b94cb22d338 | 128 | |
sgmcb | 32:4b94cb22d338 | 129 | printf("-- mdm.registerNet status dump\r\n"); |
sgmcb | 32:4b94cb22d338 | 130 | |
sgmcb | 32:4b94cb22d338 | 131 | // Open a data connecction |
sgmcb | 32:4b94cb22d338 | 132 | if(mdmOk) { |
sgmcb | 32:4b94cb22d338 | 133 | |
sgmcb | 32:4b94cb22d338 | 134 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
sgmcb | 32:4b94cb22d338 | 135 | printf("-- mdm.join dump\r\n"); |
sgmcb | 32:4b94cb22d338 | 136 | |
sgmcb | 32:4b94cb22d338 | 137 | |
sgmcb | 32:4b94cb22d338 | 138 | // If we secure an IP address, keep going! |
sgmcb | 32:4b94cb22d338 | 139 | |
sgmcb | 32:4b94cb22d338 | 140 | if (ip != NOIP) { |
sgmcb | 32:4b94cb22d338 | 141 | |
sgmcb | 32:4b94cb22d338 | 142 | printf("\n\n\rWe got's an IP address!\r\n"); |
sgmcb | 32:4b94cb22d338 | 143 | mdm.dumpIp(ip); |
sgmcb | 32:4b94cb22d338 | 144 | |
sgmcb | 32:4b94cb22d338 | 145 | } |
sgmcb | 32:4b94cb22d338 | 146 | } |
sgmcb | 32:4b94cb22d338 | 147 | |
sgmcb | 32:4b94cb22d338 | 148 | // SMS code |
sgmcb | 32:4b94cb22d338 | 149 | while(true) { |
sgmcb | 32:4b94cb22d338 | 150 | wait(5); |
sgmcb | 32:4b94cb22d338 | 151 | if (mdmOk) { |
sgmcb | 32:4b94cb22d338 | 152 | // check the network status |
sgmcb | 32:4b94cb22d338 | 153 | if (mdm.checkNetStatus(&netStatus)) { |
sgmcb | 32:4b94cb22d338 | 154 | printf("\r\n-- mdm.dumpNetStatus\r\n"); |
sgmcb | 32:4b94cb22d338 | 155 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
sgmcb | 32:4b94cb22d338 | 156 | break; |
sgmcb | 32:4b94cb22d338 | 157 | } |
sgmcb | 32:4b94cb22d338 | 158 | } |
sgmcb | 32:4b94cb22d338 | 159 | } |
sgmcb | 32:4b94cb22d338 | 160 | |
sgmcb | 32:4b94cb22d338 | 161 | // Send SMS |
sgmcb | 33:4ed19bed18c0 | 162 | char num1[32] = "+14259749434"; |
sgmcb | 32:4b94cb22d338 | 163 | |
sgmcb | 32:4b94cb22d338 | 164 | char smsText[144]; |
sgmcb | 33:4ed19bed18c0 | 165 | sprintf(smsText, "PONY unit located at: %f, %f, UTC %f", la, lo, UTCtime); |
sgmcb | 32:4b94cb22d338 | 166 | printf("Message: %s\r\n", smsText); |
sgmcb | 32:4b94cb22d338 | 167 | |
sgmcb | 33:4ed19bed18c0 | 168 | |
sgmcb | 32:4b94cb22d338 | 169 | |
sgmcb | 32:4b94cb22d338 | 170 | printf("\r\nSend to: %s\r\n", num1); |
sgmcb | 32:4b94cb22d338 | 171 | if( mdm.smsSend(num1, smsText) ) { |
sgmcb | 32:4b94cb22d338 | 172 | printf("\r\nSMS num1 (AT&T) success!\r\n"); |
sgmcb | 32:4b94cb22d338 | 173 | } |
sgmcb | 32:4b94cb22d338 | 174 | else { |
sgmcb | 32:4b94cb22d338 | 175 | printf("SMS fail. :-( \r\n"); |
sgmcb | 32:4b94cb22d338 | 176 | } |
sgmcb | 32:4b94cb22d338 | 177 | |
sgmcb | 33:4ed19bed18c0 | 178 | |
sgmcb | 32:4b94cb22d338 | 179 | |
sgmcb | 33:4ed19bed18c0 | 180 | } |