I am attempting to follow the Python downlink queueing example here:
https://www.chirpstack.io/application-server/api/python-examples/
My server’s api page is accessible via:
https://redacted_server_name/api
(no special port needed)
The example shows how to queue a downlink assuming the example is ran on the same host instance as the server. I’m attempting to queue a downlink from a host external to the Chirpstack server.
So - I modified the example code as follows - I obviously redacted my server address and API key
import os
import sys
import grpc
from chirpstack_api.as_pb.external import api
# Configuration.
# This must point to the API interface.
server = "redacted_server_address"
# The DevEUI for which you want to enqueue the downlink.
# dev_eui = bytes([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])
dev_eui = bytes([0x00, 0x25, 0xca, 0x00, 0x00, 0x00, 0x01, 0xeb])
# The API token (retrieved using the web-interface).
api_token = "readacted API token"
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()
req.device_queue_item.confirmed = False
req.device_queue_item.data = bytes([2, 2, 20, 12, 2, 19, 33, 31])
req.device_queue_item.dev_eui = dev_eui.hex()
req.device_queue_item.f_port = 10
resp = client.Enqueue(req, metadata=auth_token)
# Print the downlink frame-counter value.
print(resp.f_cnt)
Attempting to execute the code fails:
ubuntu@ip-172-31-35-174:~$ python3 Chirp_Sender.py
Traceback (most recent call last):
File "Chirp_Sender.py", line 36, in <module>
resp = client.Enqueue(req, metadata=auth_token)
File "/home/ubuntu/.local/lib/python3.6/site-packages/grpc/_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/home/ubuntu/.local/lib/python3.6/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses"
debug_error_string = "{"created":"@1607197345.168422894","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4166,"referenced_errors":[{"created":"@1607197345.168419511","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}"
>
Has anyone been able to queue a downlink from Python?
Jim