Skip to content

Commit

Permalink
Rough but working start to running on the pi
Browse files Browse the repository at this point in the history
  • Loading branch information
albus522 committed Mar 3, 2023
1 parent f1b7e8a commit d203c0f
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pi/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"
ruby "3.2.1"

gem "json"
gem "puma"
gem "rack"
23 changes: 23 additions & 0 deletions pi/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
GEM
remote: https://rubygems.org/
specs:
json (2.6.3)
nio4r (2.5.8)
puma (6.1.1)
nio4r (~> 2.0)
rack (3.0.4.2)

PLATFORMS
arm64-darwin-21
armv7l-linux-eabihf

DEPENDENCIES
json
puma
rack

RUBY VERSION
ruby 3.2.1p31

BUNDLED WITH
2.4.7
52 changes: 52 additions & 0 deletions pi/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "bundler/setup"

require "net/http"
require "json"

class StopLight
RED_LED = "16"
GREEN_LED = "14"
YELLOW_LED = "15"

def self.startup
File.write("/sys/class/gpio/export", RED_LED) unless File.exist?("/sys/class/gpio/gpio#{RED_LED}/value")
File.write("/sys/class/gpio/export", GREEN_LED) unless File.exist?("/sys/class/gpio/gpio#{GREEN_LED}/value")
File.write("/sys/class/gpio/export", YELLOW_LED) unless File.exist?("/sys/class/gpio/gpio#{YELLOW_LED}/value")

sleep 1

set_color(RED_LED, "1")
set_color(GREEN_LED, "1")
set_color(YELLOW_LED, "1")

sleep 1

set_color(RED_LED, "0")
set_color(GREEN_LED, "0")
set_color(YELLOW_LED, "0")
end

def self.set_colors(colors)
set_color(RED_LED, colors["red"] ? "1" : "0")
set_color(GREEN_LED, colors["green"] ? "1" : "0")
set_color(YELLOW_LED, colors["yellow"] ? "1" : "0")
end

def self.set_color(pin, value)
File.write("/sys/class/gpio/gpio#{pin}/value", value)
end
end

StopLight.startup

run do |env|
req = Rack::Request.new(env)
case req.path
when "/set-colors"
colors = JSON.parse(req.body.read)["colors"]
StopLight.set_colors(colors)
[200, {}, ["OK"]]
else
[404, {}, ["Not Found"]]
end
end
40 changes: 40 additions & 0 deletions pi/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
sudo apt update
sudo apt dist-upgrade
sudo reboot

sudo apt install libcurl4-openssl-dev git libreadline6-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf ncurses-dev automake libtool bison

wget https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.1.tar.gz
tar xzf ruby-3.2.1.tar.gz
ruby-3.2.1/
./configure --prefix=/usr/local --enable-shared --disable-install-doc
make -j 2
sudo make install

curl https://my.webhookrelay.com/webhookrelay/downloads/install-cli.sh | bash
vi relay_config.yml
```
version: "v1"
key: KEY_HERE
secret: SECRET_HERE
buckets:
- Buildlight
```
sudo relay service install -c /home/pi/relay_config.yml --user pi
sudo relay service start

mkdir app
copy config.ru Gemfile Gemfile.lock
bundle config set --local path 'vendor'
bundle install

# Setup puma to load via systemd
https://github.com/puma/puma/blob/master/docs/systemd.md

Change:
```
User=pi
WorkingDirectory=/home/pi/app
ExecStart=/usr/local/bin/bundle exec puma -p 8080 -v --redirect-stdout /home/pi/app/server.log
```

0 comments on commit d203c0f

Please sign in to comment.