ESP8266 project resets and syncall() not called

i have a water tank and usage monitoring app on ESP8266. have 10 data points monitored, write once every minute.
there is no delay between Blynk.virtualWrite()calls

 Blynk.virtualWrite(V1, WaterDepth1);                                //send depth to Blynk server
  Blynk.virtualWrite(V2, Litres1);
  Blynk.virtualWrite(V3, Gallons1); //send litres to Blynk server
  justStarted= false;

  if (flowRate > 0.0) {
    if (flowRate > maxFlowRate || flowRate < maxFlowRate)
      maxFlowRate = flowRate;
   if (flowRate >   targetFlowRate)
      targetFlowRate = flowRate;
  if (maxFlowRate > 0.0) {
    Blynk.virtualWrite(V4, maxFlowRate); //send latest rate to Blynk server
    Blynk.virtualWrite(V5, targetFlowRate); //send target flow rate
    Blynk.virtualWrite(V6, flowRate); //send target flow rate
    Blynk.virtualWrite(V7, pulseCount); //send target flow rate
    Blynk.virtualWrite(V8, elapsed); //send target flow rate
    Blynk.virtualWrite(V14, WaterUsed/ ticksPerGallon) ; //send water used since reset
    Blynk.virtualWrite(V15, WaterUsed);  // ticks of sensor

during setup(), i use syncAll() to get the latest server valuesā€¦ (if the user sets the size of the tank, i need to use that, not the default values in the arduino compiled code. )

butā€¦ i get resets every now and then (weekly?), but the setup() code is not called, or the syncAll() is not called.
if I manually change the slider of the value, then the appropriate writebacks are called

BLYNK_WRITE(V10) {   // diameter
  Diameter1 = (int)(param.asInt() * 2.54);
  printmsg("v10 (diameter) =" + String(Diameter1) + " read=" + String(param.asInt()));
  Area1 = PI * ((Diameter1 / 2) * (Diameter1 / 2));
  AlertCounter = 1;
BLYNK_WRITE(V11) {   // height
  Depth1 = (int)(param.asInt() * 2.54);
  MAX_DISTANCE = Depth1 + minDistance+distancetofull;
  printmsg("v11 (depth) =" + String(Depth1) + " read=" + String(param.asInt()));
  AlertCounter = 1;

the setup code

void setup() {
  ArduinoOTA.onError([](ota_error_t error) {
  });       //added for OTA

  timer.setInterval(Period, sendSensorReadings);      // Setup a function to be called every 'n' seconds
  timer.setInterval(watchFlow, flowTimer);


  //**    can be commented out, test only
  Serial.begin(115200);                                               // Open serial console.
  pulseCount        = 0;
  flowRate          = 0.0;
  lastTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  WiFiManager wifi;
  printmsg("interrupt setup");
  // WiFi.begin(ssid, pass);
  Blynk.config(auth); //,ssid, pass);

it works great, then resets, then works great, then resetsā€¦

i have interrupts that collect the values, then timer (1 minute) that calculates the values and send to server

No idea why the resets in the first placeā€¦ but I have found that Blynk.syncAll() is a potentially naughty commandā€¦ as it literally tries to sync every single available vPinā€¦ and depending on what each vPin calls, that could end up with multiple functions all trying to run at the same time.

I just specifically sync each absolutely needed vpinā€¦

Blynk.syncVirtual(V0, V8, V22);

I think Blynk.syncAll() works best when used in the way as shown by @Gunner, that is inside the BLYNK_CONNECTED() function.

especially if you are just dropping connection (bad internet, etc.), and your device isnā€™t actually resetting.

thanks, that is easy to doā€¦

still need to figure out why the resetā€¦

i used to have individual calls to syncVirtualā€¦

thanksā€¦ butā€¦ the values defined at compile time are suddenly being usedā€¦ NOT the most recentā€¦

that is what I call resetā€¦ ALMOST like power cycle on the deviceā€¦except the sync of the previous value is not usedā€¦

if I was just dropping connection, then on reconnect, I would still have the old values (used a minute ago, or last connect)

Copy that. I would still use it as shown. This will ensure your are actually connected to BLYNK when the sync function is called.

ok, but it seems like a LOT of unnecessary syncs.

doneā€¦ will upload new code to the device tomorrow on next visit to the house

Are you sure this line is correct?

1 Like

yes, i am watching the flowrate as a historical max valueā€¦over long periods of timeā€¦

i donā€™t want one cycle of 20gpm to skew the chart foreverā€¦

But your if statement will execute in all situations, unless of course flowRate is EXACTLY equal to MaxFlowRate.
I canā€™t see how this helps what youā€™re trying to achieve.

Also, thereā€™s no curly brackets after your if statement, which will really mess-up your program flow.

There is a similar issue with this block of code:

The Blynk.virtualWrite statements fall outside of any function so will never execute. This may well be to do with how youā€™ve chopped your code up into snippets, which is why itā€™s always best to post the whole code in one block.


Thanks. Understood about loading all the code. I posted only what I thought was relevant to the issue at hand.

This is code inside a timer method and in setup.

so far the change to do only sync during the BLYNK_CONNECTED() callback works greatā€¦ thanks!!

1 Like

well, after more spurious resets caused by button push, I decided to add an other ui element to act as a control on accepting the button pushā€¦ I picked a slider value, which would make it near impossible to ā€˜accidentallyā€™ get a specific value.

since adding the slider as the control variable, I have not had a single spurious resetā€¦
soā€¦ something is calling my BLYNK_WRITE(V9) (button push) routine when it shouldnā€™t be

I had put the button on a separate tab to prevent accidental pushes , but that didnā€™t help
I do NOT sync this variable on reconnect

new code

BLYNK_WRITE(V9)     // water used reset button pushed
  if(justStarted == false)
    if(resetSlider==51)  // new
     {    // new
     // reset the water used counter
     WaterUsed =0;
     Blynk.virtualWrite(V15, WaterUsed);
     resetSlider=0;  // new
     Blynk.virtualWrite(V6, resetSlider);  // new
     }  // end of new
  Blynk.syncVirtual(V10, V11, V12, V13,V15,V5, V1);  // do NOT sync the waterused reset button (V9)