Just started to look at the espidf framework.
I am on windows VSCode.
Platformio.ini
Code: Select all
[env:esp32doit-devkit-v1]
platform = espressif32
board = wemosbat
framework = espidf
upload_port = com9
monitor_speed=115200
monitor_port = com9
I was using their example at
https://docs.platformio.org/en/latest/t ... lysis.html
I will include my current code, but the bottom line when I used tcpip_adapter_init() it works and if I use esp_netif_init it can not get an IP. The log shows a connect but my device after timeout says it can not obtain IP.
This may not be a bug but my limited understanding of the framework and wifi library.
I saw the depreciation message, so as part of my learning I was going to fix it.
I assumed it was just a matter of switching names for functions. If I understand that these two functions only handle the hardware layer, I would think the upper layers (DHCP) would have been the same, correct?
Here is a log of sucssufull (
tcpip_adapter_init()) connect and DHCP assigned IP.
Code: Select all
I (18529) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (18529) wifi:station: a0:cc:2b:1c:4f:8e join, AID=1, bgn, 20
␛[0;32mI (18589) wifi softAP: station a0:cc:2b:1c:4f:8e join, AID=1␛[0m
W (18769) wifi:<ba-add>idx:4 (ifx:1, a0:cc:2b:1c:4f:8e), tid:6, ssn:0, winSize:64
␛[0;32mI (19179) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2␛[0m
I (386639) wifi:station: a0:cc:2b:1c:4f:8e leave, AID = 1, bss_flags is 658547, bss:0x3ffba33c
I (386639) wifi:new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
W (386639) wifi:<ba-del>idx
␛[0;32mI (386639) wifi softAP: station a0:cc:2b:1c:4f:8e leave, AID=1␛[0m
Hre is a log of unsucssufull (
esp_netif_init()) connect and DHCP assigned IP.
Code: Select all
I (19329) wifi:new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (19339) wifi:station: a0:cc:2b:1c:4f:8e join, AID=1, bgn, 20
␛[0;32mI (19419) wifi softAP: station a0:cc:2b:1c:4f:8e join, AID=1␛[0m
W (19569) wifi:<ba-add>idx:4 (ifx:1, a0:cc:2b:1c:4f:8e), tid:6, ssn:0, winSize:64
I (55739) wifi:station: a0:cc:2b:1c:4f:8e leave, AID = 1, bss_flags is 658547, bss:0x3ffba33c
The only difference is unremarked the tcpip_adaper vs esp_netif
Here is the code:
Code: Select all
/* WiFi softAP Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#define EXAMPLE_ESP_WIFI_SSID "PaulTest"
#define EXAMPLE_ESP_WIFI_PASS "abcd1234"
#define EXAMPLE_MAX_STA_CONN (3)
static const char *TAG = "wifi softAP";
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
MAC2STR(event->mac), event->aid);
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
void wifi_init_softap()
{
//tcpip_adapter_init();
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
wifi_config_t wifi_config = {
.ap = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
.password = EXAMPLE_ESP_WIFI_PASS,
.max_connection = EXAMPLE_MAX_STA_CONN,
.authmode = WIFI_AUTH_WPA_WPA2_PSK
},
};
if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) {
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
}
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "wifi_init_softap finished. SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
void app_main()
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "ESP_WIFI_MODE_AP");
wifi_init_softap();
}