Skip to content

Instantly share code, notes, and snippets.

@CaffeinatedDave
Created April 22, 2016 07:38
Show Gist options
  • Save CaffeinatedDave/cc6073cfbcc3ae4db13e442bdd293121 to your computer and use it in GitHub Desktop.
Save CaffeinatedDave/cc6073cfbcc3ae4db13e442bdd293121 to your computer and use it in GitHub Desktop.
require "serialport"
require "net/http"
require "uri"
port_str = "/dev/tty.usbmodem1421"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
uri = "http://localhost:5000/"
#just read forever
while true do
while (i = sp.gets.chomp) do
important = i.split(",").take(3)
warn important.join(",")
if important[0].to_i == 0
send = URI.parse("#{uri}#{important[1]}")
http = Net::HTTP.new(send.host, send.port)
response = http.request(Net::HTTP::Get.new(send.request_uri))
warn response
elsif important[0].to_i == 200
send = URI.parse("#{uri}-1")
http = Net::HTTP.new(send.host, send.port)
response = http.request(Net::HTTP::Get.new(send.request_uri))
warn response
end
end
end
sp.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment