mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
board profiles: pre-configured pin layouts #11
This commit is contained in:
2
makefile
2
makefile
@@ -33,7 +33,7 @@ CXX_STANDARD := -std=c++11
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Defined Symbols
|
# Defined Symbols
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
DEFINES += -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST
|
DEFINES += -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST -DEMSESP_DEFAULT_BOARD_PROFILE=\"LOLIN\"
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
# Sources & Files
|
# Sources & Files
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
; example custom platformio.ini file for EMS-ESP
|
||||||
|
;
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_flags =
|
upload_flags =
|
||||||
@@ -8,7 +11,7 @@ upload_port = 10.10.10.101
|
|||||||
[common]
|
[common]
|
||||||
; debug_flags = -DENABLE_CORS -DEMSESP_TEST
|
; debug_flags = -DENABLE_CORS -DEMSESP_TEST
|
||||||
; debug_flags = -DEMSESP_DEBUG -DEMSESP_TEST
|
; debug_flags = -DEMSESP_DEBUG -DEMSESP_TEST
|
||||||
debug_flags = -DEMSESP_TEST
|
; debug_flags = -DEMSESP_DEFAULT_BOARD_PROFILE=\"LOLIN\"
|
||||||
|
|
||||||
[env:esp32]
|
[env:esp32]
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
|
|||||||
@@ -60,7 +60,28 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
|
|||||||
root["board_profile"] = settings.board_profile;
|
root["board_profile"] = settings.board_profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// call on initialization and also when settings are updated via web or console
|
||||||
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
|
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
|
||||||
|
// set or load board profile
|
||||||
|
settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE;
|
||||||
|
|
||||||
|
// load default GPIO configuration based on board profile
|
||||||
|
std::vector<uint8_t> data; // led, dallas, rx, tx, button
|
||||||
|
if (!System::load_board_profile(data, settings.board_profile.c_str())) {
|
||||||
|
// invalid board configuration, override the default in case it has been misspelled
|
||||||
|
settings.board_profile = "S32";
|
||||||
|
}
|
||||||
|
uint8_t default_led_gpio = data[0];
|
||||||
|
uint8_t default_dallas_gpio = data[1];
|
||||||
|
uint8_t default_rx_gpio = data[2];
|
||||||
|
uint8_t default_tx_gpio = data[3];
|
||||||
|
uint8_t default_pbutton_gpio = data[4];
|
||||||
|
|
||||||
|
// check to see if we have a settings file, if not it's a fresh install
|
||||||
|
if (!root.size()) {
|
||||||
|
EMSESP::logger().info(F("Initializing configuration with board profile %s"), settings.board_profile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
int prev;
|
int prev;
|
||||||
reset_flags();
|
reset_flags();
|
||||||
|
|
||||||
@@ -72,10 +93,10 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
settings.tx_delay = root["tx_delay"] | EMSESP_DEFAULT_TX_DELAY;
|
settings.tx_delay = root["tx_delay"] | EMSESP_DEFAULT_TX_DELAY;
|
||||||
check_flag(prev, settings.tx_delay, ChangeFlags::UART);
|
check_flag(prev, settings.tx_delay, ChangeFlags::UART);
|
||||||
prev = settings.rx_gpio;
|
prev = settings.rx_gpio;
|
||||||
settings.rx_gpio = root["rx_gpio"] | EMSESP_DEFAULT_RX_GPIO;
|
settings.rx_gpio = root["rx_gpio"] | default_rx_gpio;
|
||||||
check_flag(prev, settings.rx_gpio, ChangeFlags::UART);
|
check_flag(prev, settings.rx_gpio, ChangeFlags::UART);
|
||||||
prev = settings.tx_gpio;
|
prev = settings.tx_gpio;
|
||||||
settings.tx_gpio = root["tx_gpio"] | EMSESP_DEFAULT_TX_GPIO;
|
settings.tx_gpio = root["tx_gpio"] | default_tx_gpio;
|
||||||
check_flag(prev, settings.tx_gpio, ChangeFlags::UART);
|
check_flag(prev, settings.tx_gpio, ChangeFlags::UART);
|
||||||
|
|
||||||
// syslog
|
// syslog
|
||||||
@@ -93,12 +114,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
|
|
||||||
String old_syslog_host = settings.syslog_host;
|
String old_syslog_host = settings.syslog_host;
|
||||||
settings.syslog_host = root["syslog_host"] | EMSESP_DEFAULT_SYSLOG_HOST;
|
settings.syslog_host = root["syslog_host"] | EMSESP_DEFAULT_SYSLOG_HOST;
|
||||||
|
if (old_syslog_host.equals(settings.syslog_host.c_str())) {
|
||||||
#ifndef EMSESP_STANDALONE
|
|
||||||
if (old_syslog_host.equals(settings.syslog_host)) {
|
|
||||||
add_flags(ChangeFlags::SYSLOG);
|
add_flags(ChangeFlags::SYSLOG);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
prev = settings.syslog_port;
|
prev = settings.syslog_port;
|
||||||
settings.syslog_port = root["syslog_port"] | EMSESP_DEFAULT_SYSLOG_PORT;
|
settings.syslog_port = root["syslog_port"] | EMSESP_DEFAULT_SYSLOG_PORT;
|
||||||
@@ -116,12 +134,12 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
|
|
||||||
// button
|
// button
|
||||||
prev = settings.pbutton_gpio;
|
prev = settings.pbutton_gpio;
|
||||||
settings.pbutton_gpio = root["pbutton_gpio"] | EMSESP_DEFAULT_PBUTTON_GPIO;
|
settings.pbutton_gpio = root["pbutton_gpio"] | default_pbutton_gpio;
|
||||||
check_flag(prev, settings.pbutton_gpio, ChangeFlags::BUTTON);
|
check_flag(prev, settings.pbutton_gpio, ChangeFlags::BUTTON);
|
||||||
|
|
||||||
// dallas
|
// dallas
|
||||||
prev = settings.dallas_gpio;
|
prev = settings.dallas_gpio;
|
||||||
settings.dallas_gpio = root["dallas_gpio"] | EMSESP_DEFAULT_DALLAS_GPIO;
|
settings.dallas_gpio = root["dallas_gpio"] | default_dallas_gpio;
|
||||||
check_flag(prev, settings.dallas_gpio, ChangeFlags::DALLAS);
|
check_flag(prev, settings.dallas_gpio, ChangeFlags::DALLAS);
|
||||||
prev = settings.dallas_parasite;
|
prev = settings.dallas_parasite;
|
||||||
settings.dallas_parasite = root["dallas_parasite"] | EMSESP_DEFAULT_DALLAS_PARASITE;
|
settings.dallas_parasite = root["dallas_parasite"] | EMSESP_DEFAULT_DALLAS_PARASITE;
|
||||||
@@ -137,7 +155,7 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
|
|
||||||
// led
|
// led
|
||||||
prev = settings.led_gpio;
|
prev = settings.led_gpio;
|
||||||
settings.led_gpio = root["led_gpio"] | EMSESP_DEFAULT_LED_GPIO;
|
settings.led_gpio = root["led_gpio"] | default_led_gpio;
|
||||||
check_flag(prev, settings.led_gpio, ChangeFlags::LED);
|
check_flag(prev, settings.led_gpio, ChangeFlags::LED);
|
||||||
prev = settings.hide_led;
|
prev = settings.hide_led;
|
||||||
settings.hide_led = root["hide_led"] | EMSESP_DEFAULT_HIDE_LED;
|
settings.hide_led = root["hide_led"] | EMSESP_DEFAULT_HIDE_LED;
|
||||||
@@ -150,9 +168,6 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
// doesn't need any follow-up actions
|
// doesn't need any follow-up actions
|
||||||
settings.api_enabled = root["api_enabled"] | EMSESP_DEFAULT_API_ENABLED;
|
settings.api_enabled = root["api_enabled"] | EMSESP_DEFAULT_API_ENABLED;
|
||||||
|
|
||||||
// board profiles
|
|
||||||
settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE;
|
|
||||||
|
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,24 +43,18 @@
|
|||||||
#define EMSESP_DEFAULT_API_ENABLED false // turn off, because its insecure
|
#define EMSESP_DEFAULT_API_ENABLED false // turn off, because its insecure
|
||||||
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
|
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
|
||||||
#define EMSESP_DEFAULT_ANALOG_ENABLED false
|
#define EMSESP_DEFAULT_ANALOG_ENABLED false
|
||||||
#define EMSESP_DEFAULT_BOARD_PROFILE "S32"
|
|
||||||
|
|
||||||
// Default GPIO PIN definitions
|
#ifndef EMSESP_DEFAULT_BOARD_PROFILE
|
||||||
#if defined(ESP32)
|
#define EMSESP_DEFAULT_BOARD_PROFILE "S32" // Gateway S32
|
||||||
#define EMSESP_DEFAULT_RX_GPIO 23 // D7 on Wemos D1-32, OR 17 for UART2 on Lolin D32
|
|
||||||
#define EMSESP_DEFAULT_TX_GPIO 5 // D8 on Wemos D1-32, OR 16 for UART2 on Lolin D32
|
|
||||||
#define EMSESP_DEFAULT_DALLAS_GPIO 18 // 18 on Wemos D1-32, 14 on LOLIN D32
|
|
||||||
#define EMSESP_DEFAULT_LED_GPIO 2 // 2 on Wemos D1-32, 5 on LOLIN D32
|
|
||||||
#define EMSESP_DEFAULT_PBUTTON_GPIO 0 // default GPIO is 0 (off)
|
|
||||||
#else
|
|
||||||
// for standalone
|
|
||||||
#define EMSESP_DEFAULT_RX_GPIO 0
|
|
||||||
#define EMSESP_DEFAULT_TX_GPIO 0
|
|
||||||
#define EMSESP_DEFAULT_DALLAS_GPIO 0
|
|
||||||
#define EMSESP_DEFAULT_LED_GPIO 0
|
|
||||||
#define EMSESP_DEFAULT_PBUTTON_GPIO 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Default GPIO PIN definitions - based on Wemos/Nodemcu
|
||||||
|
#define EMSESP_DEFAULT_RX_GPIO 23 // D7
|
||||||
|
#define EMSESP_DEFAULT_TX_GPIO 5 // D8
|
||||||
|
#define EMSESP_DEFAULT_DALLAS_GPIO 18
|
||||||
|
#define EMSESP_DEFAULT_LED_GPIO 2
|
||||||
|
#define EMSESP_DEFAULT_PBUTTON_GPIO 0
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
class WebSettings {
|
class WebSettings {
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ std::string EMSESPStreamConsole::console_name() {
|
|||||||
// Log order is off, err, warning, notice, info, debug, trace, all
|
// Log order is off, err, warning, notice, info, debug, trace, all
|
||||||
void Console::start() {
|
void Console::start() {
|
||||||
shell = std::make_shared<EMSESPStreamConsole>(Serial, true);
|
shell = std::make_shared<EMSESPStreamConsole>(Serial, true);
|
||||||
shell->maximum_log_messages(100); // default is 50
|
shell->maximum_log_messages(100); // default was 50
|
||||||
shell->start();
|
shell->start();
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
@@ -623,8 +623,7 @@ void Console::start() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(EMSESP_STANDALONE)
|
#if defined(EMSESP_STANDALONE)
|
||||||
// always start in su/admin mode when running tests
|
shell->add_flags(CommandFlags::ADMIN); // always start in su/admin mode when running tests
|
||||||
shell->add_flags(CommandFlags::ADMIN);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start the telnet service
|
// start the telnet service
|
||||||
|
|||||||
@@ -1090,13 +1090,12 @@ void EMSESP::start() {
|
|||||||
// start the file system
|
// start the file system
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
if (!LITTLEFS.begin(true)) {
|
if (!LITTLEFS.begin(true)) {
|
||||||
Serial.println("LITTLEFS Mount Failed");
|
Serial.println("LITTLEFS Mount Failed. EMS-ESP stopped.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
esp8266React.begin(); // loads system settings (wifi, mqtt, etc)
|
esp8266React.begin(); // loads system settings (wifi, mqtt, etc)
|
||||||
webSettingsService.begin(); // load EMS-ESP specific settings
|
|
||||||
|
|
||||||
system_.check_upgrade(); // do any upgrades
|
system_.check_upgrade(); // do any upgrades
|
||||||
|
|
||||||
@@ -1105,7 +1104,10 @@ void EMSESP::start() {
|
|||||||
#include "device_library.h"
|
#include "device_library.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
console_.start(); // telnet and serial console
|
console_.start(); // telnet and serial console
|
||||||
|
|
||||||
|
webSettingsService.begin(); // load EMS-ESP specific settings, like GPIO configurations
|
||||||
|
|
||||||
mqtt_.start(); // mqtt init
|
mqtt_.start(); // mqtt init
|
||||||
system_.start(heap_start); // starts syslog, uart, sets version, initializes LED. Requires pre-loaded settings.
|
system_.start(heap_start); // starts syslog, uart, sets version, initializes LED. Requires pre-loaded settings.
|
||||||
shower_.start(); // initialize shower timer and shower alert
|
shower_.start(); // initialize shower timer and shower alert
|
||||||
|
|||||||
@@ -230,11 +230,9 @@ void System::start(uint32_t heap_start) {
|
|||||||
|
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||||
hostname(networkSettings.hostname.c_str());
|
hostname(networkSettings.hostname.c_str());
|
||||||
LOG_INFO(F("System %s booted (EMS-ESP version %s)"), networkSettings.hostname.c_str(), EMSESP_APP_VERSION); // print boot message
|
LOG_INFO(F("System %s booted (EMS-ESP version %s) "), networkSettings.hostname.c_str(), EMSESP_APP_VERSION); // print boot message
|
||||||
});
|
});
|
||||||
|
|
||||||
LOG_INFO("Loaded Board profile: %s", board_profile_.c_str());
|
|
||||||
|
|
||||||
commands_init(); // console & api commands
|
commands_init(); // console & api commands
|
||||||
led_init(false); // init LED
|
led_init(false); // init LED
|
||||||
adc_init(false); // analog ADC
|
adc_init(false); // analog ADC
|
||||||
@@ -833,14 +831,12 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
flash_string_vector{F_(set), F_(board_profile)},
|
flash_string_vector{F_(set), F_(board_profile)},
|
||||||
flash_string_vector{F_(name_mandatory)},
|
flash_string_vector{F_(name_mandatory)},
|
||||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
// check for valid profile
|
|
||||||
std::vector<uint8_t> data; // led, dallas, rx, tx, button
|
std::vector<uint8_t> data; // led, dallas, rx, tx, button
|
||||||
std::string board_profile = Helpers::toUpper(arguments.front());
|
std::string board_profile = Helpers::toUpper(arguments.front());
|
||||||
if (!load_board_profile(data, board_profile)) {
|
if (!load_board_profile(data, board_profile)) {
|
||||||
shell.println(F("Invalid board profile"));
|
shell.println(F("Invalid board profile"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
shell.printfln("Loaded board profile %s with %d,%d,%d,%d,%d", board_profile.c_str(), data[0], data[1], data[2], data[3], data[4]);
|
|
||||||
EMSESP::webSettingsService.update(
|
EMSESP::webSettingsService.update(
|
||||||
[&](WebSettings & settings) {
|
[&](WebSettings & settings) {
|
||||||
settings.board_profile = board_profile.c_str();
|
settings.board_profile = board_profile.c_str();
|
||||||
@@ -1040,6 +1036,7 @@ bool System::command_test(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// takes a board profile and populates a data array with GPIO configurations
|
// takes a board profile and populates a data array with GPIO configurations
|
||||||
// data = led, dallas, rx, tx, button
|
// data = led, dallas, rx, tx, button
|
||||||
|
// returns false if profile is not found, and uses default
|
||||||
bool System::load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile) {
|
bool System::load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile) {
|
||||||
if (board_profile == "S32") {
|
if (board_profile == "S32") {
|
||||||
data = {2, 3, 23, 5, 0}; // Gateway S32
|
data = {2, 3, 23, 5, 0}; // Gateway S32
|
||||||
@@ -1058,6 +1055,7 @@ bool System::load_board_profile(std::vector<uint8_t> & data, const std::string &
|
|||||||
} else if (board_profile == "TLK110") {
|
} else if (board_profile == "TLK110") {
|
||||||
data = {2, 4, 5, 17, 33}; // Ethernet (TLK110)
|
data = {2, 4, 5, 17, 33}; // Ethernet (TLK110)
|
||||||
} else {
|
} else {
|
||||||
|
data = {EMSESP_DEFAULT_LED_GPIO, EMSESP_DEFAULT_DALLAS_GPIO, EMSESP_DEFAULT_RX_GPIO, EMSESP_DEFAULT_TX_GPIO, EMSESP_DEFAULT_PBUTTON_GPIO};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user