Blynk 2.0 walk in cooler (Offline)


I am currently running Blynk 1.0 with custom server and want to go to 2.0. I have searched but cant seem to find a clear answer on wether or not my sketch will continue to run if internet connection is down. I am going to be running an A/C unit with a particle Photon to control cooler temp. If internet goes down or connection lost will the Photon know or retain the set temp on the slider widget? I did read on the forum somewhere 2.0 would be able to accomplish this in the future, post was about 1yr old. Has this been accomplished and if so how or what do i need to do? Below is the sketch

  Download latest Blynk library here:

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials:
    Sketch generator: 
    Blynk community:  
    Follow us:        

  Blynk library is licensed under MIT license
  This example code is in public domain.


  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - Arduino Ethernet board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
//#include "math.h"
//#include "adafruit-sht31.h"

// Temp/Humidity Sensor
//Adafruit_SHT31 sht31 = Adafruit_SHT31();
#include <Wire.h>
#include "DFRobot_SHT20.h"

DFRobot_SHT20    sht20;


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxx";

const char* IP = "xxxxxxxxxxxxxx";

bool tempflag = true;

int relaisOn = D7; 
int relaisV = D6;  
int hysteresis = 2;
float Thermostat = 0;

//float h = sht20.readHumidity();                  // Read Humidity
    //float t = sht20.readTemperature(); 
    //float Thermostat = (t* 9) /5 + 32;

  Thermostat = param.asFloat();

// the timer object
BlynkTimer timer;

void setup() {

  // Debug console
    //Serial.println("SHT20 Example!");
    sht20.initSHT20();                                  // Init SHT20 Sensor

   Blynk.config(auth, IP, 80);

 delay (5000);
   timer.setInterval(7 * 1000L, sendSensor) ;
   timer.setInterval(1000L, relaisAlim);
 //timer.setInterval(30 * 1000L, Temp) ;
 //timer.setInterval(5 * 1000L, sendTemps) ;
 //timer.setInterval(5000L, TempNotify );

void loop() 



void sendSensor()

    float h = sht20.readHumidity();                  // Read Humidity
    float t = sht20.readTemperature(); 
    float ftemp = (t* 9) /5 + 32;

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, ftemp);

  //Serial.print(" Temperature:");
  //Serial.print(ftemp, 1);
  //Serial.print(" Humidity:");
  //Serial.print(h, 1);


void relaisAlim()   


 float h = sht20.readHumidity();                  
 float t = sht20.readTemperature(); 
 float ftemp = (t* 9) /5 + 32;
  //Serial.print("Temperature : ");
 // Serial.print(TempSom);
  //Serial.print("Thermostat : ");

  if (ftemp >= (Thermostat + hysteresis))

    digitalWrite(relaisOn, 1);
    Blynk.virtualWrite(V3, 0);
    Blynk.virtualWrite(V2, 255);

  else if (ftemp <= (Thermostat - hysteresis))
    digitalWrite(relaisOn, 0);
    Blynk.virtualWrite(V2, 0);
    Blynk.virtualWrite(V3, 255);

How does your sketch prepay the moment if you take your Legacy local server offline?

I ask, because although you’ve used Blynk.config instead of Blynk.begin, you make no effort to prevent from being executed if Blynk.connected is false. This will probably result in long reconnection attempt periods, when no other parts of the sketch are being executed.

I think you’re probably referring to offline automations, which is something different.


Does it work on automations? I have a cattle feeder setup to feed twice a day with automations on 2.0 so will offline automations work?
So your saying I need a if blynk not connected statement? Even with that what controls the temp if thermostat widget slider isnt connected? How does it know if thermostat is >=. I dont have a physical rotor or button to set the temp, its all controlled from blynk app.

Only if you have a White Label business account.

You’re storing the value in a global variable. If the device loses its connection to Blynk then that variable will hold the last value and continue to use it - provided it can actually execute the void loop without being constantly blocked by reconnection attempts.
Obviously if the device loses power itself then you would either need a hard-coded default value to use, or store the last slider value in non-volatile memory.


So offline automations wont work with plus account? What if automation is mission critical like greenhouse fan/water, Feeder or Meat Cooler? Say I have a feeder setup to feed twice a day while Im gone on vacation and internet goes down? Will feeder stop working until internet comes back? These are questions I have before i implement 2.0. I have been running everything here on the farm with local server for yrs and never an issue because it runs on the local network but now I can no longer download the 1.0 app from the app store so Im being forced to go to 2.0 or find another solution. The reason for this post is mostly irrelevant to the local server as it will go away because no longer have access to the 1.0 app. These questions are for the upgrade to 2.0. Is there an alternative to automations?

How is this accomplished on a particle board (Photon,Boron,Argon)?

That is currently correct, and I have no idea if that will change in the future.

It won’t perform any actions that are normally triggered by Automations.
As far as the rest of it is concerns, it depends how you’ve written your code, and tat’s something I’ve touched-on already.

Yes, of course. you can do the process in code. Obviously, with any system - including offline automations - if you want to change the settings or schedule then the device needs an internet connection to see those changes.

I have no idea, as I’m not familiar with that hardware. I only use ESP8266 and ESP32 dev boards.


Pete Thanks for all your help im not sure what to do at this point. As i live in a rural area where internet sucks and thats why i am using the local server. Just really stinks it has to go away because i cant download the app. I will research what you have suggested and see what i can come up with. If anyone else has a solution they are implementing Please share.

Personally, I use Node-Red as my rules engine, and that runs on a local server (a Raspberry Pi in my case).
This communicates with my WiFi devices via MQTT messaging, so my devices don’t run any Blynk code.

My Node-Red server has the Blynk plug-in installed, and when I have an internet connection (which is most of the time for me), I can use Blynk to view and change data on my Node_Red server.

The server is connected to a UPS, and it keeps track of the time, and synchronises this when a, internet connection is available. The rules engine holds my schedules, which can very easily be based on set times of day or sunrise/sunset times.
Node-Red has a browser based interface, so even if there is no internet connection I can monitor and change values from within the local network.

Something to consider?


Pete thanks I will definitely look into it!!


1 Like