Run script automatically when wifi/bluetooth detects my phone is nearby

hal_sk

New Member
Joined
May 25, 2020
Messages
19
Reaction score
3
Credits
188
Is there a way to do automatically run arbitrary script when Linux wireless adapter detects lets say specific MAC address of my mobile device in area? And then run other script when device is out of range?
The intended use: Run my shell script that will temporary disable my Raspberry based motion alarm when I come into my garage with my phone in my pocket. So I don't have to disable the alarm using keypad or pushing button on remote controller. And then activating alarm when I leave the area.
 


Why would you want to do that MAC Addresses can be spoofed then anybody can get access
 
There are a lot of variables at play here.
  • First, you could use GPS on the mobile device, but if you're just talking about your garage. You've going to get thousands of false positives or false negatives and your monitor will be unstable in it's use. GPS is great and can detect ranges to very close proximities, but the general public use of GPS isn't quite as good as the governments.
  • You can use arp tables to detect if a device is around, but even then. Once you see the MAC, you would need to continuously ping the address until it vanished off the network. That said, it only works if your devices is connected to the same network. (WiFi for the mobile device)
To be clear here, you could be a long way from your garage and still be on a WiFi network thereby disabling your monitor even though you're not in the garage.

Another idea, would be to detect Bluetooth. You would need to program this up in some programming language and ensure you have Bluetooth enabled on your RPi so that it can detect your mobile device's Bluetooth.

Bluetooth would likely be a much better option than using WiFi and MAC due to it's more limited range than WiFi. Though, you could still easily be in your living room or something and still disable your monitoring in the garage.
 
There are a lot of variables at play here.
  • First, you could use GPS on the mobile device, but if you're just talking about your garage. You've going to get thousands of false positives or false negatives and your monitor will be unstable in it's use. GPS is great and can detect ranges to very close proximities, but the general public use of GPS isn't quite as good as the governments.
  • You can use arp tables to detect if a device is around, but even then. Once you see the MAC, you would need to continuously ping the address until it vanished off the network. That said, it only works if your devices is connected to the same network. (WiFi for the mobile device)
To be clear here, you could be a long way from your garage and still be on a WiFi network thereby disabling your monitor even though you're not in the garage.

Another idea, would be to detect Bluetooth. You would need to program this up in some programming language and ensure you have Bluetooth enabled on your RPi so that it can detect your mobile device's Bluetooth.

Bluetooth would likely be a much better option than using WiFi and MAC due to it's more limited range than WiFi. Though, you could still easily be in your living room or something and still disable your monitoring in the garage.
My garage is separate from my home location so that's no problem. The problem is how to make my raspberry to trigger my shell commands when given MAC address is in reach of my raspberry's wifi or bluetooth. I can also setup wifi access point on my raspberry (in fact I have already did) and set it up that my phone will automatically connect to that access point network when it get close enough. But then how I trigger my commands on raspberry? Maybe I can set up static local IP on my phone and set up my raspberry to constantly ping my phone local IP. And IF my phone responds THEN run script. But I am sure there are much cleaner solutions then this (if it is even workable doable). :)
 
I was looking into something vaguely similar and ended up deciding that NFC and RFID was likely the way to go, along with a cryptographically updated OTP for authorization. Basically, you'd swipe your phone along a sensor in the wall (or wherever) and it'd automatically disable the alarm.
 
I was looking into something vaguely similar and ended up deciding that NFC and RFID was likely the way to go, along with a cryptographically updated OTP for authorization. Basically, you'd swipe your phone along a sensor in the wall (or wherever) and it'd automatically disable the alarm.
That's an action required from me every time I enter and leave garage. And because I am lazy I am trying to avoid it :cool:

MAC Addresses can be spoofed
And also I just learned that phones are from privacy reasons automatically changing (spoofing?) their MAC address so it would not work.

The solution might be creating wifi access point from that raspberry and make my phone to automatically connect to that AP wifi network. Then every time I come there my phone connects to raspberry AP. And raspberry might ping every 5 seconds devices in the network and if there is new device it triggers my script. Assuming I will be only one with password to that AP wifi network. Is that viable?
But then I would like to prevent my raspberry AP to share it's internet connection because I have very limited data plan on my raspberry just for iOT signaling stuff.
 
That's an action required from me every time I enter and leave garage.

It would, indeed. I couldn't come up with anything else that was even remotely secure. In my case, the goal was to open and control a gate at the end of the driveway. I got busy and never followed through with it. I'll probably end up buying something COTS.
 

Members online


Top