-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEsp8266.cpp
49 lines (40 loc) · 1.09 KB
/
Esp8266.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define BUFFER_SIZE 256
WiFiUDP udp;
char packetBuffer[BUFFER_SIZE];
// Set this to your network's SSID and Password
const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
void packetHandler(uint8_t *buffer, uint16_t len) {
Serial.print("Packet captured: ");
Serial.print(len);
Serial.println(" bytes");
// Extract basic information
for (int i = 0; i < len; i++) {
Serial.print(buffer[i], HEX);
Serial.print(" ");
if ((i + 1) % 16 == 0) {
Serial.println();
}
}
Serial.println("\n");
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA); // Station mode
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nWiFi connected!");
// Set ESP8266 to promiscuous mode
wifi_promiscuous_enable(true);
wifi_set_promiscuous_rx_cb(packetHandler);
}
void loop() {
// Continuously listen to network packets
delay(1000);
}