Browse Source

Added English as supported language (GUI+log)

master
Torsten Stauder 5 years ago
parent
commit
0a785f6440
  1. 1
      .vscode/settings.json
  2. 23
      html/websiteBasic_EN.html
  3. 358
      html/website_EN.html
  4. 23
      processHtml.py
  5. 23
      src/logmessages.h
  6. 139
      src/logmessages_EN.h
  7. 38
      src/main.cpp
  8. 24
      src/websiteBasic_EN.h
  9. 359
      src/websiteMgmt_EN.h

1
.vscode/settings.json

@ -1,3 +1,2 @@
{
"python.pythonPath": "/Users/torsten/.platformio/penv/bin/python"
}

23
html/websiteBasic_EN.html

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Wifi-configuration</title>
</head>
<body>
<form action="/init" method="POST">
<fieldset>
<legend>Basic wifi-setup</legend>
<label for="ssid">SSID:</label><br>
<input type="text" id="ssid" name="ssid" placeholder="SSID" required><br>
<label for="pwd">Password:</label><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="Submit">
</fieldset>
</form>
<form action="/restart">
<button type="submit">Reboot</button>
</form>
</body>
</html>

358
html/website_EN.html

@ -0,0 +1,358 @@
<!DOCTYPE html>
<html lang="de">
<head>
<title>ESPuino-configuration</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://ts-cs.de/tonuino/css/bootstrap.min.css">
<script src="https://ts-cs.de/tonuino/js/jquery.min.js"></script>
<script src="https://ts-cs.de/tonuino/js/popper.min.js"></script>
<script src="https://ts-cs.de/tonuino/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand">
<img src="https://raw.githubusercontent.com/biologist79/Tonuino-ESP32-I2S/master/html/tonuino_logo.png" width="30" height="30" class="d-inline-block align-top" alt="" />
Tonuino
</a>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#wifiConfig">Wifi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#rfidMusicTags">RFID-assignments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#rfidModTags">RFID-modifications</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#mqttConfig">MQTT</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#ftpConfig">FTP</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#generalConfig">General</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#importNvs">NVS-importer</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/restart" style="color: orange">Reboot Tonuino</a>
</li>
</ul>
</div>
</nav>
<br />
<div class="container" id="wifiConfig">
<h2>Wifi-configuration</h2>
<form action="#wifiConfig" method="POST" onsubmit="wifiConfig('wifiConfig'); return false">
<div class="form-group col-md-6">
<label for="ssid">Wifi-name (SSID):</label>
<input type="text" class="form-control" id="ssid" placeholder="SSID" name="ssid" required>
<div class="invalid-feedback">
Please enter name of wifi (SSID).
</div>
<label for="pwd">Password:</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">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<div class="container my-5" id="rfidMusicTags">
<h2>RFID-assignments</h2>
<form action="#rfidMusicTags" method="POST" onsubmit="rfidAssign('rfidMusicTags'); return false">
<div class="form-group col-md-6">
<label for="rfidIdMusic">RFID-chip-ID (12 digits)</label>
<input type="text" class="form-control" id="rfidIdMusic" maxlength="12" pattern="[0-9]{12}" placeholder="%RFID_TAG_ID%" name="rfidIdMusic" required>
<label for="fileOrUrl">File, directory or URL (^ und # are not allowed)</label>
<input type="text" class="form-control" id="fileOrUrl" maxlength="255" placeholder="z.B. /mp3/Hoerspiele/Yakari/Yakari_und_seine_Freunde.mp3" pattern="^[^\^#]+$" name="fileOrUrl" required>
<label for="playMode">Playmode</label>
<select class="form-control" id="playMode" name="playMode">
<option value="1">Single track</option>
<option value="2">Single track (infinite loop)</option>
<option value="3">Audiobook</option>
<option value="4">Audiobook (infinite loop)</option>
<option value="5">All tracks of directory (sorted)</option>
<option value="6">All tracks of directory (random)</option>
<option value="7">All tracks of directory (sorted, inf. loop)</option>
<option value="9">All tracks of directory (random, inf. loop)</option>
<option value="8">Webradio</option>
</select>
</div>
<button type="reset" class="btn btn-secondary">Reset</button>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<div class="container my-5" id="rfidModTags">
<h2>RFID-modifications</h2>
<form class="needs-validation" action="#rfidModTags" method="POST" onsubmit="rfidMods('rfidModTags'); return false">
<div class="form-group col-md-6">
<label for="rfidIdMod">RFID-chip-ID (12-digits)</label>
<input type="text" class="form-control" id="rfidIdMod" maxlength="12" pattern="[0-9]{12}" placeholder="%RFID_TAG_ID%" name="rfidIdMod" required>
<div class="invalid-feedback">
Please enter a 12-digits-number.
</div>
<label for="modId">Abspielmodus</label>
<select class="form-control" id="modId" name="modId">
<option value="100">Lock keys</option>
<option value="101">Sleep after 15 minutes</option>
<option value="102">Sleep after 30 minutes</option>
<option value="103">Sleep after 1 hour</option>
<option value="104">Sleep after 1 hours</option>
<option value="105">Sleep after end of track</option>
<option value="106">Sleep after end of playlist</option>
<option value="107">Sleep after five tracks</option>
<option value="110">Repeat playlist (inf. loop)</option>
<option value="111">Repeat track (inf. loop)</option>
<option value="112">Dimm LEDs (nightmode)</option>
</select>
</div>
<button type="reset" class="btn btn-secondary">Reset</button>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<div class="container my-5" id="mqttConfig">
<h2>MQTT-configuration</h2>
<form class="needs-validation" action="#mqttConfig" method="POST" onsubmit="mqttSettings('mqttConfig'); return false">
<div class="form-check col-md-6">
<input class="form-check-input" type="checkbox" value="1" id="mqttEnable" name="mqttEnable" %MQTT_ENABLE%>
<label class="form-check-label" for="mqttEnable">
Enable MQTT
</label>
</div>
<div class="form-group my-2 col-md-6">
<label for="mqttServer">MQTT-server (IP-address)</label>
<input type="text" class="form-control" id="mqttServer" pattern="^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" minlength="7" maxlength="15" placeholder="z.B. 192.168.2.89" name="mqttServer" value="%MQTT_SERVER%">
<div class="invalid-feedback">
Please enter a valid IPv4-address, e.g. 192.168.2.89.
</div>
<label for="mqttUser">MQTT-username (optional):</label>
<input type="text" class="form-control" id="mqttUser" maxlength="15" placeholder="Benutzername" name="mqttUser" value="%MQTT_USER%">
<label for="mqttPwd">Password (optional):</label>
<input type="password" class="form-control" id="mqttPwd" maxlength="15" placeholder="Passwort" name="mqttPwd" value="%MQTT_PWD%">
</div>
<button type="reset" class="btn btn-secondary">Reset</button>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<div class="container" id="ftpConfig">
<h2>FTP-configuration</h2>
<form action="#ftpConfig" method="POST" onsubmit="ftpSettings('ftpConfig'); return false">
<div class="form-group col-md-6">
<label for="ftpUser">FTP-username:</label>
<input type="text" class="form-control" id="ftpUser" maxlength="32" placeholder="Benutzername" name="ftpUser" value="%FTP_USER%" required>
<label for="pwd">password:</label>
<input type="password" class="form-control" id="ftpPwd" maxlength="32" placeholder="Passwort" name="ftpPwd" value="%FTP_PWD%" required>
</div>
<button type="reset" class="btn btn-secondary">Reset</button>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<div class="container my-5" id="generalConfig">
<h2>General configuration</h2>
<form action="#generalConfig" method="POST" onsubmit="genSettings('generalConfig'); return false">
<div class="form-group col-md-6">
<label for="initialVolume">Volume after start</label>
<input type="number" min="1" max="21" class="form-control" id="initialVolume" name="initialVolume" value="%INIT_VOLUME%" required>
<label for="maxVolume">Maximum volume</label>
<input type="number" min="1" max="21" class="form-control" id="maxVolume" name="maxVolume" value="%MAX_VOLUME%" required>
</div>
<div class="form-group col-md-6">
<label for="initBrightness">Neopixel-brightness after start</label>
<input type="number" min="0" max="255" class="form-control" id="initBrightness" name="initBrightness" value="%INIT_LED_BRIGHTBESS%" required>
<label for="nightBrightness">Neopixel-brightness in nightmode</label>
<input type="number" min="0" max="255" class="form-control" id="nightBrightness" name="nightBrightness" value="%NIGHT_LED_BRIGHTBESS%" required>
</div>
<div class="form-group col-md-6">
<label for="inactivityTime">Deepsleep after inactivity (minutes)</label>
<input type="number" min="1" max="1440" class="form-control" id="inactivityTime" name="inactivityTime" value="%MAX_INACTIVITY%" required>
</div>
<button type="reset" class="btn btn-secondary">Reset</button>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<div class="container my-5" id="importNvs">
<h2>NVS-importer</h2>
<form action="/upload" enctype="multipart/form-data" method="POST">
<div class="form-group">
<label for="nvsUpload">Backup-files can be imported here.</label>
<input type="file" class="form-control-file" id="nvsUpload" name="nvsUpload" accept=".txt">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="messages col-md-6 my-2"></div>
</div>
<script>
var lastIdclicked = '';
var errorBox = '<div class="alert alert-danger alert-dismissible fade show" role="alert">Error occured!<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
var okBox = '<div class="alert alert-success alert-dismissible fade show" role="alert">Action successful.<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>';
var socket = new WebSocket("ws://%IPv4%/ws");
function connect() {
socket = new WebSocket("ws://%IPv4%/ws");
}
function ping() {
var myObj = {
"ping": {
ping: 'ping'
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
tm = setTimeout(function () {
alert("Connection to tonuino is broken!\\nPlease refresh this website.");
}, 5000);
}
function pong() {
clearTimeout(tm);
}
socket.onopen = function () {
setInterval(ping, 15000);
};
socket.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 5000);
};
socket.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
socket.close();
};
socket.onmessage = function(event) {
console.log(event.data);
var socketMsg = JSON.parse(event.data);
if (socketMsg.rfidId != null) {
document.getElementById('rfidIdMod').value = socketMsg.rfidId;
document.getElementById('rfidIdMusic').value = socketMsg.rfidId;
$("#rfidIdMusic").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);
$("#rfidIdMod").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);
} if (socketMsg.status != null) {
if (socketMsg.status == 'ok') {
$("#" + lastIdclicked).find('.messages').html(okBox);
} else {
$("#" + lastIdclicked).find('.messages').html(errorBox);
}
} if (socketMsg.pong != null) {
if (socketMsg.pong == 'pong') {
pong();
}
}
};
function genSettings(clickedId) {
lastIdclicked = clickedId;
var myObj = {
"general": {
iVol: document.getElementById('initialVolume').value,
mVol: document.getElementById('maxVolume').value,
iBright: document.getElementById('initBrightness').value,
nBright: document.getElementById('nightBrightness').value,
iTime: document.getElementById('inactivityTime').value
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
}
function ftpSettings(clickedId) {
lastIdclicked = clickedId;
var myObj = {
"ftp": {
ftpUser: document.getElementById('ftpUser').value,
ftpPwd: document.getElementById('ftpPwd').value
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
}
function mqttSettings(clickedId) {
lastIdclicked = clickedId;
var val;
if (document.getElementById('mqttEnable').checked) {
val = document.getElementById('mqttEnable').value;
} else {
val = 0;
}
var myObj = {
"mqtt": {
mqttEnable: val,
mqttServer: document.getElementById('mqttServer').value,
mqttUser: document.getElementById('mqttUser').value,
mqttPwd: document.getElementById('mqttPwd').value
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
}
function rfidMods(clickedId) {
lastIdclicked = clickedId;
var myObj = {
"rfidMod": {
rfidIdMod: document.getElementById('rfidIdMod').value,
modId: document.getElementById('modId').value
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
}
function removeTrSlash(str) {
if(str.substr(-1) === '/') {
return str.substr(0, str.length - 1);
}
return str;
}
function rfidAssign(clickedId) {
lastIdclicked = clickedId;
var myObj = {
"rfidAssign": {
rfidIdMusic: document.getElementById('rfidIdMusic').value,
fileOrUrl: removeTrSlash(document.getElementById('fileOrUrl').value),
playMode: document.getElementById('playMode').value
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
}
function wifiConfig(clickedId) {
lastIdclicked = clickedId;
var myObj = {
"wifiConfig": {
ssid: document.getElementById('ssid').value,
pwd: document.getElementById('pwd').value,
hostname: document.getElementById('hostname').value
}
};
var myJSON = JSON.stringify(myObj);
socket.send(myJSON);
}
</script>
</body>
</html>

23
processHtml.py

@ -2,6 +2,8 @@
content = ''
content2 = ''
contentEN = ''
content2EN = ''
with open('html/website.html', 'r') as r:
data = r.read().replace('\n', '\\\n')
@ -16,6 +18,18 @@ with open('src/websiteMgmt.h', 'w') as w:
w.write(content)
w.write("\";")
with open('html/website_EN.html', 'r') as ren:
data = ren.read().replace('\n', '\\\n')
data = data.replace('\"', '\\"')
data = data.replace('\\d', '\\\d')
data = data.replace('\\.', '\\\.')
data = data.replace('\\^', '\\\\^')
contentEN += data
with open('src/websiteMgmt_EN.h', 'w') as wen:
wen.write("static const char mgtWebsite[] PROGMEM = \"")
wen.write(contentEN)
wen.write("\";")
with open('html/websiteBasic.html', 'r') as r2:
data = r2.read().replace('\n', '\\\n')
@ -27,6 +41,15 @@ with open('src/websiteBasic.h', 'w') as w2:
w2.write(content2)
w2.write("\";")
with open('html/websiteBasic_EN.html', 'r') as r2en:
data = r2en.read().replace('\n', '\\\n')
data = data.replace('\"', '\\"')
content2EN += data
with open('src/websiteBasic_EN.h', 'w') as w2en:
w2en.write("static const char basicWebsite[] PROGMEM = \"")
w2en.write(content2EN)
w2en.write("\";")
r.close()
w.close()

23
src/logmessages.h

@ -108,27 +108,27 @@ static const char unableToCreateMgmtQ[] PROGMEM = "Konnte Play-Management-Queue
static const char unableToCreatePlayQ[] PROGMEM = "Konnte Track-Queue nicht anlegen..";
static const char initialBrightnessfromNvs[] PROGMEM = "Initiale LED-Helligkeit wurde aus NVS geladen";
static const char wroteInitialBrightnessToNvs[] PROGMEM = "Initiale LED-Helligkeit wurde ins NVS geschrieben.";
static const char loadedInitialBrightnessForNmFromNvs[] PROGMEM = "LED-Helligkeit für Nachtmodus wurde aus NVS geladen";
static const char restoredInitialBrightnessForNmFromNvs[] PROGMEM = "LED-Helligkeit für Nachtmodus wurde aus NVS geladen";
static const char wroteNmBrightnessToNvs[] PROGMEM = "LED-Helligkeit für Nachtmodus wurde ins NVS geschrieben.";
static const char wroteFtpUserToNvs[] PROGMEM = "FTP-User wurde ins NVS geschrieben.";
static const char loadedFtpUserFromNvs[] PROGMEM = "FTP-User wurde aus NVS geladen";
static const char restoredFtpUserFromNvs[] PROGMEM = "FTP-User wurde aus NVS geladen";
static const char wroteFtpPwdToNvs[] PROGMEM = "FTP-Passwort wurde ins NVS geschrieben.";
static const char loadedFtpPwdFromNvs[] PROGMEM = "FTP-Passwort wurde aus NVS geladen";
static const char loadedMaxInactivityFromNvs[] PROGMEM = "Maximale Inaktivitätszeit wurde aus NVS geladen";
static const char restoredFtpPwdFromNvs[] PROGMEM = "FTP-Passwort wurde aus NVS geladen";
static const char restoredMaxInactivityFromNvs[] PROGMEM = "Maximale Inaktivitätszeit wurde aus NVS geladen";
static const char wroteMaxInactivityToNvs[] PROGMEM = "Maximale Inaktivitätszeit wurde ins NVS geschrieben.";
static const char loadedInitialLoudnessFromNvs[] PROGMEM = "Initiale Lautstärke wurde aus NVS geladen";
static const char restoredInitialLoudnessFromNvs[] PROGMEM = "Initiale Lautstärke wurde aus NVS geladen";
static const char wroteInitialLoudnessToNvs[] PROGMEM = "Initiale Lautstärke wurde ins NVS geschrieben.";
static const char loadedMaxLoudnessFromNvs[] PROGMEM = "Maximale Lautstärke wurde aus NVS geladen";
static const char restoredMaxLoudnessFromNvs[] PROGMEM = "Maximale Lautstärke wurde aus NVS geladen";
static const char wroteMaxLoudnessToNvs[] PROGMEM = "Maximale Lautstärke wurde ins NVS geschrieben.";
static const char wroteMqttFlagToNvs[] PROGMEM = "MQTT-Flag wurde ins NVS geschrieben.";
static const char loadedMqttActiveFromNvs[] PROGMEM = "MQTT-Flag (aktiviert) wurde aus NVS geladen";
static const char loadedMqttDeactiveFromNvs[] PROGMEM = "MQTT-Flag (deaktiviert) wurde aus NVS geladen";
static const char restoredMqttActiveFromNvs[] PROGMEM = "MQTT-Flag (aktiviert) wurde aus NVS geladen";
static const char restoredMqttDeactiveFromNvs[] PROGMEM = "MQTT-Flag (deaktiviert) wurde aus NVS geladen";
static const char wroteMqttServerToNvs[] PROGMEM = "MQTT-Server wurde ins NVS geschrieben.";
static const char loadedMqttServerFromNvs[] PROGMEM = "MQTT-Server wurde aus NVS geladen";
static const char restoredMqttServerFromNvs[] PROGMEM = "MQTT-Server wurde aus NVS geladen";
static const char wroteMqttUserToNvs[] PROGMEM = "MQTT-User wurde ins NVS geschrieben.";
static const char loadedMqttUserFromNvs[] PROGMEM = "MQTT-User wurde aus NVS geladen";
static const char restoredMqttUserFromNvs[] PROGMEM = "MQTT-User wurde aus NVS geladen";
static const char wroteMqttPwdToNvs[] PROGMEM = "MQTT-Passwort wurde ins NVS geschrieben.";
static const char loadedMqttPwdFromNvs[] PROGMEM = "MQTT-Passwort wurde aus NVS geladen";
static const char restoredMqttPwdFromNvs[] PROGMEM = "MQTT-Passwort wurde aus NVS geladen";
static const char mqttWithPwd[] PROGMEM = "Verbinde zu MQTT-Server mit User und Passwort";
static const char mqttWithoutPwd[] PROGMEM = "Verbinde zu MQTT-Server ohne User und Passwort";
static const char ssidNotFoundInNvs[] PROGMEM = "SSID wurde im NVS nicht gefunden.";
@ -136,3 +136,4 @@ static const char wifiPwdNotFoundInNvs[] PROGMEM = "WLAN-Passwort wurde im NVS n
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";
static const char restoredHostnameFromNvs[] PROGMEM = "Hostname aus NVS geladen";

139
src/logmessages_EN.h

@ -0,0 +1,139 @@
static const char stillOnlineMqtt[] PROGMEM = "MQTT: still online.";
static const char tryConnectMqttS[] PROGMEM = "Trying to connect to MQTT-broker";
static const char mqttOk[] PROGMEM = "MQTT-connection established.";
static const char sleepTimerEOP[] PROGMEM = "Sleep-timer: after last track of playlist.";
static const char sleepTimerEOT[] PROGMEM = "Sleep-timer: after end of current track.";
static const char sleepTimerStop[] PROGMEM = "Sleep-timer has been disabled.";
static const char sleepTimerEO5[] PROGMEM = "Sleep-timer: after five track or end of playlist - whatever is reached first";
static const char sleepTimerAlreadyStopped[] PROGMEM = "sleep-timer is already disabled.";
static const char sleepTimerSetTo[] PROGMEM = "sleep-timer adjusted to";
static const char allowButtons[] PROGMEM = "Unlocking all keys.";
static const char lockButtons[] PROGMEM = "Locking all keys.";
static const char noPlaylistNotAllowedMqtt[] PROGMEM = "Playmode cannot be adjusted to 'no playlist' via MQTT.";
static const char playmodeChangedMQtt[] PROGMEM = "Playlist adjusted via MQTT.";
static const char noPlaymodeChangeIfIdle[] PROGMEM = "Playlist cannot be adjusted while no playlist is active.";
static const char noValidTopic[] PROGMEM = "No valid MQTT-topic";
static const char freePtr[] PROGMEM = "Releasing Pointer";
static const char freeMemory[] PROGMEM = "Free memory";
static const char writeEntryToNvs[] PROGMEM = "Storing data to NVS";
static const char freeMemoryAfterFree[] PROGMEM = "Free memory after cleaning";
static const char releaseMemoryOfOldPlaylist[] PROGMEM = "Releasing memory of old playlist.";
static const char dirOrFileDoesNotExist[] PROGMEM = "File of directory does not exist!";
static const char unableToAllocateMemForPlaylist[] PROGMEM = "Unable to allocate memory for playlist!";
static const char unableToAllocateMem[] PROGMEM = "Unable to allocate memory!";
static const char fileModeDetected[] PROGMEM = "File-mode detected.";
static const char nameOfFileFound[] PROGMEM = "File found";
static const char reallocCalled[] PROGMEM = "Reallocated memory.";
static const char unableToAllocateMemForLinearPlaylist[] PROGMEM = "Unable to allocate memory for linear playlist!";
static const char numberOfValidFiles[] PROGMEM = "Number of valid files";
static const char newLoudnessReceivedQueue[] PROGMEM = "New volume received via queue";
static const char newCntrlReceivedQueue[] PROGMEM = "Control-command received via queue";
static const char newPlaylistReceived[] PROGMEM = "New playlist received";
static const char repeatTrackDueToPlaymode[] PROGMEM = "Repeating track due to playmode configured.";
static const char repeatPlaylistDueToPlaymode[] PROGMEM = "Repeating playlist due to playmode configured.";
static const char cmndStop[] PROGMEM = "Command: stop";
static const char cmndPause[] PROGMEM = "Command: pause";
static const char cmndNextTrack[] PROGMEM = "Command: next track";
static const char cmndPrevTrack[] PROGMEM = "Command: previous track";
static const char cmndFirstTrack[] PROGMEM = "Command: first track of playlist";
static const char cmndLastTrack[] PROGMEM = "Command: last track of playlist";
static const char cmndDoesNotExist[] PROGMEM = "Command requested does not exist.";
static const char lastTrackAlreadyActive[] PROGMEM = "Already playing last track.";
static const char firstTrackAlreadyActive[] PROGMEM = "Already playing first track.";
static const char trackStartAudiobook[] PROGMEM = "Starting track in playmode from the very beginning.";
static const char trackStart[] PROGMEM = "Starting track from the very beginning.";
static const char trackChangeWebstream[] PROGMEM = "Playing from the very beginning is not possible while webradio-mode is active.";
static const char endOfPlaylistReached[] PROGMEM = "Reached end of playlist.";
static const char trackStartatPos[] PROGMEM = "Starting track at position";
static const char rfidScannerReady[] PROGMEM = "RFID-tags can now be applied...";
static const char rfidTagDetected[] PROGMEM = "RFID-tag detected: ";
static const char rfidTagReceived[] PROGMEM = "RFID-tag received";
static const char rfidTagUnknownInNvs[] PROGMEM = "RFID-tag is unkown to NVS.";
static const char goToSleepDueToIdle[] PROGMEM = "Going to deepsleep due to inactivity-timer...";
static const char goToSleepDueToTimer[] PROGMEM = "Going to deepsleep due to sleep timer...";
static const char goToSleepNow[] PROGMEM = "Going to deepsleep now!";
static const char maxLoudnessReached[] PROGMEM = "Already reached max volume!";
static const char minLoudnessReached[] PROGMEM = "Already reached min volume!";
static const char errorOccured[] PROGMEM = "Error occured!";
static const char noMp3FilesInDir[] PROGMEM = "Directory does not contain mp3-files.";
static const char modeSingleTrack[] PROGMEM = "Mode: Single track";
static const char modeSingleTrackLoop[] PROGMEM = "Mode: single track as infinite loop";
static const char modeSingleAudiobook[] PROGMEM = "Mode: audiobook";
static const char modeSingleAudiobookLoop[] PROGMEM = "Mode: audiobook as infinite loop";
static const char modeAllTrackAlphSorted[] PROGMEM = "Mode: all tracks (in alph. order) of directory";
static const char modeAllTrackRandom[] PROGMEM = "Mode: all tracks (in random. order) of directory";
static const char modeAllTrackAlphSortedLoop[] PROGMEM = "Mode: all tracks (in alph. order) of directory as infinite loop";
static const char modeAllTrackRandomLoop[] PROGMEM = "Mode: all tracks (in random order) of directory as infinite loop";
static const char modeWebstream[] PROGMEM = "Mode: webstream";
static const char webstreamNotAvailable[] PROGMEM = "Unable to access webstream as no wifi-connection is available!";
static const char modeDoesNotExist[] PROGMEM = "Playmode does not exist!";
static const char modeRepeatNone[] PROGMEM = "Repeatmode: no repeat";
static const char modeRepeatTrack[] PROGMEM = "Repeatmode: current track";
static const char modeRepeatPlaylist[] PROGMEM = "Repeatmode: whole playlist";
static const char modeRepeatTracknPlaylist[] PROGMEM = "Repeatmode: track and playlist";
static const char modificatorAllButtonsLocked[] PROGMEM = "Modificator: locking all keys via RFID-tag.";
static const char modificatorAllButtonsUnlocked[] PROGMEM = "Modificator: unlocking all keys via RFID-tag.";
static const char modificatorSleepd[] PROGMEM = "Modificator: sleep-Timer deactivated.";
static const char modificatorSleepTimer15[] PROGMEM = "Modificator: sleep-Timer enabled via RFID (15 minutes).";
static const char modificatorSleepTimer30[] PROGMEM = "Modificator: sleep-Timer enabled via RFID (30 minutes).";
static const char modificatorSleepTimer60[] PROGMEM = "Modificator: sleep-Timer enabled via RFID (60 minutes).";
static const char modificatorSleepTimer120[] PROGMEM = "Modificator: sleep-Timer enabled via RFID (2 hours).";
static const char ledsDimmedToNightmode[] PROGMEM = "Dimmed LEDs to nightmode.";
static const char modificatorNotallowedWhenIdle[] PROGMEM = "Modificator cannot be applied while playlist is inactive.";
static const char modificatorSleepAtEOT[] PROGMEM = "Modificator: adjusted sleep-timer to after end of current track.";
static const char modificatorSleepAtEOTd[] PROGMEM = "Modificator: disabled sleep-timer after end of current track.";
static const char modificatorSleepAtEOP[] PROGMEM = "Modificator: adjusted sleep-timer to after end of playlist.";
static const char modificatorSleepAtEOPd[] PROGMEM = "Modificator: disabled sleep-timer after end of playlist.";
static const char modificatorAllTrackAlphSortedLoop[] PROGMEM = "Modificator: adjusted to all tracks (in alph. order) as infinite loop.";
static const char modificatorAllTrackRandomLoop[] PROGMEM = "Modificator: adjusted to all tracks (in random order) as infinite loop.";
static const char modificatorCurTrackLoop[] PROGMEM = "Modificator: adjusted to current track as infinite loop.";
static const char modificatorCurAudiobookLoop[] PROGMEM = "Modificator: adjusted to current audiobook as infinite loop.";
static const char modificatorPlaylistLoopActive[] PROGMEM = "Modificator: adjusted to all tracks as infinite loop.";
static const char modificatorPlaylistLoopDeactive[] PROGMEM = "Modificator: disabled all tracks as infinite loop.";
static const char modificatorTrackActive[] PROGMEM = "Modificator: adjusted to current track as infinite loop.";
static const char modificatorTrackDeactive[] PROGMEM = "Modificator: disabled current track as infinite loop.";
static const char modificatorNotAllowed[] PROGMEM = "Unable to apply modificator.";
static const char modificatorLoopRev[] PROGMEM = "Modificator: infinite loop ended.";
static const char modificatorDoesNotExist[] PROGMEM = "This type of card-modificator does not exist";
static const char errorOccuredNvs[] PROGMEM = "Error occured while reading from NVS!";
static const char statementsReceivedByServer[] PROGMEM = "Data received from server";
static const char savedSsidInNvs[] PROGMEM = "Storing SSID to NVS";
static const char savedWifiPwdInNvs[] PROGMEM = "Storing wifi-password to NVS";
static const char apReady[] PROGMEM = "Started wifi-access-point";
static const char httpReady[] PROGMEM = "Started HTTP-server.";
static const char unableToMountSd[] PROGMEM = "Unable to mount sd-card.";
static const char unableToCreateVolQ[] PROGMEM = "Unable to create volume-queue.";
static const char unableToCreateRfidQ[] PROGMEM = "Unable to create RFID-queue.";
static const char unableToCreateMgmtQ[] PROGMEM = "Unable to play-management-queue.";
static const char unableToCreatePlayQ[] PROGMEM = "Unable to create track-queue..";
static const char initialBrightnessfromNvs[] PROGMEM = "Restoring initial LED-brightness from NVS";
static const char wroteInitialBrightnessToNvs[] PROGMEM = "Storing initial LED-brightness to NVS.";
static const char restoredInitialBrightnessForNmFromNvs[] PROGMEM = "Restored LED-brightness for nightmode from NVS";
static const char wroteNmBrightnessToNvs[] PROGMEM = "Stored LED-brightness for nightmode to NVS.";
static const char wroteFtpUserToNvs[] PROGMEM = "Stored FTP-user to NVS.";
static const char restoredFtpUserFromNvs[] PROGMEM = "Restored FTP-user from NVS";
static const char wroteFtpPwdToNvs[] PROGMEM = "Stored FTP-password to NVS.";
static const char restoredFtpPwdFromNvs[] PROGMEM = "Restored FTP-password from NVS";
static const char restoredMaxInactivityFromNvs[] PROGMEM = "Restored maximum inactivity-time from NVS.";
static const char wroteMaxInactivityToNvs[] PROGMEM = "Stored maximum inactivity-time to NVS.";
static const char restoredInitialLoudnessFromNvs[] PROGMEM = "Restored initial volume from NVS";
static const char wroteInitialLoudnessToNvs[] PROGMEM = "Stored initial volume to NVS.";
static const char restoredMaxLoudnessFromNvs[] PROGMEM = "Restored maximum volume from NVS";
static const char wroteMaxLoudnessToNvs[] PROGMEM = "Stored maximum volume to NVS.";
static const char wroteMqttFlagToNvs[] PROGMEM = "Stored MQTT-flag to NVS.";
static const char restoredMqttActiveFromNvs[] PROGMEM = "Restored MQTT-flag (enabled) from NVS";
static const char restoredMqttDeactiveFromNvs[] PROGMEM = "Restored MQTT-flag (disabled) from NVS";
static const char wroteMqttServerToNvs[] PROGMEM = "Stored MQTT-server to NVS.";
static const char restoredMqttServerFromNvs[] PROGMEM = "Restored MQTT-Server from NVS";
static const char wroteMqttUserToNvs[] PROGMEM = "Stored MQTT-user to NVS.";
static const char restoredMqttUserFromNvs[] PROGMEM = "Restored MQTT-user from NVS";
static const char wroteMqttPwdToNvs[] PROGMEM = "Stored MQTT-password to NVS.";
static const char restoredMqttPwdFromNvs[] PROGMEM = "Restored MQTT-password from NVS";
static const char mqttWithPwd[] PROGMEM = "Try to connect to MQTT-server with user und password";
static const char mqttWithoutPwd[] PROGMEM = "Try to connect to MQTT-server without user und password";
static const char ssidNotFoundInNvs[] PROGMEM = "Unable to find SSID to NVS.";
static const char wifiPwdNotFoundInNvs[] PROGMEM = "Unable to find wifi-password to NVS.";
static const char wifiStaticIpConfigNotFoundInNvs[] PROGMEM = "Unable to find static wifi-ip-configuration to NVS.";
static const char wifiHostnameNotSet[] PROGMEM = "Unable to find hostname-configuration to NVS.";
static const char mqttConnFailed[] PROGMEM = "Unable to establish mqtt-connection, trying again...";
static const char restoredHostnameFromNvs[] PROGMEM = "Restored hostname from NVS";

38
src/main.cpp

@ -3,6 +3,7 @@
#define FTP_ENABLE
#define NEOPIXEL_ENABLE // Don't forget configuration of NUM_LEDS
#define NEOPIXEL_REVERSE_ROTATION // Some Neopixels are adressed/soldered counter-clockwise. This can be configured here.
#define LANGUAGE 1 // 1 = deutsch; 2 = english
#include <ESP32Encoder.h>
#include "Arduino.h"
@ -24,9 +25,18 @@
#ifdef NEOPIXEL_ENABLE
#include <FastLED.h>
#endif
#if LANGUAGE == 1
#include "logmessages.h"
#include "websiteMgmt.h"
#include "websiteBasic.h"
#endif
#if LANGUAGE == 2
#include "logmessages_EN.h"
#include "websiteMgmt_EN.h"
#include "websiteBasic_EN.h"
#endif
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>
@ -2581,15 +2591,15 @@ wl_status_t wifiManager(void) {
// 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());
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(restoredHostnameFromNvs), hostname.c_str());
loggerNl(logBuf, LOGLEVEL_INFO);
} else {
loggerNl((char *) FPSTR(wifiHostnameNotSet), LOGLEVEL_INFO);
}
// ...and create a connection with it. If not successful, an access-point will is opened
// ...and create a connection with it. If not successful, an access-point is opened
WiFi.begin(_ssid, _pwd);
uint8_t tryCount=0;
@ -3083,7 +3093,7 @@ void setup() {
uint8_t nvsNLedBrightness = prefsSettings.getUChar("nLedBrightness", 0);
if (nvsNLedBrightness) {
nightLedBrightness = nvsNLedBrightness;
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %d", (char *) FPSTR(loadedInitialBrightnessForNmFromNvs), nvsNLedBrightness);
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %d", (char *) FPSTR(restoredInitialBrightnessForNmFromNvs), nvsNLedBrightness);
loggerNl(logBuf, LOGLEVEL_INFO);
} else {
prefsSettings.putUChar("nLedBrightness", nightLedBrightness);
@ -3097,7 +3107,7 @@ void setup() {
loggerNl((char *) FPSTR(wroteFtpUserToNvs), LOGLEVEL_ERROR);
} else {
strncpy(ftpUser, nvsFtpUser.c_str(), sizeof(ftpUser)/sizeof(ftpUser[0]));
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(loadedFtpUserFromNvs), nvsFtpUser.c_str());
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(restoredFtpUserFromNvs), nvsFtpUser.c_str());
loggerNl(logBuf, LOGLEVEL_INFO);
}
@ -3108,7 +3118,7 @@ void setup() {
loggerNl((char *) FPSTR(wroteFtpPwdToNvs), LOGLEVEL_ERROR);
} else {
strncpy(ftpPassword, nvsFtpPassword.c_str(), sizeof(ftpPassword)/sizeof(ftpPassword[0]));
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(loadedFtpPwdFromNvs), nvsFtpPassword.c_str());
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(restoredFtpPwdFromNvs), nvsFtpPassword.c_str());
loggerNl(logBuf, LOGLEVEL_INFO);
}
@ -3116,7 +3126,7 @@ void setup() {
uint32_t nvsMInactivityTime = prefsSettings.getUInt("mInactiviyT", 0);
if (nvsMInactivityTime) {
maxInactivityTime = nvsMInactivityTime;
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMaxInactivityFromNvs), nvsMInactivityTime);
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(restoredMaxInactivityFromNvs), nvsMInactivityTime);
loggerNl(logBuf, LOGLEVEL_INFO);
} else {
prefsSettings.putUInt("mInactiviyT", maxInactivityTime);
@ -3127,7 +3137,7 @@ void setup() {
uint32_t nvsInitialVolume = prefsSettings.getUInt("initVolume", 0);
if (nvsInitialVolume) {
initVolume = nvsInitialVolume;
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedInitialLoudnessFromNvs), nvsInitialVolume);
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(restoredInitialLoudnessFromNvs), nvsInitialVolume);
loggerNl(logBuf, LOGLEVEL_INFO);
} else {
prefsSettings.putUInt("initVolume", initVolume);
@ -3138,7 +3148,7 @@ void setup() {
uint32_t nvsMaxVolume = prefsSettings.getUInt("maxVolume", 0);
if (nvsMaxVolume) {
maxVolume = nvsMaxVolume;
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMaxLoudnessFromNvs), nvsMaxVolume);
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(restoredMaxLoudnessFromNvs), nvsMaxVolume);
loggerNl(logBuf, LOGLEVEL_INFO);
} else {
prefsSettings.putUInt("maxVolume", maxVolume);
@ -3155,12 +3165,12 @@ void setup() {
case 1:
//prefsSettings.putUChar("enableMQTT", enableMqtt);
enableMqtt = nvsEnableMqtt;
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMqttActiveFromNvs), nvsEnableMqtt);
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(restoredMqttActiveFromNvs), nvsEnableMqtt);
loggerNl(logBuf, LOGLEVEL_INFO);
break;
case 0:
enableMqtt = nvsEnableMqtt;
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMqttDeactiveFromNvs), nvsEnableMqtt);
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(restoredMqttDeactiveFromNvs), nvsEnableMqtt);
loggerNl(logBuf, LOGLEVEL_INFO);
break;
}
@ -3172,7 +3182,7 @@ void setup() {
loggerNl((char*) FPSTR(wroteMqttServerToNvs), LOGLEVEL_ERROR);
} else {
strncpy(mqtt_server, nvsMqttServer.c_str(), sizeof(mqtt_server)/sizeof(mqtt_server[0]));
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(loadedMqttServerFromNvs), nvsMqttServer.c_str());
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(restoredMqttServerFromNvs), nvsMqttServer.c_str());
loggerNl(logBuf, LOGLEVEL_INFO);
}
@ -3183,7 +3193,7 @@ void setup() {
loggerNl((char *) FPSTR(wroteMqttUserToNvs), LOGLEVEL_ERROR);
} else {
strncpy(mqttUser, nvsMqttUser.c_str(), sizeof(mqttUser)/sizeof(mqttUser[0]));
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(loadedMqttUserFromNvs), nvsMqttUser.c_str());
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(restoredMqttUserFromNvs), nvsMqttUser.c_str());
loggerNl(logBuf, LOGLEVEL_INFO);
}
@ -3194,7 +3204,7 @@ void setup() {
loggerNl((char *) FPSTR(wroteMqttPwdToNvs), LOGLEVEL_ERROR);
} else {
strncpy(mqttPassword, nvsMqttPassword.c_str(), sizeof(mqttPassword)/sizeof(mqttPassword[0]));
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(loadedMqttPwdFromNvs), nvsMqttPassword.c_str());
snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(restoredMqttPwdFromNvs), nvsMqttPassword.c_str());
loggerNl(logBuf, LOGLEVEL_INFO);
}

24
src/websiteBasic_EN.h

@ -0,0 +1,24 @@
static const char basicWebsite[] PROGMEM = "<!DOCTYPE html>\
<html>\
<head>\
<title>Wifi-configuration</title>\
</head>\
<body>\
<form action=\"/init\" method=\"POST\">\
<fieldset>\
<legend>Basic wifi-setup</legend>\
<label for=\"ssid\">SSID:</label><br>\
<input type=\"text\" id=\"ssid\" name=\"ssid\" placeholder=\"SSID\" required><br>\
<label for=\"pwd\">Password:</label><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=\"Submit\">\
</fieldset>\
</form>\
<form action=\"/restart\">\
<button type=\"submit\">Reboot</button>\
</form>\
</body>\
</html>\
";

359
src/websiteMgmt_EN.h

@ -0,0 +1,359 @@
static const char mgtWebsite[] PROGMEM = "<!DOCTYPE html>\
<html lang=\"de\">\
<head>\
<title>ESPuino-configuration</title>\
<meta charset=\"utf-8\">\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
<link rel=\"stylesheet\" href=\"https://ts-cs.de/tonuino/css/bootstrap.min.css\">\
<script src=\"https://ts-cs.de/tonuino/js/jquery.min.js\"></script>\
<script src=\"https://ts-cs.de/tonuino/js/popper.min.js\"></script>\
<script src=\"https://ts-cs.de/tonuino/js/bootstrap.min.js\"></script>\
</head>\
<body>\
<nav class=\"navbar navbar-expand-sm bg-primary navbar-dark\">\
<button class=\"navbar-toggler\" type=\"button\" data-toggle=\"collapse\" data-target=\"#navbarSupportedContent\" aria-controls=\"navbarSupportedContent\" aria-expanded=\"false\" aria-label=\"Toggle navigation\">\
<span class=\"navbar-toggler-icon\"></span>\
</button>\
<a class=\"navbar-brand\">\
<img src=\"https://raw.githubusercontent.com/biologist79/Tonuino-ESP32-I2S/master/html/tonuino_logo.png\" width=\"30\" height=\"30\" class=\"d-inline-block align-top\" alt=\"\" />\
Tonuino\
</a>\
<div class=\"collapse navbar-collapse\" id=\"collapsibleNavbar\">\
<ul class=\"navbar-nav mr-auto\">\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#wifiConfig\">Wifi</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#rfidMusicTags\">RFID-assignments</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#rfidModTags\">RFID-modifications</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#mqttConfig\">MQTT</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#ftpConfig\">FTP</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#generalConfig\">General</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"#importNvs\">NVS-importer</a>\
</li>\
<li class=\"nav-item\">\
<a class=\"nav-link\" href=\"/restart\" style=\"color: orange\">Reboot Tonuino</a>\
</li>\
</ul>\
</div>\
</nav>\
<br />\
<div class=\"container\" id=\"wifiConfig\">\
<h2>Wifi-configuration</h2>\
<form action=\"#wifiConfig\" method=\"POST\" onsubmit=\"wifiConfig('wifiConfig'); return false\">\
<div class=\"form-group col-md-6\">\
<label for=\"ssid\">Wifi-name (SSID):</label>\
<input type=\"text\" class=\"form-control\" id=\"ssid\" placeholder=\"SSID\" name=\"ssid\" required>\
<div class=\"invalid-feedback\">\
Please enter name of wifi (SSID).\
</div>\
<label for=\"pwd\">Password:</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\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<div class=\"container my-5\" id=\"rfidMusicTags\">\
<h2>RFID-assignments</h2>\
<form action=\"#rfidMusicTags\" method=\"POST\" onsubmit=\"rfidAssign('rfidMusicTags'); return false\">\
<div class=\"form-group col-md-6\">\
<label for=\"rfidIdMusic\">RFID-chip-ID (12 digits)</label>\
<input type=\"text\" class=\"form-control\" id=\"rfidIdMusic\" maxlength=\"12\" pattern=\"[0-9]{12}\" placeholder=\"%RFID_TAG_ID%\" name=\"rfidIdMusic\" required>\
<label for=\"fileOrUrl\">File, directory or URL (^ und # are not allowed)</label>\
<input type=\"text\" class=\"form-control\" id=\"fileOrUrl\" maxlength=\"255\" placeholder=\"z.B. /mp3/Hoerspiele/Yakari/Yakari_und_seine_Freunde.mp3\" pattern=\"^[^\\^#]+$\" name=\"fileOrUrl\" required>\
<label for=\"playMode\">Playmode</label>\
<select class=\"form-control\" id=\"playMode\" name=\"playMode\">\
<option value=\"1\">Single track</option>\
<option value=\"2\">Single track (infinite loop)</option>\
<option value=\"3\">Audiobook</option>\
<option value=\"4\">Audiobook (infinite loop)</option>\
<option value=\"5\">All tracks of directory (sorted)</option>\
<option value=\"6\">All tracks of directory (random)</option>\
<option value=\"7\">All tracks of directory (sorted, inf. loop)</option>\
<option value=\"9\">All tracks of directory (random, inf. loop)</option>\
<option value=\"8\">Webradio</option>\
</select>\
</div>\
<button type=\"reset\" class=\"btn btn-secondary\">Reset</button>\
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<div class=\"container my-5\" id=\"rfidModTags\">\
<h2>RFID-modifications</h2>\
<form class=\"needs-validation\" action=\"#rfidModTags\" method=\"POST\" onsubmit=\"rfidMods('rfidModTags'); return false\">\
<div class=\"form-group col-md-6\">\
<label for=\"rfidIdMod\">RFID-chip-ID (12-digits)</label>\
<input type=\"text\" class=\"form-control\" id=\"rfidIdMod\" maxlength=\"12\" pattern=\"[0-9]{12}\" placeholder=\"%RFID_TAG_ID%\" name=\"rfidIdMod\" required>\
<div class=\"invalid-feedback\">\
Please enter a 12-digits-number.\
</div>\
<label for=\"modId\">Abspielmodus</label>\
<select class=\"form-control\" id=\"modId\" name=\"modId\">\
<option value=\"100\">Lock keys</option>\
<option value=\"101\">Sleep after 15 minutes</option>\
<option value=\"102\">Sleep after 30 minutes</option>\
<option value=\"103\">Sleep after 1 hour</option>\
<option value=\"104\">Sleep after 1 hours</option>\
<option value=\"105\">Sleep after end of track</option>\
<option value=\"106\">Sleep after end of playlist</option>\
<option value=\"107\">Sleep after five tracks</option>\
<option value=\"110\">Repeat playlist (inf. loop)</option>\
<option value=\"111\">Repeat track (inf. loop)</option>\
<option value=\"112\">Dimm LEDs (nightmode)</option>\
</select>\
</div>\
<button type=\"reset\" class=\"btn btn-secondary\">Reset</button>\
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<div class=\"container my-5\" id=\"mqttConfig\">\
<h2>MQTT-configuration</h2>\
<form class=\"needs-validation\" action=\"#mqttConfig\" method=\"POST\" onsubmit=\"mqttSettings('mqttConfig'); return false\">\
<div class=\"form-check col-md-6\">\
<input class=\"form-check-input\" type=\"checkbox\" value=\"1\" id=\"mqttEnable\" name=\"mqttEnable\" %MQTT_ENABLE%>\
<label class=\"form-check-label\" for=\"mqttEnable\">\
Enable MQTT\
</label>\
</div>\
<div class=\"form-group my-2 col-md-6\">\
<label for=\"mqttServer\">MQTT-server (IP-address)</label>\
<input type=\"text\" class=\"form-control\" id=\"mqttServer\" pattern=\"^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$\" minlength=\"7\" maxlength=\"15\" placeholder=\"z.B. 192.168.2.89\" name=\"mqttServer\" value=\"%MQTT_SERVER%\">\
<div class=\"invalid-feedback\">\
Please enter a valid IPv4-address, e.g. 192.168.2.89.\
</div>\
<label for=\"mqttUser\">MQTT-username (optional):</label>\
<input type=\"text\" class=\"form-control\" id=\"mqttUser\" maxlength=\"15\" placeholder=\"Benutzername\" name=\"mqttUser\" value=\"%MQTT_USER%\">\
<label for=\"mqttPwd\">Password (optional):</label>\
<input type=\"password\" class=\"form-control\" id=\"mqttPwd\" maxlength=\"15\" placeholder=\"Passwort\" name=\"mqttPwd\" value=\"%MQTT_PWD%\">\
</div>\
<button type=\"reset\" class=\"btn btn-secondary\">Reset</button>\
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<div class=\"container\" id=\"ftpConfig\">\
<h2>FTP-configuration</h2>\
<form action=\"#ftpConfig\" method=\"POST\" onsubmit=\"ftpSettings('ftpConfig'); return false\">\
<div class=\"form-group col-md-6\">\
<label for=\"ftpUser\">FTP-username:</label>\
<input type=\"text\" class=\"form-control\" id=\"ftpUser\" maxlength=\"32\" placeholder=\"Benutzername\" name=\"ftpUser\" value=\"%FTP_USER%\" required>\
<label for=\"pwd\">password:</label>\
<input type=\"password\" class=\"form-control\" id=\"ftpPwd\" maxlength=\"32\" placeholder=\"Passwort\" name=\"ftpPwd\" value=\"%FTP_PWD%\" required>\
</div>\
<button type=\"reset\" class=\"btn btn-secondary\">Reset</button>\
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<div class=\"container my-5\" id=\"generalConfig\">\
<h2>General configuration</h2>\
<form action=\"#generalConfig\" method=\"POST\" onsubmit=\"genSettings('generalConfig'); return false\">\
<div class=\"form-group col-md-6\">\
<label for=\"initialVolume\">Volume after start</label>\
<input type=\"number\" min=\"1\" max=\"21\" class=\"form-control\" id=\"initialVolume\" name=\"initialVolume\" value=\"%INIT_VOLUME%\" required>\
<label for=\"maxVolume\">Maximum volume</label>\
<input type=\"number\" min=\"1\" max=\"21\" class=\"form-control\" id=\"maxVolume\" name=\"maxVolume\" value=\"%MAX_VOLUME%\" required>\
</div>\
<div class=\"form-group col-md-6\">\
<label for=\"initBrightness\">Neopixel-brightness after start</label>\
<input type=\"number\" min=\"0\" max=\"255\" class=\"form-control\" id=\"initBrightness\" name=\"initBrightness\" value=\"%INIT_LED_BRIGHTBESS%\" required>\
<label for=\"nightBrightness\">Neopixel-brightness in nightmode</label>\
<input type=\"number\" min=\"0\" max=\"255\" class=\"form-control\" id=\"nightBrightness\" name=\"nightBrightness\" value=\"%NIGHT_LED_BRIGHTBESS%\" required>\
</div>\
<div class=\"form-group col-md-6\">\
<label for=\"inactivityTime\">Deepsleep after inactivity (minutes)</label>\
<input type=\"number\" min=\"1\" max=\"1440\" class=\"form-control\" id=\"inactivityTime\" name=\"inactivityTime\" value=\"%MAX_INACTIVITY%\" required>\
</div>\
<button type=\"reset\" class=\"btn btn-secondary\">Reset</button>\
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<div class=\"container my-5\" id=\"importNvs\">\
<h2>NVS-importer</h2>\
<form action=\"/upload\" enctype=\"multipart/form-data\" method=\"POST\">\
<div class=\"form-group\">\
<label for=\"nvsUpload\">Backup-files can be imported here.</label>\
<input type=\"file\" class=\"form-control-file\" id=\"nvsUpload\" name=\"nvsUpload\" accept=\".txt\">\
</div>\
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>\
</form>\
<div class=\"messages col-md-6 my-2\"></div>\
</div>\
<script>\
var lastIdclicked = '';\
var errorBox = '<div class=\"alert alert-danger alert-dismissible fade show\" role=\"alert\">Error occured!<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button></div>';\
var okBox = '<div class=\"alert alert-success alert-dismissible fade show\" role=\"alert\">Action successful.<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button></div>';\
\
var socket = new WebSocket(\"ws://%IPv4%/ws\");\
\
function connect() {\
socket = new WebSocket(\"ws://%IPv4%/ws\");\
}\
\
function ping() {\
var myObj = {\
\"ping\": {\
ping: 'ping'\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
tm = setTimeout(function () {\
alert(\"Connection to tonuino is broken!\\nPlease refresh this website.\");\
}, 5000);\
}\
\
function pong() {\
clearTimeout(tm);\
}\
\
socket.onopen = function () {\
setInterval(ping, 15000);\
};\
\
socket.onclose = function(e) {\
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);\
setTimeout(function() {\
connect();\
}, 5000);\
};\
\
socket.onerror = function(err) {\
console.error('Socket encountered error: ', err.message, 'Closing socket');\
socket.close();\
};\
\
socket.onmessage = function(event) {\
console.log(event.data);\
var socketMsg = JSON.parse(event.data);\
if (socketMsg.rfidId != null) {\
document.getElementById('rfidIdMod').value = socketMsg.rfidId;\
document.getElementById('rfidIdMusic').value = socketMsg.rfidId;\
$(\"#rfidIdMusic\").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);\
$(\"#rfidIdMod\").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500);\
\
} if (socketMsg.status != null) {\
if (socketMsg.status == 'ok') {\
$(\"#\" + lastIdclicked).find('.messages').html(okBox);\
} else {\
$(\"#\" + lastIdclicked).find('.messages').html(errorBox);\
}\
} if (socketMsg.pong != null) {\
if (socketMsg.pong == 'pong') {\
pong();\
}\
}\
};\
\
function genSettings(clickedId) {\
lastIdclicked = clickedId;\
var myObj = {\
\"general\": {\
iVol: document.getElementById('initialVolume').value,\
mVol: document.getElementById('maxVolume').value,\
iBright: document.getElementById('initBrightness').value,\
nBright: document.getElementById('nightBrightness').value,\
iTime: document.getElementById('inactivityTime').value\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
}\
\
function ftpSettings(clickedId) {\
lastIdclicked = clickedId;\
var myObj = {\
\"ftp\": {\
ftpUser: document.getElementById('ftpUser').value,\
ftpPwd: document.getElementById('ftpPwd').value\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
}\
\
function mqttSettings(clickedId) {\
lastIdclicked = clickedId;\
var val;\
if (document.getElementById('mqttEnable').checked) {\
val = document.getElementById('mqttEnable').value;\
} else {\
val = 0;\
}\
var myObj = {\
\"mqtt\": {\
mqttEnable: val,\
mqttServer: document.getElementById('mqttServer').value,\
mqttUser: document.getElementById('mqttUser').value,\
mqttPwd: document.getElementById('mqttPwd').value\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
}\
\
function rfidMods(clickedId) {\
lastIdclicked = clickedId;\
var myObj = {\
\"rfidMod\": {\
rfidIdMod: document.getElementById('rfidIdMod').value,\
modId: document.getElementById('modId').value\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
}\
\
function removeTrSlash(str) {\
if(str.substr(-1) === '/') {\
return str.substr(0, str.length - 1);\
}\
return str;\
}\
\
function rfidAssign(clickedId) {\
lastIdclicked = clickedId;\
var myObj = {\
\"rfidAssign\": {\
rfidIdMusic: document.getElementById('rfidIdMusic').value,\
fileOrUrl: removeTrSlash(document.getElementById('fileOrUrl').value),\
playMode: document.getElementById('playMode').value\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
}\
\
function wifiConfig(clickedId) {\
lastIdclicked = clickedId;\
var myObj = {\
\"wifiConfig\": {\
ssid: document.getElementById('ssid').value,\
pwd: document.getElementById('pwd').value,\
hostname: document.getElementById('hostname').value\
}\
};\
var myJSON = JSON.stringify(myObj);\
socket.send(myJSON);\
}\
</script>\
</body>\
</html>\
";
Loading…
Cancel
Save