ecosoph
(Markovicz)
1
Hi Guys,
I’m having good progress with the application APIs and the webhooks to onboard my sensors on my webinterface.
Now, I would like to move on to also include data of the gateway.
Unfortunately, this doesn’t seem to be as easy or well supported as the sensor nodes.
I would just like to receive basic data like last received, ontime, uplinks etc.
I have read the documentation for the gateway api
and from what I see, you can do an http get request:
HTTP bindings GET
/api/v3/gs/gateways/{gateway_id}/connection/stats
So I’ve tried the following python code snippet:
from requests.auth import HTTPBasicAuth
import requests
url = 'https://eu1.cloud.thethings.network/api/v3/gs/gateways/XXX/connection/stats'
headers = {'Accept': 'application/json'}
auth = HTTPBasicAuth('<apikey>', '<private pi key>')
req = requests.get(url, headers=headers, auth=auth)
print(req)
But I receive a 401 authentication failed error.
When I enter the url in my browser, I can see some information about my gateway:
descartes
(Nick McCloud)
2
This from @htdvisser may be relevant:
ecosoph
(Markovicz)
3
Sorry guys…
Here is the working solution, just put the api key in the header.
Reference: Using the API | The Things Stack for LoRaWAN
Minimum code example:
import requests
url = 'https://eu1.cloud.thethings.network/api/v3/gs/gateways/<gateway_id>/connection/stats'
headers = {'Authorization': 'Bearer NNSXS.XXX',
'Accept': 'application/json'}
req = requests.get(url, headers=headers)
print(req.json())
descartes
(Nick McCloud)
4
Opps, my bad, should have spotted the headers!
ecosoph
(Markovicz)
5
@descartes I just hope my newbish forum entries will help some other guys → eventually edit the topic name.
Anyways, another question: can you also receive GPS information for the gateway using the api?
descartes
(Nick McCloud)
6
We are all new to v3 and learning as we go. Topic name seems appropriate!
Not so much the GPS but the location set on the console if set to public.
It’s held in the Antenna section:
https://www.thethingsindustries.com/docs/reference/api/gateway/#message:GatewayAntenna