Wifi from new settings
This commit is contained in:
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=7
|
-DDEFAULT_FIELDWEAKMAX=7
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
|
||||||
-DAP_PASSWORD=Passwort_123
|
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
-DFEATURE_OTA
|
-DFEATURE_OTA
|
||||||
-DOTA_USERNAME="allfeatures"
|
-DOTA_USERNAME="allfeatures"
|
||||||
|
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=7
|
-DDEFAULT_FIELDWEAKMAX=7
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=comr_bobbyquad
|
|
||||||
-DAP_PASSWORD=Passwort_123
|
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
-DFEATURE_OTA
|
-DFEATURE_OTA
|
||||||
-DOTA_USERNAME="comred"
|
-DOTA_USERNAME="comred"
|
||||||
|
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=17
|
-DDEFAULT_FIELDWEAKMAX=17
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
|
||||||
-DAP_PASSWORD=Passwort_123
|
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
-DFEATURE_OTA
|
-DFEATURE_OTA
|
||||||
-DOTA_USERNAME="feedc0de"
|
-DOTA_USERNAME="feedc0de"
|
||||||
|
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=7
|
-DDEFAULT_FIELDWEAKMAX=7
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
|
||||||
# -DAP_PASSWORD=Passwort_123
|
|
||||||
# -DFEATURE_WEBSERVER
|
# -DFEATURE_WEBSERVER
|
||||||
# -DFEATURE_OTA
|
# -DFEATURE_OTA
|
||||||
# -DOTA_USERNAME="greyhash"
|
# -DOTA_USERNAME="greyhash"
|
||||||
|
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=7
|
-DDEFAULT_FIELDWEAKMAX=7
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
|
||||||
-DAP_PASSWORD=Passwort_123
|
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
# -DFEATURE_OTA
|
# -DFEATURE_OTA
|
||||||
-DOTA_USERNAME="mick"
|
-DOTA_USERNAME="mick"
|
||||||
|
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=7
|
-DDEFAULT_FIELDWEAKMAX=7
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
|
||||||
-DAP_PASSWORD=Passwort_123
|
|
||||||
# -DFEATURE_WEBSERVER
|
# -DFEATURE_WEBSERVER
|
||||||
# -DFEATURE_OTA
|
# -DFEATURE_OTA
|
||||||
-DOTA_USERNAME="nofeatures"
|
-DOTA_USERNAME="nofeatures"
|
||||||
|
@@ -40,8 +40,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DDEFAULT_NMOTMAX=2000
|
-DDEFAULT_NMOTMAX=2000
|
||||||
-DDEFAULT_FIELDWEAKMAX=7
|
-DDEFAULT_FIELDWEAKMAX=7
|
||||||
-DDEFAULT_FIELDADVMAX=40
|
-DDEFAULT_FIELDADVMAX=40
|
||||||
-DDEVICE_PREFIX=peter_bobbyquad
|
|
||||||
-DAP_PASSWORD=Passwort_123
|
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
-DFEATURE_OTA
|
-DFEATURE_OTA
|
||||||
-DOTA_USERNAME="peter"
|
-DOTA_USERNAME="peter"
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
|
||||||
//! Special type of RefAccessor that also saves settings after setValue()
|
//! Special type of RefAccessor that also saves settings after setValue()
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -39,8 +40,16 @@ struct FieldWeakMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t
|
|||||||
struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } };
|
struct PhaseAdvMaxAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.limits.phaseAdvMax; } };
|
||||||
|
|
||||||
// WiFi
|
// WiFi
|
||||||
struct WifiStaEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.wifiSettings.wifiStaEnabled; } };
|
struct WifiStaEnabledAccessor : public virtual espgui::AccessorInterface<bool>
|
||||||
struct WifiApEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.wifiSettings.wifiApEnabled; } };
|
{
|
||||||
|
bool getValue() const override { return configs.wifiStaEnabled.value; }
|
||||||
|
void setValue(bool value) override { configs.write_config(configs.wifiStaEnabled, value); }
|
||||||
|
};
|
||||||
|
struct WifiApEnabledAccessor : public virtual espgui::AccessorInterface<bool>
|
||||||
|
{
|
||||||
|
bool getValue() const override { return configs.wifiApEnabled.value; }
|
||||||
|
void setValue(bool value) override { configs.write_config(configs.wifiApEnabled, value); }
|
||||||
|
};
|
||||||
|
|
||||||
// Bluetooth
|
// Bluetooth
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
|
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
void BluetoothBeginAction::triggered()
|
void BluetoothBeginAction::triggered()
|
||||||
{
|
{
|
||||||
if (!bluetoothSerial.begin(deviceName))
|
if (!bluetoothSerial.begin(configs.bluetoothName.value.c_str()))
|
||||||
{
|
{
|
||||||
//Serial.println("Could not begin bluetooth");
|
//Serial.println("Could not begin bluetooth");
|
||||||
// TODO: better error handling
|
// TODO: better error handling
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "actioninterface.h"
|
#include "actioninterface.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ class BluetoothBeginMasterAction : public virtual ActionInterface
|
|||||||
public:
|
public:
|
||||||
void triggered() override
|
void triggered() override
|
||||||
{
|
{
|
||||||
if (!bluetoothSerial.begin(deviceName, true))
|
if (!bluetoothSerial.begin(configs.bluetoothName.value.c_str(), true))
|
||||||
{
|
{
|
||||||
//Serial.println("Could not begin bluetooth master");
|
//Serial.println("Could not begin bluetooth master");
|
||||||
// TODO: better error handling
|
// TODO: better error handling
|
||||||
|
@@ -3,11 +3,46 @@
|
|||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
namespace {
|
// 3rdparty lib includes
|
||||||
constexpr const char * const TAG = "BOBBYBLE";
|
#include <ArduinoJson.h>
|
||||||
} // namespace
|
#include <wifi_bobbycar.h>
|
||||||
|
#include <futurecpp.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#ifdef FEATURE_LEDSTRIP
|
||||||
|
#include "ledstrip.h"
|
||||||
|
#endif
|
||||||
|
#include "globals.h"
|
||||||
|
#include "modes/remotecontrolmode.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
|
||||||
#ifdef FEATURE_BLE
|
#ifdef FEATURE_BLE
|
||||||
|
namespace {
|
||||||
|
constexpr const char * const TAG = "BOBBYBLE";
|
||||||
|
|
||||||
|
class RemoteControlCallbacks : public NimBLECharacteristicCallbacks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void onWrite(NimBLECharacteristic* pCharacteristic) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef FEATURE_WIRELESS_CONFIG
|
||||||
|
class WirelessSettingsCallbacks : public NimBLECharacteristicCallbacks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void onWrite(NimBLECharacteristic* pCharacteristic) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class WiFiListCallbacks : public NimBLECharacteristicCallbacks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void onRead(NimBLECharacteristic* pCharacteristic) override;
|
||||||
|
};
|
||||||
|
#endif // FEATURE_WIRELESS_CONFIG
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
BLEServer *pServer{};
|
BLEServer *pServer{};
|
||||||
BLEService *pService{};
|
BLEService *pService{};
|
||||||
BLECharacteristic *livestatsCharacteristic{};
|
BLECharacteristic *livestatsCharacteristic{};
|
||||||
@@ -15,21 +50,21 @@ BLECharacteristic *remotecontrolCharacteristic{};
|
|||||||
#ifdef FEATURE_WIRELESS_CONFIG
|
#ifdef FEATURE_WIRELESS_CONFIG
|
||||||
BLECharacteristic *wirelessConfig{};
|
BLECharacteristic *wirelessConfig{};
|
||||||
BLECharacteristic *getwifilist{};
|
BLECharacteristic *getwifilist{};
|
||||||
#endif
|
#endif // FEATURE_WIRELESS_CONFIG
|
||||||
|
|
||||||
|
namespace {
|
||||||
RemoteControlCallbacks bleRemoteCallbacks;
|
RemoteControlCallbacks bleRemoteCallbacks;
|
||||||
|
|
||||||
#ifdef FEATURE_WIRELESS_CONFIG
|
#ifdef FEATURE_WIRELESS_CONFIG
|
||||||
WirelessSettingsCallbacks bleWirelessSettingsCallbacks;
|
WirelessSettingsCallbacks bleWirelessSettingsCallbacks;
|
||||||
WiFiListCallbacks bleWiFiListCallbacks;
|
WiFiListCallbacks bleWiFiListCallbacks;
|
||||||
#endif
|
#endif // FEATURE_WIRELESS_CONFIG
|
||||||
|
|
||||||
namespace {
|
|
||||||
void createBle()
|
void createBle()
|
||||||
{
|
{
|
||||||
ESP_LOGI("BOBBY", "called");
|
ESP_LOGI("BOBBY", "called");
|
||||||
|
|
||||||
BLEDevice::init(deviceName);
|
BLEDevice::init(configs.bluetoothName.value);
|
||||||
|
|
||||||
const auto serviceUuid{"0335e46c-f355-4ce6-8076-017de08cee98"};
|
const auto serviceUuid{"0335e46c-f355-4ce6-8076-017de08cee98"};
|
||||||
|
|
||||||
@@ -198,6 +233,8 @@ void handleBle()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
||||||
{
|
{
|
||||||
const auto &val = pCharacteristic->getValue();
|
const auto &val = pCharacteristic->getValue();
|
||||||
@@ -212,7 +249,7 @@ void RemoteControlCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
|||||||
#ifdef FEATURE_LEDSTRIP
|
#ifdef FEATURE_LEDSTRIP
|
||||||
auto newBlinkAnimation = doc["anim"].as<int16_t>();
|
auto newBlinkAnimation = doc["anim"].as<int16_t>();
|
||||||
if (blinkAnimation != newBlinkAnimation) blinkAnimation = newBlinkAnimation;
|
if (blinkAnimation != newBlinkAnimation) blinkAnimation = newBlinkAnimation;
|
||||||
#endif
|
#endif // FEATURE_LEDSTRIP
|
||||||
|
|
||||||
const bool isInverted = (settings.controllerHardware.invertFrontLeft && !settings.controllerHardware.invertFrontRight);
|
const bool isInverted = (settings.controllerHardware.invertFrontLeft && !settings.controllerHardware.invertFrontRight);
|
||||||
|
|
||||||
@@ -244,8 +281,8 @@ void WirelessSettingsCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
|||||||
if (write_type == "wifi") {
|
if (write_type == "wifi") {
|
||||||
const int index = doc["wifi_index"].as<int>();
|
const int index = doc["wifi_index"].as<int>();
|
||||||
ESP_LOGI(TAG, "[ble_config]: Set wifi%i: WiFi-SSID: %s, WiFi-Password: ***", doc["wifi_index"].as<int>(), doc["wifi_ssid"].as<const char*>());
|
ESP_LOGI(TAG, "[ble_config]: Set wifi%i: WiFi-SSID: %s, WiFi-Password: ***", doc["wifi_index"].as<int>(), doc["wifi_ssid"].as<const char*>());
|
||||||
stringSettings.wifis[index].ssid = doc["wifi_ssid"].as<std::string>();
|
configs.write_config(configs.wifi_configs[index].ssid, doc["wifi_ssid"].as<std::string>());
|
||||||
stringSettings.wifis[index].key = doc["wifi_pass"].as<std::string>();
|
configs.write_config(configs.wifi_configs[index].key, doc["wifi_pass"].as<std::string>());
|
||||||
saveSettings();
|
saveSettings();
|
||||||
} else {
|
} else {
|
||||||
const auto deserialized = deserializeJson(doc, val);
|
const auto deserialized = deserializeJson(doc, val);
|
||||||
@@ -253,19 +290,22 @@ void WirelessSettingsCallbacks::onWrite(NimBLECharacteristic* pCharacteristic)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiListCallbacks::onRead(NimBLECharacteristic *pCharacteristic) {
|
void WiFiListCallbacks::onRead(NimBLECharacteristic *pCharacteristic)
|
||||||
|
{
|
||||||
StaticJsonDocument<768> responseDoc;
|
StaticJsonDocument<768> responseDoc;
|
||||||
auto wifis = stringSettings.wifis;
|
|
||||||
auto wifiArray = responseDoc.createNestedArray("wifis");
|
auto wifiArray = responseDoc.createNestedArray("wifis");
|
||||||
ESP_LOGI(TAG, "[ble_wifilist] Got request for listing wifi ssids.");
|
ESP_LOGI(TAG, "[ble_wifilist] Got request for listing wifi ssids.");
|
||||||
for (unsigned int index = 0; index < wifis.size(); index++) {
|
for (const auto &wifi : configs.wifi_configs)
|
||||||
wifiArray.add(wifis[index].ssid);
|
{
|
||||||
|
wifiArray.add(wifi.ssid.value);
|
||||||
}
|
}
|
||||||
responseDoc["wifi_count"] = wifis.size();
|
responseDoc["wifi_count"] = configs.wifi_configs.size();
|
||||||
std::string json;
|
std::string json;
|
||||||
serializeJson(responseDoc, json);
|
serializeJson(responseDoc, json);
|
||||||
pCharacteristic->setValue(json);
|
pCharacteristic->setValue(json);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // FEATURE_WIRELESS_CONFIG
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,24 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// 3rdparty lib includes
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#ifdef FEATURE_BLE
|
#ifdef FEATURE_BLE
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
#include <NimBLEDevice.h>
|
#include <NimBLEDevice.h>
|
||||||
#endif
|
|
||||||
#ifdef FEATURE_LEDSTRIP
|
|
||||||
#include "ledstrip.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// local includes
|
|
||||||
#include "globals.h"
|
|
||||||
#include "futurecpp.h"
|
|
||||||
#include "modes/remotecontrolmode.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
//wifistack
|
|
||||||
#include "wifi_bobbycar.h"
|
|
||||||
|
|
||||||
#ifdef FEATURE_BLE
|
|
||||||
extern BLEServer *pServer;
|
extern BLEServer *pServer;
|
||||||
extern BLEService *pService;
|
extern BLEService *pService;
|
||||||
extern BLECharacteristic *livestatsCharacteristic;
|
extern BLECharacteristic *livestatsCharacteristic;
|
||||||
@@ -26,34 +12,7 @@ extern BLECharacteristic *remotecontrolCharacteristic;
|
|||||||
#ifdef FEATURE_WIRELESS_CONFIG
|
#ifdef FEATURE_WIRELESS_CONFIG
|
||||||
extern BLECharacteristic *wirelessConfig;
|
extern BLECharacteristic *wirelessConfig;
|
||||||
extern BLECharacteristic *getwifilist;
|
extern BLECharacteristic *getwifilist;
|
||||||
#endif
|
#endif // FEATURE_WIRELESS_CONFIG
|
||||||
|
|
||||||
class RemoteControlCallbacks : public NimBLECharacteristicCallbacks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void onWrite(NimBLECharacteristic* pCharacteristic) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef FEATURE_WIRELESS_CONFIG
|
|
||||||
class WirelessSettingsCallbacks : public NimBLECharacteristicCallbacks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void onWrite(NimBLECharacteristic* pCharacteristic) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WiFiListCallbacks : public NimBLECharacteristicCallbacks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void onRead(NimBLECharacteristic* pCharacteristic) override;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern RemoteControlCallbacks bleRemoteCallbacks;
|
|
||||||
|
|
||||||
#ifdef FEATURE_WIRELESS_CONFIG
|
|
||||||
extern WirelessSettingsCallbacks bleWirelessSettingsCallbacks;
|
|
||||||
extern WiFiListCallbacks bleWiFiListCallbacks;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void initBle();
|
void initBle();
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "displays/menus/debugmenu.h"
|
#include "displays/menus/debugmenu.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "screenmanager.h"
|
#include "screenmanager.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ void QrCodeDebugDisplay::buttonPressed(espgui::Button button)
|
|||||||
case Button::Right:
|
case Button::Right:
|
||||||
{
|
{
|
||||||
uint8_t qrcodeBytes[qrcode_getBufferSize(7)];
|
uint8_t qrcodeBytes[qrcode_getBufferSize(7)];
|
||||||
qrcode_initText(&m_qrcode, qrcodeBytes, 7, ECC_MEDIUM, fmt::format("WIFI:T:WPA;S:{};P:{};", deviceName, stringSettings.ap_password).c_str());
|
qrcode_initText(&m_qrcode, qrcodeBytes, 7, ECC_MEDIUM, fmt::format("WIFI:T:WPA;S:{};P:{};", configs.wifiApName.value, configs.wifiApKey.value).c_str());
|
||||||
|
|
||||||
for (uint8_t y = 0; y < m_qrcode.size; y++) {
|
for (uint8_t y = 0; y < m_qrcode.size; y++) {
|
||||||
for (uint8_t x = 0; x < m_qrcode.size; x++) {
|
for (uint8_t x = 0; x < m_qrcode.size; x++) {
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "udpcloud.h"
|
#include "udpcloud.h"
|
||||||
#include "modes/defaultmode.h"
|
#include "modes/defaultmode.h"
|
||||||
#include "taskmanager.h"
|
#include "taskmanager.h"
|
||||||
|
#include "newsettings.h"
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
using namespace espgui;
|
using namespace espgui;
|
||||||
@@ -176,7 +177,7 @@ clearIp:
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_labelMode.redraw(currentMode->displayName());
|
m_labelMode.redraw(currentMode->displayName());
|
||||||
m_labelName.redraw(deviceName);
|
m_labelName.redraw(configs.wifiApName.value);
|
||||||
const auto profile = settingsPersister.currentlyOpenProfileIndex();
|
const auto profile = settingsPersister.currentlyOpenProfileIndex();
|
||||||
m_labelProfile.redraw(profile ? std::to_string(*profile) : "-");
|
m_labelProfile.redraw(profile ? std::to_string(*profile) : "-");
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,6 @@ float avgSpeedKmh{};
|
|||||||
float sumCurrent{};
|
float sumCurrent{};
|
||||||
bool isLocked{};
|
bool isLocked{};
|
||||||
|
|
||||||
char deviceName[32] = STRING(DEVICE_PREFIX) "_ERR";
|
|
||||||
|
|
||||||
bool simplified =
|
bool simplified =
|
||||||
#if defined(HAS_SIMPLIFIED)
|
#if defined(HAS_SIMPLIFIED)
|
||||||
true
|
true
|
||||||
|
@@ -42,7 +42,6 @@ extern float avgSpeed;
|
|||||||
extern float avgSpeedKmh;
|
extern float avgSpeedKmh;
|
||||||
extern float sumCurrent;
|
extern float sumCurrent;
|
||||||
|
|
||||||
extern char deviceName[32];
|
|
||||||
extern bool isLocked;
|
extern bool isLocked;
|
||||||
|
|
||||||
#ifdef GLOBALS_PLUGIN
|
#ifdef GLOBALS_PLUGIN
|
||||||
|
@@ -66,12 +66,6 @@ extern "C" void app_main()
|
|||||||
else
|
else
|
||||||
ESP_LOGE("BOBBY", "init() failed");
|
ESP_LOGE("BOBBY", "init() failed");
|
||||||
|
|
||||||
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));
|
|
||||||
else
|
|
||||||
ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
|
||||||
|
|
||||||
for (const auto &task : schedulerTasks)
|
for (const auto &task : schedulerTasks)
|
||||||
{
|
{
|
||||||
bootLabel.redraw(task.name());
|
bootLabel.redraw(task.name());
|
||||||
|
@@ -1,11 +1,24 @@
|
|||||||
#include "newsettings.h"
|
#include "newsettings.h"
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <configmanager_priv.h>
|
#include <configmanager_priv.h>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <espwifistack.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
//constexpr const char * const TAG = "CONFIG";
|
||||||
|
}
|
||||||
|
|
||||||
std::string defaultHostname()
|
std::string defaultHostname()
|
||||||
{
|
{
|
||||||
return "hallo";
|
if (const auto result = wifi_stack::get_default_mac_addr())
|
||||||
|
return fmt::format("bobby_{:02x}{:02x}{:02x}", result->at(3), result->at(4), result->at(5));
|
||||||
|
else
|
||||||
|
ESP_LOGE(TAG, "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
||||||
|
return "bobby";
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager<ConfigContainer> configs;
|
ConfigManager<ConfigContainer> configs;
|
||||||
|
@@ -73,13 +73,13 @@ public:
|
|||||||
ConfigWrapper<int8_t> wifiStaMinRssi {-90, DoReset, {}, "wifiStaMinRssi" };
|
ConfigWrapper<int8_t> wifiStaMinRssi {-90, DoReset, {}, "wifiStaMinRssi" };
|
||||||
|
|
||||||
ConfigWrapper<bool> wifiApEnabled {true, DoReset, {}, "wifiApEnabled" };
|
ConfigWrapper<bool> wifiApEnabled {true, DoReset, {}, "wifiApEnabled" };
|
||||||
ConfigWrapper<std::string> factoryWifiApName {defaultHostname, NoReset, StringMinMaxSize<4, 32>, "facWifiApName" };
|
ConfigWrapper<std::string> wifiApName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "wifiApName" };
|
||||||
ConfigWrapper<std::string> wifiApName { factoryWifiApName, StringMinMaxSize<4, 32>, "wifiApName" };
|
ConfigWrapper<std::string> wifiApKey {"Passwort_123", DoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
|
||||||
ConfigWrapper<std::string> factoryWifiApKey {"Passwort_123", NoReset, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "factWifiApKey" };
|
|
||||||
ConfigWrapper<std::string> wifiApKey { factoryWifiApKey, StringOr<StringEmpty, StringMinMaxSize<8, 64>>, "wifiApKey" };
|
|
||||||
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, {}, "wifiApChannel" };
|
ConfigWrapper<uint8_t> wifiApChannel {1, DoReset, {}, "wifiApChannel" };
|
||||||
ConfigWrapper<wifi_auth_mode_t> wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" };
|
ConfigWrapper<wifi_auth_mode_t> wifiApAuthmode{WIFI_AUTH_WPA2_PSK, DoReset, {}, "wifiApAuthmode" };
|
||||||
|
|
||||||
|
ConfigWrapper<std::string> bluetoothName {defaultHostname, DoReset, StringMinMaxSize<4, 32>, "bluetoothName" };
|
||||||
|
|
||||||
#define NEW_SETTINGS(x) \
|
#define NEW_SETTINGS(x) \
|
||||||
x(baseMacAddressOverride) \
|
x(baseMacAddressOverride) \
|
||||||
x(hostname) \
|
x(hostname) \
|
||||||
@@ -189,12 +189,12 @@ public:
|
|||||||
x(wifiStaMinRssi) \
|
x(wifiStaMinRssi) \
|
||||||
\
|
\
|
||||||
x(wifiApEnabled) \
|
x(wifiApEnabled) \
|
||||||
x(factoryWifiApName) \
|
|
||||||
x(wifiApName) \
|
x(wifiApName) \
|
||||||
x(factoryWifiApKey) \
|
|
||||||
x(wifiApKey) \
|
x(wifiApKey) \
|
||||||
x(wifiApChannel) \
|
x(wifiApChannel) \
|
||||||
//x(wifiApAuthmode)
|
x(wifiApAuthmode) \
|
||||||
|
\
|
||||||
|
//x(bluetoothName)
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void callForEveryConfig(T &&callback)
|
void callForEveryConfig(T &&callback)
|
||||||
@@ -202,7 +202,7 @@ public:
|
|||||||
#define HELPER(x) callback(x);
|
#define HELPER(x) callback(x);
|
||||||
NEW_SETTINGS(HELPER)
|
NEW_SETTINGS(HELPER)
|
||||||
#undef HELPER
|
#undef HELPER
|
||||||
callback(wifiApAuthmode);
|
callback(bluetoothName);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto getAllConfigParams()
|
auto getAllConfigParams()
|
||||||
@@ -211,7 +211,7 @@ public:
|
|||||||
#define HELPER(x) std::ref<ConfigWrapperInterface>(x),
|
#define HELPER(x) std::ref<ConfigWrapperInterface>(x),
|
||||||
NEW_SETTINGS(HELPER)
|
NEW_SETTINGS(HELPER)
|
||||||
#undef HELPER
|
#undef HELPER
|
||||||
std::ref<ConfigWrapperInterface>(wifiApAuthmode)
|
std::ref<ConfigWrapperInterface>(bluetoothName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -4,24 +4,11 @@
|
|||||||
namespace presets {
|
namespace presets {
|
||||||
StringSettings makeDefaultStringSettings()
|
StringSettings makeDefaultStringSettings()
|
||||||
{
|
{
|
||||||
using ConfiguredWifi = StringSettings::ConfiguredWifi;
|
|
||||||
#ifdef FEATURE_OTA
|
#ifdef FEATURE_OTA
|
||||||
using ConfiguredOtaServer = StringSettings::ConfiguredOtaServer;
|
using ConfiguredOtaServer = StringSettings::ConfiguredOtaServer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return {
|
return {
|
||||||
.wifis = std::array<ConfiguredWifi, 10> {
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} },
|
|
||||||
ConfiguredWifi { .ssid = {}, .key = {} }
|
|
||||||
},
|
|
||||||
#ifdef FEATURE_CLOUD
|
#ifdef FEATURE_CLOUD
|
||||||
.cloudUrl = {},
|
.cloudUrl = {},
|
||||||
#endif
|
#endif
|
||||||
@@ -52,11 +39,6 @@ StringSettings makeDefaultStringSettings()
|
|||||||
},
|
},
|
||||||
.otaServerUrl = {},
|
.otaServerUrl = {},
|
||||||
#endif
|
#endif
|
||||||
#ifdef AP_PASSWORD
|
|
||||||
.ap_password = STRING(AP_PASSWORD),
|
|
||||||
#else
|
|
||||||
.ap_password = "Bobbycar_123",
|
|
||||||
#endif
|
|
||||||
#ifdef FEATURE_OTA
|
#ifdef FEATURE_OTA
|
||||||
.otaServerBranch = {},
|
.otaServerBranch = {},
|
||||||
#endif
|
#endif
|
||||||
|
@@ -96,11 +96,6 @@ constexpr Settings::ControllerHardware mosfetsOffControllerHardware {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Settings::WifiSettings defaultWifiSettings {
|
|
||||||
.wifiStaEnabled = true,
|
|
||||||
.wifiApEnabled = true
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
constexpr Settings::BluetoothSettings defaultBluetoothSettings {
|
constexpr Settings::BluetoothSettings defaultBluetoothSettings {
|
||||||
.autoBluetoothMode = BluetoothMode::Master
|
.autoBluetoothMode = BluetoothMode::Master
|
||||||
@@ -321,7 +316,6 @@ constexpr Settings defaultSettings {
|
|||||||
#endif
|
#endif
|
||||||
.buzzer = defaultBuzzer,
|
.buzzer = defaultBuzzer,
|
||||||
.limits = defaultLimits,
|
.limits = defaultLimits,
|
||||||
.wifiSettings = defaultWifiSettings,
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
.bluetoothSettings = defaultBluetoothSettings,
|
.bluetoothSettings = defaultBluetoothSettings,
|
||||||
#endif
|
#endif
|
||||||
|
@@ -47,11 +47,6 @@ struct Settings
|
|||||||
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed.
|
int16_t phaseAdvMax; // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed.
|
||||||
} limits;
|
} limits;
|
||||||
|
|
||||||
struct WifiSettings {
|
|
||||||
bool wifiStaEnabled;
|
|
||||||
bool wifiApEnabled;
|
|
||||||
} wifiSettings;
|
|
||||||
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
struct BluetoothSettings {
|
struct BluetoothSettings {
|
||||||
BluetoothMode autoBluetoothMode;
|
BluetoothMode autoBluetoothMode;
|
||||||
@@ -254,9 +249,6 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
|||||||
callable("revBeepDur0", buzzer.reverseBeepDuration0);
|
callable("revBeepDur0", buzzer.reverseBeepDuration0);
|
||||||
callable("revBeepDur1", buzzer.reverseBeepDuration1);
|
callable("revBeepDur1", buzzer.reverseBeepDuration1);
|
||||||
|
|
||||||
callable("wifiStaEnabled", wifiSettings.wifiStaEnabled);
|
|
||||||
callable("wifiApEnabled", wifiSettings.wifiApEnabled);
|
|
||||||
|
|
||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
callable("autoBluetoothMo", bluetoothSettings.autoBluetoothMode);
|
callable("autoBluetoothMo", bluetoothSettings.autoBluetoothMode);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
struct StringSettings
|
struct StringSettings
|
||||||
{
|
{
|
||||||
struct ConfiguredWifi {
|
|
||||||
std::string ssid;
|
|
||||||
std::string key;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::array<ConfiguredWifi, 10> wifis;
|
|
||||||
|
|
||||||
#ifdef FEATURE_CLOUD
|
#ifdef FEATURE_CLOUD
|
||||||
std::string cloudUrl;
|
std::string cloudUrl;
|
||||||
#endif
|
#endif
|
||||||
@@ -51,7 +44,6 @@ struct StringSettings
|
|||||||
#ifdef FEATURE_DNS_NS
|
#ifdef FEATURE_DNS_NS
|
||||||
std::string dns_key;
|
std::string dns_key;
|
||||||
#endif
|
#endif
|
||||||
std::string ap_password;
|
|
||||||
#ifdef FEATURE_OTA
|
#ifdef FEATURE_OTA
|
||||||
std::string otaServerBranch;
|
std::string otaServerBranch;
|
||||||
#endif
|
#endif
|
||||||
@@ -70,27 +62,6 @@ struct StringSettings
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void StringSettings::executeForEveryCommonSetting(T &&callable)
|
void StringSettings::executeForEveryCommonSetting(T &&callable)
|
||||||
{
|
{
|
||||||
callable("ssid0", wifis[0].ssid);
|
|
||||||
callable("key0", wifis[0].key);
|
|
||||||
callable("ssid1", wifis[1].ssid);
|
|
||||||
callable("key1", wifis[1].key);
|
|
||||||
callable("ssid2", wifis[2].ssid);
|
|
||||||
callable("key2", wifis[2].key);
|
|
||||||
callable("ssid3", wifis[3].ssid);
|
|
||||||
callable("key3", wifis[3].key);
|
|
||||||
callable("ssid4", wifis[4].ssid);
|
|
||||||
callable("key4", wifis[4].key);
|
|
||||||
callable("ssid5", wifis[5].ssid);
|
|
||||||
callable("key5", wifis[5].key);
|
|
||||||
callable("ssid6", wifis[6].ssid);
|
|
||||||
callable("key6", wifis[6].key);
|
|
||||||
callable("ssid7", wifis[7].ssid);
|
|
||||||
callable("key7", wifis[7].key);
|
|
||||||
callable("ssid8", wifis[8].ssid);
|
|
||||||
callable("key8", wifis[8].key);
|
|
||||||
callable("ssid9", wifis[9].ssid);
|
|
||||||
callable("key9", wifis[9].key);
|
|
||||||
|
|
||||||
#ifdef FEATURE_CLOUD
|
#ifdef FEATURE_CLOUD
|
||||||
callable("cloudUrl", cloudUrl);
|
callable("cloudUrl", cloudUrl);
|
||||||
#endif
|
#endif
|
||||||
@@ -137,7 +108,6 @@ void StringSettings::executeForEveryCommonSetting(T &&callable)
|
|||||||
#ifdef FEATURE_DNS_NS
|
#ifdef FEATURE_DNS_NS
|
||||||
callable("dnskey", dns_key);
|
callable("dnskey", dns_key);
|
||||||
#endif
|
#endif
|
||||||
callable("ap_pw", ap_password);
|
|
||||||
callable("webpw", webserver_password);
|
callable("webpw", webserver_password);
|
||||||
|
|
||||||
#ifdef FEATURE_ESPNOW
|
#ifdef FEATURE_ESPNOW
|
||||||
|
@@ -10,27 +10,28 @@
|
|||||||
#include <espwifistack.h>
|
#include <espwifistack.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "globals.h"
|
#include "newsettings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
wifi_stack::config wifi_create_config();
|
wifi_stack::config createConfig();
|
||||||
std::optional<wifi_stack::sta_config> wifi_create_sta_config();
|
std::optional<wifi_stack::sta_config> createStaConfig();
|
||||||
std::optional<wifi_stack::ap_config> wifi_create_ap_config();
|
wifi_stack::wifi_entry createWifiEntry(const WiFiConfig &wifi_config);
|
||||||
}
|
std::optional<wifi_stack::ap_config> createApConfig();
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void wifi_begin()
|
void wifi_begin()
|
||||||
{
|
{
|
||||||
wifi_stack::init(wifi_create_config());
|
wifi_stack::init(createConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifi_update()
|
void wifi_update()
|
||||||
{
|
{
|
||||||
wifi_stack::update(wifi_create_config());
|
wifi_stack::update(createConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t wifi_scan()
|
esp_err_t wifi_scan()
|
||||||
{
|
{
|
||||||
const auto &sta_config = wifi_create_sta_config();
|
const auto &sta_config = createStaConfig();
|
||||||
if (!sta_config)
|
if (!sta_config)
|
||||||
{
|
{
|
||||||
ESP_LOGE("BOBBY", "no sta enabled");
|
ESP_LOGE("BOBBY", "no sta enabled");
|
||||||
@@ -47,63 +48,99 @@ esp_err_t wifi_scan()
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
wifi_stack::config wifi_create_config()
|
wifi_stack::config createConfig()
|
||||||
{
|
{
|
||||||
return wifi_stack::config {
|
return wifi_stack::config {
|
||||||
.sta = wifi_create_sta_config(),
|
.base_mac_override = configs.baseMacAddressOverride.value,
|
||||||
.ap = wifi_create_ap_config(),
|
//.dual_ant = dual_ant_config{},
|
||||||
.country = wifi_country_t {
|
.sta = createStaConfig(),
|
||||||
.cc = { 'A', 'T', '\0' },
|
.ap = createApConfig(),
|
||||||
.schan = 1,
|
#ifdef CONFIG_ETH_ENABLED
|
||||||
.nchan = 13,
|
.eth = createEthConfig()
|
||||||
.max_tx_power = 30,
|
#endif
|
||||||
.policy = WIFI_COUNTRY_POLICY_MANUAL
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<wifi_stack::sta_config> wifi_create_sta_config()
|
std::optional<wifi_stack::sta_config> createStaConfig()
|
||||||
{
|
{
|
||||||
if (!settings.wifiSettings.wifiStaEnabled)
|
if (!configs.wifiStaEnabled.value)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
return wifi_stack::sta_config {
|
return wifi_stack::sta_config{
|
||||||
.hostname = deviceName,
|
.hostname = configs.hostname.value,
|
||||||
.wifis = std::array<wifi_stack::wifi_entry, 10> {
|
.wifis = std::array<wifi_stack::wifi_entry, 10> {
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[0].ssid, .key = stringSettings.wifis[0].key },
|
createWifiEntry(configs.wifi_configs[0]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[1].ssid, .key = stringSettings.wifis[1].key },
|
createWifiEntry(configs.wifi_configs[1]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[2].ssid, .key = stringSettings.wifis[2].key },
|
createWifiEntry(configs.wifi_configs[2]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[3].ssid, .key = stringSettings.wifis[3].key },
|
createWifiEntry(configs.wifi_configs[3]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[4].ssid, .key = stringSettings.wifis[4].key },
|
createWifiEntry(configs.wifi_configs[4]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[5].ssid, .key = stringSettings.wifis[5].key },
|
createWifiEntry(configs.wifi_configs[5]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[6].ssid, .key = stringSettings.wifis[6].key },
|
createWifiEntry(configs.wifi_configs[6]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[7].ssid, .key = stringSettings.wifis[7].key },
|
createWifiEntry(configs.wifi_configs[7]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[8].ssid, .key = stringSettings.wifis[8].key },
|
createWifiEntry(configs.wifi_configs[8]),
|
||||||
wifi_stack::wifi_entry { .ssid = stringSettings.wifis[9].ssid, .key = stringSettings.wifis[9].key }
|
createWifiEntry(configs.wifi_configs[9])
|
||||||
},
|
},
|
||||||
.min_rssi = -90
|
.min_rssi = configs.wifiStaMinRssi.value,
|
||||||
|
.long_range = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<wifi_stack::ap_config> wifi_create_ap_config()
|
wifi_stack::wifi_entry createWifiEntry(const WiFiConfig &wifi_config)
|
||||||
{
|
{
|
||||||
if (!settings.wifiSettings.wifiApEnabled)
|
std::optional<wifi_stack::static_ip_config> static_ip;
|
||||||
|
if (wifi_config.useStaticIp.value)
|
||||||
|
static_ip = wifi_stack::static_ip_config {
|
||||||
|
.ip = wifi_config.staticIp.value,
|
||||||
|
.subnet = wifi_config.staticSubnet.value,
|
||||||
|
.gateway = wifi_config.staticGateway.value
|
||||||
|
};
|
||||||
|
|
||||||
|
wifi_stack::static_dns_config static_dns;
|
||||||
|
if (wifi_config.useStaticDns.value)
|
||||||
|
{
|
||||||
|
if (wifi_config.staticDns0.value.value())
|
||||||
|
static_dns.main = wifi_config.staticDns0.value;
|
||||||
|
if (wifi_config.staticDns1.value.value())
|
||||||
|
static_dns.backup = wifi_config.staticDns1.value;
|
||||||
|
if (wifi_config.staticDns2.value.value())
|
||||||
|
static_dns.fallback = wifi_config.staticDns2.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wifi_stack::wifi_entry {
|
||||||
|
.ssid = wifi_config.ssid.value,
|
||||||
|
.key = wifi_config.key.value,
|
||||||
|
.static_ip = static_ip,
|
||||||
|
.static_dns = static_dns
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<wifi_stack::ap_config> createApConfig()
|
||||||
|
{
|
||||||
|
if (!configs.wifiApEnabled.value)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
|
// if (configs.wifiDisableApWhenOnline.value &&
|
||||||
|
// cloudStarted &&
|
||||||
|
// cloudConnected &&
|
||||||
|
// lastCloudConnectedToggled &&
|
||||||
|
// espchrono::ago(*lastCloudConnectedToggled) >= 30s)
|
||||||
|
// return std::nullopt;
|
||||||
|
|
||||||
return wifi_stack::ap_config {
|
return wifi_stack::ap_config {
|
||||||
.hostname = deviceName,
|
.hostname = configs.hostname.value,
|
||||||
.ssid = deviceName,
|
.ssid = configs.wifiApName.value,
|
||||||
.key = stringSettings.ap_password,
|
.key = configs.wifiApKey.value,
|
||||||
.static_ip = {
|
.static_ip = {
|
||||||
.ip = {10, 0, 0, 1},
|
.ip = apIP,
|
||||||
.subnet = {255, 255, 255, 0},
|
.subnet = netMsk,
|
||||||
.gateway = {10, 0, 0, 1},
|
.gateway = apIP
|
||||||
},
|
},
|
||||||
.channel = 1,
|
.channel = configs.wifiApChannel.value,
|
||||||
.authmode = WIFI_AUTH_WPA2_PSK,
|
.authmode = configs.wifiApAuthmode.value,
|
||||||
.ssid_hidden = false,
|
.ssid_hidden = false,
|
||||||
.max_connection = 4,
|
.max_connection = 4,
|
||||||
.beacon_interval = 100
|
.beacon_interval = 100,
|
||||||
|
.long_range = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@@ -3,6 +3,12 @@
|
|||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <espwifiutils.h>
|
||||||
|
|
||||||
|
constexpr const wifi_stack::ip_address_t apIP{10, 0, 0, 1};
|
||||||
|
constexpr const wifi_stack::ip_address_t netMsk{255, 255, 255, 0};
|
||||||
|
|
||||||
void wifi_begin();
|
void wifi_begin();
|
||||||
|
|
||||||
void wifi_update();
|
void wifi_update();
|
||||||
|
Reference in New Issue
Block a user