Repository navigation
feat(firmware): add over-the-air firmware and filesystem updates #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
28eba60
feat(firmware): play audio at 22050 Hz
Mechazawa ee77732
feat(firmware): add over-the-air firmware and filesystem updates
Mechazawa f9fe89e
Merge remote-tracking branch 'origin/main' into feat/ota-updates
Mechazawa 4cda0f9
refactor(firmware): make OTA an opt-in build environment
Mechazawa 4f5039e
docs: list the ota env USB upload in the no-flash rule
Mechazawa a1a3837
refactor(firmware): play audio at 22050 Hz in every build
Mechazawa c4758be
fix(scripts): upload LittleFS for the environment being flashed
Mechazawa c861698
fix(firmware): reject WAV clips that do not match the I2S format
Mechazawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Name, Type, SubType, Offset, Size, Flags | ||
| # 4MB, used by [env:ota]: two 1.5MB OTA app slots replace the coredump | ||
| # partition, and LittleFS shrinks to 960KB. | ||
| nvs, data, nvs, 0x9000, 0x5000, | ||
| otadata, data, ota, 0xe000, 0x2000, | ||
| app0, app, ota_0, 0x10000, 0x180000, | ||
| app1, app, ota_1, 0x190000,0x180000, | ||
| spiffs, data, spiffs, 0x310000,0xF0000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| Import("env") | ||
|
|
||
| import os | ||
| import subprocess | ||
| from pathlib import Path | ||
| from urllib.parse import urlparse | ||
|
|
||
| DEFAULT_HOST = "tiny-engineer.local" | ||
|
|
||
|
|
||
| def ota_host(): | ||
| url = os.environ.get("TINY_ENGINEER_URL", "") | ||
| # urlparse only finds a hostname after "//"; accept a bare host or IP too. | ||
| host = urlparse(url if "//" in url else f"//{url}").hostname | ||
| return host or DEFAULT_HOST | ||
|
|
||
|
|
||
| def espota(image, filesystem): | ||
| command = [ | ||
| env.subst("$PYTHONEXE"), | ||
| str(Path(env.PioPlatform().get_package_dir("framework-arduinoespressif32")) / "tools" / "espota.py"), | ||
| "--ip", ota_host(), | ||
| "--file", str(image), | ||
| "--progress", | ||
| ] | ||
|
|
||
| token = os.environ.get("TINY_ENGINEER_TOKEN") | ||
|
|
||
| if token: | ||
| command += ["--auth", token] | ||
|
|
||
| if filesystem: | ||
| command.append("--spiffs") | ||
|
|
||
| print(f"OTA {'filesystem' if filesystem else 'firmware'} -> {ota_host()}") | ||
| subprocess.run(command, check=True) | ||
|
|
||
|
|
||
| def upload_firmware(source, target, env): | ||
| espota(env.subst("$BUILD_DIR/${PROGNAME}.bin"), filesystem=False) | ||
|
|
||
|
|
||
| def upload_filesystem(source, target, env): | ||
| project_dir = env.subst("$PROJECT_DIR") | ||
| # The platform only wires up the LittleFS image builder when buildfs is a command-line target. | ||
| subprocess.run( | ||
| [env.subst("$PYTHONEXE"), "-m", "platformio", "run", "-t", "buildfs", "-e", env.subst("$PIOENV"), "-d", project_dir], | ||
| check=True, | ||
| ) | ||
| espota(env.subst("$BUILD_DIR/${ESP32_FS_IMAGE_NAME}.bin"), filesystem=True) | ||
|
|
||
|
|
||
| env.AddCustomTarget( | ||
| name="ota", | ||
| dependencies="$BUILD_DIR/${PROGNAME}.bin", | ||
| actions=upload_firmware, | ||
| title="Upload OTA", | ||
| description="Upload firmware over Wi-Fi", | ||
| ) | ||
|
|
||
| env.AddCustomTarget( | ||
| name="otafs", | ||
| dependencies=None, | ||
| actions=upload_filesystem, | ||
| title="Upload Filesystem OTA", | ||
| description="Upload LittleFS image over Wi-Fi", | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.