File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1313from coderbot import CoderBot
1414from program import ProgramEngine , Program
1515from config import Config
16+ import pigpio
17+
18+ BUTTON_PIN = 16
1619
1720bot_config = Config .get ()
1821bot = CoderBot .get_instance (
@@ -118,12 +121,20 @@ def exec(data):
118121
119122def status ():
120123 sts = get_status ()
124+ # getting reset log file
125+ try :
126+ with open ('/home/pi/coderbot/logs/reset_trigger_service.log' , 'r' ) as log_file :
127+ data = [x for x in log_file .read ().split ('\n ' ) if x ]
128+ except Exception :
129+ data = [] # if file doesn't exist, no restore as ever been performed. return empty data
130+
121131
122132 return {
123133 "status" : "ok" ,
124134 "internetConnectivity" : sts ["internet_status" ],
125135 "temp" : sts ["temp" ],
126136 "uptime" : sts ["uptime" ],
137+ "log" : data
127138 }
128139
129140def info ():
@@ -206,3 +217,16 @@ def resetDefaultPrograms():
206217 with open ("data/defaults/programs/" + filename ) as p :
207218 q = p .read ()
208219 programs .insert (json .loads (q ))
220+
221+ ## Reset
222+ def reset ():
223+ pi = pigpio .pi ('localhost' )
224+ #simulating FALLING EDGE
225+ # it triggers the reset by using the service altready running on the system that detects a button press (3 sec).
226+ pi .write (BUTTON_PIN , 1 )
227+ pi .write (BUTTON_PIN , 0 )
228+
229+ return {
230+ "status" : "ok"
231+ }
232+
Original file line number Diff line number Diff line change @@ -164,12 +164,21 @@ paths:
164164 /status :
165165 get :
166166 operationId : " api.status"
167- summary : " Bot general informations and execution status"
167+ summary : " Bot general informations, execution status and reset log file "
168168 tags :
169169 - Status informations
170170 responses :
171171 200 :
172172 description : " Bot status"
173+ /reset :
174+ post :
175+ operationId : " api.reset"
176+ summary : " Reset coderbot by restoring boot partition"
177+ tags :
178+ - Coderbot reset
179+ responses :
180+ 200 :
181+ description : " resets coderbot entirely"
173182 /info :
174183 get :
175184 operationId : " api.info"
You can’t perform that action at this time.
0 commit comments