Download data using python

tropfen
Sun, 24 Dec 2023 06:56:30 +0000
How to get started

Hello,

i am new in the topic. i would like to download data from ttn (v3) via python. I have created an ApiKey and have tried the example code from descartes https://github.com/descartes/TheThingsStack-Integration-Starters/blob/main/MQTT-to-Tab-Python3/TTS.MQTT.Tab.py.

In principle, the program starts up well and generates the following output:

Imports:
Functions:
Body of program:
Init mqtt client
Assign callbacks
Connect

Log: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
Subscribe

Log: Sending SUBSCRIBE (d0, m1) [(b'#', 0)]
And run forever
.
Log: Received CONNACK (0, 0)

Connect: rc = 0
.
Log: Received SUBACK

Subscribe: 1 (0,)
......
Log: Sending PINGREQ
..
Log: Received PINGRESP

....
ERROR:root:Caught exception in on_message: 'data_rate_index'

Log: Received PUBLISH (d0, q0, r0, m0), 'v3xxxx@ttn/devices/xxxxx/up', ...  (1481 bytes)

Message: v3/xxx/devices/xxxx/up 0
{
    "end_device_ids": {
     xxxxxx
    },

    "received_at": "2023-12-24T06:29:44.829554629Z",
    "uplink_message": {
        "session_key_id": ".....",
        "f_port": 2,
        "f_cnt": 6064,
        "frm_payload": "......",
        "decoded_payload": {
            "Ext": 1,
            "Hum_SHT": 100,
            "Systimestamp": 1703399375,
            "TempC_DS": 327.67,
            "TempC_SHT": 7.46
   ... here is a lot more output but ...
    }
    }
}

Log: Caught exception in on_message: 'data_rate_index'

First:
what does both error messages / exceptiona are saying to me and how to solve it?

Second:
How can i get an array (time + values) of the decoded payload (eg TempC_SHT)?

Third:
i am not sure what to do with the following line

print(os.path.basename(__file__) + " " + VER)

do i have to exchange “file” to a self chosen filename?

Last:
the program is not producing an outputfile.

Can you help?

Thanks in advance
Frank

7 posts - 4 participants