require 'sinatra' 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