Adds device IP address to channels

This commit is contained in:
Patrick McDonagh
2018-07-11 15:21:46 -05:00
parent 668cbf3b9f
commit b8778389e5
13 changed files with 170 additions and 32 deletions

View File

@@ -1,31 +0,0 @@
"""Driver for connecting ABB Flowmeter to Meshify."""
import threading
from device_base import deviceBase
class start(threading.Thread, deviceBase):
"""Start class required for driver."""
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None,
companyId=None, offset=None, mqtt=None, Nodes=None):
"""Initalize the driver."""
threading.Thread.__init__(self)
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 = "7"
self.finished = threading.Event()
threading.Thread.start(self)
# this is a required function for all drivers
# its goal is to upload some piece of data
# about your device so it can be seen on the web
def register(self):
"""Register the driver."""
self.channels["status"]["last_value"] = ""
def run(self):
"""Run the driver."""
pass

14
channels_abbflow.csv Normal file
View File

@@ -0,0 +1,14 @@
id,name,deviceTypeId,fromMe,io,subTitle,helpExplanation,channelType,dataType,defaultValue,regex,regexErrMsg,units,min,max,change,guaranteedReportPeriod,minReportTime
8333,battery_voltage,317,FALSE,readonly,Battery Voltage,V,device,float,,,,,,,,,
8334,volume_flow,317,FALSE,readonly,Volume Flow,MCF/Day,device,float,,,,,,,,,
8335,today_volume,317,FALSE,readonly,Today Volume,MCF,device,float,,,,,,,,,
8336,yesterday_volume,317,FALSE,readonly,Yesterday Volume,MCF,device,float,,,,,,,,,
8337,accumulated_volume,317,FALSE,readonly,Accumulated Volume,MCF,device,float,,,,,,,,,
8338,last_calculation_period_volume,317,FALSE,readonly,Last Calculation Period Volume,SCF,device,float,,,,,,,,,
8339,differential_pressure,317,FALSE,readonly,Differential Pressure,InH2O,device,float,,,,,,,,,
8340,static_pressure,317,FALSE,readonly,Static Pressure,PSIA,device,float,,,,,,,,,
8341,temperature,317,FALSE,readonly,Temperature,deg F,device,float,,,,,,,,,
8349,charger_voltage,317,FALSE,readonly,Charger Voltage,V,device,float,,,,,,,,,
8358,notes,317,FALSE,readwrite,Notes,User-entered notes,user input,string,No notes yet...,,,,,,,,
9018,sleeplog,317,FALSE,readonly,Sleep Log,Log of sleep and awakeness,device,string,Nothing here yet...,,,,,,,,
,public_ip_address,317,FALSE,readonly,Public IP Address,Network Address,device,string,n/a,,,,,,,,
1 id name deviceTypeId fromMe io subTitle helpExplanation channelType dataType defaultValue regex regexErrMsg units min max change guaranteedReportPeriod minReportTime
2 8333 battery_voltage 317 FALSE readonly Battery Voltage V device float
3 8334 volume_flow 317 FALSE readonly Volume Flow MCF/Day device float
4 8335 today_volume 317 FALSE readonly Today Volume MCF device float
5 8336 yesterday_volume 317 FALSE readonly Yesterday Volume MCF device float
6 8337 accumulated_volume 317 FALSE readonly Accumulated Volume MCF device float
7 8338 last_calculation_period_volume 317 FALSE readonly Last Calculation Period Volume SCF device float
8 8339 differential_pressure 317 FALSE readonly Differential Pressure InH2O device float
9 8340 static_pressure 317 FALSE readonly Static Pressure PSIA device float
10 8341 temperature 317 FALSE readonly Temperature deg F device float
11 8349 charger_voltage 317 FALSE readonly Charger Voltage V device float
12 8358 notes 317 FALSE readwrite Notes User-entered notes user input string No notes yet...
13 9018 sleeplog 317 FALSE readonly Sleep Log Log of sleep and awakeness device string Nothing here yet...
14 public_ip_address 317 FALSE readonly Public IP Address Network Address device string n/a

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["abbflow.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>

53
python-driver/abbflow.py Normal file
View File

@@ -0,0 +1,53 @@
"""Driver for connecting ABB Flowmeter to Meshify."""
import threading
import time
from device_base import deviceBase
from utilities import get_public_ip_address
WAIT_FOR_CONNECTION_SECONDS = 60
IP_CHECK_PERIOD = 60
class start(threading.Thread, deviceBase):
"""Start class required for driver."""
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None,
companyId=None, offset=None, mqtt=None, Nodes=None):
"""Initalize the driver."""
threading.Thread.__init__(self)
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 = "8"
self.finished = threading.Event()
self.public_ip_address = ""
self.public_ip_address_last_checked = 0
threading.Thread.start(self)
# this is a required function for all drivers
# its goal is to upload some piece of data
# about your device so it can be seen on the web
def register(self):
"""Register the driver."""
self.channels["status"]["last_value"] = ""
def run(self):
"""Run the driver."""
for i in range(0, WAIT_FOR_CONNECTION_SECONDS):
print("abbflow driver will start in {} seconds".format(WAIT_FOR_CONNECTION_SECONDS - i))
time.sleep(1)
while True:
if (time.time() - self.public_ip_address_last_checked) > IP_CHECK_PERIOD:
self._check_ip_address()
def _check_ip_address(self):
"""Check the public IP address and send to Meshify if changed."""
print("Checking IP Address...")
self.public_ip_address_last_checked = time.time()
test_public_ip = get_public_ip_address()
print("Got {} for IP Address".format(test_public_ip))
if not test_public_ip == self.public_ip_address:
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'abbflow')
self.public_ip_address = test_public_ip

View File

@@ -3,7 +3,7 @@
"driverFileName":"abbflow.py",
"deviceName":"abbflow",
"driverId":"0110",
"releaseVersion":"7",
"releaseVersion":"8",
"files": {
"file1":"abbflow.py",
"file2":"modbusMap.p" }

View File

@@ -0,0 +1,11 @@
{
"name": "abbflow",
"driverFilename": "abbflow.py",
"driverId": "0110",
"additionalDriverFiles": [
"utilities.py",
"modbusMap.p"
],
"version": 8,
"s3BucketName": "abbflow"
}

View File

@@ -0,0 +1,49 @@
"""Utility functions for the driver."""
import socket
import struct
def get_public_ip_address():
"""Find the public IP Address of the host device."""
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(("8.8.8.8", 80))
ip_address = sock.getsockname()[0]
sock.close()
return ip_address
def int_to_float16(int_to_convert):
"""Convert integer into float16 representation."""
bin_rep = ('0' * 16 + '{0:b}'.format(int_to_convert))[-16:]
sign = 1.0
if int(bin_rep[0]) == 1:
sign = -1.0
exponent = float(int(bin_rep[1:6], 2))
fraction = float(int(bin_rep[6:17], 2))
if exponent == float(0b00000):
return sign * 2 ** -14 * fraction / (2.0 ** 10.0)
elif exponent == float(0b11111):
if fraction == 0:
return sign * float("inf")
return float("NaN")
frac_part = 1.0 + fraction / (2.0 ** 10.0)
return sign * (2 ** (exponent - 15)) * frac_part
def ints_to_float(int1, int2):
"""Convert 2 registers into a floating point number."""
mypack = struct.pack('>HH', int1, int2)
f_unpacked = struct.unpack('>f', mypack)
print("[{}, {}] >> {}".format(int1, int2, f_unpacked[0]))
return f_unpacked[0]
def degf_to_degc(temp_f):
"""Convert deg F to deg C."""
return (temp_f - 32.0) * (5.0/9.0)
def degc_to_degf(temp_c):
"""Convert deg C to deg F."""
return temp_c * 1.8 + 32.0