summaryrefslogtreecommitdiff
path: root/scarecrow.rb
diff options
context:
space:
mode:
Diffstat (limited to 'scarecrow.rb')
-rw-r--r--scarecrow.rb20
1 files changed, 8 insertions, 12 deletions
diff --git a/scarecrow.rb b/scarecrow.rb
index bd5509f..793f5de 100644
--- a/scarecrow.rb
+++ b/scarecrow.rb
@@ -1,5 +1,5 @@
require 'sinatra'
-require 'mqtt'
+require 'paho-mqtt'
require 'sqlite3'
require 'date'
require 'dm-core'
@@ -43,15 +43,11 @@ def init
DataMapper.auto_upgrade!
# sleep 10
Thread.new do
- MQTT::Client.connect('192.168.0.59') do |c|
- c.subscribe('+/temperature', '+/humidity', '+/moisture')
- loop do
- while !c.queue_empty? do
- topic, message = c.get
- handle_msg(topic, message)
- end
- sleep 1
- end
+ mqtt_client = PahoMqtt::Client.new
+ mqtt_client.connect('192.168.0.59', 1883, mqtt_client.keep_alive, true, mqtt_client.blocking)
+ mqtt_client.subscribe('+/temperature', '+/humidity', '+/moisture')
+ mqtt_client.on_message do |m|
+ handle_msg(m.topic, m.payload)
end
end
end
@@ -106,7 +102,7 @@ def get_value(type, device_id)
value = entry[:value]
end
- return value
+ return value
end
def get_time(type, device_id)
@@ -124,7 +120,7 @@ def get_time(type, device_id)
value = entry[:timestamp]
end
- return value
+ return value
end
get '/' do