Skip to content

Commit 57ffac7

Browse files
committed
Added custom_safeboot_restart_path property to support alternate API path to restart in safeboot mode
1 parent c78f4e9 commit 57ffac7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

examples/App_ESPConnect_OTA/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ board_build.partitions = partitions-4MB-safeboot.csv
4040
board_build.app_partition_name = app
4141
# custom_safeboot_dir = ../..
4242
; custom_safeboot_file = safeboot-esp32dev.bin
43+
; custom_safeboot_restart_path = /api/system/safeboot
4344

4445
; --------------------------------------------------------------------
4546
; ENVIRONMENTs

tools/safeboot.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@
44

55
quiet = False
66

7+
78
def status(msg):
89
"""Print status message to stderr"""
910
if not quiet:
1011
critical(msg)
1112

13+
1214
def critical(msg):
1315
"""Print critical message to stderr"""
1416
sys.stderr.write("safeboot.py: ")
1517
sys.stderr.write(msg)
1618
sys.stderr.write("\n")
1719

20+
1821
# open "/safeboot" on target to restart in SafeBoot-mode
1922
def safeboot(source, target, env):
2023
upload_protocol = env.GetProjectOption("upload_protocol")
2124
upload_port = env.GetProjectOption("upload_port")
22-
if upload_protocol != "espota":
25+
if upload_protocol != "espota":
2326
critical("Wrong upload protocol (%s)" % upload_protocol)
2427
raise Exception("Wrong upload protocol!")
2528
else:
26-
status("Trying to activate SafeBoot on: %s" % upload_port)
27-
req = urllib.request.Request('http://'+upload_port+'/safeboot', method='POST')
28-
try:
29+
status("Trying to activate SafeBoot on: %s" % upload_port)
30+
safeboot_path = env.GetProjectOption("custom_safeboot_restart_path", "/safeboot")
31+
req = urllib.request.Request("http://" + upload_port + safeboot_path, method="POST")
32+
try:
2933
urllib.request.urlopen(req)
3034
except urllib.error.URLError as e:
3135
critical(e)
3236
# Raise exception when SafeBoot cannot be activated
3337
pass
34-
38+
3539
status("Activated SafeBoot on: %s" % upload_port)
3640

41+
3742
env.AddPreAction("upload", safeboot)
3843
env.AddPreAction("uploadfs", safeboot)
3944
env.AddPreAction("uploadfsota", safeboot)

0 commit comments

Comments
 (0)