@@ -173,11 +173,6 @@ void System::get_settings() {
173
173
// Board profile
174
174
board_profile_ = settings.board_profile ;
175
175
});
176
-
177
- EMSESP::esp8266React.getNetworkSettingsService ()->read ([&](NetworkSettings & networkSettings) {
178
- hostname (networkSettings.hostname .c_str ());
179
- LOG_INFO (F (" System %s booted (EMS-ESP version %s)" ), networkSettings.hostname .c_str (), EMSESP_APP_VERSION); // print boot message
180
- });
181
176
}
182
177
183
178
// adjust WiFi settings
@@ -207,6 +202,17 @@ void System::wifi_tweak() {
207
202
#endif
208
203
}
209
204
205
+ // check for valid ESP32 pins
206
+ // 1, 6-11, 12, 14 & 15 are not allowed
207
+ // we allow 0 (since its pulled high)
208
+ // See https://diyprojects.io/esp32-how-to-use-gpio-digital-io-arduino-code/#.YFpVEq9KhjG
209
+ bool System::is_valid_gpio (uint8_t pin) {
210
+ if ((pin == 1 ) || (pin >= 6 && pin <= 12 ) || (pin >= 14 && pin <= 15 )) {
211
+ return false ; // bad
212
+ }
213
+ return true ;
214
+ }
215
+
210
216
// first call. Sets memory and starts up the UART Serial bridge
211
217
void System::start (uint32_t heap_start) {
212
218
#if defined(EMSESP_DEBUG)
@@ -221,14 +227,19 @@ void System::start(uint32_t heap_start) {
221
227
// load in all the settings first
222
228
get_settings ();
223
229
230
+ EMSESP::esp8266React.getNetworkSettingsService ()->read ([&](NetworkSettings & networkSettings) {
231
+ hostname (networkSettings.hostname .c_str ());
232
+ LOG_INFO (F (" System %s booted (EMS-ESP version %s)" ), networkSettings.hostname .c_str (), EMSESP_APP_VERSION); // print boot message
233
+ });
234
+
224
235
commands_init (); // console & api commands
225
236
led_init (false ); // init LED
226
237
adc_init (false ); // analog ADC
227
238
syslog_init (false ); // init SysLog
228
239
button_init (false ); // the special button
229
240
network_init (false ); // network
230
241
231
- EMSESP::init_tx (); // start UART
242
+ EMSESP::init_uart (); // start UART
232
243
}
233
244
234
245
// adc and bluetooth
@@ -285,11 +296,14 @@ void System::button_init(bool refresh) {
285
296
get_settings ();
286
297
}
287
298
288
- // Allow 0 for Boot-button on NodeMCU-32s?
289
- if (!myPButton_.init (pbutton_gpio_, HIGH)) {
290
- LOG_INFO (F (" External multi-functional button not detected" ));
299
+ if (is_valid_gpio (pbutton_gpio_)) {
300
+ if (!myPButton_.init (pbutton_gpio_, HIGH)) {
301
+ LOG_INFO (F (" External multi-functional button not detected" ));
302
+ } else {
303
+ LOG_INFO (F (" External multi-functional button enabled" ));
304
+ }
291
305
} else {
292
- LOG_INFO (F (" External multi-functional button enabled " ));
306
+ LOG_WARNING (F (" Invalid button GPIO. Check config. " ));
293
307
}
294
308
295
309
myPButton_.onClick (BUTTON_Debounce, button_OnClick);
0 commit comments