-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
62 lines (50 loc) · 1.57 KB
/
Copy pathSConstruct
File metadata and controls
62 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
PlatformIO build customization.
Adds upload_ota task to the project tasks UI.
Usage: pio run -e esp32s3 -t upload_ota [--host=IP]
"""
import os
import subprocess
from pathlib import Path
Import("env")
def upload_ota_action(target, source, env):
"""Upload firmware via OTA to device."""
# Get host from command line (--host=192.168.1.50) or default
host = "192.168.4.1"
for arg in ARGUMENTS.keys():
if arg.startswith("host"):
host = ARGUMENTS.get(arg)
break
firmware_path = env.subst("$BUILD_DIR/${PROGNAME}.bin")
url = f"http://{host}/api/ota"
if not Path(firmware_path).exists():
print(f"ERROR: Firmware not found at {firmware_path}")
return 1
print(f"\n{'='*70}")
print(f"OTA Upload")
print(f"{'='*70}")
print(f"Target: {url}")
print(f"Firmware: {firmware_path}")
print(f"{'='*70}\n")
cmd = [
"curl",
"-X", "POST",
"--data-binary", f"@{firmware_path}",
url
]
result = subprocess.run(cmd)
if result.returncode != 0:
print(f"\nERROR: OTA upload failed (curl exit code {result.returncode})")
return 1
print(f"\n{'='*70}")
print("✓ OTA upload complete! Device is rebooting with new firmware.")
print(f"{'='*70}\n")
return 0
# Register upload_ota as a custom target
env.AddCustomTarget(
name="upload_ota",
dependencies=["buildprog"],
actions=[upload_ota_action],
title="Upload OTA",
description="Build and upload firmware via OTA to device (default: 192.168.4.1, use --host=IP for custom)"
)