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