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)
|
mqtt=mqtt, Nodes=Nodes)
|
||||||
|
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.version = "17"
|
self.version = "18"
|
||||||
self.finished = threading.Event()
|
self.finished = threading.Event()
|
||||||
self.force_send = False
|
self.force_send = False
|
||||||
self.public_ip_address = ""
|
self.public_ip_address = ""
|
||||||
@@ -124,7 +124,7 @@ class start(threading.Thread, deviceBase):
|
|||||||
test_public_ip = get_public_ip_address()
|
test_public_ip = get_public_ip_address()
|
||||||
test_public_ip = test_public_ip[:-1]
|
test_public_ip = test_public_ip[:-1]
|
||||||
test_private_ip = get_private_ip_address()
|
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.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'PiFlow')
|
||||||
self.public_ip_address = test_public_ip
|
self.public_ip_address = test_public_ip
|
||||||
if not test_private_ip == self.private_ip_address:
|
if not test_private_ip == self.private_ip_address:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"driverFileName":"PiFlow.py",
|
"driverFileName":"PiFlow.py",
|
||||||
"deviceName":"piflow",
|
"deviceName":"piflow",
|
||||||
"driverId":"0280",
|
"driverId":"0280",
|
||||||
"releaseVersion":"17",
|
"releaseVersion":"18",
|
||||||
"files": {
|
"files": {
|
||||||
"file1":"PiFlow.py",
|
"file1":"PiFlow.py",
|
||||||
"file2":"Channel.py",
|
"file2":"Channel.py",
|
||||||
|
|||||||
@@ -16,8 +16,12 @@ def get_private_ip_address():
|
|||||||
|
|
||||||
def get_public_ip_address():
|
def get_public_ip_address():
|
||||||
ip_address = "0.0.0.0"
|
ip_address = "0.0.0.0"
|
||||||
with contextlib.closing(urllib.urlopen("httpd://checkip.amazonaws.com")) as url:
|
try:
|
||||||
ip_address = url.read()
|
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]
|
return ip_address[:-1]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"file4": "Tags.py"
|
"file4": "Tags.py"
|
||||||
},
|
},
|
||||||
"deviceName": "plcfreshwater",
|
"deviceName": "plcfreshwater",
|
||||||
"releaseVersion": "5",
|
"releaseVersion": "7",
|
||||||
"driverFileName": "plcfreshwater.py",
|
"driverFileName": "plcfreshwater.py",
|
||||||
"driverId": "0100"
|
"driverId": "0100"
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ class start(threading.Thread, deviceBase):
|
|||||||
mqtt=mqtt, Nodes=Nodes)
|
mqtt=mqtt, Nodes=Nodes)
|
||||||
|
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.version = "5"
|
self.version = "7"
|
||||||
self.finished = threading.Event()
|
self.finished = threading.Event()
|
||||||
self.force_send = False
|
self.force_send = False
|
||||||
self.public_ip_address = ""
|
self.public_ip_address = ""
|
||||||
@@ -104,13 +104,19 @@ class start(threading.Thread, deviceBase):
|
|||||||
log.warning("FORCE SEND: TRUE")
|
log.warning("FORCE SEND: TRUE")
|
||||||
|
|
||||||
for chan in CHANNELS:
|
for chan in CHANNELS:
|
||||||
val = chan.read()
|
try:
|
||||||
if chan.check(val, self.force_send):
|
val = chan.read()
|
||||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'plcfreshwater')
|
if chan.check(val, self.force_send):
|
||||||
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'plcfreshwater')
|
||||||
|
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Something went wrong in read: {}".format(e))
|
||||||
|
|
||||||
# print("plcfreshwater driver still alive...")
|
# print("plcfreshwater driver still alive...")
|
||||||
plc_ping = os.system("ping -c 1 " + IP_TABLE[self.mac])
|
try:
|
||||||
|
plc_ping = os.system("ping -c 1 " + IP_TABLE[self.mac] + " > /dev/null 2>&1")
|
||||||
|
except Exception as e:
|
||||||
|
log.error("something went wrong in ping: {}".format(e))
|
||||||
if plc_ping == 0:
|
if plc_ping == 0:
|
||||||
if not self.plc_ping_status == "OK":
|
if not self.plc_ping_status == "OK":
|
||||||
self.sendtodbDev(1, "plc_ping","OK", 0, 'plcfreshwater')
|
self.sendtodbDev(1, "plc_ping","OK", 0, 'plcfreshwater')
|
||||||
@@ -139,14 +145,18 @@ class start(threading.Thread, deviceBase):
|
|||||||
test_public_ip = get_public_ip_address()
|
test_public_ip = get_public_ip_address()
|
||||||
test_public_ip = test_public_ip
|
test_public_ip = test_public_ip
|
||||||
test_private_ip = get_private_ip_address()
|
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, 'plcfreshwater')
|
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'plcfreshwater')
|
||||||
self.public_ip_address = test_public_ip
|
self.public_ip_address = test_public_ip
|
||||||
if not test_private_ip == self.private_ip_address:
|
if not test_private_ip == self.private_ip_address:
|
||||||
self.sendtodbDev(1, 'private_ip_address', test_private_ip, 0, 'plcfreshwater')
|
self.sendtodbDev(1, 'private_ip_address', test_private_ip, 0, 'plcfreshwater')
|
||||||
self.private_ip_address = test_private_ip
|
self.private_ip_address = test_private_ip
|
||||||
hostname = "google.com"
|
hostname = "8.8.8.8"
|
||||||
response = os.system("ping -c 1 " + hostname)
|
response = 1
|
||||||
|
try:
|
||||||
|
response = os.system("ping -c 1 " + hostname + " > /dev/null 2>&1")
|
||||||
|
except Exception as e:
|
||||||
|
print("Something went wrong in ping: {}".format(e))
|
||||||
|
|
||||||
#and then check the response...
|
#and then check the response...
|
||||||
if response == 0:
|
if response == 0:
|
||||||
@@ -157,7 +167,7 @@ class start(threading.Thread, deviceBase):
|
|||||||
self.ping_counter += 1
|
self.ping_counter += 1
|
||||||
|
|
||||||
if self.ping_counter >= 3:
|
if self.ping_counter >= 3:
|
||||||
log.info("Rebooting because no internet detected")
|
print("Rebooting because no internet detected")
|
||||||
os.system('reboot')
|
os.system('reboot')
|
||||||
|
|
||||||
|
|
||||||
@@ -169,6 +179,7 @@ class start(threading.Thread, deviceBase):
|
|||||||
|
|
||||||
def plcfreshwater_writeplctag(self, name, value):
|
def plcfreshwater_writeplctag(self, name, value):
|
||||||
"""Write a value to the PLC."""
|
"""Write a value to the PLC."""
|
||||||
|
from Channel import write_tag
|
||||||
new_val = json.loads(str(value).replace("'", '"'))
|
new_val = json.loads(str(value).replace("'", '"'))
|
||||||
tag_n = str(new_val['tag']) # "cmd_Start"
|
tag_n = str(new_val['tag']) # "cmd_Start"
|
||||||
val_n = new_val['val']
|
val_n = new_val['val']
|
||||||
|
|||||||
@@ -17,8 +17,12 @@ def get_private_ip_address():
|
|||||||
|
|
||||||
def get_public_ip_address():
|
def get_public_ip_address():
|
||||||
ip_address = "0.0.0.0"
|
ip_address = "0.0.0.0"
|
||||||
with contextlib.closing(urllib.urlopen("http://checkip.amazonaws.com")) as url:
|
try:
|
||||||
ip_address = url.read()
|
with contextlib.closing(urllib.urlopen("http://checkip.amazonaws.com")) as url:
|
||||||
|
ip_address = url.read()
|
||||||
|
except Exception as e:
|
||||||
|
print("could not resolve check IP: {}".format(e))
|
||||||
|
return ip_address
|
||||||
return ip_address[:-1]
|
return ip_address[:-1]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user