{"id":4034,"date":"2023-02-22T14:06:49","date_gmt":"2023-02-22T14:06:49","guid":{"rendered":"https:\/\/lora.vsb.cz\/?page_id=4034"},"modified":"2025-01-04T11:40:30","modified_gmt":"2025-01-04T11:40:30","slug":"sending-downlinks-via-tts-using-a-python-script","status":"publish","type":"page","link":"https:\/\/lora.vsb.cz\/index.php\/sending-downlinks-via-tts-using-a-python-script\/","title":{"rendered":"Sending downlinks via TTS using a Python script"},"content":{"rendered":"<table style=\"height: 66px;\" width=\"356\">\n<tbody>\n<tr>\n<td style=\"text-align: left; min-width: 100px;\" width=\"10%\"><strong>TTN version:<\/strong><\/td>\n<td><strong><span style=\"color: #008000;\">TTNv3 \/ TTS SANDBOX<\/span><\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left; min-width: 100px;\" width=\"10%\"><strong>Last revision:<\/strong><\/td>\n<td>December 14, 2024<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This article provides instructions for <strong>sending downlinks via TTS<\/strong> using a Python script. The payload is encoded in the <strong>Cayenne LPP<\/strong> format. For more information about our <strong>Cayenne LPP encoder in Python<\/strong>, see the <strong><a href=\"https:\/\/lora.vsb.cz\/index.php\/cayenne-lpp-encoder-in-python\/\" target=\"_blank\" rel=\"noopener\">Cayenne LPP encoder in Python<\/a><\/strong> tutorial.<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #189bd6;\"><strong>Prepare<\/strong><\/span><\/h2>\n<ul>\n<li>Computer<\/li>\n<li>Registered board in TTS with the ability to receive and decode Cayenne LPP format:\n<ul>\n<li>For <strong>Adafruit Feather M0 RFM95 LoRa Radio<\/strong>, you can follow this <a href=\"https:\/\/lora.vsb.cz\/index.php\/downlink-reception-and-cayenne-lpp-decoding\/\" target=\"_blank\" rel=\"noopener\"><strong>Downlink reception and Cayenne LPP decoding<\/strong><\/a> tutorial.<\/li>\n<li>For <strong>Seeeduino LoRaWAN<\/strong>, you can follow this <a href=\"https:\/\/lora.vsb.cz\/index.php\/868-mhz-seeeduino-downlink-reception-and-cayenne-lpp-decoding\" target=\"_blank\" rel=\"noopener\"><strong>868 MHz Seeeduino &#8211; Downlink reception and Cayenne LPP decoding\u00a0<\/strong><\/a> tutorial.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><strong><span style=\"color: #800000;\">Fair Use Policy<\/span><\/strong><\/h2>\n<h6><strong>The\u00a0<a href=\"https:\/\/www.thethingsnetwork.org\/docs\/lorawan\/duty-cycle\/#fair-use-policy\" target=\"_blank\" rel=\"noopener\">TTN documentation<\/a>\u00a0says about Fair Use Policy:<\/strong><\/h6>\n<p>On The Things Network\u2019s public community network a\u00a0<strong>Fair Use Policy<\/strong>\u00a0applies which limits the\u00a0uplink airtime\u00a0to\u00a030 seconds per day (24 hours) per node\u00a0and the\u00a0<strong>downlink messages<\/strong>\u00a0to\u00a0<strong>10 messages per day (24 hours) per node<\/strong>. If you use a private network, these limits do not apply, but you still have to be compliant with the governmental and LoRaWAN limits.<\/p>\n<p><span style=\"color: #ff0000;\">Note: Don\u2019t send more than 10 downlinks per day per node.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><strong><span style=\"color: #800000;\">Python setup<\/span><\/strong><\/h2>\n<ol>\n<li>Download <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noopener\"><strong>Python<\/strong><\/a> and install it.<\/li>\n<li>Open CMD\/Terminal and type <code>python3 --version<\/code>.<\/li>\n<li>If the installation was successful, you will see the installed version of Python.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2><strong><span style=\"color: #800000;\">Python script<\/span><\/strong><\/h2>\n<ol>\n<li>Download as ZIP this <strong><a href=\"https:\/\/github.com\/OndrejKnebl\/TTS_Downlinks_Python_Script\" target=\"_blank\" rel=\"noopener\">Python script for sending downlinks via TTS<\/a><\/strong>.<\/li>\n<li>Extract all.<\/li>\n<li>Open the <strong>config.py<\/strong> file in your favorite code editor.<\/li>\n<li>In the <strong>config.py<\/strong> file, fill <strong>applicationName<\/strong> with the name of your application from TTS. The app name is in <strong>TTS -&gt; Applications -&gt; &#8222;YourAppName&#8220;<\/strong>.<\/li>\n<li>In the <strong>config.py<\/strong> file, fill <strong>endDeviceName<\/strong> with the name of your end device from TTS. End device name is in <strong>TTS -&gt; Applications -&gt; YourAppName -&gt; &#8222;YourEndDeviceName&#8220;<\/strong>.<\/li>\n<li>In the next steps, we will fill in the <strong>APIKey<\/strong>.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2><strong><span style=\"color: #800000;\">The Things Stack &#8211; API key<\/span><\/strong><\/h2>\n<ol>\n<li>In <strong>TTS -&gt; Applications -&gt; YourAppName -&gt; API keys<\/strong>\u00a0click\u00a0button\u00a0<strong>+Add API key<\/strong>.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8418 \" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key.png\" alt=\"\" width=\"701\" height=\"301\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key.png 1198w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key-300x129.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key-1024x439.png 1024w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key-768x330.png 768w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/li>\n<li>Write something in the <strong>Name<\/strong>.<\/li>\n<li>Select <strong>Grant individual rights<\/strong>.<\/li>\n<li>Check <strong>Write downlink application traffic<\/strong>.<\/li>\n<li>Click on button <strong>Create API key<\/strong>.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8419 \" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key_write.png\" alt=\"\" width=\"501\" height=\"698\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key_write.png 711w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_api_key_write-215x300.png 215w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/li>\n<li>Click the <strong>Copy to clipboard<\/strong> button and paste the key into the <strong>config.py<\/strong> file as <strong>APIKey<\/strong>.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2><strong><span style=\"color: #800000;\">Sending a downlink<\/span><\/strong><\/h2>\n<ol>\n<li>Open the <strong>main.py<\/strong> file in your favorite code editor.<\/li>\n<li><strong>FPort<\/strong>, <strong>Confirmed downlink<\/strong>, <strong>Priority<\/strong> and <strong>Insert mode<\/strong> can be set in the <strong>Downlink Settings<\/strong> section.<\/li>\n<li>For example, uncomment line 27 to send the accelerometer data (or create your own data).<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4122 \" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Script.png\" alt=\"Python Script main.py\" width=\"649\" height=\"443\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Script.png 1045w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Script-300x205.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Script-1024x699.png 1024w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Script-768x524.png 768w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/li>\n<li>Run <strong>main.py<\/strong> script. (In CMD\/Terminal navigate to directory with main.py file and type <code>python3 main.py<\/code>).<\/li>\n<li>In <strong>CMD\/Terminal<\/strong> you should see this:<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4127 \" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/cmd.png\" alt=\"\" width=\"647\" height=\"103\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/cmd.png 1103w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/cmd-300x48.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/cmd-1024x162.png 1024w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/cmd-768x122.png 768w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/li>\n<li>In\u00a0<strong>TTS -&gt; Applications -&gt; YourAppName -&gt; YourEndDeviceName -&gt; Live data<\/strong>\u00a0you should see this:<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8421 \" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_live_data.png\" alt=\"\" width=\"650\" height=\"96\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_live_data.png 918w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_live_data-300x44.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2024\/12\/ttss_live_data-768x113.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/li>\n<li>(After sending the uplink and receiving the downlink by Feather, you should see the following in Arduino IDE <strong>Serial Monitor<\/strong>):<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4131 \" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Fether_Downlink.png\" alt=\"Serial Monitor\" width=\"650\" height=\"290\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Fether_Downlink.png 896w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Fether_Downlink-300x134.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2023\/02\/Fether_Downlink-768x343.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/li>\n<\/ol>\n<h5><strong>Data types<\/strong><\/h5>\n<p>All data types can be found in this\u00a0<strong><a href=\"https:\/\/github.com\/OndrejKnebl\/CayenneLPP#data-types-1\" target=\"_blank\" rel=\"noopener\">table<\/a><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TTN version: TTNv3 \/ TTS SANDBOX Last revision: December 14, 2024 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. &nbsp; Prepare Computer Registered [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4034","page","type-page","status-publish","hentry","post"],"_links":{"self":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/4034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/comments?post=4034"}],"version-history":[{"count":46,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/4034\/revisions"}],"predecessor-version":[{"id":8517,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/4034\/revisions\/8517"}],"wp:attachment":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/media?parent=4034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}