Add a keepalive signal
This commit is contained in:
parent
c221206571
commit
d973fe865d
1 changed files with 6 additions and 2 deletions
|
@ -7,6 +7,7 @@ int16_t idleValue = 0;
|
|||
int16_t sensorValue = 0;
|
||||
int8_t cutOffThreshold = cutOffTime;
|
||||
int16_t cooldownRemaining = 0;
|
||||
int16_t keepAliveRemaining = 0;
|
||||
ESP8266WiFiMulti wifi;
|
||||
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
||||
|
||||
|
@ -46,9 +47,9 @@ void loop() {
|
|||
delay(loopTime*1000);
|
||||
|
||||
// Callibrate the idle value
|
||||
if (idleValue == 0) {
|
||||
if (idleValue == 0 || keepAliveRemaining == 0) {
|
||||
if (DEBUG) Serial.println("Calibrate ...");
|
||||
uint16_t samples;
|
||||
uint16_t samples = 0;
|
||||
for (uint8_t i=0; i<30; i++) {
|
||||
samples += analogRead(A0);
|
||||
digitalWrite(D2, !digitalRead(D2));
|
||||
|
@ -56,9 +57,12 @@ void loop() {
|
|||
}
|
||||
|
||||
idleValue = round(samples / 30);
|
||||
keepAliveRemaining = keepAliveSignalTime;
|
||||
if (DEBUG) Serial.println("Idle value: " + String(idleValue));
|
||||
influxdb.write("pump-action idle_value=" + String(idleValue));
|
||||
digitalWrite(D2, HIGH);
|
||||
}
|
||||
keepAliveRemaining -= 1;
|
||||
|
||||
// Need to cutoff the power to the pump?
|
||||
if (cutOffThreshold <= 0) {
|
||||
|
|
Loading…
Reference in a new issue