Doubts about the links between app, server and arduino

Hello,
I’m developing a project with an arduino mega (with esp module) and a local server running in a raspeberry. the idea is to control the temperatura in my home controlling the boiler (with temperature sensor, hourly program and relay to command the boiler).

I have some doubts about some aspects of this system…
1-I use the function generated by a variation of the value insert in the numeric input setting widget (V16) to doing this:

BLYNK_WRITE(V16){ setpoint=param.asInt()}

The global variable “setpoint” mantain the value also if the smartphone where is installed the widget is offline? So if the code has a control placed in a function called each second like this:

if(setpoint<sensor_value)turn_on_boiler();

arduino does this action also if the smartphone is offline? If the local server is offline? I don’ understand how much the code in the arduino is indipendent to the server and the smartphone…

2-I have the same doubt about the function generated by the timer setting widget (V17):

BLYNK_WRITE(V17){ if (param.asInt()==HIGH) turn_off_boiler()}

For example I set in the widget the start time 10.00 and the stop time 20.00.
If from the 9.59 the arduino or the local server are down what happen? when it’s 10.00 the code calls the function “turn_off_boiler”

Thanks

A BLYNK_WRITE() function is called whenever a corresponding widget is touched/triggered… if the App is offline, then obviously this cannot happen (technically the API call or a write/sync command combo will work… but that requires the server for sure to be connected to the device)

But depending on how you write your code, the previous value is already assigned to setpoint, or if the device itself is rebooting, can be recalled from the server with a Blynk.syncVirtual(V16) command.

Then your device is totally dependent on how you wrote your code (able to function when disconnected from server or not), and whether or not it is still running with last values retained in the variable or not.

Depends on the widget… the Time Input widget is just a simple data collection widget that sends both start and stop times to your device as soon as you enter them… then it is up to your code to remember and process them “on time”… thus needs to be running and probably connected to the server, unless you have implemented connection management code as per link above.

However, I think the Timer Widget should process accordingly on time IF the server is connected to the device, even if App not active… You should be able to test this on your own with a simple sketch.

Thanks for your reply. I understood and you preceded another my question.

If arduino is starting but the local server is down, arduino doesn’t connects to the local server not even when the local server returns online.

If I understood your suggested code it allow to arduino to try a new connection every 30 seconds if is not connected. this resolves the problem explained above…

Well… that example is more for a dedicated ESP8266 device… I had some slight modifications that seemed to run better on my Mega/ESP-01 combo.

in setup() and loop() instead of this…

  WiFi.begin(ssid, pass);  // Non-blocking if no WiFi available
  Blynk.config(auth, server, port);
  Blynk.connect();

I had this…

  wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
  Blynk.config(wifi, auth, server, port);
  if (Blynk.connectWiFi(ssid, pass)) {
    Blynk.connect();
  }

If I recall, it worked on the basis that my ESP (in AT mode) had at one time retained the SSID/password in memory… but I am no longer sure why I did this differently :stuck_out_tongue:

Try and see which works better on your end

Sorry but in my code I’m using the ESP8266_Lib.h (according the Blynk sketch code builder), but you are using ESP8266WiFi.h.
Do I change the library?

Thanks

Depends on what hardware you are running… an ESP8266 used as a dedicated device uses one library, an ESP8266, used in AT mode as a Serial-WiFi adapter for Arduino, uses a different library.

You can toggle between different hardware options in the Sketch Builder to see the differing needed libraries.

Sorry but this isn’t clear for me… now I’m using arduino mega with esp8266 module to connect to the LAN and I’m using ESP8266_Lib.h… I’d like to use your sketch to implement the “reconnection”… I don’t unsterstand if I have to change the library…

All the Blynk libraries work the same way… just meant for different hardware config. I make some sketches for different hardware, so you keep whatever library works for your hardware (ESP as shield) and use the rest of the sketch.

Again… L :eyes: k at the different sketch builder examples for different hardware… Say, Blynk.Blink… note how the library changes but the rest of the code generally stays the same.

UNO & ESP8266 as shield
https://examples.blynk.cc/?board=Arduino%20Uno&shield=ESP8266%20WiFi%20Shield&example=GettingStarted%2FBlynkBlink

ESP8266 standalone
https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=GettingStarted%2FBlynkBlink

ESP32 standalone
https://examples.blynk.cc/?board=ESP32&shield=ESP32%20WiFi&example=GettingStarted%2FBlynkBlink