Using Raw Data library with ZeoMobile?

English

Hello there,

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. 

Thanks,

madmaze 

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.

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):

0000000000  0
1111111111  1
1111111111  1
1111111111  1
1111111113  1
3663333333  3
3333333333  3
3333333333  3
3333333011  1 *
1133332223  1 *
3366333333  3
3322244444  4
4444433336  4
2246446466  4
3366633344  3
2223644446  4
3333333111  1  * woke up after a long dream
1111111111  1
1111111111  1
1111113333  1
3333333333  3
3333333333  3
3331111331  1  
1111111333  1
3333333333  3
3333333666  3
4446443333  4
3366666644  4
4446643333  4
3333643663  3
3333333333  3
3333333333  3
3322223333  3
2331111113  1
3331111111  1
3312222222  1  *
2222222222  2
2222222211  1  *  woke up after continuation of dream
1111333333  1
3333322233  3
3323000000  3
0000000000  0
0000000000  0
0000000000  0
0000000000  0
0364444446  4
3444444433  4

The * show where I think the estimate of average sleep state is a bit wonky

0000011111  1
1111111111  1
1111111111  1
1111111111  1
1111111111  1
1111111111  1
1114444444  1
4444444444  4
4444444444  4
1311111444  1
4444444444  4
4444444444  4
4444444444  4
4444444444  4
4443344333  3
3334444433  3
3333333333  3
3333333444  3
3433333333  3
1111112122  1  *
2222111111  1  *
1222211111  1
1111111111  1
1111111111  1
1111333300  1
0000000000  0
0000000000  0
0000000000  0
4334444443  4
3333333333  3
3333333333  3
3303333333  3
3333333333  3
4444333333  3
3312113331  1
1111113122  1
3233222221  1  *
1222222222  1  *
1112122222  1  *
1111111111  1
1111100000  1

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.

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?

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?

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.

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.

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()

 

def track_sleep(): 

  droid.wakeLockAcquireDim()

  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

  f2.write('sleep data:\n')

  f2.close()

  while True:

    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 new_record:

      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

        f2.close()

        lastlen = l

        if rem:  ## headband state 2 means rem sleep

          droid.toggleRingerSilentMode(False) ## sound on

          droid.ttsSpeak('Dreaming')

          time.sleep(3) ## wait for voice to activate

          droid.toggleRingerSilentMode(True) ## sound off

    time.sleep(10) ## time between zeo database checks

 

if __name__ == '__main__':

  track_sleep()

 

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.

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.

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?

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?

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 ...