restructured files
This commit is contained in:
BIN
Pub_Sub/rigpump/.DS_Store
vendored
BIN
Pub_Sub/rigpump/.DS_Store
vendored
Binary file not shown.
@@ -1,54 +0,0 @@
|
||||
# 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 ["auto_manual", "auto_control_mode", "device_status"]:
|
||||
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):
|
||||
auto_manual = {
|
||||
0: "Manual",
|
||||
1: "Auto"
|
||||
}
|
||||
|
||||
auto_control_mode = {
|
||||
0: "Pressure",
|
||||
1: "Flow"
|
||||
}
|
||||
|
||||
device_status = {
|
||||
1: "Running",
|
||||
64: "Idle",
|
||||
128: "Overpressure",
|
||||
1024: "Faulted"
|
||||
}
|
||||
|
||||
p
|
||||
|
||||
plc_tags = {
|
||||
"auto_manual": auto_manual.get(value, "Invalid Code"),
|
||||
"auto_control_mode": auto_control_mode.get(value, "Invalid Code"),
|
||||
"device_status": device_status.get(value, "Invalid Code"),
|
||||
}
|
||||
|
||||
return plc_tags.get(plc_tag, "Invalid Tag")
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
# 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/_/rigpump/" + 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 = {"rigpump":{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)}]))
|
||||
Reference in New Issue
Block a user