Gateway API to fetch online status

“connected/not connected” is effectively a timeout value determined as some period from last “timestamp” when seen…most GW’s ‘update’ on 30sec interval timeline, others longer. Typically I find the Console can take anything from 2min to >30mins to ‘change’ to not connected if I shutdown or disconnect the netwroek connection…(similarly when coming back on line though I have seen it take many hiurs depending on Console Data Display scrape activity timing…

1 Like

For a modest investment, you could have a canary device that uplinks a small payload at what ever interval fits your downtime notification needs (but obviously respects the fair use policy).

By doing this, your gateway stats will tick up and the timestamp will be updated AND as a bonus, you can check the uplink has arrived at your application so you know that the gateway is alive & well and that the infrastructure is passing on messages.

But obviously, don’t hammer the gateway status.

What downtime can you cope with - I haven’t got anything running that couldn’t go a few hours without issues - maybe an irritating gap in data, but all alerts should have boundaries set - “hey, there may be a issue”, “ouch, that hurt” and “byeeeeeee” - which the server should also be able to extrapolate - and maybe one day, I’ll figure out enough ML to get it to auto-guess for me.

2 Likes

I’ve got into the habit of always installing such a canary typically 50-250m away from any new GW deployment if I can get a good site for just such a purpose - most on 20min update some longer/slower - critical application locations might be as low as 5mins - proximity means canary chirps on SF7 with no significant payload to worry about so its low time on air :slight_smile: (might send canary battery level but usually try for a powered location if poss). If I have to get closer to GW I set Tx power v low so as to minimise battery use and minimise near/far problems for remote sensors, as well as helping ensure GW is running with ability to pick up low sensitivity signals - have seen some GW’s in past go partially deaf - I suspect due to latent failure due to static damage or near miss with lightning strikes… Always keep canary at least 3m, pref >5m away from GW ant and behind an absorber if poss…

2 Likes

Hi All,

With the v2 → v3 in mind, I am trying to figure out how to retrieve that status of v3 gateways?
Currently I am using NodeRed (node-red-contrib-ttn module) to fetch v2 gateways.

Should we be using these to convert our checks, and what would be an example URL?
https://www.thethingsindustries.com/docs/reference/api/gateway/

I second this. Just migrated do v3 and my nodered status is not working.

This looks like the most likely candidate as a ‘web page’ type request:

https://www.thethingsindustries.com/docs/reference/api/gateway_server/

GET /api/v3/gs/gateways/{gateway_id}/connection/stats

Returns a packet that looks like this:

{
  "connected_at": "0001-01-01T00:00:00Z",
  "protocol": "",
  "last_status_received_at": "0001-01-01T00:00:00Z",
  "last_status": {},
  "last_uplink_received_at": "0001-01-01T00:00:00Z",
  "uplink_count": 0,
  "last_downlink_received_at": "0001-01-01T00:00:00Z",
  "downlink_count": 0,
  "round_trip_times": {},
  "sub_bands": [],
}
1 Like

Hello everybody
I could not find the https adress i have to use for the eu1 server?
With the http://noc.thethingsnetwork.org:8085… it does not work.
Thanks for your help!

If that is the url you used then not surprised it didn’t work, as incomplete. Also if/when you get the correct one you will see it is actually a V2 noc (as called out in the url) so won’t work with V3.

See also earlier post

All,

Getting a bit further on the URL.
In the below commands, replace ’ NNSXS.API_KEY ’ with your API key, and 1234567890 with your gateway ID.

Example v3 URL:

curl -i -H “Authorization: Bearer NNSXS.API_KEY” https://eu1.cloud.thethings.network/api/v3/gateways/eui-1234567890/rights

or

curl -i -H “Authorization: Bearer NNSXS.API_KEY” https://eu1.cloud.thethings.network/api/v3/gateways/eui-1234567890/api-keys

and

curl -i -H “Authorization: Bearer NNSXS.API_KEY” https://eu1.cloud.thethings.network/api/v3/gs/gateways/eui-1234567890/connection/stats

I do have the API key belonging to the specific gateway, and get the result (the GW is indeed offline)

{“code”:5,“message”:“error:pkg/gatewayserver:not_connected (gateway eui-0000024b080605f0@ttn not connected)”,“details”:[{“@type”:“type.googleapis.com/ttn.lorawan.v3.ErrorDetails",“namespace”:“pkg/gatewayserver”,“name”:“not_connected”,“message_format”:"gateway {gateway_uid} not connected”,“attributes”:{“gateway_uid”:“eui-0000024b080605f0@ttn”},“correlation_id”:“2b7bc0cc621440258c72834b9aa95941”,“cause”:{“namespace”:“pkg/redis”,“name”:“not_found”,“message_format”:“entity not found”,“code”:5},“code”:5}]}

Now need to test when the GW is online!

3 Likes

I can confirm the API works…nice!

gateway

I am still a bit puzzled by the ‘last_status_received’ element…
My GW is online, and the uplink/downlink counts show increasing but the timestamp on last_received_status is almost the same as the connected_at timestamp:

From node-red:

connected_at: "2021-02-16T13:13:42.432475261Z"
protocol: "ws"
last_status_received_at: "2021-02-16T13:13:42.465851358Z"
last_status: object
time: "2021-02-16T13:13:42.465716693Z"
boot_time: "0001-01-01T00:00:00Z"
versions: object
firmware: ""
package: ""
platform: "kerlink - Firmware  - Protocol 2"
station: "2.0.5(kerlink/std)"
advanced: object
features: "rmtsh"
model: "kerlink"
last_uplink_received_at: "2021-02-16T20:45:22.715022985Z"
uplink_count: "2395"
last_downlink_received_at: "2021-02-16T20:42:34.237813913Z"
downlink_count: "35"
sub_bands: array[6]

Should this last_status_received timestamp be recent?

As discussions evolve here we get more insights in to the infrastructure - to stop the database(s) melting, some data is cold - ie it’s not updated live - which makes sense.

The wording and the structures imply that the timestamp is when the gateway last sent a status message - the question being is, what is that status message!

@htdvisser, can you tell us how the last_status_received field is defined / updated please.

This depends on the type of gateway. The UDP packet forwarder, as well as the MQTT forwarder of The Things Kickstarter gateway regularly send status messages with information about the gateway. The Basic Station protocol doesn’t send regular status messages, and the only status we get is when it sends the station, firmware, package, model, protocol and features fields when it connects.

2 Likes

@ronnie_low_power, you’ll only get data in the last_status_received field if your gateway sends a status.

Hi Guys,

Many thanks for the clear feedback. It explains why there is a difference between de gateways. In my case I use the ‘Basic Station’.

As I am trying to monitor my gateways in a simple NodeRed flow, is there a query possible, which basically shows the same status, as is visible the new console?

In other words, where is the console Gateway status retrieved from, and can we do that via any API?

Many thanks for helping out!

Ron

The lack of status messages was opened on Basics Station Github back in November 2019. It includes a response “We have this feature on our roadmap and it will be included in future releases.”

@htdvisser you are a bit closer to the action, Any idea when that might occur?

Health Status Messages? · Issue #46 · lorabasics/basicstation (github.com)

That’s not up to him, it’s up to the people writing Basic Station, which could be you …

Reason for asking. I along with others have asked that question in the github issues and no response. Just wondered if htdvisser may have some idea. Not looking for any action on his part.

I would have a go but I’m not sufficiently versed in C to do this. I have looked a few times but could not figure out its architecture to understand how it would be added. I also came to the conclusion it’s not easy and the code may need some restructuring, otherwise it most likely would have already been done by now.

  • Lean Design
    - No external software dependencies (except mbedTLS and libloragw/-v2)
    - Portable C code, no C++, dependent only on GNU libc
    - Easily portable to Linux-based gateways and embedded systems

aka:

We kept things simple by omitting any design documentation and made all the filenames somewhat cryptic.

I think we can be almost 99.999% sure TTI have their hands full so any addition would be a community effort and it would be rather gateway specific as to what attributes it could send. It would certainly be nice to know if your gateway is cooking or has enough battery life when running on solar.

Maybe @Jeff-UK could make enquiries, particularly as he’s in to solar and a bit of status info may help him too.

1 Like

There are other software options available…