Class: HumbleRPiPluginNFC

Inherits:
Object
  • Object
show all
Defined in:
lib/humble_rpi-plugin-nfc.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings: {}, variables: {}) ⇒ HumbleRPiPluginNFC

Returns a new instance of HumbleRPiPluginNFC.



12
13
14
15
16
17
18
19
# 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

Instance Method Details

#startObject Also known as: on_start



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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