BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Receiving sms with sim800L when blynk get out (internet issue)

_i have a sim800L with arduino nano and it’s work fine (in app and server) i would to use sms when internet get down.
so i don’t have any errour but it’s not working. ^-^
also i try the sms programme alone and it’s work.
_when i use the sms programme with blynk programme the sms programme don’t work.
Sorry my english is bad.
i appreciate any help.
this is my programme.


#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 60
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

char auth[] = "dHtDSxTlyQDtNmdZTabQohcle8o*****";

char apn[]  = "YourAPN";
char user[] = "";
char pass[] = "";
char server[] = "197.***.**.**";
int port = 8080;

#include <SoftwareSerial.h>

SoftwareSerial SerialAT(2, 3); // RX, TX MySim
String message;
TinyGsm modem(SerialAT);
BlynkTimer timer;
void myTimerEvent()
{
  Blynk.virtualWrite(V20, digitalRead(8));
  Blynk.virtualWrite(V0, analogRead(A0));
  Blynk.virtualWrite(V2, analogRead(A1));
  Blynk.virtualWrite(V3, analogRead(A2));
  Blynk.virtualWrite(V4, analogRead(A3));
  Blynk.virtualWrite(V5, analogRead(A4));
  Blynk.virtualWrite(V6, analogRead(A5));
  SerialAT.println("AT+CMGF=1"); // Configuring TEXT mode
  SerialAT.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  pinMode(8, OUTPUT);
  while (SerialAT.available() )
  {
    message = SerialAT.readString();
    Serial.println(message);
    if (message.indexOf("D1ON") >= 0) {
      digitalWrite(8, HIGH);
      delay(1000);
      digitalWrite(8, LOW);
      delay(250);
    }
  }
}
void setup()
{
  // Debug console
  Serial.begin(9600);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(1000);

  Serial.println("Initializing modem...");
  modem.restart();

  //modem.simUnlock("1234");



  Blynk.begin(auth, modem, apn, user, pass, server, port );
  timer.setInterval(2000L, myTimerEvent);
}
void loop()
{
  Blynk.run();
  timer.run();
}

@ibrahim please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

oki thanks

Blynk.begin is a blocking function. If it cant connect to the internet or to the Blynk server then it will stop all code execution.

Search the forum for Blynk.config and Blynk.begin with the SIM800 and you’ll see how to use these commands instead.
You will probably also have to do a Blynk.connected() test to know when to switch overs to SMS mode. I don’t think your current approach of switching to SMS mode every 2 seconds (and never switching back as far as I can see) will work with Blynk.

Pete.

i get it sir pete thank you so much and you right i should test blynk.connected() to switch to SMS mode ; :sweat_smile:
please help me with some site to read how programmed the sms sim800l with blynk

Use the search facility on this forum, but I doubt very much that you will find a ready-made so.option that echos what you are trying to do, so you’ll need to do your own testing and experimentation to get this working (if that is even possible).

Pete.

thank you so much sir pete , it works fine now :hugs: , I would never have had success without your advice :blush: .
i just have one problem , how to restart the sim800L if he get out or quit to researching to get network , i’m not skilled in coding yet .

To check network status you can use AT+CREG? command.

And, You can use command like AT+CFUN=0 and then AT+CFUN=1 to put module in flight mode and again back to normal mode. This would simulate a network reboot.

You could also try modem.restart(); or modem.init()

Pete.

hello, thanks pete and john
-my program work fine when i have internet or not (with SMS, when he get just the network without internet) , the problem as you know , I could not program the SIM800l to reboot when it completely leaves or lose the network and stop trying to get in, i don’t know how to use yours advice yet to reboot the SIM800l automatically , please give me a hande

#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 60
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>


char auth[] = "dHtDSxTlyQDtNmdZTabQohcle8o*****";


char apn[]  = "YourAPN";
char user[] = "";
char pass[] = "";
char server[] = "197.***.**.**";
int port = 8080;

#include <SoftwareSerial.h>

SoftwareSerial SerialAT(2, 3); // RX, TX MySim
//GPRSk gprs(SerialAT);
String message;
#define led
TinyGsm modem(SerialAT);
BlynkTimer timer;
void myTimerEvent()
{
  Blynk.virtualWrite(V20, digitalRead(8));
  Blynk.virtualWrite(V0, analogRead(A0));
  Blynk.virtualWrite(V1, analogRead(A1));
  Blynk.virtualWrite(V2, analogRead(A2));
  Blynk.virtualWrite(V3, analogRead(A3));
  Blynk.virtualWrite(V4, analogRead(A4));
  Blynk.virtualWrite(V5, analogRead(A5));
}
void reconnectBlynk() {
  if (!Blynk.connected()) {
    Serial.println("Lost connection");
    if (Blynk.connect()) {
      Serial.println("Reconnected");
    }
    else {
      Serial.println("Not reconnected");
    }
  }
}
void setup() {
  pinMode(8, OUTPUT);

  // Debug console
  Serial.begin(9600);
  delay(10);
  //gprs.powerOn();
  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(1000);

  Serial.println("Initializing modem...");
  modem.restart();

  //modem.simUnlock("1234");

  Blynk.begin(auth, modem, apn, user, pass, server, port );//config
  timer.setInterval(2000L, myTimerEvent);
  SerialAT.println("AT+CMGF=1"); // Configuring TEXT mode
  SerialAT.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
}
void loop()
{
  timer.run();
  if (Blynk.connected()) {
    Blynk.run();
  }
  else {
    while (SerialAT.available() )
    {
      message = SerialAT.readString();
      Serial.println(message);
      if (message.indexOf("D1ON") >= 0) {
        digitalWrite(8, HIGH);
        delay(1000);
        digitalWrite(8, LOW);
        delay(250);
      }
    }
  }
}

ibrahim

I guess you’re connecting pin 8 to the sim800l reset pin, am I right?

hello john ,sorry i’m late reply
no , D8 return pin I used to get the single from the card PCB

You can use the RST pin to reset the module, to do that just pull this pin low for 100ms to perform a hard reset.

oky i get it , so i should use AT+CREG? and AT+CFUN to know or check the network and if it’s down ! pull the pin reset low to reset the sim800l module .

Yes, this should work.

ok thank you so much i will try this solution .
john i have a new problem this code is not working in ATMEGA328 microcontroller alone , when i use the board of arduino nano work fine and when i use the microcontroller alone not works (the same microcontroller but the package difference).

Check this out

okay thanks again brother

1 Like

yes john i do this steps before i upload my program .

It would help if you explained exactly what hardware setup you are using, what Arduino IDE version you are using, what bootloader you’ve used, and exactly how far you are getting in the process of uploading and running your sketch.

Pete.