BlynkClient with TinyGSM

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 .

Got the following screen. Whats wrong ??

Thanks !!

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?

How are you powering your SIM800?

Pete.

Thanks for the quick response. Appears that my SIM800 module is capable of only 9600 baud. Onc ethat was corrected everything worked like magic !

I brought in a gauge and updated it once every second and it works well. Just a few doubts :

  1. When I use the GSM network is there any limitation on the min interval for data update ?
  2. In case the Modem gets stuck , do I do a periodic Blynk.connect() check as I do when using WiFi and restart() the ESP 32 module ?

Thanks

  1. No, but trying to do more than about 5 updates per second is probably a bad idea, but it depends on your ping times.

  2. it’s difficult to say without seeing your code.

Pete.

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();
    }
  }
}

It depends on the code you’re using for your GSM setup.
I’ve asked you twice to share it, but you don’t seem to want to!

Pete,

:sweat_smile:
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 !

Thanks

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.

Pete.

I spent time to look around for the Blynk.config usage but could not locate. All examples are with Blynk.begin() only.

Anyway I have carried out the other corrections and the code is functional now.

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Your WiFi credentials.
//char ssid[] = "";
//char pass[] = "";
char ssid[] = "T";
char pass[] = "";

BlynkTimer timer;
Adafruit_BME280 bme; // I2C define

float Pressure ;
float DegC ;
float Humidity ;
int status;
const byte blueLED = 2;
byte blynkStatus ;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// This function sends data to Blynk App. At the specified interval when it 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);
}

// This function tries to restore connection if there is any momentary router drop out
void checkConnection()
{
  blynkStatus = Blynk.connected();
  if (blynkStatus ) {
    digitalWrite( blueLED, HIGH ) ;
  }
  else {
    digitalWrite( blueLED, LOW ) ;
    ESP.restart();
  }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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);

  digitalWrite(blueLED, HIGH ); 

  // Specify the intervals for two timer calls
  timer.setInterval(60000L, myTimerEvent);
  timer.setInterval(110000L, checkConnection) ;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Not sure where you’ve looked, but if you’ve studied the 50+ results here then you should know what you need to do…

https://community.blynk.cc/search?q=Blynk.config()

Pete.

Modified the connection part as below instead of Blynk.begin()

Blynk.connectWiFi(ssid, pass);
  Blynk.config(BLYNK_AUTH_TOKEN);
  blynkStatus =  Blynk.connect();
  if (!blynkStatus) {
    ESP.restart(); 
  }
  digitalWrite(blueLED, HIGH ); // Connected to Blynk. Light up !!

It connected in a snap and this is the serial read out

16:15:36.130 -> [151] Connecting to RR_DLINK_2.4_EXT
16:15:39.732 -> [3761] Connected to WiFi
16:15:39.778 -> [3761] IP: 192.168.0.136
16:15:39.824 -> [3761] 
16:15:39.824 ->     ___  __          __
16:15:39.824 ->    / _ )/ /_ _____  / /__
16:15:39.871 ->   / _  / / // / _ \/  '_/
16:15:39.917 ->  /____/_/\_, /_//_/_/\_\
16:15:39.917 ->         /___/ v1.2.0 on ESP32
16:15:39.963 -> 
16:15:39.963 ->  #StandWithUkraine    https://bit.ly/swua
16:15:40.010 -> 
16:15:40.010 -> 
16:15:40.010 -> [3884] Connecting to blynk.cloud:80
16:15:40.056 -> [4038] Ready (ping: 21ms).

Just wondering why this is not the default method in the Example Browser which is my bible !!

This is also a blocking function.
You need to manage your own WiFi connection.

Pete.

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 ?

Thanks

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

Pete.

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);
  }

  WiFi.begin(ssid, pass);
  int timeout_counter = 0;
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(200);
    timeout_counter++;
    if (timeout_counter >= CONNECTION_TIMEOUT * 5) {
      ESP.restart();
    }
  }

  Blynk.config(BLYNK_AUTH_TOKEN);
  blynkStatus =  Blynk.connect();
  if (!blynkStatus) {
    ESP.restart();
  }
  digitalWrite(blueLED, HIGH ); // Connected to Blynk. Light up !!

  // Specify the intervals for two timer calls
  timer.setInterval(60000L, myTimerEvent);
  timer.setInterval(110000L, checkConnection) ;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void loop()
{
  timer.run();
  if ( Blynk.connected()) {
    Blynk.run();
  }
  else {
    digitalWrite( blueLED, LOW ) ;
    ESP.restart();
  }

}

I have now removed the blocking code after reading some examples. Also do the check Blynk.connected() before Blynk.run().

Does it look somewhat OK now ?? ( no change in rest of code so only posting setup() and loop() )

I don’t see the point in this code…

I’d just use Blynk.connect()

And there’s no Liu t in having the time to call

or the checkConnection function.

Are you happy to keep rebooting your device if it can’t connect to WiFi and/or the Blynk server?
Don’t you want it ti run in stand-alone mode instead?

Pete.

Could not figure out that.

In this application, running in stand alone mode is of no use. The device does not store anything nor have a display .

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.

Thanks