mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
fix hostname when using static ip - #432
This commit is contained in:
@@ -178,7 +178,7 @@ The Web is based off Rick's awesome [esp8266-react](https://github.com/rjwats/es
|
|||||||
* `MqttStatus.cpp` added root["mqtt_fails"]
|
* `MqttStatus.cpp` added root["mqtt_fails"]
|
||||||
* `SecuritySettingsService.cpp` added version to the JWT payload
|
* `SecuritySettingsService.cpp` added version to the JWT payload
|
||||||
* `SecuritySettingsService.h` #include "../../src/version.h"
|
* `SecuritySettingsService.h` #include "../../src/version.h"
|
||||||
* `WiFiSettingsService.cpp` added WiFi.setOutputPower(20.0f) - removed
|
* `WiFiSettingsService.cpp` added WiFi.setOutputPower(20.0f), moved setHostname
|
||||||
* `OTASettingsService.h` added #include "../../src/system.h"
|
* `OTASettingsService.h` added #include "../../src/system.h"
|
||||||
* `OTASettingsService.cpp` added call to emsesp::System::upload_status(true)
|
* `OTASettingsService.cpp` added call to emsesp::System::upload_status(true)
|
||||||
* `features.ini`: -D FT_NTP=0
|
* `features.ini`: -D FT_NTP=0
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <WiFiSettingsService.h>
|
#include <WiFiSettingsService.h>
|
||||||
|
|
||||||
WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
WiFiSettingsService::WiFiSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
_httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager),
|
: _httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager)
|
||||||
_fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE),
|
, _fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE)
|
||||||
_lastConnectionAttempt(0) {
|
, _lastConnectionAttempt(0) {
|
||||||
// We want the device to come up in opmode=0 (WIFI_OFF), when erasing the flash this is not the default.
|
// We want the device to come up in opmode=0 (WIFI_OFF), when erasing the flash this is not the default.
|
||||||
// If needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future.
|
// If needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future.
|
||||||
if (WiFi.getMode() != WIFI_OFF) {
|
if (WiFi.getMode() != WIFI_OFF) {
|
||||||
@@ -17,11 +17,9 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
|
|||||||
// Init the wifi driver on ESP32
|
// Init the wifi driver on ESP32
|
||||||
WiFi.mode(WIFI_MODE_MAX);
|
WiFi.mode(WIFI_MODE_MAX);
|
||||||
WiFi.mode(WIFI_MODE_NULL);
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
WiFi.onEvent(
|
WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
|
||||||
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
||||||
WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeStop, this, std::placeholders::_1, std::placeholders::_2),
|
WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeStop, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_STOP);
|
||||||
WiFiEvent_t::SYSTEM_EVENT_STA_STOP);
|
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
|
|
||||||
// proddy added
|
// proddy added
|
||||||
@@ -31,8 +29,7 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
|
|||||||
// high tx power causing weird behavior, slightly lowering from 20.5 to 20.0 may help stability
|
// high tx power causing weird behavior, slightly lowering from 20.5 to 20.0 may help stability
|
||||||
// WiFi.setOutputPower(20.0f); // in dBm
|
// WiFi.setOutputPower(20.0f); // in dBm
|
||||||
|
|
||||||
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(
|
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
|
||||||
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addUpdateHandler([&](const String & originId) { reconfigureWiFiConnection(); }, false);
|
addUpdateHandler([&](const String & originId) { reconfigureWiFiConnection(); }, false);
|
||||||
@@ -80,12 +77,16 @@ void WiFiSettingsService::manageSTA() {
|
|||||||
// configure for DHCP
|
// configure for DHCP
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||||
WiFi.setHostname(_state.hostname.c_str());
|
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
|
WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
|
||||||
WiFi.hostname(_state.hostname);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
// set hostname
|
||||||
|
#ifdef ESP32
|
||||||
|
WiFi.setHostname(_state.hostname.c_str());
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
WiFi.hostname(_state.hostname);
|
||||||
|
#endif
|
||||||
// attempt to connect to the network
|
// attempt to connect to the network
|
||||||
WiFi.begin(_state.ssid.c_str(), _state.password.c_str());
|
WiFi.begin(_state.ssid.c_str(), _state.password.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user