How to send a downlink to nodes via python and MQTT?

Hello,
I used example on TTN (https://www.thethingsnetwork.org/docs/applications/python/) to build a python SDK to send and receive message. I have successfully received uplink message and stored them. However, I had no idea about how to use codes in this website (https://www.thethingsnetwork.org/docs/applications/python/api-reference.html#send) especially the code following:

image

In addition, do I need this code to set? And how to use this?
image

1 Like

Hi Bismarck,

a) I had the same problem. I just resolved by sending the message in base64 instead of hexadeximal. This means: 0 is “AA==” and 1 is “AQ==”. I think there is some bug in TTN because I couldn’t send it with hexadecimal.

Now, the following script sends a downlink with value 1:

import ttn
app_id = "app_id_XX"
access_key = "access_key_XXX"
handler = ttn.HandlerClient(app_id, access_key)
mqtt_client = handler.data()
mqtt_client.connect()
mqtt_client.send(dev_id="dev_id_xxx",  pay= "AQ==", port=1, conf=True, sched="replace")
mqtt_client.close()

b) You don’t need to use “set_downlink_callback”.

Best regards,

Juan

1 Like

Thanks a lot! I have worked it out a few days ago. But your suggestion about not using “set_downlink_callback” is very useful.
By the way, have you figured out what is the function of “set_downlink_callback” ? Is it about ACK confirmed?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.