Template
merging code
This commit is contained in:
@@ -48,6 +48,7 @@ DPRINTLN(); \
|
|||||||
#define PUMP_ON digitalWrite(PUMP_PIN,LOW)
|
#define PUMP_ON digitalWrite(PUMP_PIN,LOW)
|
||||||
#define PUMP_OFF digitalWrite(PUMP_PIN,HIGH)
|
#define PUMP_OFF digitalWrite(PUMP_PIN,HIGH)
|
||||||
|
|
||||||
|
// == water into the water heater = hot water demand when LOW
|
||||||
#define FLOW_PIN 11 // this is INT0
|
#define FLOW_PIN 11 // this is INT0
|
||||||
#define FLOWING digitalRead(FLOW_PIN)==LOW
|
#define FLOWING digitalRead(FLOW_PIN)==LOW
|
||||||
#define NOTFLOWING digitalRead(FLOW_PIN)==HIGH
|
#define NOTFLOWING digitalRead(FLOW_PIN)==HIGH
|
||||||
@@ -64,9 +65,6 @@ void flowstate();
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool notRun = true;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ticks are each 100mS so uint is 6553.5 seconds = 109.2 min
|
* ticks are each 100mS so uint is 6553.5 seconds = 109.2 min
|
||||||
* ticktime 32 bit 0.1sec rollover is 13 years
|
* ticktime 32 bit 0.1sec rollover is 13 years
|
||||||
@@ -84,6 +82,7 @@ unsigned long pumpstop_tc = 0;
|
|||||||
|
|
||||||
|
|
||||||
boolean flow = false;
|
boolean flow = false;
|
||||||
|
boolean flowOn = false;
|
||||||
boolean pump = false;
|
boolean pump = false;
|
||||||
boolean pumpOn = false;
|
boolean pumpOn = false;
|
||||||
boolean pumpRan = false;
|
boolean pumpRan = false;
|
||||||
@@ -100,7 +99,6 @@ volatile extern unsigned int ticknum;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void hotwater_setup() {
|
void hotwater_setup() {
|
||||||
pinMode(PUMP_PIN, OUTPUT);
|
pinMode(PUMP_PIN, OUTPUT);
|
||||||
pinMode(FLOW_PIN, INPUT_PULLUP);
|
pinMode(FLOW_PIN, INPUT_PULLUP);
|
||||||
@@ -176,7 +174,7 @@ void hotwater_loop () {
|
|||||||
flowstart_tc = 0; // reset
|
flowstart_tc = 0; // reset
|
||||||
}
|
}
|
||||||
intflag1_FLOW = false; // clear interrupt.
|
intflag1_FLOW = false; // clear interrupt.
|
||||||
if (DEBUG) Serial.println("flow interrupt");
|
DPRINTLN("flow interrupt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-25
@@ -28,14 +28,13 @@
|
|||||||
#endif /* SERIAL_DEBUGGING */
|
#endif /* SERIAL_DEBUGGING */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <ArduinoMqttClient.h>
|
#include <ArduinoMqttClient.h>
|
||||||
#include <Adafruit_SleepyDog.h>
|
#include <Adafruit_SleepyDog.h>
|
||||||
|
|
||||||
#include <WiFi101.h>
|
#include <WiFi101.h>
|
||||||
|
|
||||||
|
|
||||||
#include "arduino_secrets.h"
|
#include "arduino_secrets.h"
|
||||||
/////// sensitive data in arduino_secrets.h
|
/////// sensitive data in arduino_secrets.h
|
||||||
char ssid[] = SECRET_SSID;
|
char ssid[] = SECRET_SSID;
|
||||||
@@ -48,14 +47,10 @@ char pw[] = SECRET_PW;
|
|||||||
|
|
||||||
#define LED_PIN 13
|
#define LED_PIN 13
|
||||||
|
|
||||||
#define FLOW_PIN 11 // this is INT0
|
#define toggleLED digitalWrite(LED_PIN, !digitalRead(LED_PIN))
|
||||||
// == water into the water heater = hot water demand when LOW
|
|
||||||
|
|
||||||
#define RATE 10 // Hz == 100mS
|
#define RATE 10 // Hz == 100mS
|
||||||
|
|
||||||
#define FLOWING digitalRead(FLOW_PIN)==LOW
|
|
||||||
#define NOTFLOWING digitalRead(FLOW_PIN)==HIGH
|
|
||||||
|
|
||||||
|
|
||||||
void wifi_connect();
|
void wifi_connect();
|
||||||
void mqtt_connect();
|
void mqtt_connect();
|
||||||
@@ -84,6 +79,7 @@ volatile extern unsigned long ticktime; // timer interrupt
|
|||||||
volatile extern unsigned int ticknum; // wifi checked when this is > wifiTick
|
volatile extern unsigned int ticknum; // wifi checked when this is > wifiTick
|
||||||
|
|
||||||
extern boolean flow;
|
extern boolean flow;
|
||||||
|
extern boolean flowOn;
|
||||||
extern boolean pump;
|
extern boolean pump;
|
||||||
extern boolean pumpOn;
|
extern boolean pumpOn;
|
||||||
|
|
||||||
@@ -102,10 +98,6 @@ unsigned long lasttimestamp = 0;
|
|||||||
|
|
||||||
const unsigned int wifiTick = 100; //(interval/RATE);
|
const unsigned int wifiTick = 100; //(interval/RATE);
|
||||||
|
|
||||||
void toggleLED(){
|
|
||||||
digitalWrite(LED_PIN, isLEDOn);
|
|
||||||
isLEDOn = !isLEDOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mqtt_setup() {
|
void mqtt_setup() {
|
||||||
int countdownMS;
|
int countdownMS;
|
||||||
@@ -164,13 +156,13 @@ void mqtt_loop() {
|
|||||||
// record flow
|
// record flow
|
||||||
if (flow) {
|
if (flow) {
|
||||||
mqtt_connect();
|
mqtt_connect();
|
||||||
if (FLOWING) { // pin is LOW
|
if (flowOn) { // pin is LOW
|
||||||
flowstarted = WiFi.getTime();
|
flowstarted = WiFi.getTime();
|
||||||
mqttClient.beginMessage(topic);
|
mqttClient.beginMessage(topic);
|
||||||
mqttClient.print("start flow event@: ");
|
mqttClient.print("start flow event@: ");
|
||||||
DPRINT(flowstarted);
|
DPRINT(flowstarted);
|
||||||
DPRINTLN();
|
DPRINTLN();
|
||||||
mqttClient.print(WiFi.getTime());
|
mqttClient.print(flowstarted);
|
||||||
mqttClient.endMessage();
|
mqttClient.endMessage();
|
||||||
flow = false; // once is enough
|
flow = false; // once is enough
|
||||||
} else { // pin is HIGH
|
} else { // pin is HIGH
|
||||||
@@ -179,14 +171,14 @@ void mqtt_loop() {
|
|||||||
mqttClient.print("stop flow event@: ");
|
mqttClient.print("stop flow event@: ");
|
||||||
DPRINT(flowstopped);
|
DPRINT(flowstopped);
|
||||||
DPRINTLN();
|
DPRINTLN();
|
||||||
mqttClient.print(WiFi.getTime());
|
mqttClient.print(flowstopped);
|
||||||
mqttClient.endMessage();
|
mqttClient.endMessage();
|
||||||
}
|
}
|
||||||
mqttClient.stop();
|
mqttClient.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// process pump interrupt
|
// record pump activity
|
||||||
if (pump) {
|
if (pump) {
|
||||||
mqtt_connect();
|
mqtt_connect();
|
||||||
if (pumpOn) { // pin is LOW
|
if (pumpOn) { // pin is LOW
|
||||||
@@ -195,7 +187,7 @@ void mqtt_loop() {
|
|||||||
mqttClient.print("start pump event@: ");
|
mqttClient.print("start pump event@: ");
|
||||||
DPRINT(pumpstarted);
|
DPRINT(pumpstarted);
|
||||||
DPRINTLN();
|
DPRINTLN();
|
||||||
mqttClient.print(WiFi.getTime());
|
mqttClient.print(pumpstarted);
|
||||||
mqttClient.endMessage();
|
mqttClient.endMessage();
|
||||||
} else { // pin is HIGH
|
} else { // pin is HIGH
|
||||||
pumpstopped = WiFi.getTime();
|
pumpstopped = WiFi.getTime();
|
||||||
@@ -203,7 +195,7 @@ void mqtt_loop() {
|
|||||||
mqttClient.print("stop pump event@: ");
|
mqttClient.print("stop pump event@: ");
|
||||||
DPRINT(pumpstopped);
|
DPRINT(pumpstopped);
|
||||||
DPRINTLN();
|
DPRINTLN();
|
||||||
mqttClient.print(WiFi.getTime());
|
mqttClient.print(pumpstopped);
|
||||||
mqttClient.endMessage();
|
mqttClient.endMessage();
|
||||||
}
|
}
|
||||||
mqttClient.stop();
|
mqttClient.stop();
|
||||||
@@ -224,12 +216,7 @@ void mqtt_loop() {
|
|||||||
|
|
||||||
// blink LED @ 1Hz
|
// blink LED @ 1Hz
|
||||||
if ((ticktime % 10) == 0) {
|
if ((ticktime % 10) == 0) {
|
||||||
if (notToggled) { // ticks are every 100mS. only toggle ONCE
|
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
|
||||||
toggleLED();
|
|
||||||
notToggled = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
notToggled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -256,7 +243,7 @@ void wifi_connect() {
|
|||||||
DPRINT("!");
|
DPRINT("!");
|
||||||
for (int i=0; i<20; i++){ // 2 sec delay with 10hz blink
|
for (int i=0; i<20; i++){ // 2 sec delay with 10hz blink
|
||||||
delay(100);
|
delay(100);
|
||||||
toggleLED();
|
toggleLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,7 +259,7 @@ void mqtt_connect() {
|
|||||||
DPRINTLN(mqttClient.connectError());
|
DPRINTLN(mqttClient.connectError());
|
||||||
for (int i=0; i<10; i++){ // 2 sec delay with 5hz blink
|
for (int i=0; i<10; i++){ // 2 sec delay with 5hz blink
|
||||||
delay(200);
|
delay(200);
|
||||||
toggleLED();
|
toggleLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user