This is the next step of this story.
I've set up an RPi as access point (SSID "IoT_and_Trains"), can connect to it with an android device, tested with an ESP-WROVER-KIT and this ESP_WifiScan application. The ESPWifiscan's output:
Code: Select all
Number of access points found: 10
======================================================================
SSID | RSSI | AUTH
======================================================================
devolo-8f4 | -19 | WIFI_AUTH_WPA2_PSK
devolo-guest-8f4 | -19 | WIFI_AUTH_OPEN
IoT_and_Trains | -32 | WIFI_AUTH_WPA2_PSK
polder | -61 | WIFI_AUTH_WPA_WPA2_PSK
| -62 | WIFI_AUTH_WPA2_PSK
PROXIMUS_FON | -79 | WIFI_AUTH_OPEN
WiFi-2.4-39C0 | -79 | WIFI_AUTH_WPA2_PSK
Proximus Smart Wi-Fi | -79 | Unknown
polder | -87 | WIFI_AUTH_WPA_WPA2_PSK
| -97 | WIFI_AUTH_WPA2_PSK
I started a new project based on the IDF-Template and modified main.cpp as follows:
Code: Select all
/*
* main.cpp
*
* Created on: May 10, 2018
* Author: paulvdbergh
*/
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "esp_log.h"
static char tag[] = "app_main";
#include <string.h>
#define RPI_SSID "IoT_and_Trains"
#define RPI_SSID_PWD "IoTTESP32"
esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id)
{
case SYSTEM_EVENT_WIFI_READY:
{
ESP_LOGI(tag, "SYSTEM_EVENT_WIFI_READY");
break;
}
case SYSTEM_EVENT_SCAN_DONE:
{
ESP_LOGI(tag, "SYSTEM_EVENT_SCAN_DONE");
break;
}
case SYSTEM_EVENT_STA_START:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_START");
break;
}
case SYSTEM_EVENT_STA_STOP:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_STOP");
break;
}
case SYSTEM_EVENT_STA_CONNECTED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_CONNECTED");
break;
}
case SYSTEM_EVENT_STA_DISCONNECTED:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_DISCONNECTED");
break;
}
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_AUTHMODE_CHANGE");
break;
}
case SYSTEM_EVENT_STA_GOT_IP:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_GOT_IP");
break;
}
case SYSTEM_EVENT_STA_LOST_IP:
{
ESP_LOGI(tag, "SYSTEM_EVENT_STA_LOST_IP");
break;
}
default:
{
ESP_LOGI(tag, "EventHandler received %i", event->event_id);
break;
}
}
return ESP_OK;
}
extern "C"
void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
wifi_config_t sta_config;
memcpy(&sta_config.sta.ssid, RPI_SSID, strlen(RPI_SSID));
memcpy(&sta_config.sta.password, RPI_SSID_PWD, strlen(RPI_SSID_PWD));
sta_config.sta.bssid_set = false;
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
ESP_ERROR_CHECK( esp_wifi_start() );
ESP_ERROR_CHECK( esp_wifi_connect() );
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
int level = 0;
while (true) {
gpio_set_level(GPIO_NUM_4, level);
level = !level;
vTaskDelay(300 / portTICK_PERIOD_MS);
}
}
When the global log level is set to info or lower, the connection fails... (see LogLevel_info.txt).
I'm searching for the reason why this happens...
Any suggestions or hints are very welcome.
Thanks in advance,
Paul.