Skip to content

Elixir library to work with the NXP PN532 RFID module

License

Notifications You must be signed in to change notification settings

dwyl/nerves_io_pn532

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nerves.IO.PN532

Hardware

Any PN532 board should work as long as it supports UART, I've been using the following board to develop.

Installation

This version is best pulled from git:

  1. Add nerves_io_pn532 to your list of dependencies in mix.exs:
def deps do
 [{:nerves_io_pn532, git: "https://github.com/dwyl/nerves_io_pn532"}]
end

How to use

defmodule MifareClientImplementation do
  use Nerves.IO.PN532.MifareClient

  def handle_event(:card_detected, card = %{tg: target_number, sens_res: sens_res, sel_res: sel_res, nfcid: identifier}) do
    Logger.info("Detected new Mifare card with ID: #{Base.encode16(identifier)}")
  end

  def handle_event(:card_lost, card = %{tg: target_number, sens_res: sens_res, sel_res: sel_res, nfcid: identifier}) do
    Logger.info("Lost connection with Mifare card with ID: #{Base.encode16(identifier)}")
  end
end
defmodule Example do
  def main do
    with {:ok, pid} <- MifareClientImplementation.start_link(),
         :ok <- MifareClientImplementation.open(pid, "COM3"),
         :ok <- MifareClientImplementation.start_target_detection(pid) do
      # ...
    end
  end
end

About

Elixir library to work with the NXP PN532 RFID module

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%