Skip to content

2. Setting up Nfcpyr

Roderick Gadellaa edited this page Dec 21, 2015 · 6 revisions

The basics

  • Download and copy the contents of the /python/nfcpyr folder to the raspberry
  • Copy nfcpyr.config.json and nfcpyr.users.json from 'data_examples' to 'data'
  • Edit the json files (see examples below)
  • Start nfcpyr by running 'python2 nfcpyr.py'
  • Repeat the steps for every raspberry/reader you want to set up

nfcpyr.config.json

Edit the contents of nfcpyr.config.json to suit your needs.

{

    # Id, user and pass are used to generate an apikey which identifies your 'group' of readers
    # These should be identical for every raspberry/reader you set up
    "nfcpyr_id":"YOUR_CUSTOM_ID", 
    "nfcpyr_user":"CUSTOM_USERNAME",
    "nfcpyr_pass":"CUSTOM_PASSWORD",
    
    # The url of the nfcpyr api. You can run it on your own server or use mine
    "url_nfcpyrapi":"http://www.rejh.nl/nfcpyr/api/?",
    
    # The configuration of this reader
    "reader":{
        "id":"nfcpi001", # a unique(!) id of this reader
        "name":"Livingroom", # a human-readable name for this reader
        "on_checkin":{
            "checkin":[], # list of ids that also should be checked in
            "checkout":[ # list of ids that should be checked out
                "nfcpi002" 
            ],
            "url_requests":[ # list of urls, also see 'Config: Url requests' chapter below
                "http://www.google.com"
            ],
            "plugins":[ # list of plugins that should be called
                "examplePlugin"
            ]
        },
        "on_checkout":{
            "checkin":[],
            "checkout":[],
            "url_requests":[]
            "plugins":[
                "examplePlugin"
            ]
        },
        "on_scan":{
            "checkin":[],
            "checkout":[],
            "url_requests":[]
            "plugins":[
                "examplePlugin"
            ]
        }
    },
    
    "sounds":{
        "enabled":true,
        "checkin":"sound/snd.beeps01.ogg",
        "checkout":"sound/snd.fail01.ogg"
    }
    
}

nfcpyr.users.json

Contains a list of user configs. A 'user entry' consists of a (unique!) username, human-readable name and a list of NFC tag id's that are associated with the user.

While every reader may have a nfcpyr.users.json file these do not have to incude all the users. At startup, Nfcpyr will update the users list with the centralized API. Do keep in mind that Nfcpyr only loads the user list at startup, updates and adds non-existing users and then loads the full updated list from the api. If you start another instance of Nfcpyr on another machine that adds users it will not be available on any readers that were started before it.

A more sophisticated way to manage users is being worked on but not available at this time.

{"coming":"soon"}

Config: Events

on_checkin

Everything that is executed when a user checks in

on_checkout

Everything that is executed when a user checks out

on_scan

Always executed whether a user checks in or out

Config: Url requests

General

The 'url_requests' field may contain a list of urls that are requested when the parent event is fired. For example, it can call some Rest API request on a remote server.

Keywords

There are certain keywords you can use in a url request field that will be replaced by Nfcpyr:

Keyword Description
##USER-USERNAME## Current user's username
##USER-FULLNAME## Current user's full name
##USER-EMAIL## Current user's email (if provided)
##READER-ID## Current reader's id
##READER-NAME## Current reader's name
##TIMESEC## Current time in seconds (int)
##TIMEMS## Current time in milliseconds (int)

Config: Plugins

General

Nfcpyr supports plugins, which are native python scripts that must implement a certain structure to be compatible. This enables users and other developers to extend on Nfcpyr's functionality without having to make changes in its code.

Adding an extension

Simply copy the plugin into the /nfcpyr/plugin folder and it will be imported on startup. Then add the name of the plugin (filename without the .py extension) in the plugins list of the event where you want it to be executed. A plugin should have a method for every Nfcpyr event (on_scan, on_checkin, etc) which will be called when the corresponding event is fired.

Building your own extension

See nfcpyr/plugins/examplePlugin.py for an example

..More coming soon...

Clone this wiki locally