summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2019-02-16 20:39:24 +0000
committerJoe Robinson <joe@lc8n.com>2019-02-16 20:39:24 +0000
commite9c1150f5761317535bc1893aae7a7354fb6a3b8 (patch)
tree5e6707071089c67eab02a178d457cb064a7f6d12
parentf0d35d959c4daa8bd9f71ff4594326ae78ab92c4 (diff)
Listen for MQTT
-rw-r--r--scarecrow.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/scarecrow.rb b/scarecrow.rb
index a4a057b..ef3b694 100644
--- a/scarecrow.rb
+++ b/scarecrow.rb
@@ -4,6 +4,25 @@ require 'mqtt'
set :public_folder, File.dirname(__FILE__) + '/public'
set :bind, '::'
+def init
+ Thread.new do
+ MQTT::Client.connect('192.168.0.16') do |c|
+ c.get('humidity') do |topic,message|
+ puts "#{topic}: #{message}"
+ end
+ end
+ end
+ Thread.new do
+ MQTT::Client.connect('192.168.0.16') do |c|
+ c.get('temperature') do |topic,message|
+ puts "#{topic}: #{message}"
+ end
+ end
+ end
+end
+
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
+
+init