edit mulfunction
This commit is contained in:
parent
a179f05921
commit
8dbb6c0ba5
|
@ -84,25 +84,25 @@ def Read_Temperature(client, ch_num):
|
|||
id = 3
|
||||
name = 'tempFn3'
|
||||
|
||||
result = client.read_holding_registers(address=2003, count=2, slave=id)
|
||||
result = client.read_holding_registers(address=2002, count=1, slave=id)
|
||||
if not result.isError():
|
||||
# print(f'Temperature: {ch_num} {result.registers}')
|
||||
value = (result.registers[0])/10
|
||||
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time()),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
}
|
||||
}
|
||||
|
||||
Publish_mqtt(data)
|
||||
else:
|
||||
print(f'Temperature Err: {ch_num} \n {result}')
|
||||
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time()),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
}
|
||||
}
|
||||
|
||||
Publish_mqtt(data)
|
||||
|
||||
def Set_Temperature(client, ch_num, value):
|
||||
def Set_Temperature(client, ch_num, order, val=None):
|
||||
if ch_num == 1:
|
||||
id = 1
|
||||
elif ch_num == 2:
|
||||
|
@ -110,7 +110,18 @@ def Set_Temperature(client, ch_num, value):
|
|||
else: # ch_num == 3
|
||||
id = 3
|
||||
|
||||
return 0
|
||||
if order == 'start':
|
||||
client.write_register(address=2336, value=val, slave=id) # H.SP_L1
|
||||
client.write_register(address=2338, value=val, slave=id) # H.TSP_L1
|
||||
client.write_register(address=2340, value=1440, slave=id) # H.TM
|
||||
|
||||
client.write_register(address=2315, value=1, slave=id) # MODE
|
||||
elif order == 'change':
|
||||
client.write_register(address=2336, value=val, slave=id) # H.SP_L1
|
||||
client.write_register(address=2338, value=val, slave=id) # H.TSP_L1
|
||||
client.write_register(address=2340, value=1440, slave=id) # H.TM
|
||||
else: # order == 'stop'
|
||||
client.write_register(address=2315, value=0, slave=id) # MODE
|
||||
|
||||
def Read_Power(client, ch_num):
|
||||
if ch_num == 1:
|
||||
|
@ -127,26 +138,27 @@ def Read_Power(client, ch_num):
|
|||
s_power_rate = client.read_input_registers(address=306, count=1, slave=id)
|
||||
t_power_rate = client.read_input_registers(address=307, count=1, slave=id)
|
||||
|
||||
max_power = 23036
|
||||
if not r_power_rate.isError() and not s_power_rate.isError() and not t_power_rate.isError():
|
||||
max_power = 23036
|
||||
|
||||
mean_power_rate = (
|
||||
(r_power_rate.registers[0] +
|
||||
s_power_rate.registers[0] +
|
||||
t_power_rate.registers[0]) / 30000)
|
||||
mean_power_rate = (
|
||||
(r_power_rate.registers[0] +
|
||||
s_power_rate.registers[0] +
|
||||
t_power_rate.registers[0]) / 30000)
|
||||
|
||||
value = (max_power * mean_power_rate) / 1000
|
||||
# print(value)
|
||||
value = (max_power * mean_power_rate) / 1000
|
||||
# print(value)
|
||||
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time()),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time()),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
}
|
||||
}
|
||||
}
|
||||
# print(data)
|
||||
Publish_mqtt(data)
|
||||
# print(data)
|
||||
Publish_mqtt(data)
|
||||
|
||||
result = []
|
||||
def Read_GasDetector(client, ch_num):
|
||||
|
@ -218,18 +230,10 @@ def Read_GasDetector(client, ch_num):
|
|||
def Set_FlowPump(client, value):
|
||||
id = 31
|
||||
|
||||
# print(f'Set_FlowPump In!: {value}')
|
||||
val = int(float(value) * 1000)
|
||||
|
||||
register_value = val * 8 + 10000
|
||||
# print(f'register_value: {register_value}')
|
||||
client.write_registers(address=40004, values=register_value, slave=id)
|
||||
|
||||
try:
|
||||
result = client.read_holding_registers(address=40004, count=1, slave=id)
|
||||
# print(f'result: {result.registers}')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
client.write_registers(address=3, values=register_value, slave=id)
|
||||
|
||||
def Publish_mqtt(data):
|
||||
send_mqtt_data = json.dumps(data, indent=4)
|
||||
|
@ -262,14 +266,17 @@ def Command_Read():
|
|||
Set_FlowPump(client=client4, value=float(cmd['cmd']['precAc']))
|
||||
|
||||
if cmd['cmd']['tempFn1'] != 'null':
|
||||
Set_Temperature(client=client1, ch_num=1, value=float(cmd['cmd']['tempFn1']))
|
||||
Set_Temperature(client=client1, ch_num=1, order=cmd['type'], val=float(cmd['cmd']['tempFn1']))
|
||||
|
||||
if cmd['cmd']['tempFn2'] != 'null':
|
||||
Set_Temperature(client=client2, ch_num=2, value=float(cmd['cmd']['tempFn1']))
|
||||
Set_Temperature(client=client2, ch_num=2, order=cmd['type'], val=float(cmd['cmd']['tempFn2']))
|
||||
|
||||
if cmd['cmd']['tempFn3'] != 'null':
|
||||
Set_Temperature(client=client2, ch_num=3, value=float(cmd['cmd']['tempFn1']))
|
||||
Set_Temperature(client=client3, ch_num=3, order=cmd['type'], val=float(cmd['cmd']['tempFn3']))
|
||||
else: # 'stop' in cmd['type]
|
||||
Set_Temperature(client=client1, ch_num=1, order=cmd['type'])
|
||||
Set_Temperature(client=client2, ch_num=2, order=cmd['type'])
|
||||
Set_Temperature(client=client3, ch_num=3, order=cmd['type'])
|
||||
Set_FlowPump(client=client4, value=0.0)
|
||||
|
||||
cmd = {
|
||||
|
@ -289,12 +296,12 @@ while True:
|
|||
# Need to add a function call for reading control.json
|
||||
Command_Read()
|
||||
|
||||
# # Read Temperature
|
||||
# Read Temperature
|
||||
Read_Temperature(client1, 1)
|
||||
Read_Temperature(client2, 2)
|
||||
Read_Temperature(client3, 3)
|
||||
|
||||
# # Read Power
|
||||
# Read Power
|
||||
Read_Power(client1, 1)
|
||||
Read_Power(client2, 2)
|
||||
Read_Power(client3, 3)
|
||||
|
|
Loading…
Reference in New Issue