Merge branch 'master' into feature/esp32s2beta_update

This commit is contained in:
Angus Gratton
2019-08-08 13:44:24 +10:00
committed by Angus Gratton
2414 changed files with 160787 additions and 45783 deletions

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "espnow_example_main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "espnow_example_main.c"
INCLUDE_DIRS ".")

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "softap_example_main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "softap_example_main.c"
INCLUDE_DIRS ".")

View File

@@ -18,7 +18,7 @@
#include "lwip/err.h"
#include "lwip/sys.h"
/* The examples use WiFi configuration that you can set via 'make menuconfig'.
/* The examples use WiFi configuration that you can set via project configuration menu.
If you'd rather not, just change the below entries to strings with
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "station_example_main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "station_example_main.c"
INCLUDE_DIRS ".")

View File

@@ -19,7 +19,7 @@
#include "lwip/err.h"
#include "lwip/sys.h"
/* The examples use WiFi configuration that you can set via 'make menuconfig'.
/* The examples use WiFi configuration that you can set via project configuration menu
If you'd rather not, just change the below entries to strings with
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"

View File

@@ -1,7 +1,3 @@
set(COMPONENT_ADD_INCLUDEDIRS .)
set(COMPONENT_SRCS "iperf.c")
set(COMPONENT_REQUIRES lwip)
register_component()
idf_component_register(SRCS "iperf.c"
INCLUDE_DIRS .
REQUIRES lwip)

View File

@@ -56,24 +56,13 @@ inline static bool iperf_is_tcp_server(void)
static int iperf_get_socket_error_code(int sockfd)
{
uint32_t optlen = sizeof(int);
int result;
int err;
/* get the error state, and clear it */
err = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &result, &optlen);
if (err == -1) {
ESP_LOGE(TAG, "getsockopt failed: ret=%d", err);
return -1;
}
return result;
return errno;
}
static int iperf_show_socket_error_reason(const char *str, int sockfd)
{
int err = iperf_get_socket_error_code(sockfd);
int err = errno;
if (err != 0) {
ESP_LOGW(TAG, "%s error, error code: %d, reason: %s", str, err, strerror(err));
}

View File

@@ -1,5 +1,3 @@
set(COMPONENT_SRCS "cmd_wifi.c"
"iperf_example_main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "cmd_wifi.c"
"iperf_example_main.c"
INCLUDE_DIRS ".")

View File

@@ -53,7 +53,7 @@ static EventGroupHandle_t wifi_event_group;
const int CONNECTED_BIT = BIT0;
const int DISCONNECTED_BIT = BIT1;
static void scan_done_handler(void* arg, esp_event_base_t event_base,
static void scan_done_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
uint16_t sta_number = 0;
@@ -76,14 +76,14 @@ static void scan_done_handler(void* arg, esp_event_base_t event_base,
ESP_LOGI(TAG, "sta scan done");
}
static void got_ip_handler(void* arg, esp_event_base_t event_base,
static void got_ip_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
xEventGroupClearBits(wifi_event_group, DISCONNECTED_BIT);
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
}
static void disconnect_handler(void* arg, esp_event_base_t event_base,
static void disconnect_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
if (reconnect) {
@@ -128,7 +128,7 @@ static bool wifi_cmd_sta_join(const char* ssid, const char* pass)
strlcpy((char*) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
if (pass) {
strncpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
strlcpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
}
if (bits & CONNECTED_BIT) {
@@ -205,14 +205,14 @@ static bool wifi_cmd_ap_set(const char* ssid, const char* pass)
};
reconnect = false;
strncpy((char*) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
strlcpy((char*) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
if (pass) {
if (strlen(pass) != 0 && strlen(pass) < 8) {
reconnect = true;
ESP_LOGE(TAG, "password less than 8");
return false;
}
strncpy((char*) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
strlcpy((char*) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
}
if (strlen(pass) == 0) {

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "power_save.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "power_save.c"
INCLUDE_DIRS ".")

View File

@@ -1,11 +1,11 @@
# Wifi SCAN Example
This example shows how to use scan of ESP32.
This example shows how to use the scan functionality of the Wi-Fi driver of ESP32.
We have two way to scan, fast scan and all channel scan:
Two scan methods are supported: fast scan and all channel scan.
* fast scan: in this mode, scan will finish after find match AP even didn't scan all the channel, you can set thresholds for signal and authmode, it will ignore the AP which below the thresholds.
* fast scan: in this mode, scan finishes right after a matching AP is detected, even if channels are not completely scanned. You can set thresholds for signal strength, as well as select desired authentication modes provided by the AP's. The Wi-Fi driver will ignore AP's that fail to meet mentioned criteria.
* all channel scan : scan will end after checked all the channel, it will store four of the whole matched AP, you can set the sort method base on rssi or authmode, after scan, it will choose the best one
* all channel scan: scan will end only after all channels are scanned; the Wi-Fi driver will store 4 of the fully matching AP's. Sort methods for AP's include rssi and authmode. After the scan, the Wi-Fi driver selects the AP that fits best based on the sort.
and try to connect. Because it need malloc dynamic memory to store match AP, and most of cases is to connect to better signal AP, so it needn't record all the AP matched. The number of matches is limited to 4 in order to limit dynamic memory usage. Four matches allows APs with the same SSID name and all possible auth modes - Open, WEP, WPA and WPA2.
After the scan, the Wi-Fi driver will try to connect. Because it needs to to allocate precious dynamic memory to store matching AP's, and, most of the cases, connect to the AP with the strongest reception, it does not need to record all the AP's matched. The number of matches stored is limited to 4 in order to limit dynamic memory usage. Among the 4 matches, AP's are allowed to carry the same SSID name and all possible authentication modes - Open, WEP, WPA and WPA2.

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "scan.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "scan.c"
INCLUDE_DIRS ".")

View File

@@ -28,7 +28,7 @@
#include "esp_event.h"
#include "nvs_flash.h"
/*Set the SSID and Password via "make menuconfig"*/
/* Set the SSID and Password via project configuration, or can set directly here */
#define DEFAULT_SSID CONFIG_EXAMPLE_WIFI_SSID
#define DEFAULT_PWD CONFIG_EXAMPLE_WIFI_PASSWORD

View File

@@ -19,7 +19,7 @@ If you want to send packets to host, make sure to connect ESP32 to some kind of
### Configure the project
Enter `make menuconfig` if you are using GNU Make based build system or enter `idf.py menuconfig` if you are using CMake based build system. Then go into `Example Configuration` menu.
Open the project configuration menu (`idf.py menuconfig`). Then go into `Example Configuration` menu.
- Check `Store command history in flash` if you want to save command history into flash (recommend).
- Select where to save the pcap file in `Select destination to store pcap file` menu item.
@@ -33,7 +33,11 @@ Enter `make menuconfig` if you are using GNU Make based build system or enter `i
### Build and Flash
Enter `make -j4 flash monitor` if you are using GNU Make based build system or enter `idf.py build flash monitor` if you' are using CMake based build system.
```
idf.py -p PORT flash monitor
```
(Replace PORT with name of the serial port.)
(To exit the serial monitor, type ``Ctrl-]``.)
@@ -114,7 +118,7 @@ I (248800) example: Card unmounted
### Steps for sending packets to host via JTAG interface
1. Select `JTAG (App Trace)` as the destination of pcap files.
2. Build & Flash with `idf.py build flash` or `make flash`.
2. Build & Flash with `idf.py -p PORT flash`
3. Connect JTAG, run OpenOCD (for more information about how-to please refer to [JTAG Debugging](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html)).
4. Telnet to localhost with 4444 port: `telnet localhost 4444`.
5. In the telnet session, run command like `esp32 apptrace start file://sniffer-esp32.pcap 1 -1 20` (more information about this command, please refer to [apptrace command](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/app_trace.html#openocd-application-level-tracing-commands)).

View File

@@ -1,5 +1,2 @@
set(COMPONENT_ADD_INCLUDEDIRS .)
set(COMPONENT_SRCS "pcap.c")
register_component()
idf_component_register(SRCS "pcap.c"
INCLUDE_DIRS .)

View File

@@ -1,10 +1,3 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
set(COMPONENT_SRCS "simple_sniffer_example_main.c"
"cmd_sniffer.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "simple_sniffer_example_main.c"
"cmd_sniffer.c"
INCLUDE_DIRS ".")

View File

@@ -1,5 +1,5 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, 0x10000, 1M,

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "smartconfig_main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "smartconfig_main.c"
INCLUDE_DIRS ".")

View File

@@ -29,7 +29,7 @@ static EventGroupHandle_t s_wifi_event_group;
to the AP with an IP? */
static const int CONNECTED_BIT = BIT0;
static const int ESPTOUCH_DONE_BIT = BIT1;
static const char *TAG = "sc";
static const char *TAG = "smartconfig_example";
static void smartconfig_example_task(void * parm);
@@ -43,6 +43,36 @@ static void event_handler(void* arg, esp_event_base_t event_base,
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
} else if (event_base == SC_EVENT && event_id == SC_EVENT_SCAN_DONE) {
ESP_LOGI(TAG, "Scan done");
} else if (event_base == SC_EVENT && event_id == SC_EVENT_FOUND_CHANNEL) {
ESP_LOGI(TAG, "Found channel");
} else if (event_base == SC_EVENT && event_id == SC_EVENT_GOT_SSID_PSWD) {
ESP_LOGI(TAG, "Got SSID and password");
smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)event_data;
wifi_config_t wifi_config;
uint8_t ssid[33] = { 0 };
uint8_t password[65] = { 0 };
bzero(&wifi_config, sizeof(wifi_config_t));
memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, evt->password, sizeof(wifi_config.sta.password));
wifi_config.sta.bssid_set = evt->bssid_set;
if (wifi_config.sta.bssid_set == true) {
memcpy(wifi_config.sta.bssid, evt->bssid, sizeof(wifi_config.sta.bssid));
}
memcpy(ssid, evt->ssid, sizeof(evt->ssid));
memcpy(password, evt->password, sizeof(evt->password));
ESP_LOGI(TAG, "SSID:%s", ssid);
ESP_LOGI(TAG, "PASSWORD:%s", password);
ESP_ERROR_CHECK( esp_wifi_disconnect() );
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_connect() );
} else if (event_base == SC_EVENT && event_id == SC_EVENT_SEND_ACK_DONE) {
xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
}
}
@@ -57,51 +87,18 @@ static void initialise_wifi(void)
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL) );
ESP_ERROR_CHECK( esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_start() );
}
static void sc_callback(smartconfig_status_t status, void *pdata)
{
switch (status) {
case SC_STATUS_WAIT:
ESP_LOGI(TAG, "SC_STATUS_WAIT");
break;
case SC_STATUS_FIND_CHANNEL:
ESP_LOGI(TAG, "SC_STATUS_FINDING_CHANNEL");
break;
case SC_STATUS_GETTING_SSID_PSWD:
ESP_LOGI(TAG, "SC_STATUS_GETTING_SSID_PSWD");
break;
case SC_STATUS_LINK:
ESP_LOGI(TAG, "SC_STATUS_LINK");
wifi_config_t *wifi_config = pdata;
ESP_LOGI(TAG, "SSID:%s", wifi_config->sta.ssid);
ESP_LOGI(TAG, "PASSWORD:%s", wifi_config->sta.password);
ESP_ERROR_CHECK( esp_wifi_disconnect() );
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, wifi_config) );
ESP_ERROR_CHECK( esp_wifi_connect() );
break;
case SC_STATUS_LINK_OVER:
ESP_LOGI(TAG, "SC_STATUS_LINK_OVER");
if (pdata != NULL) {
uint8_t phone_ip[4] = { 0 };
memcpy(phone_ip, (uint8_t* )pdata, 4);
ESP_LOGI(TAG, "Phone ip: %d.%d.%d.%d\n", phone_ip[0], phone_ip[1], phone_ip[2], phone_ip[3]);
}
xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
break;
default:
break;
}
}
static void smartconfig_example_task(void * parm)
{
EventBits_t uxBits;
ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
ESP_ERROR_CHECK( esp_smartconfig_start(sc_callback) );
smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_smartconfig_start(&cfg) );
while (1) {
uxBits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
if(uxBits & CONNECTED_BIT) {

View File

@@ -1,8 +1,4 @@
set(COMPONENT_SRCS "wpa2_enterprise_main.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
# Embed CA, certificate & key directly into binary
set(COMPONENT_EMBED_TXTFILES wpa2_ca.pem wpa2_client.crt wpa2_client.key)
register_component()
idf_component_register(SRCS "wpa2_enterprise_main.c"
INCLUDE_DIRS "."
EMBED_TXTFILES wpa2_ca.pem wpa2_client.crt wpa2_client.key)

View File

@@ -30,12 +30,12 @@
#include "tcpip_adapter.h"
/* The examples use simple WiFi configuration that you can set via
'make menuconfig'.
project configuration menu.
If you'd rather not, just change the below entries to strings with
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
You can choose EAP method via 'make menuconfig' according to the
You can choose EAP method via project configuration according to the
configuration of AP.
*/
#define EXAMPLE_WIFI_SSID CONFIG_EXAMPLE_WIFI_SSID
@@ -94,7 +94,6 @@ static void initialise_wifi(void)
unsigned int ca_pem_bytes = ca_pem_end - ca_pem_start;
unsigned int client_crt_bytes = client_crt_end - client_crt_start;
unsigned int client_key_bytes = client_key_end - client_key_start;
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
tcpip_adapter_init();
wifi_event_group = xEventGroupCreate();
@@ -121,7 +120,7 @@ static void initialise_wifi(void)
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EXAMPLE_EAP_PASSWORD, strlen(EXAMPLE_EAP_PASSWORD)) );
}
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_enable(&config) );
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_enable() );
ESP_ERROR_CHECK( esp_wifi_start() );
}

View File

@@ -1,4 +1,2 @@
set(COMPONENT_SRCS "wps.c")
set(COMPONENT_ADD_INCLUDEDIRS ".")
register_component()
idf_component_register(SRCS "wps.c"
INCLUDE_DIRS ".")

View File

@@ -29,7 +29,7 @@
#include "nvs_flash.h"
/*set wps mode via "make menuconfig"*/
/*set wps mode via project configuration */
#if CONFIG_EXAMPLE_WPS_TYPE_PBC
#define WPS_MODE WPS_TYPE_PBC
#elif CONFIG_EXAMPLE_WPS_TYPE_PIN