Hardware is a UNO + SIM800 Shield in Software Serial. Communication with UNO checked with AT commands.
Using the BlynkClient.ino
Created a GSM device in Blynk Console and got Auth Code.
Checked the apn for my cellular network ( on Google ) and entered .
It wold help if you posted that sketch, correctly formatted with triple backticks.
It would also help if you did the same thing when posting serial output, instead of posting screenshots, which are impossible to quote because they aren’t text.
How have you connected your SIM800 to your Arduino?
Have you established what baud rate your SIM800 is using and used the appropriate baud rate in your sketch?
Thanks for the response on data rate when using GSM. With regard to auto restart function when using WiFi , I follow the method as in the code below. It is working and last two days … but do have some short breaks in connectivity. Please advise if any such will be needed for GSM also ? ( I thought they are more stable and reliable )
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "";
//char pass[] = "";
char ssid[] = "";
char pass[] = "";
BlynkTimer timer;
Adafruit_BME280 bme; // I2C
float Pressure ;
float DegC ;
float Humidity ;
int status;
const byte blueLED = 2;
unsigned long blynkChkMillis, blynkChkInterval = 80000;
byte blynkStatus ;
// This function sends data to Blynk App. At the specified interval whenit fires.
void myTimerEvent()
{
DegC = bme.readTemperature();
Humidity = bme.readHumidity();
Pressure = bme.readPressure();
Blynk.virtualWrite(V0, DegC);
Blynk.virtualWrite(V1, Humidity);
Blynk.virtualWrite(V2, Pressure / 100);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup()
{
// Debug console
Serial.begin(9600);
status = bme.begin(0x76);
pinMode(blueLED, OUTPUT);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Setup a function to be called every second
timer.setInterval(60000L, myTimerEvent);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
if ( millis() - blynkChkMillis > blynkChkInterval ) {
blynkChkMillis = millis ();
blynkStatus = Blynk.connect();
if (blynkStatus ) {
digitalWrite( blueLED, HIGH ) ;
}
else {
digitalWrite( blueLED, LOW ) ;
ESP.restart();
}
}
}
I have just completed the basic code for GSM. Right now working on it to get three more channels and then shall move on to the Restart method - maybe I will use the same as I did in the above code !
Your ESP32 code makes no sense, because you’re using Blynk.connect() instead of Blynk.connected() and if the device fails to connect at startup you’ll never get past the Blynk.begin() command, because this is a blocking command.
Also, doing millis comparisons in your void loop is crazy when you already have BlynkTimer available and in use within your sketch.
If you wnat a foolproof system then you need to be using Blynk.config(BLYNK_AUTH_TOKEN) and Blynk.connect(optional_timeout_in_millis) and have Blynk.run() inside a Blynk.connected() logical test.
I am using two instances of the Blynk timer - posting values to Blynk cloud once every 60 sec and then checking if the connection is valid once every 110 sec. I made it so to avoid the connection checking to be not a multiple of 60 so that both don’ t fire together. Not clear on following things ,
What happens if it happens that both fire together ?
After timing out does the Timer reset or continue like the millis() value till the long variable rolls over ?
They might both be due to execute at the same time, and in that case the first one will execute, then te next time that timer.run() is encountered the next one will execute.
This means that the second timed function may execute slightly late, but that wont be a problem.
The problem is when you have say 10 timers that are executed every 500ms, and the 10 timed functions take more than 500ms to execute. Eventually you’ll have such a big backlog of timers in the queue that the device will crash.
These are interval timers, not timeout timers. They keep executing at the same interval so long as timer.run() is being executed.
That doesn’t happen, because the BlynkTimer code is written in a way where millis rollover isn’t a problem.
If you want to know more about timers you should read this…
But none of this is relevant unless you’ve figured-out your non-blocking code for your connection/re-connection routines, and you don’t execute Blynk.run() when Blynk.connected() is true
OK I now think I get your point. Now that the Blynk.Connected status is checked inside the loop, the function checkConnection() is almost redundant. Will knock it off.