#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" #include "sdkconfig.h" #include #include "radio.h" #include "buscfg.h" #include "driver/spi_master.h" #include "esp_event.h" #include "esp_system.h" #include "esp_event.h" #include "esp_timer.h" #include "esp_wifi.h" #include "esp_log.h" #include "esp_mac.h" #include "nvs_flash.h" #include "string.h" #include "mbedtls/base64.h" #include "driver/uart.h" #define TAG "canZem" void wifi_sniffer_packet_handler(void *buf, wifi_promiscuous_pkt_type_t type) { if (type != WIFI_PKT_MGMT && type != WIFI_PKT_DATA) return; const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buf; const uint8_t *payload = ppkt->payload; uint32_t len = ppkt->rx_ctrl.sig_len + 44; const int8_t rssi = ppkt->rx_ctrl.rssi; // Simple PlecyC header check if (len > 24 + 11 && payload[29] == 'P' && payload[30] == 'l' && payload[31] == 'e' && payload[32] == 'c' && payload[33] == 'y' && payload[34] == 'C') { unsigned char outBuf[3136]; size_t output_len = 0; // will store the real output size mbedtls_base64_encode(outBuf, sizeof(outBuf), &output_len, buf, len); printf("\n the frame is %ld bytes long\n", len); printf("\nGot 2400mhZ frame on %d: %s\n", rssi, outBuf); // // Parse further as needed // ESP_LOGI(TAG, "HEXko\n"); // ESP_LOG_BUFFER_HEXDUMP(TAG, buf, len, ESP_LOG_INFO); } } void start_sniffer() { nvs_flash_init(); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); cfg.static_rx_buf_num = 32; cfg.dynamic_rx_buf_num = 32; cfg.ampdu_tx_enable = 1; ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); // Set mode to NULL (or STA) ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); ESP_ERROR_CHECK(esp_wifi_start()); // Set channel 10 explicitly ESP_ERROR_CHECK(esp_wifi_set_channel(10, WIFI_SECOND_CHAN_NONE)); // Enable promiscuous mode and set callback ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // Optional: Disable power saving ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); } void app_main(void) { uart_set_baudrate(UART_NUM_0, 921600); ESP_LOGI("BOOT", "BRN Systems incorporated CanSat flight firmware build: %s %s", __DATE__, __TIME__); start_sniffer(); spi_bus_config_t HighSpeedBusCfg = { // CONNECTED to LoRa and SD card .mosi_io_num = HSPI_MOSI_GPIO, .miso_io_num = HSPI_MISO_GPIO, .sclk_io_num = HSPI_SCK_GPIO, .quadwp_io_num = -1, .quadhd_io_num = -1, .max_transfer_sz = 64, // probably change }; ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &HighSpeedBusCfg, SPI_DMA_CH_AUTO)); xTaskCreate( lora_comms_task, "LoraCommsTask", 8192, NULL, (tskIDLE_PRIORITY + 2), NULL); while (1) { vTaskDelay(100 / portTICK_PERIOD_MS); } }