I am using a esp32 in BLE mode and making a outboard fuel -meter. On start up I call Blynk.syncVirtual(V3) to get the total fuel consumption followed by a corresponding BLYNK_WRITE(V3) but this function never gets called!? I have tried syncAll() as well but none of my BLYNK_WRITE gets called.
It works with my esp8266 but not esp32 in BLE mode!?
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT
#include <BlynkSimpleEsp32_BLE.h>
#include <BLEDevice.h>
#include <BLEServer.h>
BlynkTimer timer1;
volatile double trip_volume = 0.0;
volatile double n_pulse = 0.0;
volatile double total_consumption = 1.0; %%UPDATE THIS AT BOOT
int Signal_Pin = 13;
volatile double Flow = 0.0;
float dt = 1.0;
float v_disp = 0.17; // mL per pulse
float F_pulse = 98.0; //98pulse per sek = 1L/min
float speed_kmt;
float speed_knots;
float speed_mps;
float Flow_lpkm;
bool going_to_sleep = false;
bool syncedonboot = false;
int noConnect = 0;
int update_timer;
int boot_timer;
int units;
float speed_units;
float conv = 1.944;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";
void setup()
{
attachInterrupt(digitalPinToInterrupt(Signal_Pin),pulse, RISING);
Serial.begin(9600);
Serial.println("Waiting for connections...");
Blynk.setDeviceName("Blynk");
Blynk.begin(auth);
delay(200);
}
BLYNK_CONNECTED()
{
Serial.println("connected and syncing");
Blynk.syncVirtual(V3); %% <----------- HERE I TRY TO GET THE LATEST CLOUD DATA
delay(500);
}
BLYNK_APP_DISCONNECTED() {
timer1.disable(update_timer);
Serial.println("app diconnected");
}
BLYNK_WRITE(V3) <----------------- THIS NEVER GETS CALLED
{
Serial.println("synced at boot");
delay(50);
total_consumption = param.asFloat(); // get the latest fuel consuption from server
syncedonboot = true;
update_timer = timer1.setInterval(1000L*dt, update_values);
}
BLYNK_WRITE(V5)
{
units = param.asInt(); // Swith between units
delay(20);
}
BLYNK_WRITE(V8)
{
dt = param.asInt(); // Swith between units
delay(20);
Serial.print("dt is now");
Serial.println(dt);
}
void update_values()
{
Flow = n_pulse / F_pulse * 1 / dt; // in [L/min]
speed_kmt = speed_knots/0.54; //mps to kmt
Flow_lpkm = Flow * 60.0 / (speed_kmt); // in ???
if (units == 0){
speed_units = speed_knots;
}
else{
speed_units = speed_kmt;
}
Blynk.virtualWrite(V0, Flow);
delay(20);
Blynk.virtualWrite(V1, trip_volume);
delay(20);
Blynk.virtualWrite(V3, total_consumption);
delay(20);
Blynk.virtualWrite(V2, Flow_lpkm);
delay(20);
Blynk.virtualWrite(V6, speed_units);
Serial.println("updating values");
Serial.println(Flow);
Serial.println(trip_volume);
n_pulse = 0;
}
BLYNK_WRITE(V7)
{
Serial.println("speed is synced");
speed_knots = param[3].asFloat()*conv;
}
BLYNK_WRITE(V4)
{
trip_volume = 0.0;
Blynk.virtualWrite(V1, 0.0);
}
void pulse() //measure the quantity of square wave
{
trip_volume += 1.0 / 5880.0; // in Liters
total_consumption += 1.0 / 5880.0; // in Liters
n_pulse += 1.0;
}
void loop()
{
Blynk.run();
timer1.run();
}