From 36242e0e02102e7f6534f53ec519ac304515cac3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 5 Sep 2018 15:38:48 +0200 Subject: [PATCH] Add network information Add network information to display start screen (#3704) --- sonoff/_changelog.ino | 1 + sonoff/sonoff.h | 2 +- sonoff/sonoff.ino | 10 +++++----- sonoff/xdrv_13_display.ino | 22 +++++++++++++++++++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 145e435e3..77020540e 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -2,6 +2,7 @@ * Rewrite energy monitoring using energy sensor driver modules * Add Wifi channel number to state message (#3664) * Add support for Shelly 1 and basic support for Shelly 2 - No energy monitoring yet (#2789) + * Add network information to display start screen (#3704) * * 6.2.1 20180905 * Fix possible ambiguity on command parameters if StateText contains numbers only (#3656) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 2c5d5cce9..a0b65b348 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -204,7 +204,7 @@ enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MA enum XsnsFunctions {FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR, - FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM}; + FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_DISPLAY, FUNC_FREE_MEM}; const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 }; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index c92a8db76..8afae580e 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2540,19 +2540,19 @@ void setup() snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BOOT_COUNT " %d"), Settings.bootcount); AddLog(LOG_LEVEL_DEBUG); - GpioInit(); - - SetSerialBaudrate(baudrate); - Format(mqtt_client, Settings.mqtt_client, sizeof(mqtt_client)); Format(mqtt_topic, Settings.mqtt_topic, sizeof(mqtt_topic)); - if (strstr(Settings.hostname, "%")) { strlcpy(Settings.hostname, WIFI_HOSTNAME, sizeof(Settings.hostname)); snprintf_P(my_hostname, sizeof(my_hostname)-1, Settings.hostname, mqtt_topic, ESP.getChipId() & 0x1FFF); } else { snprintf_P(my_hostname, sizeof(my_hostname)-1, Settings.hostname); } + + GpioInit(); + + SetSerialBaudrate(baudrate); + WifiConnect(); if (MOTOR == Settings.module) Settings.poweronstate = POWER_ALL_ON; // Needs always on else in limbo! diff --git a/sonoff/xdrv_13_display.ino b/sonoff/xdrv_13_display.ino index 74b4069e1..c8972536a 100644 --- a/sonoff/xdrv_13_display.ino +++ b/sonoff/xdrv_13_display.ino @@ -626,11 +626,24 @@ void DisplayLogBufferInit() DisplayReAllocLogBuffer(); - char buffer[20]; + char buffer[40]; snprintf_P(buffer, sizeof(buffer), PSTR(D_VERSION " %s"), my_version); DisplayLogBufferAdd(buffer); snprintf_P(buffer, sizeof(buffer), PSTR("Display mode %d"), Settings.display_mode); DisplayLogBufferAdd(buffer); + + snprintf_P(buffer, sizeof(buffer), PSTR(D_CMND_HOSTNAME " %s"), my_hostname); + DisplayLogBufferAdd(buffer); + snprintf_P(buffer, sizeof(buffer), PSTR(D_JSON_SSID " %s"), Settings.sta_ssid[Settings.sta_active]); + DisplayLogBufferAdd(buffer); + snprintf_P(buffer, sizeof(buffer), PSTR(D_JSON_MAC " %s"), WiFi.macAddress().c_str()); + DisplayLogBufferAdd(buffer); + if (!global_state.wifi_down && (static_cast(WiFi.localIP()) != 0)) { + snprintf_P(buffer, sizeof(buffer), PSTR("IP %s"), WiFi.localIP().toString().c_str()); + DisplayLogBufferAdd(buffer); + snprintf_P(buffer, sizeof(buffer), PSTR(D_JSON_RSSI " %d%%"), WifiGetRssiAsQuality(WiFi.RSSI())); + DisplayLogBufferAdd(buffer); + } } } @@ -915,8 +928,8 @@ boolean DisplayCommand() if (last_display_mode && !Settings.display_mode) { // Switch to mode 0 DisplayInit(DISPLAY_INIT_MODE); DisplayClear(); - } - if (!last_display_mode && Settings.display_mode) { // Switch to non mode 0 + } else { +// if (!last_display_mode && Settings.display_mode) { // Switch to non mode 0 DisplayLogBufferInit(); DisplayInit(DISPLAY_INIT_MODE); } @@ -1047,6 +1060,9 @@ boolean Xdrv13(byte function) case FUNC_PRE_INIT: DisplayInitDriver(); break; + case FUNC_DISPLAY: + DisplayLogBufferAdd(log_data); + break; case FUNC_EVERY_50_MSECOND: if (Settings.display_model) { XdspCall(FUNC_DISPLAY_EVERY_50_MSECOND); } break;