Skip to content

jmerriweather/nerves_io_pn532

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 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.

NFC/RFID PN532 breakout Module

NFC/RFID PN532 breakout Module

Installation

If available in Hex, the package can be installed as:

  1. Add nerves_io_pn532 to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:nerves_io_pn532, "~> 0.1.0"}]
end
```
  1. Ensure nerves_io_pn532 is started before your application:
```elixir
def application do
  [applications: [:nerves_io_pn532]]
end
```

How to use

defmodule MifareClientImplementation do
  use Nerves.IO.PN532.MifareClient

  def 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 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