mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
added hostname, some formatting
This commit is contained in:
@@ -37,6 +37,7 @@ bool System::hide_led_ = false;
|
||||
uint8_t System::led_gpio_ = 0;
|
||||
uint16_t System::analog_ = 0;
|
||||
bool System::analog_enabled_ = false;
|
||||
std::string System::hostname_;
|
||||
|
||||
// send on/off to a gpio pin
|
||||
// value: true = HIGH, false = LOW
|
||||
@@ -168,6 +169,8 @@ void System::init() {
|
||||
analog_enabled_ = settings.analog_enabled;
|
||||
});
|
||||
|
||||
EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & settings) { hostname(settings.hostname.c_str()); });
|
||||
|
||||
EMSESP::init_tx(); // start UART
|
||||
}
|
||||
|
||||
@@ -266,6 +269,9 @@ void System::send_heartbeat() {
|
||||
if (analog_enabled_) {
|
||||
doc["adc"] = analog_;
|
||||
}
|
||||
#if defined(ESP8266)
|
||||
doc["fragmentation"] = ESP.getHeapFragmentation();
|
||||
#endif
|
||||
|
||||
Mqtt::publish_retain(F("heartbeat"), doc.as<JsonObject>(), false); // send to MQTT with retain off. This will add to MQTT queue.
|
||||
}
|
||||
@@ -404,11 +410,6 @@ void System::show_system(uuid::console::Shell & shell) {
|
||||
shell.printfln(F("Flash chip: 0x%08X (%u bytes)"), ESP.getFlashChipId(), ESP.getFlashChipRealSize());
|
||||
shell.printfln(F("Reset reason: %s"), ESP.getResetReason().c_str());
|
||||
shell.printfln(F("Reset info: %s"), ESP.getResetInfo().c_str());
|
||||
shell.printfln(F("Free heap: %lu bytes"), (unsigned long)ESP.getFreeHeap());
|
||||
shell.printfln(F("Free mem: %d %%"), free_mem());
|
||||
shell.printfln(F("Maximum free block size: %lu bytes"), (unsigned long)ESP.getMaxFreeBlockSize());
|
||||
shell.printfln(F("Heap fragmentation: %u %%"), ESP.getHeapFragmentation());
|
||||
shell.printfln(F("Free continuations stack: %lu bytes"), (unsigned long)ESP.getFreeContStack());
|
||||
#elif defined(ESP32)
|
||||
shell.printfln(F("SDK version: %s"), ESP.getSdkVersion());
|
||||
shell.printfln(F("CPU frequency: %u MHz"), ESP.getCpuFreqMHz());
|
||||
@@ -416,6 +417,11 @@ void System::show_system(uuid::console::Shell & shell) {
|
||||
shell.printfln(F("Sketch size: %u bytes (%u bytes free)"), ESP.getSketchSize(), ESP.getFreeSketchSpace());
|
||||
shell.printfln(F("Free heap: %lu bytes"), (unsigned long)ESP.getFreeHeap());
|
||||
shell.printfln(F("Free mem: %d %%"), free_mem());
|
||||
#if defined(ESP8266)
|
||||
shell.printfln(F("Heap fragmentation: %u %%"), ESP.getHeapFragmentation());
|
||||
shell.printfln(F("Maximum free block size: %lu bytes"), (unsigned long)ESP.getMaxFreeBlockSize());
|
||||
shell.printfln(F("Free continuations stack: %lu bytes"), (unsigned long)ESP.getFreeContStack());
|
||||
#endif
|
||||
shell.println();
|
||||
|
||||
switch (WiFi.status()) {
|
||||
@@ -541,7 +547,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
||||
|
||||
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
||||
CommandFlags::USER,
|
||||
flash_string_vector{F_(show), F_(system)},
|
||||
flash_string_vector{F_(show)},
|
||||
[=](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) {
|
||||
show_system(shell);
|
||||
shell.println();
|
||||
@@ -635,7 +641,6 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
||||
// the logic is bit abnormal (loading both filesystems and testing) but this was the only way I could get it to work reliably
|
||||
bool System::check_upgrade() {
|
||||
#if defined(ESP8266)
|
||||
|
||||
LittleFSConfig l_cfg;
|
||||
l_cfg.setAutoFormat(false);
|
||||
LittleFS.setConfig(l_cfg); // do not auto format if it can't find LittleFS
|
||||
@@ -837,7 +842,6 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
|
||||
#ifdef EMSESP_STANDALONE
|
||||
output["test"] = "testing";
|
||||
#else
|
||||
|
||||
EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & settings) {
|
||||
char s[7];
|
||||
JsonObject node = output.createNestedObject("WIFI");
|
||||
|
||||
@@ -63,6 +63,14 @@ class System {
|
||||
void syslog_init();
|
||||
void send_heartbeat();
|
||||
|
||||
static std::string hostname() {
|
||||
return hostname_;
|
||||
}
|
||||
|
||||
static void hostname(std::string hostname) {
|
||||
hostname_ = hostname;
|
||||
}
|
||||
|
||||
private:
|
||||
static uuid::log::Logger logger_;
|
||||
|
||||
@@ -96,6 +104,7 @@ class System {
|
||||
uint32_t last_heartbeat_ = 0;
|
||||
static bool upload_status_; // true if we're in the middle of a OTA firmware upload
|
||||
static uint16_t analog_;
|
||||
static std::string hostname_;
|
||||
|
||||
// settings
|
||||
static bool hide_led_;
|
||||
|
||||
Reference in New Issue
Block a user