Last active
          January 11, 2022 11:49 
        
      - 
      
 - 
        
Save chendo/c4b8a28a244bd33d17778f61dfb189be to your computer and use it in GitHub Desktop.  
Revisions
- 
        
chendo revised this gist
Jan 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ begin IO.popen('raven') do |io| puts "Process started, connecting to MQTT server..." MQTT::Client.connect('mqtt://user:pass@host') do |c| puts "Connected to MQTT server."  - 
        
chendo revised this gist
Jan 11, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,4 +41,5 @@ $stderr.puts(ex.backtrace.join("\n")) $stderr.puts("Restarting...") sleep 2 retry end  - 
        
chendo revised this gist
Jan 11, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # License: Public domain # Depends on https://github.com/nonspecialist/pyraven being installed and accessible at `raven` require 'bundler/inline'  - 
        
chendo revised this gist
Jan 11, 2022 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,19 +15,24 @@ begin IO.popen('raven') do |io| puts "Process started, connecting to MQTT server" MQTT::Client.connect('mqtt://user:pass@host') do |c| puts "Connected to MQTT server." while line = io.gets do begin data = JSON.parse(line) if demand = data['raw_demand'] puts "#{Time.now.iso8601}\t Demand: #{demand}W" c.publish('energy/meter', demand) end rescue StandardError => ex $stderr.puts("Error publishing: #{ex}") end end end end rescue StandardError => ex  - 
        
chendo created this gist
Jan 11, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ # Depends on https://github.com/nonspecialist/pyraven being installed and accessible at `raven` require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'mqtt' end require 'json' require 'time' ENV['PYTHONUNBUFFERED'] = 'true' begin IO.popen('raven') do |io| puts "Process started, connecting to MQTT server" MQTT::Client.connect('mqtt://user:pass@host') do |c| puts "Connected to MQTT server." while line = io.gets do begin data = JSON.parse(line) if demand = data['raw_demand'] puts "#{Time.now.iso8601}\t Demand: #{demand}W" c.publish('energy/meter', demand) end rescue StandardError => ex $stderr.puts("Error publishing: #{ex}") end end end end rescue StandardError => ex $stderr.puts("Error: #{ex}") $stderr.puts(ex.backtrace.join("\n")) $stderr.puts("Restarting...") sleep 2 end