Door lock script

require 'sps-sub'
require 'sps-pub'
require 'secret_knock'


sps = SPSSub.new host: '192.168.4.140'
pub = SPSPub.new address: '192.168.4.140'

class Notifier < SPSPub

  def initialize(host)
    super(address: host)
  end

  def knock()

    self.notice 'HumbleRPi/root/sol/output/led: 1 on duration 0.2'
  end

  def message(s)

    puts 'message : ' + s.inspect
    case s
    when ' '
      self.notice 'niko: door close' 
    when 'hi'      
      self.notice 'niko: door open' 
    else
      self.notice 'HumbleRPi/root/sol/output/led: 1 blink 0.04 0.07'
      sleep 0.7
      self.notice 'HumbleRPi/root/sol/output/led: 1 on'
    end
  end
end

notifier = Notifier.new '192.168.4.140'
sk = SecretKnock.new short_delay: 0.55, long_delay: 1.1, external: notifier, verbose: false

sk.detect

sps.subscribe topic: 'HumbleRPi/root/sol/button/0' do |x|

  sk.knock if x =~ /value 1/

end