From 6008368f9d5b4ff9096e8942916e04fa2c099b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20H=C3=B8rup?= Date: Sat, 24 Jun 2017 22:12:30 +0200 Subject: [PATCH 1/9] Reset to factory defaults on initialization (ATZ) --- DFRobot_sim808.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index baffe87..24d7549 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -60,11 +60,15 @@ DFRobot_SIM808::DFRobot_SIM808(SoftwareSerial *mySerial) bool DFRobot_SIM808::init(void) { //检查AT指令是否有效 - if(!sim808_check_with_cmd("AT\r\n","OK\r\n",CMD)){ - - return false; - + if(!sim808_check_with_cmd("AT\r\n","OK\r\n",CMD)){ + return false; } + + // Reset to factory defaults + if(!sim808_check_with_cmd("ATZ\r\n","OK\r\n",CMD)){ + return false; + } + //检查SIM是否可以打电话,发短信 // 1 : OK if(!sim808_check_with_cmd("AT+CFUN=1\r\n","OK\r\n",CMD)){ From 1041dd67cdcf16a8f01ced2bd9bf4f8d1781d5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20H=C3=B8rup?= Date: Sun, 9 Jul 2017 21:11:07 +0200 Subject: [PATCH 2/9] use const char* instead of char* --- DFRobot_sim808.cpp | 2 +- DFRobot_sim808.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index 24d7549..c046c59 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -129,7 +129,7 @@ bool DFRobot_SIM808::checkSIMStatus(void) return true; } -bool DFRobot_SIM808::sendSMS(char *number, char *data) +bool DFRobot_SIM808::sendSMS(const char *number, const char *data) { //char cmd[32]; if(!sim808_check_with_cmd("AT+CMGF=1\r\n", "OK\r\n", CMD)) { // Set message mode to ASCII diff --git a/DFRobot_sim808.h b/DFRobot_sim808.h index 8d0845a..43dbcc4 100644 --- a/DFRobot_sim808.h +++ b/DFRobot_sim808.h @@ -97,7 +97,7 @@ class DFRobot_SIM808 * false on success * true on error */ - bool sendSMS(char* number, char* data); + bool sendSMS(const char* number, const char* data); /** Check if there is any UNREAD SMS: this function DOESN'T change the UNREAD status of the SMS * @returns From 823295cdb8bb9f54316b68ccfe4eae6763a063d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20H=C3=B8rup?= Date: Sun, 9 Jul 2017 21:19:00 +0200 Subject: [PATCH 3/9] add functions to stop/start gps UART dataflow --- DFRobot_sim808.cpp | 24 +++++++++++++++++++++++- DFRobot_sim808.h | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index c046c59..eab3b49 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -911,12 +911,34 @@ bool DFRobot_SIM808::attachGPS() bool DFRobot_SIM808::detachGPS() { - if(!sim808_check_with_cmd("AT+CGNSPWR=0\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd("AT+CGNSPWR=0\r\n", "OK\r\n", CMD)) { return false; } + if(!sim808_check_with_cmd("AT+CGNSTST=0\r\n", "OK\r\n", CMD)) { + return false; + } + return true; +} + +bool DFRobot_SIM808::stopGpsDataflow() +{ + if(!sim808_check_with_cmd("AT+CGNSTST=0\r\n", "OK\r\n", CMD)) { + return false; + } + return true; +} + +bool DFRobot_SIM808::startGpsDataflow() +{ + if(!sim808_check_with_cmd("AT+CGNSTST=1\r\n", "OK\r\n", CMD)) { + return false; + } return true; } + + + bool DFRobot_SIM808::getGPRMC() { char c; diff --git a/DFRobot_sim808.h b/DFRobot_sim808.h index 43dbcc4..38374a0 100644 --- a/DFRobot_sim808.h +++ b/DFRobot_sim808.h @@ -326,6 +326,11 @@ class DFRobot_SIM808 //Open or Close GPS bool attachGPS(); bool detachGPS(); + + //function to stop and start dataflow + bool startGpsDataflow(); + bool stopGpsDataflow(); + // Parse a (potentially negative) number with up to 2 decimal digits -xxxx.yy From 9d1cfbd5d474b5a2ac8f087681a6fd5b1de223a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20H=C3=B8rup?= Date: Mon, 10 Jul 2017 08:55:36 +0200 Subject: [PATCH 4/9] use extra precision in GPS example --- examples/SIM808_GetGPS/SIM808_GetGPS.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/SIM808_GetGPS/SIM808_GetGPS.ino b/examples/SIM808_GetGPS/SIM808_GetGPS.ino index a7bc279..247572d 100644 --- a/examples/SIM808_GetGPS/SIM808_GetGPS.ino +++ b/examples/SIM808_GetGPS/SIM808_GetGPS.ino @@ -55,9 +55,9 @@ void loop() { Serial.print(":"); Serial.println(sim808.GPSdata.centisecond); Serial.print("latitude :"); - Serial.println(sim808.GPSdata.lat); + Serial.println(sim808.GPSdata.lat, 6); Serial.print("longitude :"); - Serial.println(sim808.GPSdata.lon); + Serial.println(sim808.GPSdata.lon, 6); Serial.print("speed_kph :"); Serial.println(sim808.GPSdata.speed_kph); Serial.print("heading :"); From 6aa7ac5627812fc90d405e770043a4a0d679bd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20H=C3=B8rup?= Date: Tue, 25 Jul 2017 11:29:48 +0200 Subject: [PATCH 5/9] overload sendSMS to accept __FlashStringHelper* --- DFRobot_sim808.cpp | 23 +++++++++++++++++++++++ DFRobot_sim808.h | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index eab3b49..5e40a0f 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -152,6 +152,29 @@ bool DFRobot_SIM808::sendSMS(const char *number, const char *data) return sim808_wait_for_resp("OK\r\n", CMD); } +bool DFRobot_SIM808::sendSMS(const char *number, const __FlashStringHelper* data) +{ + //char cmd[32]; + if(!sim808_check_with_cmd("AT+CMGF=1\r\n", "OK\r\n", CMD)) { // Set message mode to ASCII + return false; + } + delay(500); + sim808_flush_serial(); + sim808_send_cmd("AT+CMGS=\""); + sim808_send_cmd(number); + //sprintf(cmd,"AT+CMGS=\"%s\"\r\n", number); + //snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n", number); +// if(!sim808_check_with_cmd(cmd,">",CMD)) { + if(!sim808_check_with_cmd("\"\r\n",">",CMD)) { + return false; + } + delay(1000); + sim808_send_cmd(data); + delay(500); + sim808_send_End_Mark(); + return sim808_wait_for_resp("OK\r\n", CMD); +} + char DFRobot_SIM808::isSMSunread() { char gprsBuffer[48]; //48 is enough to see +CMGL: diff --git a/DFRobot_sim808.h b/DFRobot_sim808.h index 38374a0..e3d0e3a 100644 --- a/DFRobot_sim808.h +++ b/DFRobot_sim808.h @@ -98,7 +98,9 @@ class DFRobot_SIM808 * true on error */ bool sendSMS(const char* number, const char* data); - + bool sendSMS(const char* number, const __FlashStringHelper* data); + + /** Check if there is any UNREAD SMS: this function DOESN'T change the UNREAD status of the SMS * @returns * 1..20 on success, position/index where SMS is stored, suitable for the function ReadSMS From 8c45019bd68d71d9ab9697ea6196bf0d6977ea4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20H=C3=B8rup?= Date: Tue, 25 Jul 2017 13:37:49 +0200 Subject: [PATCH 6/9] Force AT* const strings to PROGMEM in order to save arduino memory --- DFRobot_sim808.cpp | 97 +++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index 5e40a0f..587d4fd 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -30,6 +30,7 @@ #include +#include #include "DFRobot_sim808.h" extern Stream *serialSIM808; @@ -60,18 +61,18 @@ DFRobot_SIM808::DFRobot_SIM808(SoftwareSerial *mySerial) bool DFRobot_SIM808::init(void) { //检查AT指令是否有效 - if(!sim808_check_with_cmd("AT\r\n","OK\r\n",CMD)){ + if(!sim808_check_with_cmd( F("AT\r\n"),"OK\r\n",CMD)){ return false; } // Reset to factory defaults - if(!sim808_check_with_cmd("ATZ\r\n","OK\r\n",CMD)){ + if(!sim808_check_with_cmd( F("ATZ\r\n"),"OK\r\n",CMD)){ return false; } //检查SIM是否可以打电话,发短信 // 1 : OK - if(!sim808_check_with_cmd("AT+CFUN=1\r\n","OK\r\n",CMD)){ + if(!sim808_check_with_cmd( F("AT+CFUN=1\r\n"),"OK\r\n",CMD)){ return false; } @@ -84,7 +85,7 @@ bool DFRobot_SIM808::init(void) bool DFRobot_SIM808::checkPowerUp(void) { - return sim808_check_with_cmd("AT\r\n","OK\r\n",CMD); + return sim808_check_with_cmd( F("AT\r\n"),"OK\r\n",CMD); } void DFRobot_SIM808::powerUpDown(uint8_t pin) @@ -115,7 +116,7 @@ bool DFRobot_SIM808::checkSIMStatus(void) int count = 0; sim808_clean_buffer(gprsBuffer,32); while(count < 3) { - sim808_send_cmd("AT+CPIN?\r\n"); + sim808_send_cmd( F("AT+CPIN?\r\n") ); sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT); if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) { //表示SIM状态正常 break; @@ -132,12 +133,12 @@ bool DFRobot_SIM808::checkSIMStatus(void) bool DFRobot_SIM808::sendSMS(const char *number, const char *data) { //char cmd[32]; - if(!sim808_check_with_cmd("AT+CMGF=1\r\n", "OK\r\n", CMD)) { // Set message mode to ASCII + if(!sim808_check_with_cmd( F("AT+CMGF=1\r\n"), "OK\r\n", CMD)) { // Set message mode to ASCII return false; } delay(500); sim808_flush_serial(); - sim808_send_cmd("AT+CMGS=\""); + sim808_send_cmd( F("AT+CMGS=\"") ); sim808_send_cmd(number); //sprintf(cmd,"AT+CMGS=\"%s\"\r\n", number); //snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n", number); @@ -155,12 +156,12 @@ bool DFRobot_SIM808::sendSMS(const char *number, const char *data) bool DFRobot_SIM808::sendSMS(const char *number, const __FlashStringHelper* data) { //char cmd[32]; - if(!sim808_check_with_cmd("AT+CMGF=1\r\n", "OK\r\n", CMD)) { // Set message mode to ASCII + if(!sim808_check_with_cmd( F("AT+CMGF=1\r\n"), "OK\r\n", CMD)) { // Set message mode to ASCII return false; } delay(500); sim808_flush_serial(); - sim808_send_cmd("AT+CMGS=\""); + sim808_send_cmd( F("AT+CMGS=\"") ); sim808_send_cmd(number); //sprintf(cmd,"AT+CMGS=\"%s\"\r\n", number); //snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n", number); @@ -180,11 +181,11 @@ char DFRobot_SIM808::isSMSunread() char gprsBuffer[48]; //48 is enough to see +CMGL: char *s; - sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD); + sim808_check_with_cmd( F("AT+CMGF=1\r\n"),"OK\r\n",CMD); delay(1000); //List of all UNREAD SMS and DON'T change the SMS UNREAD STATUS - sim808_send_cmd(F("AT+CMGL=\"REC UNREAD\",1\r\n")); + sim808_send_cmd( F("AT+CMGL=\"REC UNREAD\",1\r\n") ); /*If you want to change SMS status to READ you will need to send: AT+CMGL=\"REC UNREAD\"\r\n This command will list all UNREAD SMS and change all of them to READ @@ -225,7 +226,7 @@ char DFRobot_SIM808::isSMSunread() sim808_wait_for_resp("OK\r\n", CMD); //sim808_flush_serial(); //We have to call command again - sim808_send_cmd("AT+CMGL=\"REC UNREAD\",1\r\n"); + sim808_send_cmd( F("AT+CMGL=\"REC UNREAD\", 1\r\n" ) ); sim808_clean_buffer(gprsBuffer,48); sim808_read_buffer(gprsBuffer,47,DEFAULT_TIMEOUT); //Serial.print("Buffer isSMSunread 2: ");Serial.println(gprsBuffer); @@ -262,11 +263,11 @@ bool DFRobot_SIM808::readSMS(int messageIndex, char *message, int length, char * char num[4]; char *p,*p2,*s; - sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD); + sim808_check_with_cmd( F("AT+CMGF=1\r\n"),"OK\r\n",CMD); delay(1000); //sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex); //sim808_send_cmd(cmd); - sim808_send_cmd("AT+CMGR="); + sim808_send_cmd( F("AT+CMGR=")); itoa(messageIndex, num, 10); sim808_send_cmd(num); sim808_send_cmd("\r\n"); @@ -319,9 +320,9 @@ bool DFRobot_SIM808::readSMS(int messageIndex, char *message,int length) char num[4]; char *p,*s; - sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD); + sim808_check_with_cmd( F("AT+CMGF=1\r\n"), "OK\r\n",CMD); delay(1000); - sim808_send_cmd("AT+CMGR="); + sim808_send_cmd( F("AT+CMGR=")); itoa(messageIndex, num, 10); sim808_send_cmd(num); sim808_send_cmd("\r\n"); @@ -347,7 +348,7 @@ bool DFRobot_SIM808::deleteSMS(int index) //char cmd[16]; char num[4]; //sprintf(cmd,"AT+CMGD=%d\r\n",index); - sim808_send_cmd("AT+CMGD="); + sim808_send_cmd( F("AT+CMGD=") ); itoa(index, num, 10); sim808_send_cmd(num); //snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index); @@ -361,14 +362,14 @@ bool DFRobot_SIM808::deleteSMS(int index) bool DFRobot_SIM808::callUp(char *number) { //char cmd[24]; - if(!sim808_check_with_cmd("AT+COLP=1\r\n","OK\r\n",CMD)) { + if(!sim808_check_with_cmd( F("AT+COLP=1\r\n"),"OK\r\n",CMD)) { return false; } delay(1000); //HACERR quitar SPRINTF para ahorar memoria ??? //sprintf(cmd,"ATD%s;\r\n", number); //sim808_send_cmd(cmd); - sim808_send_cmd("ATD"); + sim808_send_cmd( F("ATD") ); sim808_send_cmd(number); sim808_send_cmd(";\r\n"); return true; @@ -376,17 +377,17 @@ bool DFRobot_SIM808::callUp(char *number) void DFRobot_SIM808::answer(void) { - sim808_send_cmd("ATA\r\n"); //TO CHECK: ATA doesnt return "OK" ???? + sim808_send_cmd( F("ATA\r\n") ); //TO CHECK: ATA doesnt return "OK" ???? } bool DFRobot_SIM808::hangup(void) { - return sim808_check_with_cmd("ATH\r\n","OK\r\n",CMD); + return sim808_check_with_cmd( F("ATH\r\n"),"OK\r\n",CMD); } bool DFRobot_SIM808::disableCLIPring(void) { - return sim808_check_with_cmd("AT+CLIP=0\r\n","OK\r\n",CMD); + return sim808_check_with_cmd( F("AT+CLIP=0\r\n"),"OK\r\n",CMD); } bool DFRobot_SIM808::getSubscriberNumber(char *number) @@ -400,7 +401,7 @@ bool DFRobot_SIM808::getSubscriberNumber(char *number) char gprsBuffer[65]; char *p,*s; sim808_flush_serial(); - sim808_send_cmd("AT+CNUM\r\n"); + sim808_send_cmd( F("AT+CNUM\r\n") ); sim808_clean_buffer(gprsBuffer,65); sim808_read_buffer(gprsBuffer,65,DEFAULT_TIMEOUT); //Serial.print(gprsBuffer); @@ -426,7 +427,7 @@ bool DFRobot_SIM808::isCallActive(char *number) char *p, *s; int i = 0; - sim808_send_cmd("AT+CPAS\r\n"); + sim808_send_cmd( F("AT+CPAS\r\n") ); /*Result code: 0: ready 2: unknown @@ -458,7 +459,7 @@ bool DFRobot_SIM808::isCallActive(char *number) //There is something "running" (but number 2 that is unknow) if (*s != '2') { //3 or 4, let's go to check for the number - sim808_send_cmd("AT+CLCC\r\n"); + sim808_send_cmd( F("AT+CLCC\r\n") ); /* AT+CLCC --> 9 @@ -518,7 +519,7 @@ bool DFRobot_SIM808::getDateTime(char *buffer) char gprsBuffer[50]; char *p,*s; sim808_flush_serial(); - sim808_send_cmd("AT+CCLK?\r"); + sim808_send_cmd( F("AT+CCLK?\r") ); sim808_clean_buffer(gprsBuffer,50); sim808_read_buffer(gprsBuffer,50,DEFAULT_TIMEOUT); if(NULL != ( s = strstr(gprsBuffer,"+CCLK:"))) { @@ -548,7 +549,7 @@ bool DFRobot_SIM808::getSignalStrength(int *buffer) char *p, *s; char buffers[4]; sim808_flush_serial(); - sim808_send_cmd("AT+CSQ\r"); + sim808_send_cmd( F("AT+CSQ\r") ); sim808_clean_buffer(gprsBuffer, 26); sim808_read_buffer(gprsBuffer, 26, DEFAULT_TIMEOUT); if (NULL != (s = strstr(gprsBuffer, "+CSQ:"))) { @@ -581,7 +582,7 @@ bool DFRobot_SIM808::sendUSSDSynchronous(char *ussdCommand, char *resultcode, ch sim808_clean_buffer(response, sizeof(response)); sim808_flush_serial(); - sim808_send_cmd("AT+CUSD=1,\""); + sim808_send_cmd( F("AT+CUSD=1,\"") ); sim808_send_cmd(ussdCommand); sim808_send_cmd("\"\r"); if(!sim808_wait_for_resp("OK\r\n", CMD)) @@ -610,7 +611,7 @@ bool DFRobot_SIM808::sendUSSDSynchronous(char *ussdCommand, char *resultcode, ch bool DFRobot_SIM808::cancelUSSDSession(void) { - return sim808_check_with_cmd("AT+CUSD=2\r\n","OK\r\n",CMD); + return sim808_check_with_cmd( F("AT+CUSD=2\r\n"),"OK\r\n",CMD); } //Here is where we ask for APN configuration, with F() so we can save MEMORY @@ -625,7 +626,7 @@ bool DFRobot_SIM808::join(const __FlashStringHelper *apn, const __FlashStringHel //set APN. OLD VERSION //snprintf(cmd,sizeof(cmd),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",_apn,_userName,_passWord); //sim808_check_with_cmd(cmd, "OK\r\n", DEFAULT_TIMEOUT,CMD); - sim808_send_cmd("AT+CSTT=\""); + sim808_send_cmd( F("AT+CSTT=\"") ); if (apn) { sim808_send_cmd(apn); } @@ -641,10 +642,10 @@ bool DFRobot_SIM808::join(const __FlashStringHelper *apn, const __FlashStringHel //Brings up wireless connection - sim808_check_with_cmd("AT+CIICR\r\n","OK\r\n", CMD); + sim808_check_with_cmd( F("AT+CIICR\r\n"),"OK\r\n", CMD); //Get local IP address - sim808_send_cmd("AT+CIFSR\r\n"); + sim808_send_cmd( F("AT+CIFSR\r\n") ); sim808_clean_buffer(ipAddr,32); sim808_read_buffer(ipAddr,32); //Response: @@ -676,7 +677,7 @@ bool DFRobot_SIM808::join(const __FlashStringHelper *apn, const __FlashStringHel void DFRobot_SIM808::disconnect() { - sim808_send_cmd("AT+CIPSHUT\r\n"); + sim808_send_cmd( F("AT+CIPSHUT\r\n") ); } bool DFRobot_SIM808::connect(Protocol ptl,const char * host, int port, int timeout, int chartimeout) @@ -687,7 +688,7 @@ bool DFRobot_SIM808::connect(Protocol ptl,const char * host, int port, int timeo //sim808_clean_buffer(cmd,64); if(ptl == TCP) { - sim808_send_cmd("AT+CIPSTART=\"TCP\",\""); + sim808_send_cmd( F("AT+CIPSTART=\"TCP\",\"") ); sim808_send_cmd(host); sim808_send_cmd("\","); itoa(port, num, 10); @@ -695,7 +696,7 @@ bool DFRobot_SIM808::connect(Protocol ptl,const char * host, int port, int timeo sim808_send_cmd("\r\n"); // sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",%d\r\n",host, port); } else if(ptl == UDP) { - sim808_send_cmd("AT+CIPSTART=\"UDP\",\""); + sim808_send_cmd( F("AT+CIPSTART=\"UDP\",\"")); sim808_send_cmd(host); sim808_send_cmd("\","); itoa(port, num, 10); @@ -747,7 +748,7 @@ bool DFRobot_SIM808::connect(Protocol ptl,const __FlashStringHelper *host, const bool DFRobot_SIM808::is_connected(void) { char resp[96]; - sim808_send_cmd("AT+CIPSTATUS\r\n"); + sim808_send_cmd( F("AT+CIPSTATUS\r\n") ); sim808_read_buffer(resp,sizeof(resp),DEFAULT_TIMEOUT); if(NULL != strstr(resp,"CONNECTED")) { //+CIPSTATUS: 1,0,"TCP","216.52.233.120","80","CONNECTED" @@ -765,7 +766,7 @@ bool DFRobot_SIM808::close() if (!is_connected()) { return true; } - return sim808_check_with_cmd("AT+CIPCLOSE\r\n", "CLOSE OK\r\n", CMD); + return sim808_check_with_cmd( F("AT+CIPCLOSE\r\n"), "CLOSE OK\r\n", CMD); } int DFRobot_SIM808::readable(void) @@ -790,7 +791,7 @@ int DFRobot_SIM808::send(const char * str, int len) if(len > 0){ //snprintf(cmd,sizeof(cmd),"AT+CIPSEND=%d\r\n",len); //sprintf(cmd,"AT+CIPSEND=%d\r\n",len); - sim808_send_cmd("AT+CIPSEND="); + sim808_send_cmd( F("AT+CIPSEND=") ); itoa(len, num, 10); sim808_send_cmd(num); if(!sim808_check_with_cmd("\r\n",">",CMD)) { @@ -883,19 +884,19 @@ bool DFRobot_SIM808::getLocation(const __FlashStringHelper *apn, float *longitud char *s; //send AT+SAPBR=3,1,"Contype","DFRobot_SIM808" - sim808_check_with_cmd("AT+SAPBR=3,1,\"Contype\",\"DFRobot_SIM808\"\r","OK\r\n",CMD); + sim808_check_with_cmd( F("AT+SAPBR=3,1,\"Contype\",\"DFRobot_SIM808\"\r"),"OK\r\n",CMD); //sen AT+SAPBR=3,1,"APN","DFRobot_SIM808_APN" - sim808_send_cmd("AT+SAPBR=3,1,\"APN\",\""); + sim808_send_cmd( F("AT+SAPBR=3,1,\"APN\",\"") ); if (apn) { sim808_send_cmd(apn); } sim808_check_with_cmd("\"\r","OK\r\n",CMD); //send AT+SAPBR =1,1 - sim808_check_with_cmd("AT+SAPBR=1,1\r","OK\r\n",CMD); + sim808_check_with_cmd( F("AT+SAPBR=1,1\r"),"OK\r\n",CMD); //AT+CIPGSMLOC=1,1 sim808_flush_serial(); - sim808_send_cmd("AT+CIPGSMLOC=1,1\r"); + sim808_send_cmd( F("AT+CIPGSMLOC=1,1\r") ); sim808_clean_buffer(gprsBuffer,sizeof(gprsBuffer)); sim808_read_buffer(gprsBuffer,sizeof(gprsBuffer),2*DEFAULT_TIMEOUT,6*DEFAULT_INTERCHAR_TIMEOUT); //Serial.println(gprsBuffer); @@ -923,10 +924,10 @@ bool DFRobot_SIM808::getLocation(const __FlashStringHelper *apn, float *longitud bool DFRobot_SIM808::attachGPS() { - if(!sim808_check_with_cmd("AT+CGNSPWR=1\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd( F("AT+CGNSPWR=1\r\n"), "OK\r\n", CMD)) { return false; } - if(!sim808_check_with_cmd("AT+CGNSTST=1\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd( F("AT+CGNSTST=1\r\n"), "OK\r\n", CMD)) { return false; } return true; @@ -934,10 +935,10 @@ bool DFRobot_SIM808::attachGPS() bool DFRobot_SIM808::detachGPS() { - if(!sim808_check_with_cmd("AT+CGNSPWR=0\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd( F("AT+CGNSPWR=0\r\n"), "OK\r\n", CMD)) { return false; } - if(!sim808_check_with_cmd("AT+CGNSTST=0\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd( F("AT+CGNSTST=0\r\n"), "OK\r\n", CMD)) { return false; } return true; @@ -945,7 +946,7 @@ bool DFRobot_SIM808::detachGPS() bool DFRobot_SIM808::stopGpsDataflow() { - if(!sim808_check_with_cmd("AT+CGNSTST=0\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd( F("AT+CGNSTST=0\r\n"), "OK\r\n", CMD)) { return false; } return true; @@ -953,7 +954,7 @@ bool DFRobot_SIM808::stopGpsDataflow() bool DFRobot_SIM808::startGpsDataflow() { - if(!sim808_check_with_cmd("AT+CGNSTST=1\r\n", "OK\r\n", CMD)) { + if(!sim808_check_with_cmd( F("AT+CGNSTST=1\r\n"), "OK\r\n", CMD)) { return false; } return true; From e45f02c00f2ecb9f79c3c049d2a811e661fa1708 Mon Sep 17 00:00:00 2001 From: caladeira Date: Sun, 30 Jul 2017 15:34:12 +0100 Subject: [PATCH 7/9] Add files via upload Added the following methods: char isSMS(typeSMS type = ALL); bool getInfGPS(); Corrections on: bool sendUSSDSynchronous(char *ussdCommand, char *resultcode, char *response); --- DFRobot_sim808.cpp | 219 ++++++++++++++++++++++++++++++++++++++++++--- DFRobot_sim808.h | 34 +++++-- 2 files changed, 235 insertions(+), 18 deletions(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index 587d4fd..f5f60a0 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -30,7 +30,7 @@ #include -#include +#include // in my linux system, names are case sensitive #include "DFRobot_sim808.h" extern Stream *serialSIM808; @@ -246,6 +246,92 @@ char DFRobot_SIM808::isSMSunread() return -1; } +char DFRobot_SIM808::isSMS(typeSMS type) +{ + char gprsBuffer[48]; //48 is enough to see +CMGL: + char *s; + + sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD); + delay(1000); + + //List of all UNREAD SMS and DON'T change the SMS UNREAD STATUS + sim808_send_cmd(F("AT+CMGL=\"")); + switch (type) { + case REC_UNREAD: sim808_send_cmd(F("REC UNREAD")); break; + case REC_READ: sim808_send_cmd(F("REC READ")); break; + case STO_UNSENT: sim808_send_cmd(F("STO UNSENT")); break; + case STO_SENT: sim808_send_cmd(F("STO SENT")); break; + case ALL: sim808_send_cmd(F("ALL")); + }; + sim808_send_cmd(F("\",1\r\n")); + /*If you want to change SMS status to READ you will need to send: + AT+CMGL=\"REC UNREAD\"\r\n + This command will list all UNREAD SMS and change all of them to READ + + If there is not SMS, response is (30 chars) + AT+CMGL="REC UNREAD",1 --> 22 + 2 + --> 2 + OK --> 2 + 2 + + If there is SMS, response is like (>64 chars) + AT+CMGL="REC UNREAD",1 + +CMGL: 9,"REC UNREAD","XXXXXXXXX","","14/10/16,21:40:08+08" + Here SMS text. + OK + + or + + AT+CMGL="REC UNREAD",1 + +CMGL: 9,"REC UNREAD","XXXXXXXXX","","14/10/16,21:40:08+08" + Here SMS text. + +CMGL: 10,"REC UNREAD","YYYYYYYYY","","14/10/16,21:40:08+08" + Here second SMS + OK + */ + + sim808_clean_buffer(gprsBuffer,31); + sim808_read_buffer(gprsBuffer,30,DEFAULT_TIMEOUT); + //Serial.print("Buffer isSMSunread: ");Serial.println(gprsBuffer); + + if(NULL != ( s = strstr(gprsBuffer,"OK"))) { + //In 30 bytes "doesn't" fit whole +CMGL: response, if recieve only "OK" + // means you don't have any UNREAD SMS + delay(50); + return 0; + } else { + //More buffer to read + //We are going to flush serial data until OK is recieved + sim808_wait_for_resp("OK\r\n", CMD); + //sim808_flush_serial(); + //We have to call command again + sim808_send_cmd(F("AT+CMGL=\"")); + switch (type) { + case REC_UNREAD: sim808_send_cmd(F("REC UNREAD")); break; + case REC_READ: sim808_send_cmd(F("REC READ")); break; + case STO_UNSENT: sim808_send_cmd(F("STO UNSENT")); break; + case STO_SENT: sim808_send_cmd(F("STO SENT")); break; + case ALL: sim808_send_cmd(F("ALL")); + }; + sim808_send_cmd(F("\",1\r\n")); + sim808_clean_buffer(gprsBuffer,48); + sim808_read_buffer(gprsBuffer,47,DEFAULT_TIMEOUT); + //Serial.print("Buffer isSMSunread 2: ");Serial.println(gprsBuffer); + if(NULL != ( s = strstr(gprsBuffer,"+CMGL:"))) { + //There is at least one UNREAD SMS, get index/position + s = strstr(gprsBuffer,":"); + if (s != NULL) { + //We are going to flush serial data until OK is recieved + sim808_wait_for_resp("OK\r\n", CMD); + return atoi(s+1); + } + } else { + return -1; + + } + } + return -1; +} + bool DFRobot_SIM808::readSMS(int messageIndex, char *message, int length, char *phone, char *datetime) { /* Response is like: @@ -576,25 +662,27 @@ bool DFRobot_SIM808::sendUSSDSynchronous(char *ussdCommand, char *resultcode, ch // //+CUSD:1,"{response}",{int} - byte i = 0; + byte i = 0; char gprsBuffer[200]; char *p,*s; - sim808_clean_buffer(response, sizeof(response)); + // nonsense, sizeof(response) is not the size of the buffer! + //sim808_clean_buffer(response, sizeof(response)); - sim808_flush_serial(); + sim808_flush_serial(); sim808_send_cmd( F("AT+CUSD=1,\"") ); sim808_send_cmd(ussdCommand); sim808_send_cmd("\"\r"); - if(!sim808_wait_for_resp("OK\r\n", CMD)) + delay(500); // I had beter results with this delay (caladeira) + if(!sim808_wait_for_resp("OK\r\n", CMD)) return false; sim808_clean_buffer(gprsBuffer,200); sim808_read_buffer(gprsBuffer,200,DEFAULT_TIMEOUT); if(NULL != ( s = strstr(gprsBuffer,"+CUSD: "))) { *resultcode = *(s+7); - resultcode[1] = '\0'; - if(!('0' <= *resultcode && *resultcode <= '2')) - return false; - s = strstr(s,"\""); + resultcode[1] = '\0'; + if(!('0' <= *resultcode && *resultcode <= '2')) + return false; + s = strstr(s,"\""); s = s + 1; //We are in the first phone number character p = strstr(s,"\""); //p is last character """ if (NULL != s) { @@ -604,9 +692,9 @@ bool DFRobot_SIM808::sendUSSDSynchronous(char *ussdCommand, char *resultcode, ch } response[i] = '\0'; } - return true; - } - return false; + return true; + } + return false; } bool DFRobot_SIM808::cancelUSSDSession(void) @@ -1168,4 +1256,111 @@ bool DFRobot_SIM808::getGPS() return true; } +/* + Parse GPS data after command AT+CGNSINF + stopGpsDataflow() must be called right after attachGPS() to avoid + constant data flow with gps data + This way, gps function can be used simultaneously with other chip functions + unlike getGPS() that needs gps data flow to be on + +== without FIX == +AT+CGNSINF ++CGNSINF: 1,0,20170729175800.000,,,,0.52,180.4,0,,,,,,12,3,,,34,, + +== with FIX == +AT+CGNSINF ++CGNSINF: 1,1,20170729175803.000,38.975588,-9.258235,129.400,1.02,75.1,1,,1.3,1.6,0.9,,12,5,,,41,, + +*/ + +bool DFRobot_SIM808::getInfGPS() +{ + char gprsBuffer[120]; + char buf[5]; + char *s, *tok; + + sim808_flush_serial(); + sim808_send_cmd("AT+CGNSINF\r"); + sim808_clean_buffer(gprsBuffer, 120); + sim808_read_buffer(gprsBuffer, 120, DEFAULT_TIMEOUT); + if (NULL != (s = strstr(gprsBuffer, "+CGNSINF:"))) { + s += 10; + + // skip gps status + if (strsep(&s,",") == NULL) return false; + + // check fix + if ((tok = strsep(&s,",")) == NULL) return false; + if (atoi(tok) != 1) return false; // valid data only after fix + + // grab time & date + if ((tok = strsep(&s,",")) == NULL) return false; + strncpy(buf, tok, 4); buf[4] = '\0'; // YYYYmmddhhmmss.ccc + GPSdata.year = atoi(buf); + strncpy(buf, tok+4, 2); buf[2] = '\0'; // yyyyMMddhhmmss.ccc + GPSdata.month = atoi(buf); + strncpy(buf, tok+6, 2); buf[2] = '\0'; // yyyymmDDhhmmss.ccc + GPSdata.day = atoi(buf); + strncpy(buf, tok+8, 2); buf[2] = '\0'; // yyyymmddHHmmss.ccc + GPSdata.hour = atoi(buf); + strncpy(buf, tok+10, 2); buf[2] = '\0'; // yyyymmddhhMMss.ccc + GPSdata.minute = atoi(buf); + strncpy(buf, tok+12, 2); buf[2] = '\0'; // yyyymmddhhmmSS.ccc + GPSdata.second = atoi(buf); + strncpy(buf, tok+15, 3); buf[3] = '\0'; // yyyymmddhhmmss.CCC + GPSdata.centisecond = atoi(buf); + + // grab the latitude + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.lat = atof(tok); + + // grab longitude + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.lon = atof(tok); + + // skip MSL Altitude + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.altitude = atof(tok) * 1.852; + + // grab the speed in knots + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.speed_kph = atof(tok) * 1.852; + + // grab the heading + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.heading = atof(tok); + + // skip fix mode + if (strsep(&s,",") == NULL) return false; + + // skip recerved1 + if (strsep(&s,",") == NULL) return false; + + // skip hdop + if (strsep(&s,",") == NULL) return false; + + // skip pdop + if (strsep(&s,",") == NULL) return false; + + // skip vdop + if (strsep(&s,",") == NULL) return false; + + // skip reserved2 + if (strsep(&s,",") == NULL) return false; + + // get gps satelites in view + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.satelites_view = atoi(tok); + + // grab gnss satelites used + if ((tok = strsep(&s,",")) == NULL) return false; + GPSdata.satelites_use = atoi(tok); + + // no need to continue + return true; + } + return false; +} + + diff --git a/DFRobot_sim808.h b/DFRobot_sim808.h index e3d0e3a..63358d6 100644 --- a/DFRobot_sim808.h +++ b/DFRobot_sim808.h @@ -43,6 +43,17 @@ enum Protocol { UDP = 2, }; +/* Type of SMS to isSMS function + * + */ +enum typeSMS { + REC_UNREAD, + REC_READ, + STO_UNSENT, + STO_SENT, + ALL +}; + class DFRobot_SIM808 { public: @@ -107,8 +118,15 @@ class DFRobot_SIM808 * -1 on error * 0 - there is no SMS with specified status (UNREAD) */ + char isSMSunread(); - char isSMSunread(); + /** Check if there is any SMS present of the specified type, default to ALL + * @returns + * 1..20 on success, position/index where SMS is stored, suitable for the function ReadSMS + * -1 on error + * 0 - there is no SMS with specified status (UNREAD) + */ + char isSMS(typeSMS type = ALL); /** read SMS, phone and date if getting a SMS message. It changes SMS status to READ * @param messageIndex SIM position to read @@ -347,14 +365,16 @@ class DFRobot_SIM808 //get GPS signal bool getGPS(); + + // get gps information + bool getInfGPS(); - - SoftwareSerial *gprsSerial; - HardwareSerial *hgprsSerial; + SoftwareSerial *gprsSerial; + HardwareSerial *hgprsSerial; Stream *sgprsSerial; public: - struct gspdata{ + struct gpsdata { uint16_t year; uint8_t month; uint8_t day; @@ -367,7 +387,9 @@ class DFRobot_SIM808 float speed_kph; float heading; float altitude; - }GPSdata; + uint8_t satelites_view; + uint8_t satelites_use; + } GPSdata; private: byte serialFlag; From eccd212edf3cd0ac05931ee2e8c6c4771f8086f2 Mon Sep 17 00:00:00 2001 From: caladeira Date: Sun, 30 Jul 2017 20:10:24 +0100 Subject: [PATCH 8/9] Add files via upload --- DFRobot_sim808.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index f5f60a0..16d1bf6 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -1269,7 +1269,7 @@ AT+CGNSINF == with FIX == AT+CGNSINF -+CGNSINF: 1,1,20170729175803.000,38.975588,-9.258235,129.400,1.02,75.1,1,,1.3,1.6,0.9,,12,5,,,41,, ++CGNSINF: 1,1,20170729175803.000,38.707528,-9.136422,129.400,1.02,75.1,1,,1.3,1.6,0.9,,12,5,,,41,, */ From bec8c65caf2dc38e9b3e766be282e27fbda2dd88 Mon Sep 17 00:00:00 2001 From: caladeira Date: Thu, 3 Aug 2017 22:42:12 +0100 Subject: [PATCH 9/9] Added some corrections suggested by @hoerup Add some F() functions and commented the command "AT+CGNSTST=1" at attachGPS() function as suggested by @hoerup --- DFRobot_sim808.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/DFRobot_sim808.cpp b/DFRobot_sim808.cpp index 16d1bf6..0346eb3 100644 --- a/DFRobot_sim808.cpp +++ b/DFRobot_sim808.cpp @@ -143,7 +143,7 @@ bool DFRobot_SIM808::sendSMS(const char *number, const char *data) //sprintf(cmd,"AT+CMGS=\"%s\"\r\n", number); //snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n", number); // if(!sim808_check_with_cmd(cmd,">",CMD)) { - if(!sim808_check_with_cmd("\"\r\n",">",CMD)) { + if(!sim808_check_with_cmd(F("\"\r\n"),">",CMD)) { return false; } delay(1000); @@ -166,7 +166,7 @@ bool DFRobot_SIM808::sendSMS(const char *number, const __FlashStringHelper* data //sprintf(cmd,"AT+CMGS=\"%s\"\r\n", number); //snprintf(cmd, sizeof(cmd),"AT+CMGS=\"%s\"\r\n", number); // if(!sim808_check_with_cmd(cmd,">",CMD)) { - if(!sim808_check_with_cmd("\"\r\n",">",CMD)) { + if(!sim808_check_with_cmd(F("\"\r\n"),">",CMD)) { return false; } delay(1000); @@ -251,7 +251,7 @@ char DFRobot_SIM808::isSMS(typeSMS type) char gprsBuffer[48]; //48 is enough to see +CMGL: char *s; - sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD); + sim808_check_with_cmd(F("AT+CMGF=1\r\n"),"OK\r\n",CMD); delay(1000); //List of all UNREAD SMS and DON'T change the SMS UNREAD STATUS @@ -411,7 +411,7 @@ bool DFRobot_SIM808::readSMS(int messageIndex, char *message,int length) sim808_send_cmd( F("AT+CMGR=")); itoa(messageIndex, num, 10); sim808_send_cmd(num); - sim808_send_cmd("\r\n"); + sim808_send_cmd(F("\r\n")); // sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex); // sim808_send_cmd(cmd); sim808_clean_buffer(gprsBuffer,sizeof(gprsBuffer)); @@ -442,7 +442,7 @@ bool DFRobot_SIM808::deleteSMS(int index) //return 0; // We have to wait OK response //return sim808_check_with_cmd(cmd,"OK\r\n",CMD); - return sim808_check_with_cmd("\r","OK\r\n",CMD); + return sim808_check_with_cmd(F("\r"),"OK\r\n",CMD); } bool DFRobot_SIM808::callUp(char *number) @@ -457,7 +457,7 @@ bool DFRobot_SIM808::callUp(char *number) //sim808_send_cmd(cmd); sim808_send_cmd( F("ATD") ); sim808_send_cmd(number); - sim808_send_cmd(";\r\n"); + sim808_send_cmd(F(";\r\n")); return true; } @@ -671,7 +671,7 @@ bool DFRobot_SIM808::sendUSSDSynchronous(char *ussdCommand, char *resultcode, ch sim808_flush_serial(); sim808_send_cmd( F("AT+CUSD=1,\"") ); sim808_send_cmd(ussdCommand); - sim808_send_cmd("\"\r"); + sim808_send_cmd(F("\"\r")); delay(500); // I had beter results with this delay (caladeira) if(!sim808_wait_for_resp("OK\r\n", CMD)) return false; @@ -718,15 +718,15 @@ bool DFRobot_SIM808::join(const __FlashStringHelper *apn, const __FlashStringHel if (apn) { sim808_send_cmd(apn); } - sim808_send_cmd("\",\""); + sim808_send_cmd(F("\",\"")); if (userName) { sim808_send_cmd(userName); } - sim808_send_cmd("\",\""); + sim808_send_cmd(F("\",\"")); if (passWord) { sim808_send_cmd(passWord); } - sim808_check_with_cmd("\"\r\n", "OK\r\n", CMD); + sim808_check_with_cmd(F("\"\r\n"), "OK\r\n", CMD); //Brings up wireless connection @@ -778,18 +778,18 @@ bool DFRobot_SIM808::connect(Protocol ptl,const char * host, int port, int timeo if(ptl == TCP) { sim808_send_cmd( F("AT+CIPSTART=\"TCP\",\"") ); sim808_send_cmd(host); - sim808_send_cmd("\","); + sim808_send_cmd(F("\",")); itoa(port, num, 10); sim808_send_cmd(num); - sim808_send_cmd("\r\n"); + sim808_send_cmd(F("\r\n")); // sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",%d\r\n",host, port); } else if(ptl == UDP) { sim808_send_cmd( F("AT+CIPSTART=\"UDP\",\"")); sim808_send_cmd(host); - sim808_send_cmd("\","); + sim808_send_cmd(F("\",")); itoa(port, num, 10); sim808_send_cmd(num); - sim808_send_cmd("\r\n"); + sim808_send_cmd(F("\r\n")); // sprintf(cmd, "AT+CIPSTART=\"UDP\",\"%s\",%d\r\n",host, port); } else { @@ -882,7 +882,7 @@ int DFRobot_SIM808::send(const char * str, int len) sim808_send_cmd( F("AT+CIPSEND=") ); itoa(len, num, 10); sim808_send_cmd(num); - if(!sim808_check_with_cmd("\r\n",">",CMD)) { + if(!sim808_check_with_cmd(F("\r\n"),">",CMD)) { //if(!sim808_check_with_cmd(cmd,">",CMD)) { return 0; } @@ -978,7 +978,7 @@ bool DFRobot_SIM808::getLocation(const __FlashStringHelper *apn, float *longitud if (apn) { sim808_send_cmd(apn); } - sim808_check_with_cmd("\"\r","OK\r\n",CMD); + sim808_check_with_cmd(F("\"\r"),"OK\r\n",CMD); //send AT+SAPBR =1,1 sim808_check_with_cmd( F("AT+SAPBR=1,1\r"),"OK\r\n",CMD); @@ -1015,9 +1015,11 @@ bool DFRobot_SIM808::attachGPS() if(!sim808_check_with_cmd( F("AT+CGNSPWR=1\r\n"), "OK\r\n", CMD)) { return false; } + /* if(!sim808_check_with_cmd( F("AT+CGNSTST=1\r\n"), "OK\r\n", CMD)) { return false; } + */ return true; } @@ -1256,10 +1258,10 @@ bool DFRobot_SIM808::getGPS() return true; } + /* Parse GPS data after command AT+CGNSINF - stopGpsDataflow() must be called right after attachGPS() to avoid - constant data flow with gps data + GPS data flow must be stoped for this to work correctlly: stopGpsDataflow() This way, gps function can be used simultaneously with other chip functions unlike getGPS() that needs gps data flow to be on @@ -1280,7 +1282,7 @@ bool DFRobot_SIM808::getInfGPS() char *s, *tok; sim808_flush_serial(); - sim808_send_cmd("AT+CGNSINF\r"); + sim808_send_cmd(F("AT+CGNSINF\r")); sim808_clean_buffer(gprsBuffer, 120); sim808_read_buffer(gprsBuffer, 120, DEFAULT_TIMEOUT); if (NULL != (s = strstr(gprsBuffer, "+CGNSINF:"))) { @@ -1293,7 +1295,7 @@ bool DFRobot_SIM808::getInfGPS() if ((tok = strsep(&s,",")) == NULL) return false; if (atoi(tok) != 1) return false; // valid data only after fix - // grab time & date + // grab date & time if ((tok = strsep(&s,",")) == NULL) return false; strncpy(buf, tok, 4); buf[4] = '\0'; // YYYYmmddhhmmss.ccc GPSdata.year = atoi(buf);