Recently I had to do a few projects using The Things Network and its Cayenne Integration to quickly build some dashboard.
In order to use the integration, the packets must use the in the Low Power Payload format.
To facilitate that, I made a simple Python library (compatible with Micropython, Python 2 and 3) and thought I would share it with you since it could be useful to someone else. It is available on GitHub and via
pip install cayenneLPP .
The type of sensors compatible with this library are:
- digital input/output;
- analog input/output;
- luminosity (or illuminance) sensor;
- presence sensor;
- temperature sensor;
- humidity sensor;
- and gps.
Here is a small example of how it works with a LoPy from Pycom, using a LoRa socket to transmit the packet:
import socket # importing the module import cayenneLPP # create a LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setsockopt(socket.SOL_LORA, socket.SO_DR, 0) s.setblocking(True) # creating Cayenne LPP packet lpp = cayenneLPP.CayenneLPP(size = 100, sock = s) # adding 2 digital outputs, the first one uses the default channel lpp.add_digital_input(True) lpp.add_digital_input(False, channel = 112) # sending the packet via the socket lpp.send()
Hope it helps someone