Back to (Sleep) School!
I was wondering whether its possible to use the Raw Data lib with the Zeo Mobile?I didnt see a serial line on the back of the Mobile basestation.
Mon, 07/16/2012 - 13:22
Currently the raw data library only works with Zeo bedside due to battery and memory constraints. The Zeo mobile does have an open android API that at least gives you access to the sleepstages, but not raw EEG.
Mon, 07/16/2012 - 15:59
I have adapted the python program I posted on this thread to look at the data from the zeo mobile headband. Every 5 minutes it sends 10 readings of sleep state ( 0 = undefined, 1 = wake, 2 = rem, 3 = light sleep, 4 = deep sleep, and I haven't found out what 6 is). Last night I had these readings (10 states + the zeo estimate of the average sleep for this 5 minute cycle):
3333333011 1 *
1133332223 1 *
3333333111 1 * woke up after a long dream
3312222222 1 *
2222222211 1 * woke up after continuation of dream
The * show where I think the estimate of average sleep state is a bit wonky
Tue, 07/17/2012 - 08:15
1111112122 1 *
2222111111 1 *
3233222221 1 *
1222222222 1 *
1112122222 1 *
Tue, 07/17/2012 - 10:26
The averages that seem a little odd is due to our wake override feature. In order to best represent the sleep data at a more course scale, we found it necessary to place emphasis on short awakenings so that they don't get buried due to other sleep stages. If even a single 30sec window is classified as wake within a 5min window, the whole 5min window is classified as wake. This way users can better see when they've had awakenings even when looking at the 5min hypnogram.
As to the "6" sleepstage, that is a particularly deep stage of light sleep. Depending on the sleepstages around it and throughout the night, it may be used to classify a 5min window as deep or light sleep. This was necessary since what qualifies as "deep" sleep can vary for different people and different ages.
Wed, 07/18/2012 - 09:07
Thanks for that information Brian. I notice the first 2 headband outputs are at 2.5 minute intervals followed by 5 minute intervals. Is there any way to get the headband to output data faster (ie every 30 seconds). I understand that the increased bluetooth activity will drain the battery faster but this could be overcome by reducing the amount of data sent each time. With a handshake method the headband only needs to output 1 number every 30 seconds (ie the sleep state) rather than the whole data package. The reason I ask is because the current method could incur a delay of up to 5 minutes before a rem state is detected. This means any interactive method to induce lucid dreaming could frequently be activated too late. Also, I notice that Zeo wants our sleep data to be available to us more easily. Could you change the permissions in the package manifest to allow access to the database records without having to have a rooted android?
Mon, 07/23/2012 - 08:55
There is currently no way to get the headband to output the data faster. That would require a new firmware to be developed. Perhaps in the future we will develop this (I certainly would love to have a complete RDL for Zeo Mobile), but we are currently busy with other developments.
Honestly, for any kind of unintended use (lucid dreaming) the Zeo Bedside is currently the best option.
We absolutely want the sleep data to be easily available. I'm not personally an android developer, but could you explain what data you are trying to obtain that isn't accessible through the android api?
Fri, 07/27/2012 - 07:11
I have done some development work in java using eclipse to create an apk (actually helping to develop a few apis for sl4a) and compared to writing python scripts in sl4a it is as much fun as banging your head against a brick wall. My python script which reads zeo data in real time (delayed by 5 minutes!) was fun and easy to produce. I am not interested in producing an app for zeo but willing to allow others to use (and improve) my scripts for their own particular purposes. If you make a simple change in the permissions of your zeo mobile app this will allow many more people to work with their own sleep data. There is now a python for android development which will obviate the need for sl4a but, unfortunately, only currently available on the ubuntu platform. I am willing to help provide an update to the zeo mobile firmware (for faster output) if you wish.
Fri, 07/27/2012 - 09:02
Glad to hear you've had success using python to read the Zeo data. It'd be great for you to share those scripts!
Given that you've already had success reading the data without changing the permissions, could you please explain what additional features you are trying to access? I don't believe the Zeo android API requires a rooted phone to be used.
Fri, 07/27/2012 - 11:35
My current python script is shown below (in which you can see I use my root su status to change permissions of your database files). The point I was trying to make is that my approach is quick and easy, the java+eclipse+zeo api is much harder and more time consuming (I have tried both methods in the past!).
I suggested you change your database permissions since there may be plenty of python programmers happy to use sl4a or 'python for android' but unhappy to root their android device (since this invalidates any warranties).
Do you want my help to update the zeo mobile firmware (for faster output)?
## run this script from sl4a after starting the zeo mobile app
## requires rooted android with python interpreter for sl4a
import android, os, time, sqlite3
from datetime import datetime
droid = android.Android()
new_record = False ## wait for new database record to start
droid.toggleRingerSilentMode(True) ## silent mode on
droid.setMediaVolume(4) ## set sound level
lastlen = 0
da = '/sdcard/sleepdata'+datetime.now().strftime('%d%m%y')+'.txt'
f2 = file(da, 'w') ## your 30 second sleep data is recorded to this file
os.system('su -c "chmod 777 /data/data/com.myzeo.android/databases/zeo.db"')
os.system('su -c "chmod 777 /data/data/com.myzeo.android/databases/zeo.db-journal"')
conn = sqlite3.connect('/data/data/com.myzeo.android/databases/zeo.db')
cmnd = "SELECT base_hypnogram FROM sleep_records order by sleep_event_id desc limit 1"
for row in conn.execute(cmnd).fetchone():
stages = repr(str(row)) ## get all sleep states this night
l = len(stages)
if (l>40) and (l<100):
new_record = True ## new database record started
if l > lastlen:
f2 = file('/sdcard/graph.txt', 'a')
rem = False ## reset rem state for next reading
ct = 0
i = l - 36
while i <= l:
s_state = stages[i-2:i-1] ## latest sleep states from database
if str(s_state) == '2':
rem = True
if rem and (str(s_state) == '1'):
rem = False ## no voice reminder if awake after rem
i += 4
f2.write( str(s_state) ) ## record this set of sleep states
ct += 1
if ct == 10: ## 10 sleep states for 1 graph record
ct = 0
tim = ' ' + datetime.now().strftime('%H:%M') + '\n'
f2.write(tim) ## add time at end of 10 states
lastlen = l
if rem: ## headband state 2 means rem sleep
droid.toggleRingerSilentMode(False) ## sound on
time.sleep(3) ## wait for voice to activate
droid.toggleRingerSilentMode(True) ## sound off
time.sleep(10) ## time between zeo database checks
if __name__ == '__main__':
Sun, 09/16/2012 - 12:35
I've recently got into the current trend of programming for android because of my Java background and this script has been my introduction to Python and sl4a. I have to say thanks jokar49. Not only have you given me a relatively clear solution to the problem I was originally browsing to solve but you've also shown me what I've been missing without Python. Thank you good Sir.
Fri, 07/27/2012 - 15:49
I see what you are talking about now. Thank you for explaining. I'm not in charge of the android api & app, so I'll forward your suggestion to the person who is. I'd love to see more people hacking on it with python.
Thank you for the offer, but adjusting the headband firmware is something we prefer to keep internal. This allows us to make sure that the new firmware has been thoroughly tested and evaluated before releasing it.
Tue, 11/06/2012 - 18:10
I am also very interested in getting data faster. 30 Second intervals would be ideal. Any update on maybe getting a custom firmware to do this?
Mon, 09/17/2012 - 16:32
Three days after I've gotten a notification in my inbox saying "Congrats - Someone relpied to you comment" and still no sign of the comment. Seriously guys?!? Are you guys using an early version of codeigniter or something?
Mon, 09/17/2012 - 16:40
Please excuse my atrocious spelling and try not to let that distract from the issue at hand. Although the irony of talking about database issues while you browse a site the suffers seriously from them ...
Sign Up for Zeo Updates, User Stories, and Sleep Tips
Get the App
Feel Your best!
Zeo Sleep Manager is neither a medical device nor a medical program and is not intended for the diagnosis or
treatment of sleep disorders. If you suspect that you may have a sleep disorder, consult your physician.