Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = { // eslint-disable-line no-undef
],
"linebreak-style": [
"error",
"unix",
(require("os").EOL === "\r\n" ? "windows" : "unix"),
],
curly: [
"error",
Expand Down
7 changes: 4 additions & 3 deletions docs/config-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ Adding the field `"control": "select",` will turn the item into a drop down menu

Adding the field `"control": "slider",` will turn the itemm into a slider, the `min`, `max` and `step` properties will also apply to the slider. This is only valid for numeric types.

There are a few unique parameters:
There are a few special parameters:

* The configuration parameter `projectName` is unique in this framework. You can remove it, but if you use a parameter with this name, it will be shown as the header title in the web interface :).
* The parameter named `language` is also unique and can be used to change the language of the web interface. Supported languages are placed in the folder `gui/js/lang`. Change the language code and rebuild the HTML interface to change the language. If your language is not yet supported, feel free to create a pull request for it.
* The configuration parameter `projectName` is special in this framework. You can remove it, but if you use a parameter with this name, it will be shown as the header title in the web interface :).
* The parameter named `language` is also special and can be used to change the language of the web interface. Supported languages are placed in the folder `gui/js/lang`. Change the language code and rebuild the HTML interface to change the language. If your language is not yet supported, feel free to create a pull request for it.
* The parameter named `projectVersion` can be added to the configuration file, and will add this version string to the header of the web interface, and can of course be used in your code as well.
* `hostName` optional special parameter can be used to explicitly set initial, and enable GUI configuration, of the device's Wifi Hostname. Not specifying a hostname usually results in the device name being `ESP-<MAC Address last 3 bytes hex encoded>`.

For this example, the pre-build python script `preBuildConfig.py` will generate the following two files. These should be fairly self explanatory and show how the JSON file is translated into a C struct.

Expand Down
1 change: 1 addition & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void loop()
//software interrupts
WiFiManager.loop();
updater.loop();
configManager.loop(); // Ensures config changes survive reboot by persisting to EEPROM
}
```

Expand Down
11 changes: 6 additions & 5 deletions examples/configManager/configManagerExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ void loop()
//in this case make sure you set all values
configData newData =
{
"Generic ESP8266 Firmware",
configManager.data.dummyInt + 1,
true,
1.2345,
"invisible!"
{.projectName2 = "Generic ESP8266 Firmware"},
{.hostName = "ESP8266-01"},
.dummyInt = configManager.data.dummyInt + 1,
.dummyBool = true,
.dummyFloat = 1.2345,
.dummyString = "invisible!"
};

///The saveExternal function copies the object to EEPROM
Expand Down
7 changes: 7 additions & 0 deletions examples/configManager/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"length": 32,
"value": "ESP8266 IoT Framework"
},
{
"name": "hostName",
"label": "Host Name",
"type": "char",
"length": 32,
"value": "ESP8266-01"
},
{
"name": "dummyInt",
"label": "Dummy Int",
Expand Down
14 changes: 12 additions & 2 deletions gui/js/comp/WifiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ if (Config.find(entry => entry.name === "language")) {
}

export function WifiPage(props) {
const [state, setState] = useState({ captivePortal: [], ssid: []});
const [state, setState] = useState({
captivePortal: [],
ssid: [],
hostName: [],
ipAddress: [],
macAddress: [],
});
const [forgetModal, setForgetModal] = useState(false);
const [saveModal, setSaveModal] = useState(false);
const [dhcpForm, setDhcpForm] = useState(true);
Expand Down Expand Up @@ -84,7 +90,11 @@ export function WifiPage(props) {
if (state.captivePortal === true) {
connectedTo = loc.wifiCP;
} else if (state.captivePortal === false) {
connectedTo = <>{loc.wifiConn} {state.ssid} (<a onClick={() => setForgetModal(true)}>{loc.wifiForget}</a>)</>;
connectedTo = <>{loc.wifiConn} {state.ssid} (<a onClick={() => setForgetModal(true)}>{loc.wifiForget}</a>)
<li>{state.hostName}</li>
<li>{state.ipAddress}</li>
<li>{state.macAddress}</li>
</>;
}

page = <>{page}<p>{connectedTo == null ? <Spinner /> : connectedTo}</p></>;
Expand Down
2 changes: 1 addition & 1 deletion gui/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (Config.find(entry => entry.name === "language")) {
loc = require("./lang/en.json");
}

let url = "http://192.168.1.54";
let url = "http://192.168.0.171";
if (process.env.NODE_ENV === "production") {url = window.location.origin;}

if (process.env.NODE_ENV === "development") {require("preact/debug");}
Expand Down
45 changes: 44 additions & 1 deletion src/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
WifiManager WiFiManager;

//function to call in setup
void WifiManager::begin(char const *apName, unsigned long newTimeout)
void WifiManager::begin(char const *apName, unsigned long newTimeout, char const *hostName)
{
captivePortalName = apName;
timeout = newTimeout;

if (hostName != NULL) {
this->hostName = hostName;
}

WiFi.mode(WIFI_STA);
WiFi.persistent(true);

Expand All @@ -37,6 +41,15 @@ void WifiManager::begin(char const *apName, unsigned long newTimeout)
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();

if (hostName != NULL && strlen(hostName) > 0) {
#ifdef ESP32
WiFi.setHostname(hostName);
#elif defined(ESP8266)
WiFi.hostname(hostName);
#endif
}

WiFi.begin();
}

Expand Down Expand Up @@ -134,6 +147,14 @@ void WifiManager::connectNewWifi(String newSSID, String newPass)
String oldSSID = WiFi.SSID();
String oldPSK = WiFi.psk();

if (hostName != NULL && strlen(hostName) > 0) {
#ifdef ESP32
WiFi.setHostname(hostName);
#elif defined(ESP8266)
WiFi.hostname(hostName);
#endif
}

WiFi.begin(newSSID.c_str(), newPass.c_str(), 0, NULL, true);
delay(2000);

Expand Down Expand Up @@ -216,6 +237,28 @@ String WifiManager::SSID()
return WiFi.SSID();
}

//return current Host Name
String WifiManager::getHostName()
{
#ifdef ESP32
return WiFi.getHostname();
#elif defined(ESP8266)
return WiFi.hostname();
#endif
}

//return current IP Address
String WifiManager::getIPAddress()
{
return WiFi.localIP().toString();
}

//return current MAC Address
String WifiManager::getMacAddress()
{
return WiFi.macAddress();
}

//captive portal loop
void WifiManager::loop()
{
Expand Down
6 changes: 5 additions & 1 deletion src/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class WifiManager
bool inCaptivePortal = false;
char const *captivePortalName;
unsigned long timeout = 60000;
char const *hostName;

void startCaptivePortal(char const *apName);
void stopCaptivePortal();
Expand All @@ -28,11 +29,14 @@ class WifiManager
int8_t waitForConnectResult(unsigned long timeoutLength);

public :
void begin(char const *apName, unsigned long newTimeout = 60000);
void begin(char const *apName, unsigned long newTimeout = 60000, char const *hostName = NULL);
void loop();
void forget();
bool isCaptivePortal();
String SSID();
String getHostName();
String getIPAddress();
String getMacAddress();
void setNewWifi(String newSSID, String newPass);
void setNewWifi(String newSSID, String newPass, String newIp, String newSub, String newGw, String newDns);
};
Expand Down
Loading