Package: micropython-pycayennelpp
PyCayenneLPPA Cayenne Low Power Payload (CayenneLPP) decoder and encoder written in Python.PyCayenneLPP offers a concise interface with proper encoding and decoding
functionality for the CayenneLPP format, supporting many sensor types.
The project aims for overall high code quality and good test coverage.See alsomyDevicesIoT/CayenneLPPfor more information on the format and a reference implementation in C++.The project is under active development. Releases will be published on the
fly as soon as a certain number of new features and fixes have been made.Supported Data TypesThe following table lists the currently supported data types with the LPP code
(which equals IPSO code - 3200), data size in bytes, dimensions, signedness,
and data resolution.Type NameLPPSizeDimSignedResolutionDigital Input011False1Digital Output111False1Analog Input221True0.01Analog Output321True0.01Generic Sensor10041False1Illuminance10121False1 LuxPresence10211False1Temperature10321True0.1°CHumidity10411False0.5 %Accelerometer11363True0.001 GBarometer11521False0.1 hPaVoltage11621False0.01 VCurrent11721False0.001 AFrequency11841False1 HzPercentage12011False1 %Altitude12121True1 mLoad12231True0.001 kgConcentration12521False1Power12821False1Distance13041False0.001 kmEnergy13141False0.001 kJDirection13221False1 °Time13341False1 sGyrometer13463True0.01 °/sColour13533False1 RGBLocation13693True0.00001 lat0.00001 lon0.01 altSwitch14211False1 on/offGetting StartedPyCayenneLPP does not have any external dependencies and only uses builtin
functions and types of Python 3. It is compatible with all the latest and
officially supported Python versions 3.6 and above, though even Python 3.4
will do.Since PyCayenneLPP 1.2.0 MicroPython is officially supported, and published
as a separate package undermicropython-pycayennelpp.Python 3 PrerequisitesThe PyCayenneLPP package is available via PyPi usingpip. To install it run:pip3installpycayennelppMicroPython PrerequisitesUsing MicroPythonsupipmodule PyCayenneLPP can be installed as follows
within MicroPython:importupipupip.install("micropython-pycayennelpp")Or alternatively run with in a shell:micropython-mupipinstallmicropython-pycayennelppUsage ExamplesThe following show how to utilise PyCayenneLPP in your own application
to encode and decode data into and from CayenneLPP. The code snippets
work with standard Python 3 as well as MicroPython, assuming you have
installed the PyCayenneLPP package as shown above.EncodingfromcayennelppimportLppFrame# create empty frameframe=LppFrame()# add some sensor dataframe.add_temperature(0,-1.2)frame.add_humidity(6,34.5)# get byte buffer in CayenneLPP formatbuffer=bytes(frame)Note:MicroPython does not supportbytes(frame)utilising the internal
methodLppFrame.__bytes__(self)(yet).
Hence, you need to useLppFrame.to_bytes(self)instead.DecodingfromcayennelppimportLppFrame# byte buffer in CayenneLPP format with 1 data item# i.e. on channel 1, with a temperature of 25.5Cbuffer=bytearray([0x01,0x67,0x00,0xff])# create frame from bytesframe=LppFrame().from_bytes(buffer)# print the frame and its dataprint(frame)JSON EncodingThe LppUtil class provides helper function for proper JSON encoding of
PyCayenneLpp types, i.e. LppFrame, LppData and LppType.importjsonfromcayennelppimportLppFrame,LppUtil# create empty frameframe=LppFrame()# add some sensor dataframe.add_temperature(0,-1.2)frame.add_humidity(6,34.5)# json encodingprint(json.dumps(frame,default=LppUtil.json_encode,indent=2))There are two wrapper functions to explicitly encode the LPP type as a
number or string, number being default forLppUtil.json_encode(see above):# type as numberprint(json.dumps(frame,default=LppUtil.json_encode_type_int,indent=2))# type as stringprint(json.dumps(frame,default=LppUtil.json_encode_type_str,indent=2))ContributingContributing to a free open source software project can take place in many
different ways. Feel free to open issues and create pull requests to help
improving this project. Each pull request has to pass some automatic tests and
checks run by Travis-CI before being merged into the master branch.Please take note of thecontributing guidelinesand theCode of Conduct.LicenseThis is a free open source software project published under theMIT License.