diff --git a/README.md b/README.md index 866bcd3..318a6af 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,8 @@ Optionally, GPIO 17 can be used to drive a NPN-transistor (BC337-40) that pulls * compile and upload the sketch ## Starting Tonuino-ESP32 first time -After plugging in it takes a few seconds until neopixel indicates that Tonuino is ready (by four (slow) rotating LEDs). If uC was not able to connect to WiFi, an access-point (named Tonuino) is opened and after connecting this WiFi, a [configuration-Interface](http://192.168.4.1) is available. Enter WiFI-credentials, save them and restart the uC. Then reconnect to your "regular" WiFi. Now you're ready to got: place your favourite RFID-tag next to the RFID-reader and the music should start to play. While the playlist is generated, fast-rotating LEDs are shown. The more tracks a playlist/directory contains the longer this step takes. +After plugging in it takes a few seconds until neopixel indicates that Tonuino is ready (by four (slow) rotating LEDs). If uC was not able to connect to WiFi, an access-point (named Tonuino) is opened and after connecting this WiFi, a [configuration-Interface](http://192.168.4.1) is available. Enter WiFI-credentials + the hostname (Tonuio's name) and save them and restart the uC. Then reconnect to your "regular" WiFi. Now you're ready to got: place your favourite RFID-tag next to the RFID-reader and the music should start to play. While the playlist is generated, fast-rotating LEDs are shown. The more tracks a playlist/directory contains the longer this step takes.
+Please note: hostname can be used to call webgui or FTP-server. I tested it with a Fritzbox 7490 and worked fine. Make sure you don't use a name that already exists in you local network (LAN). ## After Tonuino-ESP32 is connected to your WiFi After connecting the Tonuino to your WiFi, the 'regular' Webgui is available at the IP assigned by the router. Using this GUI, you can configure: @@ -186,6 +187,7 @@ This mode is different from the other ones because the last playposition is save ### Webinterface-configuration After having Tonuino running on your ESP32 in your local WiFi, the webinterface-configuration is accessable. Using this GUI you can configure: +* Wifi-configuration (Wifi-SSID, Wifi-password, Tonuino's name (for nameserver)) * Link between RFID-tag and corresponding action * MQTT-configuration (broker's IP) * FTP-configuration (username and password) diff --git a/html/website.html b/html/website.html index 1a9c57e..ca3c453 100644 --- a/html/website.html +++ b/html/website.html @@ -59,6 +59,8 @@ + + @@ -344,7 +346,8 @@ var myObj = { "wifiConfig": { ssid: document.getElementById('ssid').value, - pwd: document.getElementById('pwd').value + pwd: document.getElementById('pwd').value, + hostname: document.getElementById('hostname').value } }; var myJSON = JSON.stringify(myObj); diff --git a/html/websiteBasic.html b/html/websiteBasic.html index 8909bcb..15c3302 100644 --- a/html/websiteBasic.html +++ b/html/websiteBasic.html @@ -10,7 +10,9 @@


-

+
+
+

diff --git a/src/logmessages.h b/src/logmessages.h index cccb45b..8e1e1b8 100644 --- a/src/logmessages.h +++ b/src/logmessages.h @@ -133,4 +133,6 @@ static const char mqttWithPwd[] PROGMEM = "Verbinde zu MQTT-Server mit User und static const char mqttWithoutPwd[] PROGMEM = "Verbinde zu MQTT-Server ohne User und Passwort"; static const char ssidNotFoundInNvs[] PROGMEM = "SSID wurde im NVS nicht gefunden."; static const char wifiPwdNotFoundInNvs[] PROGMEM = "WLAN-Passwort wurde im NVS nicht gefunden."; +static const char wifiStaticIpConfigNotFoundInNvs[] PROGMEM = "Statische WLAN-IP-Konfiguration wurde im NVS nicht gefunden."; +static const char wifiHostnameNotSet[] PROGMEM = "Keine Hostname-Konfiguration im NVS gefunden."; static const char mqttConnFailed[] PROGMEM = "Verbindung fehlgeschlagen, versuche erneut in Kürze erneut"; diff --git a/src/main.cpp b/src/main.cpp index 00c0fc8..8c0d277 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2519,11 +2519,13 @@ void accessPointStart(const char *SSID, IPAddress ip, IPAddress netmask) { }); wServer.on("/init", HTTP_POST, [] (AsyncWebServerRequest *request) { - if (request->hasParam("ssid", true) && request->hasParam("pwd", true)) { + if (request->hasParam("ssid", true) && request->hasParam("pwd", true) && request->hasParam("hostname", true)) { Serial.println(request->getParam("ssid", true)->value()); Serial.println(request->getParam("pwd", true)->value()); + Serial.println(request->getParam("hostname", true)->value()); prefsSettings.putString("SSID", request->getParam("ssid", true)->value()); prefsSettings.putString("Password", request->getParam("pwd", true)->value()); + prefsSettings.putString("Hostname", request->getParam("hostname", true)->value()); } request->send_P(200, "text/html", basicWebsite); }); @@ -2555,6 +2557,38 @@ wl_status_t wifiManager(void) { const char *_ssid = strSSID.c_str(); const char *_pwd = strPassword.c_str(); + /* + // Get (optional) static-IP-configration from NVS + String strStaticIp = prefsSettings.getString("staticIP", "-1"); + String strStaticIpGw = prefsSettings.getString("staticIPGw", "-1"); + String strStaticIpNetmask = prefsSettings.getString("staticIPNetmask", "-1"); + if (!strStaticIp.compareTo("-1") || !strStaticIpGw.compareTo("-1") || !strStaticIpNetmask.compareTo("-1")) { + loggerNl((char *) FPSTR(wifiStaticIpConfigNotFoundInNvs), LOGLEVEL_INFO); + } else { + IPAddress staticWifiIp; + IPAddress staticWifiIpGw; + IPAddress staticWifiIpNetmask; + + if (strStaticIp.length() >= 7 && strStaticIpGw.length() >= 7 && strStaticIpNetmask.length() >= 7) { + staticWifiIp.fromString(strStaticIp.c_str()); + staticWifiIpGw.fromString(strStaticIpGw.c_str()); + staticWifiIpNetmask.fromString(strStaticIpNetmask.c_str()); + WiFi.config(staticWifiIp, staticWifiIpGw, staticWifiIpNetmask); + } else { + Serial.println("IP-config nicht gueltig!"); + } + }*/ + + // Get (optional) hostname-configration from NVS + String hostname = prefsSettings.getString("Hostname", "-1"); + Serial.println(hostname.c_str()); + if (hostname.compareTo("-1")) { + WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + WiFi.setHostname(hostname.c_str()); + Serial.println(hostname.c_str()); + } else { + loggerNl((char *) FPSTR(wifiHostnameNotSet), LOGLEVEL_INFO); + } // ...and create a connection with it. If not successful, an access-point will is opened WiFi.begin(_ssid, _pwd); @@ -2619,6 +2653,14 @@ String templateProcessor(const String& templ) { return String(logBuf); } else if (templ == "RFID_TAG_ID") { return String(currentRfidTagId); + /*} else if (templ == "STATIC_IP") { + return prefsSettings.getString("staticIP", "-1"); + } else if (templ == "STATIC_IP_GW") { + return prefsSettings.getString("staticIPGw", "-1"); + } else if (templ == "STATIC_IP_NETMASK") { + return prefsSettings.getString("staticIPNetmask", "-1");*/ + } else if (templ == "HOSTNAME") { + return prefsSettings.getString("Hostname", "-1"); } return String(); @@ -2694,6 +2736,15 @@ bool processJsonRequest(char *_serialJson) { return false; } + /*} else if (doc.containsKey("staticIP")) { + const char *_staticIp = object["ip"]["staticIP"]; + const char *_staticIpGW = doc["ip"]["staticIPGW"]; + const char *_staticIpNM = doc["ip"]["staticIPNM"]; + + prefsSettings.putString("staticIP", (String) _staticIp); + prefsSettings.putString("staticIPGw", (String) _staticIpGW); + prefsSettings.putString("staticIPNetmask", (String) _staticIpNM);*/ + } else if (doc.containsKey("rfidMod")) { const char *_rfidIdModId = object["rfidMod"]["rfidIdMod"]; uint8_t _modId = object["rfidMod"]["modId"]; @@ -2726,12 +2777,15 @@ bool processJsonRequest(char *_serialJson) { } else if (doc.containsKey("wifiConfig")) { const char *_ssid = object["wifiConfig"]["ssid"]; const char *_pwd = object["wifiConfig"]["pwd"]; + const char *_hostname = object["wifiConfig"]["hostname"]; prefsSettings.putString("SSID", _ssid); prefsSettings.putString("Password", _pwd); + prefsSettings.putString("Hostname", (String) _hostname); String sSsid = prefsSettings.getString("SSID", "-1"); String sPwd = prefsSettings.getString("Password", "-1"); + String sHostname = prefsSettings.getString("Hostname", "-1"); if (sSsid.compareTo(_ssid) || sPwd.compareTo(_pwd)) { return false; diff --git a/src/websiteBasic.h b/src/websiteBasic.h index 057d7a7..8bb02a7 100644 --- a/src/websiteBasic.h +++ b/src/websiteBasic.h @@ -10,7 +10,9 @@ static const char basicWebsite[] PROGMEM = "\
\
\
\ -

\ +
\ +
\ +

\ \ \ \ diff --git a/src/websiteMgmt.h b/src/websiteMgmt.h index 518c46c..69f8d7b 100644 --- a/src/websiteMgmt.h +++ b/src/websiteMgmt.h @@ -59,6 +59,8 @@ static const char mgtWebsite[] PROGMEM = "\ \ \ \ + \ + \ \ \ \ @@ -344,7 +346,8 @@ static const char mgtWebsite[] PROGMEM = "\ var myObj = {\ \"wifiConfig\": {\ ssid: document.getElementById('ssid').value,\ - pwd: document.getElementById('pwd').value\ + pwd: document.getElementById('pwd').value,\ + hostname: document.getElementById('hostname').value\ }\ };\ var myJSON = JSON.stringify(myObj);\