Using gRPC API in python to get device data

Dear all,

I’m trying to create a python program to print my end device data via ChirpStack. I can see the uplink data from Application Server’s web interface (under the tab ‘device data’), but I’m not sure how to use the gRPC API for my python program to get the data.

My setting:
The end device is a Raspberry Pi 3 Model B+ with Dragino LoRa/GPS HAT.
The gateway is a Raspberry Pi 4 Model B with RAK 2245 Pi HAT.
The Network Server, Application Server, and my python program are all within one single PC running Ubuntu Linux.
The gateway communicates with the PC using ChirpStack’s built-in MQTT mosquitto broker, and on my PC I can use mosquitto_sub utility to receive device data.

For my external python program, I saw in the ChirpStack documentation that I may use the UplinkEvent protobuf message to receive device data :
https://www.chirpstack.io/application-server/integrate/sending-receiving/
but I’m not sure how to begin using that message in my python program,
as I looked at the integration.proto but there is no service definition in it:


I looked at the as.proto and there is an ApplicationServerService but it did not use UplinkEvent message:

I looked at the application.proto but also did not see where it uses the UplinkEvent message:

Any hint or example would be much appreciated!

Sincerely,
Chao

@cw86

Currently, there is an issue in chirpstack-api repo that exposes the use of python to grab information from the gRPC chirpstack api.

I’m not sure how long this will be ready in the official repository, however, you can start to take a closer look at. In other instance, you can check the javascript read documentation to have a feeling of how you would start to communicate with the api, it will be very similar in python.

That being said, you have another option and is using the HTTP integration. For that you will require to add the integration from the application server to the specific application you want to use. In python you must implement your endpoint that will then receive the data events.

Thanks for pointers, @sophiekovalevsky!
Now I see the issue and the on-going effort in the repo. I’ll begin by studying the javascript doc to learn the use of the API.

Thanks!
Chao

I just saw the python support updated in the chirpstack-api repo and the following: https://pypi.org/project/chirpstack-api/
Thanks for all the effort!

3 Likes

Hello Chao,

I am also working to use the ChirpStack API (python) to be able to receive device data.
In the solution you have build is the device data actually pushed to you?

If so would it be possble to share your code?

Thanks!

Hi DeBuffel,

I haven’t used the recent python support yet, because for our project’s current direction I need to build a C++ support for the ChirpStack API instead. Nevertheless, I think the procedure would be very similar: here are two examples, where the code can be found in the sub-folders here:

  1. exampleQuery: this one extends the python example (https://github.com/brocaar/chirpstack-api/tree/master/python/src), and make use of jwt token to query ChirpStack application information (applicadion id in this case).

  2. exampleStreaming: this one leverages a debugging feature (the StreamEventLogs rpc defined in service DeviceService in device.proto) to stream the events of the device with the given device EUI.

Our goal is to have a customized C++ application to receive event data and work with the application server, and the above code works for that purpose.

hope that helps,

Chao

2 Likes

Thanks Chao, that really helps me a lot. I also intend to use the StreamEventLogs rpc as defined in the device.proto.

Once I have the python examples working I will share it here.

Have a great w/e

1 Like

Hello. I have the same task. Have you found a solution? can you share the code?