From 19516620648b083ead78cb8cf82a91b308edb40b Mon Sep 17 00:00:00 2001 From: "kh.kim" Date: Tue, 29 Oct 2024 14:52:22 +0900 Subject: [PATCH] Commit message --- config.json | 10 +++++----- framework.yaml | 2 +- main.py | 23 ++++++++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/config.json b/config.json index 07d9365..e6b0791 100644 --- a/config.json +++ b/config.json @@ -1,10 +1,10 @@ { - "get_data_interval": 1, + "get_data_interval": 10, "set_zero_temperature": "n", "ref_zero_point": { - "oilInFlowRate": 3989, - "oilOutFlowRate": 3978, + "oilInFlowRate": 4016, + "oilOutFlowRate": 3995, "waterInFlowRate": 3984, - "waterOutFlowRate": 4000 + "waterOutFlowRate": 3995 } -} +} \ No newline at end of file diff --git a/framework.yaml b/framework.yaml index db33cf2..af6b27e 100644 --- a/framework.yaml +++ b/framework.yaml @@ -8,5 +8,5 @@ spec: package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.) runtime: python3.9 stackbase: - tagName: v1.0.2 # Stackbase(gitea)에 릴리즈 태그명 입니다. + tagName: v1.0.3 # Stackbase(gitea)에 릴리즈 태그명 입니다. repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다. diff --git a/main.py b/main.py index 213f277..6d5343f 100644 --- a/main.py +++ b/main.py @@ -47,16 +47,14 @@ def get_keyence_devices(serial_obj): try: res = serial_obj.read_holding_registers(address=50, count=8, slave=5) - + print(f'k_col: {k_col} g_zero: {g_zero_point}') 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') + print(f'[{j}] Flow_rate: {res_dict[j]:.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 @@ -84,8 +82,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,18 +111,19 @@ 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) cnt += 1 if cnt == cnt_limit: - 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() if value != 0.0} sdtcloud.pubMessage(snd_data) cnt = 0 - sum_data = {} + sum_data = init_data_dict() time.sleep(sleep_time)