Synchronize flow meter reading HELP

Hi I’m trying to use a Wemos d1 mini and YF-S201 flow meter and I would like to synchronize the flow reading via blynk in case of lack of connection.
I have enabled virtual pin V3 on Blynk console in the datastreams section
with Data Type “String” and with Sync with latest server value every time device connects to the cloud but it doesn’t work, the value on restart is always 0.
Where am I wrong?
Thank you.

  
#define D2 4    

#define BLYNK_TEMPLATE_ID       "TMPL4xYq*****"
#define BLYNK_TEMPLATE_NAME     "TEST"
#define BLYNK_FIRMWARE_VERSION  "0.9"

#define BLYNK_PRINT Serial
#define APP_DEBUG
#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"

BlynkTimer timer;


//******************** VARIABILI FLUSSOMETRO ********************
int ingresso = D2;   //Piedino di ingresso del flussostato
int flusso  ;      //Quantità di acqua che scorre
volatile int count; //Variabile di conteggio 

//******************** VARIABILI FLUSSOMETRO ********************

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

  BLYNK_WRITE(V3) { flusso , param.asInt();}



void setup() {
  Serial.begin(115200); 
  BlynkEdgent.begin() ;  

  pinMode (ingresso, INPUT);  //Imposta piedino 2 in ingresso
  attachInterrupt (ingresso, IntCallback, RISING);  //Configura interrupt D2 pin 2

  timer.setInterval( 1000L, LetturaFlusso ) ;
   }


IRAM_ATTR void  IntCallback(){

count = count +1;   //Incrementa count di 1}
}


void LetturaFlusso(){

  flusso = (count * 2.25);  //2.25mL per ogni impulso
  flusso = flusso / 1000;   //Trasforma i mL in litri
  Blynk.virtualWrite(V3, flusso ," L");
}


void loop() {
  BlynkEdgent.run();
  timer.run();

}

You don’t need that option enabled unless you’re using the Blynk.syncAll() command.

You’re using a string data type, but asking your sketch to treat this as an integer (that’s what the “int” bit in param.asInt() means).

I’d try this instead…

BLYNK_WRITE(V3)
{
  String V3_value=param.asString();
  Serial.print("V3 value = ");
  Serial.println(V3_value);
}

Pete.

Hi Peter,
the original value of “int flow” was “flaot flow”, unfortunately in datastreams if I set Data type double or int the value is no longer displayed on the app, it is only displayed if I set String.

I tried as you recommended, and I noticed that on the serial line the value is displayed correctly, however on the app I always get 0.000

I don’t understand.

Pete.

On the serial monitor the flow value is read by the blynk server and therefore synchronized, instead on the blynk iot app (it always remains 0.000 when the device restarts)


It’s difficult to tell what you’re actually testing there, because you’ve changed the code from what I suggested.

When you post code/serial output in future, please post it as text with triple backticks, not screenshots.

Pete.

Solved, so it works perfectly.

  
#define D2 4    

#define BLYNK_TEMPLATE_ID       "TMPL4xYq"
#define BLYNK_TEMPLATE_NAME     "TEST"
#define BLYNK_FIRMWARE_VERSION  "0.9"

#define BLYNK_PRINT Serial
#define APP_DEBUG
#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"

BlynkTimer timer;


//******************** VARIABILI FLUSSOMETRO ********************
int ingresso = D2;   //Piedino di ingresso del flussostato
float flusso  ;      //Quantità di acqua che scorre
float flussoprec  ;      //Quantità di acqua che scorre

volatile int count; //Variabile di conteggio 

//******************** VARIABILI FLUSSOMETRO ********************

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

  BLYNK_WRITE(V3) { 
  flussoprec = param.asFloat();
  Serial.print("flusso = ");
  Serial.println(flusso+flussoprec);}



void setup() {
  Serial.begin(115200); 
  BlynkEdgent.begin() ;  

  pinMode (ingresso, INPUT);  //Imposta piedino 2 in ingresso
  attachInterrupt (ingresso, IntCallback, RISING);  //Configura interrupt D2 pin 2

  timer.setInterval( 1000L, LetturaFlusso ) ;
   }


IRAM_ATTR void  IntCallback(){

count = count +1;   //Incrementa count di 1}
}


void LetturaFlusso(){

  flusso = (count * 2.25);  //2.25mL per ogni impulso
  flusso = flusso / 1000;   //Trasforma i mL in litri
  flusso = flusso+flussoprec ;
  Blynk.virtualWrite(V3, flusso ," L");
}


void loop() {
  BlynkEdgent.run();
  timer.run();

}