Last active
July 17, 2021 22:29
-
-
Save Staubgeborener/28d571ef812303cbf47915b81c158576 to your computer and use it in GitHub Desktop.
Grep and parse the RSSI of received packets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ESP32 Get RSSI of packets- Promiscuous Mode | |
(C) 2017, Staubgeborener | |
https://github.com/Staubgeborener/ */ | |
#include "esp_wifi.h" | |
#include "esp_wifi_internal.h" | |
#include "lwip/err.h" | |
#include "esp_system.h" | |
#include "esp_event.h" | |
#include "esp_event_loop.h" | |
#include "nvs_flash.h" | |
esp_err_t event_handler(void* ctx, system_event_t* event) | |
{ | |
return ESP_OK; | |
} | |
void wifi_promiscuous(void* buffer, wifi_promiscuous_pkt_type_t type) | |
{ | |
//parsing buffer data | |
wifi_promiscuous_pkt_t* p = (wifi_promiscuous_pkt_t*)buffer; | |
//see: https://github.com/espressif/esp-idf/blob/8e4a8e17037c51ce2452e55b5b75bbfaecb25838/components/esp32/include/esp_wifi_types.h#L192 | |
printf("%02d\n", p->rx_ctrl.rssi); | |
} | |
void app_main() | |
{ | |
nvs_flash_init(); | |
tcpip_adapter_init(); | |
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)); | |
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); | |
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); | |
ESP_ERROR_CHECK(esp_wifi_start()); | |
ESP_ERROR_CHECK(esp_wifi_set_country(WIFI_COUNTRY_EU)); //set country EU for channel range [1, 13] | |
esp_wifi_set_channel(6, WIFI_SECOND_CHAN_NONE); //sniff only on channel 6. Increment this value in a loop for sniffing all channels | |
esp_wifi_set_promiscuous_rx_cb(&wifi_promiscuous); | |
esp_wifi_set_promiscuous(true); //as soon this flag is true, the callback will triggered for each packet | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing.
Can you share required libraries?
I am using PlatformIO to compile the code.
However, I can not find the libraries required for header files.
I am looking to get RSSI value at ESP-NOW receiver (made with ESP8266 NodeMcu).
All the espressif forums on this topic leads to your code.
Can you share the code with its dependencies? i.e. a PlatformIO project as GitHub repo.
Your code can help numerous other like me.