|
#include "endianness.h" |
|
#include "esp_wifi.h" |
|
#include <stdio.h> |
|
#include <inttypes.h> |
|
#include <string.h> |
|
|
|
//IEEE 802.11 header with type "data" and subtype "null data" |
|
//https://en.wikipedia.org/wiki/802.11_frame_types |
|
uint8_t ieee80211header[] = { |
|
//IEEE802.11 header |
|
0x48, 0x00, 0x00, 0x00, |
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,//addr1 |
|
0x13, 0x22, 0x33, 0x44, 0x55, 0x66,//addr2 |
|
0x13, 0x22, 0x33, 0x44, 0x55, 0x66,//addr3 |
|
0x00, 0x00,//duration or seq number, idk |
|
//END IEEE802.11 header |
|
}; |
|
|
|
uint8_t data_you_want_to_send[] = { |
|
0x12, 0x32, 0x33, 0x53 |
|
}; |
|
|
|
//I am not sure what is necesary for witi to init succesfuly |
|
void init_wifi() { |
|
esp_err_t ret = nvs_flash_init(); |
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { |
|
ESP_ERROR_CHECK(nvs_flash_erase()); |
|
ret = nvs_flash_init(); |
|
} |
|
ESP_ERROR_CHECK(ret); |
|
|
|
ESP_ERROR_CHECK(esp_netif_init()); |
|
ESP_ERROR_CHECK(esp_event_loop_create_default()); |
|
esp_netif_create_default_wifi_ap(); |
|
|
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); |
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); |
|
|
|
const wifi_country_t wifi_country = { |
|
.cc = "CN", |
|
.schan = 1, |
|
.nchan = 13, |
|
.policy = WIFI_COUNTRY_POLICY_AUTO |
|
}; |
|
ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country)); //set country for channel range [1, 13] |
|
|
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); |
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); |
|
ESP_ERROR_CHECK(esp_wifi_start()); |
|
|
|
ESP_ERROR_CHECK(esp_wifi_set_channel(11, 0)); |
|
} |
|
|
|
void send_packet() { |
|
//declare esp_wifi_80211_tx_mod, it can be in header file |
|
extern int esp_wifi_80211_tx_mod(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq); |
|
|
|
char buf[sizeof(ieee80211header) + sizeof(data_you_want_to_send)]; |
|
memcpy(buf, &ieee80211header, sizeof(ieee80211header)); |
|
memcpy(buf + sizeof(ieee80211header), &data_you_want_to_send, sizeof(data_you_want_to_send)); |
|
|
|
int err = esp_wifi_80211_tx_mod(WIFI_IF_STA, buf, sizeof(buf), false); |
|
if(err != ESP_OK) { |
|
printf("error while sending packet"); |
|
} |
|
} |
@wojtess Hi! Thanks for this contribution. After minor adjustments, this fix fit properly to my code.
I am searching for a way to make a wireless device (ieee802.11) to transmit a frame, any kind, in order to detect device presence. It's only needed that device transmit a frame with its MAC as source address.
Any clue?