Wemos water project Timers?

I guess I misunderstood how the timers worked, I thought that for some reason they would run right after each other if they were on the same time slot. Thanks for steering me correctly.

its weird though, because it seems like my interrupt isn’t working now. I’ve only changed the times of the timers and i can only get it to work in the first code I sent. I currently have it as follows and it is not functional. its reading the flow count variable as 0 even though I know its passing water and the sensor works if i upload the old code so thats not it…
hmmmmm

  FlowTimer = timer.setInterval(1000, sendFlow);//interupt for flow sensor 
  timer.setInterval(300000L, CheckConnection); // check if still connected
  timer.setInterval(3600000L, ResetVs);// reset daily flow counter
  timer.setInterval(200L, Sent_serial);//send serial updates to blynk for debug
 // timer.setInterval(50, WIFILed);//show wifi status on actual box. 
  timer.setInterval(1502L, sendTemps);// update pipe temp, need to get thermowell i think

I haven’t gone through your code… i just don’t have the focus for that :stuck_out_tongue: Nor can I say I have used interrupts much… but I think interrupts, by their nature, shouldn’t need timers for polling… but can disrupt timing of code (based on what little I have read about them).

Try commenting out the serial debug and see what happens.

Also, I do not see any pinMode() for this pin 13

Try looking at this document… is seems to mention a few things about interrupts that I don’t think I see in your code… so far…

Thanks ! I did miss that pin mode, and reading that doc was definitely enlightening, it seems that the digitalPinToInterrupt function they referred to is only needed when using the referenced pin name, not the actual pin assignment, so I shouldn’t need that, (i may be wrong so ill try it both ways.)

I’ll try removing the serial debug and see what happens.

Thanks so much for your help so far.

i added the pinMode for that and commented out the serial debug timer, and unfortunately this had no affect on the functionality… i saw a spike in flow once, but it went straight back to zero.

was I just getting lucky when this was (half) working before? :tired_face:

At this point you may need to block out large sections of your code and start working with one piece at a time, adding in another as you confirm the first is working and so on.

One quick note… as per another topic, try adding in…

#define BLYNK_NO_BUILTIN  // Disable built-in analog & digital pin operations

…to your code. If you do not use any direct pin reading or control in your App (and you shouldn’t if you are using virtual pins) then this will disable that internal function and may help with timing.

Is your ESP resetting when the water is flowing, or just randomly?
Interrupts are great, and the only way to deal with flow sensors like this, but they take priority over everything else, so can disrupt your code flow if an interrupt occurs at an unwanted/unexpected time.
It’s normal practice to either disable the interrupt, or use the nointerrupts command to ensure that the interrupts don’t mess up your processing. Of course this means that you could miss some pulses from your flow meter.
If the ESP is resetting when no interrupt pulses are being generated than this isn’t where your problem lies.

You may also find that the flow sensor produces some unwanted noise when each pulse is generated - in effect switch bounce from the internal mechanism that generates the pulses. I have a rain gauge that uses a tipping bucket mechanism where a magnet triggers a reed switch when a certain amount of water has Ben collected in the little bucket. The reed switch produces several pulses per tip of the bucket, so to get an accurate reading I have to use a switch denouncing routine to filter out the noise. This may not be an issue with your sensor, and you may not even care if you get inaccurate readings, but it’s something to be aware of.

Pete.

Can’t say Much about the code but the control to sensor response lags your seeing are the basis of a whole branch of engineering.
Look up “PID controllers”.

Unfortunately its randomly. I have started by letting the changes sit for a day to see what happens, so far same result, except that i’m seeing it throw “Confused Hot OFF” which is only called in this section of code: a BLYNK_WRITE(), but its only if the button doesn’t send a 1 or 0 which doesn’t make sense to me. its also only happening when the app isnt open on my phone. Is it possible blynk is sending something else? im going to have it serial print whatever the param is there. ill report back soon.

BLYNK_WRITE(V1) // hot or cold
{
  if (param.asInt()) {    // if Button sends 1
    DisableTimers();
    WaterStatus = 1;
    Blynk.virtualWrite(V9, WaterStatus);
    hMovetime = 0;
    cMovetime = 0;
    OpenHot();
    Serial.print("Button Sent 1, Manual on for "); Serial.print(virtualpin7 / 60000); Serial.println("Mins");
    Override = 1;
    timer.setTimeout(20000, OpenCold);
    timerNo = timer.setTimeout(virtualpin7, OverrideCountdown);
    RegulateTimer = timer.setInterval(20000, TemperatureRegulate);
    Serial.print("Timer Begins. Override Time= "); Serial.println(Override);

  } else {
    Serial.println("Button Sent 0, Turning Off");
    Blynk.virtualWrite(V0, 20);
    Blynk.setProperty(V1, "color", "#0099ff");
    if (Override == 1) {
      Serial.println("Manual Off. Disable Timer(s).");
      DisableTimers();
      MoveValve(2, 1, 50000, 50000, "Manual Hot OFF");
      Override = 0;
    } else {
      MoveValve(2, 1, 50000, 50000, "Confused Hot OFF");
      Override = 0;
    }
  }
}

but also unfortunately I have a work trip this weekend and wont be able to spend much time on it till Sunday.

Interesting, seems like a pretty in-depth subject. Ill fix my current rebooting issues and dive into this a little deeper.

I’m getting those same responses more now on that if statement which is unusual.
But it’s printing a zero for what the parameter of the Blynk_Write is sending. I’m confused why this function is even being called, as no one is in the app and nothing is changing.

The serial print back looks like this:

Confused Hot OFF
0

----MoveValve Called----
Confused Hot OFF
2
1
50000
50000
------------------------
Hot MoveTime 4294877296
Cold MoveTime 90300
Button Sent 0, Turning Off
Confused Hot OFF
0

----MoveValve Called----
Confused Hot OFF
2
1
50000
50000
------------------------
Hot MoveTime 4294827296
Cold MoveTime 140300
Button Sent 0, Turning Off
Confused Hot OFF
0

----MoveValve Called----
Confused Hot OFF
2
1
50000
50000
------------------------
Hot MoveTime 4294777296
Cold MoveTime 190300

Do you have anything connected to the 5v or 3.3v pins on the Wemos D1 Mini?
I’ve had a situation before where I was powering a Wemos via the USB connector and powering a sensor via the 5v pin. The Wemos would randomly reset itself and the problem was solved (eventually) by powering the Wemos and the sensor separately.

The other thing is, I personally try to avoid this type of coding:

in favour of:

int x = param.asInt() {    // Store button value in local variable x
Serial.println(x);         // print the value from the button
if (x) {                   // could also be written as if x == 1

Both approaches work, it’s just a bit more transparent and it’s then easier to to do an explicit if (x==0) test rather than use an else statement.

Pete.

1 Like

hope this could help you

1 Like

a bit much to read it all, anyway I noticed:

} else if (disconnectCount > 20) {
  ESP.restart();
}

this can go wrong (esp can get stuck) you need to add delays around it. E.g.:

} else if (disconnectCount > 20) {
  delay(3000);
  ESP.restart();
 delay(5000);
}

delays can be shorter, but its better to be on the safe side.

1 Like

Thanks Wolph, this seemed to stop the random restarts. I also added a WiFi AP closer to this unit which way have helped some.

Also thanks Peter, not sure exactly if this made a difference but I went with it.

Alexis, This seems pretty useful, ill definitely be looking into it to confirm some of my timer operations here.
Nice Work!

1 Like

So for about a week or so the only restarts that have happened are on purpose. and its passing data back and forth as needed. seems like i’m in a pretty good spot aside from the temperature regulation.

I’m going to strip it back and start with a more simple situation, just opening the cold a fraction at a time until it hits the correct temp. If anyone has any ideas on how to make that work better I would love to hear it.

You guys have been fantastic so far though. thanks for all the help.

Maybe one solution is to sense the temperature of the hot and cold lines before they go through the valves, so that you can estimate how much of each will be needed to give your desired output temperature?

Pete.

And how will your system work without the Internet? In such projects I use a real time clock with a battery (ds3231), and install a small display (oled 1.3") and buttons on the main box. And all the timers and other data saved to ds3231 onboard memory.