Hi, so I am trying to write an implementation for Wifi in AP mode.
Her is the code
_broadcast.h
#ifndef BROADCASTED_SERVER_H
#define BROADCASTED_SERVER_H
#include <esp_http_server.h>
class BroadcastedServer {
public:
BroadcastedServer();
void begin();
private:
static esp_err_t testHandler(httpd_req_t *req);
httpd_handle_t server;
};
#endif
_broadcast.cpp
#include "_broadcast.h"
#include <string.h>
#include <esp_log.h>
#include "esp_wifi.h"
#include "esp_netif.h"
#include "nvs_flash.h" // Add this header for NVS related functions
BroadcastedServer::BroadcastedServer() : server(NULL) {}
void BroadcastedServer::begin() {
// Initialize the NVS
ESP_ERROR_CHECK(nvs_flash_erase());
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
// If NVS storage was not initialized yet, erase it and initialize again
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
// Initialize the Wi-Fi module
ESP_ERROR_CHECK(esp_netif_init());
esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap();
assert(ap_netif);
wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&wifi_cfg));
// Configure the ESP32 as an AP
//esp_netif_create_default_wifi_ap(); // Create a default WiFi AP netif
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
ESP_ERROR_CHECK(esp_wifi_start());
wifi_config_t ap_config = {
.ap = {
.ssid = "HIVE",
.password = "LMHIVE2DRONE",
.authmode = WIFI_AUTH_OPEN,
.max_connection = 1, // Set the maximum number of connections allowed
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config));
// Start the HTTP server
/*httpd_config_t config = HTTPD_DEFAULT_CONFIG();
if (httpd_start(&server, &config) == ESP_OK) {
httpd_uri_t testUri = {
.uri = "/test",
.method = HTTP_GET,
.handler = testHandler,
.user_ctx = NULL
};
httpd_register_uri_handler(server, &testUri);
}*/
}
esp_err_t BroadcastedServer::testHandler(httpd_req_t *req) {
const char resp[] = "<h1>Hello World</h1>";
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
return ESP_OK;
}
I am able to build and flash to the esp32 and the network is created and shows on other devices. However when I try to connect on a client it is stuck on loading and the output from the esp 32 is:
I (3011) wifi:mode : softAP (ec:62:60:76:2c:8d)
I (3011) wifi:Total power save buffer number: 16
I (3011) wifi:Init max length of beacon: 752/752
I (3011) wifi:Init max length of beacon: 752/752
E (3011) wifi:failed to post WiFi event=12 ret=259
E (3021) wifi:failed to post WiFi event=13 ret=259
I (3021) wifi:Total power save buffer number: 16
E (3031) wifi:failed to post WiFi event=12 ret=259
I (3031) main_task: Returned from app_main()
I (7211) wifi<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (7211) wifi c6:81:73:28:c4:5e join, AID=1, bgn, 20
E (7211) wifi:failed to post WiFi event=14 ret=259
I (7501) wifi:<ba-add>idx:2 (ifx:1, c6:81:73:28:c4:5e), tid:0, ssn:0, winSize:64
What am I doing wrong?. Thanks
WIFI IN AP MODE IMPLEMENTATION ISSUE
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Baidu [Spider], Google [Bot] and 87 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.