added new devices

This commit is contained in:
Nico Melone
2022-03-09 15:33:48 -06:00
parent f4b34734af
commit dd41db1602
15 changed files with 1341 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.DS_Store

BIN
Pub_Sub/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -896,6 +896,44 @@
"minScaleValue": "",
"gain": "",
"offset": ""
},
{
"ctrlName": "advvfdipp",
"dataType": "BIT",
"addr": "cmd_Start",
"readWrite": "rw",
"uploadType": "periodic",
"group": "default",
"name": "cmd_Start",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "advvfdipp",
"dataType": "BIT",
"addr": "cmd_Stop",
"readWrite": "rw",
"uploadType": "periodic",
"group": "default",
"name": "cmd_Stop",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
}
],
"alarms": [],

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,180 @@
# Enter your python code.
import json
from common.Logger import logger
from quickfaas.remotebus import publish
import re, uuid
from paho.mqtt import client
lwtData = {
"init":False,
"client": client.Client(client_id=str(uuid.uuid4()), clean_session=True, userdata=None, protocol=client.MQTTv311, transport="tcp")
}
def lwt(mac):
try:
#if not lwtData["connected"]:
if not lwtData["init"]:
logger.info("INITIALIZING LWT CLIENT")
lwtData["client"].username_pw_set(username="admin", password="columbus")
lwtData["client"].will_set("meshify/db/194/_/mainHP/" + mac + ":00:00/connected",json.dumps({"value":False}))
lwtData["init"] = True
logger.info("Connecting to MQTT Broker for LWT purposes!!!!!!!")
lwtData["client"].connect("mq194.imistaway.net",1883, 600)
lwtData["client"].publish("meshify/db/194/_/mainHP/" + mac + ":00:00/connected", json.dumps({"value":True}))
except Exception as e:
logger.error("LWT DID NOT DO THE THING")
logger.error(e)
def sendData(message):
#logger.debug(message)
mac = __topic__.split("/")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))
lwt(mac)
for measure in message["measures"]:
try:
logger.debug(measure)
if measure["name"] in ["volume_flow_units", "totalizer_1_units", "totalizer_2_units", "totalizer_3_units"]:
logger.debug("Converting DINT/BOOL to STRING")
value = convert_int(measure["name"], measure["value"])
logger.debug("Converted {} to {}".format(measure["value"], value))
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": value}), __qos__)
else:
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
except Exception as e:
logger.error(e)
#publish(__topic__, json.dumps({measure["name"]: measure["value"]}), __qos__)
def convert_int(plc_tag, value):
volume_flow_codes = {
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)"
}
totalizer_codes = {
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"
}
plc_tags = {
"volume_flow_units": volume_flow_codes.get(value, "Invalid Code"),
"totalizer_1_units": totalizer_codes.get(value, "Invalid Code"),
"totalizer_2_units": totalizer_codes.get(value, "Invalid Code"),
"totalizer_3_units": totalizer_codes.get(value, "Invalid Code")
}
return plc_tags.get(plc_tag, "Invalid Tag")

View File

@@ -0,0 +1,189 @@
# Enter your python code.
import json
from quickfaas.measure import recall
from common.Logger import logger
def sync(mac,value, wizard_api):
#get new values and send
try:
data = recall()#json.loads(recall().decode("utf-8"))
except Exception as e:
logger.error(e)
logger.info(data)
for controller in data:
for measure in controller["measures"]:
#publish measure
topic = "meshify/db/194/_/promagmbs/" + mac + "/" + measure["name"]
if measure["name"] in ["volume_flow_units", "totalizer_1_units", "totalizer_2_units", "totalizer_3_units"]:
payload = [{"value": convert_int(measure["name"], measure["value"])}]
else:
payload = [{"value": measure["value"]}]
logger.debug("Sending on topic: {}".format(topic))
logger.debug("Sending value: {}".format(payload))
wizard_api.mqtt_publish(topic, json.dumps(payload))
def writeplctag(mac, value, wizard_api):
try:
value = json.loads(value.replace("'",'"'))
logger.debug(value)
message = {"promagmbs":{value["tag"]: value["val"]}}
wizard_api.write_plc_values(message)
except Exception as e:
logger.debug(e)
def receiveCommand(topic, payload, wizard_api):
logger.debug(topic)
logger.debug(json.loads(payload))
p = json.loads(payload)[0]
command = p["payload"]["name"].split(".")[1]
commands = {
"sync": sync,
"writeplctag": writeplctag,
}
commands[command](p["mac"].lower(),p["payload"]["value"], wizard_api)
#logger.debug(command)
ack(p["msgId"], p["mac"], p["payload"]["name"].split(".")[1], p["payload"]["value"], wizard_api)
def ack(msgid, mac, name, value, wizard_api):
#logger.debug(mac)
mac = "".join(mac.split(":")[:-2])
#logger.debug(msgid)
#logger.debug(mac)
#logger.debug(name)
#logger.debug(value)
wizard_api.mqtt_publish("meshify/responses/" + str(msgid), json.dumps([{"value": "{} Success Setting: {} To: {}".format(mac,name, value), "msgid": str(msgid)}]))
def convert_int(plc_tag, value):
volume_flow_codes = {
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)"
}
totalizer_codes = {
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"
}
plc_tags = {
"volume_flow_units": volume_flow_codes.get(value, "Invalid Code"),
"totalizer_1_units": totalizer_codes.get(value, "Invalid Code"),
"totalizer_2_units": totalizer_codes.get(value, "Invalid Code"),
"totalizer_3_units": totalizer_codes.get(value, "Invalid Code")
}
return plc_tags.get(plc_tag, "Invalid Tag")

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,574 @@
{
"controllers": [
{
"protocol": "EtherNet/IP",
"name": "transferlite",
"args": {},
"samplePeriod": 60,
"expired": 10000,
"endpoint": "192.168.1.10:44818"
}
],
"groups": [
{
"name": "default",
"uploadInterval": 60,
"reference": 9
}
],
"measures": [
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "FT01_Flowmeter_BPD",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "ft01_flowmeter_bpd",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "BIT",
"addr": "sts_autoMode",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"name": "auto_manual",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "FT01_Flowmeter.val",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "ft01_flowmeter_gpm",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "LT11_PondLevel.val",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "lt11_pondlevel",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "LT21_PondLevel.val",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "lt21_pondlevel",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "BIT",
"addr": "cfg_System1.hasLevelTransmitter",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"name": "system1_hasleveltransmitter",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "BIT",
"addr": "cfg_System2.hasLevelTransmitter",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"name": "system2_hasleveltransmitter",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "PT11_DischargePressure.val",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "pt11_dischargepressure",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "PT21_DischargePressure.val",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "pt21_dischargepressure",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "set_FlowRateSetpoint",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "flow_rate_setpoint",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "set_ManualFrequencySP_System1",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "system1_frequency_setpoint",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "set_ManualFrequencySP_System2",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "system2_frequency_setpoint",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "FT01_Flowmeter_History[1]",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "ft01_flowmeter_bpd_yesterday",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "FT01_Flowmeter_History[0]",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "ft01_flowmeter_bpd_today",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "MC11_Pump.status.speedFeedback",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "mc11_motorfrequency",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "FLOAT",
"addr": "MC21_Pump.status.speedFeedback",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"decimal": 2,
"name": "mc21_motorfrequency",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": ""
},
{
"ctrlName": "transferlite",
"dataType": "INT",
"addr": "Supervisor.State",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"name": "state_supervisor",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "INT",
"addr": "System1.State",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"name": "state_system1",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "INT",
"addr": "System2.State",
"readWrite": "ro",
"uploadType": "periodic",
"group": "default",
"name": "state_system2",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "BIT",
"addr": "cmd_Stop",
"readWrite": "rw",
"uploadType": "periodic",
"group": "default",
"name": "cmd_Stop",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
},
{
"ctrlName": "transferlite",
"dataType": "BIT",
"addr": "cmd_Stop",
"readWrite": "rw",
"uploadType": "periodic",
"group": "default",
"name": "cmd_Start",
"desc": "",
"unit": "",
"transformType": 0,
"gain": "1.0",
"offset": "0.0",
"maxValue": "",
"minValue": "",
"maxScaleValue": "",
"minScaleValue": "",
"decimal": 2
}
],
"alarms": [],
"misc": {
"maxAlarmRecordSz": 2000,
"logLvl": "DEBUG",
"coms": [
{
"name": "rs232",
"baud": 9600,
"bits": 8,
"stopbits": 1,
"parityChk": "n"
},
{
"name": "rs485",
"baud": 9600,
"bits": 8,
"stopbits": 1,
"parityChk": "n"
}
]
},
"clouds": [
{
"cacheSize": 100,
"enable": 1,
"type": "Standard MQTT",
"args": {
"host": "mq194.imistaway.net",
"port": 1883,
"clientId": "sv-inhand-demo",
"auth": 1,
"tls": 0,
"cleanSession": 1,
"mqttVersion": "v3.1.1",
"keepalive": 120,
"key": "",
"cert": "",
"rootCA": "",
"verifyServer": 0,
"verifyClient": 0,
"username": "admin",
"passwd": "columbus",
"authType": 1
},
"name": "default"
}
],
"labels": [
{
"key": "SN",
"value": "GF5022137006251"
},
{
"key": "MAC",
"value": "00:18:05:1a:e5:36"
},
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:37"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:37"
}
],
"quickfaas": {
"genericFuncs": [],
"uploadFuncs": [
{
"name": "Send Data",
"trigger": "measure_event",
"topic": "meshify/db/194/_/transferlite/${MAC_LOWER}",
"qos": 1,
"groups": [
"default"
],
"funcName": "sendData",
"script": "# Enter your python code.\nimport json\nfrom common.Logger import logger\nfrom quickfaas.remotebus import publish\nimport re, uuid\nfrom paho.mqtt import client\n\nlwtData = {\n \"init\":False,\n \"client\": client.Client(client_id=str(uuid.uuid4()), clean_session=True, userdata=None, protocol=client.MQTTv311, transport=\"tcp\")\n}\ndef lwt(mac):\n try:\n #if not lwtData[\"connected\"]:\n if not lwtData[\"init\"]:\n logger.info(\"INITIALIZING LWT CLIENT\")\n lwtData[\"client\"].username_pw_set(username=\"admin\", password=\"columbus\")\n lwtData[\"client\"].will_set(\"meshify/db/194/_/mainHP/\" + mac + \":00:00/connected\",json.dumps({\"value\":False}))\n lwtData[\"init\"] = True\n logger.info(\"Connecting to MQTT Broker for LWT purposes!!!!!!!\")\n lwtData[\"client\"].connect(\"mq194.imistaway.net\",1883, 600)\n lwtData[\"client\"].publish(\"meshify/db/194/_/mainHP/\" + mac + \":00:00/connected\", json.dumps({\"value\":True}))\n except Exception as e:\n logger.error(\"LWT DID NOT DO THE THING\")\n logger.error(e)\n\ndef sendData(message):\n #logger.debug(message)\n mac = __topic__.split(\"/\")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))\n lwt(mac)\n for measure in message[\"measures\"]:\n try:\n logger.debug(measure)\n if measure[\"name\"] in [\"auto_manual\", \"system1_hasleveltransmitter\", \"system2_hasleveltransmitter\", \"state_supervisor\", \"state_system1\", \"state_system2\"]:\n logger.debug(\"Converting DINT/BOOL to STRING\")\n value = convert_int(measure[\"name\"], measure[\"value\"])\n logger.debug(\"Converted {} to {}\".format(measure[\"value\"], value))\n publish(__topic__ + \":01:99/\" + measure[\"name\"], json.dumps({\"value\": value}), __qos__)\n else:\n publish(__topic__ + \":01:99/\" + measure[\"name\"], json.dumps({\"value\": measure[\"value\"]}), __qos__)\n except Exception as e:\n logger.error(e)\n \n #publish(__topic__, json.dumps({measure[\"name\"]: measure[\"value\"]}), __qos__)\n\ndef convert_int(plc_tag, value):\n \n\n TRUE_FALSE = {\n 0: \"false\",\n 1: \"true\"\n }\n\n AUTO_MANUAL = {\n 0: \"Auto\",\n 1: \"Manual\"\n }\n\n PHASE_STATES = {\n 1: \"Running\",\n 2: \"Holding\",\n 4: \"Restarting\",\n 8: \"Stopping\",\n 16: \"Aborting\",\n 32: \"Resetting\",\n 64: \"Idle\",\n 128: \"Held\",\n 256: \"Complete\",\n 512: \"Stopped\",\n 1024: \"Aborted\"\n }\n \n\n plc_tags = {\n \"auto_manual\": AUTO_MANUAL.get(value, \"Invalid Code\"),\n \"system1_hasleveltransmitter\": TRUE_FALSE.get(value, \"Invalid Code\"),\n \"system2_hasleveltransmitter\": TRUE_FALSE.get(value, \"Invalid Code\"),\n \"state_supervisor\": PHASE_STATES.get(value, \"Invalid Code\"),\n \"state_system1\": PHASE_STATES.get(value, \"Invalid Code\"),\n \"state_system2\": PHASE_STATES.get(value, \"Invalid Code\")\n }\n\n return plc_tags.get(plc_tag, \"Invalid Tag\")\n\n ",
"msgType": 0,
"cloudName": "default"
}
],
"downloadFuncs": [
{
"name": "Commands",
"topic": "meshify/sets/194/${MAC_UPPER}:01:99",
"qos": 1,
"funcName": "receiveCommand",
"payload_type": "Plaintext",
"script": "# Enter your python code.\nimport json\nfrom quickfaas.measure import recall\nfrom common.Logger import logger\n\ndef sync(mac,value, wizard_api):\n #get new values and send\n try:\n data = recall()#json.loads(recall().decode(\"utf-8\"))\n except Exception as e:\n logger.error(e)\n logger.info(data)\n for controller in data:\n for measure in controller[\"measures\"]:\n #publish measure\n topic = \"meshify/db/194/_/transferlite/\" + mac + \"/\" + measure[\"name\"]\n if measure[\"name\"] in [\"auto_manual\", \"system1_hasleveltransmitter\", \"system2_hasleveltransmitter\", \"state_supervisor\", \"state_system1\", \"state_system2\"]:\n payload = [{\"value\": convert_int(measure[\"name\"], measure[\"value\"])}]\n else:\n payload = [{\"value\": measure[\"value\"]}]\n logger.debug(\"Sending on topic: {}\".format(topic))\n logger.debug(\"Sending value: {}\".format(payload))\n wizard_api.mqtt_publish(topic, json.dumps(payload))\ndef writeplctag(mac, value, wizard_api):\n try:\n value = json.loads(value.replace(\"'\",'\"'))\n logger.debug(value)\n message = {\"transferlite\":{value[\"tag\"]: value[\"val\"]}}\n wizard_api.write_plc_values(message)\n except Exception as e:\n logger.debug(e)\n \ndef receiveCommand(topic, payload, wizard_api):\n logger.debug(topic)\n logger.debug(json.loads(payload))\n p = json.loads(payload)[0]\n command = p[\"payload\"][\"name\"].split(\".\")[1]\n commands = {\n \"sync\": sync,\n \"writeplctag\": writeplctag,\n }\n commands[command](p[\"mac\"].lower(),p[\"payload\"][\"value\"], wizard_api)\n #logger.debug(command)\n ack(p[\"msgId\"], p[\"mac\"], p[\"payload\"][\"name\"].split(\".\")[1], p[\"payload\"][\"value\"], wizard_api)\n\ndef ack(msgid, mac, name, value, wizard_api):\n #logger.debug(mac)\n mac = \"\".join(mac.split(\":\")[:-2])\n #logger.debug(msgid)\n #logger.debug(mac)\n #logger.debug(name)\n #logger.debug(value)\n wizard_api.mqtt_publish(\"meshify/responses/\" + str(msgid), json.dumps([{\"value\": \"{} Success Setting: {} To: {}\".format(mac,name, value), \"msgid\": str(msgid)}]))\n\ndef convert_int(plc_tag, value):\n \n\n TRUE_FALSE = {\n 0: \"false\",\n 1: \"true\"\n }\n\n AUTO_MANUAL = {\n 0: \"Auto\",\n 1: \"Manual\"\n }\n\n PHASE_STATES = {\n 1: \"Running\",\n 2: \"Holding\",\n 4: \"Restarting\",\n 8: \"Stopping\",\n 16: \"Aborting\",\n 32: \"Resetting\",\n 64: \"Idle\",\n 128: \"Held\",\n 256: \"Complete\",\n 512: \"Stopped\",\n 1024: \"Aborted\"\n }\n \n\n plc_tags = {\n \"auto_manual\": AUTO_MANUAL.get(value, \"Invalid Code\"),\n \"system1_hasleveltransmitter\": TRUE_FALSE.get(value, \"Invalid Code\"),\n \"system2_hasleveltransmitter\": TRUE_FALSE.get(value, \"Invalid Code\"),\n \"state_supervisor\": PHASE_STATES.get(value, \"Invalid Code\"),\n \"state_system1\": PHASE_STATES.get(value, \"Invalid Code\"),\n \"state_system2\": PHASE_STATES.get(value, \"Invalid Code\")\n }\n\n return plc_tags.get(plc_tag, \"Invalid Tag\")\n\n ",
"msgType": 0,
"trigger": "command_event",
"cloudName": "default"
}
]
},
"modbusSlave": {
"enable": 0,
"protocol": "Modbus-TCP",
"port": 502,
"slaveAddr": 1,
"int16Ord": "ab",
"int32Ord": "abcd",
"float32Ord": "abcd",
"maxConnection": 5,
"mapping_table": []
},
"iec104Server": {
"enable": 0,
"cotSize": 2,
"port": 2404,
"serverList": [
{
"asduAddr": 1
}
],
"kValue": 12,
"wValue": 8,
"t0": 15,
"t1": 15,
"t2": 10,
"t3": 20,
"maximumLink": 5,
"timeSet": 1,
"byteOrder": "abcd",
"mapping_table": []
},
"opcuaServer": {
"enable": 0,
"port": 4840,
"maximumLink": 5,
"securityMode": 0,
"identifierType": "String",
"mapping_table": []
},
"bindConfig": {
"enable": 0,
"bind": {
"modelId": "",
"modelName": "",
"srcId": "",
"srcName": "",
"devId": "",
"devName": ""
},
"varGroups": [],
"variables": [],
"alerts": []
},
"southMetadata": {},
"bindMetadata": {
"version": "",
"timestamp": ""
}
}

View File