Luup Plugin - External IP

Hi

Sharing another one of my Vera Luup plugins, this one is pretty straight forward, it just records your external IP address. (Which you can then watch, to see if/when it changes )

Here’s a quick screenshot of the device (with a dummy/example IP) …

2 Likes

Great to see someone developing plugins for Vera firmware hubs, keep up the good work!

Will you be looking at Ezlo’s plugin framework they just released for their new Ezlo hubs?

Regarding the WAN IP, I did a similar thing using Multi System Reactor (MSR) , a rule sends a http request to a public json end point that returns your current WAN IP, that then gets stored in a variable in MSR.
The rule then sends the IP address value to a Multi String plugin device on my Vera, which is then used to display the current IP address on a tile in the Home Remote dashboard.

I have another rule that monitors that IP address and alerts me with a notification if it changes.

I wonder with your plugin, can you send a http request into Vera to obtain the IP address value? Using a variable get http request into Vera etc.

Hi @cw-kid

Not sure what I’m going to do next to be honest, it’s taken me over a decade to just get one plugin working well, as I had absolutely no coding experience when I started out with Vera, but over time a little bit here and there of Lua, and I’m riding a bit of a wave at the moment, so will be sharing a few more soon

As for the ezlo framework, I’ve not looked at it in any great detail, it’ll all depend if I decide to go that route really. Vera (luup) and OpenLuup are my focus at the moment.

Regarding your question below…

Do you mean your internal (local) IP address e.g 192.168.x.xxx ?

With os.execute or io.popen you can call any command line commands you want and then process the response.

Your doing much better than me at coding and plugins that’s for sure!

I meant the WAN IP that your plugin obtains and stores in a variable.

Was wondering if there might be some way to send a http request say from MSR, to Vera to get that current IP address value etc.

I might install your plugin on my test Vera Edge box and have a play around with it.

Thanks.

Yes please, have a play with it :slight_smile:

Regarding MSR , can’t that just retrieve the IP address from the variable that this plugin creates on your Vera ? No need to make any other http calls

1 Like

Possible if MSR supports the Vera plugin. I think Patrick has to do a bit of coding for each Vera plugin we would like to work in MSR. I will maybe ask him.

I’ve got the plugin installed, its not updated the IP address yet however.

image

I installed all these files:

image

These are the variable on the plugin

image

These are the Params


image

How often will the plugin check what is the current WAN IP ?

Looking in the log:

01/07/22 17:09:51.493	luup_log:162: ExternalIP: Plugin STARTING-UP! <0x76bc3520>
06	01/07/22 17:09:51.501	Device_Variable::m_szValue_set device: 18 service: urn:rboer-com:serviceId:Harmony1 variable: IconSet was: 2 now: 1 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x759c3520>
06	01/07/22 17:09:51.502	Device_Variable::m_szValue_set device: 18 service: urn:rboer-com:serviceId:Harmony1 variable: IconSet was: 1 now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x759c3520>
06	01/07/22 17:09:51.503	Device_Variable::m_szValue_set device: 18 service: urn:rboer-com:serviceId:Harmony1 variable: LinkStatus was: Starting... now: Ok #hooks: 0 upnp: 0 skip: 0 v:0xe4d650/NONE duplicate:0 <0x759c3520>
50	01/07/22 17:09:51.507	luup_log:162: ExtIP: Setting up plugin.... DevNo = 162 <0x76bc3520>
06	01/07/22 17:09:51.508	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Icon was: EMPTY now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.508	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: PluginVersion was: EMPTY now: 0.1 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.509	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: PluginStatus was: EMPTY now: Plugin being installed 1/2  #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
50	01/07/22 17:09:51.510	luup_log:162: ExtIP: Setting up plugins variables for ... DevNo = 162 <0x76bc3520>
06	01/07/22 17:09:51.510	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: PluginStatus was: Plugin being installed 1/2  now: Plugin variables being set up 2/2 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.511	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Current External IP was: EMPTY now: 0.0.0.0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.512	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Previous External IP was: EMPTY now: 0.0.0.0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.512	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Last Changed was: EMPTY now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.513	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Last Changed HR was: EMPTY now: Date #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.514	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Last Checked was: EMPTY now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
06	01/07/22 17:09:51.514	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Last Checked HR was: EMPTY now: Date #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76bc3520>
03	01/07/22 17:09:51.515	JobHandler_LuaUPnP::m_bReloadCriticalOnly_set now 1 <0x76bc3520>
01/07/22 17:13:11.190	luup_log:162: ExternalIP: Plugin STARTING-UP! <0x76b29520>
50	01/07/22 17:13:11.194	luup_log:162: ExtIP: Setting up plugin.... DevNo = 162 <0x76b29520>
06	01/07/22 17:13:11.205	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: Icon was: 0 now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:1 <0x76b29520>
06	01/07/22 17:13:11.205	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: PluginVersion was: 0.1 now: 0.1 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:1 <0x76b29520>
06	01/07/22 17:13:11.206	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: PluginStatus was: Plugin variables being set up 2/2 now: Plugin being installed 1/2  #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76b29520>
50	01/07/22 17:13:11.207	luup_log:162: ExtIP: Setting up plugins variables for ... DevNo = 162 <0x76b29520>
06	01/07/22 17:13:11.207	Device_Variable::m_szValue_set device: 162 service: urn:nodecentral-net:serviceId:ExternalIP1 variable: PluginStatus was: Plugin being installed 1/2  now: Plugin variables being set up 2/2 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x76b29520>
03	01/07/22 17:13:11.209	JobHandler_LuaUPnP::m_bReloadCriticalOnly_set now 1 <0x76b29520>

It hasn’t changed from 0.0.0.0.

I even dropped my VPN tunnel connection on my router, wondered if it wasn’t like that, but it still hasn’t updated to any current external IP.

What mechanism are you using to obtain the external IP address ?

Thanks

Hey @cw-kid

Thanks - this is why I need other testers :slight_smile: - I‘ll look into that initial IP population piece, otherwise it’s set to check/every 24 hours.

If you need to populate/check/refresh it manually, then…

In the lua start up, you can run the following code, remember to change 1148 to your ExternalIP deviceID (which is #162 by the looks of it)

local ExternalIP = require("L_ExternalIP1") 
ExternalIP.refreshExternalIP(1148) 

Hi @cw-kid

I’ve also uploaded a new L_ExternalIP1.lua file to the GitHub repository above. Please upload that too when you can.

1 Like

OK thanks I will try it later and report back.

I’ve just uploaded that updated file and instantly the device plugin is now reporting my correct current WAN IP.

So seems to be working now.

So for the HTTP requests.

This command for example sent to a Vera hub will return the current temp value of a temp sensor device.

http://Local-Vera-IP/port_3480/data_request?id=variableget&DeviceNum=678&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature

I copied your URN and tried this command:

http://Local-Vera-IP/port_3480/data_request?id=variableget&DeviceNum=162&serviceId=urn:nodecentral-net:device:ExternalIP:1&Variable=Current%20External%20IP

ID # 162 being that of the External IP plugin device etc.

But I get: Error: variable not found

So must be doing something wrong.

Seems you might be right about MSR support out of the box.

I just looked in MSR Entities on my Vera Edge and I can see your plugin device listed with this data:

x_vera_device.configured=false
x_vera_device.device_number=162
x_vera_device.device_type="urn:nodecentral-net:device:ExternalIP:1"
x_vera_device.failed=null
x_vera_device.mapped_by="*"
x_vera_device.mapped_class="generic_device"
x_vera_device.parent_device=0
x_vera_device.room_id="0"
x_vera_svc_micasaverde_com_HaDevice1.Configured="0"
x_vera_svc_nodecentral_net_ExternalIP1.Current External IP="xx.xx.xx.xx"
x_vera_svc_nodecentral_net_ExternalIP1.Icon="0"
x_vera_svc_nodecentral_net_ExternalIP1.Last Changed="1641612887"
x_vera_svc_nodecentral_net_ExternalIP1.Last Changed HR="1641612887"
x_vera_svc_nodecentral_net_ExternalIP1.Last Checked="1641612887"
x_vera_svc_nodecentral_net_ExternalIP1.Last Checked HR="1641612887"
x_vera_svc_nodecentral_net_ExternalIP1.PluginStatus="Plugin variables being set up 2/2"
x_vera_svc_nodecentral_net_ExternalIP1.PluginVersion="0.2"
x_vera_svc_nodecentral_net_ExternalIP1.Previous External IP="0.0.0.0"
Capabilities: x_vera_device, x_vera_svc_micasaverde_com_HaDevice1, x_vera_svc_nodecentral_net_ExternalIP1
Actions: x_vera_device.set_variable, x_vera_svc_micasaverde_com_HaDevice1.AllowPairing, x_vera_svc_micasaverde_com_HaDevice1.Poll, x_vera_svc_micasaverde_com_HaDevice1.Reconfigure, x_vera_svc_micasaverde_com_HaDevice1.Remove, x_vera_svc_micasaverde_com_HaDevice1.SetPollFrequency, x_vera_svc_micasaverde_com_HaDevice1.StressTest, x_vera_svc_micasaverde_com_HaDevice1.ToggleState, x_vera_svc_nodecentral_net_ExternalIP1.refreshExternalIP

So looks good, and looks like we can just now use your plugin in our MSR rules !

My comments and question on the MSR forum here.

Next thing I need to try is having more frequent polls of the current IP address. 24 hours is not going to do it for me.

I need like every 5 or 10 mins to tell me if my VPN tunnel has dropped on the router and disconnected.

I will look at the LUA code to force a re-polling you mentioned.

I’ll have a look at it later and make the poll frequency a variable you can change.

1 Like

Well, for some strange reason I cannot get a luup.call_delay or a luup.timer to work within my plugin so that it routinely checks and if needed refreshes the IP address.

I’ve tried numerous things, the one I thought would work was the following…

Within the Lua (L_ExternalIP1.lua) file I have a function called refreshExternalIP(lul_device)
Within the Implementation (I_ExternalIP1.xml) file, I have declared a global function called NC_RefreshExtIP - see below…

function initialiseExternalIPPlugin(lul_device)
	luup.log("ExternalIP: Plugin STARTING-UP!")
	ExternalIP = require "L_ExternalIP1"
	NC_RefreshMyExtIP = ExternalIP.refreshExternalIP
	return ExternalIP.ExternalIPStartUp(lul_device)
end

Then at the end of the end of the refreshExternalIP(lul_device) function I added a luup.call delay to call the global name of that function.

luup.call_delay ("NC_RefreshMyExtIP", PollPeriod, lul_device)

I’ve tried to mirror how other plugins have used it both these call back functions, but something doesn’t seem to like me…

When the function runs initially upon start up, the logs show the following…

50 01/08/22 15:52:06.881 luup_log:1188: ExtIP: Refreshing External IP Address <0x76c92520>
50 01/08/22 15:52:06.881 luup_log:1188: ExtIP: lul_device submitted =1188 <0x76c92520>
50 01/08/22 15:52:06.882 luup_log:1188: ExtIP: PollPeriod = 60 <0x76c92520>
50 01/08/22 15:52:07.458 luup_log:1188: ExtIP: Address check returned = 51.22.33.44 <0x76c92520>
50 01/08/22 15:52:07.458 luup_log:1188: ExtIP: Existing IP = 51.22.33.44 <0x76c92520>
50 01/08/22 15:52:07.459 luup_log:1188: ExtIP: previousIP = 0.0.0.0 <0x76c92520>

But when that same function is called via the luup.call_delay, it’s a different picture…

FYI - To avoid getting an error against PollPeriod if it couldn’t retrieve a value, I set it it to use 30, which is why that is presented…

50 01/08/22 15:53:07.100 luup_log:1188: ExtIP: Refreshing External IP Address <0x74c92520>
50 01/08/22 15:53:07.101 luup_log:1188: ExtIP: lul_device submitted =1188 <0x74c92520>
01 01/08/22 15:53:07.102 GetLuaInterface can’t find device type: 4/0xf46cf8 str: 1188 <0x74c92520>
01 01/08/22 15:53:07.102 luup_variable_get interface 0xf46180 args 3 <0x74c92520>
50 01/08/22 15:53:07.103 luup_log:1188: ExtIP: PollPeriod = 30 <0x74c92520>
50 01/08/22 15:53:07.842 luup_log:1188: ExtIP: Address check returned = 51.22.33.44 <0x74c92520>
01 01/08/22 15:53:07.843 GetLuaInterface can’t find device type: 4/0xf46cf8 str: 1188 <0x74c92520>
01 01/08/22 15:53:07.843 luup_variable_get interface 0xf46180 args 3 <0x74c92520>
01 01/08/22 15:53:07.851 LuaInterface::CallFunction_Timer-5 function NC_RefreshMyExtIP failed [string module(L_ExternalIP1, package.seeall)…]:29: attempt to concatenate local ‘existingIP’ (a nil value) <0x74c92520>

So my current thinking is that when the call back is made it’s looking at that function in isolation, so it’s not aware of all the predefined parementers / arguments that it needs to use… Sound plusable . ??

In the interim, you can simply create an interval based scene, using the luup.code I provided earlier>.

Ok, fixed it !

Not 100% sure of the cause, but It seems when the call back is made (via luup.call_delay) the deviceID (lul_device) provided is a string value, which it doesn’t like - But by changing it to a number/integer via tonumber(lul-device) it doesn’t throw any errors and the callback works… :partying_face:

1 Like

Hi @cw-kid - I’ve uploaded a new Implementation (I), Lua (L) and Static JSON (D) file to the github, repository, when you can , please download and upload them to your Vera…

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules