Implemented wifi stack with AP

This commit is contained in:
2021-06-29 10:59:44 +02:00
parent f146deca05
commit 4b9ef50d06
3 changed files with 101 additions and 42 deletions

View File

@ -92,6 +92,7 @@ using namespace std::chrono_literals;
#ifdef FEATURE_CLOUD
#include "cloud.h"
#endif
#include "wifi_bobbycar.h"
namespace {
ModeInterface *lastMode{};
@ -173,12 +174,6 @@ extern "C" void app_main()
}
printMemoryStats("loadSettings()");
#ifdef FEATURE_SERIAL
bootLabel.redraw("swap front back");
updateSwapFrontBack();
printMemoryStats("swapFronBack()");
#endif
bootLabel.redraw("deviceName");
if (const auto result = wifi_stack::get_default_mac_addr())
std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", result->at(3), result->at(4), result->at(5));
@ -186,40 +181,15 @@ extern "C" void app_main()
ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
printMemoryStats("deviceName");
//bootLabel.redraw("setHostname");
//if (!WiFi.setHostname(deviceName))
//{
//Serial.println("Could not setHostname");
//}
//printMemoryStats("setHostname()");
bootLabel.redraw("wifi");
wifi_begin();
printMemoryStats("wifi_begin()");
//bootLabel.redraw("softAPsetHostname");
//if (!WiFi.softAPsetHostname(deviceName))
//{
//Serial.println("Could not softAPsetHostname");
//}
//printMemoryStats("softAPsetHostname()");
//bootLabel.redraw("WiFi mode");
//if (!WiFi.mode(settings.wifiSettings.autoWifiMode))
//{
//Serial.println("Could not set mode to WIFI_AP_STA");
//}
//printMemoryStats("WiFi.mode()");
//if (settings.wifiSettings.autoEnableAp)
//{
//bootLabel.redraw("WiFi softAp");
//WifiSoftApAction{}.triggered();
//printMemoryStats("WifiSoftApAction()");
//}
//bootLabel.redraw("WiFi begin");
//if (!WiFi.begin("realraum", "r3alraum"))
//{
//Serial.println("Could not begin WiFi");
//}
//printMemoryStats("WiFi.begin()");
#ifdef FEATURE_SERIAL
bootLabel.redraw("swap front back");
updateSwapFrontBack();
printMemoryStats("swapFronBack()");
#endif
#ifdef FEATURE_BLUETOOTH
if (settings.bluetoothSettings.autoBluetoothMode == BluetoothMode::Master)
@ -305,6 +275,8 @@ extern "C" void app_main()
const auto now = espchrono::millis_clock::now();
wifi_update();
#ifdef FEATURE_DPAD
dpad::update();
#endif

View File

@ -3,6 +3,93 @@
// 3rdparty lib includes
#include <espwifistack.h>
namespace {
// local includes
#include "globals.h"
namespace {
wifi_stack::config wifi_create_config()
{
return wifi_stack::config {
.wifiEnabled = true,
.hostname = deviceName,
.wifis = std::array<wifi_stack::wifi_entry, 10> {
wifi_stack::wifi_entry { .ssid = "realraum", .key = "r3alraum" },
wifi_stack::wifi_entry { .ssid = "McDonalds Free WiFi", .key = "Passwort_123" },
wifi_stack::wifi_entry { .ssid = "***REMOVED***", .key = "***REMOVED***" },
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
wifi_stack::wifi_entry { .ssid = {}, .key = {} },
wifi_stack::wifi_entry { .ssid = {}, .key = {} }
},
.sta_ip = {
.dhcpEnabled = true,
.staticIp = {},
.staticGateway = {},
.staticSubnet = {},
.staticDns1 = {},
.staticDns2 = {}
},
.ap = {
{
.ssid = deviceName,
.key = STRING(AP_PASSWORD)
},
.channel = 1,
.authmode = WIFI_AUTH_WPA2_PSK,
.ssid_hidden = false,
.max_connection = 4,
.beacon_interval = 100,
.ip = {10, 0, 0, 1},
.subnet = {255, 255, 255, 0}
},
.min_rssi = -90
};
}
void wifi_begin()
{
wifi_stack::init(wifi_create_config());
//bootLabel.redraw("setHostname");
//if (!WiFi.setHostname(deviceName))
//{
//Serial.println("Could not setHostname");
//}
//printMemoryStats("setHostname()");
//bootLabel.redraw("softAPsetHostname");
//if (!WiFi.softAPsetHostname(deviceName))
//{
//Serial.println("Could not softAPsetHostname");
//}
//printMemoryStats("softAPsetHostname()");
//bootLabel.redraw("WiFi mode");
//if (!WiFi.mode(settings.wifiSettings.autoWifiMode))
//{
//Serial.println("Could not set mode to WIFI_AP_STA");
//}
//printMemoryStats("WiFi.mode()");
//if (settings.wifiSettings.autoEnableAp)
//{
//bootLabel.redraw("WiFi softAp");
//WifiSoftApAction{}.triggered();
//printMemoryStats("WifiSoftApAction()");
//}
//bootLabel.redraw("WiFi begin");
//if (!WiFi.begin("realraum", "r3alraum"))
//{
//Serial.println("Could not begin WiFi");
//}
//printMemoryStats("WiFi.begin()");
}
void wifi_update()
{
wifi_stack::update(wifi_create_config());
}
} // namespace

View File

@ -1,10 +1,10 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x10000, 0x40000,
nvsFac, data, nvs, 0x50000, 0x40000,
#nvsFac, data, nvs, 0x50000, 0x40000,
phy_init, data, phy, 0x90000, 0x1000,
otadata, data, ota, 0x91000, 0x2000,
# PADDING FOR APP ALIGN 0x93000, 0xD000,
factory, app, factory, 0xA0000, 0x100000,
#factory, app, factory, 0xA0000, 0x100000,
app_0, app, ota_0, 0x1A0000, 0x400000,
app_1, app, ota_1, 0x5A0000, 0x400000,
nvs_key, data, nvs_keys, 0x9A0000, 0x1000, encrypted

1 # Name, Type, SubType, Offset, Size, Flags
2 nvs, data, nvs, 0x10000, 0x40000,
3 nvsFac, data, nvs, 0x50000, 0x40000, #nvsFac, data, nvs, 0x50000, 0x40000,
4 phy_init, data, phy, 0x90000, 0x1000,
5 otadata, data, ota, 0x91000, 0x2000,
6 # PADDING FOR APP ALIGN 0x93000, 0xD000,
7 factory, app, factory, 0xA0000, 0x100000, #factory, app, factory, 0xA0000, 0x100000,
8 app_0, app, ota_0, 0x1A0000, 0x400000,
9 app_1, app, ota_1, 0x5A0000, 0x400000,
10 nvs_key, data, nvs_keys, 0x9A0000, 0x1000, encrypted