This commit is contained in:
Paul
2019-11-09 15:19:48 +01:00
parent 26b84b1281
commit 135d844a57
8 changed files with 117 additions and 69 deletions

View File

@@ -18,6 +18,7 @@ There are breaking changes in this release. See `publish_time` below and make su
- Added build scripts for automated CI with TravisCI - Added build scripts for automated CI with TravisCI
- Implemented timezone support and automatic adjustment, also taking daylight saving times into account - Implemented timezone support and automatic adjustment, also taking daylight saving times into account
- Added `kick` command to reset core services like NTP, Web, Web Sockets - Added `kick` command to reset core services like NTP, Web, Web Sockets
- Added WiFi static IP (setting done in WebUI only)
### Fixed ### Fixed

View File

@@ -80,6 +80,10 @@ MyESP::MyESP() {
_network_password = nullptr; _network_password = nullptr;
_network_ssid = nullptr; _network_ssid = nullptr;
_network_wmode = 1; // default AP _network_wmode = 1; // default AP
_network_staticip = nullptr;
_network_gatewayip = nullptr;
_network_nmask = nullptr;
_network_dnsip = nullptr;
_wifi_callback_f = nullptr; _wifi_callback_f = nullptr;
_wifi_connected = false; _wifi_connected = false;
@@ -534,7 +538,15 @@ void MyESP::_wifi_setup() {
jw.enableSTA(true); // Enable STA mode (connecting to a router) jw.enableSTA(true); // Enable STA mode (connecting to a router)
jw.enableScan(false); // Configure it to not scan available networks and connect in order of dBm jw.enableScan(false); // Configure it to not scan available networks and connect in order of dBm
jw.cleanNetworks(); // Clean existing network configuration jw.cleanNetworks(); // Clean existing network configuration
jw.addNetwork(_network_ssid, _network_password); // Add a network
if (_hasValue(_network_staticip)) {
#if MYESP_DEBUG
myDebug_P(PSTR("[WIFI] Using fixed IP"));
#endif
jw.addNetwork(_network_ssid, _network_password, _network_staticip, _network_gatewayip, _network_nmask, _network_dnsip); // fixed IP
} else {
jw.addNetwork(_network_ssid, _network_password); // use DHCP
}
} }
// set the callback function for the OTA onstart // set the callback function for the OTA onstart
@@ -698,7 +710,7 @@ void MyESP::_consoleShowHelp() {
myDebug_P(PSTR("*")); myDebug_P(PSTR("*"));
myDebug_P(PSTR("* Commands:")); myDebug_P(PSTR("* Commands:"));
myDebug_P(PSTR("* ?/help=show commands, CTRL-D/quit=close telnet session")); myDebug_P(PSTR("* ?/help=show commands, CTRL-D/quit=close telnet session"));
myDebug_P(PSTR("* set, system, restart, mqttlog, kick")); myDebug_P(PSTR("* set, system, restart, mqttlog, kick, save"));
#ifdef CRASH #ifdef CRASH
myDebug_P(PSTR("* crash <dump | clear | test [n]>")); myDebug_P(PSTR("* crash <dump | clear | test [n]>"));
@@ -772,6 +784,9 @@ void MyESP::_printSetCommands() {
} }
} }
myDebug_P(PSTR("")); myDebug_P(PSTR(""));
if (_hasValue(_network_staticip)) {
myDebug_P(PSTR(" wifi_staticip=%s"), _network_staticip);
}
myDebug_P(PSTR(" mqtt_enabled=%s"), (_mqtt_enabled) ? "on" : "off"); myDebug_P(PSTR(" mqtt_enabled=%s"), (_mqtt_enabled) ? "on" : "off");
if (_hasValue(_mqtt_ip)) { if (_hasValue(_mqtt_ip)) {
myDebug_P(PSTR(" mqtt_ip=%s"), _mqtt_ip); myDebug_P(PSTR(" mqtt_ip=%s"), _mqtt_ip);
@@ -1025,6 +1040,13 @@ void MyESP::_telnetCommand(char * commandLine) {
return; return;
} }
// save everything
if ((strcmp(ptrToCommandName, "save") == 0) && (wc == 1)) {
_fs_writeConfig();
_fs_createCustomConfig();
return;
}
// show system stats // show system stats
if ((strcmp(ptrToCommandName, "quit") == 0) && (wc == 1)) { if ((strcmp(ptrToCommandName, "quit") == 0) && (wc == 1)) {
myDebug_P(PSTR("[TELNET] exiting telnet session")); myDebug_P(PSTR("[TELNET] exiting telnet session"));
@@ -1793,6 +1815,10 @@ bool MyESP::_fs_loadConfig() {
_network_ssid = strdup(network["ssid"] | ""); _network_ssid = strdup(network["ssid"] | "");
_network_password = strdup(network["password"] | ""); _network_password = strdup(network["password"] | "");
_network_wmode = network["wmode"]; // 0 is client, 1 is AP _network_wmode = network["wmode"]; // 0 is client, 1 is AP
_network_staticip = strdup(network["staticip"] | "");
_network_gatewayip = strdup(network["gatewayip"] | "");
_network_nmask = strdup(network["nmask"] | "");
_network_dnsip = strdup(network["dnsip"] | "");
JsonObject general = doc["general"]; JsonObject general = doc["general"];
_general_password = strdup(general["password"] | MYESP_HTTP_PASSWORD); _general_password = strdup(general["password"] | MYESP_HTTP_PASSWORD);
@@ -2024,6 +2050,10 @@ bool MyESP::_fs_writeConfig() {
network["ssid"] = _network_ssid; network["ssid"] = _network_ssid;
network["password"] = _network_password; network["password"] = _network_password;
network["wmode"] = _network_wmode; network["wmode"] = _network_wmode;
network["staticip"] = _network_staticip;
network["gatewayip"] = _network_gatewayip;
network["nmask"] = _network_nmask;
network["dnsip"] = _network_dnsip;
JsonObject general = doc.createNestedObject("general"); JsonObject general = doc.createNestedObject("general");
general["password"] = _general_password; general["password"] = _general_password;

View File

@@ -9,7 +9,7 @@
#ifndef MyESP_h #ifndef MyESP_h
#define MyESP_h #define MyESP_h
#define MYESP_VERSION "1.2.18" #define MYESP_VERSION "1.2.19"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
@@ -367,6 +367,10 @@ class MyESP {
char * _network_ssid; char * _network_ssid;
char * _network_password; char * _network_password;
uint8_t _network_wmode; uint8_t _network_wmode;
char * _network_staticip;
char * _network_gatewayip;
char * _network_nmask;
char * _network_dnsip;
bool _wifi_connected; bool _wifi_connected;
String _getESPhostname(); String _getESPhostname();

View File

@@ -257,6 +257,6 @@
</div> </div>
</div> </div>
<div class="row form-group" style="text-align: center;"> <div class="row form-group" style="text-align: center;">
<button onclick="refreshEMS()" class="btn btn-info">Refresh</button> <button onclick="refreshCustomStatus()" class="btn btn-info">Refresh</button>
</div> </div>
</div> </div>

View File

@@ -1 +1 @@
#define APP_VERSION "1.9.4b9" #define APP_VERSION "1.9.4b10"

View File

@@ -308,10 +308,10 @@
</form> </form>
</div> </div>
</div> </div>
<div class="row form-group" style="display:none" id="hidessid"> <div class="row form-group" style="display:none" id="hideclient">
<label class="col-xs-3">SSID<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" <label class="col-xs-3">SSID<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="wifi Network Name"></i></label> data-content="WiFi Network Name"></i></label>
<span class="col-xs-7 col-md-5"> <span class="col-xs-7 col-md-5">
<input class="form-control input-sm" id="inputtohide" type="text" name="ap_ssid"> <input class="form-control input-sm" id="inputtohide" type="text" name="ap_ssid">
<select class="form-control input-sm" style="display:none;" id="ssid" onchange="listBSSID();"></select> <select class="form-control input-sm" style="display:none;" id="ssid" onchange="listBSSID();"></select>
@@ -320,16 +320,51 @@
<button id="scanb" type="button" class="btn btn-info btn-xs" style="display:none;" <button id="scanb" type="button" class="btn btn-info btn-xs" style="display:none;"
onclick="scanWifi()">Scan...</button> onclick="scanWifi()">Scan...</button>
</span> </span>
</div>
<div class="row form-group" style="display:none" id="hidepasswd"> <br><br>
<label class="col-xs-3">Password<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" <label class="col-xs-3">Password<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right" aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="wifi Password"></i></label> data-content="WiFi Password"></i></label>
<span class="col-xs-9 col-md-5"> <span class="col-xs-9 col-md-5">
<input id="wifipass" class="form-control input-sm" name="ap_passwd" type="password"> <input id="wifipass" class="form-control input-sm" name="ap_passwd" type="password">
</span> </span>
</div>
<br><br>
<h6 style="margin-left: 10px;" class="text-muted">If you're not using DHCP and want a fixed IP address enter the values below:</h6>
<br> <br>
<label class="col-xs-3">Static IP<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="static IP address"></i></label>
<span class="col-xs-9 col-md-5">
<input type="text" class="form-control input-sm" id="staticip" placeholder="">
</span>
<br><br>
<label class="col-xs-3">Gateway IP<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="gateway IP address"></i></label>
<span class="col-xs-9 col-md-5">
<input type="text" class="form-control input-sm" id="gatewayip" placeholder="">
</span>
<br><br>
<label class="col-xs-3">Network Mask<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="network mask"></i></label>
<span class="col-xs-9 col-md-5">
<input type="text" class="form-control input-sm" id="nmask" placeholder="255.255.255.0">
</span>
<br><br>
<label class="col-xs-3">DNS IP<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="DNS IP address"></i></label>
<span class="col-xs-9 col-md-5">
<input type="text" class="form-control input-sm" id="dnsip" placeholder="">
</span>
</div>
<br><br>
<div class="col-xs-9 col-md-8"> <div class="col-xs-9 col-md-8">
<button onclick="savenetwork()" class="btn btn-primary btn-sm pull-right">Save</button> <button onclick="savenetwork()" class="btn btn-primary btn-sm pull-right">Save</button>
</div> </div>
@@ -338,7 +373,8 @@
<div id="ntpcontent"> <div id="ntpcontent">
<br> <br>
<legend>Time Settings</legend> <legend>Time Settings</legend>
<h6 class="text-muted">With Network Time Protocol (NTP) enabled, all times are adjusted to the local timezone and <h6 class="text-muted">With Network Time Protocol (NTP) enabled, all times are adjusted to the local timezone
and
respect daylight saving time (DST)</h6> respect daylight saving time (DST)</h6>
<br> <br>
<div class="row form-group"> <div class="row form-group">
@@ -354,10 +390,7 @@
<label class="col-xs-3">Browser Time</label> <label class="col-xs-3">Browser Time</label>
<span id="rtc" class="col-xs-9 col-md-5"></span> <span id="rtc" class="col-xs-9 col-md-5"></span>
<div class="col-xs-3"> <div class="col-xs-3">
<button onclick="syncBrowserTime()" class="btn btn-info btn-sm">Sync Browser Time to Device</button><i <button onclick="syncBrowserTime()" class="btn btn-info btn-sm">Sync Browser Time to Device</button>
style="margin-left: 10px;" class="glyphicon glyphicon-info-sign" aria-hidden="true"
data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="Use your browser time. Useful when the system does not have an internet connection."></i>
</div> </div>
</div> </div>

View File

@@ -26,39 +26,7 @@ var formData = new FormData();
var nextIsNotJson = false; var nextIsNotJson = false;
var config = { var config = {};
"command": "configfile",
"network": {
"ssid": "",
"wmode": 1,
"password": ""
},
"general": {
"hostname": "",
"serial": false,
"password": "admin",
"log_events": true,
"version": "1.0.0"
},
"mqtt": {
"enabled": false,
"ip": "",
"port": 1883,
"qos": 1,
"keepalive": 60,
"retain": true,
"base": "",
"user": "",
"password": "",
"heartbeat": false
},
"ntp": {
"server": "pool.ntp.org",
"interval": 60,
"timezone": 2,
"enabled": true
}
};
function browserTime() { function browserTime() {
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
@@ -217,6 +185,10 @@ function savenetwork() {
config.network.wmode = wmode; config.network.wmode = wmode;
config.network.password = document.getElementById("wifipass").value; config.network.password = document.getElementById("wifipass").value;
config.network.staticip = document.getElementById("staticip").value;
config.network.gatewayip = document.getElementById("gatewayip").value;
config.network.nmask = document.getElementById("nmask").value;
config.network.dnsip = document.getElementById("dnsip").value;
saveconfig(); saveconfig();
} }
@@ -293,15 +265,13 @@ function inProgressUpload() {
function handleSTA() { function handleSTA() {
document.getElementById("scanb").style.display = "block"; document.getElementById("scanb").style.display = "block";
document.getElementById("hidessid").style.display = "block"; document.getElementById("hideclient").style.display = "block";
document.getElementById("hidepasswd").style.display = "block";
} }
function handleAP() { function handleAP() {
document.getElementById("ssid").style.display = "none"; document.getElementById("ssid").style.display = "none";
document.getElementById("scanb").style.display = "none"; document.getElementById("scanb").style.display = "none";
document.getElementById("hidessid").style.display = "none"; document.getElementById("hideclient").style.display = "none";
document.getElementById("hidepasswd").style.display = "none";
document.getElementById("inputtohide").style.display = "block"; document.getElementById("inputtohide").style.display = "block";
} }
@@ -317,6 +287,11 @@ function listnetwork() {
handleSTA(); handleSTA();
} }
document.getElementById("staticip").value = config.network.staticip;
document.getElementById("gatewayip").value = config.network.gatewayip;
document.getElementById("nmask").value = config.network.nmask;
document.getElementById("dnsip").value = config.network.dnsip;
} }
function listgeneral() { function listgeneral() {
@@ -985,7 +960,7 @@ function start() {
}); });
} }
function refreshEMS() { function refreshCustomStatus() {
websock.send("{\"command\":\"custom_status\"}"); websock.send("{\"command\":\"custom_status\"}");
} }

View File

@@ -64,13 +64,18 @@ var configfile = {
"network": { "network": {
"ssid": "myssid", "ssid": "myssid",
"wmode": 0, "wmode": 0,
"password": "password" "password": "password",
"password": "",
"staticip": "",
"gatewayip": "",
"nmask": "",
"dnsip": ""
}, },
"general": { "general": {
"hostname": "myesp", "hostname": "ems-esp",
"password": "admin", "password": "admin",
"serial": true, "serial": true,
"version": "1.9.1", "version": "1.0.0",
"log_events": true "log_events": true
}, },
"mqtt": { "mqtt": {
@@ -87,7 +92,7 @@ var configfile = {
}, },
"ntp": { "ntp": {
"server": "pool.ntp.org", "server": "pool.ntp.org",
"interval": 60, "interval": 720,
"timezone": 2, "timezone": 2,
"enabled": true "enabled": true
} }