Page 1 of 1

Find out device's IP address, starting from DeviceName

Posted: Tuesday 08 October 2019 15:13
by midomot
Setup as example
A smart plug with Tasmota, fixed IP-address and Idx from Domoticz: plug is also created as a switch in Domoticz so has a device name and Idx
mqtt plugin is enabled (mosquitto). I can pilot the plug from domoticz, or by pushing the button on the plug itself
As it's wifi, things can go wrong, and domoticz might claim plug is on, but not in real life.. (and I have a dozen or so devices around the house)

I want to build a generic function that checks real status of a given "device name" by querying the device itself.
And then take appropriate action(s).

For this I need to know how to retrieve the IP-address of the plug itself (I'd rather not make a list of IPs)

The command for real status retrieval is simple: http://192.168.178.77/cm?&user=xxxx&pas ... mnd=Power1
and I can already parse the json output.

Problem: I know how to go from device name to device ID
but how to go from either of those to the IP-address ?
I searched but so far failed to see where in domoticz is the link between Idx and IP-address - I guess it's in the mqtt plugin

Thanks for reading, and for any help you could provide !

Re: Find out device's IP address, starting from DeviceName

Posted: Tuesday 08 October 2019 15:36
by waaren
midomot wrote: Tuesday 08 October 2019 15:13 How to go to the IP-address ?
I searched but so far failed to see where in domoticz is the link between Idx and IP-address - I guess it's in the mqtt plugin
I don't think you will find such a relation in domoticz or in the plugin. The way MQTT works is by using topics. The MQTT broker broadcasts (publish) information in topics. All listening (subscribed) systems interested in that topic can do what the want with the information in it.
So the Only IP known to all in this setup is the IP of the MQTT broker and the MQTT broker does know all IP addresses but I have not found an easy way to get that information from this broker.
You might get some extra information from site

Re: Find out device's IP address, starting from DeviceName

Posted: Tuesday 08 October 2019 16:21
by ben53252642
Set a static IP for the plugs MAC address at the DHCP level on your router.

Everytime the Plug connects to the network it will always get the same IP address.

Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.

Re: Find out device's IP address, starting from DeviceName

Posted: Tuesday 08 October 2019 17:51
by midomot
ben53252642 wrote: Tuesday 08 October 2019 16:21 Set a static IP for the plugs MAC address at the DHCP level on your router.

Every-time the Plug connects to the network it will always get the same IP address.

Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.
Hello
Thanks, I did always give static IP addresses to all my devices, on a range outside the modem's own DHCP range.

I would like the function to be for example CheckRealStatus(DeviceName,DesiredStatus)
and then the function would take care of finding out the IP, starting with DeviceName

So I'm trying to avoid having to maintain a table with pairs "domoticz device name | IP " or rather 'domoticz idx / IP" as domoticz name might change.

Seems like I'll have to build a table for my dozen devices - not too much work
The function would be CheckRealStatus(MyPlug,On), would go from MyPlug to Idx, lookup Idx in a table to find relevant IP, send the command to retrieve real status etc

Re: Find out device's IP address, starting from DeviceName

Posted: Tuesday 08 October 2019 19:43
by ben53252642
midomot wrote: Tuesday 08 October 2019 17:51
ben53252642 wrote: Tuesday 08 October 2019 16:21 Set a static IP for the plugs MAC address at the DHCP level on your router.

Every-time the Plug connects to the network it will always get the same IP address.

Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.
Hello
Thanks, I did always give static IP addresses to all my devices, on a range outside the modem's own DHCP range.

I would like the function to be for example CheckRealStatus(DeviceName,DesiredStatus)
and then the function would take care of finding out the IP, starting with DeviceName

So I'm trying to avoid having to maintain a table with pairs "domoticz device name | IP " or rather 'domoticz idx / IP" as domoticz name might change.

Seems like I'll have to build a table for my dozen devices - not too much work
The function would be CheckRealStatus(MyPlug,On), would go from MyPlug to Idx, lookup Idx in a table to find relevant IP, send the command to retrieve real status etc
You should never do this using network device names, many IoT devices are dumb enough to use the same name making the method unreliable.

The most reliable way is via the DHCP setting a static IP for the MAC address.

I know it's not ideal, I use pfSense as my gateway which has a pretty good user interface for managing all my static IP assignments.

Re: Find out device's IP address, starting from DeviceName

Posted: Wednesday 05 February 2020 19:46
by erem
on windows ping -a <ip-address> will resolve to the name thru reverse dns lookup

on *nix, host <ip-address> will resolve the ip address to a name.