Sending downlinks via TTS using a Python script

TTN version: TTNv3
Last updated: March 31, 2023

This article provides instructions for sending downlinks via TTS using a Python script. The payload is encoded in the Cayenne LPP format. For more information about our Cayenne LPP encoder in Python, see the Cayenne LPP encoder in Python tutorial.




Fair Use Policy

The TTN documentation says about Fair Use Policy:

On The Things Network’s public community network a Fair Use Policy applies which limits the uplink airtime to 30 seconds per day (24 hours) per node and the downlink messages to 10 messages per day (24 hours) per node. If you use a private network, these limits do not apply, but you still have to be compliant with the governmental and LoRaWAN limits.

Note: Don’t send more than 10 downlinks per day per node.


Python setup

  1. Download Python and install it.
  2. Open CMD/Terminal and type python3 --version.
  3. If the installation was successful, you will see the installed version of Python.


Python script

  1. Download as ZIP this Python script for sending downlinks via TTS.
  2. Extract all.
  3. Open the file in your favorite code editor.
  4. In the file, fill applicationName with the name of your application from TTS. The app name is in TTS -> Applications -> “YourAppName”.
  5. In the file, fill endDeviceName with the name of your end device from TTS. End device name is in TTS -> Applications -> YourAppName -> “YourEndDeviceName”.
  6. In the next steps, we will fill in the APIKey.


The Things Stack – API key

  1. In TTS -> Applications -> YourAppName -> API keys click button +Add API key.API key
  2. Write something in the Name.
  3. Select Grant individual rights.
  4. Check Write downlink application traffic.
  5. Click on button Create API key.API key
  6. Click the Copy to clipboard button and paste the key into the file as APIKey.


Sending a downlink

  1. Open the file in your favorite code editor.
  2. FPort, Confirmed downlink, Priority and Insert mode can be set in the Downlink Settings section.
  3. For example, uncomment line 27 to send the accelerometer data (or create your own data).Python Script
  4. Run script. (In CMD/Terminal navigate to directory with file and type python3
  5. In CMD/Terminal you should see this:
  6. In TTS -> Applications -> YourAppName -> YourEndDeviceName -> Live data you should see this:TTS Downlink
  7. (After sending the uplink and receiving the downlink by Feather, you should see the following in Arduino IDE Serial Monitor):Serial Monitor
Data types

All data types can be found in this table.