mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
added static IP support - https://github.com/proddy/EMS-ESP/issues/231
This commit is contained in:
@@ -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
|
||||
- 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 WiFi static IP (setting done in WebUI only)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -77,9 +77,13 @@ MyESP::MyESP() {
|
||||
_mqtt_will_offline_payload = strdup(MQTT_WILL_OFFLINE_PAYLOAD);
|
||||
|
||||
// network
|
||||
_network_password = nullptr;
|
||||
_network_ssid = nullptr;
|
||||
_network_wmode = 1; // default AP
|
||||
_network_password = nullptr;
|
||||
_network_ssid = nullptr;
|
||||
_network_wmode = 1; // default AP
|
||||
_network_staticip = nullptr;
|
||||
_network_gatewayip = nullptr;
|
||||
_network_nmask = nullptr;
|
||||
_network_dnsip = nullptr;
|
||||
|
||||
_wifi_callback_f = nullptr;
|
||||
_wifi_connected = false;
|
||||
@@ -530,11 +534,19 @@ void MyESP::_wifi_setup() {
|
||||
jw.enableAP(false);
|
||||
}
|
||||
|
||||
jw.enableAPFallback(true); // AP mode only as fallback
|
||||
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.cleanNetworks(); // Clean existing network configuration
|
||||
jw.addNetwork(_network_ssid, _network_password); // Add a network
|
||||
jw.enableAPFallback(true); // AP mode only as fallback
|
||||
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.cleanNetworks(); // Clean existing network configuration
|
||||
|
||||
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
|
||||
@@ -698,7 +710,7 @@ void MyESP::_consoleShowHelp() {
|
||||
myDebug_P(PSTR("*"));
|
||||
myDebug_P(PSTR("* Commands:"));
|
||||
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
|
||||
myDebug_P(PSTR("* crash <dump | clear | test [n]>"));
|
||||
@@ -772,6 +784,9 @@ void MyESP::_printSetCommands() {
|
||||
}
|
||||
}
|
||||
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");
|
||||
if (_hasValue(_mqtt_ip)) {
|
||||
myDebug_P(PSTR(" mqtt_ip=%s"), _mqtt_ip);
|
||||
@@ -1025,6 +1040,13 @@ void MyESP::_telnetCommand(char * commandLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
// save everything
|
||||
if ((strcmp(ptrToCommandName, "save") == 0) && (wc == 1)) {
|
||||
_fs_writeConfig();
|
||||
_fs_createCustomConfig();
|
||||
return;
|
||||
}
|
||||
|
||||
// show system stats
|
||||
if ((strcmp(ptrToCommandName, "quit") == 0) && (wc == 1)) {
|
||||
myDebug_P(PSTR("[TELNET] exiting telnet session"));
|
||||
@@ -1793,6 +1815,10 @@ bool MyESP::_fs_loadConfig() {
|
||||
_network_ssid = strdup(network["ssid"] | "");
|
||||
_network_password = strdup(network["password"] | "");
|
||||
_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"];
|
||||
_general_password = strdup(general["password"] | MYESP_HTTP_PASSWORD);
|
||||
@@ -2020,10 +2046,14 @@ bool MyESP::_fs_writeConfig() {
|
||||
|
||||
root["command"] = "configfile"; // header, important!
|
||||
|
||||
JsonObject network = doc.createNestedObject("network");
|
||||
network["ssid"] = _network_ssid;
|
||||
network["password"] = _network_password;
|
||||
network["wmode"] = _network_wmode;
|
||||
JsonObject network = doc.createNestedObject("network");
|
||||
network["ssid"] = _network_ssid;
|
||||
network["password"] = _network_password;
|
||||
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");
|
||||
general["password"] = _general_password;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef MyESP_h
|
||||
#define MyESP_h
|
||||
|
||||
#define MYESP_VERSION "1.2.18"
|
||||
#define MYESP_VERSION "1.2.19"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
@@ -367,6 +367,10 @@ class MyESP {
|
||||
char * _network_ssid;
|
||||
char * _network_password;
|
||||
uint8_t _network_wmode;
|
||||
char * _network_staticip;
|
||||
char * _network_gatewayip;
|
||||
char * _network_nmask;
|
||||
char * _network_dnsip;
|
||||
bool _wifi_connected;
|
||||
String _getESPhostname();
|
||||
|
||||
|
||||
@@ -257,6 +257,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
@@ -1 +1 @@
|
||||
#define APP_VERSION "1.9.4b9"
|
||||
#define APP_VERSION "1.9.4b10"
|
||||
|
||||
@@ -308,10 +308,10 @@
|
||||
</form>
|
||||
</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"
|
||||
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">
|
||||
<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>
|
||||
@@ -320,16 +320,51 @@
|
||||
<button id="scanb" type="button" class="btn btn-info btn-xs" style="display:none;"
|
||||
onclick="scanWifi()">Scan...</button>
|
||||
</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"
|
||||
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">
|
||||
<input id="wifipass" class="form-control input-sm" name="ap_passwd" type="password">
|
||||
</span>
|
||||
|
||||
<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>
|
||||
<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><br>
|
||||
<div class="col-xs-9 col-md-8">
|
||||
<button onclick="savenetwork()" class="btn btn-primary btn-sm pull-right">Save</button>
|
||||
</div>
|
||||
@@ -338,7 +373,8 @@
|
||||
<div id="ntpcontent">
|
||||
<br>
|
||||
<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>
|
||||
<br>
|
||||
<div class="row form-group">
|
||||
@@ -354,10 +390,7 @@
|
||||
<label class="col-xs-3">Browser Time</label>
|
||||
<span id="rtc" class="col-xs-9 col-md-5"></span>
|
||||
<div class="col-xs-3">
|
||||
<button onclick="syncBrowserTime()" class="btn btn-info btn-sm">Sync Browser Time to Device</button><i
|
||||
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>
|
||||
<button onclick="syncBrowserTime()" class="btn btn-info btn-sm">Sync Browser Time to Device</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -26,39 +26,7 @@ var formData = new FormData();
|
||||
|
||||
var nextIsNotJson = false;
|
||||
|
||||
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
|
||||
}
|
||||
};
|
||||
var config = {};
|
||||
|
||||
function browserTime() {
|
||||
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.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();
|
||||
}
|
||||
@@ -293,15 +265,13 @@ function inProgressUpload() {
|
||||
|
||||
function handleSTA() {
|
||||
document.getElementById("scanb").style.display = "block";
|
||||
document.getElementById("hidessid").style.display = "block";
|
||||
document.getElementById("hidepasswd").style.display = "block";
|
||||
document.getElementById("hideclient").style.display = "block";
|
||||
}
|
||||
|
||||
function handleAP() {
|
||||
document.getElementById("ssid").style.display = "none";
|
||||
document.getElementById("scanb").style.display = "none";
|
||||
document.getElementById("hidessid").style.display = "none";
|
||||
document.getElementById("hidepasswd").style.display = "none";
|
||||
document.getElementById("hideclient").style.display = "none";
|
||||
|
||||
document.getElementById("inputtohide").style.display = "block";
|
||||
}
|
||||
@@ -317,6 +287,11 @@ function listnetwork() {
|
||||
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() {
|
||||
@@ -985,7 +960,7 @@ function start() {
|
||||
});
|
||||
}
|
||||
|
||||
function refreshEMS() {
|
||||
function refreshCustomStatus() {
|
||||
websock.send("{\"command\":\"custom_status\"}");
|
||||
}
|
||||
|
||||
|
||||
@@ -64,13 +64,18 @@ var configfile = {
|
||||
"network": {
|
||||
"ssid": "myssid",
|
||||
"wmode": 0,
|
||||
"password": "password"
|
||||
"password": "password",
|
||||
"password": "",
|
||||
"staticip": "",
|
||||
"gatewayip": "",
|
||||
"nmask": "",
|
||||
"dnsip": ""
|
||||
},
|
||||
"general": {
|
||||
"hostname": "myesp",
|
||||
"hostname": "ems-esp",
|
||||
"password": "admin",
|
||||
"serial": true,
|
||||
"version": "1.9.1",
|
||||
"version": "1.0.0",
|
||||
"log_events": true
|
||||
},
|
||||
"mqtt": {
|
||||
@@ -87,7 +92,7 @@ var configfile = {
|
||||
},
|
||||
"ntp": {
|
||||
"server": "pool.ntp.org",
|
||||
"interval": 60,
|
||||
"interval": 720,
|
||||
"timezone": 2,
|
||||
"enabled": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user