Fix for MAXH2O-17, adds MAXH2O-18.

Increments driver version to 5
This commit is contained in:
Patrick McDonagh
2017-10-04 13:53:37 -05:00
parent e91d57cc49
commit 11609e96e9
5 changed files with 606 additions and 520 deletions

View File

@@ -1,3 +1,11 @@
# Rig Water Pump
### Developed by @patrickjmcd, @Henry-Pump
## Automatic Control Modes
### Pressure Control
### Flow Control
## Manual Control Mode

View File

@@ -0,0 +1,42 @@
<div class="row row-flex box-me">
<div class="col-md-6 text-center">
<h2 class="uppercase">Public IP Address</h2>
<p><%= channels["rigpump.public_ip_address"].value %><p>
</div>
</div>
<style>
.uppercase {
text-transform: uppercase;
font-size: 14px;
color: #666;
font-weight: 400;
letter-spacing: 1px;
z-index: 100;
}
.box-me {
position: relative;
padding: 0.5em;
padding-bottom: 1.5em;
border: 1px solid #eee;
/*margin: 1em 0;*/
}
.row-flex {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.row-flex > [class*='col-'] {
display: flex;
flex-direction: column;
}
p {
font-size: 1.25em;
}
</style>

View File

@@ -3,7 +3,7 @@
"driverFileName":"rigpump.py",
"deviceName":"rigpump",
"driverId":"0150",
"releaseVersion":"1",
"releaseVersion":"5",
"files": {
"file1":"rigpump.py",
"file2":"Channel.py",

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
"""Driver for rigpump"""
"""Driver for rigpump."""
import threading
from device_base import deviceBase
@@ -7,6 +7,7 @@ from Maps import rigpump_map as maps
from random import randint
import json
import time
import socket
_ = None
@@ -16,7 +17,7 @@ try:
except Exception:
persist = {}
plc_ip_address = "192.168.1.10"
PLC_IP_ADDRESS = "192.168.1.10"
def reverse_map(value, map_):
@@ -27,6 +28,15 @@ def reverse_map(value, map_):
return None
def get_public_ip_address():
"""Find the public IP Address of the host device."""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
channels = []
@@ -39,7 +49,7 @@ class start(threading.Thread, deviceBase):
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "3"
self.version = "5"
self.finished = threading.Event()
self.forceSend = False
threading.Thread.start(self)
@@ -54,7 +64,7 @@ class start(threading.Thread, deviceBase):
def run(self):
"""Actually run the driver."""
global persist
watchdog = self.rigpump_watchdog()
wait_sec = 60
for i in range(0, wait_sec):
print("rigpump driver will start in {} seconds".format(wait_sec - i))
@@ -63,7 +73,14 @@ class start(threading.Thread, deviceBase):
# after its booted up assuming that M1 is now reading modbus data
# we can replace the reference made to this device name to the M1 driver with this
# driver. The 01 in the 0199 below is the device number you referenced in the modbus wizard
self.nodes["rigpump_0199"] = self
# self.nodes["rigpump_0199"] = self
public_ip_address = get_public_ip_address()
self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'rigpump')
watchdog = self.rigpump_watchdog()
self.sendtodbDev(1, 'watchdog', watchdog, 0, 'rigpump')
send_loops = 0
watchdog_loops = 0
watchdog_check_after = 5000
@@ -88,17 +105,25 @@ class start(threading.Thread, deviceBase):
if (watchdog_loops >= watchdog_check_after):
test_watchdog = self.rigpump_watchdog()
if not test_watchdog == watchdog:
self.sendtodb('watchdog', test_watchdog, 0)
self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'rigpump')
watchdog = test_watchdog
test_public_ip = get_public_ip_address()
if not test_public_ip == public_ip_address:
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'rigpump')
public_ip_address = test_public_ip
watchdog_loops = 0
def rigpump_watchdog(self):
"""Write a random integer to the PLC and then 1 seconds later check that it has been decremented by 1."""
randval = randint(0, 32767)
write_tag(str(plc_ip_address), 'watchdog_INT', randval)
write_tag(str(PLC_IP_ADDRESS), 'watchdog_INT', randval)
time.sleep(1)
watchdog_val = read_tag(str(plc_ip_address), 'watchdog_INT')
return (randval - 1) == watchdog_val[0]
watchdog_val = read_tag(str(PLC_IP_ADDRESS), 'watchdog_INT')
try:
return (randval - 1) == watchdog_val[0]
except (KeyError, TypeError):
return False
def rigpump_sync(self, name, value):
"""Sync all data from the driver."""
@@ -111,7 +136,7 @@ class start(threading.Thread, deviceBase):
new_val = json.loads(str(value).replace("'", '"'))
tag_n = str(new_val['tag']) # "cmd_Start"
val_n = new_val['val']
w = write_tag(str(plc_ip_address), tag_n, val_n)
w = write_tag(str(PLC_IP_ADDRESS), tag_n, val_n)
print("Result of rigpump_writeplctag(self, {}, {}) = {}".format(name, value, w))
if w is None:
w = "Error writing to PLC..."