From 8d082b28d98d991a3433313569d693d4c0dc00c7 Mon Sep 17 00:00:00 2001 From: "kh.kim" Date: Fri, 24 Jan 2025 10:51:53 +0900 Subject: [PATCH] Commit message --- config.json | 26 ++++++++++++++++++++------ framework.yaml | 2 +- main.py | 44 +++++++++++++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/config.json b/config.json index 7b8db0d..fb17fd8 100644 --- a/config.json +++ b/config.json @@ -1,10 +1,24 @@ { "get_data_interval": 10, - "set_zero_temperature": "y", + "set_zero_temperature": "n", "ref_zero_point": { - "oilInFlowRate": 4016, - "oilOutFlowRate": 3995, - "waterInFlowRate": 3984, - "waterOutFlowRate": 3995 + "oilInFlowRate": 6143, + "oilOutFlowRate": 5998, + "waterInFlowRate": 5778, + "waterOutFlowRate": 5758 + }, + "temperature_point": { + "ch_1": ["n", "test_ch_1"], + "ch_2": ["n", "ch_2_name"], + "ch_3": ["n", "ch_3_name"], + "ch_4": ["n", "ch_4_name"], + "ch_5": ["n", "ch_5_name"], + "ch_6": ["n", "ch_6_name"], + "ch_7": ["n", "ch_7_name"], + "ch_8": ["n", "ch_8_name"], + "ch_9": ["n", "ch_2_name"], + "ch_10": ["n", "ch_10_name"], + "ch_11": ["n", "ch_11_name"], + "ch_12": ["n", "ch_12_name"] } -} \ No newline at end of file +} diff --git a/framework.yaml b/framework.yaml index c548821..2ea40d7 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.4 # Stackbase(gitea)에 릴리즈 태그명 입니다. + tagName: v1.0.5 # Stackbase(gitea)에 릴리즈 태그명 입니다. repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다. diff --git a/main.py b/main.py index 26d11fb..31061f1 100644 --- a/main.py +++ b/main.py @@ -11,20 +11,27 @@ sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string def get_point_temperature(serial_obj): global t_col # CWT-TM-320s - res_dict = { - "topLeftTemperature": 999.99, - "topRightTemperature": 999.99, - "bottomLeftTemperature": 999.99, - "bottomRightTemperature": 999.99 - } - points = [1, 3, 7, 9] + res_dict = {} + points = [] + ch_list = [f'ch_{num}' for num in range(1, 13)] + + with open('config.json', 'r') as f: + info = json.load(f) + + t_col = [] + for key, value in info['temperature_point'].items(): + if value[0] == 'y': + t_col.append(value[1]) + points.append(ch_list.index(key) + 1) + res_dict[value[1]] = 999.99 try: res = serial_obj.read_holding_registers(address=32, count=32, slave=2) - for i, j in zip(t_col, points): + for i, j in zip(res_dict.keys(), points): res_dict[i] = res.registers[j - 1] * 0.1 except Exception as e: + print(f'error: {e}') pass return res_dict @@ -84,13 +91,17 @@ 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"] + global k_col, t_col + # col = ["topLeftTemperature", "topRightTemperature", "bottomLeftTemperature", "bottomRightTemperature", + # "oilInFlowRate", "oilInTemperature", "oilOutFlowRate", "oilOutTemperature", + # "waterInFlowRate", "waterInTemperature", "waterOutFlowRate", "waterOutTemperature"] + col = k_col + t_col + return {key: 0.0 for key in col} def runAction(): sum_data = init_data_dict() + # sum_data = {} cnt, cnt_limit = 0, 0 while True: @@ -112,9 +123,12 @@ def runAction(): pub_data = { **get_point_temperature(client1), **get_keyence_devices(client1) } - + for key, value in pub_data.items(): - sum_data[key] += value + try: + sum_data[key] += value + except: + sum_data[key] = value end = int(time.time() * 1000) diff = end - start @@ -125,7 +139,7 @@ def runAction(): sdtcloud.pubMessage(snd_data) cnt = 0 sum_data = init_data_dict() - + time.sleep(sleep_time) if __name__ == "__main__": @@ -139,6 +153,6 @@ if __name__ == "__main__": g_zero_point = [0] * 4 k_col = ["oilInFlowRate","oilInTemperature","oilOutFlowRate","oilOutTemperature", "waterInFlowRate","waterInTemperature","waterOutFlowRate","waterOutTemperature"] - t_col = ["topLeftTemperature", "topRightTemperature", "bottomLeftTemperature", "bottomRightTemperature"] + t_col = [] runAction() \ No newline at end of file