updated check public ip
setup try/catch for checking public IP address
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"driverFileName":"PiFlow.py",
|
||||
"deviceName":"piflow",
|
||||
"driverId":"0280",
|
||||
"releaseVersion":"17",
|
||||
"releaseVersion":"18",
|
||||
"files": {
|
||||
"file1":"PiFlow.py",
|
||||
"file2":"Channel.py",
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user