added all current configs

This commit is contained in:
Nico Melone
2022-02-17 17:56:16 -06:00
parent 8f83dbbf96
commit f4b34734af
36 changed files with 3218 additions and 28 deletions

BIN
Pub_Sub/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -284,6 +284,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:57"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:57"
}
],
"quickfaas": {
@@ -292,7 +296,7 @@
{
"name": "Mistaway",
"trigger": "measure_event",
"topic": "meshify/db/194/_/abbflow/",
"topic": "meshify/db/194/_/abbflow/${MAC_LOWER}",
"qos": 1,
"groups": [
"default"

View File

@@ -284,6 +284,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:57"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:57"
}
],
"quickfaas": {
@@ -292,13 +296,13 @@
{
"name": "Mistaway",
"trigger": "measure_event",
"topic": "meshify/db/194/_/abbflow/",
"topic": "meshify/db/194/_/abbflow/${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 #publish(\"meshify/db/194/_/mainHP/00:18:05:1a:e5:37:00:00/connected\", json.dumps({\"value\":True}), __qos__)\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 = ':'.join(re.findall('..', '%012x' % uuid.getnode()))\n lwt(mac)\n for measure in message[\"measures\"]:\n publish(__topic__ + mac + \":01:99/\" + measure[\"name\"], json.dumps([{\"value\": measure[\"value\"]}]), __qos__)\n #publish(__topic__, json.dumps({measure[\"name\"]: measure[\"value\"]}), __qos__)\n ",
"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 #publish(\"meshify/db/194/_/mainHP/00:18:05:1a:e5:37:00:00/connected\", json.dumps({\"value\":True}), __qos__)\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 publish(__topic__ + \":01:99/\" + measure[\"name\"], json.dumps([{\"value\": measure[\"value\"]}]), __qos__)\n #publish(__topic__, json.dumps({measure[\"name\"]: measure[\"value\"]}), __qos__)\n ",
"msgType": 0,
"cloudName": "default"
}

View File

@@ -27,9 +27,9 @@ def lwt(mac):
def sendData(message):
logger.debug(message)
mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
mac = __topic__.split("/")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))
lwt(mac)
for measure in message["measures"]:
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps([{"value": measure["value"]}]), __qos__)
publish(__topic__ + ":01:99/" + measure["name"], json.dumps([{"value": measure["value"]}]), __qos__)
#publish(__topic__, json.dumps({measure["name"]: measure["value"]}), __qos__)

Binary file not shown.

BIN
Pub_Sub/advvfdipp/guidon/.DS_Store vendored Normal file

Binary file not shown.

BIN
Pub_Sub/advvfdipp/guidon/v1/.DS_Store vendored Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,191 @@
# Enter your python code.
import json
from common.Logger import logger
from quickfaas.remotebus import publish
import re, uuid
def sendData(message):
#logger.debug(message)
mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
for measure in message["measures"]:
try:
logger.debug(measure)
if measure["name"] in ["wellstatus","pidcontrolmode","downholesensorstatus","alarmflowrate","alarmintakepressure","alarmintaketemperature","alarmtubingpressure","alarmvfd","alarmlockout","alarmfluidlevel","runpermissive","startpermissive","last_vfd_fault_code","vfd_fault"]:
logger.debug("Converting DINT/BOOL to STRING")
value = convert_int(measure["name"], measure["value"])
logger.debug("Converted {} to {}".format(measure["value"], value))
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps({"value": value}), __qos__)
else:
publish(__topic__ + mac + ":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):
well_status_codes = {
0: "Running",
1: "Pumped Off",
2: "Alarmed",
3: "Locked Out",
4: "Stopped"
}
pid_control_codes = {
0: "Flow",
1: "Fluid Level",
2: "Tubing Pressure",
3: "Manual"
}
downhole_codes = {
0: "OK",
1: "Connecting",
2: "Open Circuit",
3: "Shorted",
4: "Cannot Decode"
}
permissive_codes = {
0: "OK",
1: "Flow",
2: "Intake Pressure",
3: "Intake Temperature",
4: "Tubing Pressure",
5: "VFD",
6: "Fluid Level",
7: "Min. Downtime"
}
alarm_codes = {
0: "OK",
1: "Alarm"
}
alarm_vfd_codes = {
0: "OK",
1: "Locked Out"
}
vfd_fault_codes = {
0: "No Fault",
2: "Auxiliary Input",
3: "Power Loss",
4: "UnderVoltage",
5: "OverVoltage",
7: "Motor Overload",
8: "Heatsink OverTemp",
9: "Thermister OverTemp",
10: "Dynamic Brake OverTemp",
12: "Hardware OverCurrent",
13: "Ground Fault",
14: "Ground Warning",
15: "Load Loss",
17: "Input Phase Loss",
18: "Motor PTC Trip",
19: "Task Overrun",
20: "Torque Prove Speed Band",
21: "Output Phase Loss",
24: "Decel Inhibit",
25: "OverSpeed Limit",
26: "Brake Slipped",
27: "Torque Prove Conflict",
28: "TP Encls Confict",
29: "Analog In Loss",
33: "Auto Restarts Exhausted",
35: "IPM OverCurrent",
36: "SW OverCurrent",
38: "Phase U to Ground",
39: "Phase V to Ground",
40: "Phase W to Ground",
41: "Phase UV Short",
42: "Phase VW Short",
43: "Phase WU Short",
44: "Phase UNeg to Ground",
45: "Phase VNeg to Ground",
46: "Phase WNeg to Ground",
48: "System Defaulted",
49: "Drive Powerup",
51: "Clear Fault Queue",
55: "Control Board Overtemp",
59: "Invalid Code",
61: "Shear Pin 1",
62: "Shear Pin 2",
64: "Drive Overload",
66: "OW Torque Level",
67: "Pump Off",
71: "Port 1 Adapter",
72: "Port 2 Adapter",
73: "Port 3 Adapter",
74: "Port 4 Adapter",
75: "Port 5 Adapter",
76: "Port 6 Adapter",
77: "IR Volts Range",
78: "FluxAmps Ref Range",
79: "Excessive Load",
80: "AutoTune Aborted",
81: "Port 1 DPI Loss",
82: "Port 2 DPI Loss",
83: "Port 3 DPI Loss",
84: "Port 4 DPI Loss",
85: "Port 5 DPI Loss",
86: "Port 6 DPI Loss",
87: "IXo Voltage Range",
91: "Primary Velocity Feedback Loss",
93: "Hardware Enable Check",
94: "Alternate Velocity Feedback Loss",
95: "Auxiliary Velocity Feedback Loss",
96: "Position Feedback Loss",
97: "Auto Tach Switch",
100: "Parameter Checksum",
101: "Power Down NVS Blank",
102: "NVS Not Blank",
103: "Power Down NVS Incompatible",
104: "Power Board Checksum",
106: "Incompat MCB-PB",
107: "Replaced MCB-PB",
108: "Analog Calibration Checksum",
110: "Invalid Power Board Data",
111: "Power Board Invalid ID",
112: "Power Board App Min Version",
113: "Tracking DataError",
115: "Power Down Table Full",
116: "Power Down Entry Too Large",
117: "Power Down Data Checksum",
118: "Power Board Power Down Checksum",
124: "App ID Changed",
125: "Using Backup App",
134: "Start on Power Up",
137: "External Precharge Error",
138: "Precharge Open",
141: "Autotune Enc Angle",
142: "Autotune Speed Restricted",
143: "Autotune Current Regulator",
144: "Autotune Inertia",
145: "Autotune Travel",
13035: "Net IO Timeout",
13037: "Net IO Timeout"
}
plc_tags = {
"wellstatus": well_status_codes.get(value, "Invalid Code"),
"pidcontrolmode": pid_control_codes.get(value, "Invalid Code"),
"downholesensorstatus": downhole_codes.get(value, "Invalid Code"),
"alarmflowrate": alarm_codes.get(value, "Invalid Code"),
"alarmintakepressure": alarm_codes.get(value, "Invalid Code"),
"alarmintaketemperature": alarm_codes.get(value, "Invalid Code"),
"alarmtubingpressure": alarm_codes.get(value, "Invalid Code"),
"alarmvfd": alarm_codes.get(value, "Invalid Code"),
"alarmlockout": alarm_vfd_codes.get(value, "Invalid Code"),
"alarmfluidlevel": alarm_codes.get(value, "Invalid Code"),
"runpermissive": permissive_codes.get(value, "Invalid Code"),
"startpermissive": permissive_codes.get(value, "Invalid Code"),
"last_vfd_fault_code": vfd_fault_codes.get(value, "Invalid Code"),
"vfd_fault": vfd_fault_codes.get(value, "Invalid Code")
}
return plc_tags.get(plc_tag, "Invalid Tag")

View File

@@ -0,0 +1,50 @@
# 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/_/abbflow/" + mac + "/" + measure["name"]
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 = {"advvfdipp":{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)}]))

BIN
Pub_Sub/advvfdipp/guidon/v2/.DS_Store vendored Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,248 @@
# 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 ["wellstatus","pidcontrolmode","downholesensorstatus","alarmflowrate","alarmintakepressure","alarmintaketemperature","alarmtubingpressure","alarmvfd","alarmlockout","alarmfluidlevel","runpermissive","startpermissive","last_vfd_fault_code","vfd_fault", "external_commands", "remote_comm", "aux_pump_hand","aux_pump_auto","aux_pump_run", "aux_pump_fault"]:
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):
well_status_codes = {
0: "Running",
1: "Pumped Off",
2: "Alarmed",
3: "Locked Out",
4: "Stopped"
}
pid_control_codes = {
0: "Flow",
1: "Fluid Level",
2: "Tubing Pressure",
3: "Manual"
}
downhole_codes = {
0: "OK",
1: "Connecting",
2: "Open Circuit",
3: "Shorted",
4: "Cannot Decode"
}
permissive_codes = {
0: "OK",
1: "Flow",
2: "Intake Pressure",
3: "Intake Temperature",
4: "Tubing Pressure",
5: "VFD",
6: "Fluid Level",
7: "Min. Downtime"
}
alarm_codes = {
0: "OK",
1: "Alarm"
}
alarm_vfd_codes = {
0: "OK",
1: "Locked Out"
}
vfd_fault_codes = {
0: "No Fault",
2: "Auxiliary Input",
3: "Power Loss",
4: "UnderVoltage",
5: "OverVoltage",
7: "Motor Overload",
8: "Heatsink OverTemp",
9: "Thermister OverTemp",
10: "Dynamic Brake OverTemp",
12: "Hardware OverCurrent",
13: "Ground Fault",
14: "Ground Warning",
15: "Load Loss",
17: "Input Phase Loss",
18: "Motor PTC Trip",
19: "Task Overrun",
20: "Torque Prove Speed Band",
21: "Output Phase Loss",
24: "Decel Inhibit",
25: "OverSpeed Limit",
26: "Brake Slipped",
27: "Torque Prove Conflict",
28: "TP Encls Confict",
29: "Analog In Loss",
33: "Auto Restarts Exhausted",
35: "IPM OverCurrent",
36: "SW OverCurrent",
38: "Phase U to Ground",
39: "Phase V to Ground",
40: "Phase W to Ground",
41: "Phase UV Short",
42: "Phase VW Short",
43: "Phase WU Short",
44: "Phase UNeg to Ground",
45: "Phase VNeg to Ground",
46: "Phase WNeg to Ground",
48: "System Defaulted",
49: "Drive Powerup",
51: "Clear Fault Queue",
55: "Control Board Overtemp",
59: "Invalid Code",
61: "Shear Pin 1",
62: "Shear Pin 2",
64: "Drive Overload",
66: "OW Torque Level",
67: "Pump Off",
71: "Port 1 Adapter",
72: "Port 2 Adapter",
73: "Port 3 Adapter",
74: "Port 4 Adapter",
75: "Port 5 Adapter",
76: "Port 6 Adapter",
77: "IR Volts Range",
78: "FluxAmps Ref Range",
79: "Excessive Load",
80: "AutoTune Aborted",
81: "Port 1 DPI Loss",
82: "Port 2 DPI Loss",
83: "Port 3 DPI Loss",
84: "Port 4 DPI Loss",
85: "Port 5 DPI Loss",
86: "Port 6 DPI Loss",
87: "IXo Voltage Range",
91: "Primary Velocity Feedback Loss",
93: "Hardware Enable Check",
94: "Alternate Velocity Feedback Loss",
95: "Auxiliary Velocity Feedback Loss",
96: "Position Feedback Loss",
97: "Auto Tach Switch",
100: "Parameter Checksum",
101: "Power Down NVS Blank",
102: "NVS Not Blank",
103: "Power Down NVS Incompatible",
104: "Power Board Checksum",
106: "Incompat MCB-PB",
107: "Replaced MCB-PB",
108: "Analog Calibration Checksum",
110: "Invalid Power Board Data",
111: "Power Board Invalid ID",
112: "Power Board App Min Version",
113: "Tracking DataError",
115: "Power Down Table Full",
116: "Power Down Entry Too Large",
117: "Power Down Data Checksum",
118: "Power Board Power Down Checksum",
124: "App ID Changed",
125: "Using Backup App",
134: "Start on Power Up",
137: "External Precharge Error",
138: "Precharge Open",
141: "Autotune Enc Angle",
142: "Autotune Speed Restricted",
143: "Autotune Current Regulator",
144: "Autotune Inertia",
145: "Autotune Travel",
13035: "Net IO Timeout",
13037: "Net IO Timeout"
}
external_commands = {
0: "HP Control",
1: "Customer Control"
}
remote_comm = {
0: "Good",
1: "Comms Failure"
}
aux_pump_hand = {
0: "Off",
1: "On"
}
aux_pump_auto = {
0: "Off",
1: "On"
}
aux_pump_run = {
0: "Stopped",
1: "Running"
}
aux_pump_fault = {
0: "Good",
1: "Faulted"
}
plc_tags = {
"external_commands": external_commands.get(value, "Invalid Code"),
"remote_comm": remote_comm.get(value, "Invalid Code"),
"aux_pump_hand": aux_pump_hand.get(value, "Invalid Code"),
"aux_pump_auto": aux_pump_auto.get(value, "Invalid Code"),
"aux_pump_run": aux_pump_run.get(value, "Invalid Code"),
"aux_pump_fault": aux_pump_fault.get(value, "Invalid Code"),
"wellstatus": well_status_codes.get(value, "Invalid Code"),
"pidcontrolmode": pid_control_codes.get(value, "Invalid Code"),
"downholesensorstatus": downhole_codes.get(value, "Invalid Code"),
"alarmflowrate": alarm_codes.get(value, "Invalid Code"),
"alarmintakepressure": alarm_codes.get(value, "Invalid Code"),
"alarmintaketemperature": alarm_codes.get(value, "Invalid Code"),
"alarmtubingpressure": alarm_codes.get(value, "Invalid Code"),
"alarmvfd": alarm_codes.get(value, "Invalid Code"),
"alarmlockout": alarm_vfd_codes.get(value, "Invalid Code"),
"alarmfluidlevel": alarm_codes.get(value, "Invalid Code"),
"runpermissive": permissive_codes.get(value, "Invalid Code"),
"startpermissive": permissive_codes.get(value, "Invalid Code"),
"last_vfd_fault_code": vfd_fault_codes.get(value, "Invalid Code"),
"vfd_fault": vfd_fault_codes.get(value, "Invalid Code")
}
return plc_tags.get(plc_tag, "Invalid Tag")

View File

@@ -0,0 +1,255 @@
# 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/_/advvfdipp/" + mac + "/" + measure["name"]
if measure["name"] in ["wellstatus","pidcontrolmode","downholesensorstatus","alarmflowrate","alarmintakepressure","alarmintaketemperature","alarmtubingpressure","alarmvfd","alarmlockout","alarmfluidlevel","runpermissive","startpermissive","last_vfd_fault_code","vfd_fault", "external_commands", "remote_comm", "aux_pump_hand","aux_pump_auto","aux_pump_run", "aux_pump_fault"]:
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 = {"advvfdipp":{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):
well_status_codes = {
0: "Running",
1: "Pumped Off",
2: "Alarmed",
3: "Locked Out",
4: "Stopped"
}
pid_control_codes = {
0: "Flow",
1: "Fluid Level",
2: "Tubing Pressure",
3: "Manual"
}
downhole_codes = {
0: "OK",
1: "Connecting",
2: "Open Circuit",
3: "Shorted",
4: "Cannot Decode"
}
permissive_codes = {
0: "OK",
1: "Flow",
2: "Intake Pressure",
3: "Intake Temperature",
4: "Tubing Pressure",
5: "VFD",
6: "Fluid Level",
7: "Min. Downtime"
}
alarm_codes = {
0: "OK",
1: "Alarm"
}
alarm_vfd_codes = {
0: "OK",
1: "Locked Out"
}
vfd_fault_codes = {
0: "No Fault",
2: "Auxiliary Input",
3: "Power Loss",
4: "UnderVoltage",
5: "OverVoltage",
7: "Motor Overload",
8: "Heatsink OverTemp",
9: "Thermister OverTemp",
10: "Dynamic Brake OverTemp",
12: "Hardware OverCurrent",
13: "Ground Fault",
14: "Ground Warning",
15: "Load Loss",
17: "Input Phase Loss",
18: "Motor PTC Trip",
19: "Task Overrun",
20: "Torque Prove Speed Band",
21: "Output Phase Loss",
24: "Decel Inhibit",
25: "OverSpeed Limit",
26: "Brake Slipped",
27: "Torque Prove Conflict",
28: "TP Encls Confict",
29: "Analog In Loss",
33: "Auto Restarts Exhausted",
35: "IPM OverCurrent",
36: "SW OverCurrent",
38: "Phase U to Ground",
39: "Phase V to Ground",
40: "Phase W to Ground",
41: "Phase UV Short",
42: "Phase VW Short",
43: "Phase WU Short",
44: "Phase UNeg to Ground",
45: "Phase VNeg to Ground",
46: "Phase WNeg to Ground",
48: "System Defaulted",
49: "Drive Powerup",
51: "Clear Fault Queue",
55: "Control Board Overtemp",
59: "Invalid Code",
61: "Shear Pin 1",
62: "Shear Pin 2",
64: "Drive Overload",
66: "OW Torque Level",
67: "Pump Off",
71: "Port 1 Adapter",
72: "Port 2 Adapter",
73: "Port 3 Adapter",
74: "Port 4 Adapter",
75: "Port 5 Adapter",
76: "Port 6 Adapter",
77: "IR Volts Range",
78: "FluxAmps Ref Range",
79: "Excessive Load",
80: "AutoTune Aborted",
81: "Port 1 DPI Loss",
82: "Port 2 DPI Loss",
83: "Port 3 DPI Loss",
84: "Port 4 DPI Loss",
85: "Port 5 DPI Loss",
86: "Port 6 DPI Loss",
87: "IXo Voltage Range",
91: "Primary Velocity Feedback Loss",
93: "Hardware Enable Check",
94: "Alternate Velocity Feedback Loss",
95: "Auxiliary Velocity Feedback Loss",
96: "Position Feedback Loss",
97: "Auto Tach Switch",
100: "Parameter Checksum",
101: "Power Down NVS Blank",
102: "NVS Not Blank",
103: "Power Down NVS Incompatible",
104: "Power Board Checksum",
106: "Incompat MCB-PB",
107: "Replaced MCB-PB",
108: "Analog Calibration Checksum",
110: "Invalid Power Board Data",
111: "Power Board Invalid ID",
112: "Power Board App Min Version",
113: "Tracking DataError",
115: "Power Down Table Full",
116: "Power Down Entry Too Large",
117: "Power Down Data Checksum",
118: "Power Board Power Down Checksum",
124: "App ID Changed",
125: "Using Backup App",
134: "Start on Power Up",
137: "External Precharge Error",
138: "Precharge Open",
141: "Autotune Enc Angle",
142: "Autotune Speed Restricted",
143: "Autotune Current Regulator",
144: "Autotune Inertia",
145: "Autotune Travel",
13035: "Net IO Timeout",
13037: "Net IO Timeout"
}
external_commands = {
0: "HP Control",
1: "Customer Control"
}
remote_comm = {
0: "Good",
1: "Comms Failure"
}
aux_pump_hand = {
0: "Off",
1: "On"
}
aux_pump_auto = {
0: "Off",
1: "On"
}
aux_pump_run = {
0: "Stopped",
1: "Running"
}
aux_pump_fault = {
0: "Good",
1: "Faulted"
}
plc_tags = {
"external_commands": external_commands.get(value, "Invalid Code"),
"remote_comm": remote_comm.get(value, "Invalid Code"),
"aux_pump_hand": aux_pump_hand.get(value, "Invalid Code"),
"aux_pump_auto": aux_pump_auto.get(value, "Invalid Code"),
"aux_pump_run": aux_pump_run.get(value, "Invalid Code"),
"aux_pump_fault": aux_pump_fault.get(value, "Invalid Code"),
"wellstatus": well_status_codes.get(value, "Invalid Code"),
"pidcontrolmode": pid_control_codes.get(value, "Invalid Code"),
"downholesensorstatus": downhole_codes.get(value, "Invalid Code"),
"alarmflowrate": alarm_codes.get(value, "Invalid Code"),
"alarmintakepressure": alarm_codes.get(value, "Invalid Code"),
"alarmintaketemperature": alarm_codes.get(value, "Invalid Code"),
"alarmtubingpressure": alarm_codes.get(value, "Invalid Code"),
"alarmvfd": alarm_codes.get(value, "Invalid Code"),
"alarmlockout": alarm_vfd_codes.get(value, "Invalid Code"),
"alarmfluidlevel": alarm_codes.get(value, "Invalid Code"),
"runpermissive": permissive_codes.get(value, "Invalid Code"),
"startpermissive": permissive_codes.get(value, "Invalid Code"),
"last_vfd_fault_code": vfd_fault_codes.get(value, "Invalid Code"),
"vfd_fault": vfd_fault_codes.get(value, "Invalid Code")
}
return plc_tags.get(plc_tag, "Invalid Tag")

Binary file not shown.

View File

@@ -957,6 +957,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:37"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:37"
}
],
"quickfaas": {
@@ -965,7 +969,7 @@
{
"name": "Send Data",
"trigger": "measure_event",
"topic": "meshify/db/194/_/advvfdipp/",
"topic": "meshify/db/194/_/advvfdipp/${MAC_LOWER}",
"qos": 1,
"groups": [
"default"

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -26,7 +26,7 @@ def lwt(mac):
def sendData(message):
#logger.debug(message)
mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
mac = __topic__.split("/")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))
lwt(mac)
for measure in message["measures"]:
try:
@@ -35,9 +35,9 @@ def sendData(message):
logger.debug("Converting DINT/BOOL to STRING")
value = convert_int(measure["name"], measure["value"])
logger.debug("Converted {} to {}".format(measure["value"], value))
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps({"value": value}), __qos__)
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": value}), __qos__)
else:
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
except Exception as e:
logger.error(e)

View File

@@ -30,11 +30,11 @@ def write_config(path, config, pub, sub):
json.dump(config, f, indent=4)
root = os.getcwd()
devicetype = "rigpump"
startversion = 3
devicetype = "advvfdipp"
startversion = 1
deviceconfig = "device_supervisor_" + devicetype +"v" + str(startversion) + ".cfg"
#write_code(root + "/" + devicetype + "/v" + str(startversion) + "/pub" + "/sendData.py", get_config_pub(root + "/" + devicetype + "/v" + str(startversion) + "/" + deviceconfig))
#write_code(root + "/" + devicetype + "/v" + str(startversion) + "/sub" + "/receiveCommand.py", get_config_sub(root + "/" + devicetype + "/v" + str(startversion) + "/" + deviceconfig))
write_config(root + "/" + devicetype + "/v" + str(startversion + 1) + "/device_supervisor_" + devicetype + "v" + str(startversion + 1) + ".cfg", get_config(root + "/" + devicetype + "/v" + str(startversion) + "/device_supervisor_" + devicetype + "v" + str(startversion) + ".cfg"), code_to_string(root + "/" + devicetype + "/v" + str(startversion + 1) + "/pub" + "/sendData.py"), code_to_string(root + "/" + devicetype + "/v" + str(startversion + 1) + "/sub" + "/receiveCommand.py"))
write_config(root + "/" + devicetype + "/guidon/v" + str(startversion + 1) + "/device_supervisor_" + devicetype + "v" + str(startversion + 1) + ".cfg", get_config(root + "/" + devicetype + "/guidon/v" + str(startversion) + "/device_supervisor_" + devicetype + "v" + str(startversion) + ".cfg"), code_to_string(root + "/" + devicetype + "/guidon/v" + str(startversion + 1) + "/pub" + "/sendData.py"), code_to_string(root + "/" + devicetype + "/guidon/v" + str(startversion + 1) + "/sub" + "/receiveCommand.py"))

Binary file not shown.

Binary file not shown.

View File

@@ -685,7 +685,7 @@
{
"name": "Send Data",
"trigger": "measure_event",
"topic": "meshify/db/194/_/recycle_train/",
"topic": "meshify/db/194/_/recycle_train/${MAC_LOWER}",
"qos": 1,
"groups": [
"default"
@@ -722,6 +722,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:37"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:37"
}
],
"modbusSlave": {

Binary file not shown.

View File

@@ -685,13 +685,13 @@
{
"name": "Send Data",
"trigger": "measure_event",
"topic": "meshify/db/194/_/recycle_train/",
"topic": "meshify/db/194/_/recycle_train/${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 = ':'.join(re.findall('..', '%012x' % uuid.getnode()))\n lwt(mac)\n for measure in message[\"measures\"]:\n try:\n logger.debug(measure)\n publish(__topic__ + mac + \":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\n\n ",
"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 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\n\n ",
"cloudName": "default",
"msgType": 0
}
@@ -703,7 +703,7 @@
"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/_/rigpump/\" + mac + \"/\" + measure[\"name\"]\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 = {\"rigpump\":{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)}]))",
"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/_/recycle_train/\" + mac + \"/\" + measure[\"name\"]\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 = {\"recycle_train\":{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)}]))",
"msgType": 0,
"trigger": "command_event",
"cloudName": "default"
@@ -722,6 +722,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:37"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:37"
}
],
"modbusSlave": {

View File

@@ -26,12 +26,12 @@ def lwt(mac):
def sendData(message):
#logger.debug(message)
mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
mac = __topic__.split("/")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))
lwt(mac)
for measure in message["measures"]:
try:
logger.debug(measure)
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
except Exception as e:
logger.error(e)

View File

@@ -13,7 +13,7 @@ def sync(mac,value, wizard_api):
for controller in data:
for measure in controller["measures"]:
#publish measure
topic = "meshify/db/194/_/rigpump/" + mac + "/" + measure["name"]
topic = "meshify/db/194/_/recycle_train/" + mac + "/" + measure["name"]
payload = [{"value": measure["value"]}]
logger.debug("Sending on topic: {}".format(topic))
logger.debug("Sending value: {}".format(payload))
@@ -22,7 +22,7 @@ def writeplctag(mac, value, wizard_api):
try:
value = json.loads(value.replace("'",'"'))
logger.debug(value)
message = {"rigpump":{value["tag"]: value["val"]}}
message = {"recycle_train":{value["tag"]: value["val"]}}
wizard_api.write_plc_values(message)
except Exception as e:
logger.debug(e)

Binary file not shown.

Binary file not shown.

View File

@@ -281,7 +281,7 @@
{
"name": "Send Data",
"trigger": "measure_event",
"topic": "meshify/db/194/_/rigpump/",
"topic": "meshify/db/194/_/rigpump/${MAC_LOWER}",
"qos": 1,
"groups": [
"default"
@@ -318,6 +318,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:37"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:37"
}
],
"modbusSlave": {

Binary file not shown.

View File

@@ -281,13 +281,13 @@
{
"name": "Send Data",
"trigger": "measure_event",
"topic": "meshify/db/194/_/rigpump/",
"topic": "meshify/db/194/_/rigpump/${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 = ':'.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\", \"auto_control_mode\", \"device_status\"]:\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__ + mac + \":01:99/\" + measure[\"name\"], json.dumps({\"value\": value}), __qos__)\n else:\n publish(__topic__ + mac + \":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 auto_manual = {\n 0: \"Manual\",\n 1: \"Auto\"\n }\n\n auto_control_mode = {\n 0: \"Pressure\",\n 1: \"Flow\"\n }\n\n device_status = {\n 1: \"Running\",\n 64: \"Idle\",\n 128: \"Overpressure\",\n 1024: \"Faulted\"\n }\n \n plc_tags = {\n \"auto_manual\": auto_manual.get(value, \"Invalid Code\"),\n \"auto_control_mode\": auto_control_mode.get(value, \"Invalid Code\"),\n \"device_status\": device_status.get(value, \"Invalid Code\"),\n }\n\n return plc_tags.get(plc_tag, \"Invalid Tag\")\n\n ",
"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\", \"auto_control_mode\", \"device_status\"]:\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 auto_manual = {\n 0: \"Manual\",\n 1: \"Auto\"\n }\n\n auto_control_mode = {\n 0: \"Pressure\",\n 1: \"Flow\"\n }\n\n device_status = {\n 1: \"Running\",\n 64: \"Idle\",\n 128: \"Overpressure\",\n 1024: \"Faulted\"\n }\n \n plc_tags = {\n \"auto_manual\": auto_manual.get(value, \"Invalid Code\"),\n \"auto_control_mode\": auto_control_mode.get(value, \"Invalid Code\"),\n \"device_status\": device_status.get(value, \"Invalid Code\"),\n }\n\n return plc_tags.get(plc_tag, \"Invalid Tag\")\n\n ",
"cloudName": "default",
"msgType": 0
}
@@ -318,6 +318,10 @@
{
"key": "MAC_UPPER",
"value": "00:18:05:1A:E5:37"
},
{
"key": "MAC_LOWER",
"value": "00:18:05:1a:e5:37"
}
],
"modbusSlave": {

View File

@@ -26,7 +26,7 @@ def lwt(mac):
def sendData(message):
#logger.debug(message)
mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
mac = __topic__.split("/")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))
lwt(mac)
for measure in message["measures"]:
try:
@@ -35,9 +35,9 @@ def sendData(message):
logger.debug("Converting DINT/BOOL to STRING")
value = convert_int(measure["name"], measure["value"])
logger.debug("Converted {} to {}".format(measure["value"], value))
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps({"value": value}), __qos__)
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": value}), __qos__)
else:
publish(__topic__ + mac + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
publish(__topic__ + ":01:99/" + measure["name"], json.dumps({"value": measure["value"]}), __qos__)
except Exception as e:
logger.error(e)