Initial Commit

This commit is contained in:
Patrick McDonagh
2018-05-22 13:20:48 -05:00
parent 891db3d9c5
commit 28d6009e85
17 changed files with 1647 additions and 0 deletions

22
channels_promagmbs.csv Normal file
View File

@@ -0,0 +1,22 @@
id,name,deviceTypeId,fromMe,io,subTitle,helpExplanation,channelType,dataType,defaultValue,regex,regexErrMsg,units,min,max,change,guaranteedReportPeriod,minReportTime
13414,volume_flow,457,False,readonly,Volume Flow Rate,Reg 2007,device,float,0.0,,,,,,,,
13415,mass_flow,457,False,readonly,Mass Flow Rate,Reg 2009,device,float,,,,,,,,,
13416,conductivity,457,False,readonly,Conductivity,Reg 2013,device,float,0.0,,,,,,,,
13417,totalizer_1,457,False,readonly,Totalizer 1 Value,Reg 2610,device,float,0.0,,,,,,,,
13418,totalizer_2,457,False,readonly,Totalizer 2 Value,Reg 2810,device,float,0.0,,,,,,,,
13419,totalizer_3,457,False,readonly,Totalizer 3 Value,Reg 3010,device,float,0.0,,,,,,,,
13429,volume_flow_units,457,False,readonly,Volume Flow Units,Units of Volume Flow,device,string,,,,,,,,,
13430,totalizer_1_units,457,False,readonly,Totalizer 1 Units,Units of Totalizer 1,device,string,,,,,,,,,
13431,sync,457,False,readwrite,Sync,Sync Channel,device,string,,,,,,,,,
13432,log,457,False,readwrite,Log,Log Channel,device,string,,,,,,,,,
13440,totalizer_2_units,457,False,readonly,Totalizer 2 Units,Units of Totalizer 2,device,string,,,,,,,,,
13441,totalizer_3_units,457,False,readonly,Totalizer 3 Units,Units of Totalizer 3,device,string,,,,,,,,,
13448,totalizer_1_val_at_midnight,457,False,readonly,Totalizer 1 Value at Midnight,value of Totalizer 1 at midnight,device,float,,,,,,,,,
13449,totalizer_1_today,457,False,readonly,Totalizer 1 Today,Flow Today on Totalizer 1,device,float,,,,,,,,,
13450,totalizer_1_yesterday,457,False,readonly,Totalizer 1 Yesterday,Yesterday's Totalized Flow,device,float,,,,,,,,,
13452,totalizer_2_val_at_midnight,457,False,readonly,Totalizer 2 Value at Midnight,value of Totalizer 2 at midnight,device,float,,,,,,,,,
13453,totalizer_3_val_at_midnight,457,False,readonly,Totalizer 3 Value at Midnight,value of Totalizer 3 at midnight,device,float,,,,,,,,,
13454,totalizer_2_today,457,False,readonly,Totalizer 2 Today,Totalized flow for Totalizer 2 Today,device,float,,,,,,,,,
13455,totalizer_3_today,457,False,readonly,Totalizer 3 Today,Totalized flow for Totalizer 3 Today,device,float,,,,,,,,,
13456,totalizer_2_yesterday,457,False,readonly,Totalizer 2 Yesterday,Totalized flow for Totalizer 2 Yesterday,device,float,,,,,,,,,
13457,totalizer_3_yesterday,457,False,readonly,Totalizer 3 Yesterday,Totalized flow for Totalizer 3 Yesterday,device,float,,,,,,,,,
1 id name deviceTypeId fromMe io subTitle helpExplanation channelType dataType defaultValue regex regexErrMsg units min max change guaranteedReportPeriod minReportTime
2 13414 volume_flow 457 False readonly Volume Flow Rate Reg 2007 device float 0.0
3 13415 mass_flow 457 False readonly Mass Flow Rate Reg 2009 device float
4 13416 conductivity 457 False readonly Conductivity Reg 2013 device float 0.0
5 13417 totalizer_1 457 False readonly Totalizer 1 Value Reg 2610 device float 0.0
6 13418 totalizer_2 457 False readonly Totalizer 2 Value Reg 2810 device float 0.0
7 13419 totalizer_3 457 False readonly Totalizer 3 Value Reg 3010 device float 0.0
8 13429 volume_flow_units 457 False readonly Volume Flow Units Units of Volume Flow device string
9 13430 totalizer_1_units 457 False readonly Totalizer 1 Units Units of Totalizer 1 device string
10 13431 sync 457 False readwrite Sync Sync Channel device string
11 13432 log 457 False readwrite Log Log Channel device string
12 13440 totalizer_2_units 457 False readonly Totalizer 2 Units Units of Totalizer 2 device string
13 13441 totalizer_3_units 457 False readonly Totalizer 3 Units Units of Totalizer 3 device string
14 13448 totalizer_1_val_at_midnight 457 False readonly Totalizer 1 Value at Midnight value of Totalizer 1 at midnight device float
15 13449 totalizer_1_today 457 False readonly Totalizer 1 Today Flow Today on Totalizer 1 device float
16 13450 totalizer_1_yesterday 457 False readonly Totalizer 1 Yesterday Yesterday's Totalized Flow device float
17 13452 totalizer_2_val_at_midnight 457 False readonly Totalizer 2 Value at Midnight value of Totalizer 2 at midnight device float
18 13453 totalizer_3_val_at_midnight 457 False readonly Totalizer 3 Value at Midnight value of Totalizer 3 at midnight device float
19 13454 totalizer_2_today 457 False readonly Totalizer 2 Today Totalized flow for Totalizer 2 Today device float
20 13455 totalizer_3_today 457 False readonly Totalizer 3 Today Totalized flow for Totalizer 3 Today device float
21 13456 totalizer_2_yesterday 457 False readonly Totalizer 2 Yesterday Totalized flow for Totalizer 2 Yesterday device float
22 13457 totalizer_3_yesterday 457 False readonly Totalizer 3 Yesterday Totalized flow for Totalizer 3 Yesterday device float

View File

@@ -0,0 +1 @@
<module>Alerts</module>

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

@@ -0,0 +1,6 @@
<div class='col-xs-1'>
<div class="<%= nodecolors.statuscolor %> nodecolor"></div>
</div>
<div class='col-xs-6'>
<h3><%= node.vanityname %></h3>
</div>

View File

@@ -0,0 +1,31 @@
<style>
.header h4 {
position: relative;
top: 0.9em;
}
.header h2 {
text-transform: uppercase;
font-size: 14px;
color: #aaa;
margin: 0.75em 0;
}
.header p {
font-size: 24px;
color: black;
font-weight: 600;
}
</style>
<div class="row header">
<div class="col-xs-1">
<div class="<%= nodecolors.statuscolor %> nodecolor"></div>
</div>
<div class="col-xs-2">
<img src="<%= nodeimgurl %>" />
</div>
<div class="col-xs-4">
<h4><%= node.vanityname %></h4>
</div>
</div>

View File

@@ -0,0 +1,121 @@
<div class="row row-flex box-me">
<div class="col-xs-12 text-center">
<h1>HEADER 1</h1>
</div>
<div class="col-xs-4 text-center">
<h2>CHANNEL 1</h2>
<div class="gauge-box">
<div data-labelheight="10"
style="height: 170px; background: transparent; margin: 0 auto;"
id="gauge-channel_1"
data-chart="solidgauge"
data-nodename="siemens_mag8000.channel_1"
data-units="UNITS"
data-min="0"
data-max="100"
data-decimalplaces="2"
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
data-valuefontsize="18px">
</div>
<div class- "timestamp-box">
<a href="#" data-channelId="<%= channels['siemens_mag8000.channel_1'].channelId %>" class="data-table" title="Download Channel History">
<i class="fa fa-download"></i>
</a>
</div>
<span data-timeupdate="channel_1">
<%= channels["siemens_mag8000.channel_1"].timestamp %>
</span>
</div>
</div>
</div>
<style>
.box-me {
position: relative;
padding: 0.5em;
padding-bottom: 1.5em;
border: 1px solid #eee;
/*margin: 1em 0;*/
}
.box-me .gauge-box {
margin-top: -0.25em;
}
.pad15 {
margin: 15px 15px;
}
.box-me h2 {
text-transform: uppercase;
font-size: 14px;
color: #666;
font-weight: 400;
letter-spacing: 1px;
z-index: 100;
}
.dynamic-chart-form {
background-color: whiteSmoke;
padding: 1em 0.5em;
margin-top: 1em;
}
.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;
}
#systemStatusTimelineContainer h2 {
text-transform: uppercase;
font-size: 14px;
color: #666;
font-weight: 400;
letter-spacing: 1px;
z-index: 100;
}
.slice.node-detail hr {
border-color: #ccc;
}
.slice.node-detail #alarms li {
margin-bottom: 1em;
padding: 0.5em;
}
.slice.node-detail #alarms li:nth-child(even){
background-color: whiteSmoke;
}
.slice.node-detail #alarms li span {
margin-left: 1em;
color: #aaa;
}
</style>
<script>
$('.val_box').each(function(topLevel){
$(this).change(function(){
var id = "#" + $(this).closest(".entry-top-level").attr('id');
if (id !== "#undefined"){
var val = $(id).find('.val_box').val();
var tag = $(id).find('.setstatic').attr('data-staticsend', val);
console.log($(id).find('.setstatic').attr('data-staticsend'));
}
});
});
</script>

View File

@@ -0,0 +1,15 @@
<a href="#"
data-channelId="<%= channels["siemens_mag8000.log"].channelId %>"
class="data-table btn-block btn btn-theme animated"
title="Device Log"><i style='margin-left: 0.5em; cursor: pointer' class="fa fa-th-list icon-theme"></i> Device Log</a>
<a href="#"
data-refreshpause="1"
data-staticsend="1"
data-channelId="<%= channels["siemens_mag8000.sync"].channelId %>"
data-techname="<%=channels["siemens_mag8000.sync"].techName %>"
data-name="<%= channels["siemens_mag8000.sync"].name%>"
data-nodechannelcurrentId="<%= channels["siemens_mag8000.sync"].nodechannelcurrentId %>"
id="<%= channels["siemens_mag8000.sync"].channelId %>"
class="btn btn-large btn-block btn-theme animated setstatic mqtt">
<i class="icon-repeat icon-white mqtt" ></i>Sync All Data</a>

View File

@@ -0,0 +1,37 @@
<div class='col-xs-12' style="padding-top: 1em; margin-bottom: 1em;">
<div class="input-daterange input-group" id="datepicker">
<input data-chartid="dynamicChart" id="fromDate" data-daysofhistory="7" type="text" class="form-control" name="start">
<span class="input-group-addon">to</span>
<input class="form-control" data-chartid="dynamicChart" id="toDate" type="text" name="end">
<span class='input-group-btn'>
<a href="#!" data-chartid="dynamicChart" data-otherchartids="statusTimeline" class="btn chart-update btn-theme">Run</a>
</span>
</div>
</div>
<hr>
<div class='clearfix col-xs-12'
style='height: 450px'
id="dynamicChart"
data-chart="dynamicchart"
data-daysofhistory="7"
data-chartlabel="Data"
data-ylabel=""
data-xlabel="Date"
data-units=""
data-channelnames="siemens_mag8000.channel_1,">
</div>
<style>
.dynamic-chart-form {
background-color: whiteSmoke;
padding: 1em 0.5em;
margin-top: 1em;
}
#systemStatusTimelineContainer h2 {
text-transform: uppercase;
font-size: 14px;
color: #666;
font-weight: 400;
letter-spacing: 1px;
z-index: 100;
}
</style>

42
lambda/totalType.js Normal file
View File

@@ -0,0 +1,42 @@
function toTotalType(number_1, number_2, decimal_1, decimal_2){
const number = (makeTwosComplement32BitInt(
numberTo16BitBinary(number_1),
numberTo16BitBinary(number_2)
));
const decimal = (makeTwosComplement32BitInt(
numberTo16BitBinary(decimal_1),
numberTo16BitBinary(decimal_2)
));
return number + decimal / 1000000000
}
function numberTo16BitBinary(num){
const binString = ("0".repeat(16) + num.toString(2)).slice(-16);
return binString;
}
function binary16BitToNumber(binRep){
const intRep = parseInt(binRep, 2);
return intRep;
}
function makeBinaryStringFrom32BitInt(intVal){
const bin32 = ("0".repeat(32) + intVal.toString(2)).slice(-32);
return [ bin32.substr(0,16), bin32.substr(16,16) ]
}
function makeTwosComplement32BitInt(high, low){
const combined = high + low;
let intVal = parseInt(combined, 2);
if (high[0] === "1"){
let twosString = [];
for(let bit in combined){
const newBit = combined[bit] === "0" ? 1 : 0;
twosString.push(newBit)
}
intVal = -1 * (parseInt(twosString.join(""), 2) + 1);
}
return intVal;
}
console.log(toTotalType(65535, 65534, 4577, 41728));

816
modbusMap.json Normal file
View File

@@ -0,0 +1,816 @@
{
"1": {
"c": "M1-485",
"b": "9600",
"addresses": {
"1": {
"2-2": {
"r": "0-65535",
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Battery Terminal Voltage",
"ct": "number",
"le": "16",
"grp": "600",
"la": 20046,
"chn": "adc_vbterm_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775290.922508,
"da": "1",
"a": "18",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-2",
"s": "On",
"mv": "0",
"t": "int"
},
"2-3": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Array Voltage",
"ct": "number",
"le": "16",
"grp": "600",
"la": 19750,
"chn": "adc_va_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775567.950101,
"da": "1",
"a": "19",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-3",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-1": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Array Current",
"ct": "number",
"le": "16",
"grp": "600",
"la": 35208,
"chn": "adc_ia_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775632.3861568,
"da": "1",
"a": "17",
"c": "1",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-1",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-6": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Ambient Temp",
"ct": "number",
"le": "16",
"grp": "600",
"la": 19672,
"chn": "t_amb_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775649.7532053,
"da": "1",
"a": "28",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-6",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-7": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Min Daily Battery Voltage",
"ct": "number",
"le": "16",
"grp": "600",
"la": 20045,
"chn": "vb_min_daily_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775097.6945858,
"da": "1",
"a": "65",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-7",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-4": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Load Voltage",
"ct": "number",
"le": "16",
"grp": "600",
"la": 20047,
"chn": "adc_vl_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775666.2369888,
"da": "1",
"a": "20",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-4",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-5": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Load Current",
"ct": "number",
"le": "16",
"grp": "600",
"la": 12292,
"chn": "adc_il_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775618.7710588,
"da": "1",
"a": "22",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-5",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-8": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Raw Max Daily Battery Voltage",
"ct": "number",
"le": "16",
"grp": "600",
"la": 20058,
"chn": "vb_max_daily_raw",
"un": "1",
"dn": "prostarsolar",
"vm": null,
"lrt": 1515775181.078918,
"da": "1",
"a": "66",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-8",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-9": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Charge State",
"ct": "number",
"le": "16",
"grp": "600",
"la": 1,
"chn": "charge_state",
"un": "1",
"dn": "prostarsolar",
"vm": {
"1": "Night Check",
"0": "Start",
"3": "Night",
"2": "Disconnect",
"5": "Bulk",
"4": "Fault",
"7": "Float",
"6": "Absorption",
"8": "Equalize"
},
"lrt": 1515775635.6964083,
"da": "1",
"a": "33",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-9",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
},
"2-10": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Array Fault",
"ct": "number",
"le": "16",
"grp": "600",
"la": 0,
"chn": "array_fault",
"un": "1",
"dn": "prostarsolar",
"vm": {
"11": "Processor Supply Fault",
"10": "Dip Switch Changed (Excl. DIP 8)",
"1": "FETs Shorted",
"0": "Overcurrent Phase 1",
"3": "Battery HVD (High Voltage Disconnect)",
"2": "Software Bug",
"5": "EEPROM Setting Edit (Reset required)",
"4": "Array HVD (High Voltage Disconnect)",
"7": "RTS was valid now disconnected",
"6": "RTS Shorted",
"9": "Battery LVD (Low Voltage Disconnect)",
"8": "Local temp. sensor failed"
},
"lrt": 1515775246.518816,
"da": "1",
"a": "34",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "2-10",
"mv": "0",
"s": "On",
"r": "0-65535",
"t": "int"
}
}
},
"f": "Off",
"p": "",
"s": "2"
},
"2": {
"c": "M1-485",
"b": "9600",
"addresses": {
"2": {
"4-1": {
"r": "0-100000",
"ah": "",
"bytary": null,
"al": "0",
"vn": "Volume Flow",
"ct": "number",
"le": "32",
"grp": "600",
"la": 0.0,
"chn": "volume_flow",
"un": "1",
"dn": "promagmbs",
"vm": null,
"lrt": 1515775636.862535,
"da": "2",
"a": "2008",
"c": "5",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-1",
"s": "On",
"mv": "0",
"t": "floatbs"
},
"4-3": {
"r": "0-10000",
"ah": "",
"bytary": null,
"al": "0",
"vn": "Conductivity",
"ct": "number",
"le": "32",
"grp": "600",
"la": NaN,
"chn": "conductivity",
"un": "1",
"dn": "promagmbs",
"vm": null,
"lrt": 1515775621.262141,
"da": "2",
"a": "2012",
"c": "0.5",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-3",
"s": "On",
"mv": "0",
"t": "floatbs"
},
"4-4": {
"r": "0-10000000",
"ah": "",
"bytary": null,
"al": "0",
"vn": "Totalizer 1",
"ct": "number",
"le": "32",
"grp": "600",
"la": 245249.88,
"chn": "totalizer_1",
"un": "1",
"dn": "promagmbs",
"vm": null,
"lrt": 1515775638.257201,
"da": "2",
"a": "2609",
"c": "50.0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-4",
"s": "On",
"mv": "0",
"t": "floatbs"
},
"4-5": {
"r": "0-10000000",
"ah": "",
"bytary": null,
"al": "0",
"vn": "Totalizer 2",
"ct": "number",
"le": "32",
"grp": "600",
"la": 265849.72,
"chn": "totalizer_2",
"un": "1",
"dn": "promagmbs",
"vm": null,
"lrt": 1515775574.650748,
"da": "2",
"a": "2809",
"c": "50",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-5",
"s": "On",
"mv": "0",
"t": "floatbs"
},
"4-6": {
"ah": "",
"bytary": null,
"al": "0",
"vn": "Totalizer 3",
"ct": "number",
"le": "32",
"grp": "600",
"la": 0,
"chn": "totalizer_3",
"un": "1",
"dn": "promagmbs",
"da": "2",
"lrt": 1515624472.5080974,
"a": "3009",
"c": "50",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-6",
"mv": "0",
"s": "On",
"r": "-10000000-10000000",
"t": "floatbs",
"vm": null
},
"4-7": {
"r": "0-100",
"ah": "",
"bytary": null,
"al": "",
"vn": "Volume Flow Units",
"ct": "number",
"le": "16",
"grp": "86400",
"la": 45,
"chn": "volume_flow_units",
"un": "1",
"dn": "promagmbs",
"vm": {
"24": "Ml/s",
"25": "Ml/min",
"26": "Ml/h",
"27": "Ml/d",
"20": "hl/s",
"21": "hl/min",
"22": "hl/h",
"23": "hl/d",
"0": "cm3/s",
"4": "dm3/s",
"8": "m3/s",
"59": "BBL/d (US beer)",
"58": "BBL/h (US beer)",
"55": "BBL/d (US liq.)",
"54": "BBL/h (US liq.)",
"57": "BBL/min (US beer)",
"56": "BBL/s (US beer)",
"51": "Mgal/d",
"50": "Mgal/h",
"53": "BBL/min (US liq.)",
"52": "BBL/s (US liq.)",
"88": "kgal/s (us)",
"89": "kgal/min (us)",
"82": "BBL/h (imp oil)",
"83": "BBL/d (imp oil)",
"80": "BBL/s (imp oil)",
"81": "BBL/min (imp oil)",
"86": "User vol / hour",
"87": "User vol / day",
"84": "User vol / s",
"85": "User vol / min",
"3": "cm3/d",
"7": "dm3/d",
"39": "ft3/d",
"38": "ft3/h",
"33": "af/min",
"32": "af/s",
"37": "ft3/min",
"36": "ft3/s",
"35": "af/d",
"34": "af/h",
"60": "BBL/s (US oil)",
"61": "BBL/min (US oil)",
"62": "BBL/h (US oil)",
"63": "BBL/d (US oil)",
"64": "BBL/s (US tank)",
"65": "BBL/min (US tank)",
"66": "BBL/h (US tank)",
"67": "BBL/d (US tank)",
"68": "gal/s (imp)",
"69": "gal/min (imp)",
"2": "cm3/h",
"6": "dm3/h",
"91": "kgal/d (us)",
"90": "kgal/h (us)",
"11": "m3/d",
"10": "m3/h",
"13": "mL/min",
"12": "mL/s",
"15": "mL/d",
"14": "mL/h",
"17": "l/min",
"16": "l/s",
"19": "l/d",
"18": "l/h",
"48": "Mgal/s",
"49": "Mgal/min",
"46": "gal/h",
"47": "gal/d",
"44": "gal/s",
"45": "gal/min",
"42": "fl oz/h",
"43": "fl oz/d",
"40": "fl oz/s",
"41": "fl oz/min",
"1": "cm3/min",
"5": "dm3/min",
"9": "m3/min",
"77": "BBL/min (imp beer)",
"76": "BBL/s (imp beer)",
"75": "Mgal/d (imp)",
"74": "Mgal/h (imp)",
"73": "Mgal/min (imp)",
"72": "Mgal/s (imp)",
"71": "gal/d (imp)",
"70": "gal/h (imp)",
"79": "BBL/d (imp beer)",
"78": "BBL/h (imp beer)"
},
"lrt": 1515711271.343798,
"da": "2",
"a": "2102",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-7",
"s": "On",
"mv": "0",
"t": "int"
},
"4-8": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Volume Units",
"ct": "number",
"le": "16",
"grp": "86400",
"la": 11,
"chn": "",
"un": "",
"dn": "M1",
"vm": {
"20": "BBL (imp oil)",
"21": "User vol.",
"22": "kgal (us)",
"1": "dm3",
"0": "cm3",
"3": "ml",
"2": "m3",
"5": "hl",
"4": "l",
"6": "Ml Mega",
"9": "ft3",
"8": "af",
"11": "gal (us)",
"10": "fl oz (us)",
"13": "BBL (US liq)",
"12": "Mgal (us)",
"15": "BBL (US oil)",
"14": "BBL (US beer)",
"17": "gal (imp)",
"16": "BBL (US tank)",
"19": "BBL (imp beer)",
"18": "Mgal (imp)"
},
"lrt": 1515711271.8358023,
"da": "2",
"a": "2103",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-8",
"mv": "0",
"s": "On",
"r": "0-22",
"t": "int"
},
"4-9": {
"al": "",
"ah": "",
"bytary": null,
"vm": null,
"vn": "Conductivity Unit",
"ct": "number",
"le": "16",
"grp": "86400",
"la": 8,
"chn": "",
"un": "",
"dn": "M1",
"da": "2",
"lrt": 1515711272.327509,
"r": "0-10",
"a": "2120",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-9",
"s": "On",
"mv": "0",
"t": "int"
},
"4-12": {
"ah": "",
"bytary": null,
"al": "",
"vn": "Totalizer 1 Units",
"ct": "number",
"le": "16",
"grp": "86400",
"la": 11,
"chn": "totalizer_1_units",
"un": "1",
"dn": "promagmbs",
"vm": {
"20": "BBL (imp oil)",
"21": "User vol.",
"22": "kGal (us)",
"1": "dm3",
"0": "cm3",
"3": "ml",
"2": "m3",
"5": "hl",
"4": "l",
"6": "Ml Mega",
"9": "ft3",
"8": "af",
"11": "gal (us)",
"10": "fl oz (us)",
"13": "BBL (US liq)",
"12": "Mgal (us)",
"15": "BBL (US oil)",
"14": "BBL (US beer)",
"17": "gal (imp)",
"16": "BBL (US tank)",
"19": "BBL (imp beer)",
"18": "Mgal (imp)",
"56": "User mass",
"51": "kg",
"50": "g",
"53": "oz",
"52": "t",
"55": "STon",
"54": "lb"
},
"lrt": 1515711272.82556,
"da": "2",
"a": "4603",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-12",
"mv": "0",
"s": "On",
"r": "0-56",
"t": "int"
},
"4-13": {
"al": "",
"ah": "",
"bytary": null,
"vm": {
"20": "BBL (imp oil)",
"21": "User vol.",
"22": "kGal (us)",
"1": "dm3",
"0": "cm3",
"3": "ml",
"2": "m3",
"5": "hl",
"4": "l",
"6": "Ml Mega",
"9": "ft3",
"8": "af",
"11": "gal (us)",
"10": "fl oz (us)",
"13": "BBL (US liq)",
"12": "Mgal (us)",
"15": "BBL (US oil)",
"14": "BBL (US beer)",
"17": "gal (imp)",
"16": "BBL (US tank)",
"19": "BBL (imp beer)",
"18": "Mgal (imp)",
"56": "User mass",
"51": "kg",
"50": "g",
"53": "oz",
"52": "t",
"55": "STon",
"54": "lb"
},
"vn": "Totalizer 2 Units",
"ct": "number",
"le": "16",
"grp": "86400",
"la": 11,
"chn": "totalizer_2_units",
"un": "1",
"dn": "promagmbs",
"da": "2",
"lrt": 1515711273.323234,
"r": "0-56",
"a": "4604",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-13",
"s": "On",
"mv": "0",
"t": "int"
},
"4-14": {
"al": "",
"ah": "",
"bytary": null,
"vm": {
"20": "BBL (imp oil)",
"21": "User vol.",
"22": "kGal (us)",
"1": "dm3",
"0": "cm3",
"3": "ml",
"2": "m3",
"5": "hl",
"4": "l",
"6": "Ml Mega",
"9": "ft3",
"8": "af",
"11": "gal (us)",
"10": "fl oz (us)",
"13": "BBL (US liq)",
"12": "Mgal (us)",
"15": "BBL (US oil)",
"14": "BBL (US beer)",
"17": "gal (imp)",
"16": "BBL (US tank)",
"19": "BBL (imp beer)",
"18": "Mgal (imp)",
"56": "User mass",
"51": "kg",
"50": "g",
"53": "oz",
"52": "t",
"55": "STon",
"54": "lb"
},
"vn": "Totalizer 3 Units",
"ct": "number",
"le": "16",
"grp": "86400",
"la": 11,
"chn": "totalizer_3_units",
"un": "1",
"dn": "promagmbs",
"da": "2",
"lrt": 1515711273.829602,
"r": "0-56",
"a": "4605",
"c": "0",
"misc_u": "",
"f": "3",
"mrt": "60",
"m": "none",
"m1ch": "4-14",
"s": "On",
"mv": "0",
"t": "int"
}
}
},
"f": "Off",
"p": "None",
"s": "1"
}
}

287
python-driver/Channel.py Normal file
View File

@@ -0,0 +1,287 @@
"""Define Meshify channel class."""
from pycomm.ab_comm.clx import Driver as ClxDriver
from pycomm.cip.cip_base import CommError, DataError
import time
def binarray(intval):
"""Split an integer into its bits."""
bin_string = '{0:08b}'.format(intval)
bin_arr = [i for i in bin_string]
bin_arr.reverse()
return bin_arr
def read_tag(addr, tag, plc_type="CLX"):
"""Read a tag from the PLC."""
direct = plc_type == "Micro800"
c = ClxDriver()
try:
if c.open(addr, direct_connection=direct):
try:
v = c.read_tag(tag)
return v
except DataError as e:
c.close()
print("Data Error during readTag({}, {}): {}".format(addr, tag, e))
except CommError:
# err = c.get_status()
c.close()
print("Could not connect during readTag({}, {})".format(addr, tag))
# print err
except AttributeError as e:
c.close()
print("AttributeError during readTag({}, {}): \n{}".format(addr, tag, e))
c.close()
return False
def read_array(addr, tag, start, end, plc_type="CLX"):
"""Read an array from the PLC."""
direct = plc_type == "Micro800"
c = ClxDriver()
if c.open(addr, direct_connection=direct):
arr_vals = []
try:
for i in range(start, end):
tag_w_index = tag + "[{}]".format(i)
v = c.read_tag(tag_w_index)
# print('{} - {}'.format(tag_w_index, v))
arr_vals.append(round(v[0], 4))
# print(v)
if len(arr_vals) > 0:
return arr_vals
else:
print("No length for {}".format(addr))
return False
except Exception:
print("Error during readArray({}, {}, {}, {})".format(addr, tag, start, end))
err = c.get_status()
c.close()
print err
pass
c.close()
def write_tag(addr, tag, val, plc_type="CLX"):
"""Write a tag value to the PLC."""
direct = plc_type == "Micro800"
c = ClxDriver()
if c.open(addr, direct_connection=direct):
try:
cv = c.read_tag(tag)
print(cv)
wt = c.write_tag(tag, val, cv[1])
return wt
except Exception:
print("Error during writeTag({}, {}, {})".format(addr, tag, val))
err = c.get_status()
c.close()
print err
c.close()
class Channel(object):
"""Holds the configuration for a Meshify channel."""
def __init__(self, mesh_name, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False):
"""Initialize the channel."""
self.mesh_name = mesh_name
self.data_type = data_type
self.last_value = None
self.value = None
self.last_send_time = 0
self.chg_threshold = chg_threshold
self.guarantee_sec = guarantee_sec
self.map_ = map_
self.write_enabled = write_enabled
def __str__(self):
"""Create a string for the channel."""
return "{}\nvalue: {}, last_send_time: {}".format(self.mesh_name, self.value, self.last_send_time)
def check(self, new_value, force_send=False):
"""Check to see if the new_value needs to be stored."""
send_needed = False
send_reason = ""
if self.data_type == 'BOOL' or self.data_type == 'STRING':
if self.last_send_time == 0:
send_needed = True
send_reason = "no send time"
elif self.value is None:
send_needed = True
send_reason = "no value"
elif not (self.value == new_value):
if self.map_:
if not self.value == self.map_[new_value]:
send_needed = True
send_reason = "value change"
else:
send_needed = True
send_reason = "value change"
elif (time.time() - self.last_send_time) > self.guarantee_sec:
send_needed = True
send_reason = "guarantee sec"
elif force_send:
send_needed = True
send_reason = "forced"
else:
if self.last_send_time == 0:
send_needed = True
send_reason = "no send time"
elif self.value is None:
send_needed = True
send_reason = "no value"
elif abs(self.value - new_value) > self.chg_threshold:
send_needed = True
send_reason = "change threshold"
elif (time.time() - self.last_send_time) > self.guarantee_sec:
send_needed = True
send_reason = "guarantee sec"
elif force_send:
send_needed = True
send_reason = "forced"
if send_needed:
self.last_value = self.value
if self.map_:
try:
self.value = self.map_[new_value]
except KeyError:
print("Cannot find a map value for {} in {} for {}".format(new_value, self.map_, self.mesh_name))
self.value = new_value
else:
self.value = new_value
self.last_send_time = time.time()
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
return send_needed
def read(self):
"""Read the value."""
pass
def identity(sent):
"""Return exactly what was sent to it."""
return sent
class ModbusChannel(Channel):
"""Modbus channel object."""
def __init__(self, mesh_name, register_number, data_type, chg_threshold, guarantee_sec, channel_size=1, map_=False, write_enabled=False, transformFn=identity):
"""Initialize the channel."""
super(ModbusChannel, self).__init__(mesh_name, data_type, chg_threshold, guarantee_sec, map_, write_enabled)
self.mesh_name = mesh_name
self.register_number = register_number
self.channel_size = channel_size
self.data_type = data_type
self.last_value = None
self.value = None
self.last_send_time = 0
self.chg_threshold = chg_threshold
self.guarantee_sec = guarantee_sec
self.map_ = map_
self.write_enabled = write_enabled
self.transformFn = transformFn
def read(self, mbsvalue):
"""Return the transformed read value."""
return self.transformFn(mbsvalue)
class PLCChannel(Channel):
"""PLC Channel Object."""
def __init__(self, ip, mesh_name, plc_tag, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False, plc_type='CLX'):
"""Initialize the channel."""
super(PLCChannel, self).__init__(mesh_name, data_type, chg_threshold, guarantee_sec, map_, write_enabled)
self.plc_ip = ip
self.mesh_name = mesh_name
self.plc_tag = plc_tag
self.data_type = data_type
self.last_value = None
self.value = None
self.last_send_time = 0
self.chg_threshold = chg_threshold
self.guarantee_sec = guarantee_sec
self.map_ = map_
self.write_enabled = write_enabled
self.plc_type = plc_type
def read(self):
"""Read the value."""
plc_value = None
if self.plc_tag and self.plc_ip:
read_value = read_tag(self.plc_ip, self.plc_tag, plc_type=self.plc_type)
if read_value:
plc_value = read_value[0]
return plc_value
class BoolArrayChannels(Channel):
"""Hold the configuration for a set of boolean array channels."""
def __init__(self, ip, mesh_name, plc_tag, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False):
"""Initialize the channel."""
self.plc_ip = ip
self.mesh_name = mesh_name
self.plc_tag = plc_tag
self.data_type = data_type
self.last_value = None
self.value = None
self.last_send_time = 0
self.chg_threshold = chg_threshold
self.guarantee_sec = guarantee_sec
self.map_ = map_
self.write_enabled = write_enabled
def compare_values(self, new_val_dict):
"""Compare new values to old values to see if the values need storing."""
send = False
for idx in new_val_dict:
try:
if new_val_dict[idx] != self.last_value[idx]:
send = True
except KeyError:
print("Key Error in self.compare_values for index {}".format(idx))
send = True
return send
def read(self, force_send=False):
"""Read the value and check to see if needs to be stored."""
send_needed = False
send_reason = ""
if self.plc_tag:
v = read_tag(self.plc_ip, self.plc_tag)
if v:
bool_arr = binarray(v[0])
new_val = {}
for idx in self.map_:
try:
new_val[self.map_[idx]] = bool_arr[idx]
except KeyError:
print("Not able to get value for index {}".format(idx))
if self.last_send_time == 0:
send_needed = True
send_reason = "no send time"
elif self.value is None:
send_needed = True
send_reason = "no value"
elif self.compare_values(new_val):
send_needed = True
send_reason = "value change"
elif (time.time() - self.last_send_time) > self.guarantee_sec:
send_needed = True
send_reason = "guarantee sec"
elif force_send:
send_needed = True
send_reason = "forced"
if send_needed:
self.value = new_val
self.last_value = self.value
self.last_send_time = time.time()
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
return send_needed

View File

@@ -0,0 +1 @@
id,name,deviceTypeId,fromMe,io,subTitle,helpExplanation,channelType,dataType,defaultValue,regex,regexErrMsg,units,min,max,change,guaranteedReportPeriod,minReportTime
1 id name deviceTypeId fromMe io subTitle helpExplanation channelType dataType defaultValue regex regexErrMsg units min max change guaranteedReportPeriod minReportTime

View File

@@ -0,0 +1,2 @@
class deviceBase(object):
pass

View File

@@ -0,0 +1,12 @@
{
"name": "siemens_mag8000",
"driverFilename": "siemens_mag8000.py",
"driverId": "0000",
"additionalDriverFiles": [
"utilities.py",
"persistence.py",
"Channel.py"
],
"version": 1,
"s3BucketName": "siemens_mag8000"
}

View File

@@ -0,0 +1,21 @@
"""Data persistance functions."""
# if more advanced persistence is needed, use a sqlite database
import json
def load(filename="persist.json"):
"""Load persisted settings from the specified file."""
try:
with open(filename, 'r') as persist_file:
return json.load(persist_file)
except Exception:
return False
def store(persist_obj, filename="persist.json"):
"""Store the persisting settings into the specified file."""
try:
with open(filename, 'w') as persist_file:
return json.dump(persist_obj, persist_file, indent=4)
except Exception:
return False

View File

@@ -0,0 +1,140 @@
"""Driver for siemens_mag8000"""
import threading
import sys
from device_base import deviceBase
from Channel import Channel, read_tag, write_tag
import persistence
from random import randint
from utilities import get_public_ip_address
import json
import time
import logging
_ = None
# LOGGING SETUP
from logging.handlers import RotatingFileHandler
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
logFile = './siemens_mag8000.log'
my_handler = RotatingFileHandler(logFile, mode='a', maxBytes=500*1024, backupCount=2, encoding=None, delay=0)
my_handler.setFormatter(log_formatter)
my_handler.setLevel(logging.INFO)
logger = logging.getLogger('siemens_mag8000')
logger.setLevel(logging.INFO)
logger.addHandler(my_handler)
console_out = logging.StreamHandler(sys.stdout)
console_out.setFormatter(log_formatter)
logger.addHandler(console_out)
logger.info("siemens_mag8000 startup")
# GLOBAL VARIABLES
WATCHDOG_SEND_PERIOD = 3600 # Seconds, the longest amount of time before sending the watchdog status
PLC_IP_ADDRESS = "192.168.1.10"
CHANNELS = []
# PERSISTENCE FILE
persist = persistence.load()
class start(threading.Thread, deviceBase):
"""Start class required by Meshify."""
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
"""Initialize 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 = "1"
self.finished = threading.Event()
self.forceSend = False
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.sendtodb("log", "BOOM! Booted.", 0)
pass
def run(self):
"""Actually run the driver."""
global persist
wait_sec = 60
for i in range(0, wait_sec):
print("siemens_mag8000 driver will start in {} seconds".format(wait_sec - i))
time.sleep(1)
logger.info("BOOM! Starting siemens_mag8000 driver...")
public_ip_address = get_public_ip_address()
self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'siemens_mag8000')
watchdog = self.siemens_mag8000_watchdog()
self.sendtodbDev(1, 'watchdog', watchdog, 0, 'siemens_mag8000')
watchdog_send_timestamp = time.time()
send_loops = 0
watchdog_loops = 0
watchdog_check_after = 5000
while True:
if self.forceSend:
logger.warning("FORCE SEND: TRUE")
for c in CHANNELS:
v = c.read()
if c.check(self.forceSend):
self.sendtodbDev(1, c.mesh_name, c.value, 0, 'siemens_mag8000')
# print("siemens_mag8000 driver still alive...")
if self.forceSend:
if send_loops > 2:
logger.warning("Turning off forceSend")
self.forceSend = False
send_loops = 0
else:
send_loops += 1
watchdog_loops += 1
if (watchdog_loops >= watchdog_check_after):
test_watchdog = self.siemens_mag8000_watchdog()
if not test_watchdog == watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD:
self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'siemens_mag8000')
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, 'siemens_mag8000')
public_ip_address = test_public_ip
watchdog_loops = 0
def siemens_mag8000_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)
time.sleep(1)
watchdog_val = read_tag(str(PLC_IP_ADDRESS), 'watchdog_INT')
try:
return (randval - 1) == watchdog_val[0]
except (KeyError, TypeError):
return False
def siemens_mag8000_sync(self, name, value):
"""Sync all data from the driver."""
self.forceSend = True
# self.sendtodb("log", "synced", 0)
return True
def siemens_mag8000_writeplctag(self, name, value):
"""Write a value to the PLC."""
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)
print("Result of siemens_mag8000_writeplctag(self, {}, {}) = {}".format(name, value, w))
if w is None:
w = "Error writing to PLC..."
return w

View File

@@ -0,0 +1,51 @@
"""Utility functions for the driver."""
import socket
import struct
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
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")
else:
return float("NaN")
else:
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 = struct.unpack('>f', mypack)
print("[{}, {}] >> {}".format(int1, int2, f[0]))
return f[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