What is the SmartThings hub's IP address?

I see st/driver.lua Driver:environment_info_handler saves this information in self.environment_info.hub_ipv4 and notifies self:lan_info_changed_handler with the address.

I set up my Driver with a lan_info_changed_handler.
It never gets called and self.environment_info.hub_ipv4 is not set.

I can see in the log that Driver:environment_info_handler is called with zigbee and zwave information

Received event with handler environment_info
Received event with handler environment_info
Z-Wave hub node ID environment changed.

… setting …

driver.environment_info.hub_zigbee_eui
driver.environment_info. hub_zwave_id

… but never

driver.environment_info.hub_ipv4

Certainly, the SmartThings hub has an IP address.
Why won’t it share it with me?

@nayelyz ?

Hi!

Does this mean you set a custom lan_info_changed_handler in the driver?

Yes, but it is never called and the log suggests that its caller is never called (this information is not fed to my driver over the environment channel).

Ok, I was able to replicate the issue with the value of driver.environment_info.hub_ipv4 being null.

The team mentioned this is a known issue that will be solved in a future release (there’s no ETA yet).
For now, the workaround is to create a UDP socket and query its name, which will more reliably provide the IP address. For example:

local function find_hub_ip(driver)
    --First check if the hub_ipv4 is known
    if driver.environment_info.hub_ipv4 then
        return driver.environment_info.hub_ipv4 
    end
    --If not, use this other method
    local s = cosock:udp()
    -- The IP address here doesn't seem to matter so long as it isn't '*'
    s:setpeername('192.168.0.0', 0)
    local localip, _, _ = s:getsockname()
    return localip
  end

… and

s:close()

Yes, it should be fixed but, I think, your workaround is better because

  1. It works even before this information would come over the environment channel.
  2. It works even outside the SmartThings hub environment, where …
  3. On multi-homed hosts, if setpeername uses the address of a potential peer, getsockname will return the address of the interface on the route to that peer (the address that peer can reach me at). Ultimately, that is what I want.

Thank you!

1 Like