Marc's Public Blog - OSA, Obstructive Sleep Apnea and MMA Surgery


All | Aquariums | Arduino | Btrfs | Cars | Cats | Clubbing | Computers | Dining | Diving | Electronics | Exercising | Festivals | Flying | Halloween | Hbot | Hiking | Linux | Linuxha | Mexico | Monuments | Museums | Outings | Public | Rc | Sciencemuseums | Solar | Tfsf | Trips



This page has a few of my blog posts about my issues with OSA, Obstructive Sleep Apnea, which basically means not being able to breathe at night and having restless nights, night after night.
Because my sleep apnea scored low but somehow the impact on me was fairly high, it took a while to diagnose, and I tried several things before eventually getting Maxillomandibular Advancement Surgery (MMA) to fix my airway for good.

I made this summary page after the fact, so it starts with a few sleep studies I likely did 5 years later than I should have.

>>> Back to post index <<<

2011/12/17 Zeo Raw Library Simple Callback Example
π 2011-12-17 01:01 in Linux, Osa
The MyZeo folks definitely deserve credit for releasing open firmware and instructions on how to interface with their bedside Zeo device via a custom made serial port: http://zeorawdata.sourceforge.net/starting.html

Since I had been working on arduino, I happened to have one of those 3.3V FTDI USB-serial converters, and was able to make a cable that connects my bedside Zeo to my server closer via a custom cable going through my existing Cat-5 wiring.

The example code they gave is however, while very fancy, not that simple to borrow from for a more simple application that simply needs to keep track of the sleep stage.

So, after finding the relevant info, I compiled the code below, which I'm posting for others to use (you can also download it here: zeo raw data code sample).

#!/usr/bin/python

# This is based off the Zeo Raw Data Library at the bottom of # http://zeorawdata.sourceforge.net/starting.html # This script is a much simpler version of how to log basic data than the cool # and pretty GUI_Viewer from http://zeorawdata.sourceforge.net/examples.html # This script is an easier example to steal from for simple logging/integration.

# By Marc MERLIN <marc_soft@merlins.org> / 2011/12/17 # License: GPLv3.

#gandalfthegrey [mc]$ ./logsleep.py # 2011-12-17 12:19:10: HeadbandDocked # 2011-12-17 12:19:15: HeadbandUnDocked # 2011-12-17 12:19:22: Sleep state: Undefined # 2011-12-17 12:19:52: Sleep state: Undefined # 2011-12-17 12:20:22: Sleep state: Undefined # 2011-12-17 12:20:52: Sleep state: Undefined # 2011-12-17 12:21:22: Sleep state: Undefined # 2011-12-17 12:21:52: Sleep state: Undefined # 2011-12-17 12:22:22: Sleep state: Undefined # 2011-12-17 12:22:52: Sleep state: Undefined # 2011-12-17 12:23:22: Sleep state: Undefined # 2011-12-17 12:23:52: NightStart # 2011-12-17 12:23:52: Sleep state: Awake # 2011-12-17 12:24:22: Sleep state: Awake # 2011-12-17 12:24:52: Sleep state: Awake # 2011-12-17 12:25:22: Sleep state: Awake # 2011-12-17 12:25:52: Sleep state: Awake # 2011-12-17 12:26:23: Sleep state: Awake # 2011-12-17 12:26:32: HeadbandDocked

# System Libraries import time import sys

# Zeo Libraries from ZeoRawData import BaseLink, Parser from ZeoRawData.Utility import *

# User customizable variables port = '/dev/ttyUSB0'

class Callbacks: def logtime(self): return time.strftime("%Y-%m-%d %H:%M:%S: ", time.localtime())

def SliceCallback(self, slice): if slice['SleepStage']: print self.logtime() + "Sleep state: " + slice['SleepStage']

def EventCallback(self, logtime, version, event): print self.logtime() + event

if __name__ = "__main__": link = BaseLink.BaseLink(port) parser = Parser.Parser()

callbacks = Callbacks()

# Add Callbacks and Start the Link link.addCallback(parser.update) parser.addSliceCallback(callbacks.SliceCallback) parser.addEventCallback(callbacks.EventCallback) link.start()

# Infinitely loop to allow the script to run continuously while(True): time.sleep(5)


More pages: March 2004 November 2005 April 2006 July 2006 December 2009 January 2010 July 2010 August 2010 December 2010 March 2011 May 2011 December 2011

>>> Back to post index <<<

Contact Email