Compare commits

..

No commits in common. "main" and "Version_1.0" have entirely different histories.

1 changed files with 44 additions and 64 deletions

View File

@ -46,20 +46,13 @@ def MFC_Read_Flow(client):
ch1 = client.readline()
# print(ch1)
ch1 = str(ch1, 'utf-8')
# print(f'ch1: {ch1}')
ch1 = ch1.replace('\r', '')
# print(ch1)
if ch1 != '':
if len(ch1) < 8:
ch1 = float(ch1)
else:
ch1 = None
ch1 = float(ch1[:-1])
else:
ch1 = None
time.sleep(0.02)
client.reset_input_buffer()
command_hex = '235246320D' # '#RF2'
command_bytes = bytes.fromhex(command_hex)
@ -68,23 +61,17 @@ def MFC_Read_Flow(client):
ch2 = client.readline()
# print(ch2)
ch2 = str(ch2, 'utf-8')
# print(f'ch2: {ch2}')
ch2 = ch2.replace('\r', '')
# print(ch2)
if ch2 != '':
if len(ch2) < 8:
ch2 = float(ch2)
else:
ch2 = None
ch2 = float(ch2[:-1])
else:
ch2 = None
time.sleep(0.02)
client.reset_input_buffer()
data = {
"assetCode": info['mqtt']['assetCode'],
"timestamp": int(time.time() * 1000),
"timestamp": int(time.time()),
"dataType": "DATA",
"data": {
}
@ -136,62 +123,55 @@ def MFC_Write(client, cmd, ch, subcmd=None, value=None):
def Temp_Hum_Press_Read(client):
ch1_temp, ch1_humi, ch1_pres, ch2_temp, ch2_humi = None, None, None, None, None
command_hex = '410030305A53300D'
command_bytes = bytes.fromhex(command_hex)
client.write(command_bytes)
time.sleep(0.3)
ch1 = client.readline()
#time.sleep(0.02)
# print(f'Receive: 00 {ch1}')
parts = ch1.split()
if len(parts) > 7:
if b'\xf8C' in parts[2]:
ch1_temp = float(parts[2][:-2])
else:
ch1_temp = None
if b'RH%' in parts[3]:
ch1_humi = float(parts[3][:-3])
else:
ch1_humi = None
if b'hPa' in parts[7]:
ch1_pres = float(parts[7][:-3])
#time.sleep(5)
command_hex = '410030315A53300D'
command_bytes = bytes.fromhex(command_hex)
client.write(command_bytes)
time.sleep(0.4)
ch1 = client.readline()
time.sleep(0.02)
# print(f'Receive: 01 {ch1}')
parts = ch1.split()
for i in parts:
if b'\xf8C' in i:
i = i.replace(b'\xf8C', b'')
if i != b'':
ch1_temp = float(i)
if b'RH%' in i:
i = i.replace(b'RH%', b'')
if i != b'':
ch1_humi = float(i)
if b'hPa' in i:
i = i.replace(b'hPa', b'')
if i != b'':
ch1_pres = float(i)
client.reset_input_buffer()
command_hex = '410030305A53300D'
command_bytes = bytes.fromhex(command_hex)
client.write(command_bytes)
time.sleep(0.4)
time.sleep(0.3)
ch2 = client.readline()
time.sleep(0.02)
# print(f'Receive: 00 {ch2}')
#time.sleep(0.02)
# print(f'Receive: 01 {ch2}')
parts = ch2.split()
for i in parts:
if b'\xf8C' in i:
i = i.replace(b'\xf8C', b'')
if i != b'':
ch2_temp = float(i)
if len(parts) > 7:
if b'\xf8C' in parts[2]:
ch2_temp = float(parts[2][:-2])
else:
ch2_temp = None
if b'RH%' in i:
i = i.replace(b'RH%', b'')
if i != b'':
ch2_humi = float(i)
client.reset_input_buffer()
if b'RH%' in parts[3]:
ch2_humi = float(parts[3][:-3])
else:
ch2_humi = None
data = {
"assetCode":info['mqtt']['assetCode'],
"timestamp": int(time.time() * 1000),
"timestamp": int(time.time()),
"dataType": "DATA",
"data": {
}
@ -200,7 +180,7 @@ def Temp_Hum_Press_Read(client):
data['data']['tempOn'] = ch1_temp
if ch1_humi != None:
data['data']['humiOn'] = ch1_humi
data['data']['humiOn'] = ch1_temp
if ch1_pres != None:
data['data']['presOn'] = ch1_pres