whatever
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
main.cpp
- Committer:
- sgmcb
- Date:
- 2015-12-01
- Revision:
- 34:f28937f7657d
- Parent:
- 33:4ed19bed18c0
File content as of revision 34:f28937f7657d:
#include "mbed.h" #include <string.h> // ublox C027 support libraries #include "GPS.h" // GPS support #include "MDM.h" // Modem support // AT&T Support //------------------------------------------------------------------------------------ // Cellular modem/SIM parameters #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs. #define APN "m2m.com.attz" // Defined AT&T M2M APN #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't) #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't) //------------------------------------------------------------------------------------ // PONY refactored code #include "PonyLoc.h" // Set pinout for LED DigitalOut myled(LED); extern const char* NMEA_talkers[]; // MAIN int main(void) { printf("\n\n\r----------\r\nI'm alive!\r\n"); // Loading wait for(int i = 0; i < 10; i++) { myled = !myled;; wait(0.2); } //int ret; // Integer returns //int len; // The length of the ret integer double la = 0, lo = 0; // Declare latitude and longitude variables double UTCtime = 0; // Not 100% sure where this LARGE_DATA flag is being set, but I think we might be using it... (SGM) #ifdef LARGE_DATA char buf[2048] = ""; #else char buf[512] = ""; #endif ////////////////////////////////// GPSI2C gps; // Initialize GPS object printf("GPS initialized...\r\n"); /* while( (ret = gps.getMessage(buf, sizeof(buf))) < 1 ) { if (ret<0) printf("WAIT received from GPS\r\n"); if (ret==0) printf("NOT FOUND received from GPS\r\n"); myled = !myled; wait(1.0); }*/ // How long will we wait before we accept ANY location value? float locationLoopWait = 0.25; int locationLoopTimeout = 30; int locationLoopCountout = (float) locationLoopTimeout / locationLoopWait; // Ready the GPS if ( gpsReady(&gps, 5) ) { if ( getGLL(&gps, locationLoopCountout, &la, &lo, &UTCtime) ) { printf("Have GLL data:\r\n%s", buf); } else { printf("Timeout; no valid GLL data received"); } } printf("Latitude: %G\r\nLongitude: %G\r\nUTC Time:%f\r\n\n", la, lo, UTCtime); //----- MODEM UP!!! // Now that we know where we are, let's do something with it (modem-wise...) printf("Open modem object mdm\r\n"); MDMSerial mdm; mdm.setDebug(4); // enable this for debugging issues // Create status objects MDMParser::DevStatus devStatus = {}; MDMParser::NetStatus netStatus = {}; bool mdmOk = mdm.init(SIMPIN, &devStatus); // How we doing so far? printf("\r\n-- mdm.init status dump\r\n"); mdm.dumpDevStatus(&devStatus); if (mdmOk) { // wait until we are connected (SGM: Not sure what this means, since this isn't a loop... mdmOk = mdm.registerNet(&netStatus); mdm.dumpNetStatus(&netStatus); } printf("-- mdm.registerNet status dump\r\n"); // Open a data connecction if(mdmOk) { MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); printf("-- mdm.join dump\r\n"); // If we secure an IP address, keep going! if (ip != NOIP) { printf("\n\n\rWe got's an IP address!\r\n"); mdm.dumpIp(ip); } } // SMS code while(true) { wait(5); if (mdmOk) { // check the network status if (mdm.checkNetStatus(&netStatus)) { printf("\r\n-- mdm.dumpNetStatus\r\n"); mdm.dumpNetStatus(&netStatus, fprintf, stdout); break; } } } // Send SMS char num1[32] = "+14259749434"; char smsText[144]; sprintf(smsText, "PONY unit located at: %f, %f, UTC %f", la, lo, UTCtime); printf("Message: %s\r\n", smsText); printf("\r\nSend to: %s\r\n", num1); if( mdm.smsSend(num1, smsText) ) { printf("\r\nSMS num1 (AT&T) success!\r\n"); } else { printf("SMS fail. :-( \r\n"); } }