Marc's Public Blog - Linux Hacking


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



>>> 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: July 2002 February 2004 March 2004 November 2004 April 2005 August 2005 January 2006 July 2006 August 2007 November 2007 January 2008 October 2008 November 2008 December 2008 January 2009 May 2009 July 2009 August 2009 September 2009 November 2009 December 2009 January 2010 March 2010 April 2010 June 2010 August 2010 October 2010 January 2011 July 2011 August 2011 December 2011 January 2012 March 2012 May 2012 August 2012 December 2012 January 2013 March 2013 May 2013 September 2013 November 2013 January 2014 March 2014 April 2014 May 2014 October 2014 January 2015 March 2015 May 2015 January 2016 February 2016 June 2016 July 2016 August 2016 October 2016 January 2017 September 2017 January 2018 March 2018 December 2018 January 2019 January 2020 May 2020 January 2021 September 2021 March 2023 April 2023 December 2023 June 2024 November 2024

>>> Back to post index <<<

Contact Email