BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Is there anyway to make it remember the numeric input data after a reboot?

I can input the data I want but if the board reboots it doesn’t remember the the data and i have to do it again from the numeric input again.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  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: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

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

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!-
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>  // For OTA w/ ESP8266
#include <WiFiUdp.h>  // For OTA
#include <ArduinoOTA.h>  // For OTA

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
// char auth[] = "oiXdJdY-cmz1WbZfr7o1SdUgncXJBCQF";// House Tank
char auth[] = "x3HDpMHpx8odgd2aKsSSR-d_TeYxWWjR";// Garage Tank

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "*****";
int port = 8080;
// defines pins numbers
// trigpin on board is d14, echo is d15
const int trigPin = 4;
const int echoPin = 5;
int relayPin = 13;// define output pin for relay (13 = MOSI)
// defines variables
BlynkTimer timer; // Announcing the timer


long duration;
float sheight;
float capacity;
float height;
float pumptime;
float distance;
float percentageFull;
float finalPercentage;
float finalcapacity;

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,84), 8080);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Inputs
  pinMode(relayPin, OUTPUT); // Sets the relayPin as an Output
  digitalWrite(relayPin, HIGH); // Sets relayPin to HIGH
  timer.setInterval(15000L, sensorDataSend); //timer will run every sec (changed 500 1/2 a sec to 15000 15 secs)
//  ArduinoOTA.setHostname("House Tank");
  ArduinoOTA.setHostname("Garage Tank");
  ArduinoOTA.begin();  // For OTA

}

void sensorDataSend()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
distance= distance-sheight;
percentageFull=(distance/height);
finalPercentage=(1-percentageFull)*100;
finalcapacity= (1-percentageFull)*(capacity*100);  
/* Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
Serial.print("percentagefull: ");
Serial.println(percentageFull);
Serial.print("finalPercentage: ");
Serial.println(finalPercentage);
Serial.print("finalcapacity: ");
Serial.println(finalcapacity);
//delay(5000);
*/
Blynk.virtualWrite(V0, finalPercentage);
Blynk.virtualWrite(V1, finalcapacity);
// distance= 0;
// percentageFull= 0;
// finalPercentage= 0;
// finalcapacity= 0;
}

BLYNK_WRITE(V2)  // Virtual button on Vx to activate action
{
  int pinvalue = param.asInt();
  int buttonState = param.asInt();
     if (pinvalue == 1) {
     digitalWrite(relayPin, LOW);  // Set pin low
     Blynk.virtualWrite(V2, 1);
     timer.setTimeout((pumptime*60000L), relayOFF);  // Run ActionOFF function in 5 seconds
     }
     if (pinvalue == 0) {
     digitalWrite(relayPin, HIGH);  // Set pin high
     Blynk.virtualWrite(V2, 0);
     }
}

void relayOFF()
{
  digitalWrite(relayPin, HIGH);  // Set pin high
  Blynk.virtualWrite(V2, 0);
}

BLYNK_WRITE(V3) // Reset
{
if (param.asInt()==1) {
delay(3000);
ESP.reset();
delay(5000);
}
}
BLYNK_WRITE(V4) //input from Numeric Widget for time pump runs
{
  pumptime = param.asInt();                            // Assigning incoming value from pin V4 to variable
  Blynk.virtualWrite(V14, pumptime);                   // V14 just to test it's working
  Serial.println(pumptime);
}

BLYNK_WRITE(V5) //input from Numeric Widget for height of sensor above max water level
{
  sheight = param.asInt();                            // Assigning incoming value from pin V5 to variable
  Blynk.virtualWrite(V11, sheight);                   // V11 just to test it's working
  Serial.println(sheight);
}

BLYNK_WRITE(V6) //input from Numeric Widget for max capacity of tank in L
{
  capacity = param.asInt();                            // Assigning incoming value from pin V6 to variable
  Blynk.virtualWrite(V12, capacity);                   // V12 just to test it's working
  Serial.println(capacity);
}

BLYNK_WRITE(V7) //input from Numeric Widget for height of water from bottom of tank to max water level
{
  height = param.asInt();                            // Assigning incoming value from pin V7 to variable
  Blynk.virtualWrite(V13, height);                   // V13 just to test it's working
  Serial.println(height);
}


BLYNK_WRITE(V99)  // Virtual button on Vx to activate action
{
  int pinvalue = param.asInt();
     if (pinvalue == 1) {
     digitalWrite(relayPin, LOW);  // Set pin low
    
     }
     if (pinvalue == 0) {
     digitalWrite(relayPin, HIGH);  // Set pin high
     }
}

void loop()
{
  
  Blynk.run();        // run Blynk magic
  timer.run();        // run timer every second
  ArduinoOTA.handle();  // For OTA
  

}

@Idamo please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

done sorry i was trying to work out how to make it display like that.
cheers

Add a section of code like this:

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V5);
}

The BLYNK_CONNECTED callback function will execute each time the device connects or re-connects to Blynk.

Blynk.syncVirtual(V5) will cause the Blynk server to send the latest value from your app (via the server) to your device. This will cause the BLYNK_WRITE(V5) callback function to execute.

If you want to synchronise the status of your other widgets then you can add Blynk.SyncVirtual commands for those virtual pins as well.

Pete.

2 Likes

Sorry @PeteKnight for not replying! Thank you very much this worked a treat :slight_smile:

1 Like