Skip to content

Commit 906bc95

Browse files
author
Antonio Vivace
authored
Merge pull request #127 from CoderBotOrg/reset_service
Reset service
2 parents 60c333d + c10b83d commit 906bc95

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from coderbot import CoderBot
1414
from program import ProgramEngine, Program
1515
from config import Config
16+
import pigpio
17+
18+
BUTTON_PIN = 16
1619

1720
bot_config = Config.get()
1821
bot = CoderBot.get_instance(
@@ -118,12 +121,20 @@ def exec(data):
118121

119122
def 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

129140
def 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+

v2.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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"

0 commit comments

Comments
 (0)