Goodnight Zeo

I love quantifiable data and had been using the Zeo Mobile sleep monitor to track sleep quality.  I had worked on some projects of my own to use this data too.  After I finished the most basic functionality for these projects I lost interest, but planned to come back to them eventually. Unfortunately, my Zeo hardware started having more and more trouble and eventually I stopped using it. I still really enjoyed the concept and thought I would come back eventually.

At some point later I checked back and found they had gone out of business! More frustrating, that meant all the sleep data I had on their systems was gone. I had since removed the app thus removing local data, so the only bit of data I still had was the CSV file I exported during development.  This ended up being about 2 months out of at least 7 that I tracked.  I can at least say that I feel like it helped me improve my sleep. which is the real value.  Fun data is just a bonus.

However this does seal the deal that I will not come back to these projects.  I decided I should release what I have in case it benefits the people out there who still have function Zeo products.  I’m actually surprised that I haven’t been able to find anything out there really built on their Android API.  Most of the projects I could find seem to be centered around the Zeo Bedside unit because in some ways it gives you access to more data.

My projects contained two components which work with Zeo sleep data.  One is a reimplmentation of the SmartWake adaptive alarm feature for Android.  SmarkWake was the feature that was supposed to wake you at the optimum time such as when you are entering or leaving REM sleep.  i never saw the feature work, so I built my own.  The other is PHP code to display CSV sleep data in progress graph form.

Source and more detail available at the GitHub repository.

Other relevant information to using the Zeo Android API was mentioned in an older post:
Using the Zeo Android API

ALSO:
One of the prominent places Zeo was talked about was at the Quantified Self forums, so I mentioned this code in the Zeo shutdown thread in case anyone finds a use for it:
Zeo shutting down: export your data!

Advertisement

After installing Windows – Test Environment

I use virtual machines for testing at work.  The way I go about this is to create a base VM with whatever general purpose tools and configuration I’d like to have available.  I run updates on it occasionally and then make a copy whenever I need a new test VM.  I had bad experiences with VM cloning in the past, but that’s probably something I should look into again at some point.

I’m installing a new base VM of Windows Server 2012, so I thought for future reference I’d list the changes I make.  A lot of the changes I make are strictly personal preference.

Server Roles

As a starting place, after Windows is installed, I add the IIS Role and the Remote Desktop Services Role (RD Session Host).  Though I haven’t actually tried it yet, I’d like to try the Citrix style RemoteApp functionality so I can run individual apps from VMs remotely on my primary desktop.

Features

In addition to the .NET Framework options, I add the “Desktop Experience” feature listed under “User Interfaces and Infrastructure”.  You wouldn’t think from the description that this would add much value, but I’ve run into a few places where there are seemingly random dependencies on this feature.  I test server and client applications on the same systems, so it isn’t a bad idea anyway.

After all roles and features are installed run Windows Update to get everything totally updated.

First!

As long as the VM is network accessible, it’s easier to remote in to do everything.  So enable Remote Desktop in the System Properties on the Remote tab.  Second, disable Internet Explorer Enhanced Security Configuration so you can more easily use it to get any utilities you need.  Remember, this is an internal VM for testing things and is only even running as needed, so security features are lower priority than VMs for production purposes.

Ninite

Ninte is amazing!  I used it to install:

  • Chrome
  • Silverlight
  • 7-Zip
  • IrfanView
  • SumatraPDF
  • FileZilla
  • Notepad++
  • Classic Start

Keep the installer, because rerunning it will update the applications if needed.

Folders

  • C:Apps – The way I prefer to do things I create a folder called Apps for small single exe utilities.  SpaceSniffer is the first thing I add here because it helps clean up if I end up needing to trim the size of the VM.
  • C:Sysinternals – for the whole SysInternals Suite.  I add this to the system PATH variable so I can quickly run anything.  I also want this to always be up to date, so I use a scheduled task to run one of the following at logon
    • As long as you are 2008+ (so you have robocopy) and you have Desktop Experience feature added (so you can use WebClient), you can run this simple script with Admin privliges.
    • net start webclient
      robocopy.exe \live.sysinternals.comtools “C:SysInternals”
      net stop webclient

    • If you cannot meet those requirements, such as when you are using XP/2003, or cannot install the Desktop Experience feature, use SysInternalsUpdater with the /auto parameter
  • C:Downloads – Not that I’m frequently downloading anything on these systems after initial install, but it bugs me that downloads go into the user folder.  After creating this folder, I go to C:Users[username] and right-click on Downloads, then on the Location tab change it to C:Downloads.  Now Chrome, IE, etc will know to use this as default.
  • C:NirSoft – I don’t use NirSoft tools nearly as much as Sysinternals, but they can be nice to have available.
  • Mapped Drives – Because these VMs are not on the domain, I map a consistent drive letter to a common fileshare so it is easy to move files between VMs and my desktop.  Longer ago I had problems with just telling Windows to remember the mapped drive, so I use a script like this at startup.  The user is specifically for these shares.

    net use [drive]: /DELETE
    net use [drive]: \[server][share] [pass] /USER:[serveruser]

7-Zip

In the 7-Zip options on the 7-Zip tab I uncheck “Cascaded context menu” and leave only

  • Extract Here
  • Extract to <Folder>
  • Add to <Archive>.7z
  • Add to <Archive>.zip

On the Settings tab, check Show “..” and Full Row select.

Other

Agent Ransack/FileLocator Lite – Same program, just renamed by the author to have a “safe for work” name.  Very nice search application.

Notepad++ XML Tools – Some programs write XML without whitespace, which is painful to read without the pretty print feature (Ctrl+Alt+Shift+B).  Install from the Plugin Manager within Notepad++.

Disable the Shutdown Event Tracker

Scripts and exported registry settings for the topics mentioned above: ExtractToRootOfNewInstall.zip

For my home system it starts the same then add gaming and development apps.

amBX Usability Enhancements

I use amBX Gaming Lights and while I like them, there are some rough edges.  If my computer would go to sleep, the driver/services wouldn’t work correctly unless they were restarted.  And applications like amBX Illuminate would hang as a result, so that needed to be restarted too.

So I wrote a batch script to do this.  Then I used a scheduled task to check the event log for the Power event that meant the system was waking up.  The batch scripts need to run as Administrator, but scheduled tasks have an option for this.  Cool, now the lights work properly after the computer wakes.

But then I decided I wanted shortcut keys to manually stop and start the lights.  So I bound the batch scripts to the extra keys on my Logitech G710+ Mechanical Gaming Keyboard.  But the batch script needs to run as Administrator and there wasn’t a built-in way to do that with the keyboard configuration, so I had to find ways to make that happen.  Now the scripts auto elevate which is seemless if UAC is off.  With UAC on this will trigger a prompt, but at least it will work.

Then there was the minor problem that killing Illuminate would leave orphaned icons in the system tray.  This too could be solved with a bit of work.

Included is:

  • A script to (re)start the amBX services and amBX Illuminate
  • A script to kill amBX Illuminate
  • RefreshNotificationArea, which is called from the scripts to clear orphan icons in the system tray after killing processes
  • XML export of a scheduled task to run the restart script when the system wakes from sleep.
  • XML export of a keyboard profile for Logitech’s Gaming Software, which binds G1 to (re)start the lights, and G2 to turn them off.

The scheduled task and keyboard profile assume the scripts are in C:AppsamBX.  Be sure to update the path if needed.

Though the scripts are stopping and starting amBX Illuminate, the same principle should apply if the scripts are changed to reference an alternative program like Aurora Synesthesia or glOW.

Scripts available here: amBX Usability Enhancements

Refreshing the Notification Area (System Tray)

Because I am forcibly killing certain processes regularly, I end up with orphaned icons in what is apparently called the Notification Area, not the System Tray.

I found a good StackOverflow answer, but it needed some updates:
Can you send a signal to Windows Explorer to make it refresh the systray icons?

The answer draws its information from this informative post:
REFRESHING THE TASKBAR NOTIFICATION AREA

But the information is from 2008.  The name of the window used in XP has changed in Windows 7 (actually probably in Vista).  In addition to this, the code only works on visible icons, not on those that are currently hiding.  The following code is updated to clear both visible and hidden icons.

 

//WinXP
    GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),
            NULL,
            L"ToolbarWindow32",
            L"Notification Area"),
        &r);

    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);

	//Visible icons
    GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),
            NULL,
            L"ToolbarWindow32",
            L"User Promoted Notification Area"),
        &r);

    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);

	//Hidden icons
	GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(NULL, L"NotifyIconOverflowWindow"),
            NULL,
            L"ToolbarWindow32",
            L"Overflow Notification Area"),
        &r);

    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);

Utility available here: Refresh Notification Area

By the way, if you have the opposite problem as me and are losing the icons of programs still running, see the following:
Can I re-gain a systray icon of a running app that has gone missing?
trayrestore

 

I’ve posted my updates to the StackOverflow answer: http://stackoverflow.com/a/18038441/221018

Current Directory in Elevated Batch Scripts in Windows 8

I am seeing a difference between elevated batch scripts in Windows 7 and Windows 8.  If you copy the following in the a batch script and run in either version, you get the current directory.  However if you right-click Run As Administrator, you see the current directory in Windows 7 and “C:Windowssystem32” in Windows 8:

@echo off
echo Current path is %cd
%pause

Fortunately there is an easy workaround by changing the current directory to the path of the current script (parameter zero):

@echo off
echo Current path is %cd%
echo Changing directory to the path of the current script
cd %~dp0
echo Current path is %cd%
pause

I’m using this in context of the StackOverflow answer showing how to auto elevate a script:
How can I auto-elevate my batch file, so that it requests from UAC admin rights if required?

I added this info in case anyone else had the same issue: http://stackoverflow.com/a/18037959/221018

 

Sleep Monitoring and Quality

Originally posted as an answer here: http://www.paleohacks.com/sleep/tracking-sleep-with-an-app-22289

I’ve used Zeo for Android for the last seven months. I really like having quantifiable data to make sense of how I feel after I slept. Though I only used it more toward the beginning, their website has some pretty good tools to visualize the data and to track variables and their effect on your sleep (such as caffeine, alcohol, times you woke for the bathroom, etc). The headband is comfortable, so no worries there.

The one complaint I had was that the SmartWake alarm feature never worked for me. Because Zeo has an open API for the Android version I actually wrote my own implementation: http://projects.stephenklancher.com/project/id/85/Zeo_Sleep_Monitor

Aside from monitoring these are the things that I’ve done personally to get better sleep:

– Installed blackout blinds so my room is as dark as possible
– I take Magnesium at night
– I wake up with gradually increasing light: http://www.amazon.com/gp/product/B003XN4RIC/ref=oh_details_o03_s00_i00
– I’ve also taken to sleeping with ear plugs. I would not have thought this would make any difference, but I seem to wake up less often now.