Long time absence from here so forgive me for not getting on in so long!
Project description:
This sketch is mainly to provide data logging and hopefully alerting via IoT of an alarm condition when thresholds are breached. This will hopefully alert me to long running pump times (kids left water hose on while filling up animal water buckets), Pump is just running for the hell of it and using electricity (this could be an indication of a faulty pump or pressure control), or pump is cycling on and off too quickly which will lead to a worn out pump and wear out the pressure control contact switch. Overall I am trying to figure out if my pump is on when it should not be and wasting electricity; as I seem to have some high energy use in our household. The well pump is set to turn off at about 55PSI and turn on at about 30PSI. I have a bladder pressure tank and a pressure flow regulating valve set to allow the pump to continuously run when the pressure tank is full and there is still flow happening to try and curb any on/off cycling.
Eitherway, it is roughly a esp8266 with 32mb of memory that is in the shape of a USB dongle. I basically used a button press example but I can not for the life of me figure out how to implement an easy counting solution. Meaning that the pump state change happens too fast for it to record the change to thingspeak. The only values that are coming out of the program that record somewhere to thingspeak is the cycle rate per min and cyclerate per hour. I do have data that feeds to thingspeak, but unsure on how to record pump cycles when my IoT resolution is every 15 sec, which means if I see pump state is <ON> and in turns on and off 5 times in 15 seconds I have no way to know that on the thingspeak page. How should I record the pump "on time" over time so I can see how it behaves for various uses(example kids watering animals, shower, laundry, dishwaser, etc).
What are some of your ideas on implementing such a solution? Should I set up a local database on a desktop to record the data stream too and if so what DB should I use? If I set it up locally how do I display the data on a that same machine so I can see it in graph form similar to how do on thingspeak? Should I change by counter to data gathering every 20 seconds and only send data every 20 seconds to thingspeak. Then reset the counter bucket. Should implement some type of array to store the data in on the esp8266 and then average the values to send out to Thingspeak? If I do a local DB I shoud be able to record data every second correct?
Thank you for looking over this project and giving your feedback. I appreciate your time!
I am avoiding using delay by using millis() as much as possible. I am also grabbing time via the NTPclient.
I basically did the the following for counting cycle rate per min, below is written in Arduino IDE:
Link to Thingspeak public channel:
Project description:
- monitor a well pump cycle rate (state is on or off and time it was on pumping and using energy)
- set thresholds for an alarm if state is on for too long or cycle rate frequency (ex. turns on/off 15 times in under 60 seconds or runs for more than 10 min)
- relay this data to an IoT or webserver
- I have thingspeak free account but I think it is too slow (15 sec).
- I have a windows 10 desktop that is on most of the time, send data to this and use it as a local webserver/DB/Datalogger
- I also have a raspberry pi in a box somewhere that I could figure out how to use again if need be
- I would like to know the follow data:
- is pump state on or off
- pump on time per cycle
- max pump on time
- min pump on time
- cycle rate per min
- cycle rate per hour
- Bonus data:
- Outside Temp
- pumpHouse Temp (working with ds18b20)
- phototransistor for light source in pumphouse
- relay to control light source based on temperature
- water pressure sensor(transducer)
- current monitoring would be the cats meow
- pumpMotor SSR to disconnect power to prevent pump damage.
Eitherway, it is roughly a esp8266 with 32mb of memory that is in the shape of a USB dongle. I basically used a button press example but I can not for the life of me figure out how to implement an easy counting solution. Meaning that the pump state change happens too fast for it to record the change to thingspeak. The only values that are coming out of the program that record somewhere to thingspeak is the cycle rate per min and cyclerate per hour. I do have data that feeds to thingspeak, but unsure on how to record pump cycles when my IoT resolution is every 15 sec, which means if I see pump state is <ON> and in turns on and off 5 times in 15 seconds I have no way to know that on the thingspeak page. How should I record the pump "on time" over time so I can see how it behaves for various uses(example kids watering animals, shower, laundry, dishwaser, etc).
What are some of your ideas on implementing such a solution? Should I set up a local database on a desktop to record the data stream too and if so what DB should I use? If I set it up locally how do I display the data on a that same machine so I can see it in graph form similar to how do on thingspeak? Should I change by counter to data gathering every 20 seconds and only send data every 20 seconds to thingspeak. Then reset the counter bucket. Should implement some type of array to store the data in on the esp8266 and then average the values to send out to Thingspeak? If I do a local DB I shoud be able to record data every second correct?
Thank you for looking over this project and giving your feedback. I appreciate your time!
I am avoiding using delay by using millis() as much as possible. I am also grabbing time via the NTPclient.
I basically did the the following for counting cycle rate per min, below is written in Arduino IDE:
Link to Thingspeak public channel:
Code:
void pumpTimer() {
static byte sw1; //used for recording the pumpOn time only once and resets when pump goes off
pumpState=digitalRead(PUMP);
if(pumpState==HIGH) { //pump is on
//Serial.println ("PRESSED");
if (sw1==0){
pumpOn = currentMillis; //records time pump turned on
sw1=1; //bypass this on next loop through until pump turns off
}
}
else { //pump is off
//Serial.println ("NOT ON");
if (sw1==1){
pumpOff = currentMillis; //capture time pump turned off
pumpTime = pumpOff - pumpOn; //calculate pump runtime
sw1=0; //reset check bit
cycleCount++; //sketc lifetime counter
cyclesPerMinTemp++; //buket that is reset every 60 sec
cyclesPerHrTemp++; //bucket that is reset every 1 hour
if(pumpTime > maxCycle) {
maxCycle=pumpTime;
}
//set min and max cycle times
if(pumpTime < minCycle){
minCycle=pumpTime;
}
}
//if(mTimer==0) {
// cycleMTime=currentMillis;
// mTimer=1;
//}
}
//logic for minute and hour cycle counts
if (currentMillis - cycleMTime > 60000) {
//mTimer=0;
cyclesPerMin = cyclesPerMinTemp; //set bucket from temp bucket
cyclesPerMinTemp = 0; //reset temp bucket
cycleMTime=currentMillis; //record current time
if (currentMillis - cycleHTime > 360000) {
//mTimer=0;
cyclesPerHr = cyclesPerHrTemp;
cyclesPerHrTemp = 0;
cycleHTime=currentMillis;
}
}
}