LDAP and NFC Node-RED Nodes

About a week ago a colleague asked me to help resurrect some code I had written to use our work ID badges to look up information on the card owner in order to log into a system for a demonstration.

The ID badges are basically mifare cards so can be read by a NFC reader. The content of the cards is encrypted, but each card has a unique ID. Unfortunately the security team will not share the mapping of these IDs to actual people, but since this is for a demonstration that will only be given by a relatively small number of people it’s not a problem to set up a list of mappings our selves.

The original version of this code used nfc-eventd and some java code to the IDs then do a lookup in a little database to convert these to email addresses. It worked but was a bit of a pig to setup and move between machines as it required a number of different apps and config files so I decided to have a go at rewriting it all in Node-RED.


To do this I was going to need 2 new nodes, one to read the NFC card and one to look up details in the LDAP. Both of these actually proved reasonable easy and quick to write as there are existing Node NPM modules that do most of the heavy lifting. The flow has a couple of extra bit, it uses a mongodb to store the id to email address mappings and if there is no match it uses websockets to populate a field in a separate web page to enter a email address to update the database.


I did a first pass using the nfc npm and it worked but there was no way to shut the connection to the NFC reader down in the code which meant I couldn’t clean up properly when Node-RED shut down or when the node needed to be restarted.

The nfc on npmjs.org is actually a bit out of date compared to the git repository it’s hosted in. So I moved over to using the upstream version of the code. This changed the API a little and still didn’t have a mechanism to allow the interface to be stopped. I forked the project and after a little bit of playing I ended up with some working shutdown code.

The only call back is for when at NFC tag is detected and it polls in tight loop so the stream of data from the node is way too high to feed into a Node-RED flow really. The Node-RED wrapper rate limits to only reporting the same tag once every 10 seconds. This is good enough for the original problem I was looking to solve but I still think it can be done better. I’m planning on adding call backs for tag seen and when it is removed, this is similar to how nfc-eventd works. I also want to look at doing NDEF decoding.

You can install the current version of the node with:

npm install https://github.com/hardillb/node-red-contrib-nfc/archive/master.tar.gz

It depends on libnfc which should work on the Linux and OSx and I’ve even seen instructions to build it for Windows.
Once I’ve got a bit further I’ll add it to npmjs.org.


This one was even simpler. The LDAP npm modules links to the openldap libraries and does all the hard work.

It just needed a config dialog creating to take a base DN and a filter and a connection setup that takes a server, port and if needed a bind DN and password. The filter is a mustache template so values can be passed in.

This node is pretty much done, you can find the code on github here and the node can be installed with the following:

npm install node-red-node-ldap

Like with the NFC node, openldap should be available for Linux and OSx and there looks to be a Windows port.

12 thoughts on “LDAP and NFC Node-RED Nodes”

  1. Hey Ben,

    since i started with node red i follow your blog – its really great and you have done a lot of things i also try to realize.
    I have worked with nfc-eventd but its not really straight forward to make a query to a database or other user storage and you have to write some scripts and parse the nfcid as argument…
    Will you ever release the flow of this nfc ldap post? For sure without any userdata included if there are some….
    What kind of node is the one with the card2id card url? Is this the LDAP node? Do you send the nfcid with mqtt to the websocket?

    Thanks in advance !!!

    best regards

    1. Before I wrote the NFC node I used nfc-eventd and the mosquitto command line tools to publish the card id to a MQTT topic. Node-RED then subscribed to that topic and ran it through pretty much the same flow as above, just with a subscription node instead of the NFC node. So it can be done it’s just not as neat.

      The card2id node is a mongodb query node that does the mapping from the card id to an email address which is then used to do the LDAP lookup.

      I have to use the nfc-node for a project in the next week or two, when that is done I’ll probably have improved/tweaked some, I’ll stick it up on npm.

  2. Thank you for the reply,

    dont recognize it as mongodb was my fault.. :)

    Did you ran that node red instance with an raspberry? Currently nfc-eventd works great with my rpi but with your node i get the following message:

    15 Apr 06:01:17 - [info] Node-RED version: v0.10.6
    15 Apr 06:01:17 - [info] Node.js version: v0.10.36
    15 Apr 06:01:17 - [info] Loading palette nodes
    15 Apr 06:01:36 - [warn] ------------------------------------------
    15 Apr 06:01:36 - [warn] [arduino] Error: Cannot find module 'arduino-firmata'
    15 Apr 06:01:36 - [warn] [redisout] Error: Cannot find module 'redis'
    15 Apr 06:01:36 - [warn] [mongodb] Error: Cannot find module 'mongodb'
    15 Apr 06:01:36 - [warn] ------------------------------------------
    15 Apr 06:01:36 - [info] User Directory : /root/.node-red
    15 Apr 06:01:36 - [info] Flows file : /root/.node-red/flows_raspberrypi.json
    15 Apr 06:01:36 - [info] Server now running at
    15 Apr 06:01:37 - [info] Starting flows
    15 Apr 06:01:37 - [info] [nfc:nfc] foo
    15 Apr 06:01:37 - [error] [nfc:3bc71de9.c438e2] TypeError: Cannot call method 'on' of undefined

    Do you have any hints how to configure the PN532 Serial RFID reader with your node – imho that is the problem for the moment.

    This is my current nfc-eventd conf for the device

    device my_pn532_uart {
    driver = "PN532_UART";
    port = "/dev/ttyS0";
    speed = 115200;

    Maybe you find some time to give me a short feedback.

    kind regards

    1. I’ve not played with it since I wrote it and I’ve only ever used USB NFC readers. Do any of the other libnfc tools work e.g. nfc-poll? I have had it working on both Fedora 20 on my laptop and Raspbian in the past.

  3. Okay, found it – but any idea where i try to set up the serial reader? Is there a place to set up the reader used by the node nfc tools?

  4. Hi! This is a really cool use for NFC and thought I’d share a project I made that’s a stand-alone NFC reader that can talk over wifi: https://github.com/happy-bubbles/nfc

    It uses an ESP8266 chip and the cheap RC522 RFID modules. You can connect them together and then it’ll send the unique ID’s of the tags it reads as an HTTP POST.

    Maybe it’s useful for you.

  5. I get an error when trying to install on my Win 7 running Node.Js
    C:\Users\WIN_ADMIN>npm install https://github.com/hardillb/node-red-contrib-nfc/
    > node-gyp clean configure rebuild

    C:\Users\WIN_ADMIN\node_modules\node-red-contrib-nfc\node_modules\nfc>if not def
    ined npm_config_node_gyp (node “C:\Program Files\nodejs\node_modules\npm\bin\nod
    e-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js” clean configure rebuild
    ) else (node “” clean configure rebuild )
    Building the projects in this solution one at a time. To enable parallel build,
    please add the “/m” switch.
    ..\src\nfc.cc(2): fatal error C1083: Datei (Include) kann nicht geöffnet werden
    : “unistd.h”: No such file or directory [C:\Users\WIN_ADMIN\node_modules\node-r
    gyp ERR! build error
    gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` fail
    ed with exit code: 1
    … … …
    Any idea on what I need to do to get the “unistd.h” file?

  6. I now installed on Raspberry Pi – I’ve successfully installed ndef:
    nfc@0.1.0 node_modules/nfc
    └── ndef@0.0.4

    And my NFC Reader is also working:
    pi@raspi:~/libnfc/libnfc-1.7.1 $ sudo utils/nfc-list
    /home/pi/libnfc/libnfc-1.7.1/utils/.libs/lt-nfc-list uses libnfc 1.7.1
    NFC device: SCM Micro / SCL3711-NFC&RW opened
    1 ISO14443A passive target(s) found:
    ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00 04
    UID (NFCID1): 75 48 d1 65
    SAK (SEL_RES): 08

    However I do not see an NFC node in Node-Red, how can I incorporate now the NFC reader in a Node-Red flow?
    (your screenshot indicates a NFC Input Node that I’m missing)

    1. Are you running node red as root? This really isn’t the best place for this, post on the Node-RED mailing list or open a github issue rather than here

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>