Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf031b55b7 | ||
|
|
c92adaed01 | ||
|
|
2f5f457ffc |
No files matched your search
@@ -0,0 +1,128 @@
|
|||||||
|
name: release
|
||||||
|
|
||||||
|
# Every commit to main builds the firmware and publishes a release.
|
||||||
|
#
|
||||||
|
# The version is MAJOR.MINOR from the version in Cargo.toml, with the number
|
||||||
|
# of commits on main as the patch number, so it only ever goes up and can be
|
||||||
|
# worked out again from any commit: Cargo.toml saying 0.1.0 gives 0.1.57 for
|
||||||
|
# the 57th commit. Change MAJOR or MINOR in Cargo.toml to start a new series.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
# Must match a label of the Gitea runner.
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
ESPFLASH_VERSION: v4.6.0
|
||||||
|
steps:
|
||||||
|
- name: Check out the repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# the commit count and the previous release tag need the history
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Fetch the Zigbee stack
|
||||||
|
run: |
|
||||||
|
# the submodule is declared with an SSH address; a runner has no key
|
||||||
|
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||||
|
git submodule update --init
|
||||||
|
|
||||||
|
- name: Work out the version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
base=$(sed -n 's/^version = "\([0-9]*\.[0-9]*\)\..*"/\1/p' Cargo.toml | head -n 1)
|
||||||
|
count=$(git rev-list --count HEAD)
|
||||||
|
version="$base.$count"
|
||||||
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Releasing $version"
|
||||||
|
|
||||||
|
# the firmware reads its version from the package, so this is what
|
||||||
|
# ends up in the app descriptor and the boot log
|
||||||
|
sed -i '0,/^version = ".*"/s//version = "'"$version"'"/' Cargo.toml
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
run: |
|
||||||
|
if ! command -v rustup > /dev/null; then
|
||||||
|
curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain none
|
||||||
|
fi
|
||||||
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
# installs the toolchain, components and target that
|
||||||
|
# rust-toolchain.toml asks for
|
||||||
|
rustup toolchain install || true
|
||||||
|
cargo --version
|
||||||
|
|
||||||
|
- name: Install espflash
|
||||||
|
run: |
|
||||||
|
curl -fsSL -o espflash.zip \
|
||||||
|
"https://github.com/esp-rs/espflash/releases/download/${ESPFLASH_VERSION}/espflash-x86_64-unknown-linux-musl.zip"
|
||||||
|
python3 -m zipfile -e espflash.zip "$HOME/espflash-bin"
|
||||||
|
chmod +x "$HOME/espflash-bin/espflash"
|
||||||
|
echo "$HOME/espflash-bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Build the firmware
|
||||||
|
run: cargo build --release
|
||||||
|
|
||||||
|
- name: Package the images
|
||||||
|
env:
|
||||||
|
VERSION: ${{ steps.version.outputs.version }}
|
||||||
|
run: |
|
||||||
|
elf=target/riscv32imac-unknown-none-elf/release/smart-light
|
||||||
|
mkdir dist
|
||||||
|
|
||||||
|
# the application on its own: what goes into a firmware slot
|
||||||
|
espflash save-image --chip esp32c6 --flash-size 4mb "$elf" "dist/smart-light-$VERSION.bin"
|
||||||
|
|
||||||
|
# bootloader, partition table and application, to be written at
|
||||||
|
# address 0. Without padding it stops short of the storage
|
||||||
|
# partition, so flashing it keeps the light's Zigbee network.
|
||||||
|
espflash save-image --chip esp32c6 --flash-size 4mb --merge --skip-padding \
|
||||||
|
--partition-table partitions.csv "$elf" "dist/smart-light-$VERSION-full.bin"
|
||||||
|
|
||||||
|
# for decoding backtraces
|
||||||
|
gzip -9 -c "$elf" > "dist/smart-light-$VERSION.elf.gz"
|
||||||
|
|
||||||
|
(cd dist && sha256sum * > SHA256SUMS)
|
||||||
|
ls -l dist
|
||||||
|
|
||||||
|
- name: Publish the release
|
||||||
|
env:
|
||||||
|
VERSION: ${{ steps.version.outputs.version }}
|
||||||
|
# the job's own token if it may create releases, otherwise a token
|
||||||
|
# kept in the RELEASE_TOKEN secret
|
||||||
|
TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
|
||||||
|
API: ${{ github.server_url }}/api/v1
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
previous=$(git describe --tags --abbrev=0 --match 'v*' 2> /dev/null || true)
|
||||||
|
notes=$(git log --no-merges --pretty='- %s (%h)' -n 50 ${previous:+"$previous..HEAD"})
|
||||||
|
|
||||||
|
payload=$(python3 -c '
|
||||||
|
import json, sys
|
||||||
|
version, sha, notes = sys.argv[1:4]
|
||||||
|
body = "Built from " + sha[:7] + ".\n\n" + notes
|
||||||
|
print(json.dumps({
|
||||||
|
"tag_name": "v" + version,
|
||||||
|
"target_commitish": sha,
|
||||||
|
"name": "smart-light " + version,
|
||||||
|
"body": body,
|
||||||
|
"draft": False,
|
||||||
|
"prerelease": False,
|
||||||
|
}))' "$VERSION" "$GITHUB_SHA" "$notes")
|
||||||
|
|
||||||
|
response=$(curl -fsS -X POST \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$payload" "$API/repos/$REPO/releases")
|
||||||
|
id=$(printf '%s' "$response" | python3 -c 'import json, sys; print(json.load(sys.stdin)["id"])')
|
||||||
|
|
||||||
|
for file in dist/*; do
|
||||||
|
curl -fsS -X POST \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
-F "attachment=@$file" \
|
||||||
|
"$API/repos/$REPO/releases/$id/assets?name=$(basename "$file")" > /dev/null
|
||||||
|
echo "uploaded $(basename "$file")"
|
||||||
|
done
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
name = "smart-light"
|
name = "smart-light"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["esp32c6", "zigbee"]
|
default = ["esp32c6", "zigbee"]
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Matt Spencer
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -119,3 +119,34 @@ sets its speed and intensity. Home Assistant needs a quirk to talk to it:
|
|||||||
|
|
||||||
3. Restart Home Assistant. The light then has an Effect select and Effect speed
|
3. Restart Home Assistant. The light then has an Effect select and Effect speed
|
||||||
and Effect intensity sliders.
|
and Effect intensity sliders.
|
||||||
|
|
||||||
|
## Releases
|
||||||
|
|
||||||
|
Every commit to `main` builds the firmware on the Gitea runner and publishes a
|
||||||
|
release (`.gitea/workflows/release.yml`).
|
||||||
|
|
||||||
|
The version is the `MAJOR.MINOR` of the version in `Cargo.toml` followed by the
|
||||||
|
number of commits on `main`, so with `0.1.0` in `Cargo.toml` the 57th commit
|
||||||
|
becomes `0.1.57`. It only goes up, and can be worked out again from any commit.
|
||||||
|
To start a new series, change the major or minor number in `Cargo.toml`. The
|
||||||
|
build writes the version into the firmware, which logs it at boot, and the
|
||||||
|
release is tagged `v` plus the version.
|
||||||
|
|
||||||
|
Each release has:
|
||||||
|
|
||||||
|
- `smart-light-<version>-full.bin`: bootloader, partition table and
|
||||||
|
application. Write it at address 0 with
|
||||||
|
`espflash write-bin 0x0 smart-light-<version>-full.bin`. It stops short of
|
||||||
|
the `storage` partition, so the light keeps its Zigbee network.
|
||||||
|
- `smart-light-<version>.bin`: the application alone, for a firmware slot.
|
||||||
|
- `smart-light-<version>.elf.gz`: the unstripped build, for decoding backtraces.
|
||||||
|
- `SHA256SUMS`.
|
||||||
|
|
||||||
|
The workflow's `runs-on` must match a label of your Gitea runner. If the job's
|
||||||
|
own token is not allowed to create releases, add a token with write access to
|
||||||
|
the repository as a secret named `RELEASE_TOKEN`.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Released under the [MIT License](LICENSE). The Zigbee stack in
|
||||||
|
`vendor/zigbee-rs` is a separate project with its own licenses.
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# TODO
|
||||||
|
|
||||||
|
Things that are known to be open. None of these is being worked on yet.
|
||||||
|
|
||||||
|
## Reliability
|
||||||
|
|
||||||
|
- [ ] **The Zigbee stack forgets its network after a short coordinator outage.**
|
||||||
|
A failed rejoin is followed by a second attempt that, if it also fails,
|
||||||
|
wipes the network keys and falls back to a fresh join, which needs the
|
||||||
|
coordinator's pairing window to be open. This took the light off the network
|
||||||
|
when the server rebooted (18 Nov) and, most likely, again when Home Assistant
|
||||||
|
restarted (24 Nov; inferred, the failure itself was not captured). Each time
|
||||||
|
it needed re-pairing.
|
||||||
|
- Where: `commission` and `link_maintenance` in
|
||||||
|
`vendor/zigbee-rs/zigbee/src/stack.rs`, and the retry loop in
|
||||||
|
`stack_task` (`src/zigbee_stack.rs`).
|
||||||
|
- Idea: keep the saved network and keep retrying the rejoin with a back-off,
|
||||||
|
and only forget it after a long failure (say 30 minutes), an explicit
|
||||||
|
leave, or a network mismatch.
|
||||||
|
- It is a library change, so it belongs on its own branch off upstream
|
||||||
|
`main`, separate from the effects work.
|
||||||
|
- The 10-second button hold makes recovery easy, but does not prevent it.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
- [ ] **The Zigbee network ID and channel are hardcoded** in
|
||||||
|
`src/zigbee_stack.rs` (`EXTENDED_PAN_ID`, `CHANNEL`). The ID is broadcast by
|
||||||
|
the network and is not a secret, but it means a light only pairs with one
|
||||||
|
network.
|
||||||
|
- Why it is pinned: the stack takes both from its configuration. Resuming
|
||||||
|
after a reboot tunes to the first configured channel rather than the
|
||||||
|
channel that was joined, and rejoin looks for the configured network ID.
|
||||||
|
A wildcard ID or a range of channels would therefore break resume.
|
||||||
|
- Options: change the library to use the channel and ID it remembers, or have
|
||||||
|
the app save the network it joined in its own flash and build the
|
||||||
|
configuration from that.
|
||||||
|
- [ ] **Light and effect state is not saved across reboots.** On/off, level,
|
||||||
|
colour and the selected effect all start from their defaults.
|
||||||
|
- [ ] **The effects cluster uses development identifiers.** Manufacturer code
|
||||||
|
`0xC0DE` is not assigned to anyone, and the cluster ID is `0xFD00`. Decide on
|
||||||
|
proper values and change them together in `src/effects_cluster.rs` and
|
||||||
|
`ha/zha_quirks/smart_light.py`.
|
||||||
|
- [ ] **The effect attributes are not reportable**, so Home Assistant only
|
||||||
|
knows what it last wrote. Fine while nothing else changes them; revisit if
|
||||||
|
effects can be changed locally.
|
||||||
|
|
||||||
|
## Upstream zigbee-rs
|
||||||
|
|
||||||
|
- [ ] **Open PRs for the two branches already pushed to the fork**, each as its
|
||||||
|
own PR off upstream `main`:
|
||||||
|
- `feature/identify-trigger-effect`
|
||||||
|
- `feature/manufacturer-specific-clusters`
|
||||||
|
- [ ] **PR #109 (RGB colour control)** is open and has had review comments
|
||||||
|
applied. Squash-merge when approved.
|
||||||
|
- [ ] **Spec questions to raise in review.** Neither PR can say what ZCL
|
||||||
|
requires, so both pick an answer and flag it:
|
||||||
|
- Trigger Effect with an undefined effect or variant answers `INVALID_FIELD`.
|
||||||
|
- A frame for a manufacturer-specific cluster with the wrong manufacturer
|
||||||
|
code answers `UNSUP_COMMAND`.
|
||||||
|
- [ ] **After the PRs merge**, point the submodule at upstream (or the fork's
|
||||||
|
`main`) instead of `feature/lighting-effects-integration`, and delete the
|
||||||
|
integration branch.
|
||||||
|
|
||||||
|
## Testing gaps
|
||||||
|
|
||||||
|
Not yet tried on the hardware (the commit messages say so too):
|
||||||
|
|
||||||
|
- [ ] Trigger Effect: Okay, Channel change, Finish effect and Stop effect sent
|
||||||
|
from a coordinator. Only blink and breathe (ZHA's `flash`) were tried.
|
||||||
|
- [ ] Manufacturer-specific attribute reports.
|
||||||
|
- [ ] Rejection of a frame that carries the wrong manufacturer code.
|
||||||
|
|
||||||
|
## Housekeeping
|
||||||
|
|
||||||
|
- [ ] **`.gitmodules` uses an SSH URL** for the submodule
|
||||||
|
(`git@github.com:m5p3nc3r/zigbee-rs.git`). Switch to HTTPS if cloning from a
|
||||||
|
network that blocks SSH.
|
||||||
|
- [ ] **Older commits point at submodule commits that no longer exist on any
|
||||||
|
branch**, because the integration branch was rebased. The tip works, but
|
||||||
|
checking out an old commit and updating the submodule can fail.
|
||||||
|
- [ ] **Pre-existing `rustfmt` differences**: 1 in `src/light.rs` and 7 in
|
||||||
|
`src/zigbee_stack.rs`. Cosmetic; fix in a commit of their own.
|
||||||
|
- [ ] **No licence file.** Decide on one.
|
||||||
@@ -41,6 +41,7 @@ const BRIGHTNESS_STEP: i16 = 8;
|
|||||||
#[esp_rtos::main]
|
#[esp_rtos::main]
|
||||||
async fn main(spawner: embassy_executor::Spawner) -> ! {
|
async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||||
esp_println::logger::init_logger_from_env();
|
esp_println::logger::init_logger_from_env();
|
||||||
|
log::info!("smart-light {}", env!("CARGO_PKG_VERSION"));
|
||||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||||
|
|
||||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
|
|||||||
Reference in new issue
Block a user