@@ -157,19 +157,28 @@ void EMSESP::watch_id(uint16_t watch_id) {
157
157
watch_id_ = watch_id;
158
158
}
159
159
160
- // change the tx_mode
161
160
// resets all counters and bumps the UART
162
161
// 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 () {
164
163
uint8_t tx_mode;
164
+ uint8_t rx_gpio;
165
+ uint8_t tx_gpio;
165
166
EMSESP::webSettingsService.read ([&](WebSettings & settings) {
166
167
tx_mode = settings.tx_mode ;
167
168
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 ;
171
171
});
172
172
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
+
173
182
txservice_.start (); // sends out request to EMS bus for all devices
174
183
175
184
// force a fetch for all new values, unless Tx is set to off
@@ -1115,25 +1124,24 @@ void EMSESP::start() {
1115
1124
// main loop calling all services
1116
1125
void EMSESP::loop () {
1117
1126
esp8266React.loop (); // web
1127
+ system_.loop (); // does LED and checks system health, and syslog service
1118
1128
1119
1129
// 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
+ }
1122
1142
}
1123
1143
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
1137
1145
1138
1146
// delay(1); // helps telnet catch up. don't think its needed in ESP32 3.1.0
1139
1147
}
0 commit comments