-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdht11.rb
58 lines (40 loc) · 1.11 KB
/
dht11.rb
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#cding: utf-8
require 'sinatra'
require 'json'
require 'redis'
set :environment, :production
set :port, 1234
get '/' do
erb :index
end
get '/test/:temperature' do
redis = Redis.new host:"127.0.0.1", port:"6379"
count = redis.llen "temperature"
redis.del "temperature" if count > 50
redis.rpush "temperature", "#{params[:temperature]}"
end
get '/rial' do
erb :dynamic
end
get '/temperature/:temperature/humidity/:humidity' do
redis = Redis.new host:"127.0.0.1", port:"6379"
redis.set "humidity", "#{params[:temperature]},#{params[:humidity]}"
redis.get "humidity"
end
get '/num' do
redis = Redis.new host:"127.0.0.1", port:"6379"
redis.get "humidity"
end
get '/temperature' do
redis = Redis.new host:"127.0.0.1", port:"6379"
temp = redis.lrange "temperature", 0, 50
temp.join(", ")
end
post '/', provides: :json do
p JSON.parse request.body.read
#@temperature = @temp.values
end
post '/temperature/*/humidity/*' do
array = params[:splat]
"{temperature: #{array[0]} humidity: #{array[1]}}"
end