-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_script.py
More file actions
31 lines (24 loc) · 964 Bytes
/
upload_script.py
File metadata and controls
31 lines (24 loc) · 964 Bytes
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
import requests
import sys
from SCons.Script import Import
Import("env")
def on_upload(source, target, env):
firmware_path = str(source[0])
upload_url = env.GetProjectOption("upload_port")
print(f"\nUploading {firmware_path} to {upload_url} ...")
try:
with open(firmware_path, "rb") as f:
# The 'update' key matches the <input name="update"> in your ESP32 HTML
response = requests.post(upload_url, files={"update": f})
if response.status_code == 200:
print("\n[SUCCESS] Firmware uploaded successfully!")
print(f"Server Response: {response.text}")
else:
print(f"\n[ERROR] Upload failed. Status Code: {response.status_code}")
print(f"Response: {response.text}")
sys.exit(1)
except Exception as e:
print(f"\n[ERROR] Connection failed: {e}")
sys.exit(1)
# Register the upload handler
env.Replace(UPLOADCMD=on_upload)