Marc's Public Blog - Linux Hacking


All | Aquariums | Arduino | Btrfs | Cars | Cats | Clubbing | Dining | Dinners | Diving | Electronics | Exercising | Flying | Hiking | Linux | Linuxha | Public | Rc | Sciencemuseums | Snow | Solar | Trips

This page has a few of my blog entries about linux, but my main linux page is here
Picture of Linus


Table of Content for linux:

More pages: October 2016 August 2016 July 2016 June 2016 February 2016 January 2016 May 2015 March 2015 January 2015 October 2014 May 2014 April 2014 March 2014 January 2014 November 2013 September 2013 May 2013 March 2013 January 2013 December 2012 August 2012 May 2012 March 2012 January 2012 December 2011 August 2011 July 2011 January 2011 October 2010 August 2010 June 2010 April 2010 March 2010 January 2010 December 2009 November 2009 September 2009 August 2009 July 2009 May 2009 January 2009 December 2008 November 2008 October 2008 January 2008 November 2007 August 2007 July 2006 January 2006 August 2005 April 2005 November 2004 March 2004 February 2004



2011/12/17 Zeo Raw Library Simple Callback Example
π 2011-12-17 00:00 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: October 2016 August 2016 July 2016 June 2016 February 2016 January 2016 May 2015 March 2015 January 2015 October 2014 May 2014 April 2014 March 2014 January 2014 November 2013 September 2013 May 2013 March 2013 January 2013 December 2012 August 2012 May 2012 March 2012 January 2012 December 2011 August 2011 July 2011 January 2011 October 2010 August 2010 June 2010 April 2010 March 2010 January 2010 December 2009 November 2009 September 2009 August 2009 July 2009 May 2009 January 2009 December 2008 November 2008 October 2008 January 2008 November 2007 August 2007 July 2006 January 2006 August 2005 April 2005 November 2004 March 2004 February 2004