class HumbleRPiPluginNFC

Public Class Methods

new(settings: {}, variables: {}) click to toggle source
# File lib/humble_rpi-plugin-nfc.rb, line 12
def initialize(settings: {}, variables: {})

  @notifier = variables[:notifier]
  @device_id = variables[:device_id] || 'pi'
  @readers = NFC::Reader.all
  @hashing = settings[:hashing] || true

end

Public Instance Methods

on_start()
Alias for: start
start() click to toggle source
# File lib/humble_rpi-plugin-nfc.rb, line 21
def start()
  
  notifier = @notifier
  device_id = @device_id
      
  puts 'ready to detect RFID tags'
  
  @readers[0].poll(Mifare::Classic::Tag, 
                   Mifare::Ultralight::Tag, IsoDep::Tag) do |tag|
    
    begin
      
      tag_id = @hashing ? (Digest::MD5.new << tag.to_s).to_s : tag
      notifier.notice "%s/nfc: detected %s" % [device_id, tag_id]

    rescue Exception => e
      p e
    end
    
    sleep 0.2
    
  end    
  
end
Also aliased as: on_start