Browse Source

Added hostname-support + prepared static IP-config

master
Torsten Stauder 5 years ago
parent
commit
d6cddfffa8
  1. 4
      README.md
  2. 5
      html/website.html
  3. 4
      html/websiteBasic.html
  4. 2
      src/logmessages.h
  5. 56
      src/main.cpp
  6. 4
      src/websiteBasic.h
  7. 5
      src/websiteMgmt.h

4
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. <br >
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)

5
html/website.html

@ -59,6 +59,8 @@
</div>
<label for="pwd">Passwort:</label>
<input type="password" class="form-control" id="pwd" placeholder="Passwort" name="pwd" required>
<label for="hostname">Tonuino-Name (Hostname):</label>
<input type="text" class="form-control" id="hostname" placeholder="tonuino" name="hostname" value="%HOSTNAME%" pattern="^[^-\.]{2,32}" required>
</div>
<button type="reset" class="btn btn-secondary">Reset</button>
<button type="submit" class="btn btn-primary">Absenden</button>
@ -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);

4
html/websiteBasic.html

@ -10,7 +10,9 @@
<label for="ssid">SSID:</label><br>
<input type="text" id="ssid" name="ssid" placeholder="SSID" required><br>
<label for="pwd">Passwort:</label><br>
<input type="password" id="pwd" name="pwd" autocomplete="off" required><br><br>
<input type="password" id="pwd" name="pwd" autocomplete="off" required><br>
<label for="hostname">Tonuino-Name (Hostname):</label><br>
<input type="text" id="hostname" name="hostname" required><br><br>
<input type="submit" value="Absenden">
</fieldset>
</form>

2
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";

56
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;

4
src/websiteBasic.h

@ -10,7 +10,9 @@ static const char basicWebsite[] PROGMEM = "<!DOCTYPE html>\
<label for=\"ssid\">SSID:</label><br>\
<input type=\"text\" id=\"ssid\" name=\"ssid\" placeholder=\"SSID\" required><br>\
<label for=\"pwd\">Passwort:</label><br>\
<input type=\"password\" id=\"pwd\" name=\"pwd\" autocomplete=\"off\" required><br><br>\
<input type=\"password\" id=\"pwd\" name=\"pwd\" autocomplete=\"off\" required><br>\
<label for=\"hostname\">Tonuino-Name (Hostname):</label><br>\
<input type=\"text\" id=\"hostname\" name=\"hostname\" required><br><br>\
<input type=\"submit\" value=\"Absenden\">\
</fieldset>\
</form>\

5
src/websiteMgmt.h

@ -59,6 +59,8 @@ static const char mgtWebsite[] PROGMEM = "<!DOCTYPE html>\
</div>\
<label for=\"pwd\">Passwort:</label>\
<input type=\"password\" class=\"form-control\" id=\"pwd\" placeholder=\"Passwort\" name=\"pwd\" required>\
<label for=\"hostname\">Tonuino-Name (Hostname):</label>\
<input type=\"text\" class=\"form-control\" id=\"hostname\" placeholder=\"tonuino\" name=\"hostname\" value=\"%HOSTNAME%\" pattern=\"^[^-\\.]{2,32}\" required>\
</div>\
<button type=\"reset\" class=\"btn btn-secondary\">Reset</button>\
<button type=\"submit\" class=\"btn btn-primary\">Absenden</button>\
@ -344,7 +346,8 @@ static const char mgtWebsite[] PROGMEM = "<!DOCTYPE html>\
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);\

Loading…
Cancel
Save