我使用vscode开发,idf版本是4.4.1,做的一个小项目上用到了smartconfig,当时使用的还不是C3,封装上写的是ESP-WROOM-32,一切正常,但我换成C3后,烧写同样的代码,smartconfig运行到“scan down”也就是扫描完成开始接收ESPtouch发送的网络连接信息的时候问题就出现了,
手机端使用ESPtouch点确认发送,设备一点反应没有,代码里没找到问题就想着在跑跑例程看看,结果还是同样的问题,设备似乎接收不到UDP广播包,但换回ESP-WROOM-32就正常。 电脑上也试着抓了一下包,可以抓到UDP包。
串口输出大概如下:到scan done就停住了,用esptouch的app怎么点都没反应
Code:
Select all
I (386) wifi:wifi firmware version: 63017e0I (386) wifi:wifi cer
tification version: v7.0I (386) wifi:config NVS flash: enabledI (386) wifi:config nano formating: disabledI (396) wifi:Init data frame dynamic rx buffer num: 32I (396) wifi:Init management frame dynamic rx buffer num: 32I (406) wifi:Init management short buffer num: 32I (406) wifi:Init dynamic tx buffer num: 32I (416) wifi:Init static tx FG buffer num: 2I (416) wifi:Init static rx buffer size: 1600I (416) wifi:Init static rx buffer num: 10I (426) wifi:Init dynamic rx buffer num: 32I (426) wifi_init: rx ba win: 6I (436) wifi_init: tcpip mbox: 32I (436) wifi_init: udp mbox: 6I (436) wifi_init: tcp mbox: 6I (446) wifi_init: tcp tx win: 5744I (446) wifi_init: tcp rx win: 5744I (456) wifi_init: tcp mss: 1440I (456) wifi_init: WiFi IRAM OP enabledI (456) wifi_init: WiFi RX IRAM OP enabledI (466) phy_init: phy_version 909,156dee4,Apr 7 2022,20:27:09I (546) wifi:mode : sta (34:b4:72:f3:c3:94)I (546) wifi:enable tsfI (606) smartconfig: SC version: V3.0.1I (4696) wifi:ic_enable_snifferI (4696) smartconfig: Start to find channel...I (4696) smartconfig_example: Scan done
例程:Code:
Select all
...static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { esp_wifi_connect(); 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 }; uint8_t rvd_data[33] = { 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); if (evt->type == SC_TYPE_ESPTOUCH_V2) { ESP_ERROR_CHECK( esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)) ); ESP_LOGI(TAG, "RVD_DATA:"); for (int i=0; i<33; i++) { printf("%02x ", rvd_data
); } printf("n"); } ESP_ERROR_CHECK( esp_wifi_disconnect() ); ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); esp_wifi_connect(); } else if (event_base == SC_EVENT && event_id == SC_EVENT_SEND_ACK_DONE) { xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT); }}static void initialise_wifi(void){ ESP_ERROR_CHECK(esp_netif_init()); s_wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_create_default()); esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta(); assert(sta_netif); 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, &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 smartconfig_example_task(void * parm){ EventBits_t uxBits; ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) ); 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) { ESP_LOGI(TAG, "WiFi Connected to ap"); } if(uxBits & ESPTOUCH_DONE_BIT) { ESP_LOGI(TAG, "smartconfig over"); esp_smartconfig_stop(); vTaskDelete(NULL); } }}...
Attachments
0