Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sim808.isSMSunread() detecting an unread message even though there isn't an unread message #39

Open
LokYinBarneyWong opened this issue Dec 30, 2023 · 17 comments

Comments

@LokYinBarneyWong
Copy link

hello, I made some modifications to the code which was supposed to receive an SMS message and then get its GPS location and send the GPS location back to whoever sent the SMS message, basically a small GPS tracker, but when I put my SD into the sim808 module to test it, the message index is always 1 when the code proceeded into void loop() detecting an unread message, even though I already read all the messages before putting it in. Is there a way for me to fix this issue, Thank you for reading this. :slight_smile:
here is the complete code:
`#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
bool messageIndex = 0;
char MESSAGE[300];
char lat[12];
char lon[12];
char wspeed[12];

char phone[16];
char datetime[24];

#define PIN_TX 10
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
//******** Initialize sim808 module *************

if( sim808.attachGPS())
Serial.println("Open the GPS power success, please send SMS message to me!");

else 
Serial.println("Open the GPS power failure");
Serial.print("init message index: ");   //debug code
Serial.println(messageIndex);

}

void loop()
{
//*********** Detecting unread SMS ************************
messageIndex = sim808.isSMSunread();
Serial.print("SMS Index under loop: "); //degbug code
Serial.println(messageIndex);
//*********** At least one UNREAD SMS ***********
if (messageIndex > 0)
{
Serial.println("Entering SMS processing block");

  sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
  //***********In order not to full SIM Memory, is better to delete it**********
  sim808.deleteSMS(messageIndex);
  Serial.print("From number: ");
  Serial.println(phone);  
  Serial.print("Datetime: ");
  Serial.println(datetime);        
  Serial.print("Recieved Message: ");
  Serial.println(message); 

while(!sim808.getGPS())
{
  
}


  Serial.print(sim808.GPSdata.year);
  Serial.print("/");
  Serial.print(sim808.GPSdata.month);
  Serial.print("/");
  Serial.print(sim808.GPSdata.day);
  Serial.print(" ");
  Serial.print(sim808.GPSdata.hour);
  Serial.print(":");
  Serial.print(sim808.GPSdata.minute);
  Serial.print(":");
  Serial.print(sim808.GPSdata.second);
  Serial.print(":");
  Serial.println(sim808.GPSdata.centisecond);
  Serial.print("latitude :");
  Serial.println(sim808.GPSdata.lat);
  Serial.print("longitude :");
  Serial.println(sim808.GPSdata.lon);
  Serial.print("speed_kph :");
  Serial.println(sim808.GPSdata.speed_kph);
  Serial.print("heading :");
  Serial.println(sim808.GPSdata.heading);
  Serial.println();

  float la = sim808.GPSdata.lat;
  float lo = sim808.GPSdata.lon;
  float ws = sim808.GPSdata.speed_kph;

  dtostrf(la, 6, 2, lat); //put float value of la into char array of lat. 6 = number of digits before decimal sign. 2 = number of digits after the decimal sign.
  dtostrf(lo, 6, 2, lon); //put float value of lo into char array of lon
  dtostrf(ws, 6, 2, wspeed);  //put float value of ws into char array of wspeed

  sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working. Mewan Indula Pathirage. Try With This Link.\nhttp://www.latlong.net/Show-Latitude-Longitude.html\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, lat, lon);
  

   Serial.println("Sim808 init success");
   Serial.println("Start to send message ...");

   Serial.println(MESSAGE);
   Serial.println(phone);

   sim808.sendSMS(phone,MESSAGE);

  //************* Turn off the GPS power ************
  sim808.detachGPS();

}
else
{
Serial.println("No unread SMS");
}

}`

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 2, 2024

image
You do not seem to have initialized the module, you can try again and provide more information.

@LokYinBarneyWong
Copy link
Author

LokYinBarneyWong commented Jan 5, 2024

Thank you for your reply,
oh yea, you are right, but now it's showing 'sim808 init error' is there any way to fix that?
I believe I already have a 9V power supply to the sim808 module since the light in the module is turned on and blinking, I can provide a photo if that is needed.
Thanks.
this is what my code looks like right now. (I'm sorry, I have no clue why the code is being like this)
`
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
bool messageIndex = 0;
char MESSAGE[300];
char lat[12];
char lon[12];
char wspeed[12];

char phone[16];
char datetime[24];

#define PIN_TX 10
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
//******** Initialize sim808 module *************
while(!sim808.init()){
delay(1000);
Serial.println("Sim808 init error.");
}

// Turn on the power
if( sim808.attachGPS())
Serial.println("Open the GPS power success, please send SMS message to me!");

else 
Serial.println("Open the GPS power failure");
Serial.print("init message index: ");   //debug code
Serial.println(messageIndex);

}

void loop()
{
//*********** Detecting unread SMS ************************
messageIndex = sim808.isSMSunread();
Serial.print("SMS Index under loop: "); //degbug code
Serial.println(messageIndex);
//*********** At least one UNREAD SMS ***********
if (messageIndex > 0)
{
Serial.println("Entering SMS processing block");

  sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
  //***********In order not to full SIM Memory, is better to delete it**********
  sim808.deleteSMS(messageIndex);
  Serial.print("From number: ");
  Serial.println(phone);  
  Serial.print("Datetime: ");
  Serial.println(datetime);        
  Serial.print("Recieved Message: ");
  Serial.println(message); 

while(!sim808.getGPS())
{
  
}


  Serial.print(sim808.GPSdata.year);
  Serial.print("/");
  Serial.print(sim808.GPSdata.month);
  Serial.print("/");
  Serial.print(sim808.GPSdata.day);
  Serial.print(" ");
  Serial.print(sim808.GPSdata.hour);
  Serial.print(":");
  Serial.print(sim808.GPSdata.minute);
  Serial.print(":");
  Serial.print(sim808.GPSdata.second);
  Serial.print(":");
  Serial.println(sim808.GPSdata.centisecond);
  Serial.print("latitude :");
  Serial.println(sim808.GPSdata.lat);
  Serial.print("longitude :");
  Serial.println(sim808.GPSdata.lon);
  Serial.print("speed_kph :");
  Serial.println(sim808.GPSdata.speed_kph);
  Serial.print("heading :");
  Serial.println(sim808.GPSdata.heading);
  Serial.println();

  float la = sim808.GPSdata.lat;
  float lo = sim808.GPSdata.lon;
  float ws = sim808.GPSdata.speed_kph;

  dtostrf(la, 6, 2, lat); //put float value of la into char array of lat. 6 = number of digits before decimal sign. 2 = number of digits after the decimal sign.
  dtostrf(lo, 6, 2, lon); //put float value of lo into char array of lon
  dtostrf(ws, 6, 2, wspeed);  //put float value of ws into char array of wspeed

  sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working. Mewan Indula Pathirage. Try With This Link.\nhttp://www.latlong.net/Show-Latitude-Longitude.html\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, lat, lon);
  

   Serial.println("Sim808 init success");
   Serial.println("Start to send message ...");

   Serial.println(MESSAGE);
   Serial.println(phone);

   sim808.sendSMS(phone,MESSAGE);

  //************* Turn off the GPS power ************
  sim808.detachGPS();

}
else
{
Serial.println("No unread SMS");
}

}
`

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 8, 2024

I apologize, I didn't write or test this library myself, and I currently don't have a template for testing. Therefore, I cannot immediately identify the issues you are facing. Can you ensure that running the library examples individually works correctly? If it does, there might be some conflicting functionality when used directly, requiring further testing. In that case, I might not have time to conduct the testing for a while.

@LokYinBarneyWong
Copy link
Author

I've imported libraries and used their examples and somehow all of them have different error codes that stop the code from running before it reaches 'sim808 init error'

@hoerup
Copy link

hoerup commented Jan 9, 2024

@LokYinBarneyWong
When I look at the 2 programs you've pasted here - a thing sticks out

I can see that you use SoftwareSerial for communication between arduino and SIM808 module? So you are not using it in hat mode but have arduino and sim808 side by side and have manually made connected pwr and ground + arduino pin10/11 to sim808 pin0/1

@LokYinBarneyWong
Copy link
Author

what is hat mode, sorry I'm new to arduino and sim808.
and how would that affect my code,since I copied it from somewhere else online and I don't understand why it wouldn't work for me, Thanks

@LokYinBarneyWong
Copy link
Author

Hi, I've found this manual where it says "The bright “STA” LED will come on, and then the “NET” LED will blink once every 800
milliseconds- until the GSM module has found the network, at which point it will blink once
every three seconds. The”PPS” LED is used to indicate the GPS is fixed or not. But the GPS
function is closed by default, so there will be nothing until we do something to the GPS function" and my SIM808 module's D3 light is blinking while the G4 light is static, is this the "NET" LED they are talking about, if so, how can I fix it?
Thanks
image

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 15, 2024

Perhaps you can take a look at this wiki. In our previous tests, all these examples were working fine.

@LokYinBarneyWong
Copy link
Author

After reading through the wiki and did some debugging with DFrobot debugging tool, i found out that only GPS commands work, and the NET LED is blinking too fast, would that be the problem, and how would I fix it?
Thanks

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 17, 2024

I'm sorry, I'm not sure about the hardware differences between the two. However, the issue is likely not due to the software library. I recommend using a serial debugging assistant along with the SIM808 manual for manual function debugging. This might make it easier to identify the problem.

@LokYinBarneyWong
Copy link
Author

which serial debugging tool would you recommend, and does it need a full-sized sim card that fits the entire sim card holder, my current set up is my sim card's metal part is touching the metal golden-ish part of the sim808 module, wondering if that would be the problem.

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 19, 2024

Any serial port communication transfer module can be used, directly use the AT instruction, verify the function of sim808 module is normal. I'm not sure about the hardware problem you're talking about.

@LokYinBarneyWong
Copy link
Author

So I input these commands from the wiki into the serial debugger and it showed this, basically error on every command I use, any clue as to why or how I can further debug, and how to fix it? (sorry for the closing and reopening the issue, I miss clicked)
`at

OK

ATD1*********2;

ERROR

ATH

OK

at+cmgf=1

ERROR

at+cmgs="1*********2"

ERROR

at+cmgr=5

ERROR`

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 26, 2024

image
I think you can verify that your sim card is valid on your phone. Because the at command seems to be normal, it just can't communicate wirelessly.

@LokYinBarneyWong
Copy link
Author

yea I can still use my sim card to call/text ppl on my phone, but what do you mean by wirelessly

@qsjhyy
Copy link
Contributor

qsjhyy commented Jan 30, 2024

Wireless communication refers to network communication. If the product was purchased on our official website, sufficient instructions and precautions for normal use are already listed on our wiki. As for other situations, I lack sufficient information to discern the reasons for operational failures.

@LokYinBarneyWong
Copy link
Author

Ok, is there any way I can give you enough information to know what is wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants