ESP NOW是否可以设置成WIFI_PHY_RATE_LORA_250K速率啊

Moderator: ESP_Bob

wujing
Posts: 5
Joined: Mon Jul 10, 2023 11:08 am

ESP NOW是否可以设置成WIFI_PHY_RATE_LORA_250K速率啊

Postby wujing » Mon Jul 10, 2023 11:18 am

我在esp32-C3的esp now demo里切换了速率,在
esp_wifi_start后添加了
esp_wifi_config_espnow_rate(ESPNOW_WIFI_IF, WIFI_PHY_RATE_LORA_500K),如下

Code: Select all

static void example_wifi_init(void)
{
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
   // esp_wifi_config_80211_tx_rate(ESPNOW_WIFI_MODE,WIFI_PHY_RATE_5M_L);
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(ESPNOW_WIFI_MODE) );
    ESP_ERROR_CHECK( esp_wifi_start());
  //  esp_wifi_config_80211_tx_rate(ESP_IF_WIFI_STA,PreRate);
    esp_wifi_set_bandwidth(ESP_IF_WIFI_STA,WIFI_BW_HT20);
#if 1//CONFIG_ESPNOW_ENABLE_LONG_RANGE
   ESP_ERROR_CHECK( esp_wifi_set_protocol(ESPNOW_WIFI_IF, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR) );
    //ESP_ERROR_CHECK( esp_wifi_set_protocol(ESPNOW_WIFI_IF, WIFI_PROTOCOL_LR) );
#endif

    //ESP_ERROR_CHECK( esp_wifi_internal_set_fix_rate(ESPNOW_WIFI_IF,true, WIFI_PHY_RATE_LORA_500K));
   ESP_ERROR_CHECK( esp_wifi_config_espnow_rate(ESPNOW_WIFI_IF, WIFI_PHY_RATE_LORA_500K));
    
}
WIFI_PHY_RATE_LORA_500K和WIFI_PHY_RATE_LORA_250K速率不行,其他速率可以
发现会返回错误
W (506) wifi:invalid rate, need change phy mode to LR
不知道是哪里出问题了,按说espnow应该支持LR啊

ESP_LiuH
Posts: 42
Joined: Fri Feb 10, 2023 7:20 am

Re: ESP NOW是否可以设置成WIFI_PHY_RATE_LORA_250K速率啊

Postby ESP_LiuH » Thu Jul 13, 2023 2:12 am


zhangyanjiao
Posts: 34
Joined: Mon Aug 28, 2017 3:27 am

Re: ESP NOW是否可以设置成WIFI_PHY_RATE_LORA_250K速率啊

Postby zhangyanjiao » Thu Jul 13, 2023 9:00 am

Hi, thanks for reporting this problem. This is a bug in wifi code, we will fix it ASAP.

I have tested locally, if you call `esp_wifi_config_espnow_rate(ESPNOW_WIFI_IF, WIFI_PHY_RATE_LORA_500K)` after `esp_now_init()`, it can work successfully.

wujing
Posts: 5
Joined: Mon Jul 10, 2023 11:08 am

Re: ESP NOW是否可以设置成WIFI_PHY_RATE_LORA_250K速率啊

Postby wujing » Thu Jul 13, 2023 10:02 am

成功的设置后两个espnow可以收发250K数据了,但是esp now的广播数据无法被我的sniffer程序接收到,其他速率的话是没有问题的,sniffer接收的话是否也有特殊的设置,我的这个接收函数设置是否有什么问题?

Code: Select all

void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type)
{
 
  const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
  const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
  const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
//some analysis and then print the MAC address  

}
void wifi_sniffer_init(void)
{
#if 1
    ESP_ERROR_CHECK(esp_netif_init());

    ESP_ERROR_CHECK(esp_event_loop_create_default());
    esp_netif_create_default_wifi_sta();

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));

    esp_event_handler_instance_t instance_any_id;
    esp_event_handler_instance_t instance_got_ip;
    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                                                        ESP_EVENT_ANY_ID,
                                                        &event_handler,
                                                        NULL,
                                                        &instance_any_id));
    ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
                                                        IP_EVENT_STA_GOT_IP,
                                                        &event_handler,
                                                        NULL,
                                                        &instance_got_ip));

    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_ESP_WIFI_SSID,
            .password = EXAMPLE_ESP_WIFI_PASS,
            /* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (pasword len => 8).
             * If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
             * to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
	     * WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
             */
            .threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
            .sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
        },
    };
#endif
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL) );
    //ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_MODE_NULL, &wifi_config) );
    ESP_ERROR_CHECK(esp_wifi_start() );
    ESP_ERROR_CHECK(esp_wifi_set_protocol(WIFI_MODE_NULL, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR) );
    esp_wifi_set_promiscuous(true);
	esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler);

    wifi_promiscuous_filter_t Afilter,Bfilter;
    Afilter.filter_mask = WIFI_PROMIS_FILTER_MASK_ALL;
    //esp_wifi_set_promiscuous_filter(&Afilter);
    esp_wifi_get_promiscuous_filter(&Afilter);
    esp_wifi_get_promiscuous_ctrl_filter(&Bfilter);
    printf("WIFI Fliter A[%08X]B[%08X]\n",(unsigned int)Afilter.filter_mask,(unsigned int)Bfilter.filter_mask);
    
    //esp_wifi_set_promiscuous_filter(&wifi_filter);
    //esp_wifi_set_promiscuous_rx_cb(wifi_sniffer_cb);
    //ESP_GOTO_ON_ERROR(esp_wifi_set_promiscuous(true), err_start, SNIFFER_TAG, "create work queue failed");
    //esp_wifi_set_channel(sniffer->channel, WIFI_SECOND_CHAN_NONE);
}

zhangyanjiao
Posts: 34
Joined: Mon Aug 28, 2017 3:27 am

Re: ESP NOW是否可以设置成WIFI_PHY_RATE_LORA_250K速率啊

Postby zhangyanjiao » Fri Jul 14, 2023 8:19 am

建议可以设置 sniffer 的 filter 只抓管理包,

Code: Select all

filter = filter | WIFI_PROMIS_FILTER_MASK_MGMT;
esp_wifi_set_promiscuous_filter(&filter); 
esp_wifi_set_promiscuous_rx_cb(wifi_sniffer_packet_handler);
// 先设置 filter 和 rx cb 再启动 sniffer
esp_wifi_set_promiscuous(true);
esp_wifi_set_channel(sniffer->channel, WIFI_SECOND_CHAN_NONE); //也可以在 sniffer 启动之前设置 channel
收包回调函数 wifi_sniffer_packet_handler() 的处理看起来没什么问题,但是如果会做一些复杂的操作,建议在新的 task 里面处理.

Who is online

Users browsing this forum: No registered users and 13 guests