Compare commits

..

No commits in common. "main" and "v1.0.2" have entirely different histories.
main ... v1.0.2

3 changed files with 15 additions and 21 deletions

View File

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

View File

@ -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.4 # Stackbase(gitea)에 릴리즈 태그명 입니다. tagName: v1.0.2 # Stackbase(gitea)에 릴리즈 태그명 입니다.
repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다. repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다.

22
main.py
View File

@ -21,12 +21,11 @@ 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):
@ -52,11 +51,13 @@ 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):
@ -83,14 +84,8 @@ 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 = init_data_dict() sum_data = {}
cnt, cnt_limit = 0, 0 cnt, cnt_limit = 0, 0
while True: while True:
@ -112,10 +107,9 @@ 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)
for key, value in pub_data.items(): sum_data = Counter(sum_data) + Counter(pub_data)
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)
@ -124,7 +118,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() sum_data = {}
time.sleep(sleep_time) time.sleep(sleep_time)