Reacting to other wi-fi devices

Hi All, I am working on a home automation project and have come across the Arduino Yún. I've been tinkering with Arduino devices for a while but not with wi-fi yet.

I was wondering if it were possible for the Arduino Yún to react when my mobile (for example) came within range?

One scenario is turning an internal light on if my device is spotted at a certain time of the day.

It would be mac address based I guess, I don't want to have to associate / authenticate the phone with the Yún, it would associate with my home router.

Is this possible?

Thanks!

edgeman:
Hi All, I am working on a home automation project and have come across the Arduino Yún. I've been tinkering with Arduino devices for a while but not with wi-fi yet.

I was wondering if it were possible for the Arduino Yún to react when my mobile (for example) came within range?

One scenario is turning an internal light on if my device is spotted at a certain time of the day.

It would be mac address based I guess, I don't want to have to associate / authenticate the phone with the Yún, it would associate with my home router.

Is this possible?

Thanks!

@edgeman,
Yes, it is possible - if we ignore that the wifi is power-hungry. FWIW, you could do similar with BLE (bluetooth low energy) - if you had a phone with such capabilities (iPhone, Android Nexus).

All iPhones since iPhone4 (i believe) have supported BLE. Only a handful of Android phone support BLE. (related article)

However, doing it with wifi would be much easier.

  • You'd have to get a list of devices connect to Yun.
  • You'd have to get a list of devices connect to Yun as an AP(Access Point).
  • You'd have to get a list of devices advertising as an AP (your phone would advertise as a hotspot).
  • You then could get the MAC address or the SSID of the device and do what you need.

As it works out your in luck, I just happen to post a related article just a few days ago.

Some WiFi tricks and a scripts
http://forum.arduino.cc/index.php?topic=320773.0

At the top is Get a list of AP (Access Points) as seen by the Arduino Yun

To see who is connect Openwrt suggests(but I could not check as my Yun is not an AP):

How to get a list of connected clients?
http://wiki.openwrt.org/doc/faq/faq.wireless#how.to.get.a.list.of.connected.clients

In addition, OpenWrt has a bunch of script that could be useful

You can also try
Linux Wireless
http://linuxwireless.org/en/users/Documentation/iw/

This another place to look
Google: linux show connected wifi clients

Also, if you need additional software packages. Here is a partial list.
Yún Software Packages
http://codesnippets.altervista.org/documentation/yun/packages/packages.html

Lastly, if you get something working, it would be nice if you posted code or documentation that could help others.

Jesse

edgeman:
Hi All, I am working on a home automation project and have come across the Arduino Yún. I've been tinkering with Arduino devices for a while but not with wi-fi yet.

I was wondering if it were possible for the Arduino Yún to react when my mobile (for example) came within range?

One scenario is turning an internal light on if my device is spotted at a certain time of the day.

It would be mac address based I guess, I don't want to have to associate / authenticate the phone with the Yún, it would associate with my home router.

Is this possible?

Thanks!

Yes, It is possible by put AR9331 on monitor mode, then use wireless analyzer such like tcpdump, wireshark or kismet to get mobile mac address from packet.

edgeman:
It would be mac address based I guess, I don't want to have to associate / authenticate the phone with the Yún, it would associate with my home router.

Let me see if I have this right: You want your Yun to be connected to your home WiFi network. You then want to know when your phone is in range and has associated to the same home WiFi network, and if so, you want the Yun to recognize that and take some action. Is that right?

I agree that you would probably want to look at MAC addresses, as the IP address of the phone could change each time that it comes in range. It would seem that the easiest way would be to get the router involved: by definition, it needs to know which clients are currently associated, and it hands out IP addresses to them. It has to have a list of connected clients, and that list may or may not have MAC addresses associated with it. But it should also have a list of DHCP assignments, and that list should include the MAC addresses. And while that list might have old information in it (the DHCP lease will still be valid for a while after the phone goes out of range) you could use the IP address to cross-reference the list of active WiFi connections to a MAC address using the DHCP client list.

This would all hinge on the Yun having a way to read these lists from the router. If you are running a Linux based router (like OpenWRT, DD-WRT, and others) you can probably write a script on the router that monitors the list and sends out messages whenever the phone comes in or goes out of range - the Yun would just have to receive those messages. Otherwise, the Yun will have to periodically poll the router for the information, perhaps using a series of curl calls to access the router's web management interface? That would involve a fair amount of network calls and data parsing, and is probably easier to do on the Linux side of the Yun rather than in a sketch. The Linux side would then send an available/gone type of message to the sketch (perhaps using Bridge.put()/Bridge.get()) so the sketch could do the appropriate action.

I'm sure it would be possible to implement without getting the router involved, but it will probably be more complicated. You would need to keep scanning the network looking for packets with the phone's MAC address.

jessemonroy650:
@edgeman,
Yes, it is possible - if we ignore that the wifi is power-hungry. FWIW, you could do similar with BLE (bluetooth low energy) - if you had a phone with such capabilities (iPhone, Android Nexus).

Awesome, thanks very much for the detailed response. I wanted to get away from Bluetooth only because I don't usually have it on, I always have Wi-Fi on however, but I might investigate BLE some more.

I'll definitely post my final solution and some code here when done :slight_smile:

Thanks again!

sonnyyu:
Yes, It is possible by put AR9331 on monitor mode, then use wireless analyzer such like tcpdump, wireshark or kismet to get mobile mac address from packet.

Awesome, thanks for the info :slight_smile:

ShapeShifter:
Let me see if I have this right: You want your Yun to be connected to your home WiFi network. You then want to know when your phone is in range and has associated to the same home WiFi network, and if so, you want the Yun to recognize that and take some action. Is that right?

Pretty much, although the Yun could be connected via standard Ethernet. It really only has to log all the Wi-Fi messages, figure out which Mac Address they are coming from, and if it recognises one in the list, do something like switch a relay on or off. I'm thinking Ethernet for connectivity so that I can tell my other Arduino to react as well (Mega with ethernet shield).

Thanks for the info :slight_smile:

edgeman:
Awesome, thanks very much for the detailed response. I wanted to get away from Bluetooth only because I don't usually have it on, I always have Wi-Fi on however, but I might investigate BLE some more.

I'll definitely post my final solution and some code here when done :slight_smile:

Thanks again!

The Bluetooth support at current Yun OS kernel is more less broken. Wait next major release please.

sonnyyu:
The Bluetooth support at current Yun OS kernel is more less broken. Wait next major release please.

@sonnyyu,

I'm getting ready to implement BLE. Can you point me to where it says it is broken? I will workaround, if I can.

TIA
Jesse

jessemonroy650:
@sonnyyu,

I'm getting ready to implement BLE. Can you point me to where it says it is broken? I will workaround, if I can.

TIA
Jesse

BLE Kernel device driver is out of date? I had BLE work fine with old version Yun OS ("3.8.3") . but after upgrade "new" version ("3.3.8") it broken. same time SPI and I2S broken as well.

sonnyyu:
BLE Kernel device driver is out of date? I had BLE work fine with old version Yun OS ("3.8.3") . but after upgrade "new" version ("3.3.8") it broken. same time SPI and I2S broken as well.

Got it. Thank You.

Jesse

Setup WIFI monitor mode:

http://forum.arduino.cc/index.php?topic=319496.msg2231183#msg2231183

Install tcpdump:

opkg update
opkg install tcpdump
wifi down; wifi up
tcpdump -A -e -i  wlan0 | grep -i "18:46:17:ED:XX:XX"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type IEEE802_11_RADIO (802.11 plus radiotap header), capture size 65535 bytes
12:19:37.998091 891153268074348544us tsft 0.0 Mb/s 0 MHz Turbo -98dB signal [bit 29] BSSID:Broadcast DA:Broadcast SA:18:46:17:ed:xx:xx (oui Unknown) Probe Request (DG1670AA2) [1.0 2.0 5.5 11.0 6.0 9.0 12.0 18.0 Mbit][|802.11]
...

"18:46:17:ED:XX:XX" is Android tablet's Mac address, if its WIFI turn then Yun capture the package.