git clone https://github.com/radiodan/provision
cd provision
sudo ./provision node
git fetch origin
git checkout -b minimal origin/minimal
sudo apt-get install libv8-dev -y
sudo ./provision iptables wifi-connect
sudo apt-get install supervisor -y
git clone https://github.com/njh/petey.git
cd
cd petey
sudo apt-get install ruby bundler pulseaudio pulseaudio-utils libssl-dev -y
source 'https://rubygems.org'
gem 'mqtt', '~>0.3.1'
gem 'pi_piper'
bundle install
#!/usr/bin/env ruby
require 'mqtt'
require 'io/console'
require 'pi_piper'
username = ENV['USER'] || 'anonymous'
client = MQTT::Client.connect('test.mosquitto.org')
def record_audio
IO.popen('parec --raw --format=alaw --channels=1 --rate=8000', 'rb') do |parec|
while_pressing_space
Process.kill('TERM', parec.pid)
parec.read
end
end
# Create a seperate thread, that deals with playing the audio
receive = Thread.new do
client.get('petey/+/audio') do |topic,message|
puts "Got audio from #{topic}."
IO.popen("runuser -l pi -c 'paplay --raw --format=alaw --channels=1 --rate=8000 /home/pi/petey/oink.alaw'", 'wb') do |paplay|
paplay.write(message)
end
end
end
listen = Thread.new do
puts "listen thread called"
PiPiper.watch :pin => 17,:trigger => :falling , :pull => :down do
puts "oink!"
client.publish("petey/#{username}/audio", File.read('/home/pi/petey/oink.alaw'))
end
PiPiper.wait
end
STDOUT.sync = true
puts "Welcome to Petey!"
loop do
end
client.disconnect
# run a petey instance
[program:petey]
command=/usr/bin/ruby /home/pi/petey/petey.rb
directory=/home/pi/petey
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=1
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=1
/etc/systemd/system/wifi-connect.service
/etc/hosts
/etc/hostname
connect to the wifi network (radiodan-configuration by default) tell it your wifi network click the button to oink