Background:
I have openhab on 1 computer in one VLAN , ex 192.168.1.x with a normal WAN IP.
However, I would like to check if the WAN IP changes on another VLAN ex 192.168.2.x.
Reason, this WAN IP is always on an VPN.
I can access the second VLAN from my openhab.
Would it be possible somehow to make openhab ask VLAN ā2ā for its WAN IP adress just for this instance?
I would like top check if it goes down and reveals my āreal WAN IPā.
You can do this by setting a host route in your openHAB system. I.e. if youāre using the solution from above, you just have to add this route (Linux in this case):
ip route add 45.76.25.15/32 via 192.168.2.254
where 45.76.25.15 is the IP of icanhazip.com and 192.168.2.254 is your router in VLAN 2.
Obviously Iām a dumbnut, but could not get it to work via adding the routes normally.
Fortunately, there was a another routing setting in my router so I could set the destination IP to go via VPN instead which worked as expected.
Thank you for the help!
Thanks for the tipp.
I am using icanhazip.com successfully, but have one issue:
Sometimes it does not work and the entire html response wll flood my log file.
So I would like to check whether the returned String is shorter than 17 digits.
Any suggestion how I could do this within OH (without an external script)?
Thanks in advance.
Thatās exactly the problem I encountered, but I hoped it was just a temporary issue.
Obviously itās notā¦
Fritzbox wanip (with Fritzbox TR064 binding) is not working eitherā¦
The original example used the default REGEX transformation to just return the output of the web request. I have modified the example to use a JavaScript transformation that tests for a valid IP address. Please see above.
Cookie messages are gone, but as far as I have noticed the icanhazip service kept working as expected.
One question:
When starting in openhab.log I get the error message:
2017-09-09 15:59:59.444 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model āwanip.rulesā has errors, therefore ignoring it: [3,5]: no viable alternative at input āchangesā
2017-09-09 16:00:05.296 [ERROR] [ab.binding.http.internal.HttpBinding] - Transformation āJS(valid_ip.js)ā threw an exception. [response=xx.xx.xx.xx
]
org.openhab.core.transform.TransformationException: An error occurred while loading script.
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:62)[189:org.openhab.core.compat1x:2.1.0]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:189)[188:org.openhab.binding.http:1.10.0]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[189:org.openhab.core.compat1x:2.1.0]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169)[189:org.openhab.core.compat1x:2.1.0]
Do you know something about it?
My *.rules file:
rule "Monitor WAN IP"
when
Item Network_WAN_IP changes
then
// perform any action needed
val currentState = Network_WAN_IP.state
if (currentState == ā-ā) {
logError(āMonitorWANIPā, āUnable to get WAN IPā)
} else {
logInfo(āMonitorWANIPā, "WAN IP changed to: " + currentState)
}
end
Hello Robert, thanks for your fast reply. Yes, I am using OH2. As written in the link I created the getValue.js file in /etc/openhab2/transform folder:
2017-09-10 17:42:19.171 [ERROR] [ab.binding.http.internal.HttpBinding] - Transformation āJS(valid_ip.js)ā threw an exception. [response=91.240.65.131
]
org.openhab.core.transform.TransformationException: An error occurred while loading script.
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:62)[189:org.openhab.core.compat1x:2.1.0]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:189)[188:org.openhab.binding.http:1.10.0]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[189:org.openhab.core.compat1x:2.1.0]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169)[189:org.openhab.core.compat1x:2.1.0]
every ten minutes.
My valid_ip.js
// return valid IP or '-'
(function(ip) {
// remove blanks first
ip = ip.replace(/\s/g, '');
// http://stackoverflow.com/a/26445549
var rx=/^(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|$)){4}$/;
Oh, donāt how this typo happens. Copy paste your original and restarted the Raspberry Pi. But same behavior
2017-09-10 20:55:20.521 [ERROR] [ab.binding.http.internal.HttpBinding] - Transformation āJS(valid_ip.js)ā threw an exception. [response=91.240.65.131
]
org.openhab.core.transform.TransformationException: An error occurred while loading script.
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:62)[189:org.openhab.core.compat1x:2.1.0]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:189)[188:org.openhab.binding.http:1.10.0]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[189:org.openhab.core.compat1x:2.1.0]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169)[189:org.openhab.core.compat1x:2.1.0]
Update: Moved the *.js from scripts to transform folder and it is working
I have implemented your script on OH2.2 and it works, but I got this warning in my openhab.lg file:
2018-01-30 15:20:11.016 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JS
2018-01-30 15:20:11.020 [WARN ] [ab.binding.http.internal.HttpBinding] - Couldnāt transform response because transformationService of type āJSā is unavailable