Using your iPhone's location to start ZM recording

From ZoneMinder Wiki
Jump to navigationJump to search

<Home

Why do we need it?

Your life doesn't always follow a schedule, does it? So how can you expect your camera to follow the same schedule every day? In this day of Connected Devices, most of us carry our phones with us all the time. So wouldn't it be cool if despite whatever you have in cron, there is a way to check if your smart phone is at home or away and depending on its location, you enable/disable recording?

Gotchas

Ah. super useful. But what's the big deal?

  • How about I just allocate a permanent lan IP to my phone and ping it every 5 minutes?
    • Great idea. Except it doesn't work with phones. When phones go to sleep mode, they don't respond to ICMP. (Apparently Blackberries do respond - how cute)
  • Hmm, how about I arping or arpscan?
    • Now you are getting closer. Unfortunately, that doesn't work for iPhones - at least for 5. It gives random results - and I can't seem to use it reliably
    • If your phone does respond reliably to arping or arpscan, check out Christo's shell script here: http://www.zoneminder.com/forums/viewtopic.php?f=9&t=23026

Solution for iPhone

The only way I found out to reliably know if your iPhone is in or out of your home is to use the iCloud find my iPhone service and get your phone's location. But how do you get to iCloud? Apple does not expose its APIs to non iOS environments (so far). Well, enter pyicloud: https://github.com/picklepete/pyicloud

This is a 3rd party library that provides you iCloud access. Obviously, it can break in future if Apple decided to change its URL formats. But works great for now.

Strategy

  • I check the location of my phone every hour using a script (that uses pyicloud). The reason for this is pyicloud logs into iCloud using its web interface and I don't want Apple taking any security measures on my account if it detects too many logins. You can try other intervals
  • That script writes the word 'in' or 'out' to a text file
  • I check the status of that script as a cron job and switch ZM state forcibly if I find it conflicting with ZM's current run state (I tie this hack into my other hack where I modified ZM to remember run state names - you don't have to)

Implementation

Here are the files: