// ESP send raw frames // src https://stackoverflow.com/questions/46224416/esp8266-send-beacon-frame-with-deep-sleep-mode-does-not-work-properly #include extern "C" { #include "user_interface.h" } void setup() { delay(500); // sendBeacon("ESP8266"); // ESP.deepSleep(10e5); } void loop() { sendBeacon("ESP8266"); } void sendBeacon(char* ssid) { // Randomize channel // byte channel = 1; wifi_set_channel(channel); uint8_t packet[128] = { 0x80, 0x00, //Frame Control 0x00, 0x00, //Duration /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address /*22*/ 0xc0, 0x6c, //Seq-ctl //Frame body starts here /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active /*32*/ 0xFF, 0x00, //Beacon interval /*34*/ 0x01, 0x04, //Capability info /* SSID */ /*36*/ 0x00 }; int ssidLen = strlen(ssid); packet[37] = ssidLen; for(int i = 0; i < ssidLen; i++) { packet[38+i] = ssid[i]; } uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ }; for(int i = 0; i < 12; i++) { packet[38 + ssidLen + i] = postSSID[i]; } packet[50 + ssidLen] = channel; // get SRC MAC unsigned char mac[6]; WiFi.macAddress(mac); packet[10] = packet[16] = mac[0]; packet[11] = packet[17] = mac[1]; packet[12] = packet[18] = mac[2]; packet[13] = packet[19] = mac[3]; packet[14] = packet[20] = mac[4]; packet[15] = packet[21] = mac[5]; int packetSize = 51 + ssidLen; wifi_send_pkt_freedom(packet, packetSize, 0); delay(1); }