Skip to content

Instantly share code, notes, and snippets.

@tahnok
Created August 2, 2012 01:11
Show Gist options
  • Save tahnok/3232179 to your computer and use it in GitHub Desktop.
Save tahnok/3232179 to your computer and use it in GitHub Desktop.
Dashboard demo 2: electric boogaloo
require 'serialport'
require 'faraday'
require 'json'
sp = SerialPort.new("/dev/tty.usbmodemfa131", 9600, 8, 1, SerialPort::NONE)
def post(widget, value)
Faraday.post("http://192.168.10.75:3000/widgets/#{widget}") do |req|
req.headers['Content-Type'] = 'application/json'
req.body = {auth_token: '60b3d4dd2194e29fa045736e76995cf6', value: value.to_i}.to_json.to_s
end
end
while true do
a = sp.readline
(one, two, three) = a.split(",")
post("dial_0", one)
post("dial_1", two)
post("dial_2", three)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment