switched to the recommended wifi station example

This commit is contained in:
Skot Croshere
2023-06-12 23:07:47 -04:00
committed by johnny9
parent 51b3d344ed
commit 486f35694e
5 changed files with 155 additions and 338 deletions

View File

@@ -3,5 +3,5 @@ SRCS
"connect.c" "connect.c"
INCLUDE_DIRS INCLUDE_DIRS
"include" "include"
PRIV_REQUIRES esp_netif REQUIRES nvs_flash
) )

View File

@@ -1,84 +1,67 @@
menu "WiFi Connection Configuration" menu "WiFi Configuration"
config EXAMPLE_WIFI_SSID config ESP_WIFI_SSID
string "WiFi SSID" string "WiFi SSID"
default "myssid" default "myssid"
help help
SSID (network name) for the example to connect to. SSID (network name) for the example to connect to.
config EXAMPLE_WIFI_PASSWORD config ESP_WIFI_PASSWORD
string "WiFi Password" string "WiFi Password"
default "mypassword" default "mypassword"
help help
WiFi password (WPA or WPA2) for the example to use. WiFi password (WPA or WPA2) for the example to use.
Can be left blank if the network has no security set.
choice EXAMPLE_WIFI_SCAN_METHOD choice ESP_WIFI_SAE_MODE
prompt "WiFi Scan Method" prompt "WPA3 SAE mode selection"
default EXAMPLE_WIFI_SCAN_METHOD_ALL_CHANNEL default ESP_WPA3_SAE_PWE_BOTH
help help
WiFi scan method: Select mode for SAE as Hunt and Peck, H2E or both.
config ESP_WPA3_SAE_PWE_HUNT_AND_PECK
If "Fast" is selected, scan will end after find SSID match AP. bool "HUNT AND PECK"
config ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
If "All Channel" is selected, scan will end after scan all the channel. bool "H2E"
config ESP_WPA3_SAE_PWE_BOTH
config EXAMPLE_WIFI_SCAN_METHOD_FAST bool "BOTH"
bool "Fast"
config EXAMPLE_WIFI_SCAN_METHOD_ALL_CHANNEL
bool "All Channel"
endchoice endchoice
config ESP_WIFI_PW_ID
config EXAMPLE_WIFI_SCAN_RSSI_THRESHOLD string "PASSWORD IDENTIFIER"
int "WiFi minimum rssi" depends on ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT|| ESP_WPA3_SAE_PWE_BOTH
range -127 0 default ""
default -127
help help
The minimum rssi to accept in the scan mode. password identifier for SAE H2E
choice EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD config ESP_MAXIMUM_RETRY
int "Maximum retry"
default 5
help
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
choice ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
prompt "WiFi Scan auth mode threshold" prompt "WiFi Scan auth mode threshold"
default EXAMPLE_WIFI_AUTH_OPEN default ESP_WIFI_AUTH_WPA2_PSK
help help
The weakest authmode to accept in the scan mode. The weakest authmode to accept in the scan mode.
This value defaults to ESP_WIFI_AUTH_WPA2_PSK incase password is present and ESP_WIFI_AUTH_OPEN is used.
Please select ESP_WIFI_AUTH_WEP/ESP_WIFI_AUTH_WPA_PSK incase AP is operating in WEP/WPA mode.
config EXAMPLE_WIFI_AUTH_OPEN config ESP_WIFI_AUTH_OPEN
bool "OPEN" bool "OPEN"
config EXAMPLE_WIFI_AUTH_WEP config ESP_WIFI_AUTH_WEP
bool "WEP" bool "WEP"
config EXAMPLE_WIFI_AUTH_WPA_PSK config ESP_WIFI_AUTH_WPA_PSK
bool "WPA PSK" bool "WPA PSK"
config EXAMPLE_WIFI_AUTH_WPA2_PSK config ESP_WIFI_AUTH_WPA2_PSK
bool "WPA2 PSK" bool "WPA2 PSK"
config EXAMPLE_WIFI_AUTH_WPA_WPA2_PSK config ESP_WIFI_AUTH_WPA_WPA2_PSK
bool "WPA WPA2 PSK" bool "WPA/WPA2 PSK"
config EXAMPLE_WIFI_AUTH_WPA2_ENTERPRISE config ESP_WIFI_AUTH_WPA3_PSK
bool "WPA2 ENTERPRISE"
config EXAMPLE_WIFI_AUTH_WPA3_PSK
bool "WPA3 PSK" bool "WPA3 PSK"
config EXAMPLE_WIFI_AUTH_WPA2_WPA3_PSK config ESP_WIFI_AUTH_WPA2_WPA3_PSK
bool "WPA2 WPA3 PSK" bool "WPA2/WPA3 PSK"
config EXAMPLE_WIFI_AUTH_WAPI_PSK config ESP_WIFI_AUTH_WAPI_PSK
bool "WAPI PSK" bool "WAPI PSK"
endchoice endchoice
choice EXAMPLE_WIFI_CONNECT_AP_SORT_METHOD
prompt "WiFi Connect AP Sort Method"
default EXAMPLE_WIFI_CONNECT_AP_BY_SIGNAL
help
WiFi connect AP sort method:
If "Signal" is selected, Sort matched APs in scan list by RSSI.
If "Security" is selected, Sort matched APs in scan list by security mode.
config EXAMPLE_WIFI_CONNECT_AP_BY_SIGNAL
bool "Signal"
config EXAMPLE_WIFI_CONNECT_AP_BY_SECURITY
bool "Security"
endchoice
endmenu endmenu

View File

@@ -1,244 +1,149 @@
/* Common functions for protocol examples, to establish Wi-Fi or Ethernet connection.
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 <string.h>
//#include "protocol_examples_common.h"
#include "connect.h"
#include "sdkconfig.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "esp_wifi_default.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/event_groups.h" #include "freertos/event_groups.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/err.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#define NR_OF_IP_ADDRESSES_TO_WAIT_FOR (s_active_interfaces) #define WIFI_SSD CONFIG_ESP_WIFI_SSID
#define WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
#define MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
#if CONFIG_EXAMPLE_WIFI_SCAN_METHOD_FAST #if CONFIG_ESP_WPA3_SAE_PWE_HUNT_AND_PECK
#define EXAMPLE_WIFI_SCAN_METHOD WIFI_FAST_SCAN #define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HUNT_AND_PECK
#elif CONFIG_EXAMPLE_WIFI_SCAN_METHOD_ALL_CHANNEL #define EXAMPLE_H2E_IDENTIFIER ""
#define EXAMPLE_WIFI_SCAN_METHOD WIFI_ALL_CHANNEL_SCAN
#elif CONFIG_ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HASH_TO_ELEMENT
#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
#elif CONFIG_ESP_WPA3_SAE_PWE_BOTH
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
#endif #endif
#if CONFIG_EXAMPLE_WIFI_CONNECT_AP_BY_SIGNAL #if CONFIG_ESP_WIFI_AUTH_OPEN
#define EXAMPLE_WIFI_CONNECT_AP_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
#elif CONFIG_EXAMPLE_WIFI_CONNECT_AP_BY_SECURITY #elif CONFIG_ESP_WIFI_AUTH_WEP
#define EXAMPLE_WIFI_CONNECT_AP_SORT_METHOD WIFI_CONNECT_AP_BY_SECURITY #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
#endif #endif
#if CONFIG_EXAMPLE_WIFI_AUTH_OPEN /* FreeRTOS event group to signal when we are connected*/
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN static EventGroupHandle_t s_wifi_event_group;
#elif CONFIG_EXAMPLE_WIFI_AUTH_WEP
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA_PSK
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA2_PSK
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA_WPA2_PSK
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA2_ENTERPRISE
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_ENTERPRISE
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA3_PSK
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
#elif CONFIG_EXAMPLE_WIFI_AUTH_WPA2_WPA3_PSK
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
#elif CONFIG_EXAMPLE_WIFI_AUTH_WAPI_PSK
#define EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
#endif
static int s_active_interfaces = 0; /* The event group allows multiple bits for each event, but we only care about two events:
static xSemaphoreHandle s_semph_get_ip_addrs; * - we are connected to the AP with an IP
static esp_netif_t *s_example_esp_netif = NULL; * - we failed to connect after the maximum amount of retries */
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
static const char *TAG = "example_connect"; static const char *TAG = "wifi station";
static esp_netif_t *wifi_start(void); static int s_retry_num = 0;
static void wifi_stop(void);
/** static void event_handler(void* arg, esp_event_base_t event_base,
* @brief Checks the netif description if it contains specified prefix. int32_t event_id, void* event_data)
* All netifs created withing common connect component are prefixed with the module TAG,
* so it returns true if the specified netif is owned by this module
*/
static bool is_our_netif(const char *prefix, esp_netif_t *netif)
{ {
return strncmp(prefix, esp_netif_get_desc(netif), strlen(prefix) - 1) == 0; if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
} esp_wifi_connect();
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
/* set up connection, Wi-Fi and/or Ethernet */ if (s_retry_num < MAXIMUM_RETRY) {
static void start(void) esp_wifi_connect();
{ s_retry_num++;
ESP_LOGI(TAG, "retry to connect to the AP");
s_example_esp_netif = wifi_start(); } else {
s_active_interfaces++; xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
/* create semaphore if at least one interface is active */
s_semph_get_ip_addrs = xSemaphoreCreateCounting(NR_OF_IP_ADDRESSES_TO_WAIT_FOR, 0);
}
/* tear down connection, release resources */
static void stop(void)
{
wifi_stop();
s_active_interfaces--;
}
static esp_ip4_addr_t s_ip_addr;
static void on_got_ip(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
if (!is_our_netif(TAG, event->esp_netif)) {
ESP_LOGW(TAG, "Got IPv4 from another interface \"%s\": ignored", esp_netif_get_desc(event->esp_netif));
return;
}
ESP_LOGI(TAG, "Got IPv4 event: Interface \"%s\" address: " IPSTR, esp_netif_get_desc(event->esp_netif), IP2STR(&event->ip_info.ip));
memcpy(&s_ip_addr, &event->ip_info.ip, sizeof(s_ip_addr));
xSemaphoreGive(s_semph_get_ip_addrs);
}
esp_err_t wifi_connect(void)
{
if (s_semph_get_ip_addrs != NULL) {
return ESP_ERR_INVALID_STATE;
}
start();
ESP_ERROR_CHECK(esp_register_shutdown_handler(&stop));
ESP_LOGI(TAG, "Waiting for IP(s)");
for (int i = 0; i < NR_OF_IP_ADDRESSES_TO_WAIT_FOR; ++i) {
xSemaphoreTake(s_semph_get_ip_addrs, portMAX_DELAY);
}
// iterate over active interfaces, and print out IPs of "our" netifs
esp_netif_t *netif = NULL;
esp_netif_ip_info_t ip;
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
netif = esp_netif_next(netif);
if (is_our_netif(TAG, netif)) {
ESP_LOGI(TAG, "Connected to %s", esp_netif_get_desc(netif));
ESP_ERROR_CHECK(esp_netif_get_ip_info(netif, &ip));
ESP_LOGI(TAG, "- IPv4 address: " IPSTR, IP2STR(&ip.ip));
} }
ESP_LOGI(TAG,"connect to the AP fail");
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
} }
return ESP_OK;
} }
esp_err_t example_disconnect(void) void wifi_init_sta(void)
{ {
if (s_semph_get_ip_addrs == NULL) { s_wifi_event_group = xEventGroupCreate();
return ESP_ERR_INVALID_STATE;
}
vSemaphoreDelete(s_semph_get_ip_addrs);
s_semph_get_ip_addrs = NULL;
stop();
ESP_ERROR_CHECK(esp_unregister_shutdown_handler(&stop));
return ESP_OK;
}
ESP_ERROR_CHECK(esp_netif_init());
static void on_wifi_disconnect(void *arg, esp_event_base_t event_base, ESP_ERROR_CHECK(esp_event_loop_create_default());
int32_t event_id, void *event_data) esp_netif_create_default_wifi_sta();
{
ESP_LOGI(TAG, "Wi-Fi disconnected, trying to reconnect...");
esp_err_t err = esp_wifi_connect();
if (err == ESP_ERR_WIFI_NOT_STARTED) {
return;
}
ESP_ERROR_CHECK(err);
}
static esp_netif_t *wifi_start(void)
{
char *desc;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_init(&cfg));
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA(); esp_event_handler_instance_t instance_any_id;
// Prefix the interface description with the module TAG esp_event_handler_instance_t instance_got_ip;
// Warning: the interface desc is used in tests to capture actual connection details (IP, gw, mask) ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
asprintf(&desc, "%s: %s", TAG, esp_netif_config.if_desc); ESP_EVENT_ANY_ID,
esp_netif_config.if_desc = desc; &event_handler,
esp_netif_config.route_prio = 128; NULL,
esp_netif_t *netif = esp_netif_create_wifi(WIFI_IF_STA, &esp_netif_config); &instance_any_id));
free(desc); ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
esp_wifi_set_default_wifi_sta_handlers(); IP_EVENT_STA_GOT_IP,
&event_handler,
NULL,
&instance_got_ip));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &on_wifi_disconnect, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &on_got_ip, NULL));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
wifi_config_t wifi_config = { wifi_config_t wifi_config = {
.sta = { .sta = {
.ssid = CONFIG_EXAMPLE_WIFI_SSID, .ssid = WIFI_SSD,
.password = CONFIG_EXAMPLE_WIFI_PASSWORD, .password = WIFI_PASS,
.scan_method = EXAMPLE_WIFI_SCAN_METHOD, /* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (pasword len => 8).
.sort_method = EXAMPLE_WIFI_CONNECT_AP_SORT_METHOD, * If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
.threshold.rssi = CONFIG_EXAMPLE_WIFI_SCAN_RSSI_THRESHOLD, * to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
.threshold.authmode = EXAMPLE_WIFI_SCAN_AUTH_MODE_THRESHOLD, * WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
*/
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
// .sae_pwe_h2e = ESP_WIFI_SAE_MODE,
// .sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER,
}, },
}; };
ESP_LOGI(TAG, "Connecting to %s...", wifi_config.sta.ssid); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); ESP_ERROR_CHECK(esp_wifi_start() );
ESP_ERROR_CHECK(esp_wifi_start());
esp_wifi_connect();
return netif;
}
static void wifi_stop(void) ESP_LOGI(TAG, "wifi_init_sta finished.");
{
esp_netif_t *wifi_netif = get_example_netif_from_desc("sta"); /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &on_wifi_disconnect)); * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &on_got_ip)); EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
esp_err_t err = esp_wifi_stop(); WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
if (err == ESP_ERR_WIFI_NOT_INIT) { pdFALSE,
return; pdFALSE,
portMAX_DELAY);
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */
if (bits & WIFI_CONNECTED_BIT) {
ESP_LOGI(TAG, "Connected to SSID: %s", WIFI_SSD);
} else if (bits & WIFI_FAIL_BIT) {
ESP_LOGI(TAG, "Failed to connect to SSID: %s, password:%s", WIFI_SSD);
} else {
ESP_LOGE(TAG, "UNEXPECTED EVENT");
} }
ESP_ERROR_CHECK(err); }
ESP_ERROR_CHECK(esp_wifi_deinit());
ESP_ERROR_CHECK(esp_wifi_clear_default_wifi_driver_and_handlers(wifi_netif));
esp_netif_destroy(wifi_netif);
s_example_esp_netif = NULL;
}
esp_netif_t *get_example_netif(void)
{
return s_example_esp_netif;
}
esp_netif_t *get_example_netif_from_desc(const char *desc)
{
esp_netif_t *netif = NULL;
char *expected_desc;
asprintf(&expected_desc, "%s: %s", TAG, desc);
while ((netif = esp_netif_next(netif)) != NULL) {
if (strcmp(esp_netif_get_desc(netif), expected_desc) == 0) {
free(expected_desc);
return netif;
}
}
free(expected_desc);
return netif;
}

View File

@@ -1,77 +1,9 @@
/* Common functions for protocol examples, to establish Wi-Fi or Ethernet connection.
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.
*/
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_err.h"
#include "esp_netif.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include <lwip/netdb.h> #include <lwip/netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
void wifi_init_sta(void);
#define EXAMPLE_INTERFACE get_example_netif()
/**
* @brief Configure Wi-Fi or Ethernet, connect, wait for IP
*
* This all-in-one helper function is used in protocols examples to
* reduce the amount of boilerplate in the example.
*
* It is not intended to be used in real world applications.
* See examples under examples/wifi/getting_started/ and examples/ethernet/
* for more complete Wi-Fi or Ethernet initialization code.
*
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*
* @return ESP_OK on successful connection
*/
esp_err_t wifi_connect(void);
/**
* Counterpart to example_connect, de-initializes Wi-Fi or Ethernet
*/
esp_err_t example_disconnect(void);
/**
* @brief Configure stdin and stdout to use blocking I/O
*
* This helper function is used in ASIO examples. It wraps installing the
* UART driver and configuring VFS layer to use UART driver for console I/O.
*/
esp_err_t example_configure_stdin_stdout(void);
/**
* @brief Returns esp-netif pointer created by example_connect()
*
* @note If multiple interfaces active at once, this API return NULL
* In that case the get_example_netif_from_desc() should be used
* to get esp-netif pointer based on interface description
*/
esp_netif_t *get_example_netif(void);
/**
* @brief Returns esp-netif pointer created by example_connect() described by
* the supplied desc field
*
* @param desc Textual interface of created network interface, for example "sta"
* indicate default WiFi station, "eth" default Ethernet interface.
*
*/
esp_netif_t *get_example_netif_from_desc(const char *desc);
#ifdef __cplusplus
}
#endif

View File

@@ -29,16 +29,13 @@ void app_main(void)
{ {
ESP_LOGI(TAG, "Welcome to the bitaxe!"); ESP_LOGI(TAG, "Welcome to the bitaxe!");
ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init()); //ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default()); //ESP_ERROR_CHECK(esp_event_loop_create_default());
xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void*)&GLOBAL_STATE.SYSTEM_MODULE, 10, NULL); xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void*)&GLOBAL_STATE.SYSTEM_MODULE, 10, NULL);
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
* Read "Establishing Wi-Fi or Ethernet Connection" section in wifi_init_sta();
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(wifi_connect());
queue_init(&GLOBAL_STATE.stratum_queue); queue_init(&GLOBAL_STATE.stratum_queue);
queue_init(&GLOBAL_STATE.ASIC_jobs_queue); queue_init(&GLOBAL_STATE.ASIC_jobs_queue);