Git Product home page Git Product logo

ndeflib's Introduction

Python module for near field communication

Python Package Documentation CI Status Code Coverage

The nfcpy module implements NFC Forum specifications for wireless short-range data exchange with NFC devices and tags. It is written in Python and aims to provide an easy-to-use yet powerful framework for applications integrating NFC. The source code is licensed under the EUPL and hosted on GitHub. Release versions are published on PyPI for pip install -U nfcpy. Documentation for latest development and active release versions can be found on Read the Docs. The GitHub issues tracker is the place for bug reports or related questions. Other questions may have been or get answered on the project's Launchpad answers page or stackoverflow.

ndeflib's People

Contributors

nehpetsde avatar nickaknudson avatar te-stephentiedemann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ndeflib's Issues

parse wifi settings ndef record

How can I parse following wifi ndef record? I old library we could do it following manner
data = bytearray("\x10J\x00\x01\x10\x10\x0e\x002\x10&\x00\x01\x01\x10E\x00\x04Wxyz\x10\x03\x00\x02\x00\x01\x10\x0f\x00\x02\x00\x01\x10'\x00\x0bAbcdefg1234\x10 \x00\x06\xff\xff\xff\xff\xff\xff")
record = nfc.ndef.Record('application/vnd.wfa.wsc', '1', data)
print nfc.ndef.WifiConfigRecord(record).pretty()

Errors parameter for message_encoder() helper

In order to support strict error reporting for NDEF data encoding, ndeflib exposes two helper methods: message_decoder and message_encoder (see https://nfcpy.readthedocs.io/en/latest/modules/tag.html#nfc.tag.Tag.NDEF.records and https://ndeflib.readthedocs.io/en/stable/ndef.html#message-encoder) for more info.

In the docs, the example code is as follows:

from ndef import message_decoder, message_encoder
records = message_decoder(tag.ndef.octets, errors='strict')
octets = b''.join(message_encoder(records, errors='strict'))
tag.ndef.octets = octets

However, message_encoder does not accept the keyword arg errors. Thus I have a few questions for @nehpetsde:

  1. Should / can message_encoder accept this keyword argument? Has this just yet to be implemented?

  2. Should message_encoder not support this keyword argument? If so, what limitations are associated with encoding that would mean it is not possible to support this?

  3. In the meantime, would you like me to create pull request updating the docs?

Error output:

  File "tool.py", line 41, in <module>
    ret = clf.connect(rdwr=config)
  File "/usr/local/lib/python2.7/dist-packages/nfc/clf/__init__.py", line 580, in connect
    result = self._rdwr_connect(rdwr_options, terminate)
  File "/usr/local/lib/python2.7/dist-packages/nfc/clf/__init__.py", line 611, in _rdwr_connect
    if options['on-connect'](tag):
  File "tool.py", line 17, in on_connect
    octets = b''.join(message_encoder([rec], errors='strict'))
TypeError: message_encoder() got an unexpected keyword argument 'errors'

Platform:

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.50-v7+ #970 SMP Mon Feb 20 19:18:29 GMT 2017 armv7l GNU/Linux

pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"

Lib version:

pi@raspberrypi:~$ pip freeze
# ommited
ndeflib==0.2.0
nfcpy==0.13.2

Python version:

pi@raspberrypi:~ $ python --version
Python 2.7.9

Feature request: Support for concatenation of encoder output

I've used ndeflib in a simple tool but ran into a problem that I hadn't expected; the message_encoder cannot be told to refrain from setting MB and ME flags. Since I wanted to concatenate individually generated outputs, this means I need to change this after encoding.

One way of doing this generically is to have an ndef_concat() function that removes MB from all but the first, and ME from all but the last. Another, much simpler way would be extra function options

def message_encoder (..., first=True, last=True):

that need to be set to False to overrule the current / default behaviour of generating MB and ME on the first and last records.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.