Compare commits

...

3 Commits
v1.0.1 ... main

Author SHA1 Message Date
kh.kim f235a588f0 Commit message 2024-10-29 14:59:12 +09:00
kh.kim 1951662064 Commit message 2024-10-29 14:52:22 +09:00
kh.kim c66fa01799 Commit message 2024-10-29 14:09:00 +09:00
3 changed files with 22 additions and 16 deletions

View File

@ -1,10 +1,10 @@
{
"get_data_interval": 1,
"set_zero_temperature": "n",
"get_data_interval": 10,
"set_zero_temperature": "y",
"ref_zero_point": {
"oilInFlowRate": 3989,
"oilOutFlowRate": 3978,
"oilInFlowRate": 4016,
"oilOutFlowRate": 3995,
"waterInFlowRate": 3984,
"waterOutFlowRate": 4000
"waterOutFlowRate": 3995
}
}

View File

@ -8,5 +8,5 @@ spec:
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
runtime: python3.9
stackbase:
tagName: v1.0.1 # Stackbase(gitea)에 릴리즈 태그명 입니다.
tagName: v1.0.4 # Stackbase(gitea)에 릴리즈 태그명 입니다.
repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다.

22
main.py
View File

@ -21,11 +21,12 @@ def get_point_temperature(serial_obj):
try:
res = serial_obj.read_holding_registers(address=32, count=32, slave=2)
# print(res)
for i, j in zip(t_col, points):
res_dict[i] = res.registers[j - 1] * 0.1
except Exception as e:
pass
return res_dict
def get_keyence_devices(serial_obj):
@ -51,13 +52,11 @@ def get_keyence_devices(serial_obj):
for i, j in enumerate(k_col):
if i % 2 == 0:
res_dict[j] = ((res.registers[i] - g_zero_point[i // 2]) / 16000) * 300
# print(f'Flow_rate: {flow_rate:.6f}L')
else:
res_dict[j] = ((res.registers[i] - 4000) / 16000) * 100
# print(f'Temperature: {temperature:.6f} degree')
except Exception as e:
# print(f'Error: {e}')
pass
return res_dict
def init_zero_detection(serial_obj, config_dict):
@ -84,8 +83,14 @@ def init_zero_detection(serial_obj, config_dict):
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():
sum_data = {}
sum_data = init_data_dict()
cnt, cnt_limit = 0, 0
while True:
@ -107,9 +112,10 @@ def runAction():
pub_data = {
**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)
diff = end - start
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()}
sdtcloud.pubMessage(snd_data)
cnt = 0
sum_data = init_data_dict()
time.sleep(sleep_time)
@ -135,4 +142,3 @@ if __name__ == "__main__":
t_col = ["topLeftTemperature", "topRightTemperature", "bottomLeftTemperature", "bottomRightTemperature"]
runAction()