Express server intended to run on the 8 sleep pod.
- SSH into the Pod and run
fs-dev-server
# When you're done, undo this by CTR+C out of the npm run dev command & run:
systemctl start free-sleep
- Run the front-end app with hot reload and point it to your Pod app/README_APP.md
npm run dev:local
- I run this server on my Pod with hot reloading (see above)
- I have IntelliJ setup to auto upload my file changes to the Pod IntelliJ documentation for this config. VSCode also has a similar feature, I think this is the documentation for it VSCode
The server is composed of the following key components:
- Sets up and starts an Express.js server.
- Initializes middleware and routes.
- Manages graceful shutdown processes for reliability.
/api/deviceStatus: Fetches and updates the status of the device./api/settings: Manages device settings (e.g., timezone, away mode, priming schedules)./api/schedules: Handles scheduling for device operations./api/execute: Sends commands directly to the device./api/metrics/vitals: Biometrics (heart rate, HRV, breathing rate)/api/metrics/sleep: Sleep intervals
- Schedules periodic tasks like temperature adjustments, power on/off, and device priming using the
node-schedulelibrary. - Monitors changes to the DB storage files in
src/db/, clears all schedules and recreates them every time changes are made
- The JSON files are created the first time the server runs, you do not need to create them
- Uses
lowdbfor simple JSON-based storage. - Includes schemas for schedules, settings, and time zones, validated with
zod.
- Contains utilities to communicate with the "Franken" device using Unix sockets.
- This is based off of the EXISTING code on the pod in /home/dac/app/
- The server connects to the device using a Unix socket @
/deviceinfo/dac.sock(varies by Pod version & firmware version, path is detected in install.sh script and saved to/persistent/free-sleep-data/dac_sock_path.txt) - Commands are sent to the device for various operations, including temperature adjustments and status retrieval.
- Jobs like temperature changes, power toggling, and device priming are scheduled based on user-defined schedules.
- Changes to schedules or settings automatically trigger updates to the jobs
- Volta for node version control
- Clone the repository.
- Install dependencies:
npm install
- Build the project:
npm run build
- Start the server:
npm start
server/
├── free-sleep-data/ # For local development - mimics the /persistent/free-sleep-data/ folder on Pod
├── src/
│ ├── 8sleep/ # Integration with the "Franken" device
│ ├── db/ # JSON database and schemas
│ ├── jobs/ # Job scheduling utilities
│ ├── logger.ts # Logging configuration
│ ├── routes/ # API routes
│ ├── setup/ # Middleware and routes setup
│ ├── server.ts # Core server entry point
├── dist/ # Compiled output (generated by TypeScript)
├── tsconfig.json
├── package.json