mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
added LED support optional
This commit is contained in:
@@ -27,7 +27,6 @@ void systemCheck();
|
|||||||
void publishValues();
|
void publishValues();
|
||||||
void _showerColdShotStart();
|
void _showerColdShotStart();
|
||||||
void _showerColdShotStop();
|
void _showerColdShotStop();
|
||||||
void _toggleHeartbeat();
|
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
Ticker publishValuesTimer;
|
Ticker publishValuesTimer;
|
||||||
@@ -44,12 +43,12 @@ Ticker showerResetTimer;
|
|||||||
// Project commands for telnet
|
// Project commands for telnet
|
||||||
// Note: ?, *, $, ! and & are reserved
|
// Note: ?, *, $, ! and & are reserved
|
||||||
#define PROJECT_CMDS \
|
#define PROJECT_CMDS \
|
||||||
"s=show statistics\n\r" \
|
"* s=show statistics\n\r" \
|
||||||
"* q=toggle Verbose telegram logging\n\r" \
|
|
||||||
"* P=publish stats to MQTT\n\r" \
|
"* P=publish stats to MQTT\n\r" \
|
||||||
"* p=toggle Poll response (for debugging)\n\r" \
|
"* v=Verbose mode on/off\n\r" \
|
||||||
"* T=toggle Thermostat suport on/off\n\r" \
|
"* p=Poll response on/off\n\r" \
|
||||||
"* S=toggle Shower Timer on/off\n\r" \
|
"* T=Thermostat Support on/off\n\r" \
|
||||||
|
"* S=Shower Timer on/off\n\r" \
|
||||||
"* r [n] to request for data from EMS, some examples:\n\r" \
|
"* r [n] to request for data from EMS, some examples:\n\r" \
|
||||||
"* from Boiler: 33=UBAParameterWW, 18=UBAMonitorFast, 19=UBAMonitorSlow, 34=UBAMonitorWWMessage\n\r" \
|
"* from Boiler: 33=UBAParameterWW, 18=UBAMonitorFast, 19=UBAMonitorSlow, 34=UBAMonitorWWMessage\n\r" \
|
||||||
"* from Thermostat: 91=RC20StatusMessage, A8=RC20Temperature, 6=RC20Time, 2=Version\n\r" \
|
"* from Thermostat: 91=RC20StatusMessage, A8=RC20Temperature, 6=RC20Time, 2=Version\n\r" \
|
||||||
@@ -62,6 +61,7 @@ Ticker showerResetTimer;
|
|||||||
#define LED_RX D1 // (GPIO5 on nodemcu)
|
#define LED_RX D1 // (GPIO5 on nodemcu)
|
||||||
#define LED_TX D2 // (GPIO4 on nodemcu)
|
#define LED_TX D2 // (GPIO4 on nodemcu)
|
||||||
#define LED_ERR D3 // (GPIO0 on nodemcu)
|
#define LED_ERR D3 // (GPIO0 on nodemcu)
|
||||||
|
#define LED_HEARTBEAT LED_BUILTIN // onboard LED
|
||||||
|
|
||||||
// app specific - do not change
|
// app specific - do not change
|
||||||
#define MQTT_BOILER MQTT_BASE HOSTNAME "/"
|
#define MQTT_BOILER MQTT_BASE HOSTNAME "/"
|
||||||
@@ -120,10 +120,8 @@ _Boiler_Shower Boiler_Shower;
|
|||||||
// Debugger to telnet
|
// Debugger to telnet
|
||||||
#define myDebug(x, ...) myESP.printf(x, ##__VA_ARGS__);
|
#define myDebug(x, ...) myESP.printf(x, ##__VA_ARGS__);
|
||||||
|
|
||||||
// Timers
|
// Times
|
||||||
const unsigned long POLL_TIMEOUT_ERR = 10000; // if no signal from boiler for last 10 seconds, assume its offline
|
const unsigned long POLL_TIMEOUT_ERR = 10000; // if no signal from boiler for last 10 seconds, assume its offline
|
||||||
bool heartbeatEnabled = false;
|
|
||||||
|
|
||||||
const unsigned long TX_HOLD_LED_TIME = 2000; // how long to hold the Tx LED because its so quick
|
const unsigned long TX_HOLD_LED_TIME = 2000; // how long to hold the Tx LED because its so quick
|
||||||
|
|
||||||
unsigned long timestamp; // for internal timings, via millis()
|
unsigned long timestamp; // for internal timings, via millis()
|
||||||
@@ -331,8 +329,9 @@ void myDebugCallback() {
|
|||||||
case 'w': // set warm water temp
|
case 'w': // set warm water temp
|
||||||
ems_setWarmWaterTemp((uint8_t)strtol(&cmd[2], 0, 10));
|
ems_setWarmWaterTemp((uint8_t)strtol(&cmd[2], 0, 10));
|
||||||
break;
|
break;
|
||||||
case 'q': // quiet
|
case 'v': // verbose
|
||||||
_toggleHeartbeat();
|
b = !ems_getLogVerbose();
|
||||||
|
ems_setLogVerbose(b);
|
||||||
break;
|
break;
|
||||||
case 'a': // set ww activate on or off
|
case 'a': // set ww activate on or off
|
||||||
if ((cmd[2] - '0') == 1)
|
if ((cmd[2] - '0') == 1)
|
||||||
@@ -355,14 +354,6 @@ void myDebugCallback() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// toggle heartbeat LED
|
|
||||||
void _toggleHeartbeat() {
|
|
||||||
bool b = !ems_getLogVerbose();
|
|
||||||
ems_setLogVerbose(b);
|
|
||||||
heartbeatEnabled = b;
|
|
||||||
digitalWrite(LED_BUILTIN, (b) ? LOW : HIGH); // set the LED
|
|
||||||
}
|
|
||||||
|
|
||||||
// MQTT Callback to handle incoming/outgoing changes
|
// MQTT Callback to handle incoming/outgoing changes
|
||||||
void MQTTcallback(char * topic, byte * payload, uint8_t length) {
|
void MQTTcallback(char * topic, byte * payload, uint8_t length) {
|
||||||
// check if start is received, if so return boottime - defined in ESPHelper.h
|
// check if start is received, if so return boottime - defined in ESPHelper.h
|
||||||
@@ -387,10 +378,13 @@ void MQTTcallback(char * topic, byte * payload, uint8_t length) {
|
|||||||
void WIFIcallback() {
|
void WIFIcallback() {
|
||||||
Boiler_Status.wifi_connected = true;
|
Boiler_Status.wifi_connected = true;
|
||||||
|
|
||||||
|
#ifdef USE_LED
|
||||||
// turn off the LEDs since we've finished the boot loading
|
// turn off the LEDs since we've finished the boot loading
|
||||||
digitalWrite(LED_RX, LOW);
|
digitalWrite(LED_RX, LOW);
|
||||||
digitalWrite(LED_TX, LOW);
|
digitalWrite(LED_TX, LOW);
|
||||||
digitalWrite(LED_ERR, LOW);
|
digitalWrite(LED_ERR, LOW);
|
||||||
|
digitalWrite(LED_HEARTBEAT, HIGH);
|
||||||
|
#endif
|
||||||
|
|
||||||
// when finally we're all set up, we can fire up the uart (this will enable the interrupts)
|
// when finally we're all set up, we can fire up the uart (this will enable the interrupts)
|
||||||
emsuart_init();
|
emsuart_init();
|
||||||
@@ -421,18 +415,22 @@ void _initBoiler() {
|
|||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
// set pin for LEDs - start up with all lit up while we sort stuff out
|
// set pin for LEDs - start up with all lit up while we sort stuff out
|
||||||
|
|
||||||
|
#ifdef USE_LED
|
||||||
pinMode(LED_RX, OUTPUT);
|
pinMode(LED_RX, OUTPUT);
|
||||||
pinMode(LED_TX, OUTPUT);
|
pinMode(LED_TX, OUTPUT);
|
||||||
pinMode(LED_ERR, OUTPUT);
|
pinMode(LED_ERR, OUTPUT);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_HEARTBEAT, OUTPUT);
|
||||||
digitalWrite(LED_RX, HIGH);
|
digitalWrite(LED_RX, HIGH);
|
||||||
digitalWrite(LED_TX, HIGH);
|
digitalWrite(LED_TX, HIGH);
|
||||||
digitalWrite(LED_ERR, HIGH);
|
digitalWrite(LED_ERR, HIGH);
|
||||||
|
digitalWrite(LED_HEARTBEAT, HIGH); // onboard LED is off
|
||||||
|
heartbeatTimer.attach(heartbeatTime, heartbeat); // blink heartbeat LED
|
||||||
|
#endif
|
||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
publishValuesTimer.attach(publishValuesTime, publishValues); // post HA values
|
publishValuesTimer.attach(publishValuesTime, publishValues); // post HA values
|
||||||
systemCheckTimer.attach(systemCheckTime, systemCheck); // check if Boiler is online
|
systemCheckTimer.attach(systemCheckTime, systemCheck); // check if Boiler is online
|
||||||
heartbeatTimer.attach(heartbeatTime, heartbeat); // blink heartbeat LED
|
|
||||||
|
|
||||||
// set up Wifi, MQTT, Telnet
|
// set up Wifi, MQTT, Telnet
|
||||||
myESP.setWifiCallback(WIFIcallback);
|
myESP.setWifiCallback(WIFIcallback);
|
||||||
@@ -450,15 +448,11 @@ void setup() {
|
|||||||
|
|
||||||
// init Boiler specific params
|
// init Boiler specific params
|
||||||
_initBoiler();
|
_initBoiler();
|
||||||
|
|
||||||
// heartbeat, only if setting is enabled
|
|
||||||
heartbeatEnabled = ems_getLogVerbose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// flash LEDs
|
// flash LEDs
|
||||||
// Using a faster way to write to pins as digitalWrite does a lot of overhead like pin checking & disabling interrupts
|
// Using a faster way to write to pins as digitalWrite does a lot of overhead like pin checking & disabling interrupts
|
||||||
void showLEDs() {
|
void showLEDs() {
|
||||||
if (ems_getLogVerbose()) {
|
|
||||||
// ERR LED
|
// ERR LED
|
||||||
if (!Boiler_Status.boiler_online) {
|
if (!Boiler_Status.boiler_online) {
|
||||||
WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + 4, (1 << LED_ERR)); // turn on
|
WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + 4, (1 << LED_ERR)); // turn on
|
||||||
@@ -475,15 +469,12 @@ void showLEDs() {
|
|||||||
// because sends are quick, if we did a recent send show the LED for a short while
|
// because sends are quick, if we did a recent send show the LED for a short while
|
||||||
uint64_t t = (timestamp - EMS_Sys_Status.emsLastTx);
|
uint64_t t = (timestamp - EMS_Sys_Status.emsLastTx);
|
||||||
WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + ((t < TX_HOLD_LED_TIME) ? 4 : 8), (1 << LED_TX));
|
WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + ((t < TX_HOLD_LED_TIME) ? 4 : 8), (1 << LED_TX));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// heartbeat callback to light up the LED, called via Ticker
|
// heartbeat callback to light up the LED, called via Ticker
|
||||||
void heartbeat() {
|
void heartbeat() {
|
||||||
if (heartbeatEnabled) {
|
int state = digitalRead(LED_HEARTBEAT);
|
||||||
int state = digitalRead(LED_BUILTIN);
|
digitalWrite(LED_HEARTBEAT, !state);
|
||||||
digitalWrite(LED_BUILTIN, !state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// do a healthcheck every now and then to see if we connections
|
// do a healthcheck every now and then to see if we connections
|
||||||
@@ -524,8 +515,10 @@ void loop() {
|
|||||||
connectionStatus = myESP.loop();
|
connectionStatus = myESP.loop();
|
||||||
timestamp = millis();
|
timestamp = millis();
|
||||||
|
|
||||||
// update the Rx Tx and ERR LEDs
|
// update the Rx Tx and ERR LEDs
|
||||||
|
#ifdef USE_LED
|
||||||
showLEDs();
|
showLEDs();
|
||||||
|
#endif
|
||||||
|
|
||||||
// do not continue unless we have a wifi connection
|
// do not continue unless we have a wifi connection
|
||||||
if (connectionStatus < WIFI_ONLY) {
|
if (connectionStatus < WIFI_ONLY) {
|
||||||
|
|||||||
Reference in New Issue
Block a user