Include OTA upload script
This commit is contained in:
parent
d6ecad9be6
commit
bb2b31c042
2 changed files with 56 additions and 0 deletions
|
@ -25,3 +25,6 @@ build_flags =
|
||||||
-DCORE_DEBUG_LEVEL=4
|
-DCORE_DEBUG_LEVEL=4
|
||||||
-DBOARD_HAS_PSRAM
|
-DBOARD_HAS_PSRAM
|
||||||
-mfix-esp32-psram-cache-issue
|
-mfix-esp32-psram-cache-issue
|
||||||
|
extra_scripts = platformio_upload.py
|
||||||
|
upload_protocol = custom
|
||||||
|
upload_url = http://esp32-874bbc/update
|
||||||
|
|
53
platformio_upload.py
Normal file
53
platformio_upload.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# Allows PlatformIO to upload directly to AsyncElegantOTA
|
||||||
|
#
|
||||||
|
# To use:
|
||||||
|
# - copy this script into the same folder as your platformio.ini
|
||||||
|
# - set the following for your project in platformio.ini:
|
||||||
|
#
|
||||||
|
# extra_scripts = platformio_upload.py
|
||||||
|
# upload_protocol = custom
|
||||||
|
# upload_url = <your upload URL>
|
||||||
|
#
|
||||||
|
# An example of an upload URL:
|
||||||
|
# upload_URL = http://192.168.1.123/update
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import hashlib
|
||||||
|
Import('env')
|
||||||
|
|
||||||
|
try:
|
||||||
|
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
|
||||||
|
from tqdm import tqdm
|
||||||
|
except ImportError:
|
||||||
|
env.Execute("$PYTHONEXE -m pip install requests_toolbelt")
|
||||||
|
env.Execute("$PYTHONEXE -m pip install tqdm")
|
||||||
|
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
def on_upload(source, target, env):
|
||||||
|
firmware_path = str(source[0])
|
||||||
|
upload_url = env.GetProjectOption('upload_url')
|
||||||
|
|
||||||
|
with open(firmware_path, 'rb') as firmware:
|
||||||
|
md5 = hashlib.md5(firmware.read()).hexdigest()
|
||||||
|
firmware.seek(0)
|
||||||
|
encoder = MultipartEncoder(fields={
|
||||||
|
'MD5': md5,
|
||||||
|
'firmware': ('firmware', firmware, 'application/octet-stream')}
|
||||||
|
)
|
||||||
|
|
||||||
|
bar = tqdm(desc='Upload Progress',
|
||||||
|
total=encoder.len,
|
||||||
|
dynamic_ncols=True,
|
||||||
|
unit='B',
|
||||||
|
unit_scale=True,
|
||||||
|
unit_divisor=1024
|
||||||
|
)
|
||||||
|
|
||||||
|
monitor = MultipartEncoderMonitor(encoder, lambda monitor: bar.update(monitor.bytes_read - bar.n))
|
||||||
|
|
||||||
|
response = requests.post(upload_url, data=monitor, headers={'Content-Type': monitor.content_type})
|
||||||
|
bar.close()
|
||||||
|
print(response,response.text)
|
||||||
|
|
||||||
|
env.Replace(UPLOADCMD=on_upload)
|
Loading…
Reference in a new issue