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 <cstring>
|
||||||
|
|
||||||
#include "wireless/WifiManager.h"
|
|
||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
#include "constants/wifi.h"
|
#include "constants/wifi.h"
|
||||||
|
#include "wireless/WifiManager.h"
|
||||||
|
|
||||||
#define TAG "WifiManager"
|
#define TAG "WifiManager"
|
||||||
#define SOFTAP_SCAN_FREQUENCY_MS 30000
|
#define SOFTAP_SCAN_FREQUENCY_MS 30000
|
||||||
@@ -51,7 +51,9 @@ int WifiManager::disconnect() {
|
|||||||
break;
|
break;
|
||||||
case wifi_state::broadcasting:
|
case wifi_state::broadcasting:
|
||||||
ESP_LOGI(TAG, "Broadcasting in softap mode");
|
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
|
handle_broadcasting(); // scans for known networks
|
||||||
break;
|
break;
|
||||||
case wifi_state::disconnect:
|
case wifi_state::disconnect:
|
||||||
@@ -85,7 +87,8 @@ int WifiManager::init_connection() {
|
|||||||
this->handle_disconnect();
|
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();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
esp_wifi_init(&cfg);
|
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);
|
esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, wifi_event_handler, this);
|
||||||
|
|
||||||
wifi_config_t wifi_configuration;
|
wifi_config_t wifi_configuration;
|
||||||
wifi_configuration = {
|
wifi_configuration = {.sta = {}};
|
||||||
.sta = {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string ssid = m_config_manager.get_wifi_ssid();
|
std::string ssid = m_config_manager.get_wifi_ssid();
|
||||||
std::string pass = m_config_manager.get_wifi_password();
|
std::string pass = m_config_manager.get_wifi_password();
|
||||||
@@ -187,7 +187,8 @@ int WifiManager::init_softap() {
|
|||||||
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, this);
|
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, this);
|
||||||
|
|
||||||
wifi_config_t wifi_configuration = {
|
wifi_config_t wifi_configuration = {
|
||||||
.ap = {
|
.ap =
|
||||||
|
{
|
||||||
.ssid = WIFI_SSID,
|
.ssid = WIFI_SSID,
|
||||||
.password = "",
|
.password = "",
|
||||||
.channel = SOFTAP_CHANNEL,
|
.channel = SOFTAP_CHANNEL,
|
||||||
@@ -205,7 +206,7 @@ int WifiManager::init_softap() {
|
|||||||
|
|
||||||
esp_wifi_start();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -217,8 +218,8 @@ void WifiManager::update_state(const wifi_state state) {
|
|||||||
xSemaphoreGive(this->m_mutex);
|
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) {
|
void WifiManager::wifi_event_handler(void *event_handler_arg, esp_event_base_t event_base,
|
||||||
// Passed in as a parameter since c (freertos) cannot call the member function directly.
|
const int32_t event_id, void *event_data) {
|
||||||
const auto that = static_cast<WifiManager *>(event_handler_arg);
|
const auto that = static_cast<WifiManager *>(event_handler_arg);
|
||||||
|
|
||||||
if (WIFI_EVENT_STA_START == event_id) {
|
if (WIFI_EVENT_STA_START == event_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user