- ArduinoOTA in web_server.cpp integriert (Hostname: lasercutter-display) - WebServerManager::loop() hinzugefuegt -> ArduinoOTA.handle() - webServer.loop() in main.cpp aufgerufen - platformio.ini: gemeinsamer [env]-Basisblock (lib_deps einmalig) - Neues env az-delivery-devkit-v4-ota (espota, upload_flags --auth Anleitung) - Neues env az-delivery-devkit-v4-ota-http (ElegantOTA HTTP Fallback) - upload_ota.py: HTTP-Multipart-Upload Script fuer ElegantOTA - README.md: Abschnitt Via WiFi (OTA) mit Passwort-Anleitung - Implementation-Plan.md: Task 9.9 dokumentiert
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
# upload_ota.py – OTA-Upload via ElegantOTA HTTP-Endpoint
|
||
# PlatformIO extra_script: ersetzt den Upload-Befehl durch HTTP-POST an /update
|
||
#
|
||
# Verwendung: pio run -e az-delivery-devkit-v4-ota --target upload
|
||
# IP-Adresse in platformio.ini: upload_port = 192.168.x.x
|
||
|
||
Import("env")
|
||
|
||
import urllib.request
|
||
import os
|
||
|
||
def do_ota_upload(source, target, env):
|
||
firmware_path = str(source[0])
|
||
ip = env.get("UPLOAD_PORT", "")
|
||
|
||
if not ip:
|
||
print("FEHLER: upload_port in platformio.ini nicht gesetzt!")
|
||
env.Exit(1)
|
||
|
||
url = f"http://{ip}/update"
|
||
print(f"\n=== OTA Upload ===")
|
||
print(f" Firmware : {firmware_path}")
|
||
print(f" Ziel : {url}")
|
||
print(f" Groesse : {os.path.getsize(firmware_path)} Bytes")
|
||
|
||
boundary = "ElegantOtaBoundary"
|
||
with open(firmware_path, "rb") as f:
|
||
firmware_data = f.read()
|
||
|
||
body = (
|
||
f"--{boundary}\r\n"
|
||
f'Content-Disposition: form-data; name="firmware"; filename="firmware.bin"\r\n'
|
||
f"Content-Type: application/octet-stream\r\n\r\n"
|
||
).encode() + firmware_data + f"\r\n--{boundary}--\r\n".encode()
|
||
|
||
req = urllib.request.Request(
|
||
url,
|
||
data=body,
|
||
method="POST",
|
||
headers={"Content-Type": f"multipart/form-data; boundary={boundary}"}
|
||
)
|
||
try:
|
||
with urllib.request.urlopen(req, timeout=60) as resp:
|
||
result = resp.read().decode("utf-8", errors="ignore")
|
||
print(f" Status : {resp.status} {resp.reason}")
|
||
print(f" Antwort : {result}")
|
||
print("=== Upload erfolgreich - ESP32 startet neu ===\n")
|
||
except Exception as e:
|
||
print(f"\nFEHLER beim OTA-Upload: {e}")
|
||
env.Exit(1)
|
||
|
||
env.Replace(UPLOADCMD=do_ota_upload)
|