diff --git a/src/dashboards/chaosdorf.haml b/src/dashboards/chaosdorf.haml index 07c31dc..aba4097 100644 --- a/src/dashboards/chaosdorf.haml +++ b/src/dashboards/chaosdorf.haml @@ -14,7 +14,7 @@ .row %div{"data-id" => "downlink-traffic", "data-max" => "1000000000", "data-min" => "0", "data-title" => "Downlink Traffic", "data-view" => "Meter", "data-suffix" => "bit/s"} %div{"data-id" => "uplink-traffic", "data-max" => "50000000", "data-min" => "0", "data-title" => "Uplink Traffic", "data-view" => "Meter", "data-suffix" => "bit/s"} - %div{"data-id" => "power-total", "data-title" => "Power", "data-view" => "Graph", "data-suffix" => "W" } + %div{"data-id" => "lounge-co2", "data-title" => "CO2", "data-view" => "Graph", "data-suffix" => "ppm" } %div{"data-id" => "music", "data-header" => "now playing", "data-view" => "Music"} .row %div{"data-id" => "efa", "data-title" => "EFA: Kruppstr.", "data-view" => "Efa"} diff --git a/src/jobs/mqtt.rb b/src/jobs/mqtt.rb index d731e1e..f39ca71 100644 --- a/src/jobs/mqtt.rb +++ b/src/jobs/mqtt.rb @@ -1,6 +1,8 @@ require 'mqtt' +require 'json' power_series = Array.new(20).fill(0) +co2_series = Array.new(180).fill(0) music_status = {} last_music_update = Time.now last_dorfstatus = "unknown" @@ -16,30 +18,32 @@ client.connect() puts "mqtt: connected to #{client.host} as #{client.client_id}." - client.subscribe('sensors/flukso/power/sum/30s_average') # power + client.subscribe('sensor/esp8266_64760E/data') # hackcenter co2 sensor client.subscribe('space/dorfstatus') client.subscribe('space/bell') # door bell client.subscribe('music/#') # music client.get do |topic,message| message = message.force_encoding('utf-8') - if topic == 'sensors/flukso/power/sum/30s_average' + if topic == 'sensor/esp8266_64760E/data' ################################## - # P O W E R # + # C O 2 # ################################## - value = Float(message).round - power_series[0] = value - power_series.rotate! + # Hackcenter CO2 + data = JSON.parse(message) + value = Float(data["co2_ppm"]) + co2_series[0] = value + co2_series.rotate! case value - when 0..1500 + when 0...1000 status = "normal" - when 1500..3000 + when 1000...2000 status = "danger" else status = "warning" end - data = power_series.map.with_index{ |n,i| {"x" => -i, "y" => n} } - send_event('power-total', { points: data, status: status, moreinfo: "total power consumption" }) + data = co2_series.map.with_index { |n,i| {"x" => -i, "y" => n} } + send_event('lounge-co2', {points: data, status: status}) elsif topic == 'space/dorfstatus' ################################## # D O R F # @@ -64,7 +68,7 @@ SCHEDULER.in '1s' do send_event('music', music_status.clone) end - end + end end end client.disconnect() # TODO: does this make sense?