Python API - downlink_callback


I am trying to write an application which checks for any uplinks and downlinks of one device.
I already tried the example code which was discussed in this topic

Furthermore I tried this code which is an adaption of the example code from here (

import time
import ttn

app_id = "xxx"
access_key = ""

def downlink_callback(msg, client):
  print("Downlink from ", msg.dev_id)

handler = ttn.HandlerClient(app_id, access_key)

# using mqtt client
mqtt_client =

# using application manager client
app_client =  handler.application()
my_app = app_client.get()
my_devices = app_client.devices()

I am not able to receive downlink data. Is there something wrong in my code?
For uplink_callbacks it is working.
Can anyone help?

The TTN library is been deprecated as per the third line with the warning symbol on the page you linked to and the world may have moved on. There are other examples in the forum that are more up to date.

There may be some confusion about which direction is which - uplinks come from the device to you - you send downlinks - so you won’t receive downlink data as such unless you are entering it in the web console or from another source.

Yes, I saw this, but I did not find another API to use for python.

If I am sending confirmed data, I receive a message from gateway after successfull transmission. I expected this to be an uplink which would be visible via MQTT. At least I see it on my gateway.

How about the mqtt api?

  1. Please don’t send confirmed data and if you need to keep within the allowed 10 ACKs per day for a device.
  2. It is not clear (to me) where you receive the data. If your node transmits (uplink) and you see data in the console you should see data on mqtt as well if subscribed to the right topic(s). At least that is what I’ve been seeing for the past 4+ years.

Yes, I tried it with this API, but still do not receive data about the downlink.
As already mentioned, I used the code from A Python program to listen to your devices with MQTT
Instead of looking for uplinks, I look for downlinks.


I am aware of this. I usually send uncnf, it was just a test to check if I am receiving anything execpt uplinks.

I am running a python script locally on a RPi and want to store uplink and downlink data to a csv. But I only get uplink data.

You’ll need +/devices/+/events/down/sent (or a broader wildcard, such as #).

Do yourself a favor for future debugging and store all events you can get through MQTT. Also, store the time, and the topic you’re getting it on:

1 Like

Tanks a lot! :innocent:
It is working with +/devices/+/events/down/sent
I will also include your advice for logging.
Happy that it is working :slight_smile: