mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
Fix AP mode
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "wireless/WifiManager.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "constants/wifi.h"
|
||||
#include "wireless/WifiManager.h"
|
||||
|
||||
#define TAG "WifiManager"
|
||||
#define SOFTAP_SCAN_FREQUENCY_MS 30000
|
||||
@@ -51,7 +51,9 @@ int WifiManager::disconnect() {
|
||||
break;
|
||||
case wifi_state::broadcasting:
|
||||
ESP_LOGI(TAG, "Broadcasting in softap mode");
|
||||
vTaskDelay(SOFTAP_SCAN_FREQUENCY_MS / portTICK_PERIOD_MS); // only scan every 30 seconds, as we may disconnect users
|
||||
vTaskDelay(SOFTAP_SCAN_FREQUENCY_MS /
|
||||
portTICK_PERIOD_MS); // only scan every 30 seconds, as we may
|
||||
// disconnect users
|
||||
handle_broadcasting(); // scans for known networks
|
||||
break;
|
||||
case wifi_state::disconnect:
|
||||
@@ -85,7 +87,8 @@ int WifiManager::init_connection() {
|
||||
this->handle_disconnect();
|
||||
}
|
||||
|
||||
this->m_netif = esp_netif_create_default_wifi_sta(); // Must be destroyed with esp_netif_destroy_default_wifi()
|
||||
this->m_netif = esp_netif_create_default_wifi_sta(); // Must be destroyed with
|
||||
// esp_netif_destroy_default_wifi()
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&cfg);
|
||||
@@ -94,10 +97,7 @@ int WifiManager::init_connection() {
|
||||
esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, wifi_event_handler, this);
|
||||
|
||||
wifi_config_t wifi_configuration;
|
||||
wifi_configuration = {
|
||||
.sta = {
|
||||
}
|
||||
};
|
||||
wifi_configuration = {.sta = {}};
|
||||
|
||||
std::string ssid = m_config_manager.get_wifi_ssid();
|
||||
std::string pass = m_config_manager.get_wifi_password();
|
||||
@@ -146,7 +146,7 @@ int WifiManager::handle_disconnect() {
|
||||
|
||||
int WifiManager::handle_broadcasting() {
|
||||
ESP_LOGI(TAG, "In softap mode, scanning for known networks");
|
||||
wifi_scan_config_t scan_config {};
|
||||
wifi_scan_config_t scan_config{};
|
||||
scan_config.ssid = reinterpret_cast<uint8_t *>(m_config_manager.get_wifi_ssid().data());
|
||||
scan_config.scan_time = {.passive = 500};
|
||||
|
||||
@@ -187,7 +187,8 @@ int WifiManager::init_softap() {
|
||||
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, this);
|
||||
|
||||
wifi_config_t wifi_configuration = {
|
||||
.ap = {
|
||||
.ap =
|
||||
{
|
||||
.ssid = WIFI_SSID,
|
||||
.password = "",
|
||||
.channel = SOFTAP_CHANNEL,
|
||||
@@ -205,7 +206,7 @@ int WifiManager::init_softap() {
|
||||
|
||||
esp_wifi_start();
|
||||
|
||||
esp_netif_set_default_netif(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));
|
||||
esp_netif_set_default_netif(esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -217,8 +218,8 @@ void WifiManager::update_state(const wifi_state state) {
|
||||
xSemaphoreGive(this->m_mutex);
|
||||
}
|
||||
|
||||
void WifiManager::wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base, const int32_t event_id, void *event_data) {
|
||||
// Passed in as a parameter since c (freertos) cannot call the member function directly.
|
||||
void WifiManager::wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base,
|
||||
const int32_t event_id, void *event_data) {
|
||||
const auto that = static_cast<WifiManager *>(event_handler_arg);
|
||||
|
||||
if (WIFI_EVENT_STA_START == event_id) {
|
||||
|
||||
Reference in New Issue
Block a user