Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
kh.kim | f235a588f0 | |
kh.kim | 1951662064 | |
kh.kim | c66fa01799 |
10
config.json
10
config.json
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"get_data_interval": 1,
|
"get_data_interval": 10,
|
||||||
"set_zero_temperature": "n",
|
"set_zero_temperature": "y",
|
||||||
"ref_zero_point": {
|
"ref_zero_point": {
|
||||||
"oilInFlowRate": 3989,
|
"oilInFlowRate": 4016,
|
||||||
"oilOutFlowRate": 3978,
|
"oilOutFlowRate": 3995,
|
||||||
"waterInFlowRate": 3984,
|
"waterInFlowRate": 3984,
|
||||||
"waterOutFlowRate": 4000
|
"waterOutFlowRate": 3995
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,5 +8,5 @@ spec:
|
||||||
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
|
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
|
||||||
runtime: python3.9
|
runtime: python3.9
|
||||||
stackbase:
|
stackbase:
|
||||||
tagName: v1.0.1 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
tagName: v1.0.4 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
||||||
repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다.
|
repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다.
|
||||||
|
|
22
main.py
22
main.py
|
@ -21,11 +21,12 @@ def get_point_temperature(serial_obj):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = serial_obj.read_holding_registers(address=32, count=32, slave=2)
|
res = serial_obj.read_holding_registers(address=32, count=32, slave=2)
|
||||||
# print(res)
|
|
||||||
for i, j in zip(t_col, points):
|
for i, j in zip(t_col, points):
|
||||||
res_dict[i] = res.registers[j - 1] * 0.1
|
res_dict[i] = res.registers[j - 1] * 0.1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return res_dict
|
return res_dict
|
||||||
|
|
||||||
def get_keyence_devices(serial_obj):
|
def get_keyence_devices(serial_obj):
|
||||||
|
@ -51,13 +52,11 @@ def get_keyence_devices(serial_obj):
|
||||||
for i, j in enumerate(k_col):
|
for i, j in enumerate(k_col):
|
||||||
if i % 2 == 0:
|
if i % 2 == 0:
|
||||||
res_dict[j] = ((res.registers[i] - g_zero_point[i // 2]) / 16000) * 300
|
res_dict[j] = ((res.registers[i] - g_zero_point[i // 2]) / 16000) * 300
|
||||||
# print(f'Flow_rate: {flow_rate:.6f}L')
|
|
||||||
else:
|
else:
|
||||||
res_dict[j] = ((res.registers[i] - 4000) / 16000) * 100
|
res_dict[j] = ((res.registers[i] - 4000) / 16000) * 100
|
||||||
# print(f'Temperature: {temperature:.6f} degree')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# print(f'Error: {e}')
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return res_dict
|
return res_dict
|
||||||
|
|
||||||
def init_zero_detection(serial_obj, config_dict):
|
def init_zero_detection(serial_obj, config_dict):
|
||||||
|
@ -84,8 +83,14 @@ def init_zero_detection(serial_obj, config_dict):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def init_data_dict():
|
||||||
|
col = ["topLeftTemperature", "topRightTemperature", "bottomLeftTemperature", "bottomRightTemperature",
|
||||||
|
"oilInFlowRate", "oilInTemperature", "oilOutFlowRate", "oilOutTemperature",
|
||||||
|
"waterInFlowRate", "waterInTemperature", "waterOutFlowRate", "waterOutTemperature"]
|
||||||
|
return {key: 0.0 for key in col}
|
||||||
|
|
||||||
def runAction():
|
def runAction():
|
||||||
sum_data = {}
|
sum_data = init_data_dict()
|
||||||
cnt, cnt_limit = 0, 0
|
cnt, cnt_limit = 0, 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -107,9 +112,10 @@ def runAction():
|
||||||
pub_data = {
|
pub_data = {
|
||||||
**get_point_temperature(client1), **get_keyence_devices(client1)
|
**get_point_temperature(client1), **get_keyence_devices(client1)
|
||||||
}
|
}
|
||||||
print(int(time.time() * 1000), pub_data)
|
|
||||||
|
|
||||||
sum_data = Counter(sum_data) + Counter(pub_data)
|
for key, value in pub_data.items():
|
||||||
|
sum_data[key] += value
|
||||||
|
|
||||||
end = int(time.time() * 1000)
|
end = int(time.time() * 1000)
|
||||||
diff = end - start
|
diff = end - start
|
||||||
sleep_time = int(interval / cnt_limit) - (diff * 0.001)
|
sleep_time = int(interval / cnt_limit) - (diff * 0.001)
|
||||||
|
@ -118,6 +124,7 @@ def runAction():
|
||||||
snd_data = {key: value / cnt_limit for key, value in sum_data.items()}
|
snd_data = {key: value / cnt_limit for key, value in sum_data.items()}
|
||||||
sdtcloud.pubMessage(snd_data)
|
sdtcloud.pubMessage(snd_data)
|
||||||
cnt = 0
|
cnt = 0
|
||||||
|
sum_data = init_data_dict()
|
||||||
|
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
|
@ -135,4 +142,3 @@ if __name__ == "__main__":
|
||||||
t_col = ["topLeftTemperature", "topRightTemperature", "bottomLeftTemperature", "bottomRightTemperature"]
|
t_col = ["topLeftTemperature", "topRightTemperature", "bottomLeftTemperature", "bottomRightTemperature"]
|
||||||
|
|
||||||
runAction()
|
runAction()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue