-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.rb
More file actions
35 lines (27 loc) · 705 Bytes
/
web.rb
File metadata and controls
35 lines (27 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'sinatra'
require './degrib'
require 'json'
require 'serialport'
require 'zmq'
$stdout.sync = true
context = ZMQ::Context.new(1)
enable :sessions, :logging
get '/' do
erb :index
end
post '/wind' do
speed = Degrib.wind_speed(params[:position])
direction = Degrib.wind_direction(params[:position])
letters='abcdefghijklmnopqrs'
cmd = "#{letters[direction.round/20]}#{letters[speed.round]}"
puts "send '#{cmd}' to serial port via zmq for #{speed} knots @ #{direction}\n"
#zmq
outbound = context.socket(ZMQ::DOWNSTREAM)
outbound.connect("tcp://127.0.0.1:9000")
status = outbound.send(cmd)
content_type :json
{
speed: speed,
direction: direction
}.to_json
end