配网时出现一些数据,这些数据影响了其他任务

Moderator: ESP_Bob

fst202130609
Posts: 171
Joined: Thu Sep 23, 2021 10:03 am

配网时出现一些数据,这些数据影响了其他任务

Postby fst202130609 » Tue Nov 30, 2021 4:06 am

看不懂这些数据,想找到这些数据在哪里打印,找不到,是不是封装了???

I (11227) wifi:new:<4,0>, old:<1,0>, ap:<255,255>, sta:<4,0>, prof:1
I (11807) wifi:state: init -> auth (b0)
I (11867) wifi:state: auth -> assoc (0)
I (11877) wifi:state: assoc -> run (10)
W (11947) wifi:<ba-add>idx:0 (ifx:0, 04:d4:c4:3b:7e:70), tid:0, ssn:0, winSize:64
I (12017) wifi:connected with xxxxxxxxx, aid = 12, channel 4, BW20, bssid = 255.。。。。。。。。。
I (12017) wifi:security: WPA2-PSK, phy: bgn, rssi: -41
I (12027) wifi:pm start, type: 1

I (12027) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000
I (12037) wifi:BcnInt:102400, DTIM:3

ESP_ICY
Posts: 404
Joined: Mon Aug 23, 2021 11:10 am

Re: 配网时出现一些数据,这些数据影响了其他任务

Postby ESP_ICY » Fri Dec 03, 2021 3:56 am

你这边具体是想看什么数据

fst202130609
Posts: 171
Joined: Thu Sep 23, 2021 10:03 am

Re: 配网时出现一些数据,这些数据影响了其他任务

Postby fst202130609 » Fri Dec 03, 2021 6:16 am

官方的WiFi/smart_config例程有bug,我在这个例程添加了定时器和灯,在esptouch开始配网时让灯以100ms闪烁,在这个过程中,大概660ms灯没闪烁,不懂是怎么哪里出问题。
/* Esptouch example

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 <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_wpa2.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_smartconfig.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "driver/timer.h"
#include "esp_timer.h"
/* FreeRTOS event group to signal when we are connected & ready to make a request */
static EventGroupHandle_t s_wifi_event_group;

/* The event group allows multiple bits for each event,
but we only care about one event - are we connected
to the AP with an IP? */
static const int CONNECTED_BIT = BIT0;
static const int ESPTOUCH_DONE_BIT = BIT1;
static const char *TAG = "smartconfig_example";

static void smartconfig_example_task(void * parm);
typedef enum
{
Led_off = 0,
Config_led,
Connect_led,
mqtt_connet
}smartLedMode_t;
smartLedMode_t led_mode =Led_off;
#define led 19
#define ledon gpio_set_level(led, 0)
#define ledoff gpio_set_level(led, 1)
void led_Init(void);
void test_timer_periodic_cb(void *arg);
void led_Init(void)
{
gpio_reset_pin(led);
gpio_set_direction(led, GPIO_MODE_OUTPUT);
ledoff;
}
esp_timer_handle_t test_p_handle = 0;
esp_timer_handle_t motor_tim = 0;
//定义一个周期重复运行的定时器结构体
esp_timer_create_args_t test_periodic_arg = {
.callback =
&test_timer_periodic_cb, //设置回调函数
.arg = NULL, //不携带参数
.name = "TestPeriodicTimer" //定时器名字

};
uint8_t ledcnt =0;
uint8_t ledtrun =0;
void test_timer_periodic_cb(void *arg)
{
ledcnt++;

if((led_mode ==Config_led)&&(ledcnt >1)) //0不成功
{
ledtrun =!ledtrun;
ledcnt = 0;
gpio_set_level(led, ledtrun);
}
}
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();
led_mode =Led_off;
ledoff;
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)
{
led_mode =Config_led;
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) {
led_mode =Connect_led;
ESP_LOGI(TAG, "smartconfig over");
esp_smartconfig_stop();
vTaskDelete(NULL);
}
}
}

void app_main(void)
{
led_Init();
esp_err_t time_err = esp_timer_create(&test_periodic_arg, &test_p_handle);
time_err = esp_timer_start_periodic(test_p_handle, 50* 1000);
ESP_ERROR_CHECK( nvs_flash_init() );
initialise_wifi();

}

Who is online

Users browsing this forum: No registered users and 9 guests