face_recognition_solution example update (esp-idf v4.3)
- Migration from tcpip_adapter API to its successor ESP-NETIF. - Changes have been tested with ESP-IDF v4.3.1 on an ESP32-CAM (AI-Thinker).pull/181/head
parent
d9eb3bd63c
commit
61775dff09
|
@ -1,30 +1,212 @@
|
|||
menu "Example Configuration"
|
||||
|
||||
config ESP_WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
menu "WiFi Settings"
|
||||
config ESP_HOST_NAME
|
||||
string "Camera Host Name"
|
||||
default ""
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
Hostname that the camera will advertise over mDNS.
|
||||
|
||||
config ESP_WIFI_SSID
|
||||
string "WiFi STA SSID"
|
||||
default ""
|
||||
help
|
||||
WiFi SSID (network name) to connect to or empty for Off.
|
||||
|
||||
config ESP_WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
string "WiFi STA Password"
|
||||
default ""
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
WiFi Password if WEP/WPA/WPA2 or empty if Open.
|
||||
|
||||
config ESP_WIFI_AP_SSID
|
||||
string "WiFi AP SSID"
|
||||
default "ESP32-Camera"
|
||||
help
|
||||
AP SSID (network name) to create or empty for Off.
|
||||
|
||||
config ESP_WIFI_AP_PASSWORD
|
||||
string "WiFi AP Password"
|
||||
default ""
|
||||
help
|
||||
AP password for WPA2 or empty for Open.
|
||||
|
||||
config MAX_STA_CONN
|
||||
int "Maximal STA connections"
|
||||
default 1
|
||||
help
|
||||
Max number of the STA connects to AP.
|
||||
Max number of the STA connects to AP.
|
||||
|
||||
config ESP_WIFI_AP_CHANNEL
|
||||
string "WiFi AP Channel"
|
||||
default ""
|
||||
help
|
||||
AP channel for better connection performance.
|
||||
AP channel for better connection performance.
|
||||
|
||||
config SERVER_IP
|
||||
string "IP address of server"
|
||||
string "WiFi AP IP Address"
|
||||
default "192.168.4.1"
|
||||
help
|
||||
IP address that the ESP will assign to it's AP interface. You can use this IP to connect to the camera after flashing.
|
||||
|
||||
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.
|
||||
endmenu
|
||||
|
||||
menu "Camera Pins"
|
||||
choice CAMERA_MODEL
|
||||
bool "Select Camera Pinout"
|
||||
default CAMERA_MODEL_WROVER_KIT
|
||||
help
|
||||
Select Camera Pinout.
|
||||
|
||||
config CAMERA_MODEL_WROVER_KIT
|
||||
bool "WROVER-KIT With OV2640 Module"
|
||||
config CAMERA_MODEL_ESP32_CAM_BOARD
|
||||
bool "ESP32 Camera Development Board"
|
||||
config CAMERA_MODEL_ESP_EYE
|
||||
bool "ESP_EYE DevKit"
|
||||
config CAMERA_MODEL_M5STACK_PSRAM
|
||||
bool "M5Stack Camera With PSRAM"
|
||||
config CAMERA_MODEL_M5STACK_WIDE
|
||||
bool "M5Stack Camera F (Wide)"
|
||||
config CAMERA_MODEL_AI_THINKER
|
||||
bool "ESP32-CAM by AI-Thinker"
|
||||
config CAMERA_MODEL_CUSTOM
|
||||
bool "Custom Camera Pinout"
|
||||
endchoice
|
||||
|
||||
config CAMERA_PIN_PWDN
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Power Down pin"
|
||||
range -1 33
|
||||
default -1
|
||||
help
|
||||
Select Power Down pin or -1 for unmanaged.
|
||||
|
||||
config CAMERA_PIN_RESET
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Reset pin"
|
||||
range -1 33
|
||||
default -1
|
||||
help
|
||||
Select Camera Reset pin or -1 for software reset.
|
||||
|
||||
config CAMERA_PIN_XCLK
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "XCLK pin"
|
||||
range 0 33
|
||||
default 21
|
||||
help
|
||||
Select Camera XCLK pin.
|
||||
|
||||
config CAMERA_PIN_SIOD
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "SIOD pin"
|
||||
range 0 33
|
||||
default 26
|
||||
help
|
||||
Select Camera SIOD pin.
|
||||
|
||||
config CAMERA_PIN_SIOC
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "SIOC pin"
|
||||
range 0 33
|
||||
default 27
|
||||
help
|
||||
Select Camera SIOC pin.
|
||||
|
||||
config CAMERA_PIN_VSYNC
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "VSYNC pin"
|
||||
range 0 39
|
||||
default 25
|
||||
help
|
||||
Select Camera VSYNC pin.
|
||||
|
||||
config CAMERA_PIN_HREF
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "HREF pin"
|
||||
range 0 39
|
||||
default 23
|
||||
help
|
||||
Select Camera HREF pin.
|
||||
|
||||
config CAMERA_PIN_PCLK
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "PCLK pin"
|
||||
range 0 39
|
||||
default 25
|
||||
help
|
||||
Select Camera PCLK pin.
|
||||
|
||||
config CAMERA_PIN_Y2
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y2 pin"
|
||||
range 0 39
|
||||
default 4
|
||||
help
|
||||
Select Camera Y2 pin.
|
||||
|
||||
config CAMERA_PIN_Y3
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y3 pin"
|
||||
range 0 39
|
||||
default 5
|
||||
help
|
||||
Select Camera Y3 pin.
|
||||
|
||||
config CAMERA_PIN_Y4
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y4 pin"
|
||||
range 0 39
|
||||
default 18
|
||||
help
|
||||
Select Camera Y4 pin.
|
||||
|
||||
config CAMERA_PIN_Y5
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y5 pin"
|
||||
range 0 39
|
||||
default 19
|
||||
help
|
||||
Select Camera Y5 pin.
|
||||
|
||||
config CAMERA_PIN_Y6
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y6 pin"
|
||||
range 0 39
|
||||
default 36
|
||||
help
|
||||
Select Camera Y6 pin.
|
||||
|
||||
config CAMERA_PIN_Y7
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y7 pin"
|
||||
range 0 39
|
||||
default 39
|
||||
help
|
||||
Select Camera Y7 pin.
|
||||
|
||||
config CAMERA_PIN_Y8
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y8 pin"
|
||||
range 0 39
|
||||
default 34
|
||||
help
|
||||
Select Camera Y8 pin.
|
||||
|
||||
config CAMERA_PIN_Y9
|
||||
depends on CAMERA_MODEL_CUSTOM
|
||||
int "Y9 pin"
|
||||
range 0 39
|
||||
default 35
|
||||
help
|
||||
Select Camera Y9 pin.
|
||||
|
||||
endmenu
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -20,12 +20,14 @@
|
|||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "app_camera.h"
|
||||
|
||||
static const char *TAG = "app_camera";
|
||||
|
||||
void app_camera_init()
|
||||
{
|
||||
#if CONFIG_CAMERA_MODEL_ESP_EYE || CONFIG_CAMERA_MODEL_ESP32_CAM_BOARD
|
||||
/* IO13, IO14 is designed for JTAG by default,
|
||||
* to use it as generalized input,
|
||||
* firstly declair it as pullup input */
|
||||
|
@ -38,6 +40,7 @@ void app_camera_init()
|
|||
gpio_config(&conf);
|
||||
conf.pin_bit_mask = 1LL << 14;
|
||||
gpio_config(&conf);
|
||||
#endif
|
||||
|
||||
camera_config_t config;
|
||||
config.ledc_channel = LEDC_CHANNEL_0;
|
||||
|
|
|
@ -99,10 +99,10 @@ void app_main()
|
|||
g_state = WAIT_FOR_WAKEUP;
|
||||
|
||||
vTaskDelay(30 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI("esp-eye", "Please say 'Hi LeXin' to the board");
|
||||
ESP_LOGI("esp-eye", "Version "VERSION);
|
||||
ESP_LOGI("esp-board", "Please say 'Hi LeXin' to the board");
|
||||
ESP_LOGI("esp-board", "Version "VERSION);
|
||||
while (g_state == WAIT_FOR_WAKEUP)
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
app_wifi_init();
|
||||
app_camera_init();
|
||||
app_httpserver_init();
|
||||
|
|
|
@ -20,169 +20,263 @@
|
|||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_netif.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
|
||||
#include "app_wifi.h"
|
||||
|
||||
static const char *TAG = "app_wifi";
|
||||
/* The examples use WiFi configuration that you can set via 'make menuconfig'.
|
||||
|
||||
#define EXAMPLE_ESP_WIFI_MODE_AP 1 //TRUE:AP FALSE:STA
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#define EXAMPLE_MAX_STA_CONN CONFIG_MAX_STA_CONN
|
||||
#define EXAMPLE_IP_ADDR CONFIG_SERVER_IP
|
||||
#define EXAMPLE_ESP_WIFI_AP_CHANNEL CONFIG_ESP_WIFI_AP_CHANNEL
|
||||
If you'd rather not, just change the below entries to strings with
|
||||
the config you want - ie #define ESP_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{/*{{{*/
|
||||
switch(event->event_id) {
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
ESP_LOGI(TAG, "got ip:%s",
|
||||
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STACONNECTED:
|
||||
ESP_LOGI(TAG, "station:" MACSTR " join, AID=%d",
|
||||
MAC2STR(event->event_info.sta_connected.mac),
|
||||
event->event_info.sta_connected.aid);
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STADISCONNECTED:
|
||||
ESP_LOGI(TAG, "station:" MACSTR " leave, AID=%d",
|
||||
MAC2STR(event->event_info.sta_disconnected.mac),
|
||||
event->event_info.sta_disconnected.aid);
|
||||
#define ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#define ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}/*}}}*/
|
||||
#define ESP_WIFI_AP_SSID CONFIG_ESP_WIFI_AP_SSID
|
||||
#define ESP_WIFI_AP_PASS CONFIG_ESP_WIFI_AP_PASSWORD
|
||||
#define MAX_STA_CONN CONFIG_MAX_STA_CONN
|
||||
#define SERVER_IP_ADDR CONFIG_SERVER_IP
|
||||
#define ESP_WIFI_AP_CHANNEL CONFIG_ESP_WIFI_AP_CHANNEL
|
||||
|
||||
#if EXAMPLE_ESP_WIFI_MODE_AP
|
||||
static void wifi_init_softap()
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event,
|
||||
* For STA events handling, we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
static const char *TAG = "App_Wifi";
|
||||
|
||||
static int s_retry_num = 0;
|
||||
|
||||
esp_netif_t *AP_netif;
|
||||
esp_netif_t *STA_netif;
|
||||
|
||||
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
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);
|
||||
}
|
||||
|
||||
if (strcmp(EXAMPLE_IP_ADDR, "192.168.4.1"))
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < ESP_MAXIMUM_RETRY) {
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_softap(wifi_mode_t mode)
|
||||
{
|
||||
/* default event loop from esp_event library */
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
AP_netif = esp_netif_create_default_wifi_ap();
|
||||
assert(AP_netif);
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&wifi_event_handler,
|
||||
NULL,
|
||||
NULL));
|
||||
|
||||
if (strcmp(SERVER_IP_ADDR, "192.168.4.1"))
|
||||
{
|
||||
int a, b, c, d;
|
||||
sscanf(EXAMPLE_IP_ADDR, "%d.%d.%d.%d", &a, &b, &c, &d);
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
IP4_ADDR(&ip_info.ip, a, b, c, d);
|
||||
IP4_ADDR(&ip_info.gw, a, b, c, d);
|
||||
IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
|
||||
ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(WIFI_IF_AP));
|
||||
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(WIFI_IF_AP, &ip_info));
|
||||
ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(WIFI_IF_AP));
|
||||
sscanf(SERVER_IP_ADDR, "%d.%d.%d.%d", &a, &b, &c, &d);
|
||||
esp_netif_ip_info_t ip_info;
|
||||
esp_netif_set_ip4_addr(&ip_info.ip, a, b, c, d);
|
||||
esp_netif_set_ip4_addr(&ip_info.gw, a, b, c, d);
|
||||
esp_netif_set_ip4_addr(&ip_info.netmask, 255, 255, 255, 0);
|
||||
ESP_ERROR_CHECK(esp_netif_dhcps_stop(AP_netif));
|
||||
ESP_ERROR_CHECK(esp_netif_set_ip_info(AP_netif, &ip_info));
|
||||
ESP_ERROR_CHECK(esp_netif_dhcps_start(AP_netif));
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
uint8_t mac[6];
|
||||
ESP_ERROR_CHECK(esp_wifi_get_mac(ESP_IF_WIFI_AP, mac));
|
||||
|
||||
wifi_config_t wifi_config;
|
||||
memset(&wifi_config, 0, sizeof(wifi_config_t));
|
||||
if (strlen(EXAMPLE_ESP_WIFI_SSID) == 0)
|
||||
{
|
||||
snprintf((char *)wifi_config.ap.ssid, 32, "esp-eye-%x%x", mac[4], mac[5]);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(wifi_config.ap.ssid, EXAMPLE_ESP_WIFI_SSID, sizeof(EXAMPLE_ESP_WIFI_SSID));
|
||||
}
|
||||
memcpy(wifi_config.ap.password, EXAMPLE_ESP_WIFI_PASS, sizeof(EXAMPLE_ESP_WIFI_PASS));
|
||||
wifi_config.ap.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID);
|
||||
wifi_config.ap.max_connection = EXAMPLE_MAX_STA_CONN;
|
||||
|
||||
snprintf((char*)wifi_config.ap.ssid, 32, "%s", ESP_WIFI_AP_SSID);
|
||||
wifi_config.ap.ssid_len = strlen((char*)wifi_config.ap.ssid);
|
||||
snprintf((char*)wifi_config.ap.password, 64, "%s", ESP_WIFI_AP_PASS);
|
||||
|
||||
wifi_config.ap.max_connection = MAX_STA_CONN;
|
||||
wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
|
||||
if (strlen(EXAMPLE_ESP_WIFI_AP_CHANNEL)) {
|
||||
int channel;
|
||||
sscanf(EXAMPLE_ESP_WIFI_AP_CHANNEL, "%d", &channel);
|
||||
wifi_config.ap.channel = channel;
|
||||
}
|
||||
if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) {
|
||||
|
||||
if (strlen(ESP_WIFI_AP_PASS) == 0) {
|
||||
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
||||
}
|
||||
|
||||
esp_wifi_set_ps(WIFI_PS_NONE);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
||||
if (strlen(ESP_WIFI_AP_CHANNEL)) {
|
||||
int channel;
|
||||
sscanf(ESP_WIFI_AP_CHANNEL, "%d", &channel);
|
||||
wifi_config.ap.channel = channel;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(mode));
|
||||
// "esp_wifi_set_config" can be called only when specified interface is enabled, otherwise, API fail
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_softap finished.SSID:%s password:%s",
|
||||
wifi_config.ap.ssid, EXAMPLE_ESP_WIFI_PASS);
|
||||
|
||||
char buf[80];
|
||||
sprintf(buf, "SSID:%s", wifi_config.ap.ssid);
|
||||
sprintf(buf, "PASSWORD:%s", wifi_config.ap.password);
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_softap finished. SSID : %s password : %s channel : %s",
|
||||
ESP_WIFI_AP_SSID, ESP_WIFI_AP_PASS, ESP_WIFI_AP_CHANNEL);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void wifi_init_sta()
|
||||
void wifi_init_sta(wifi_mode_t mode)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
wifi_config_t wifi_config = {0};
|
||||
memset(&wifi_config, 0, sizeof(wifi_config_t));
|
||||
memcpy(wifi_config.sta.ssid, EXAMPLE_ESP_WIFI_SSID, sizeof(EXAMPLE_ESP_WIFI_SSID));
|
||||
memcpy(wifi_config.sta.password, EXAMPLE_ESP_WIFI_PASS, sizeof(EXAMPLE_ESP_WIFI_PASS));
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
STA_netif = esp_netif_create_default_wifi_sta();
|
||||
assert(STA_netif);
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&wifi_event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&wifi_event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
.pmf_cfg = {
|
||||
.capable = true,
|
||||
.required = false
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
snprintf((char*)wifi_config.sta.ssid, 32, "%s", ESP_WIFI_SSID);
|
||||
snprintf((char*)wifi_config.sta.password, 64, "%s", ESP_WIFI_PASS);
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(mode));
|
||||
// "esp_wifi_set_config" can be called only when specified interface is enabled, otherwise, API fail
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "connect to ap SSID:%s password:%s", wifi_config.sta.ssid, wifi_config.sta.password);
|
||||
ESP_LOGI(TAG, "wifi_init_STA finished.");
|
||||
|
||||
char buf[80];
|
||||
sprintf(buf, "SSID:%s", wifi_config.sta.ssid);
|
||||
sprintf(buf, "PASSWORD:%s", wifi_config.sta.password);
|
||||
// Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
// number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above)
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
// xEventGroupWaitBits() returns the bits before the call returned,
|
||||
// hence we can test which event actually happened.
|
||||
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
wifi_ap_record_t AP_info;
|
||||
ESP_ERROR_CHECK(esp_wifi_sta_get_ap_info(&AP_info));
|
||||
ESP_LOGI(TAG, "connected to AP, SSID : %s Channel : %d Strength : %d Authmode : %d",
|
||||
AP_info.ssid, AP_info.primary, AP_info.rssi, AP_info.authmode);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID : %s, password : %s",
|
||||
ESP_WIFI_SSID, ESP_WIFI_PASS);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
|
||||
// The event will not be processed after unregister
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id));
|
||||
|
||||
vEventGroupDelete(s_wifi_event_group);
|
||||
}
|
||||
#endif
|
||||
|
||||
void app_wifi_init ()
|
||||
void app_wifi_init(void)
|
||||
{
|
||||
//Initialize NVS
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
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);
|
||||
|
||||
#if EXAMPLE_ESP_WIFI_MODE_AP
|
||||
ESP_LOGI(TAG, "ESP_WIFI_MODE_AP");
|
||||
wifi_init_softap();
|
||||
#else
|
||||
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||
wifi_init_sta();
|
||||
#endif /*EXAMPLE_ESP_WIFI_MODE_AP*/
|
||||
/* Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values,
|
||||
* this can guarantee all the fields got correct value when more fields are added
|
||||
* into wifi_init_config_t in future release. */
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
/* esp_wifi_init API must be called before all other WiFi API can be called */
|
||||
ESP_LOGI(TAG, "Initializing ESP Wifi");
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
wifi_mode_t mode;
|
||||
mode = WIFI_MODE_NULL;
|
||||
|
||||
if (strlen(ESP_WIFI_AP_SSID) && strlen(ESP_WIFI_SSID)) {
|
||||
mode = WIFI_MODE_APSTA;
|
||||
ESP_LOGI(TAG, "Wifi mode is set to WIFI_MODE_APSTA");
|
||||
wifi_init_softap(mode);
|
||||
wifi_init_sta(mode);
|
||||
} else if (strlen(ESP_WIFI_AP_SSID)) {
|
||||
mode = WIFI_MODE_AP;
|
||||
ESP_LOGI(TAG, "Wifi mode is set to WIFI_MODE_AP");
|
||||
wifi_init_softap(mode);
|
||||
} else if (strlen(ESP_WIFI_SSID)) {
|
||||
mode = WIFI_MODE_STA;
|
||||
ESP_LOGI(TAG, "Wifi mode is set to WIFI_MODE_STA");
|
||||
wifi_init_sta(mode);
|
||||
}
|
||||
|
||||
if (mode == WIFI_MODE_NULL) {
|
||||
ESP_LOGW(TAG,"Neither AP or STA have been configured. WiFi will be off.");
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); // Set current WiFi power save type.
|
||||
}
|
||||
|
||||
|
|
|
@ -52,26 +52,169 @@
|
|||
*/
|
||||
#define CAMERA_FRAME_SIZE FRAMESIZE_QVGA
|
||||
|
||||
#if CONFIG_CAMERA_MODEL_WROVER_KIT
|
||||
#define CAM_BOARD "WROVER-KIT"
|
||||
#define PWDN_GPIO_NUM -1
|
||||
#define RESET_GPIO_NUM -1
|
||||
#define XCLK_GPIO_NUM 21
|
||||
#define SIOD_GPIO_NUM 26
|
||||
#define SIOC_GPIO_NUM 27
|
||||
|
||||
#define Y9_GPIO_NUM 35
|
||||
#define Y8_GPIO_NUM 34
|
||||
#define Y7_GPIO_NUM 39
|
||||
#define Y6_GPIO_NUM 36
|
||||
#define Y5_GPIO_NUM 19
|
||||
#define Y4_GPIO_NUM 18
|
||||
#define Y3_GPIO_NUM 5
|
||||
#define Y2_GPIO_NUM 4
|
||||
#define VSYNC_GPIO_NUM 25
|
||||
#define HREF_GPIO_NUM 23
|
||||
#define PCLK_GPIO_NUM 22
|
||||
|
||||
#elif CONFIG_CAMERA_MODEL_ESP32_CAM_BOARD
|
||||
// The 18 pin header on the board has Y5 and Y3 swapped
|
||||
#define USE_BOARD_HEADER 0
|
||||
|
||||
#define CAM_BOARD "ESP-DEVCAM"
|
||||
#define PWDN_GPIO_NUM 32
|
||||
#define RESET_GPIO_NUM 33
|
||||
#define XCLK_GPIO_NUM 4
|
||||
#define SIOD_GPIO_NUM 18
|
||||
#define SIOD_GPIO_NUM 18
|
||||
#define SIOC_GPIO_NUM 23
|
||||
|
||||
#define Y9_GPIO_NUM 36
|
||||
#define Y8_GPIO_NUM 19
|
||||
#define Y7_GPIO_NUM 21
|
||||
#define Y6_GPIO_NUM 39
|
||||
#if USE_BOARD_HEADER
|
||||
#define Y5_GPIO_NUM 13
|
||||
#else
|
||||
#define Y5_GPIO_NUM 35
|
||||
#endif
|
||||
#define Y4_GPIO_NUM 14
|
||||
#if USE_BOARD_HEADER
|
||||
#define Y3_GPIO_NUM 35
|
||||
#else
|
||||
#define Y3_GPIO_NUM 13
|
||||
#endif
|
||||
#define Y2_GPIO_NUM 34
|
||||
#define VSYNC_GPIO_NUM 5
|
||||
#define HREF_GPIO_NUM 27
|
||||
#define PCLK_GPIO_NUM 25
|
||||
|
||||
#elif CONFIG_CAMERA_MODEL_ESP_EYE
|
||||
#define CAM_BOARD "ESP-EYE"
|
||||
#define PWDN_GPIO_NUM -1
|
||||
#define RESET_GPIO_NUM -1
|
||||
#define XCLK_GPIO_NUM 4
|
||||
#define SIOD_GPIO_NUM 18
|
||||
#define SIOC_GPIO_NUM 23
|
||||
|
||||
#define Y9_GPIO_NUM 36
|
||||
#define Y8_GPIO_NUM 37
|
||||
#define Y7_GPIO_NUM 38
|
||||
#define Y6_GPIO_NUM 39
|
||||
#define Y5_GPIO_NUM 35
|
||||
#define Y4_GPIO_NUM 14
|
||||
#define Y3_GPIO_NUM 13
|
||||
#define Y2_GPIO_NUM 34
|
||||
#define VSYNC_GPIO_NUM 5
|
||||
#define HREF_GPIO_NUM 27
|
||||
#define PCLK_GPIO_NUM 25
|
||||
|
||||
#elif CONFIG_CAMERA_MODEL_M5STACK_PSRAM
|
||||
#define CAM_BOARD "M5CAM"
|
||||
#define PWDN_GPIO_NUM -1
|
||||
#define RESET_GPIO_NUM 15
|
||||
#define XCLK_GPIO_NUM 27
|
||||
#define SIOD_GPIO_NUM 25
|
||||
#define SIOC_GPIO_NUM 23
|
||||
|
||||
#define Y9_GPIO_NUM 36
|
||||
#define Y8_GPIO_NUM 37
|
||||
#define Y7_GPIO_NUM 38
|
||||
#define Y9_GPIO_NUM 19
|
||||
#define Y8_GPIO_NUM 36
|
||||
#define Y7_GPIO_NUM 18
|
||||
#define Y6_GPIO_NUM 39
|
||||
#define Y5_GPIO_NUM 35
|
||||
#define Y4_GPIO_NUM 14
|
||||
#define Y3_GPIO_NUM 13
|
||||
#define Y2_GPIO_NUM 34
|
||||
#define VSYNC_GPIO_NUM 5
|
||||
#define HREF_GPIO_NUM 27
|
||||
#define PCLK_GPIO_NUM 25
|
||||
#define Y5_GPIO_NUM 5
|
||||
#define Y4_GPIO_NUM 34
|
||||
#define Y3_GPIO_NUM 35
|
||||
#define Y2_GPIO_NUM 32
|
||||
#define VSYNC_GPIO_NUM 22
|
||||
#define HREF_GPIO_NUM 26
|
||||
#define PCLK_GPIO_NUM 21
|
||||
|
||||
#elif CONFIG_CAMERA_MODEL_M5STACK_WIDE
|
||||
#define CAM_BOARD "M5CAMW"
|
||||
#define PWDN_GPIO_NUM -1
|
||||
#define RESET_GPIO_NUM 15
|
||||
#define XCLK_GPIO_NUM 27
|
||||
#define SIOD_GPIO_NUM 22
|
||||
#define SIOC_GPIO_NUM 23
|
||||
|
||||
#define Y9_GPIO_NUM 19
|
||||
#define Y8_GPIO_NUM 36
|
||||
#define Y7_GPIO_NUM 18
|
||||
#define Y6_GPIO_NUM 39
|
||||
#define Y5_GPIO_NUM 5
|
||||
#define Y4_GPIO_NUM 34
|
||||
#define Y3_GPIO_NUM 35
|
||||
#define Y2_GPIO_NUM 32
|
||||
#define VSYNC_GPIO_NUM 25
|
||||
#define HREF_GPIO_NUM 26
|
||||
#define PCLK_GPIO_NUM 21
|
||||
|
||||
#elif CONFIG_CAMERA_MODEL_AI_THINKER
|
||||
#define CAM_BOARD "AI-THINKER"
|
||||
#define PWDN_GPIO_NUM 32
|
||||
#define RESET_GPIO_NUM -1
|
||||
#define XCLK_GPIO_NUM 0
|
||||
#define SIOD_GPIO_NUM 26
|
||||
#define SIOC_GPIO_NUM 27
|
||||
|
||||
#define Y9_GPIO_NUM 35
|
||||
#define Y8_GPIO_NUM 34
|
||||
#define Y7_GPIO_NUM 39
|
||||
#define Y6_GPIO_NUM 36
|
||||
#define Y5_GPIO_NUM 21
|
||||
#define Y4_GPIO_NUM 19
|
||||
#define Y3_GPIO_NUM 18
|
||||
#define Y2_GPIO_NUM 5
|
||||
#define VSYNC_GPIO_NUM 25
|
||||
#define HREF_GPIO_NUM 23
|
||||
#define PCLK_GPIO_NUM 22
|
||||
|
||||
|
||||
#elif CONFIG_CAMERA_MODEL_CUSTOM
|
||||
#define CAM_BOARD "CUSTOM"
|
||||
#define PWDN_GPIO_NUM CONFIG_CAMERA_PIN_PWDN
|
||||
#define RESET_GPIO_NUM CONFIG_CAMERA_PIN_RESET
|
||||
#define XCLK_GPIO_NUM CONFIG_CAMERA_PIN_XCLK
|
||||
#define SIOD_GPIO_NUM CONFIG_CAMERA_PIN_SIOD
|
||||
#define SIOC_GPIO_NUM CONFIG_CAMERA_PIN_SIOC
|
||||
|
||||
#define Y9_GPIO_NUM CONFIG_CAMERA_PIN_Y9
|
||||
#define Y8_GPIO_NUM CONFIG_CAMERA_PIN_Y8
|
||||
#define Y7_GPIO_NUM CONFIG_CAMERA_PIN_Y7
|
||||
#define Y6_GPIO_NUM CONFIG_CAMERA_PIN_Y6
|
||||
#define Y5_GPIO_NUM CONFIG_CAMERA_PIN_Y5
|
||||
#define Y4_GPIO_NUM CONFIG_CAMERA_PIN_Y4
|
||||
#define Y3_GPIO_NUM CONFIG_CAMERA_PIN_Y3
|
||||
#define Y2_GPIO_NUM CONFIG_CAMERA_PIN_Y2
|
||||
#define VSYNC_GPIO_NUM CONFIG_CAMERA_PIN_VSYNC
|
||||
#define HREF_GPIO_NUM CONFIG_CAMERA_PIN_HREF
|
||||
#define PCLK_GPIO_NUM CONFIG_CAMERA_PIN_PCLK
|
||||
#endif
|
||||
|
||||
#define XCLK_FREQ 20000000
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void app_camera_init();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
#ifndef _APP_WIFI_H_
|
||||
#define _APP_WIFI_H_
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
extern EventGroupHandle_t g_wifi_event_group;
|
||||
|
||||
void app_wifi_init();
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void app_wifi_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue