led = LED.new
#AD
io = AnalogIO.new(A0, INPUT)
serv = TCPServer.open('192.168.0.0', 80)
buf_len = 32
temp = Array.new
#AD data
10.times do
temp << io.read
end
content = Array.new
#--------HTML --------------------
content[0] = "<html>"
content[0] += "<head>"
content[0] += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
content[0] += "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>"
content[0] += "<script type=\"text/javascript\">"
content[0] += " google.load('visualization', '1', {'packages':['corechart']}); "
content[0] += " google.setOnLoadCallback(drawChart);"
content[0] += " function drawChart() { "
content[0] += " var data = google.visualization.arrayToDataTable(["
content[0] += " ['秒数', 'AD値'],"
#-------------------
content[2] = " ]);"
content[2] += " var options = {"
content[2] += " title: 'アナログ値の推移'"
content[2] += " }; "
content[2] += " var chart = new google.visualization.LineChart(document.getElementById('chart_div'));"
content[2] += " chart.draw(data, options);"
content[2] += " }"
content[2] += "</script>"
content[2] += "</head>"
content[2] += "<body>"
content[2] += " <div id=\"chart_div\" style=\"width: 100%; height: 350px\"></div> "
content[2] += "<p>LED 点滅</p>"
content[2] += "<form action=\"index.html\" method=\"post\">"
content[2] += "<input type=\"radio\" name=\"LED\" value=\"A\" />ON "
content[2] += "<input type=\"radio\" name=\"LED\" value=\"B\" />OFF<br /><br />"
content[2] += "<input type=\"submit\" name=\"button\" value=\"送信\" />"
content[2] += "</form>"
content[5] = "</body>"
content[5] += "</html>"
led.off
content[3] = "LED消灯 <br />"
loop do
content[1] = ""
c = serv.accept
recv_text = nil
while (recv_text.nil?)
recv_text = c.recv(buf_len)
end
while (t = c.recv(buf_len))
recv_text += t
end
m = recv_text[recv_text.index("LED="),5]
if m=="LED=A" then
led.on
content[3] = "LED点灯 <br />"
end
if m=="LED=B" then
led.off
content[3] = "LED消灯 <br />"
end
ad = io.read
content[4] = " AD値=#{ad}"
temp.shift
temp << ad
counter = temp.size
temp.each do |t|
counter -= 1
content[1] += "['-#{counter}', #{t}],"
end
#responce
c.send "HTTP/1.0 200 OK\r\n"
c.send "Content-Length: #{content.join.length}\r\n"
c.send "Content-Type: text/html\r\n"
c.send "\r\n"
c.send content.join
c.close
#puts content.join
end
# serv.close