Hi there. In the DFRobot SIM808 library it is possible to extract some gps information, but not all. The worst part is that nearly every time the lat and long are unprecise, which messes up the code. I was searching through the library, and it appears that it reads an NMEA string, like what happens with a NEO-6M module, and yes, I was able to get into the serial the whole NMEA string. So, is there a way to modify the library so that it recollects all the NMEA string and store it in a char, and then process it with tinyGPS++?
Here is the main library file: DFRobot_SIM808/DFRobot_SIM808.cpp at master · DFRobot/DFRobot_SIM808 · GitHub
Any help I would appreciate it very much!
Thanks
To extract NMEA messages from Serial the TinyGPS library is widely used. Isn't it compatible with your module?
Not guaranteed but it looks like you'll need to modify the getGPS() function
try adding a method
const char* DFRobot_SIM808::getGPSRawBuffer()
{
if(!getGPRMC()) // accumulate NMEA sentence in receivedStack buffer, returns true when the end marker is received
return nullptr; // message not complete yet
return receivedStack; // return the message
}
in your code, **don'**t call getGPS or the library will get confused
if (sim808.getGPS()) {
...
}
but do
const char * nmeaSentence = sim808.getGPSRawBuffer();
if (nmeaSentence != nullptr) {
Serial.print("GPS SAID : ");
Serial.println(nmeaSentence);
}
It works, but for some reason after some time it just stop printing the string. Why does this happens?
There is likely a problem with the code you forgot to post.
I've not read the library so may be there are specific thing to do to keep getting the GPS info
Which code should I post?
Can you take a look please? I've already done it but I dont understand that much about it
Please post the code that shows this behavior (all of it, using code tags):
Here is everything I modified://ESP32 code:/*! * @file SIM808_GetGPS.ino * @brief Get GPS data * @de - Pastebin.com
Please post the code in line, using code tags. Most forum members won't go off site to look.
//ESP32 code:
/*!
* @file SIM808_GetGPS.ino
* @brief Get GPS data
* @details 1. This example is used to test SIM808 GPS/GPRS/GSM Shield's reading GPS data.
* @n 2. Open the SIM808_GetGPS example or copy these code to your project
* @n 3. Download and dial the function switch to Arduino
* @n 4. open serial helper
* @n 4. Place it outside, waiting for a few minutes and then it will send GPS data to serial
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [Jason](jason.ling@dfrobot.com)
* @maintainer [qsjhyy](yihuan.huang@dfrobot.com)
* @version V1.0
* @date 2022-02-08
* @url https://github.com/DFRobot/DFRobot_SIM808
*/
#include <DFRobot_SIM808.h>
#include <SoftwareSerial.h>
/**
* Besides push-in connection with expansion board, it can also be connected by jump wires
* Set DIP switch to 3-Arduino, open the following macro
* Connect the main controller to the module with Dupont wires:
* Arduino | module
* PIN_TX | TX1
* PIN_RX | RX1
* Power the module, which is successful when the power indicator on the module is ON
*/
// #define CONNECT_BY_JUMPER 1
char * nmeaSentence;
#if CONNECT_BY_JUMPER
#define PIN_TX 10
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX, PIN_RX);
DFRobot_SIM808 sim808(&mySerial);
/**
* Use Leonardo for push-in connection
* Set DIP switch to 3-Arduino, and use the Serial1 of Leonardo for communication
*/
#elif defined(ARDUINO_AVR_LEONARDO)
DFRobot_SIM808 sim808(&Serial1);
/**
* Use UNO & MEGA2560 for push-in connection
* Set DIP switch to 3-Arduino, and use the Serial of UNO and MEGA2560 for communication
*/
#else
DFRobot_SIM808 sim808(&Serial);
#endif
void setup() {
pinMode(5,OUTPUT);
#if CONNECT_BY_JUMPER
mySerial.begin(9600);
#elif defined(ARDUINO_AVR_LEONARDO)
Serial1.begin(9600);
#endif
Serial.begin(9600,SERIAL_8N1,17,16);
//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");
}
void loop() {
const char * nmeaSentence = sim808.getGPSRawBuffer();
if (nmeaSentence != nullptr) {
Serial.print("GPS SAID : ");
Serial.println(nmeaSentence);
}
}
// Library updated:
/*!
* @file DFRobot_SIM808.cpp
* @brief Define infrastructure of DFRobot_SIM808 class
* @details A library for DFRobot's SIM808 GPS/DFRobot_SIM808/GSM Shield
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [Jason](jason.ling@dfrobot.com)
* @maintainer [qsjhyy](yihuan.huang@dfrobot.com)
* @version V1.0
* @date 2022-02-07
* @url https://github.com/DFRobot/DFRobot_SIM808
*/
#include <stdio.h>
#include "DFRobot_SIM808.h"
extern Stream *serialSIM808;
DFRobot_SIM808* DFRobot_SIM808::inst;
char receivedStackIndex = 0;
char receivedStack[130];
const char *des = "$GPRMC";
//char *receivedStack="$GPRMC,165445.000,A,3110.8635,N,12133.4627,E,0.58,70.26,220916,,,A*57";
DFRobot_SIM808::DFRobot_SIM808(HardwareSerial *mySerial)
{
inst = this;
serialFlag = 1;
hgprsSerial = mySerial;
sim808_init(mySerial, 1);
}
#if !defined(ESP32)
DFRobot_SIM808::DFRobot_SIM808(SoftwareSerial *mySerial)
{
inst = this;
serialFlag = 0;
gprsSerial = mySerial;
sim808_init(mySerial, 0);
}
#endif
bool DFRobot_SIM808::init(void)
{
if(!sim808_check_with_cmd("AT\r\n","OK\r\n",CMD)){
// Serial.println("-------");
return false;
}
// 1 : OK
if(!sim808_check_with_cmd("AT+CFUN=1\r\n","OK\r\n",CMD)){
return false;
}
if(!checkSIMStatus()) {
return false;
}
return true;
}
bool DFRobot_SIM808::checkPowerUp(void)
{
return sim808_check_with_cmd("AT\r\n","OK\r\n",CMD);
}
void DFRobot_SIM808::powerUpDown(uint8_t pin)
{
// power on pulse for SIM900 Shield
digitalWrite(pin,LOW);
delay(1000);
digitalWrite(pin,HIGH);
delay(2000);
digitalWrite(pin,LOW);
delay(3000);
}
void DFRobot_SIM808::powerReset(uint8_t pin)
{
// reset for SIM800L board.
// RST pin has to be OUTPUT, HIGH
digitalWrite(pin,LOW);
delay(1000);
digitalWrite(pin,HIGH);
delay(3000);
}
bool DFRobot_SIM808::checkSIMStatus(void)
{
char gprsBuffer[32];
int count = 0;
sim808_clean_buffer(gprsBuffer,32);
while(count < 3) {
sim808_send_cmd("AT+CPIN?\r\n");
sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
break;
}
count++;
delay(300);
}
if(count == 3) {
return false;
}
return true;
}
bool DFRobot_SIM808::sendSMS(char *number, char *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:
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=\"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
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("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);
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:
AT+CMGR=2
+CMGR: "REC READ","XXXXXXXXXXX","","14/10/09,17:30:17+08"
SMS text here
So we need (more or lees), 80 chars plus expected message length in buffer. CAUTION FREE MEMORY
*/
int i = 0;
char gprsBuffer[80 + length];
//char cmd[16];
char num[4];
char *p,*p2,*s;
sim808_check_with_cmd("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=");
itoa(messageIndex, num, 10);
sim808_send_cmd(num);
sim808_send_cmd("\r\n");
sim808_clean_buffer(gprsBuffer,sizeof(gprsBuffer));
sim808_read_buffer(gprsBuffer,sizeof(gprsBuffer));
if(NULL != ( s = strstr(gprsBuffer,"+CMGR:"))){
// Extract phone number string
p = strstr(s,",");
p2 = p + 2; //We are in the first phone number character
p = strstr((char *)(p2), "\"");
if (NULL != p) {
i = 0;
while (p2 < p) {
phone[i++] = *(p2++);
}
phone[i] = '\0';
}
// Extract date time string
p = strstr((char *)(p2),",");
p2 = p + 1;
p = strstr((char *)(p2), ",");
p2 = p + 2; //We are in the first date time character
p = strstr((char *)(p2), "\"");
if (NULL != p) {
i = 0;
while (p2 < p) {
datetime[i++] = *(p2++);
}
datetime[i] = '\0';
}
if(NULL != ( s = strstr(s,"\r\n"))){
i = 0;
p = s + 2;
while((*p != '\r')&&(i < length-1)) {
message[i++] = *(p++);
}
message[i] = '\0';
}
return true;
}
return false;
}
bool DFRobot_SIM808::readSMS(int messageIndex, char *message,int length)
{
int i = 0;
char gprsBuffer[100];
//char cmd[16];
char num[4];
char *p,*s;
sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD);
delay(1000);
sim808_send_cmd("AT+CMGR=");
itoa(messageIndex, num, 10);
sim808_send_cmd(num);
sim808_send_cmd("\r\n");
// sprintf(cmd,"AT+CMGR=%d\r\n",messageIndex);
// sim808_send_cmd(cmd);
sim808_clean_buffer(gprsBuffer,sizeof(gprsBuffer));
sim808_read_buffer(gprsBuffer,sizeof(gprsBuffer),DEFAULT_TIMEOUT);
if(NULL != ( s = strstr(gprsBuffer,"+CMGR:"))){
if(NULL != ( s = strstr(s,"\r\n"))){
p = s + 2;
while((*p != '\r')&&(i < length-1)) {
message[i++] = *(p++);
}
message[i] = '\0';
return true;
}
}
return false;
}
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=");
itoa(index, num, 10);
sim808_send_cmd(num);
//snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
//sim808_send_cmd(cmd);
//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);
}
bool DFRobot_SIM808::callUp(char *number)
{
//char cmd[24];
if(!sim808_check_with_cmd("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(number);
sim808_send_cmd(";\r\n");
return true;
}
void DFRobot_SIM808::answer(void)
{
sim808_send_cmd("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);
}
bool DFRobot_SIM808::disableCLIPring(void)
{
return sim808_check_with_cmd("AT+CLIP=0\r\n","OK\r\n",CMD);
}
bool DFRobot_SIM808::getSubscriberNumber(char *number)
{
//AT+CNUM --> 7 + CR = 8
//+CNUM: "","+628157933874",145,7,4 --> CRLF + 45 + CRLF = 49
// -->
//OK --> CRLF + 2 + CRLF = 6
byte i = 0;
char gprsBuffer[65];
char *p,*s;
sim808_flush_serial();
sim808_send_cmd("AT+CNUM\r\n");
sim808_clean_buffer(gprsBuffer,65);
sim808_read_buffer(gprsBuffer,65,DEFAULT_TIMEOUT);
//Serial.print(gprsBuffer);
if(NULL != ( s = strstr(gprsBuffer,"+CNUM:"))) {
s = strstr((char *)(s),",");
s = s + 2; //We are in the first phone number character
p = strstr((char *)(s),"\""); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
number[i++] = *(s++);
}
number[i] = '\0';
}
return true;
}
return false;
}
bool DFRobot_SIM808::isCallActive(char *number)
{
char gprsBuffer[46]; //46 is enough to see +CPAS: and CLCC:
char *p, *s;
int i = 0;
sim808_send_cmd("AT+CPAS\r\n");
/*Result code:
0: ready
2: unknown
3: ringing
4: call in progress
AT+CPAS --> 7 + 2 = 9 chars
--> 2 char
+CPAS: 3 --> 8 + 2 = 10 chars
--> 2 char
OK --> 2 + 2 = 4 chars
AT+CPAS
+CPAS: 0
OK
*/
sim808_clean_buffer(gprsBuffer,29);
sim808_read_buffer(gprsBuffer,27);
//We are going to flush serial data until OK is recieved
sim808_wait_for_resp("OK\r\n", CMD);
//Serial.print("Buffer isCallActive 1: ");Serial.println(gprsBuffer);
if(NULL != ( s = strstr(gprsBuffer,"+CPAS:"))) {
s = s + 7;
if (*s != '0') {
//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");
/*
AT+CLCC --> 9
+CLCC: 1,1,4,0,0,"656783741",161,""
OK
Without ringing:
AT+CLCC
OK
*/
sim808_clean_buffer(gprsBuffer,46);
sim808_read_buffer(gprsBuffer,45);
//Serial.print("Buffer isCallActive 2: ");Serial.println(gprsBuffer);
if(NULL != ( s = strstr(gprsBuffer,"+CLCC:"))) {
//There is at least one CALL ACTIVE, get number
s = strstr((char *)(s),"\"");
s = s + 1; //We are in the first phone number character
p = strstr((char *)(s),"\""); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
number[i++] = *(s++);
}
number[i] = '\0';
}
//I need to read more buffer
//We are going to flush serial data until OK is recieved
return sim808_wait_for_resp("OK\r\n", CMD);
}
}
}
}
return false;
}
bool DFRobot_SIM808::getDateTime(char *buffer)
{
//If it doesn't work may be for two reasons:
// 1. Your carrier doesn't give that information
// 2. You have to configurate the SIM808 IC.
// - First with SIM808_Serial_Debug example try this AT command: AT+CLTS?
// - If response is 0, then it is disabled.
// - Enable it by: AT+CLTS=1
// - Now you have to save this config to EEPROM memory of SIM808 IC by: AT&W
// - Now, you have to power down and power up again the SIM808
// - Try now again: AT+CCLK?
// - It should work
//AT+CCLK? --> 8 + CR = 9
//+CCLK: "14/11/13,21:14:41+04" --> CRLF + 29+ CRLF = 33
//
//OK --> CRLF + 2 + CRLF = 6
byte i = 0;
char gprsBuffer[50];
char *p,*s;
sim808_flush_serial();
sim808_send_cmd("AT+CCLK?\r");
sim808_clean_buffer(gprsBuffer,50);
sim808_read_buffer(gprsBuffer,50,DEFAULT_TIMEOUT);
if(NULL != ( s = strstr(gprsBuffer,"+CCLK:"))) {
s = strstr((char *)(s),"\"");
s = s + 1; //We are in the first phone number character
p = strstr((char *)(s),"\""); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
buffer[i++] = *(s++);
}
buffer[i] = '\0';
}
return true;
}
return false;
}
bool DFRobot_SIM808::getSignalStrength(int *buffer)
{
//AT+CSQ --> 6 + CR = 10
//+CSQ: <rssi>,<ber> --> CRLF + 5 + CRLF = 9
//OK --> CRLF + 2 + CRLF = 6
byte i = 0;
char gprsBuffer[26];
char *p, *s;
char buffers[4];
sim808_flush_serial();
sim808_send_cmd("AT+CSQ\r");
sim808_clean_buffer(gprsBuffer, 26);
sim808_read_buffer(gprsBuffer, 26, DEFAULT_TIMEOUT);
if (NULL != (s = strstr(gprsBuffer, "+CSQ:"))) {
s = strstr((char *)(s), " ");
s = s + 1; //We are in the first phone number character
p = strstr((char *)(s), ","); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
buffers[i++] = *(s++);
}
buffers[i] = '\0';
}
*buffer = atoi(buffers);
return true;
}
return false;
}
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
const char* DFRobot_SIM808::getGPSRawBuffer()
{
if(!getGPRMC()) //没有得到$GPRMC字符串开头的GPS信息
return nullptr; // accumulate NMEA sentence in receivedStack buffer, returns true when the end marker is received
return receivedStack; // return the message
}
bool DFRobot_SIM808::sendUSSDSynchronous(char *ussdCommand, char *resultcode, char *response)
{
//AT+CUSD=1,"{command}"
//OK
//
//+CUSD:1,"{response}",{int}
byte i = 0;
char gprsBuffer[200];
char *p,*s;
sim808_clean_buffer(response, sizeof(response));
sim808_flush_serial();
sim808_send_cmd("AT+CUSD=1,\"");
sim808_send_cmd(ussdCommand);
sim808_send_cmd("\"\r");
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,"\"");
s = s + 1; //We are in the first phone number character
p = strstr(s,"\""); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
response[i++] = *(s++);
}
response[i] = '\0';
}
return true;
}
return false;
}
bool DFRobot_SIM808::cancelUSSDSession(void)
{
return sim808_check_with_cmd("AT+CUSD=2\r\n","OK\r\n",CMD);
}
//Here is where we ask for APN configuration, with F() so we can save MEMORY
bool DFRobot_SIM808::join(const __FlashStringHelper *apn, const __FlashStringHelper *userName, const __FlashStringHelper *passWord)
{
byte i;
char *p, *s;
char ipAddr[32];
//Select multiple connection
//sim808_check_with_cmd("AT+CIPMUX=1\r\n","OK",DEFAULT_TIMEOUT,CMD);
//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=\"");
if (apn) {
sim808_send_cmd(apn);
}
sim808_send_cmd("\",\"");
if (userName) {
sim808_send_cmd(userName);
}
sim808_send_cmd("\",\"");
if (passWord) {
sim808_send_cmd(passWord);
}
sim808_check_with_cmd("\"\r\n", "OK\r\n", CMD);
//Brings up wireless connection
sim808_check_with_cmd("AT+CIICR\r\n","OK\r\n", CMD);
//Get local IP address
sim808_send_cmd("AT+CIFSR\r\n");
sim808_clean_buffer(ipAddr,32);
sim808_read_buffer(ipAddr,32);
//Response:
//AT+CIFSR\r\n --> 8 + 2
//\r\n --> 0 + 2
//10.160.57.120\r\n --> 15 + 2 (max) : TOTAL: 29
//Response error:
//AT+CIFSR\r\n
//\r\n
//ERROR\r\n
if (NULL != strstr(ipAddr,"ERROR")) {
return false;
}
s = ipAddr + 11;
p = strstr((char *)(s),"\r\n"); //p is last character \r\n
if (NULL != s) {
i = 0;
while (s < p) {
ip_string[i++] = *(s++);
}
ip_string[i] = '\0';
}
_ip = str_to_ip(ip_string);
if(_ip != 0) {
return true;
}
return false;
}
void DFRobot_SIM808::disconnect()
{
sim808_send_cmd("AT+CIPSHUT\r\n");
}
bool DFRobot_SIM808::connect(Protocol ptl,const char * host, int port, int timeout, int chartimeout)
{
//char cmd[64];
char num[4];
char resp[96];
//sim808_clean_buffer(cmd,64);
if(ptl == TCP) {
sim808_send_cmd("AT+CIPSTART=\"TCP\",\"");
sim808_send_cmd(host);
sim808_send_cmd("\",");
itoa(port, num, 10);
sim808_send_cmd(num);
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(host);
sim808_send_cmd("\",");
itoa(port, num, 10);
sim808_send_cmd(num);
sim808_send_cmd("\r\n");
// sprintf(cmd, "AT+CIPSTART=\"UDP\",\"%s\",%d\r\n",host, port);
} else {
return false;
}
//sim808_send_cmd(cmd);
sim808_read_buffer(resp, 96, timeout, chartimeout);
//Serial.print("Connect resp: "); Serial.println(resp);
if(NULL != strstr(resp,"CONNECT")) { //ALREADY CONNECT or CONNECT OK
return true;
}
return false;
}
//Overload with F() macro to SAVE memory
bool DFRobot_SIM808::connect(Protocol ptl,const __FlashStringHelper *host, const __FlashStringHelper *port, int timeout, int chartimeout)
{
//char cmd[64];
char resp[96];
//sim808_clean_buffer(cmd,64);
if(ptl == TCP) {
sim808_send_cmd(F("AT+CIPSTART=\"TCP\",\"")); //%s\",%d\r\n",host, port);
} else if(ptl == UDP) {
sim808_send_cmd(F("AT+CIPSTART=\"UDP\",\"")); //%s\",%d\r\n",host, port);
} else {
return false;
}
sim808_send_cmd(host);
sim808_send_cmd(F("\","));
sim808_send_cmd(port);
sim808_send_cmd(F("\r\n"));
// Serial.print("Connect: "); Serial.println(cmd);
sim808_read_buffer(resp, 96, timeout, chartimeout);
// Serial.print("Connect resp: "); Serial.println(resp);
if(NULL != strstr(resp,"CONNECT")) { //ALREADY CONNECT or CONNECT OK
return true;
}
return false;
}
bool DFRobot_SIM808::is_connected(void)
{
char resp[96];
sim808_send_cmd("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"
return true;
} else {
//+CIPSTATUS: 1,0,"TCP","216.52.233.120","80","CLOSED"
//+CIPSTATUS: 0,,"","","","INITIAL"
return false;
}
}
bool DFRobot_SIM808::close()
{
// if not connected, return
if (!is_connected()) {
return true;
}
return sim808_check_with_cmd("AT+CIPCLOSE\r\n", "CLOSE OK\r\n", CMD);
}
int DFRobot_SIM808::readable(void)
{
return sim808_check_readable();
}
int DFRobot_SIM808::wait_readable(int wait_time)
{
return sim808_wait_readable(wait_time);
}
int DFRobot_SIM808::wait_writeable(int req_size)
{
return req_size+1;
}
int DFRobot_SIM808::send(const char * str, int len)
{
//char cmd[32];
char num[4];
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=");
itoa(len, num, 10);
sim808_send_cmd(num);
if(!sim808_check_with_cmd("\r\n",">",CMD)) {
//if(!sim808_check_with_cmd(cmd,">",CMD)) {
return 0;
}
/*if(0 != sim808_check_with_cmd(str,"SEND OK\r\n", DEFAULT_TIMEOUT * 10 ,DATA)) {
return 0;
}*/
delay(500);
sim808_send_cmd(str);
delay(500);
sim808_send_End_Mark();
if(!sim808_wait_for_resp("SEND OK\r\n", DATA, DEFAULT_TIMEOUT * 10, DEFAULT_INTERCHAR_TIMEOUT * 10)) {
return 0;
}
}
return len;
}
int DFRobot_SIM808::recv(char* buf, int len)
{
sim808_clean_buffer(buf,len);
sim808_read_buffer(buf,len); //Ya he llamado a la funcion con la longitud del buffer - 1 y luego le estoy a diendo el 0
return strlen(buf);
}
void DFRobot_SIM808::listen(void)
{
if(serialFlag)
; //hgprsSerial->listen();
else{
#if !defined(ESP32)
gprsSerial->listen();
#endif
}
}
bool DFRobot_SIM808::isListening(void)
{
return false;
// if(serialFlag)
// return hgprsSerial.isListening();
// else
// return gprsSerial.isListening();
}
uint32_t DFRobot_SIM808::str_to_ip(const char* str)
{
uint32_t ip = 0;
char* p = (char*)str;
for(int i = 0; i < 4; i++) {
ip |= atoi(p);
p = strchr(p, '.');
if (p == NULL) {
break;
}
ip <<= 8;
p++;
}
return ip;
}
char* DFRobot_SIM808::getIPAddress()
{
//I have already a buffer with ip_string: snprintf(ip_string, sizeof(ip_string), "%d.%d.%d.%d", (_ip>>24)&0xff,(_ip>>16)&0xff,(_ip>>8)&0xff,_ip&0xff);
return ip_string;
}
unsigned long DFRobot_SIM808::getIPnumber()
{
return _ip;
}
/* NOT USED bool DFRobot_SIM808::gethostbyname(const char* host, uint32_t* ip)
{
uint32_t addr = str_to_ip(host);
char buf[17];
//snprintf(buf, sizeof(buf), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff);
if (strcmp(buf, host) == 0) {
*ip = addr;
return true;
}
return false;
}
*/
bool DFRobot_SIM808::getLocation(const __FlashStringHelper *apn, float *longitude, float *latitude)
{
int i = 0;
char gprsBuffer[80];
char buffer[20];
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);
//sen AT+SAPBR=3,1,"APN","DFRobot_SIM808_APN"
sim808_send_cmd("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);
//AT+CIPGSMLOC=1,1
sim808_flush_serial();
sim808_send_cmd("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);
if(NULL != ( s = strstr(gprsBuffer,"+CIPGSMLOC:")))
{
s = strstr((char *)s, ",");
s = s+1;
//Serial.println(*s);
i=0;
while(*(++s) != ',')
buffer[i++]=*s;
buffer[i] = 0;
*longitude = atof(buffer);
i=0;
while(*(++s) != ',')
buffer[i++]=*s;
buffer[i] = 0;
*latitude = atof(buffer);
return true;
}
return false;
}
bool DFRobot_SIM808::attachGPS()
{
if(!sim808_check_with_cmd("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)) {
return false;
}
return true;
}
bool DFRobot_SIM808::detachGPS()
{
if(!sim808_check_with_cmd("AT+CGNSPWR=0\r\n", "OK\r\n", CMD)) {
return false;
}
return true;
}
bool DFRobot_SIM808::getGPRMC()
{
char c;
static bool endflag = false;
static char count;
while(serialSIM808->available())
{ GPSdata.todo = serialSIM808->read();
c = GPSdata.todo;
if(endflag)
{
if(count--)
{
receivedStack[receivedStackIndex++] = c;
}
else{
endflag = false;
receivedStack[receivedStackIndex] = '\0';
return true;
}
}
else
{
switch(c)
{
case '$':
receivedStackIndex = 0;
receivedStack[receivedStackIndex++] = c;
break;
case '*':
endflag = true;
count = 2;
receivedStack[receivedStackIndex++] = c;
break;
default:
if(receivedStackIndex < 120)
receivedStack[receivedStackIndex++] = c;
break;
}
return false;
}
return false;
}
return false;
}
bool DFRobot_SIM808::parseGPRMC(char *gpsbuffer)
{
if(strstr(gpsbuffer,des) == NULL)
{
receivedStackIndex = 0;
return false;
}
else
{
if(gpsbuffer[18] == 'A')
return true;
else
{
//Serial.print("NO :");
//Serial.println(gpsbuffer[18]);
return false;
}
}
}
// Parse a (potentially negative) number with up to 2 decimal digits -xxxx.yy
int32_t DFRobot_SIM808::parseDecimal(const char *term)
{
bool negative = *term == '-';
if (negative) ++term;
int32_t ret = 100 * (int32_t)atol(term);
while (isdigit(*term)) ++term;
if (*term == '.' && isdigit(term[1]))
{
ret += 10 * (term[1] - '0');
if (isdigit(term[2]))
ret += term[2] - '0';
}
return negative ? -ret : ret;
}
void DFRobot_SIM808::getTime(uint32_t time){
GPSdata.hour = time / 1000000;
GPSdata.minute = (time / 10000) % 100;
GPSdata.second = (time / 100) % 100;
GPSdata.centisecond = time % 100;
}
void DFRobot_SIM808::getDate(uint32_t date){
uint16_t year = date % 100;
GPSdata. year = year + 2000;
GPSdata.month = (date / 100) % 100;
GPSdata.day = date / 10000;
}
bool DFRobot_SIM808::getGPS()
{
if(!getGPRMC()) //没有得到$GPRMC字符串开头的GPS信息
return false;
if(!parseGPRMC(receivedStack)) //不是$GPRMC字符串开头的GPS信息
return false;
// skip mode
char *tok = strtok(receivedStack, ","); //起始引导符
if (! tok) return false;
// grab time //<1> UTC时间,格式为hhmmss.sss;
// tok = strtok(NULL, ",");
char *time = strtok(NULL, ",");
if (! time) return false;
uint32_t newTime = (uint32_t)parseDecimal(time);
getTime(newTime);
// skip fix
tok = strtok(NULL, ","); //<2> 定位状态,A=有效定位,V=无效定位
if (! tok) return false;
// grab the latitude
char *latp = strtok(NULL, ","); //<3> 纬度ddmm.mmmm(度分)格式(前面的0也将被传输)
if (! latp) return false;
// grab latitude direction // <4> 纬度半球N(北半球)或S(南半球)
char *latdir = strtok(NULL, ",");
if (! latdir) return false;
// grab longitude //<5> 经度dddmm.mmmm(度分)格式(前面的0也将被传输)
char *longp = strtok(NULL, ",");
if (! longp) return false;
// grab longitude direction //<6> 经度半球E(东经)或W(西经)
char *longdir = strtok(NULL, ",");
if (! longdir) return false;
float latitude = atof(latp);
float longitude = atof(longp);
GPSdata.lat = (int)(latitude / 100) + (latitude - (int)(latitude / 100) * 100) / 60;
// convert longitude from minutes to decimal
GPSdata.lon = (int)(longitude / 100) + (longitude - (int)(longitude / 100) * 100) / 60;
// only grab speed if needed //<7> 地面速率(000.0~999.9节,前面的0也将被传输)
// if (speed_kph != NULL) {
// grab the speed in knots
char *speedp = strtok(NULL, ",");
if (! speedp) return false;
// convert to kph
//*speed_kph = atof(speedp) * 1.852;
GPSdata.speed_kph= atof(speedp) * 1.852;
// }
// only grab heading if needed
// if (heading != NULL) {
// grab the speed in knots
char *coursep = strtok(NULL, ",");
if (! coursep) return false;
//*heading = atof(coursep);
GPSdata.heading = atof(coursep);
// }
// grab date
char *date = strtok(NULL, ",");
if (! date) return false;
uint32_t newDate = atol(date);
getDate(newDate);
// no need to continue
char *alti=strtok(NULL,",");
if(!alti) return false;
uint32_t altitud = atol(alti);
Serial.print("chinos mkas ");
Serial.println(altitud);
// if (altitude == NULL){
// return true;
//}
return true;
}
void DFRobot_SIM808::latitudeConverToDMS()
{
float temp;
latDMS.degrees = (int)GPSdata.lat;
temp = (GPSdata.lat - latDMS.degrees)*60;
latDMS.minutes = (int)temp;
latDMS.seconeds = (temp - latDMS.minutes)*60;
}
void DFRobot_SIM808::LongitudeConverToDMS()
{
float temp;
longDMS.degrees = (int)GPSdata.lon;
temp = (GPSdata.lon - longDMS.degrees)*60;
longDMS.minutes = (int)temp;
longDMS.seconeds = (temp - longDMS.minutes)*60;
}
// Library .h updated:
/*!
* @file DFRobot_SIM808.h
* @brief Define infrastructure of DFRobot_SIM808 class
* @details Header file for DFRobot's SIM808 GPS/DFRobot_SIM808/GSM Shield.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [Jason](jason.ling@dfrobot.com)
* @maintainer [qsjhyy](yihuan.huang@dfrobot.com)
* @version V1.0
* @date 2022-1-18
* @url https://github.com/DFRobot/DFRobot_SIM808
*/
#ifndef __DFRobot_SIM808_H__
#define __DFRobot_SIM808_H__
#include "sim808.h"
/**
* @enum enum Protocol
* @brief communication protocol
*/
enum Protocol {
CLOSED = 0,
TCP = 1,
UDP = 2,
};
class DFRobot_SIM808
{
public:
#if !defined(ESP32)
SoftwareSerial *gprsSerial;
#endif
HardwareSerial *hgprsSerial;
Stream *sgprsSerial;
/**
* @struct struct gspdata
* @brief GPS data structure
*/
struct gspdata{
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t centisecond;
float lat;
float lon;
float speed_kph;
float heading;
float altitude;
char todo;
}GPSdata;
/**
* @struct struct DMSData
* @brief DMS data structure
*/
struct DMSData{
int degrees;
int minutes;
float seconeds;
}latDMS,longDMS;
public:
/**
* @fn DFRobot_SIM808
* @brief Constructor
* @param mySerial serial ports for communication, supporting hard and soft serial ports
* @n Tx, rx, and baudRate can also be passed in this order
* @return None
*/
#if !defined(ESP32)
DFRobot_SIM808(SoftwareSerial *mySerial);
#endif
DFRobot_SIM808(HardwareSerial *mySerial);
DFRobot_SIM808(uint8_t tx, uint8_t rx, uint32_t baudRate = 9600);
/**
* @fn getInstance
* @brief get instance of DFRobot_SIM808 class
* @return instance of DFRobot_SIM808 class
*/
static DFRobot_SIM808* getInstance() { return inst; };
/**
* @fn init
* @brief initialize DFRobot_SIM808 module including SIM card check & signal strength
* @return true if connected, false otherwise
*/
bool init(void);
/**
* @fn checkPowerUp
* @brief check if DFRobot_SIM808 module is powered on or not
* @return true on success, false on error
*/
bool checkPowerUp(void);
/**
* @fn powerUpDown
* @brief power Up DFRobot_SIM808 module (JP has to be soldered)
* @param pin pin 9 connected to JP jumper so we can power up and down through software
* @return None
*/
void powerUpDown(uint8_t pin);
/**
* @fn powerReset
* @brief power reset for SIM800 board
* @param pin (preconfigurated as OUTPUT)
* @return None
*/
void powerReset(uint8_t pin);
/**
* @fn sendSMS
* @brief send text SMS
* @param number phone number which SMS will be send to
* @param data message that will be send to
* @return true on success, false on error
*/
bool sendSMS(char* number, char* data);
/**
* @fn isSMSunread
* @brief Check if there is any UNREAD SMS: this function DOESN'T change the UNREAD status of the SMS
* @return returned value
* @retval 1~20 - on success, position/index where SMS is stored, suitable for the function ReadSMS
* @retval -1 - on error
* @retval 0 - there is no SMS with specified status (UNREAD)
*/
char isSMSunread(void);
/**
* @fn readSMS
* @brief read SMS, phone and date if getting a SMS message. It changes SMS status to READ
* @param messageIndex SIM position to read
* @param message buffer used to get SMS message
* @param length length of message buffer
* @param phone buffer used to get SMS's sender phone number
* @param datetime buffer used to get SMS's send datetime
* @return true on success, false on error
*/
bool readSMS(int messageIndex, char *message, int length, char *phone, char *datetime);
/**
* @fn readSMS
* @brief read SMS if getting a SMS message
* @param buffer buffer that get from DFRobot_SIM808 module(when getting a SMS, DFRobot_SIM808 module will return a buffer array)
* @param message buffer used to get SMS message
* @param check whether to check phone number(we may only want to read SMS from specified phone number)
* @return true on success, false on error
*/
bool readSMS(int messageIndex, char *message, int length);
/**
* @fn deleteSMS
* @brief delete SMS message on SIM card
* @param index the index number which SMS message will be delete
* @return true on success, false on error
*/
bool deleteSMS(int index);
/**
* @fn callUp
* @brief call someone
* @param number the phone number which you want to call
* @return true on success, false on error
*/
bool callUp(char* number);
/**
* @fn answer
* @brief auto answer if coming a call
* @return None
*/
void answer(void);
/**
* @fn hangup
* @brief hang up if coming a call
* @return true on success, false on error
*/
bool hangup(void);
/**
* @fn disableCLIPring
* @brief Disable +CLIP notification when an incoming call is active, RING text is always shown. See isCallActive function
* @note This is done in order no to overload serial outputCheck if there is a call active and get the phone number in that case
* @return true on success, false on error
*/
bool disableCLIPring(void);
/**
* @fn getSubscriberNumber
* @brief Get Subscriber Number (your number) using AT+CNUM command, but if nothing return, then
* @n you need to command this to your SIM900. (See AT+CPBS, AT+CPBW)
* @n AT+CPBS="ON"
* @n AT+CPBW=1,"+{Your Number}",145
* @n AT+CPBS="SM"
* @param number your phone number
* @return true on success, false on error
*/
bool getSubscriberNumber(char *number);
/**
* @fn isCallActive
* @brief Check if there is a call active and get the phone number in that case
* @param number Check if there is a call active and get the phone number in that case
* @return true on success, false on error
*/
bool isCallActive(char *number);
/**
* @fn getDateTime
* @brief get DateTime from SIM900 (see AT command: AT+CLTS=1) as string
* @param buffer DateTime from SIM900
* @return true on success, false on error
* @note If it doesn't work may be for two reasons:
* @n 1. Your carrier doesn't give that information
* @n 2. You have to configurate the SIM900 IC.
* @n - First with SIM900_Serial_Debug example try this AT command: AT+CLTS?
* @n - If response is 0, then it is disabled.
* @n - Enable it by: AT+CLTS=1
* @n - Now you have to save this config to EEPROM memory of SIM900 IC by: AT&W
* @n - Now, you have to power down and power up again the SIM900
* @n - Try now again: AT+CCLK?
* @n - It should work now
*
*/
bool getDateTime(char *buffer);
/**
* @fn getSignalStrength
* @brief get Signal Strength from SIM900 (see AT command: AT+CSQ) as integer
* @param buffer Signal Strength
* @return true on success, false on error
*/
bool getSignalStrength(int *buffer);
/**
* @fn sendUSSDSynchronous
* @brief Send USSD Command Synchronously (Blocking call until unsolicited response is received)
* @param ussdCommand command UUSD, ex: *123#
* @param resultCode char Result Code, see AT+CUSD command
* @param response string response
* @return true on success, false on error
*/
bool sendUSSDSynchronous(char *ussdCommand, char *resultcode, char *response);
/**
* @fn cancelUSSDSession
* @brief Cancel USSD Session
* @return true on success cancel active session, false on error or because no active session
*/
bool cancelUSSDSession(void);
/*************************** DFRobot_SIM808 ***************************/
/**
* @fn join
* @brief Connect the DFRobot_SIM808 module to the network.
* @param apn APN(Access Point Name)
* @param userName user name
* @param passWord pass word
* @return true if connected, false otherwise
*/
bool join(const __FlashStringHelper *apn = 0, const __FlashStringHelper *userName = 0, const __FlashStringHelper *passWord = 0);
/**
* @fn disconnect
* @brief Disconnect the DFRobot_SIM808 module from the network
* @return None
*/
void disconnect(void);
/**
* @fn connect
* @brief Open a tcp/udp connection with the specified host on the specified port
* @param ptl protocol for socket, TCP/UDP can be choosen
* @param host host (can be either an ip address or a name. If a name is provided, a dns request will be established)
* @param port port
* @param timeout wait seconds till connected
* @param chartimeout wait milliseconds between characters from DFRobot_SIM808 module
* @return true if successful, false if error
*/
bool connect(Protocol ptl, const char * host, int port, int timeout = 2 * DEFAULT_TIMEOUT, int chartimeout = 2 * DEFAULT_INTERCHAR_TIMEOUT);
bool connect(Protocol ptl, const __FlashStringHelper *host, const __FlashStringHelper *port, int timeout = 2 * DEFAULT_TIMEOUT, int chartimeout = 2 * DEFAULT_INTERCHAR_TIMEOUT);
/**
* @fn is_connected
* @brief Check if a tcp link is active
* @return true if successful, false if error
*/
bool is_connected(void);
/**
* @fn close
* @brief Close a tcp connection
* @return true if successful, false if error
*/
bool close(void);
/**
* @fn readable
* @brief check if DFRobot_SIM808 module is readable or not
* @return true if readable
*/
int readable(void);
/**
* @fn wait_readable
* @brief wait a few time to check if DFRobot_SIM808 module is readable or not
* @param wait_time time of waiting
* @return Returns the length of readable data
*/
int wait_readable(int wait_time);
/**
* @fn wait_writeable
* @brief wait a few time to check if DFRobot_SIM808 module is writeable or not
* @param req_size time of waiting
* @return req_size + 1
*/
int wait_writeable(int req_size);
/**
* @fn send
* @brief send data to socket
* @param str string to be sent
* @param len string length
* @return return bytes that actually been send
*/
int send(const char * str, int len);
/**
* @fn recv
* @brief read data from socket
* @param buf buffer that will store the data read from socket
* @param len string length need to read from socket
* @return bytes that actually read
*/
int recv(char* buf, int len);
/**
* @fn listen
* @brief Enables the selected software serial port to listen
* @return None
*/
void listen(void);
/**
* @fn isListening
* @brief Tests to see if requested software serial port is actively listening.
* @return Now masking enabled, return null
*/
bool isListening(void);
/**
* @fn gethostbyname
* @brief convert the host to ip
* @param host host ip string, ex. 10.11.12.13
* @param ip long int ip address, ex. 0x11223344
* @return true if successful
*/
//NOT USED bool gethostbyname(const char* host, uint32_t* ip);
/**
* @fn getIPAddress
* @brief get IP address
* @return IP address, char*
*/
char* getIPAddress(void);
/**
* @fn getIPnumber
* @brief get IP number
* @return IP number, unsigned long
*/
unsigned long getIPnumber(void);
/**
* @fn getLocation
* @brief get Location
* @param apn APN(Access Point Name)
* @param longitude longitude
* @param latitude latitude
* @return true if successful, false if error
*/
bool getLocation(const __FlashStringHelper *apn, float *longitude, float *latitude);
/**
* @fn attachGPS
* @brief Open GPS
* @return true if successful, false if error
*/
bool attachGPS(void);
/**
* @fn detachGPS
* @brief Close GPS
* @return true if successful, false if error
*/
bool detachGPS(void);
/**
* @fn getTime
* @brief parse time
* @param time Time data to be parsed
* @return None
*/
void getTime(uint32_t time);
/**
* @fn getDate
* @brief parse date
* @param date Date data to be parsed
* @return None
*/
void getDate(uint32_t date);
/**
* @fn parseDecimal
* @brief Parse a (potentially negative) number with up to 2 decimal digits -xxxx.yy
* @param term Data to be parsed
* @return Parsed data
*/
int32_t parseDecimal(const char *term);
/**
* @fn latitudeConverToDMS
* @brief latitude Conver To DMS
* @return None
*/
void latitudeConverToDMS(void);
/**
* @fn LongitudeConverToDMS
* @brief Longitude Conver To DMS
* @return None
*/
void LongitudeConverToDMS(void);
/**
* @fn parseGPRMC
* @brief parser GPRMC, Determine whether gpsbuffer[18] is 'A'
* @param gpsbuffer GPS buffer data to be parsed
* @return true if gpsbuffer[18] is 'A'
*/
bool parseGPRMC(char *gpsbuffer);
/**
* @fn getGPRMC
* @brief Get the parsed GPRMC
* @return true if successful, false if error
*/
bool getGPRMC(void);
/**
* @fn getGPS
* @brief get GPS signal
* @return true if successful, false if error
*/
bool getGPS(void);
/**
*@fn Sacar datos GPS
*/
const char* getGPSRawBuffer(void);
private:
/**
* @fn checkSIMStatus
* @brief check SIM status
* @return true if successful, false if error
*/
bool checkSIMStatus(void);
/**
* @fn str_to_ip
* @brief string ip to uint32_t ip
* @param str IP string to be converted
* @return uint32_t ip
*/
uint32_t str_to_ip(const char* str);
private:
static DFRobot_SIM808* inst;
byte serialFlag;
uint32_t _ip;
char ip_string[16]; //XXX.YYY.ZZZ.WWW + \0
};
#endif
One possibility is that the library is overwhelmed by 10000 to 100000 or more calls per second to get a message, and cannot get much other work done.
void loop() {
const char * nmeaSentence = sim808.getGPSRawBuffer();
if (nmeaSentence != nullptr) {
Serial.print("GPS SAID : ");
Serial.println(nmeaSentence);
}
}
Let me try a delay
It doesnt change anything, still stops after some time