Compare commits
No commits in common. "main" and "Version_1.2" have entirely different histories.
main
...
Version_1.
|
@ -84,25 +84,25 @@ def Read_Temperature(client, ch_num):
|
|||
id = 3
|
||||
name = 'tempFn3'
|
||||
|
||||
result = client.read_holding_registers(address=2002, count=1, slave=id)
|
||||
result = client.read_holding_registers(address=2003, count=2, 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() * 1000),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
}
|
||||
}
|
||||
|
||||
Publish_mqtt(data)
|
||||
else:
|
||||
print(f'Temperature Err: {ch_num} \n {result}')
|
||||
|
||||
def Set_Temperature(client, ch_num, order, val=None):
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time()),
|
||||
"dataTsype": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
}
|
||||
}
|
||||
|
||||
Publish_mqtt(data)
|
||||
|
||||
def Set_Temperature(client, ch_num, value):
|
||||
if ch_num == 1:
|
||||
id = 1
|
||||
elif ch_num == 2:
|
||||
|
@ -110,66 +110,7 @@ def Set_Temperature(client, ch_num, order, val=None):
|
|||
else: # ch_num == 3
|
||||
id = 3
|
||||
|
||||
if not val == None:
|
||||
val *= 10
|
||||
val = int(val)
|
||||
|
||||
try:
|
||||
if order == 'start':
|
||||
# Patten 1
|
||||
client.write_register(address=8000, value=1, slave=id) # PTNO._C
|
||||
client.write_register(address=8004, value=1, slave=id) # STC
|
||||
|
||||
# SEG 0
|
||||
client.write_register(address=8001, value=0, slave=id) # SEGNO._C
|
||||
client.write_register(address=8002, value=0, slave=id) # SSP_L1
|
||||
|
||||
# SEG 1
|
||||
client.write_register(address=8001, value=1, slave=id) # SEGNO._C
|
||||
|
||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
||||
client.write_register(address=8104, value=180, slave=id) # TIME
|
||||
|
||||
# SEG 2
|
||||
client.write_register(address=8001, value=2, slave=id) # SEGNO._C
|
||||
|
||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
||||
client.write_register(address=8104, value=1440, slave=id) # TIME
|
||||
|
||||
# Power On
|
||||
client.write_register(address=2321, value=1, slave=id) # PTNO.
|
||||
client.write_register(address=2315, value=1, slave=id) # MODE
|
||||
elif order == 'change':
|
||||
# Power Off
|
||||
client.write_register(address=2315, value=0, slave=id) # MODE
|
||||
|
||||
# Patten 1
|
||||
client.write_register(address=8000, value=1, slave=id) # PTNO._C
|
||||
client.write_register(address=8004, value=1, slave=id) # STC
|
||||
|
||||
# SEG 0
|
||||
client.write_register(address=8001, value=0, slave=id) # SEGNO._C
|
||||
client.write_register(address=8002, value=0, slave=id) # SSP_L1
|
||||
|
||||
# SEG 1
|
||||
client.write_register(address=8001, value=1, slave=id) # SEGNO._C
|
||||
|
||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
||||
client.write_register(address=8104, value=180, slave=id) # TIME
|
||||
|
||||
# SEG 2
|
||||
client.write_register(address=8001, value=2, slave=id) # SEGNO._C
|
||||
|
||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
||||
client.write_register(address=8104, value=1440, slave=id) # TIME
|
||||
|
||||
client.write_register(address=2321, value=1, slave=id) # PTNO.
|
||||
client.write_register(address=2315, value=1, slave=id) # MODE
|
||||
else: # order == 'stop'
|
||||
# Power Off
|
||||
client.write_register(address=2315, value=0, slave=id) # MODE
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return 0
|
||||
|
||||
def Read_Power(client, ch_num):
|
||||
if ch_num == 1:
|
||||
|
@ -186,27 +127,26 @@ 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)
|
||||
|
||||
if not r_power_rate.isError() and not s_power_rate.isError() and not t_power_rate.isError():
|
||||
max_power = 23036
|
||||
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)
|
||||
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time() * 1000),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name: value
|
||||
}
|
||||
value = (max_power * mean_power_rate) / 1000
|
||||
# print(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):
|
||||
|
@ -265,7 +205,7 @@ def Read_GasDetector(client, ch_num):
|
|||
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
"timestamp": int(time.time() * 1000),
|
||||
"timestamp": int(time.time()),
|
||||
"dataType": "DATA",
|
||||
"data": {
|
||||
name_1: oxygen_value,
|
||||
|
@ -278,10 +218,18 @@ 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
|
||||
client.write_registers(address=3, values=register_value, slave=id)
|
||||
# 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)
|
||||
|
||||
def Publish_mqtt(data):
|
||||
send_mqtt_data = json.dumps(data, indent=4)
|
||||
|
@ -314,17 +262,14 @@ def Command_Read():
|
|||
Set_FlowPump(client=client4, value=float(cmd['cmd']['precAc']))
|
||||
|
||||
if cmd['cmd']['tempFn1'] != 'null':
|
||||
Set_Temperature(client=client1, ch_num=1, order=cmd['type'], val=float(cmd['cmd']['tempFn1']))
|
||||
Set_Temperature(client=client1, ch_num=1, value=float(cmd['cmd']['tempFn1']))
|
||||
|
||||
if cmd['cmd']['tempFn2'] != 'null':
|
||||
Set_Temperature(client=client2, ch_num=2, order=cmd['type'], val=float(cmd['cmd']['tempFn2']))
|
||||
Set_Temperature(client=client2, ch_num=2, value=float(cmd['cmd']['tempFn1']))
|
||||
|
||||
if cmd['cmd']['tempFn3'] != 'null':
|
||||
Set_Temperature(client=client3, ch_num=3, order=cmd['type'], val=float(cmd['cmd']['tempFn3']))
|
||||
Set_Temperature(client=client2, ch_num=3, value=float(cmd['cmd']['tempFn1']))
|
||||
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 = {
|
||||
|
@ -344,12 +289,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