I'd like to use a ESP8266 connected to my in house Wifi, to scan the network for connected devices so that i can determine who is in the house by whether their phone MAC address is seen on the network. Then i can use this to make decision by who is home for other Automation projects.
I've looked around but not really found anything that could help me.
It might be easier to use a Raspberry Pi (i believe by using PING and ARP) running as a server to do this then use that as the control system, but would really like to use the ESP8266
Any ideas how if / how to do this with the ESP8266 ?
Typically, the MAC address is only visible on each end of a "hop" in a packet so if you are going from some device via wifi through the router to some other device, the MAC address you would see would be from your device and the router. The router will typically have a table of IP addresses and associated MAC addresses for those devices that it has handed out an IP address to via DHCP, but I don't think it tracks the MAC addresses of things with fixed IP addresses for example (granted, most portable devices like phones will be getting an address via DHCP). It has been 15+ years since I went through the Cisco class, so things are a bit fuzzy ...
I'm sorry my response has come over 30 days, but getting MAC for both client and Access Point associations and broadcasts was a bit more of an issue than I initially thought.
thanks for original code of Ricardo Oliveira and Skickar
Friend Detector by Ricardo Oliveira, forked by Skickar 9/30/2018
1)https://github.com/RicardoOliveira/FriendDetector
2)https://github.com/skickar/FriendDetector
extra Edited from George konstantinidis in Kavala Hellas 27/6/2019
{
The function of this code is to read nearby Wi-Fi traffic in the form of packets. These packets are compared
to a list of MAC addresses we wish to track, and if the MAC address of a packet matches one on the list, we
print the active stage of devices compared to mac address of list
*/
/*
* On edit by George konstantinidis add serial debuging
* to write status on serial monitor
* On version 0.3 add some delay "DELAY2" for safety
* on connection.
*
* in my area for DELAY2 =13636 time is about 300sec
*/
#include "./esppl_functions.h"
// list of my devices
#define LIST_SIZE 2
// mac adress of devices
uint8_t friendmac[LIST_SIZE][ESPPL_MAC_LEN] = {
{0x42, 0x3e, 0x8e, 0x1a, 0xfd, 0xfa}
,{0x02, 0x06, 0x4d, 0x83, 0x1a, 0x1c}
};
/*
* This is your friend's name list
* put them in the same order as the MAC addresses
*/
String friendname[LIST_SIZE] = {
"neffos x1 max"
,"Shield"
};
bool VisibleDevices[LIST_SIZE] ={false,false}; // find or not in scanning for devices
bool VisibleDevicesOld[LIST_SIZE] ={false,false}; // value to compare with old value
int VisibleDevicesTimer[LIST_SIZE] ={0,0}; // value to find then is pass time with out connection
bool VisibleDevicesTriger[LIST_SIZE] ={false,false}; // value to trigger then have change with VisibleDevices
bool VisibleDevicesConnect[LIST_SIZE]={false,false}; // value to print olny one time then disconecting( after time)!!!
bool VisibleDevicesDisConnect[LIST_SIZE]={false,false}; // value to print olny one time then connecting !!!
int DELAY2=13636; // time to delay
void setup() {
Serial.begin(115200);
esppl_init(cb);
//some blink's
pinMode(2, OUTPUT);
digitalWrite(2,LOW);
delay(200);
digitalWrite(2,HIGH);
delay(200);
digitalWrite(2,LOW);
delay(200);
digitalWrite(2,HIGH);
delay(200);
}
bool maccmp(uint8_t *mac1, uint8_t *mac2) { // compare mac address
for (int i=0; i < ESPPL_MAC_LEN; i++) {
if (mac1[i] != mac2[i]) {
return false;
}
}
return true;
}
void cb(esppl_frame_info *info) //Αναφερεται στο esppl_init(cb); του Setup
{
for (int i=0; i<LIST_SIZE; i++)
{
// compare mac address with list
if (maccmp(info->sourceaddr, friendmac[i]) || maccmp(info->receiveraddr, friendmac[i]))
{
VisibleDevices[i]=true;
VisibleDevicesTimer[i] =DELAY2;
VisibleDevicesConnect[i]=true;
}
else
{ // this is for if the packet does not match any we are tracking
VisibleDevices[i]=false;
}
// trigger then value of VisibleDevices[i] change
if (VisibleDevices[i]!=VisibleDevicesOld[i])
{
VisibleDevicesTriger[i]=true;
}
// messages triger
if ((VisibleDevicesTimer[i]==DELAY2)&&(VisibleDevicesTriger[i]==true)&&(VisibleDevicesDisConnect[i]==false))
{
Serial.printf("\n%s is near! :)", friendname[i].c_str());
VisibleDevicesDisConnect[i]=true;
VisibleDevicesConnect[i]=true;
}
if ((VisibleDevicesTimer[i]==0) && (VisibleDevicesConnect[i]==true))
{
VisibleDevicesConnect[i]=false;
Serial.printf("\n%s is Far far away .. :)", friendname[i].c_str());
VisibleDevicesDisConnect[i]=true;
}
// procces for incoming messages once for 100 times of DELAY2
if (((VisibleDevicesTimer[i]%100)==0)&&(VisibleDevicesConnect[i]==true))
{
Serial.println(friendname[i]+" have no: "+ VisibleDevicesTimer[i]);
}
// Add function
//VisibleDevicesTimer[i] always >=0
if (VisibleDevicesTimer[i]<0)
{
VisibleDevicesTimer[i]=0;
}
VisibleDevicesTimer[i]=VisibleDevicesTimer[i]-1;
} // end for
} // end cb
void loop()
{
esppl_sniffing_start();
while (true)
{
for (int i = ESPPL_CHANNEL_MIN; i <= ESPPL_CHANNEL_MAX; i++ )
{
esppl_set_channel(i);
while (esppl_process_frames()) {}
}
}
}
I love this project, is there a simple way of returning the Serial.println data into a format so I can use to send via OSC? I dont want to mess up functions.h (I already tried!) - Has anyone done this...?