-
-
Save machinechat/0ede7e2b88f9c3cd1db7e4267da63c04 to your computer and use it in GitHub Desktop.
A custom action plugin for JEDI Pro to enqueue downlinks for the Plenum Kuando Busylight LoRaWAN via ChirpStack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Change the path above to where python3 is on system - use "which python3" to find out | |
# | |
# kuando-jedi-action.py - A custom action plugin for JEDI Pro to enqueue downlinks | |
# for the Plenum Kuando Busylight (LoRaWAN) via ChirpStack using their API: | |
# https://www.chirpstack.io/application-server/api/python-examples/ | |
# | |
# Pass red blue green on_time off_time hex parameters on command line from JEDI Pro per | |
# the spec sheet for Kuando Busy Light | |
# | |
# Example: "./kuando-jedi-action.py 0x00 0xff 0x00 0xff 0x00" | |
# Busylight will turn solid blue | |
# Example: "./kuando-jedi-action.py 0xff 0x00 0x00 0xff 0x00" | |
# Busylight will turn solid red | |
# | |
# This can also be run from the command line to test | |
# | |
# v0.1 DRM 04/10/2022 | |
# | |
# Depends on Python package: chirpstack_api | |
# Install: sudo python3 -m pip install chirpstack_api | |
# | |
# | |
import os | |
import sys | |
import grpc | |
from chirpstack_api.as_pb.external import api | |
# | |
# Kuando has the colors in a strange order: red blue green versus normal RGB | |
# | |
if len(sys.argv) != 6: | |
print("usage: %s red blue green on_time off_time" % sys.argv[0]) | |
print("example: %s 0x00 0xff 0x00 0xff 0x00" % sys.argv[0]) | |
sys.exit(1) | |
if (sys.argv[1].startswith("0x") and sys.argv[2].startswith("0x") and\ | |
sys.argv[3].startswith("0x") and sys.argv[4].startswith("0x") and\ | |
sys.argv[5].startswith("0x")): # base 16 | |
red = int(sys.argv[1],16) | |
blue = int(sys.argv[2],16) | |
green = int(sys.argv[3],16) | |
ont = int(sys.argv[4],16) | |
offt = int(sys.argv[5],16) | |
else: | |
print("usage: %s red blue green on_time off_time" % sys.argv[0]) | |
print("example: %s 0x00 0xff 0x00 0xff 0x00" % sys.argv[0]) | |
sys.exit(1) | |
#DEBUG | |
#print (red) | |
#print (blue) | |
#print (green) | |
#print (ont) | |
#print (offt) | |
# Configuration. | |
# | |
########## CHANGE THIS TO YOUR ENVIRONMENT | |
# | |
# This must point to the ChirpStack API interface. | |
server = "192.168.1.55:8080" | |
# | |
########## CHANGE THIS TO YOUR ENVIRONMENT | |
# | |
# The Kuando BusyLight DevEUI for which you want to enqueue the downlink. | |
dev_eui = bytes([0x20, 0x20, 0x20, 0x41, 0x28, 0x13, 0x05, 0x02]) | |
# | |
########## CHANGE THIS TO YOUR ENVIRONMENT | |
# | |
# The API token (generated using the ChirpStack web-interface). | |
# make sure to copy the key when it is displayed - it is hidden after leaving page | |
# and it is impossible to retrieve the key again. Have to create new one if that happens | |
# | |
api_token = "PutYourUniqueTokenHere" | |
if __name__ == "__main__": | |
# Connect without using TLS. | |
channel = grpc.insecure_channel(server) | |
# Device-queue API client. | |
client = api.DeviceQueueServiceStub(channel) | |
# Define the API key meta-data. | |
auth_token = [("authorization", "Bearer %s" % api_token)] | |
# Construct request. | |
req = api.EnqueueDeviceQueueItemRequest() | |
# Confirmed downlink | |
req.device_queue_item.confirmed = True | |
req.device_queue_item.data = bytes([red, blue, green, ont, offt]) | |
req.device_queue_item.dev_eui = dev_eui.hex() | |
# 15 for Kuando Busylight | |
req.device_queue_item.f_port = 15 | |
resp = client.Enqueue(req, metadata=auth_token) | |
# DEBUG | |
# Print the downlink frame-counter value. | |
#print(resp.f_cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment