Python Plugin: Wan IP Checker

Python and python framework

Moderator: leecollings

User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

domoticzag wrote: Monday 29 January 2018 22:29 .... I would need to do some Python exercises first, I am an experienced C programmer but this is just a little bit different.
Its only a matter of some lines.
Plugin updates it's sensor only if there is an actual IP change.
We can add a plugin parameter to enable/disable notification and an alert immediate after update.

If you can wait, I can upload a new version...
domoticzag
Posts: 24
Joined: Tuesday 13 September 2016 19:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Plugin - Wan IP Checker

Post by domoticzag »

ycahome wrote: Monday 29 January 2018 22:54
domoticzag wrote: Monday 29 January 2018 22:29 .... I would need to do some Python exercises first, I am an experienced C programmer but this is just a little bit different.
Its only a matter of some lines.
Plugin updates it's sensor only if there is an actual IP change.
We can add a plugin parameter to enable/disable notification and an alert immediate after update.

If you can wait, I can upload a new version...
That would be awsome, thanks in advance!
RPi 3
Domoticz Béta
RFLink Gateway dipool antenna
Many kaku devices
P1 smart meter
Custom made ESP8266 devices
Hue lights / Milight ligts and strips
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

I would look into, tomorow morning.
Bye
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

ycahome wrote: Monday 29 January 2018 22:54
domoticzag wrote: Monday 29 January 2018 22:29 .... I would need to do some Python exercises first, I am an experienced C programmer but this is just a little bit different.
Its only a matter of some lines.
Plugin updates it's sensor only if there is an actual IP change.
We can add a plugin parameter to enable/disable notification and an alert immediate after update.

If you can wait, I can upload a new version...
I think it might be just as easy to have a Domoticz script react to a change in the text device that the plugin updates once the address changes.
But this would result in one single e-mail.
My solution is more complex, but it will keep sending one warning mail per day until I take action.
Hans
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

Version 1.2.0 released to include Notification option.

Make sure that you have properly setup your "Settings/Notifications" and/or "Settings/Email"

Hope you like it!
calouis
Posts: 2
Joined: Thursday 28 December 2017 17:08
Target OS: -
Domoticz version:
Contact:

Re: Plugin - Wan IP Checker

Post by calouis »

Hello
I have the following message :

Code: Select all

Insert Custom Icon From Zip failed on file '/home/pi/domoticz/plugins/WAN-IP-CHECKER/wanipaddress.zip' with error 'Error opening zip file'
Can you help me?
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

calouis wrote: Wednesday 31 January 2018 10:52 Hello
I have the following message :

Code: Select all

Insert Custom Icon From Zip failed on file '/home/pi/domoticz/plugins/WAN-IP-CHECKER/wanipaddress.zip' with error 'Error opening zip file'
Can you help me?
Sorry for that, is just a forgotten code test.

try again now by replacing the plugin code.
calouis
Posts: 2
Joined: Thursday 28 December 2017 17:08
Target OS: -
Domoticz version:
Contact:

Re: Plugin - Wan IP Checker

Post by calouis »

Yes, it's good now
merci
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

Where is the new code? I checked github but no luck... can you provide a link?
Hans
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

manjh wrote: Wednesday 31 January 2018 18:55 Where is the new code? I checked github but no luck... can you provide a link?
Sorry, just saw that you actually updated the code in the first post. Got it.

Now that I have it running, need a little guidance:
1. if I enable notification, will it send an e-mail? To which mail address?
2. what does the field "IP address"mean?
Hans
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

manjh wrote: Wednesday 31 January 2018 19:25 Sorry, just saw that you actually updated the code in the first post. Got it.

Now that I have it running, need a little guidance:
1. if I enable notification, will it send an e-mail? To which mail address?
2. what does the field "IP address"mean?
1. If you enable notifications, Domoticz notification settings will be used
2. "IP address" is a typo (Corrected now). Actually means "Check My IP URL" and is the URL that returns your WAN IP.
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

ycahome wrote: Wednesday 31 January 2018 19:35
manjh wrote: Wednesday 31 January 2018 19:25 Sorry, just saw that you actually updated the code in the first post. Got it.

Now that I have it running, need a little guidance:
1. if I enable notification, will it send an e-mail? To which mail address?
2. what does the field "IP address"mean?
1. If you enable notifications, Domoticz notification settings will be used
2. "IP address" is a typo (Corrected now). Actually means "Check My IP URL" and is the URL that returns your WAN IP.
OK, understand # 1. Does the plugin send one single notification, or repeating?
As for #2: what is it used for? Compare to the outside IP address? Or should I fill in a site like WhoAmI?
Hans
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

manjh wrote: Wednesday 31 January 2018 21:54 OK, understand # 1. Does the plugin send one single notification, or repeating?
As for #2: what is it used for? Compare to the outside IP address? Or should I fill in a site like WhoAmI?
1. Single notification (one for each notification option set on settings) for every WAN IP change.
2. You can use the default one or another. Its up to you.

I have created a F.A.Q section on the first post in order to help other users with their questions. ;)
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

Excellent. This is a very valuable plugin.

One more question, and one suggestion:

Q: what happens if the Internet connection fails completely?

Sug: a "test" button might be nice, to simulate a changed IP.
Hans
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

this could be a small bug: I tried a corrupted IP-checker address. The plugin crashes:

Code: Select all

2018-02-01 09:27:03.950 Error: (WAN IP checker) 'onHeartbeat' failed 'ValueError'.
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 151 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 109 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 153 in /usr/lib/python3.4/urllib/request.py, function urlopen
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 440 in /usr/lib/python3.4/urllib/request.py, function open
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 258 in /usr/lib/python3.4/urllib/request.py, function __init__
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 284 in /usr/lib/python3.4/urllib/request.py, function full_url
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 313 in /usr/lib/python3.4/urllib/request.py, function _parse
Hans
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

manjh wrote: Thursday 01 February 2018 9:30 this could be a small bug: I tried a corrupted IP-checker address. The plugin crashes:

Code: Select all

2018-02-01 09:27:03.950 Error: (WAN IP checker) 'onHeartbeat' failed 'ValueError'.
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 151 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 109 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 153 in /usr/lib/python3.4/urllib/request.py, function urlopen
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 440 in /usr/lib/python3.4/urllib/request.py, function open
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 258 in /usr/lib/python3.4/urllib/request.py, function __init__
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 284 in /usr/lib/python3.4/urllib/request.py, function full_url
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 313 in /usr/lib/python3.4/urllib/request.py, function _parse
This is because plugin does not contain error handling on urlopen (try catch). Maybe on next version.
If a connection fails completely you will not have a way to post your notification so, another method should be in place (SMS or GPRS).

As for the test, we can include a plugin option "Test" (just like "Debug") with a custom function that will fill a random IP and trick the plugin. Maybe on the next version too.

EDIT: Just remembered that Settings/Notifications have "Test" buttons. You can always try those buttons. You want a different approach?

Thank you
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

ycahome wrote: Thursday 01 February 2018 9:55
manjh wrote: Thursday 01 February 2018 9:30 this could be a small bug: I tried a corrupted IP-checker address. The plugin crashes:

Code: Select all

2018-02-01 09:27:03.950 Error: (WAN IP checker) 'onHeartbeat' failed 'ValueError'.
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 151 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 109 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 153 in /usr/lib/python3.4/urllib/request.py, function urlopen
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 440 in /usr/lib/python3.4/urllib/request.py, function open
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 258 in /usr/lib/python3.4/urllib/request.py, function __init__
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 284 in /usr/lib/python3.4/urllib/request.py, function full_url
2018-02-01 09:27:03.950 Error: (WAN IP checker) ----> Line 313 in /usr/lib/python3.4/urllib/request.py, function _parse
This is because plugin does not contain error handling on urlopen (try catch). Maybe on next version.
If a connection fails completely you will not have a way to post your notification so, another method should be in place (SMS or GPRS).

As for the test, we can include a plugin option "Test" (just like "Debug") with a custom function that will fill a random IP and trick the plugin. Maybe on the next version too.

EDIT: Just remembered that Settings/Notifications have "Test" buttons. You can always try those buttons. You want a different approach?

Thank you
Hmmm... it failed, and it does not get back on its feet any more. I restored the correct value but the plugin still crashes...
For now I have disabled it and will do some more testing later.

As for the test functions: I agree but the test on settings/notifications actually test only that functionality. By adding a test button to the plugin, you could actually test the whole path, including the plugin.
One way to do it is to make the last known IP available to the HW screen. The user could change that, and see the plugin react.
Hans
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: Plugin - Wan IP Checker

Post by ycahome »

domoticzag wrote: Monday 29 January 2018 22:29
manjh wrote: Thursday 01 February 2018 10:10
Version upgraded to 1.2.1

bug fixes, error handling and timeout on urlopen added.
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

Hmmm. replaced the code in the plugin.py, restarted Domoticz, and enabled the plugin.

Code: Select all

2018-02-01 12:40:01.517 Error: (WAN IP checker) 'onHeartbeat' failed 'ValueError'.
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 151 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 102 in /home/pi/domoticz/plugins/WAN-IP-CHECKER/plugin.py, function onHeartbeat
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 153 in /usr/lib/python3.4/urllib/request.py, function urlopen
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 440 in /usr/lib/python3.4/urllib/request.py, function open
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 258 in /usr/lib/python3.4/urllib/request.py, function __init__
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 284 in /usr/lib/python3.4/urllib/request.py, function full_url
2018-02-01 12:40:01.517 Error: (WAN IP checker) ----> Line 313 in /usr/lib/python3.4/urllib/request.py, function _parse
2018-02-01 12:40:03.075 dzVents: Warning! WAN IP has changed!
Hans
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Plugin - Wan IP Checker

Post by manjh »

Usability suggestion: add plugin version number to the title as shown on the HW page of Domoticz.
Hans
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest