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.
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
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:
- Create a JSON object that adheres to the Notecard API
- Call
card.Transaction
,card.Request
orcard.RequestResponse
and pass in the request JSON object. - 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
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:
- note-c for Standard C support
- note-go for Go
- note-arduino for Arduino
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for note_python-1.4.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cd00405aa34658330f0b412e2afa96536d60bf1cc81f35946aa55943f0fdada |
|
MD5 | 37516dbc828bbb5fbb4dc0c6c70704a1 |
|
BLAKE2b-256 | 461152fcbaa07686aa3620679a780ebe0c5cae9a79b60b37060c0fafee3e7692 |