|Software apps and online services:|
Forgive me @Walabot team for my long delay for documentation, guilty!!......:(
Now I am trying to pickup and recover my memory and update documentation as much as possible.
This project is creating an intelligent switch connecting people's sleep to the switchers/power button of any type of intelligence devices, by Walabot heart rate tracking API.
1. Today I use app to play bedtime stories for my baby. But you never know when she really fall into sleep so that I could switch the app off, to save energy and avoid wake her up. The current solution is constantly checking her by eye but this is laboring and sometimes she is not really fall into deep sleep.
2. I believe I am not the only one and it has been so many times I watching TV or listening music to sleep and wasted electricity bill, or reading in the warm bed in the night until I feel so sleepy to switch off the light.
The problems raised in above stories could be solved by one simple solution by monitor people's sleep by Walabot heart rate monitoring API and link it to the switchers of App, light or whatsoever intelligence devices.
The first stage of this project would be focused on realize above mentioned functions, mainly connecting sleeping to bed light  and story app . The switching condition could be either fixed set threshold of heart rate or personalized through machine learning. The monitor (Walabot) could be mount simply below beds/cots to ensure stable signal. In the future later stage possibilities could include but not limited to 1) link peoples mood (detected by machine learning heart rate variation) to light  and 2) intelligent DJ or even live auto composer .
It will offer not only the lazy people like myself a lazier life but the world an environmental efficient solution.
This project merged following existing projects:
"Punk Those Trick-or-Treaters with a 3D Radar Booby Trap" at https://makezine.com/projects/punk-those-trick-or-treaters-with-a-3d-radar-booby-trap/
"RASPBERRY PI HOME AUTOMATION - CONTROL LIGHTS, COMPUTERS, CCTV AND MORE!" at http://www.instructables.com/id/Raspberry-Pi-Home-Automation-Control-lights-comput/
Step 1: Do basic Pi setup.Starting with a fresh new Raspberry Pi 3, do all your basic Pi setup:
- connect to our Raspberry Pi via SSH (PuTTY)
- Install the Raspbian operating system, using NOOBs, following the directions at https://www.raspberrypi.org/learning/software-guide/quickstart/
- Update all packages to current by running the commands:
sudo apt-get updateand then
sudo apt-get upgrade
Step 2: Do basic Walabot steup.
- Install the Walabot SDK and the WalabotAPI Python library using pip.
- Check details at: https://github.com/Walabot-Projects/Walabot-HelloWalabot
Step 3: Configure the Pi to work with Walabot.
- As described in Walabot’s
PeopleCountercode example at https://github.com/Walabot-Projects/Walabot-PeopleCounter), simply add the following two lines to the end of your /boot/config.txt file:
safe_mode_gpio=4max_usb_current=1Then reboot the Pi so the new settings can take effect.
Step 4: Connect the Walabot to the Pi.
- Connect them through an ordinary powered USB hub. The Pi doesn’t provide sufficient power on its own USB ports to run the Walabot, so you’ll get cryptic error messages and crashes if you try to plug the Walabot into the Pi directly.
Step 5: Download the Walabot software to your Pi.
- Open a terminal window by PuTTY.
- Download the Walabot SDK for Raspberry Pi from http://walabot.com/getting-started, then install the downloaded .deb file:
dpkg -i walabotSDK_RasbPi.deb
- Download the Python libraries:
python -m pip install "/usr/share/walabot/python/WalabotAPI-1.0.33.zip"
Step 6: Wiring Up the Lamp, Relay Connectors and Raspberry Pi
- Follow the wiring up procedures given in Step 4 of http://www.instructables.com/id/Raspberry-Pi-Home-Automation-Control-lights-comput/
Note for test and safety, it is STRONGLY recommended to use LED instead of Lamp and use battery instead of Power Socket.
Step 7: download code and play around
- Sleep_Switch_v1.0.4.py available at https://gist.github.com/lxasqjc/c9d3b476aa3f2cbfd6355cbf6326b72c
Full assembled photo:
Preliminary result video:
Again appreciate the support of Walabot team for offering free hardware!
from __future__ import print_function from sys import platform from os import system import WalabotAPI as wlbt import time # python timer import statistics #cal std import RPi.GPIO as GPIO #This imports the GPIO Library into Python so we can use the GPIO Pins on the Pi. GPIO.setmode(GPIO.BCM) GPIO.setup(2, GPIO.OUT) #We are using GPIO 2 as our first pin, which is where the green wire is connected to the first relay switch on the baord #initialize as false, thus off wlbt.Init() # load the WalabotSDK to the Python wrapper wlbt.SetSettingsFolder() # set the path to the essetial database files wlbt.ConnectAny() # establishes communication with the Walabot wlbt.SetProfile(wlbt.PROF_SENSOR_NARROW) # set scan profile out of the possibilities # JC: replace PROF_SENSOR to PROF_SENSOR_NARROW # Sensor narrow: Lower-resolution images for a fast capture rate. Useful for tracking quick movement. # thus for heart rate wlbt.SetDynamicImageFilter(wlbt.FILTER_TYPE_DERIVATIVE) # specify filter to use #JC: replace FILTER_TYPE_MTI to FILTER_TYPE_DERIVATIVE #Moving Target Identification (MTI) filter, the Derivative filter is available for the specific frequencies typical of breathing. ## variables definition ## Walabot_SetArenaR - input parameters minInCm = 30; maxInCm = 150; resICm = 1; ## Walabot_SetArenaTheta - input parameters minIndegrees = -4; maxIndegrees = 4; resIndegrees = 2; ## Walabot_SetArenaPhi - input parameters minPhiInDegrees = -4; maxPhiInDegrees = 4; resPhiInDegrees = 2; ##JC: here below modified from C++ breathing code, before use variables needs to be defined, parameters accoarding to http://api.walabot.com/_features.html and http://api.walabot.com/_sample.html C++ breathing code ## Setup arena - specify it by Cartesian coordinates(ranges and resolution on the x, y, z axes); ## In Sensor mode there is need to specify Spherical coordinates(ranges and resolution along radial distance and Theta and Phi angles). wlbt.SetArenaR(minInCm, maxInCm, resICm) ## Sets polar range and resolution of arena (parameters in degrees). wlbt.SetArenaTheta(minIndegrees, maxIndegrees, resIndegrees) ## Sets azimuth range and resolution of arena.(parameters in degrees). wlbt.SetArenaPhi(minPhiInDegrees, maxPhiInDegrees, resPhiInDegrees) wlbt.Start() # starts Walabot in preparation for scanning print ('hello') thefile = open('%s.txt' % time.strftime("%H-%M-%S_%d-%m-%Y"), 'w') #open file with name of current time while True: MEAN =  #array which save each mean get from wlbt MAX =  #array which save each max get from wlbt MIN =  #array which save each min get from wlbt STD =  #array which save each std get from wlbt start_out = time.time() #timer control how long each circle while (time.time()-start_out) <10: #each 1min Energy =  #array which save each energy get from wlbt start_in = time.time() #timer control how long each circle while (time.time()-start_in) <5: #each 10s ##JC: add calibrates based from C++ code ##// calibrates scanning to ignore or reduce the signals wlbt.StartCalibration() #start calibration while wlbt.GetStatus() == wlbt.STATUS_CALIBRATING: #when calibraion done wlbt.Trigger() #trigger walabot Energy.append(wlbt.GetImageEnergy()) # get Energy #Energy_current = wlbt.GetImageEnergy() ##JC: replace GetSensorTargets to GetImageEnergy #system('cls' if platform == 'win32' else 'clear') # clear the terminal #print('Energy_Current = ', Energy_current, '/n') #after each 10s do following print('mean(10s)=', sum(Energy) / len(Energy), ' ') print('max(10s)=', max(Energy) , ' ') print('min(10s)=', min(Energy) , ' ') print('std(10s)=', statistics.stdev(Energy) , '\n') #print('time elapsed', time.time()-start, ' ' ) MEAN.append(sum(Energy) / len(Energy)) # get Energy MAX.append(max(Energy)) # get Energy MIN.append(min(Energy)) # get Energy STD.append(statistics.stdev(Energy)) # get Energy thefile.write("%s " % time.strftime("%H:%M:%S")) for item in Energy: thefile.write("%s " % item) thefile.write("\n") #fed analyzed sleeping criteria in: mean < 0.02, max <0.02, min <0.01, std <0.01 if ((sum(map(abs, MEAN)) / len(MEAN))<0.02): #use absolute if ((sum(map(abs, MAX)) / len(MAX))<0.02): if ((sum(map(abs, MIN)) / len(MIN))<0.01): if ((sum(map(abs, STD)) / len(STD))<0.01): print ("SLEEP!!!SLEEP!!!SLEEP!!!") GPIO.output(2, False) #light off thefile.write(" SLEEP!!!") thefile.write("\n") else: print ("AWAKE") GPIO.output(2, True) #light on thefile.write(" AWAKE!!!") thefile.write("\n") else: print ("AWAKE") GPIO.output(2, True) #light on thefile.write(" AWAKE!!!") thefile.write("\n") else: print ("AWAKE") GPIO.output(2, True) #light on thefile.write(" AWAKE!!!") thefile.write("\n") else: print ("AWAKE") GPIO.output(2, True) #light on thefile.write(" AWAKE!!!") thefile.write("\n") wlbt.Stop() # stops Walabot when finished scanning wlbt.Disconnect() # stops communication with Walabot
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!