-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rough but working start to running on the pi
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|