Having gotten my feet wet with occupant detection for the home surveillance system, I recently decided to tackle a similar scenario for another application.
This one was bought to the fore courtesy of two seemingly unrelated occurances. First, was the move to Android from Windows Mobile. My Touch Pro had a handy menu setup whereby I could easily send automated messages to my home network, and have it Do Things(tm) – notably, whether to notify me on my phone of received work emails. So far I’ve found no easy solution to do this in Android, save the laborious method of writing and sending the actual emails which command my home network.
But I was willing to let it slide. Until the second occurence – an apparent increase in the frequency of impromptu meetings at work. With the need to be away from my desk, but still being at work, I would find myself often penning the emails to my home system telling it to direct work emails to my phone.
The obvious question here is – why not send work emails to my phone all the time? And the answer should be equally obvious to the (non-existent) masses who read my blog missives; basically, I prefer to exercise a modicum of control over a series of repeating notifications for things that may not be of interest to me at the time. For personal emails there’s a set of rules that determine what fires a notification and what gets summarized at some point in the future. For work, I don’t see a point in being notified – by my phone – of a new email if I’m sitting at my desk staring at Outlook.
My excursions into the Bluetooth-powered occupant awareness solution at home have yielded favourable results, and ever since then I’ve sought to automate more tasks. Many years ago I had written a Win32 program that interfaced with my personal mail server at home, displaying new emails as one-liners in a window that lived in the system tray icon. The program would determine if I was at my desk based on the screensaver; an active screensaver meant that I was away, and no screensaver meant I was there – much the same way that IM applications determine your away status. I decided that something similar was required for this new project.
What I ended up with was a combination of a Win32 console application and a WinLogon Notification DLL. The Win32 console application can poll for the state of the screensaver, but the DLL receives events every time the screensaver starts/stops, or a logon/logoff occurs, or a the workstation is locked/unlocked. Obviously the DLL has a richer set of conditions available to it than the console app, plus there’s definitely something to be said for event-driven processes vs. polling processes.
But both have their place. In my implementation, the console app sits on a socket waiting for somebody to connect and tell it that my away state has changed. This can be the DLL, or it can be a polling thread which is launched by the console app itself – the thread wakes up every x minutes, checks the screensaver, and also pings the main thread with the current state. The main thread then sends an HTTP request to my home server, which then does all the work required to setup my mail server to notify my phone (or not to notify my phone) when a work email is received.
So long story short – it works. I’m sure there will be some bugs to work out, but I’m just loving the feeling of having busy little tech bees working behind the scenes, Making Things Happen(tm), without any direction on my part. <g>
2 thoughts on “More location awareness”
Comments are closed.
Made some code changes. Went to an event-driven architecture in the backend. This was to rectify some errors that cropped up, but it’s also more efficient. The previous method (sending periodic status updates between the RPC server and mail server) was temporary and meant to support the proof-of-concept anyhow.