mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
set system command set ethernet <profile>
This commit is contained in:
@@ -68,6 +68,7 @@ MAKE_PSTR_WORD(master)
|
|||||||
MAKE_PSTR_WORD(pin)
|
MAKE_PSTR_WORD(pin)
|
||||||
MAKE_PSTR_WORD(publish)
|
MAKE_PSTR_WORD(publish)
|
||||||
MAKE_PSTR_WORD(timeout)
|
MAKE_PSTR_WORD(timeout)
|
||||||
|
MAKE_PSTR_WORD(ethernet)
|
||||||
|
|
||||||
// for commands
|
// for commands
|
||||||
MAKE_PSTR_WORD(call)
|
MAKE_PSTR_WORD(call)
|
||||||
@@ -102,7 +103,7 @@ MAKE_PSTR(hostname_fmt, "Hostname = %s")
|
|||||||
MAKE_PSTR(mark_interval_fmt, "Mark interval = %lus")
|
MAKE_PSTR(mark_interval_fmt, "Mark interval = %lus")
|
||||||
MAKE_PSTR(wifi_ssid_fmt, "WiFi SSID = %s")
|
MAKE_PSTR(wifi_ssid_fmt, "WiFi SSID = %s")
|
||||||
MAKE_PSTR(wifi_password_fmt, "WiFi Password = %S")
|
MAKE_PSTR(wifi_password_fmt, "WiFi Password = %S")
|
||||||
MAKE_PSTR(mqtt_heartbeat_fmt, "MQTT Heartbeat is %s")
|
MAKE_PSTR(ethernet_option_fmt, "Ethernet option = %d")
|
||||||
MAKE_PSTR(cmd_optional, "[cmd]")
|
MAKE_PSTR(cmd_optional, "[cmd]")
|
||||||
MAKE_PSTR(ha_optional, "[ha]")
|
MAKE_PSTR(ha_optional, "[ha]")
|
||||||
MAKE_PSTR(deep_optional, "[deep]")
|
MAKE_PSTR(deep_optional, "[deep]")
|
||||||
|
|||||||
@@ -196,7 +196,8 @@ void System::start(uint32_t heap_start) {
|
|||||||
adc_init(false); // analog ADC
|
adc_init(false); // analog ADC
|
||||||
syslog_init(false); // init SysLog
|
syslog_init(false); // init SysLog
|
||||||
button_init(false); // the special button
|
button_init(false); // the special button
|
||||||
network_init(); // network
|
network_init(false); // network
|
||||||
|
|
||||||
EMSESP::init_tx(); // start UART
|
EMSESP::init_tx(); // start UART
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,8 +419,13 @@ void System::set_led_speed(uint32_t speed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initializes network
|
// initializes network
|
||||||
void System::network_init() {
|
void System::network_init(bool refresh) {
|
||||||
// check ethernet profile, if we're using exclusive Ethernet then disabled wifi and AP/captive portal
|
if (refresh) {
|
||||||
|
get_settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check ethernet profile
|
||||||
|
// ethernet uses lots of additional memory so we only start it when it's explicitly set in the config
|
||||||
if (ethernet_profile_ == 0) {
|
if (ethernet_profile_ == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -451,7 +457,7 @@ void System::network_init() {
|
|||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
if (ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode)) {
|
if (ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode)) {
|
||||||
// disable ssid and AP
|
// disable ssid and AP when using Ethernet
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->update(
|
EMSESP::esp8266React.getNetworkSettingsService()->update(
|
||||||
[&](NetworkSettings & settings) {
|
[&](NetworkSettings & settings) {
|
||||||
settings.ssid == ""; // remove SSID
|
settings.ssid == ""; // remove SSID
|
||||||
@@ -506,8 +512,8 @@ void System::system_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// commands - takes static function pointers
|
// commands - takes static function pointers
|
||||||
void System::commands_init() {
|
|
||||||
// these commands respond to the topic "system" and take a payload like {cmd:"", data:"", id:""}
|
// these commands respond to the topic "system" and take a payload like {cmd:"", data:"", id:""}
|
||||||
|
void System::commands_init() {
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(pin), System::command_pin);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(pin), System::command_pin);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send);
|
||||||
Command::add(EMSdevice::DeviceType::SYSTEM, F_(publish), System::command_publish);
|
Command::add(EMSdevice::DeviceType::SYSTEM, F_(publish), System::command_publish);
|
||||||
@@ -759,17 +765,40 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EMSESPShell::commands->add_command(
|
||||||
|
ShellContext::SYSTEM,
|
||||||
|
CommandFlags::ADMIN,
|
||||||
|
flash_string_vector{F_(set), F_(ethernet)},
|
||||||
|
flash_string_vector{F_(n_mandatory)},
|
||||||
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
|
uint8_t n = Helpers::hextoint(arguments.front().c_str());
|
||||||
|
if (n <= 2) {
|
||||||
|
EMSESP::esp8266React.getNetworkSettingsService()->update(
|
||||||
|
[&](NetworkSettings & networkSettings) {
|
||||||
|
networkSettings.ethernet_profile = n;
|
||||||
|
shell.printfln(F_(ethernet_option_fmt), networkSettings.ethernet_profile);
|
||||||
|
return StateUpdateResult::CHANGED;
|
||||||
|
},
|
||||||
|
"local");
|
||||||
|
EMSESP::system_.network_init(true);
|
||||||
|
} else {
|
||||||
|
shell.println(F("Must be 0, 1 or 2"));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments __attribute__((unused))) -> const std::vector<std::string> {
|
||||||
|
return std::vector<std::string>{read_flash_string(F("0")), read_flash_string(F("1")), read_flash_string(F("2"))};
|
||||||
|
});
|
||||||
|
|
||||||
EMSESPShell::commands->add_command(ShellContext::SYSTEM, CommandFlags::USER, flash_string_vector{F_(set)}, [](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) {
|
EMSESPShell::commands->add_command(ShellContext::SYSTEM, CommandFlags::USER, flash_string_vector{F_(set)}, [](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) {
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||||
shell.print(F(" "));
|
shell.print(F(" "));
|
||||||
shell.printfln(F_(hostname_fmt), networkSettings.hostname.isEmpty() ? uuid::read_flash_string(F_(unset)).c_str() : networkSettings.hostname.c_str());
|
shell.printfln(F_(hostname_fmt), networkSettings.hostname.isEmpty() ? uuid::read_flash_string(F_(unset)).c_str() : networkSettings.hostname.c_str());
|
||||||
});
|
|
||||||
|
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
|
||||||
shell.print(F(" "));
|
shell.print(F(" "));
|
||||||
shell.printfln(F_(wifi_ssid_fmt), networkSettings.ssid.isEmpty() ? uuid::read_flash_string(F_(unset)).c_str() : networkSettings.ssid.c_str());
|
shell.printfln(F_(wifi_ssid_fmt), networkSettings.ssid.isEmpty() ? uuid::read_flash_string(F_(unset)).c_str() : networkSettings.ssid.c_str());
|
||||||
shell.print(F(" "));
|
shell.print(F(" "));
|
||||||
shell.printfln(F_(wifi_password_fmt), networkSettings.ssid.isEmpty() ? F_(unset) : F_(asterisks));
|
shell.printfln(F_(wifi_password_fmt), networkSettings.ssid.isEmpty() ? F_(unset) : F_(asterisks));
|
||||||
|
shell.print(F(" "));
|
||||||
|
shell.printfln(F_(ethernet_option_fmt), networkSettings.ethernet_profile);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -65,12 +65,14 @@ class System {
|
|||||||
bool upload_status();
|
bool upload_status();
|
||||||
void show_mem(const char * note);
|
void show_mem(const char * note);
|
||||||
void get_settings();
|
void get_settings();
|
||||||
|
|
||||||
void led_init(bool refresh);
|
void led_init(bool refresh);
|
||||||
void syslog_init(bool refresh);
|
void syslog_init(bool refresh);
|
||||||
void adc_init(bool refresh);
|
void adc_init(bool refresh);
|
||||||
void network_init();
|
void network_init(bool refresh);
|
||||||
void commands_init();
|
|
||||||
void button_init(bool refresh);
|
void button_init(bool refresh);
|
||||||
|
void commands_init();
|
||||||
|
|
||||||
bool check_upgrade();
|
bool check_upgrade();
|
||||||
void send_heartbeat();
|
void send_heartbeat();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user