How can I save data in a Blynk application

Hi everyone.
I´m developing an application to test a valve with Blynk. This will open and close the valve and count the cycle until the valve fail.
I need to save the number of cycle the system run and send this to the responsable for test. How can I set up Blynk to do this?

Thanks.
Rodrigo

Count++, virtualWrite() and syncVirtual() would do it as a bare minmum.

1 Like

The system is already runnig but I can store the information of how many cycles valve ran.
I need to save this number to consult later.

virtualWrite() will store the count on the server for you and the value can be retrieved from the server on request with syncVirtual().

1 Like

I used syncVirtual(), but I think is not what I need.
I´m looking for something to saved data in some kind of database.

By saving the values on the server you automatically have up to 3 months historical data available which can be accessed via the API and downloaded in csv format.

You can use Webhooks to send the data direct to Google Sheets.

Lots of different ways.

All virtualWrites are stored in a database which you re-call using syncVirtual.

Send the data to a display widget for visual, and link the vPin to the History graph or SuperChart and pull the CSV data from there when needed.

All the info you need is in the Documents

@Gunner I already knew this solution, but I hope that was another one to save a CSV file without History Graph.
Thanks

Might have been nice to mention that up front :wink:

With Local Server you have a non-graphing widget solution…

https://github.com/blynkkk/blynk-server#enabling-raw-data-storage

Enabling raw data storage

By default raw data storage is disabled (as it consumes disk space a lot). When you enable it, every Blynk.virtualWrite command will be saved to DB. You will need to install PostgreSQL Database (minimum required version is 9.5) to enable this functionality:

I believe there is. All pins values are stored on the server and the csv is available via the API.

1 Like

Thanks guys. I´ll try use this.

Hi there.
I´m using virtualWrite and syncVirtual(). But I need to assign the value in a vitrual pin to a variable when the system is turned on.
I try it in many ways but nothing is working.

My code is like this:

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0, V1);

}

BLYNK_WRITE(V0) 
{
  db_ciclos = param.asLong(); 
}
BLYNK_WRITE(V1)
{
  contador = param.asLong();
}
BLYNK_WRITE(V2)
{
  nr_ciclos = param.asLong(); // assigning incoming value from pin V2 to a variable
  Blynk.virtualWrite(V0, nr_ciclos);
  lcd.setCursor(0, 1);
  lcd.print("Nr. Ciclos:");
  lcd.setCursor(12, 1);
  lcd.print(nr_ciclos);
  
  // process received value
}
BLYNK_WRITE(V3)
{
  start_buttom = param.asInt();
}

V0 and V1 will retrieve the server values each time you connect to the server.

However if you want to use the values outside of V0 and V1 you need to define them as global variables. So up by the libraries something like:

long db_ciclos;
long contador;

Presumably you already have these as your code wouldn’t compile without them. So what is the problem?

I define the variables as global variables as you said.
The problem is when I restart the system I want to variables db_ciclos and contador assume the values on the Blynk server. But both of then return 0 when it´s called.

What does Serial Monitor show the second time you run this code?

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0, V1, V2);
}

BLYNK_WRITE(V0) 
{
  db_ciclos = param.asLong(); 
  Serial.println(db_ciclos);
}

BLYNK_WRITE(V1)
{
  contador = param.asLong();
  Serial.println(contador);
}

BLYNK_WRITE(V2)
{
  Blynk.virtualWrite(V0, 3456);
  Blynk.virtualWrite(V1, 1212);
}

It shows 3456 and 1212

on the 2nd and subsequent reboots does it show 3456 and 1212 twice?

No. On the 2nd and subsequente reboots it shows 3456 and 1212 only once.

Yes that’s right it’s only the V0 and V1 sync that prints the values. If you now set V3 as a slider and virtualWrite db_ciclos to V0, V4 as slider with virtualWrite contador to V1 and remove V2 from the sync you will hopefully see that the slider values are being retrieved from the server when you reboot the ESP.