Skip to content

Commit 66df803

Browse files
committed
use gpio checker. wrong values will cause crash
1 parent 966f82e commit 66df803

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/emsesp.cpp

+28-20
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,28 @@ void EMSESP::watch_id(uint16_t watch_id) {
157157
watch_id_ = watch_id;
158158
}
159159

160-
// change the tx_mode
161160
// resets all counters and bumps the UART
162161
// this is called when the tx_mode is persisted in the FS either via Web UI or the console
163-
void EMSESP::init_tx() {
162+
void EMSESP::init_uart() {
164163
uint8_t tx_mode;
164+
uint8_t rx_gpio;
165+
uint8_t tx_gpio;
165166
EMSESP::webSettingsService.read([&](WebSettings & settings) {
166167
tx_mode = settings.tx_mode;
167168
tx_delay_ = settings.tx_delay * 1000;
168-
169-
EMSuart::stop();
170-
EMSuart::start(tx_mode, settings.rx_gpio, settings.tx_gpio);
169+
rx_gpio = settings.rx_gpio;
170+
tx_gpio = settings.tx_gpio;
171171
});
172172

173+
EMSuart::stop();
174+
175+
// don't start UART if we have invalid GPIOs
176+
if (System::is_valid_gpio(rx_gpio) && System::is_valid_gpio(tx_gpio)) {
177+
EMSuart::start(tx_mode, rx_gpio, tx_gpio); // start UART
178+
} else {
179+
LOG_WARNING(F("Invalid UART Rx/Tx GPIOs. Check config."));
180+
}
181+
173182
txservice_.start(); // sends out request to EMS bus for all devices
174183

175184
// force a fetch for all new values, unless Tx is set to off
@@ -1115,25 +1124,24 @@ void EMSESP::start() {
11151124
// main loop calling all services
11161125
void EMSESP::loop() {
11171126
esp8266React.loop(); // web
1127+
system_.loop(); // does LED and checks system health, and syslog service
11181128

11191129
// if we're doing an OTA upload, skip MQTT and EMS
1120-
if (system_.upload_status()) {
1121-
return;
1130+
if (!system_.upload_status()) {
1131+
rxservice_.loop(); // process any incoming Rx telegrams
1132+
shower_.loop(); // check for shower on/off
1133+
dallassensor_.loop(); // read dallas sensor temperatures
1134+
publish_all_loop(); // with HA messages in parts to avoid flooding the mqtt queue
1135+
mqtt_.loop(); // sends out anything in the MQTT queue
1136+
1137+
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
1138+
if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) {
1139+
last_fetch_ = uuid::get_uptime();
1140+
fetch_device_values();
1141+
}
11221142
}
11231143

1124-
system_.loop(); // does LED and checks system health, and syslog service
1125-
rxservice_.loop(); // process any incoming Rx telegrams
1126-
shower_.loop(); // check for shower on/off
1127-
dallassensor_.loop(); // read dallas sensor temperatures
1128-
publish_all_loop(); // with HA messages in parts to avoid flooding the mqtt queue
1129-
mqtt_.loop(); // sends out anything in the MQTT queue
1130-
console_.loop(); // telnet/serial console
1131-
1132-
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
1133-
if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) {
1134-
last_fetch_ = uuid::get_uptime();
1135-
fetch_device_values();
1136-
}
1144+
console_.loop(); // telnet/serial console
11371145

11381146
// delay(1); // helps telnet catch up. don't think its needed in ESP32 3.1.0
11391147
}

src/emsesp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class EMSESP {
113113
static void show_devices(uuid::console::Shell & shell);
114114
static void show_ems(uuid::console::Shell & shell);
115115

116-
static void init_tx();
116+
static void init_uart();
117117

118118
static void incoming_telegram(uint8_t * data, const uint8_t length);
119119

0 commit comments

Comments
 (0)