From 4efd4372d5ac02304406ec7f0879a2c6e3faf5a9 Mon Sep 17 00:00:00 2001 From: Torsten Stauder Date: Sun, 17 Jan 2021 11:37:38 +0100 Subject: [PATCH] Added (optinal) static IP-config --- README.md | 1 + platformio.ini | 2 +- src/logmessages.h | 4 +++- src/logmessages_EN.h | 4 +++- src/main.cpp | 15 +++++++++++++-- src/settings.h | 9 +++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 23dd8fc..acb677f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Finally, the long announced Tonuino-PCB for Wemos' Lolin32 is [there](https://gi
More to come... * 23.12.2020: User-config is now split into general part (settings.h) and develboard-specific part (e.g. settings-lolin32.h) * 13.01.2020: Added fileexlorer to webgui (thanks @grch87 for contribution!). Now files and directories can be renamed, uploaded and deleted via webgui. +* 17.01.2020: Added directive `STATIC_IP_ENABLE`: (optional) static IPv4-configuration ## Known bugs * Some webstreams don't run. Guess it's a combination of saturated connection-pool and lack of heap-memory. Works probably better if ESP32-WROVER (e.g. Lolin D32 pro) is used, as this chip has PSRAM. Advice: Don't enable modules (e.g. MQTT) if you don't need them as this could save memory (and trouble). * English translation for webgui is currently outdated. This will be fixed soon when i18n-support will be integrated. diff --git a/platformio.ini b/platformio.ini index 74ee4b7..14a44cb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ lib_deps_builtin = SPI Wire lib_deps_external = - https://github.com/schreibfaul1/ESP32-audioI2S.git + https://github.com/schreibfaul1/ESP32-audioI2S.git#a816a19 ; currently not master-version as commit a816a19 not compatible with latest stable ESP32-Arduino https://github.com/madhephaestus/ESP32Encoder.git https://github.com/knolleary/pubsubclient.git https://github.com/biologist79/ESP32FTPServer diff --git a/src/logmessages.h b/src/logmessages.h index 2807243..0313323 100644 --- a/src/logmessages.h +++ b/src/logmessages.h @@ -168,4 +168,6 @@ static const char mqttMsgReceived[] PROGMEM = "MQTT-Nachricht empfangen"; static const char trackPausedAtPos[] PROGMEM = "Titel pausiert bei Position"; static const char freeHeapWithoutFtp[] PROGMEM = "Freier Heap-Speicher vor FTP-Instanzierung"; static const char freeHeapWithFtp[] PROGMEM = "Freier Heap-Speicher nach FTP-Instanzierung"; -static const char freeHeapAfterSetup[] PROGMEM = "Freier Heap-Speicher nach Setup-Routine"; \ No newline at end of file +static const char freeHeapAfterSetup[] PROGMEM = "Freier Heap-Speicher nach Setup-Routine"; +static const char tryStaticIpConfig[] PROGMEM = "Statische IP-Konfiguration wird durchgeführt..."; +static const char staticIPConfigFailed[] PROGMEM = "Statische IP-Konfiguration fehlgeschlagen"; diff --git a/src/logmessages_EN.h b/src/logmessages_EN.h index 5233a90..5010c79 100644 --- a/src/logmessages_EN.h +++ b/src/logmessages_EN.h @@ -168,4 +168,6 @@ static const char mqttMsgReceived[] PROGMEM = "MQTT-message received"; static const char trackPausedAtPos[] PROGMEM = "Track paused at position"; static const char freeHeapWithoutFtp[] PROGMEM = "Free heap before FTP-allocation"; static const char freeHeapWithFtp[] PROGMEM = "Free heap after FTP-allocation"; -static const char freeHeapAfterSetup[] PROGMEM = "Free heap after setup"; \ No newline at end of file +static const char freeHeapAfterSetup[] PROGMEM = "Free heap after setup"; +static const char tryStaticIpConfig[] PROGMEM = "Performing static IP-configuration..."; +static const char staticIPConfigFailed[] PROGMEM = "Static IP-configuration failed"; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1dd7773..5072e5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3192,7 +3192,18 @@ wl_status_t wifiManager(void) { } else { loggerNl((char *) FPSTR(wifiHostnameNotSet), LOGLEVEL_INFO); } - // ...and create a connection with it. If not successful, an access-point is opened + + // Add configration of static IP (if requested) + #ifdef STATIC_IP_ENABLE + snprintf(logBuf, serialLoglength, "%s", (char *) FPSTR(tryStaticIpConfig)); + loggerNl(logBuf, LOGLEVEL_NOTICE); + if (!WiFi.config(local_IP, gateway, subnet, primaryDNS)) { + snprintf(logBuf, serialLoglength, "%s", (char *) FPSTR(staticIPConfigFailed)); + loggerNl(logBuf, LOGLEVEL_ERROR); + } + #endif + + // Try to join local WiFi. If not successful, an access-point is opened WiFi.begin(_ssid, _pwd); uint8_t tryCount=0; @@ -3810,7 +3821,7 @@ void explorerHandleFileStorageTask(void *parameter) { uploadFile = FSystem.open((char *)parameter, "w"); - snprintf(logBuf, serialLoglength, "%s: %s", (char *) FPSTR(writingFile), parameter); + snprintf(logBuf, serialLoglength, "%s: %s", (char *) FPSTR(writingFile), (char *) parameter); loggerNl(logBuf, LOGLEVEL_INFO); for(;;) { diff --git a/src/settings.h b/src/settings.h index e2d22fd..b747dd2 100644 --- a/src/settings.h +++ b/src/settings.h @@ -22,6 +22,7 @@ #define NEOPIXEL_ENABLE // Don't forget configuration of NUM_LEDS if enabled #define NEOPIXEL_REVERSE_ROTATION // Some Neopixels are adressed/soldered counter-clockwise. This can be configured here. #define LANGUAGE 1 // 1 = deutsch; 2 = english +//#define STATIC_IP_ENABLE // Enables static IP-configuration (change static ip-section accordingly) //#define HEADPHONE_ADJUST_ENABLE // Used to adjust (lower) volume for optional headphone-pcb (refer maxVolumeSpeaker / maxVolumeHeadphone) #define SHUTDOWN_IF_SD_BOOT_FAILS // Will put ESP to deepsleep if boot fails due to SD. Really recommend this if there's in battery-mode no other way to restart ESP! Interval adjustable via deepsleepTimeAfterBootFails. #define MEASURE_BATTERY_VOLTAGE // Enables battery-measurement via GPIO (ADC) and voltage-divider @@ -51,6 +52,14 @@ // Serial-logging-configuration const uint8_t serialDebug = LOGLEVEL_DEBUG; // Current loglevel for serial console +// Static ip-configuration +#ifdef STATIC_IP_ENABLE + IPAddress local_IP(192, 168, 2, 100); // Tonuino's IP + IPAddress gateway(192, 168, 2, 1); // IP of the gateway/router + IPAddress subnet(255, 255, 255, 0); // Netmask of your network (/24 => 255.255.255.0) + IPAddress primaryDNS(192, 168, 2, 1); // DNS-server of your network; in private networks it's usually the gatewy's IP +#endif + // Buttons (better leave unchanged if in doubts :-)) uint8_t buttonDebounceInterval = 50; // Interval in ms to software-debounce buttons uint16_t intervalToLongPress = 700; // Interval in ms to distinguish between short and long press of previous/next-button