From e9c1150f5761317535bc1893aae7a7354fb6a3b8 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Sat, 16 Feb 2019 20:39:24 +0000 Subject: Listen for MQTT --- scarecrow.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -- cgit v1.2.3