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 Coverage Status 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/notecard 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

Linux and Raspberry Pi

# Use PySerial on a Linux desktop or Raspberry Pi
import serial
port = serial.Serial("/dev/serial0", 9600)

card = notecard.OpenSerial(port)

macOS and Windows

# Use PySerial on a desktop
import serial
#macOS
port = serial.Serial(port="/dev/tty.usbmodemNOTE1",
                     baudrate=9600)
# Windows
# port = serial.Serial(port="COM4",
#                     baudrate=9600)

card = notecard.OpenSerial(port)

I2C Configuration

# Use python-periphery on a Linux 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 Transaction on a Notecard object 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 method. 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.

Development Setup

If you're planning to contribute to this repo, please be sure to run the tests, linting and style checks before submitting a PR.

  1. Install Pipenv if you haven't already:

    pip install pipenv
    
  2. Clone the repository and install dependencies:

    git clone https://github.com/blues/note-python.git
    cd note-python
    pipenv install --dev
    
  3. Activate the virtual environment:

    pipenv shell
    
  4. Run the tests:

    make test
    
  5. Run linting and style checks:

    make precommit
    

Installing the pre-commit Hook

Please run

pre-commit install

Before committing to this repo. It will catch a lot of common errors that you can fix locally.

You may also run the pre-commit checks before committing with

pre-commit run

Note that pre-commit run only considers staged changes, so be sure all changes are staged before running this.

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-2.3.2.tar.gz (301.3 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-2.3.2-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file note_python-2.3.2.tar.gz.

File metadata

  • Download URL: note_python-2.3.2.tar.gz
  • Upload date:
  • Size: 301.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for note_python-2.3.2.tar.gz
Algorithm Hash digest
SHA256 a03ab0e7e08a235afc1bd0f2489a4a04d875905abd5807306863171f12413472
MD5 9b54fc10fdd0aabcdd8b8f9e2150ca6f
BLAKE2b-256 5eca8fd87fe9cf0ba144c405092c80006398226d2e7098d176c6225bc5a5e28c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: note_python-2.3.2-py3-none-any.whl
  • Upload date:
  • Size: 51.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for note_python-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6816e04e2c2ea947fdc09c3941b926346923a015ac4816daf4203763ba4f59a7
MD5 3c1f207436a23274fe4fd70cf9408dfd
BLAKE2b-256 745b7ab4165cb697c169c7032a8ff831530357c3499af7e1c5c954587cbdffa0

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