I have to ping every 5 - 10 second a device to see if it is online or offline (i don't know the ip)

Ok, the title may be confusing or not, but i have my PC that currently is in an appartment connected to the internet with a mobile router, so the IP is always changing, i've tried several methods, that kinda worked but not in the way i want.

This is my configuration:
I have on my synology NAS a docker with Node-Red on it that every 5 second makes a GET request to a specific service that is running on the PC in question.

I've tried using the teamviewer API to see wether the device is online or offline, but it updated my online status every 20 seconds circa (that's the time my pc in case of a short power outage needs to restart) so every time the pc shuts down for a second i see the status online and then the next request was made once the pc was already restarted, so useless.
I've tried with Steam API, but even when the pc was shut down the status was always Online.
I've tried ZeroTier API but it updates every 2-3 minutes, and that's too much.
I've tried with Spotify API but for a novice like me is a mess.

The question is do you know a program that i can run on my pc that is connected to a external server that can show me via some API the status of the said pc?

Thank You in advance.

Hi Manupaolas, can you explain what you mean by this?

Zerotier seems to be ideal for this situation, what is the problem with it?
Have you looked at Tailscale?

No, and I don't think I'd recommend it anyway. But since the PC and NAS are on the same network, why not get the PC to call a node-red http endpoint every 20 sec? You can use the Windows scheduler to run a command. Windows PowerShell can call an http endpoint or you can download a windows version of wget. Better still would be to create a service on the PC that runs as a service (there are tools that will convert executables to services). You could use node-red on the pc for that or you could use Python, etc.

I assumed they are not on the same LAN and it's the public IP address of the LAN with the PC which keeps changing.

Certainly my home network IP changes every few minutes using a mobile data network.*

I used to connect to my Raspberry Pies from the internet using PiVPN (Wireguard) but this is impossible with the mobile router, thus I switched to Zerotier.

  • In some ways this is a pain but a Huge Benefit is that every time I visit Google Maps or Amazon.co.uk it thinks I'm in a different location. :sunglasses: :ninja:

Another solution, assuming that the machine you are trying to ping is not on the same network, is to run node-red at both ends and communicate via to one of the free cloud mqtt brokers. The destination machine could publish something every few seconds and the master master machine can check that the messages keep coming through.

1 Like

Good point. In that case, get the PC to call one of the "whatsmyip" API's and pass the result to Node-RED directly :smiley:

Re free brokers. I find they have been known to also go offline. So adding another unreliable link on the chain would not be my preference.

1 Like

If there is no real value in the data sent, just a "heartbeat", I think test.mosquitto.org or broker.hivemq.com are good enough

1 Like

The fact is that i get the online state of a device in the network, but when i turn off the said PC ZeroTier updates the status only after 2-3 minutes, so if my pc has a power outage i will know only after 2-3 minutes.

Unfortunately they are not on the same network

I'm new to the subject, can you explain what a mqtt broker is?

If those are the MQTT broker they are talking about above i will look at those, maybe simultaneously so if one goes down the other will tell the state.

Stating that i don't know how they work or even what the are, you think there is any way to test even if a smartphone is online or not?

See MQTT Essentials - All Core Concepts explained

Does not the ping stop working immediately though?

OK so your PC and NAS are on different LANs. Therefore you need a VPN of some sort to connect them together.

You can use Zerotier for this. It sets up a private virtual LAN so for example the PC has IP address and the NAS has address
The changing public IP address [probably] doesn't matter because each device reaches out to Zerotier to join your virtual network.
You can configure it so that the traffic all goes via Zerotier, which might give faster response when the IP changes.

To monitor the connection, you can use MQTT. Cloud based services exist or I believe you can run your own Mosquitto broker on a Synology NAS. Another possibility is a Raspberry Pi (a Zero 2W is fine) running Node-red & mosquitto and connected to one or other LAN.
Let's say you need to know within 10 seconds of disconnection. So from the PC send an MQTT message every 2 seconds.
A device, could be the Raspberry Pi,"subscribes" to the messages. If no mesage is received for 10 seconds it alerts you.

ps If you have Node-red at both locations, you can send "heartbeats" over MQTT from each. That lets each location monitor the status of the other. You only need one MQTT broker.

Actually i've only used ZeroTier on the PC, on the NAS i was running a node red server that reaches out to the ZeroTier Servers to get the online status of the device.
The fact is that i wanted an external server to be the intermediary between my PC and my NAS.
I think MQTT will do the job, i'm trying it and i am starting to liking it.


I was not pinging it because ZeroTier is not installed on the NAS

Why not install it on the NAS ?

I am not really understanding what you are wanting to achieve as the end result here ?

Is your PC unreliable and hence needs to be rebooted ? If so this should be driven from the PC surely ?

Have it ping multiple devices - each one a step further away, local gateway, ISP DNS server, Google IP
Google DNS - if they all fail you have lost connection to the internet - force a reboot ?

So give us the real world problem you are trying to solve and then we will be able to give you more ideas ?

For instance a smart plug with Tasmota could ping the local IP of the PC and turn power off and on if it did not respond


1 Like

OK so your PC and NAS are on different LANs. Therefore you need a VPN of some sort to connect them together.

Uhm, this is what routers do, they "route" and connect/separate networks. If NAS is not aware of some IP/network, it sends it to the default gateway, which is usually a router, which in turn will figure it as those know what is reachable via what port and if they don't, you configure a static route.

I don't understand the problem as NAS and PC are both sitting behind "mobile router"? Or does PC get the public IP and the NAS something private ? If so, how did NAS get its IP ?

Do you mean that my statement is incorrect?
I'm prepared to believe it is, after all there is much that I don't undertand about networking in general and the OP's situation in particular.
It seems desirable to have a secure connection between the OP's PC and NAS. Does a Synology NAS provide such a connection over the web?

We know that the PC is connected to a mobile router. As I understand it that means it's using the mobile phone network to connect to the internet and such a setup cannot be contacted via a dynamic DNS service.

But I get the impression I'm barking up the wrong tree with this thread. Apologies if I've not helped.