[SOLVED] GSM Sim800L not sending SMS messages if it contains any URL

Greetings,
I am kind of a rookie when it comes to this type of modules, but let me explain my project.

Basically I'm trying to send a google maps link to my phone number that contains the current coordinates of my system with the use of a SIM800L GSM & NEO 6M GPS modules.

But for some reason if the message I'm trying to send contains any links, I don't receive it on my phone number even though that there is no errors.

Mind you that my wirings are correct.

Here's my code:

#define BUTTON 5
int BUTTONstate = 0;
boolean button_pressed = false;

/*******************************************************************************
 * SIM800L
 ******************************************************************************/
#define rxPin 3
#define txPin 2
#define RESET_PIN 4
#define gsmindic A4
SoftwareSerial sim800(rxPin,txPin);
//------------------------------------------------------------------------

/*******************************************************************************
 * NEO 6M
 ******************************************************************************/
AltSoftSerial neogps;
TinyGPSPlus gps;

String latitude, longitude;
//------------------------------------------------------------------------

void setup() {
  Serial.begin(9600);
  sim800.begin(9600);
  neogps.begin(9600);
  delay(1000);
  
 //Don't mind the unrelated AT commands, I have other features for this project
  delay(1000);
  sim800.println("AT");
  delay(1000);
  sim800.println("AT+CMGF=1");
  delay(1000);
  sim800.println("AT+CLIP=1");
  delay(1000);
  sim800.println("AT+CNMI=1,2,0,0,0");
  delay(1000);
  sim800.println("AT+CMGD=1,4");
  delay(1000);
  sim800.println("AT+CMGDA=DEL ALL");
}


void loop() {
*******************************************************************************
 * Button to send SMS
 ******************************************************************************/
  BUTTONstate = digitalRead(BUTTON);

  if(digitalRead(BUTTON) == HIGH) {
    Serial.println("Getting Coordinates");
    getGps();
    digitalWrite(buzzer, HIGH); // Arduino will set off a buzzer when the button is pressed
    button_pressed = true;
  }

  if(button_pressed  == true) {
      digitalWrite(buzzer, LOW);
      Serial.println("Sending Messages");
      delay(1000);
      
      sendSMS1();
      delay(1000);
      sendSMS2();
      delay(1000);
//      sendSMS3() , sendSMS4()......
      
      button_pressed = false;

 } // END OF LOOP


/*****************************************************************************************
 * getGps() Function
*****************************************************************************************/
void getGps()
{
  // Can take up to 60 seconds
  boolean newData = false;
  for (unsigned long start = millis(); millis() - start < 2000;){
    while (neogps.available()){
      if (gps.encode(neogps.read())){
        newData = true;
        break;
      }
    }
  }
  
  if (newData) //If newData is true
  {
    latitude = String(gps.location.lat(), 6);
    longitude = String(gps.location.lng(), 6);
    newData = false;
  }
  else {
    latitude = "";
    longitude = "";
    delay(3000);
  }
}
//------------------------------------------------------------------------

// sendSMS1 function doesn't work if the message contains any link
void sendSMS1(){
  String tempo = "";
  tempo = readFromEEPROM(offsetPhone[0]);

  if(tempo == "" || tempo == "Empty" || tempo == "Wrong Format"){
     Serial.println("1st number is invalid");
  } // Again dont mind this, I'm using the EEPROM of the arduino to store multiple phone numbers
  
  else {
    sim800.println("AT+CMGF=1");
    delay(500);
    sim800.println("AT+CMGS=\""+tempo+"\"\r");
    delay(500);

    String text = ("http://maps.google.com/maps?q=loc:" + latitude + "," + longitude); // Google map link + coordinates
    sim800.println(text);
    sim800.write(0x1A);
  } 
}

// sendSMS2 function works and I receive the message in my inbox
void sendSMS2(){
  String tempo = "";
  tempo = readFromEEPROM(offsetPhone[0]);

  if(tempo == "" || tempo == "Empty" || tempo == "Wrong Format"){
     Serial.println("1st number is invalid");
  } 
  
  else {
    sim800.println("AT+CMGF=1");
    delay(500);
    sim800.println("AT+CMGS=\""+tempo+"\"\r");
    delay(500);

    String text = ("Sim 1 SMS Test!"); // This sends successfully to my phone number
    sim800.println(text);
    sim800.write(0x1A);
  } 
}

sendSMS1 that contains a google maps link executes without any error, it even prints "OK" in the serial but I didn't receive anything in my phone's inbox. With sendSMS2, I do receive an SMS message.

I'm sorry if this is quite confusing, I'll try my best to answer any questions and any help would be greatly appreciated.

1 Like

What exactly do you see if you print the text String on the Serial monitor ?

Not sure this gets you what you want (a constant pointer to which you add a float and a char and another float... hum...

try

String text = "http://maps.google.com/maps?q=loc:";
text += String(latitude,6);
text +=  ",";
text += String(longitude,6);

Exactly what I declare it.
So if I put "Sim 1 SMS Test!", it will output that in the serial monitor using Serial.print(). Same thing if I declare it as the google maps link.

Sadly this didn't work.
I even tried to declare some random numbers for the latitude and longitude but no, I still didn't receive anything. Even if the message is just "google.com" it will "send" it but I'll receive nothing.
But then again if the message doesn't contain any link it will send it and I'll receive it no problem.

Did you try printing the length of the string ?

I have a suspicion that there are hidden characters on the end of the string

@UKHeliBob Yes I did that, it printed out the whole String in the serial monitor.
But again the problem is when I'm trying to send an SMS.
If the String contains any URL, it will "send" it but I don't receive anything.
Even if the String only contains "http", I still don't receive it.
But if its other texts then its fine, kinda weird.

I don't remember seeing anywhere that you reported whether the length of the string or the number of characters it contains was what you expected

For instance, if the string had a Carriage Return on the end of it then would you notice it unless you printed a character immediately before an after it ?

String text = ("http://maps.google.com/maps?q=loc:12345,678990");
    sim800.println(text);
    sim800.write(0x1A);

Serial.println(text); // Is this what you're talking about?

Serial monitor prints out the whole String, but during "sending" it only prints out "http://maps.google".

as a test - not sure if it would change anything - but can you add a small delay (200ms) before sending 0x1A

String text = ("http://maps.google.com/maps?q=loc:12345,678990");
    sim800.println(text);
    delay(200);
    sim800.write(0x1A);

UPDATE:
The sim card is the problem.
For some reason the card that was in that sim800l is not sending any SMS messages if it contains ANY URL.
I changed it to a new card from a different cellular provider and it works fine now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.