add network options, IPv6 for mqtt

This commit is contained in:
MichaelDvP
2021-07-08 10:17:50 +02:00
parent 3ea53a8012
commit 2d7449aeba
17 changed files with 180 additions and 27 deletions

View File

@@ -47,6 +47,7 @@ void APSettingsService::manageAP() {
void APSettingsService::startAP() {
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
esp_wifi_set_bandwidth(ESP_IF_WIFI_AP, WIFI_BW_HT20);
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
if (!_dnsServer) {
IPAddress apIp = WiFi.softAPIP();

View File

@@ -101,6 +101,7 @@ void MqttSettingsService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch (event) {
case SYSTEM_EVENT_STA_GOT_IP:
case SYSTEM_EVENT_ETH_GOT_IP:
case SYSTEM_EVENT_GOT_IP6:
if (_state.enabled) {
// emsesp::EMSESP::logger().info(F("Network connection found, starting MQTT client"));
onConfigUpdated();

View File

@@ -19,12 +19,6 @@ NetworkSettingsService::NetworkSettingsService(AsyncWebServer * server, FS * fs,
WiFi.mode(WIFI_MODE_MAX);
WiFi.mode(WIFI_MODE_NULL);
#if defined(EMSESP_WIFI_TWEAK)
// www.esp32.com/viewtopic.php?t=12055
esp_wifi_set_bandwidth(ESP_IF_WIFI_STA, WIFI_BW_HT20);
esp_wifi_set_bandwidth(ESP_IF_WIFI_AP, WIFI_BW_HT20);
#endif
WiFi.onEvent(std::bind(&NetworkSettingsService::WiFiEvent, this, _1));
addUpdateHandler([&](const String & originId) { reconfigureWiFiConnection(); }, false);
@@ -68,6 +62,19 @@ void NetworkSettingsService::manageSTA() {
}
WiFi.setHostname(_state.hostname.c_str()); // set hostname
// www.esp32.com/viewtopic.php?t=12055
read([&](NetworkSettings & networkSettings) {
if (networkSettings.bandwidth20) {
esp_wifi_set_bandwidth(ESP_IF_WIFI_STA, WIFI_BW_HT20);
} else {
esp_wifi_set_bandwidth(ESP_IF_WIFI_STA, WIFI_BW_HT40);
}
esp_wifi_set_max_tx_power(networkSettings.tx_power * 4);
if (networkSettings.nosleep) {
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
}
});
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
}
}

View File

@@ -7,9 +7,7 @@
#include <JsonUtils.h>
#ifndef EMSESP_STANDALONE
#if defined(EMSESP_WIFI_TWEAK)
#include <esp_wifi.h>
#endif
#include <ETH.h>
#endif
@@ -36,6 +34,10 @@ class NetworkSettings {
String password;
String hostname;
bool staticIPConfig;
bool enableIPv6;
bool bandwidth20;
int8_t tx_power;
bool nosleep;
// optional configuration for static IP address
IPAddress localIP;
@@ -50,6 +52,10 @@ class NetworkSettings {
root["password"] = settings.password;
root["hostname"] = settings.hostname;
root["static_ip_config"] = settings.staticIPConfig;
root["enableIPv6"] = settings.enableIPv6;
root["bandwidth20"] = settings.bandwidth20;
root["tx_power"] = settings.tx_power;
root["nosleep"] = settings.nosleep;
// extended settings
JsonUtils::writeIP(root, "local_ip", settings.localIP);
@@ -64,6 +70,10 @@ class NetworkSettings {
settings.password = root["password"] | FACTORY_WIFI_PASSWORD;
settings.hostname = root["hostname"] | FACTORY_WIFI_HOSTNAME;
settings.staticIPConfig = root["static_ip_config"] | false;
settings.enableIPv6 = root["enableIPv6"] | false;
settings.bandwidth20 = root["bandwidth20"] | false;
settings.tx_power = root["tx_power"] | 20;
settings.nosleep = root["nosleep"] | false;
// extended settings
JsonUtils::readIP(root, "local_ip", settings.localIP);