Skip to main content

Cross-platform Python Library for the Blues Wireless Notecard,

Project description

note-python

Python library for communicating with the Blues Wireless Notecard over serial or I²C.

Build Python Version Support PyPi Version Wheel Support

This library allows you to control a Notecard by coding in Python and works in a desktop setting, on Single-Board Computers like the Raspberry Pi, and on Microcontrollers with MicroPython or CircuitPython support.

Installation

With pip via PyPi:

pip install note-python

or

pip3 install note-python

For use with MicroPython or CircuitPython, copy the contents of the notecard directory into the lib directory of your device.

Usage

import notecard

The note-python library requires a pointer to a serial or i2c object that you initialize and pass into the library. This object differs based on platform, so consult the examples directory for platform-specific guidance.

Serial Configuration

# Use python-periphery on a desktop or Raspberry Pi 
from periphery import Serial
port = Serial("/dev/serial0", 9600)

card = notecard.OpenSerial(port)

I2C Configuration

# Use python-periphery on a desktop or Raspberry Pi 
from periphery import I2C
port = I2C("/dev/i2c-1")

card = notecard.OpenI2C(port, 0, 0)

Sending Notecard Requests

Whether using Serial or I2C, sending Notecard requests and reading responses follows the same pattern:

  1. Create a JSON object that adheres to the Notecard API
  2. Call card.Transaction, card.Request or card.RequestResponse and pass in the request JSON object.
  3. Make sure the response contains the data you need
# Construct a JSON Object to add a Note to the Notecard
req = {"req": "note.add"}
req["body"] = {"temp": 18.6}

rsp = card.Transaction(req)
print(rsp) # {"total":1}

Using the Library Fluent API

The notecard class allows complete access to the Notecard API via manual JSON object construction and the Transaction, Request, and RequestResponse methods. Alternatively, you can import one or more Fluent API helpers to work with common aspects of the Notecard API without having to author JSON objects, by hand. Note that not all aspects of the Notecard API are available using these helpers. For a complete list of supported helpers, visit the API doc.

Here's an example that uses the hub helper to set the Notecard Product UID in CircuitPython:

import board
import busio

import notecard
from notecard import card, hub, note

port = busio.I2C(board.SCL, board.SDA)
nCard = notecard.OpenI2C(port, 0, 0, debug=True)

productUID = "com.blues.brandon.tester"
rsp = hub.set(nCard, productUID, mode="continuous", sync=True)

print(rsp) # {}

Documentation

The documentation for this library can be found here.

Examples

The examples directory contains examples for using this library with:

Contributing

We love issues, fixes, and pull requests from everyone. By participating in this project, you agree to abide by the Blues Inc code of conduct.

For details on contributions we accept and the process for contributing, see our contribution guide.

Running the Tests

If you're planning to contribute to this repo, please be sure to run the tests before submitting a PR. First run:

pip install -r requirements.txt

Then, run the linter and tests using the included MAKEFILE.

make -f MAKEFILE

Alternatively, you can inspect the contents of the MAKEFILE and run flake8 and pytest directly. Be aware, however, that the commands in the MAKEFILE run against every pull request, so your best bet is to ensure these tests are successful before submitting your PR.

More Information

For additional Notecard SDKs and Libraries, see:

To learn more about Blues Wireless, the Notecard and Notehub, see:

License

Copyright (c) 2019 Blues Inc. Released under the MIT license. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

note-python-1.3.5.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

note_python-1.3.5-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file note-python-1.3.5.tar.gz.

File metadata

  • Download URL: note-python-1.3.5.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for note-python-1.3.5.tar.gz
Algorithm Hash digest
SHA256 fec2eba7e4e3ef3fc13c2953bfd5790023bbbd31e01b1dc9d21765114d9ea39d
MD5 8a713a6c0c305e1f3a8e2843db51720c
BLAKE2b-256 13d8a74666d2a60d310a7cd467b137a7aa824695f96d7c0329f28f187cd7a9a1

See more details on using hashes here.

File details

Details for the file note_python-1.3.5-py3-none-any.whl.

File metadata

  • Download URL: note_python-1.3.5-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for note_python-1.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6c18e369ffcdaa5ef54a6409c7401f9abdb43aff18fe2a1b7522bd62d75ae2e3
MD5 442610bd5ed792232ba70c5cfecb0980
BLAKE2b-256 36fdb3c95152e2f7787b070bb54004196c18025737da00616e7b2adb0b857290

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page