Created
April 22, 2016 07:38
-
-
Save CaffeinatedDave/cc6073cfbcc3ae4db13e442bdd293121 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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