updated check public ip

setup try/catch for checking public IP address
This commit is contained in:
2020-01-28 14:57:17 -06:00
parent 85a45e832d
commit 625081b45e
6 changed files with 37 additions and 18 deletions

View File

@@ -45,7 +45,7 @@ class start(threading.Thread, deviceBase):
mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "17"
self.version = "18"
self.finished = threading.Event()
self.force_send = False
self.public_ip_address = ""
@@ -124,7 +124,7 @@ class start(threading.Thread, deviceBase):
test_public_ip = get_public_ip_address()
test_public_ip = test_public_ip[:-1]
test_private_ip = get_private_ip_address()
if not test_public_ip == self.public_ip_address:
if not test_public_ip == self.public_ip_address and not test_public_ip == "0.0.0.0":
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'PiFlow')
self.public_ip_address = test_public_ip
if not test_private_ip == self.private_ip_address:

View File

@@ -3,7 +3,7 @@
"driverFileName":"PiFlow.py",
"deviceName":"piflow",
"driverId":"0280",
"releaseVersion":"17",
"releaseVersion":"18",
"files": {
"file1":"PiFlow.py",
"file2":"Channel.py",

View File

@@ -16,8 +16,12 @@ def get_private_ip_address():
def get_public_ip_address():
ip_address = "0.0.0.0"
with contextlib.closing(urllib.urlopen("httpd://checkip.amazonaws.com")) as url:
ip_address = url.read()
try:
with contextlib.closing(urllib.urlopen("httpd://checkip.amazonaws.com")) as url:
ip_address = url.read()
except Exception as e:
print("Could not resolve address: {}".format(e))
return ip_address
return ip_address[:-1]