Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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:
- 33:4ed19bed18c0
- Parent:
- 32:4b94cb22d338
- Child:
- 34:f28937f7657d
File content as of revision 33:4ed19bed18c0:
#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");
}
}
/*
// Get a good GPS message
printf("\r\nMessage loop wait=%fs\r\n",locationLoopWait);
int locationLoopIter = 0;
while(true) {
locationLoopIter++;
ret = gps.getMessage(buf, sizeof(buf));
// Test for location data in this priority: GLL, RMC, GGA
#define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2]))
// TODO: Add check that we're getting NMEA-formatted sentences
int sentenceType = getNMEAtalker(buf);
//char talkerType[3] = NMEA_talkers[sentenceType];
printf("Talker type = %s\r\n", NMEA_talkers[sentenceType]);
if (sentenceType == 5) {
break;
}
if ( _CHECK_TALKER("GLL") ) {
char ch = '-';
// FIX: The getNmeaItem isn't working to capture the check character in a valid GLL code, which is unusual; the workaround seems to be that invalid GLL values DOES find a "V"
if(!gps.getNmeaItem(6,buf,len,ch)) {
printf("\n\n\rHave GLL location data after %f seconds and %i requests:\r\n", ( locationLoopWait * (float) locationLoopIter ), locationLoopIter );
printf(buf);
break;
}
else {
printf("\rGLL inv...");
//printf(buf); printf("\r\n");
}
}
else if ( (_CHECK_TALKER("RMC") || _CHECK_TALKER("GGA")) && locationLoopIter > locationLoopCountout ) {
printf("\r\nTaking non-GLL data due to location timeout\r\n");
printf(buf); printf("\r\n");
break;
}
else if ( _CHECK_TALKER("RMC") ) {
printf("\rRMC loc...");
//printf(buf); printf("\r\n\n");
}
else if ( _CHECK_TALKER("GGA") ) {
printf("\rGGA loc...");
//printf(buf); printf("\r\n\n");
}
else {
printf("\rNo loc...");
}
*/
//wait(locationLoopWait);
//}// LOOP THAT MOFO
// Begin parsing our GPS value
//gps.getNmeaAngle(1,buf,len,la);
//gps.getNmeaAngle(3,buf,len,lo);
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");
}
}
