TTN (http integration) to private server

Hi, I am trying to send data from TTN to my own server, and then save the data on my MySQL database. I’m fairly new at Python, and with HTTP, so for me there are some challenges.

What i’ve done so far:


HTTP INTEGRATION

Created http integration which looks like this:

Status: Running

16

[IP-ADDRESS] --> is the ip address of our server - xxx.xxx.xxx.xxx


SERVER (Python)

Created getData.py file, which looks like this:

import time
import ttn

app_id = "xxx"
access_key = "ttn-account-v2.x-xxx"

def uplink_callback(msg, client):
print("Received uplink from ", msg.dev_id)
print(msg)
handler = ttn.HandlerClient(app_id, access_key)

# using mqtt client
mqtt_client = handler.data()
mqtt_client.set_uplink_callback(uplink_callback)
mqtt_client.connect()
time.sleep(60)
mqtt_client.close()

# using application manager client
app_client = handler.application()
my_app = app_client.get()
print(my_app)
my_devices = app_client.devices()
print(my_devices)

When running the code above with this command:

sudo python getData.py

I receive this error:

  Traceback (most recent call last):
  File "getData.py", line 22, in <module>
    my_app = app_client.get()
  File "/home/xxx/.local/lib/python2.7/site-packages/ttn/application.py", line 64, in get
    " application: {}".format(err.code().name))
  RuntimeError: ('Error while getting the', ' application: PERMISSION_DENIED')

Why do I receive this error - permission denied? What am I doing wrong? Whenever this is fixed I can create code for inserting this data into the SQL database, but first of all I need this to work.


Hi @DTUIotLab, you appear to be mixing up the TTN HTTP and MQTT integrations.
Your TTN application integration is trying to post the uplink data using HTTP.
Your server-side code is trying to listen to the MQTT publish/subscribe system.
These are completely separate protocols for integration.

MQTT integration is enabled by default so if your python code is correct then this will work without any HTTP integration on the TTN servers.

I suggest that you start by following the TTN Quick Start at https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html

Get MQTT up and running using the quick start and then start to work on using python.

2 Likes

maybe this helps a bit

1 Like

Thanks, @cultsdotelecomatgmai & @BoRRoZ

I thought HTTP integration was the best solution to send data from TTN to my own server. For some reason, this code, for me, seemed to be one of the steps to do so.

I know of --> https://www.thethingsnetwork.org/docs/applications/http/ - but it makes no sense to me.

I will look into MQTT. Thanks both for responding!

I will try with node-red

Your code is not for HTTP integration :wink: