Recover data from the server on restart

Hi,

I probably don’t have the right syntax to find my answer …

But I would like to retrieve the data of the Minimun Maximum values which are on the server in case of restarting the esp

An idea ?

Thank you


#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

BlynkTimer timer;

const int PinEntree = 34;
int Valeur = 0;

void myTimerEvent()
{

  Valeur    = analogRead(PinEntree);

  if (Valeur < Minimum)
  {
    Minimum = Valeur;
  }
if (Valeur >  Maximum)
  {
    Maximum =Valeur;
  }


  Blynk.virtualWrite(V1, Valeur) ;
  Blynk.virtualWrite(V2,Minimum);
  Blynk.virtualWrite(V3,Maximum ) ;
}

void setup()
{

  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}

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


You need to use Blynk.syncVirtual(vPin) probably within a BLYNK_CONNECTED callback function.

You’ll also need BLYNK_WRITE (vPin) callback functions for your virtual pins, which will be triggered when the syncVirtual commands are executed.

It’s all in the documentation…

Pete.

1 Like

Hi

it’s work

thx

1 Like

This will work provided your value hasn’t been lower while there was no connection. To be absolutely sure you would need to store the value in littleFS every update then you could restore it from littleFS and update the server.