There are a lot of projects that you could want to have your pi do certain things based on if you are or are not near it. I've found two good ways to sense this assuming you carry your phone with you:
You can use wifi to detect devices within further proximity to the wap, or bluetooth to detect devices within closer proximity to the pi...
Detect when you are in the area using WiFi
This method assumes your pi and your phone use the same wifi, such as at your house, and that your WiFi is always on. Also you will want to set a static IP on your phone, or DHCP lease reservation on your router, so the pi is always trying to find YOUR phone and not a different device that connects to your wifi network later.
This will return that your phone is in range whenever it's pingable from your pi (connected to the same network). Your pi can be on ethernet or wifi, and as long as your phone is connected to your LAN this should work.
Detect when you are in the immediate proximity using Bluetooth
This is a little different because it's based on how close your phone is to your PI, not your wifi network. With the bluetooth module (built in to a pi3), the pi is trying to reach your phone.
You will need two things, the full MAC address of your phone's Bluetooth radio, and your phone's name. Basically your pi sends out a unicast packet to the MAC of your phone, asking for it's name. If it gets a response with the name it's expecting (that you hardcoded in the script), then it considers it in range.
This will return "in range" whenever your pi is within bluetooth radio range, typically 20-30 feet indoors? Note that the device does NOT have to be paired to the pi to respond to it, so there is nothing you need to do on your bluetooth device other than get the name it responds with, and MAC address. If you are having trouble figuring out the name, try print(bluetooth.lookup_nam("MAC")).
Possible Applications
Presence detection can be a very powerful thing to add to projects. Lets say for example, you have a pi that texts you a photo when it sees someone coming in your front door. You can use presence to disable that whenever you are in the area, so you don't get spammed with pictures of yourself. Another possible application is lighting that turns on when you arrive home.
Limitations
I've run into some problems with the bluetooth radio, most notable when you are constantly searching if a device is in range, it will make the wifi unusable. This isn't a problem if you are using ethernet, but with WiFi you might want to have the bluetooth device only search every 5-10 seconds or so.
Remember that generally your pi can't ping a wifi device directly (unless it IS the WAP, but that's not covered here). The packet always gets sent to the wifi access point, and then to your device from there. Though this isn't a bad thing, if you are in a big company that has wifi access points all over the place, your pi might be able to detect you if you are anywhere on the premises.
With bluetooth, the minimum requirement is that the radio is on. With WiFi, the radio has to be on, and your device connected to a network that's connected somehow to the pi.
Good luck with your projects!
No comments:
Post a Comment