Hello,
Is there an API to get my registered gateways data such as their status (connected or not) , their location and eventually their performance…
Thanks and best regards.
Hello,
Is there an API to get my registered gateways data such as their status (connected or not) , their location and eventually their performance…
Thanks and best regards.
Here is a API documentation: https://www.thethingsnetwork.org/docs/network/account/api.html#endpoints
But I can’t exchange access key for access token to use this API. So we can try to solve it together.
Update: I got access token. Here is a strategy to obtain access token:
Now I have a problem while requesting a list of gateways https://www.thethingsnetwork.org/docs/network/account/api.html#get-gateways
Response message:
{
“code”: 401,
“error”: “User MY_CLIENT_ID not found”
}
Does anyone know how to resolve this problem?
I’m rather interested if there is / will be a way to get stats of gateways using an API. The API there just has basic information including the location. However that API doesn’t seem to let you even see if it’s online.
Hi @Ryanteck, I use curl to the TTN NOC server to get realtime gateway status. The following is an example of me doing a curl to get status of one of my gateways about 10 minutes ago. I have re-formatted the JSON for readability.
[root@xxx]# curl http://noc.thethingsnetwork.org:8085/api/v2/gateways/eui-b827ebfffe031022
{
“timestamp”:“2018-03-14T09:00:00.701889865Z”,
“uplink”:“7974”,
“downlink”:“5”,
“location”:{“latitude”:57.124714,“longitude”:-2.164626,“source”:“REGISTRY”},
“platform”:“IMST + Rpi”,
“gps”:{“latitude”:57.124714,“longitude”:-2.164626,“source”:“REGISTRY”},
“time”:“1521018000701889865”,
“rx_ok”:7974,
“tx_in”:5
}
[root@xxx]#
The “timestamp” is, I think, when the gateway was last seen.
The access is open; no key, user/pwd, etc. needed.
Timestamp, counters, etc, match those on the TTN web console for the gateway.
I realise that curl isn’t really an API but you should be able to adapt this method for use from any platform.
That’s actually ideal for what I need. Thanks for the heads up!
I need to automatically register gateways on the TTN though Account Server API.
I got an access_token at this endpoint https://account.thethingsnetwork.org/api/v2/applications/token
Here is decrypted details of my JWT:
{
"sub": "dev_spd_rnd",
"iss": "ttn-account-v2",
"iat": 1521026647,
"client": "xelba-client5",
"scope": [
"apps:dev_spd_rnd"
],
"apps": {
"dev_spd_rnd": [
"devices",
"settings",
"messages:up:r",
"messages:down:w"
]
},
"interchangeable": false,
"exp": 1521030257
}
Here is example request to get a list of available gateways:
curl -X GET
https://account.thethingsnetwork.org/api/v2/gateways
-H ‘authorization: Bearer MY_ACCESS_TOKEN’
-H ‘cache-control: no-cache’
-H ‘content-type: application/json’
Response:
{
"code": 401,
"error": "User dev_spd_rnd not found"
}
What is the reason I can’t list gateways or register a new gateway over this API?
How to obtain access token with scope ‘apps’ and ‘gateways’?
Here is example cURL request:
curl -X POST \
https://account.thethingsnetwork.org/api/v2/applications/token \
-H 'authorization: Basic <MY_TOKEN>' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"username": "<MY_APP_ID>",
"password": "<MY_APP_ACCESS_KEY>",
"grant_type": "password"
}'
The token, which return by this request has only one scope:
"scope": [
"apps:<MY_APP_ID>"
]
But my Client has different scopes:
[apps gateways profile components]
How could I get access token with scope ‘apps’ and ‘gateways’?