It all started at my work, I work as a delivery driver at a company that just introduced deliveries. Our manager receives an order on the computer, makes it then gives it to one of the drivers. The problem here is we are on a contract and we get paid per delivery. Because there more than 1 delivery driver on at a time. the Manager has to give the delivery to who ever has been waiting the longest, IE: Haven't done a delivery in a while. The problem is the manager also helps out around the restaurant and doesn't always realize when a driver returns, or who returned first. Sometimes they don't even realize there has been a driver waiting that they thought were still out.
So, to fix this problem I thought I'd make an Arduino project to monitor when the drivers return and to check who's in the restaurant. Because all the drivers have mobile phones, and because there is free WiFi at my work I decided to sniff their phone packets and identify them by their MAC address.
I ran into many problems on the way. The biggest being the Arduino ESP32 WiFi library was not documented to the extent I needed it to be, EG: It didn't show the function to set the WiFi into promiscuous mode, or how to read raw packets...
I saw YouTuber "Andreas Spiess" demonstrate a project he found that does what I'm after but with the esp8266. And the code was not well documented. I didn't know what any of the functions did. Keep I'm rather noob at complex programming and I still don't rely know what I'm doing. Anyway, I some code from someone else who I've forgotten. Their code monitored the amount of bytes or packets (can't remember) that was being sent and displayed it in a graph on an OLED. Their code was for the esp8266 but they made some alterations to the code to make it compatible with EPS32, I'll find it and link their work...
From their code I was able find more information about the esp32 WIFI libary and was able to receive the whole payload in each packet. So with some minor alteration my code can just simply sniff all 802.11 WiFi packets.
How it works:
This stuff configures the esp32 into promiscuous mode and specifies the function to call when when packets are received, This example will call the function: sniffer() when packets are revived. Beyond that I don't really know what this does.
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
esp_wifi_init(&cfg);
esp_wifi_set_storage(WIFI_STORAGE_RAM);
esp_wifi_set_mode(WIFI_MODE_NULL);
esp_wifi_start();
esp_wifi_set_promiscuous(true);
esp_wifi_set_promiscuous_filter(&filt);
esp_wifi_set_promiscuous_rx_cb(&sniffer);
esp_wifi_set_channel(curChannel, WIFI_SECOND_CHAN_NONE);
The segment below is the start of the sniffer function and shows how the payload of the packet is found.
void sniffer(void* buf, wifi_promiscuous_pkt_type_t type) {
wifi_promiscuous_pkt_t *p = (wifi_promiscuous_pkt_t*)buf;
As with most of the WiFi code, I don't really know what it does. I've gathered it makes some object or construct that contains the information about the packet received and it is set to "p"
The data in the payload is accessed by "p->payload". This is documented in the espressif esp32 wifi libary, along with all the other things that happen. <sorry got tired of elaborating, just ask questions and ill answer them>.
The rest of the code is just data manipulation, creating a basic Time to Live setup on the found MAC addresses and displaying them using the Adaftuit OLED lib.
Hope this is enough information. Feel free to ask questions and I'll answer them soon. TBH ill probably forget about this project in like 3 months so when that time comes the response time will be longer.
Comments