/sleephq-pi

Erik's Unofficial SleepHQ-Pi Automation Utilities

Primary LanguageShellThe UnlicenseUnlicense

Erik's Unofficial SleepHQ-Pi Automation Utilities v0.3

This is a rough and dirty log of what I'm doing to automate my SleepHQ uploads until the Magic Uploader is open-sourced.

TL;DR

I remove the SD Card from my CPAP (currently a ResMed AirSense 11), insert it into my USB card reader, and plug that into the Raspberry Pi. Turn on the RPi, which on autologin runs sleephq-pi.sh which copies the data from the SD card, backs it up to my Dropbox, and uploads it automatically to SleepHQ (using a Selenium automation). It automatically unmounts the SD card when it is done and sends me a text message confirmation.

I used a Raspberry Pi 4 B that I had lying around. I see no reason why this wouldn't work with a RPi 3, or even a Zero W (might require a powered USB hub, not sure).

TODO

  • Capture last time stamp of successful run. Only include files since that time in the zip to reduce upload size! (DATALOG\YYYMMDD)
  • Test the autologin / autorun on power on feature
  • Add in SMS notifications (probably through Make.com/Twilio since I use that infrastructure already. IFTTT could work too)
  • Abstract out the paths and crentials to a config file (copy a sample config from the git repo into home directory)

Install Guide / Build Log

  • Took a Raspberry Pi 4 I had lying around
  • Downloaded the latest Raspberry Pi imager
  • Customize the settings
    • Set hostname: sleephq-pi.local
    • Enable SSH (use password auth, it's in my local network, I don't care lol)
    • Set username and password
    • Configure wireless LAN
    • Set locale settings
  • Write image to microSD card
  • Boot Raspberry Pi from microSD card
  • [Optional] Set DHCP Reservation in firewall
  • Connect over SSH to sleephq-pi.local (or by IP depending on local DNS resolver)
  • Update and Upgrade installed packages
     sudo apt update
     sudo apt upgrade -y
    
  • Enable VNC and set Desktop-Autologin so the GUI is loaded even while headless
     sudo raspi-config
     Interfacing Options --> VNC --> Yes
     System Options --> Boot / Auto Login --> Desktop Autologin
    
  • Install python and selenium
     Python3.9 should be installed by default
     pip install -U selenium
     sudo apt install chromium-chromedriver
    
  • Install Dropbox-Uploader
     curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
     chmod +x dropbox_uploader.sh
     ./dropbox_uploader.sh  # guided through wizard to create the dropbox app, get the app id / secret, and setup your tokens
    
  • Clone the git repo
     cd ~
     git clone https://github.com/grumpymaker/sleephq-pi.git
    
  • Edit the settings that you need, espescially:
    • Card reader device name [sda1 or similar] in sleephq-pi.sh
    • Backup path (and other paths) in sleephq-pi.sh
    • SleepHQ username and password in uploaddata.py
  • [Currently untested] Edit autostart to run the script on system boot --> user autologin
     sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
    
     @lxpanel --profile LXDE-pi
     @pcmanfm --desktop --profile LXDE-pi
     @xscreensaver -no-splash
     @bash /home/erik/sleephq-pi/sleephq-pi.sh
    

Original Idea

• Remove SD Card from CPAP
• Insert SD Card into Raspberry Pi setup.
• Script runs
	○ Copy the data off the SD Card into YEAR-MONTH-DAY-HHMMSS folder
	○ Update symlink to CURRENT-CPAP-DATA
	○ Throw a timestamp into my Dropbox
	○ Run Selenium automation to upload to SleepHQ
	○ Unmount the SD card and alert me it is safe to remove?
• Send me a Text through Twilio/Make/IFFFT etc
	○ "CPAP Data - 2023-05-08
		 [y/n] copied off SD Card 
		 [y/n] saved to Dropbox 
         [y/n] uploaded successfully to SleepHQ"

Resources I borrowed from