Package: note-python
note-pythonPython 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.InstallationWithpipvia PyPi:pipinstallnote-pythonorpip3installnote-pythonFor use with MicroPython or CircuitPython, copy the contents of thenotecarddirectory into thelibdirectory of your device.UsageimportnotecardThenote-pythonlibrary 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 theexamplesdirectory for platform-specific guidance.Serial ConfigurationLinux and Raspberry Pi# Use PySerial on a Linux desktop or Raspberry Piimportserialport=serial.Serial("/dev/serial0",9600)card=notecard.OpenSerial(port)macOS and Windows# Use PySerial on a desktopimportserial#macOSport=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 PifromperipheryimportI2Cport=I2C("/dev/i2c-1")card=notecard.OpenI2C(port,0,0)Sending Notecard RequestsWhether using Serial or I2C, sending Notecard requests and reading responses
follows the same pattern:Create a JSON object that adheres to the Notecard API.CallTransactionon aNotecardobject 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 Notecardreq={"req":"note.add"}req["body"]={"temp":18.6}rsp=card.Transaction(req)print(rsp)# {"total":1}Using the Library Fluent APIThenotecardclass allows complete access to the Notecard API via manual JSON
object construction and theTransactionmethod. 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.Notethat not all aspects of
the Notecard API are available using these helpers. For a complete list of
supported helpers, visit theAPIdoc.Here's an example that uses thehubhelper to set the Notecard Product UID
in CircuitPython:importboardimportbusioimportnotecardfromnotecardimportcard,hub,noteport=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)# {}DocumentationThe documentation for this library can be foundhere.ExamplesTheexamplesdirectory contains examples for using this
library with:SerialI2CRaspberryPiCircuitPythonMicroPythonContributingWe love issues, fixes, and pull requests from everyone. By participating in
this project, you agree to abide by the Blues Inccode of conduct.For details on contributions we accept and the process for contributing, see
ourcontribution guide.Running the TestsIf you're planning to contribute to this repo, please be sure to run the tests
before submitting a PR. First run:pipinstall-rrequirements.txtThen, run the linter and tests using the includedMakefile.makeAlternatively, you can inspect the contents of theMakefileand runflake8andpytestdirectly. Be aware, however, that the commands in theMakefilerun against every pull request, so your best bet is to ensure these
tests are successful before submitting your PR.Installing thepre-commitHookPlease runpre-commit installBefore 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 withpre-commit runNote thatpre-commit runonly considers staged changes, so be sure all
changes are staged before running this.More InformationFor additional Notecard SDKs and Libraries, see:note-cfor Standard C supportnote-gofor Gonote-arduinofor ArduinoTo learn more about Blues Wireless, the Notecard and Notehub, see:blues.comnotehub.iowireless.devLicenseCopyright (c) 2019 Blues Inc. Released under the MIT license. SeeLICENSEfor details.