Git Product home page Git Product logo

sunrise-alarm's Introduction

Sunrise Alarm

DIY alarm clock Result Scheme

Local development

Dependencies:

  • NodeJS
  • Golang
  • ALSA dev library
    • Fedora: sudo dnf install alsa-lib-devel
  • GCC
    • Fedora: sudo dnf group install "C Development Tools and Libraries" "Development Tools"
# Update vendor libraries
./src/update_vendors.sh

# Change to source dir
cd src

# Auto-restart Sunrise Alarm on changes to the code
go install github.com/cespare/reflex@latest
reflex -s -G alarms.json go run ./cmd/

# OR ignoring "next-ring-time" calls
reflex -s -G alarms.json go run ./cmd/ 2>&1 | grep -v "next-ring-time"

NOTE: GUI optimized for Raspberry Pi Touch Display (800x480px)

Deployment

# Enable SSH access
sudo raspi-config

# Give GPU 256MB of memory
sudo raspi-config nonint do_memory_split 256

# Enable I2C (0 = enabled, 1 = disabled)
sudo raspi-config nonint do_i2c 0

# Disable swap
# Based on https://raspberrypi.stackexchange.com/questions/84390/how-to-permanently-disable-swap-on-raspbian-stretch-lite
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo systemctl disable dphys-swapfile
sudo update-rc.d dphys-swapfile remove
sudo apt purge dphys-swapfile

# Write all logs to RAM (will be exported anyway)
# Based on https://raspberrypi.stackexchange.com/questions/124605/stop-logs-from-writing-to-var-log
sudo tee -a /etc/fstab <<EOF
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0
EOF

# Export logs
RSYSLOG_SERVER='' # IP or hostname
sudo tee /etc/rsyslog.d/rsyslog-99-graylog.conf <<EOF
*.* @${RSYSLOG_SERVER:?}:1514;RSYSLOG_SyslogProtocol23Format
EOF
sudo systemctl restart rsyslog

# Upgrade system
sudo apt update
sudo apt dist-upgrade -y
sudo reboot # Needed for "Log to RAM" anyway

# Install dependencies
sudo apt install -y firefox-esr onboard libasound2-dev

# Install Go
# Update below to latest version at https://go.dev/dl/
# See https://go.dev/doc/install for official instructions
GO_URL="https://go.dev/dl/go1.20.3.linux-arm64.tar.gz"
wget -O go.linux-arm64.tar.gz "${GO_URL:?}"
sudo rm -rf /usr/local/go ~/go || true # Removes old install
sudo tar -C /usr/local -xzf go.linux-arm64.tar.gz
rm go.linux-arm64.tar.gz
sudo tee /etc/profile.d/add-go-to-path.sh <<EOF
export PATH=\$PATH:/usr/local/go/bin
export GOPATH=~/go
EOF
source /etc/profile.d/add-go-to-path.sh

# Clone this repo
git config --global pull.ff only
git clone https://github.com/JenswBE/sunrise-alarm
cd sunrise-alarm

# Setup Sunrise Alarm
# It's intended below variables are not escaped!
sudo mkdir -p /etc/systemd/system
sudo tee /etc/systemd/system/sunrise-alarm.service <<EOF
[Unit]
Description=Sunrise Alarm

[Service]
TimeoutSec=10min
WorkingDirectory=${HOME:?}/sunrise-alarm
Environment="GOPATH=${GOPATH:?}"
Environment="HOME=${HOME:?}"
Environment="PATH=${PATH:?}"
Environment="DEBUG=true"
ExecStartPre=-$(which git) config --global --add safe.directory ${HOME:?}/sunrise-alarm
ExecStartPre=-$(which git) pull
ExecStartPre=-$(which bash) src/update_vendors.sh
ExecStartPre=$(which bash) -c "cd src; go build -o ../sunrise-alarm ./cmd/"
ExecStart=${HOME:?}/sunrise-alarm/sunrise-alarm

[Install]
WantedBy=default.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now sunrise-alarm

# Configure screen timeout
mkdir -p ~/.config/autostart
tee ~/.config/autostart/screen-timeout.desktop <<EOF
[Desktop Entry]
Type=Application
Name=Set screen timeout
Exec=/usr/bin/xset dpms 60 60 60
EOF

# Run Ansible
cd deployment
ansible-playbook main.yml

# Reboot
sudo reboot

# Open GUI
xdg-open "http://localhost:8123"

sunrise-alarm's People

Contributors

jenswbe avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.