Commit message

This commit is contained in:
support.sampyo 2024-05-29 05:51:51 +00:00
parent d1a2dd1027
commit e5d745c4e1
3 changed files with 68 additions and 8 deletions

View File

@ -29,5 +29,11 @@
"action": "Off"
}
},
"maintenance": {
"clean": {
"duration": 20,
"time": 25
}
},
"type": "manual"
}

View File

@ -7,5 +7,5 @@ spec:
virtualEnv: base # 사용할 가상환경 이름입니다.
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
stackbase:
tagName: v0.0.27 # Stackbase(gitea)에 릴리즈 태그명 입니다.
tagName: v0.0.28 # Stackbase(gitea)에 릴리즈 태그명 입니다.
repoName: sampyo-dio # Stackbase(gitea)에 저장될 저장소 이릅니다.

68
main.py
View File

@ -97,8 +97,6 @@ def Command_Read():
vent_holding = int(cmd['device']['vent']['holding'])
measure_duration = int(cmd['device']['measure']['duration'])
enter_duration = int(cmd['device']['enter']['duration'])
time.sleep(7)
start = Measure_Weight(client=client)
time.sleep(5)
@ -132,18 +130,22 @@ def Command_Read():
Valve_PureWater(chip=output_lines, status=status, action='On')
time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='On')
time.sleep(pure_holding)
time.sleep(0.5)
# 3) Open Vent
Valve_Vent(chip=output_lines, status=status, action='On')
time.sleep(pure_duration)
Valve_Vent(chip=output_lines, status=status, action='Off')
time.sleep(0.5)
Valve_PureWater(chip=output_lines, status=status, action='Off')
time.sleep(0.5)
Valve_EnterWater(chip=output_lines, status=status, action='Off')
# 4) Wait until empty
Valve_Vent(chip=output_lines, status=status, action='On')
time.sleep(vent_duration)
time.sleep(0.5)
# 5) Motor Off and Vent close
Motor(chip=output_lines, status=status, action='Off')
@ -152,7 +154,10 @@ def Command_Read():
time.sleep(0.5)
return 1
elif cmd['type'] == 'clean':
clean_system()
else: # cmd['type'] == 'manual'
Motor(chip=output_lines, status=status, action=cmd['device']['motor']['action'])
Valve_Vent(chip=output_lines, status=status, action=cmd['device']['vent']['action'])
@ -170,6 +175,25 @@ def Command_Read():
return 0
def clean_system():
with open('./control.json', 'r') as f:
cmd = json.load(f)
clean_duration = int(cmd['maintenace']['clean']['duration'])
if cmd['type'] == 'clean':
Valve_EnterWater(chip=output_lines, status=status, action='Off')
time.sleep(0.5)
Value_PureWater(chip=output_lines, status=status, action='On')
time.sleep(0.5)
Value_MixedWater(chip=output_lines, status=status, action='On')
time.sleep(clean_duration)
Value_PureWater(chip=output_lines, status=status, action='Off')
time.sleep(0.5)
Value_MixedWater(chip=output_lines, status=status, action='Off')
time.sleep(6)
def runAction():
# Write the app's actions in the "runAction" function.
@ -195,6 +219,7 @@ def runAction():
# - You may need it to create a topic.
cnt = 0
clean_flag = 0
while True:
start = time.time()
result = Command_Read()
@ -207,7 +232,21 @@ def runAction():
cnt = 0
end = time.time()
try:
now = datetime.now(pytz.timezone('Asia/Seoul'))
time_str = now.strftime('%H')
time_int = int(time_str)
if time_int == int(cmd['maintenance']['clean']['time']):
if clean_flag < 3:
clean_flag += 1
clean_system()
else:
clean_flag = 0
except:
pass
diff = end - start
if diff < 3:
time.sleep(3 - diff)
@ -267,7 +306,22 @@ def handle_client(conn, ip, port):
except Exception as e:
err_msg = 'STXERRORETX'
conn.sendall(err_msg.encode("utf8"))
elif message[3] == 'C': # Clean sequence
try:
with open('./control.json', 'r') as f:
cmd = json.load(f)
cmd['type'] = 'clean'
with open('./control.json', 'w') as f:
json.dunp(cmd, f, indent=4)
send_msg = 'STXOKETX'
conn.sendall(send_msg.encode("utf8"))
except Exception as e:
err_msg = 'STXERRORETX'
conn.sendall(err_msg.encode("utf8"))
elif message[3] == 'T': # Stop measurement
try:
with open('./control.json', 'r') as f: