The options offline and online device with physical button / switch

Hey Im using Arduino Mega with IR tempretature sensor MLX9016, ESP8266 module with Blynk. TM1637 is used as display. But I’m looking forward to make my device can running without internet connection with trigger physical button. Does blynk library give such options if we want to make two condition which are ONLINE and OFFLINE? Does anyone use “IF” operator to make an optional for device, so the device can run with or without internet? Thanks.

#include <SimpleTimer.h>
#define BLYNK_PRINT Serial    
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "TM1637.h"
#define CLK 2//Pins for TM1637       
#define DIO 3
TM1637 tm1637(CLK,DIO);
#include <Wire.h>
#include <Adafruit_MLX90614.h>
SimpleTimer timer;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
const int relay=7;

char auth[] = "d9701cfa4c974ec89954719cedc1bcec"; //token blynk
char ssid[] = "mirwandi"; //nama hotspot
char pass[] = "geronimo"; //pass hotspot
#define EspSerial Serial3 //port serial yg dipakai modul wifi
#define ESP8266_BAUD 115200 //baudrate modul wifi
ESP8266 wifi(&EspSerial);

void setup() {
  pinMode(relay,OUTPUT);//inisiasi relay 4 channel
  tm1637.init();//inisiasi 7 segment 
  tm1637.set(BRIGHT_TYPICAL); //inisiasi 7 segment 
  mlx.begin(); //inisiasi sensor mlx90168
  EspSerial.begin(ESP8266_BAUD);//inisiasi modul wifi
  Blynk.begin(auth, wifi, ssid, pass);//inisiasi koneksi ke server blynk
  timer.setInterval(1000L, sendUptime); //interval pengiriman data

void sendUptime()
  //float suhu=((float)mlx.readObjectTempC());
  float suhu = mlx.readObjectTempC();
  //int suhu=((float)mlx.readObjectTempC());//bacaan suhu sensor MLX90168
  Blynk.virtualWrite(7,suhu); //virtual pin suhu

void loop() {
  int ambient = ((float)mlx.readAmbientTempC());//pembacaan suhu lingkugan
  int object = ((float)mlx.readObjectTempC());//pembacaan suhu objek
  int digitoneA=ambient/10; //digit pertama dibagi 10
  int digittwoA=ambient%10; //digit kedua sisa hasil pembagian
  int digitoneO=object/10; //digit pertama dibagi 10
  int digittwoO=object%10; //digit kedua sisa hasil pembagian
  tm1637.display(0,digitoneO); //menampilkan digit pertama
  tm1637.display(1,digittwoO); // menampilkan digit kedua
  tm1637.display(2,18); // menampilkan simbol derajat
  tm1637.display(3,12);  // menampilkan huruf "C"
  delay(300);; //koneksi ke server blynk; //timer interval pengiriman data ke server blynk
    digitalWrite(relay, HIGH);

  } else {
    digitalWrite(relay, LOW);


Normally lots of options… but when using an Arduino and ESP in AT mode as a WiFi adapter, you are more limited in available connection management commands… so while you can use commands like Blynk.connected() or a manualy triggered Flag in your void loop to determine if needing to process or not… getting reconnected when you want too gets a bit more complicated.

Search this forum for similar issues/resolutions. In fact look for another related topic from withing the last 48 hours or so about what happens when an Arduino/ESP combo looses connection… similar principles are involved in keeping the action going without Blynk connection.

PS you will never get too far with Blynk and a void loop() like that :stuck_out_tongue_winking_eye:


+1. I’m a newbie and got educated very early on by @Gunner and @Costas on using timers and keeping the loop() very simple. Helped organise my code well too. Practically, gauge/value displays can be done in intervals of a second or 5 or 10. The loop() probably will execute a thousand times/sec limited only by any IO like serial and so on. Not necessary, IMHO. Best to figure out a good time interval to read data/pins/sensors and update the display. Use that in a timer to run the routine periodically at those intervals.

When I learnt how to use the timer, connection management too become a breeze. I now manage connections completely through timers and use event triggered calls like BLYNK_CONNECTED() to take specific actions like sync with server to restore states of pins etc. Has been a wonderful learning experience for me. Feel 40 years younger!

Great platform, great community and so much help. So, am pitching in my 2c.