Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.
Testing the module's internet connection (spoiler: it doesn't work) WARNING: this code has been written in a hurry during an hackathon. It's total crap.
gsm.cpp
- Committer:
- gipmad
- Date:
- 2015-09-19
- Revision:
- 1:180ed9f09775
- Parent:
- 0:8f9b472ff818
File content as of revision 1:180ed9f09775:
#include "gsm.h" GSM::GSM(PinName tx, PinName rx) : _gsm(tx, rx) { _gsm.baud(115200); flag_gsm_get = 0; flag_gsm_getend = 0; _gsm.attach(this,&GSM::sample,Serial::RxIrq); count = 0; } void GSM::sample() { char *e; getline(); if(flag_gsm_getend){ // pc.printf("\"%s\"\n", msg); if(sscanf(msg, "+CMTI: \"SM\",%d", &SMSid) >= 1) { pc.printf("Got SMS! ID: %d\n", SMSid); } else { //e = strchr(msg, '\n'); //pc.printf(".s: %s.\n", e); if(sscanf(e, "OK") >= 1) { //GOT OK! pc.printf("Got OK!\n"); } } /*if(sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &_time, &_latitude, &_ns, &_longitude, &_ew, &_lock) >= 1) { flag_gga = 1; strcpy(gga,msg); float degrees = floor(_latitude / 100.0f); float minutes = _latitude - (degrees * 100.0f); _latitude = degrees + minutes / 60.0f; degrees = floor(_longitude / 100.0f); minutes = _longitude - (degrees * 100.0f); _longitude = degrees + minutes /60.0f; }*/ flag_gsm_getend = 0; } } /*char* GPS::getGGA(){ if(flag_gga){ // strcpy(gga,msg); flag_gga = 0; } return gga; } float GPS::longitude(){ return _longitude; } float GPS::latitude(){ return _latitude; } float GPS::time(){ return _time; } int GPS::ns(){ int d; if(_ns == 'N'){ d = 1; }else{ d = -1; } return d; } int GPS::ew(){ int d; if(_ew == 'E'){ d = 1; }else{ d = -1; } return d; } int GPS::lock(){ return _lock; }*/ void GSM::getline() { char temp; temp = _gsm.getc(); pc.putc(temp); /*if(temp == '$'){ flag_gsm_get = 1; count = 0; }*/ //if(flag_gsm_get) { // pc.printf(".%d%c.",count,temp); msg[count] = temp; if(temp == '\n'){ msg[count] = '\0'; flag_gsm_getend = 1; count = 0; //flag_gps_get = 0; } else count ++; } }