Save payload on computer using python

if you want to save the message recently received to the uplink in your application using python so juste try this example in python it works perfectly.

import time
**import ttn # library contient les modules de ttn pour faire la connection **

**app_id = “” # identifiant de l’application **
access_key = “” # la cle d’entree de l’application

def uplink_callback(msg, client): # fonction qui fait l’affiche de message **
** print("Received uplink from ", msg.dev_id)

** #print(msg)**
** #print("####################################")**
** #print(msg.payload_fields.message)**
** sms=str(msg.payload_fields.message)**
** print(sms)**
** f=open(“xxx.txt”,“a+”)**
** f.write(sms+"\n")**
** f.close()**

**handler = ttn.HandlerClient(app_id, access_key) # on **

# using mqtt client
mqtt_client = handler.data()
mqtt_client.set_uplink_callback(uplink_callback)
mqtt_client.connect()
**time.sleep(700) # you can set the time as you like here 700 s **
mqtt_client.close()

so once you did run for this script , it will wait for 700 s , while there are new message received to uplink it will save it in the file named xxx and it will appear in the console also, you can set the time as you like but be sure that the message will come within (here 700s) to be able to catch it.
if your computer is connected on wifi which use proxy or something like that so maybe you will see an error like timeout or cannot built a gateway with the channel so try to connect on another connection then it will work fine.
this link below it will be useful:

https://www.thethingsnetwork.org/docs/applications/python/

good luck