~jojo/huelia

06d7731c8acc7a972f88154060a714845bc2c296 — JoJo 6 months ago a9a5bc6
debug updates, only fetched by devices already running debug builds
3 files changed, 46 insertions(+), 17 deletions(-)

M .gitignore
M performer/Makefile
M performer/src/ota.rs
M .gitignore => .gitignore +1 -1
@@ 3,5 3,5 @@ secrets.h
.vscode/
.embuild/
target/
app.bin
*.bin
/help/
\ No newline at end of file

M performer/Makefile => performer/Makefile +26 -10
@@ 2,26 2,42 @@ HUELIA_BROKER=mqtt.example.com
UPDATE_HOST=cdn.example.com

.PHONY: publish
publish: Cargo.toml app.bin
publish: Cargo.toml release.bin
	WWW=$$(mktemp -d) && \
	mv app.bin $${WWW}/ && \
	mv release.bin $${WWW}/ && \
	cd $${WWW} && python -m http.server 8312 & \
	mosquitto_pub -h "${HUELIA_BROKER}" -t "huelia/update" -m \
            "($$(python3.11 bin/crate-version-lisp.py) \"http://${UPDATE_HOST}:8312/app.bin\")"; \
            "($$(python3.11 bin/crate-version-lisp.py) \"http://${UPDATE_HOST}:8312/release.bin\")"; \
	wait

.PHONY: debug-publish
debug-publish: Cargo.toml debug.bin
	WWW=$$(mktemp -d) && \
	mv debug.bin $${WWW}/ && \
	cd $${WWW} && python -m http.server 8312 & \
	mosquitto_pub -h "${HUELIA_BROKER}" -t "huelia/update" -m \
            "(debug \"http://${UPDATE_HOST}:8312/debug.bin\")"; \
	wait

.PHONY: force-publish
force-publish: Cargo.toml app.bin
force-publish: Cargo.toml release.bin
	WWW=$$(mktemp -d) && \
	mv app.bin $${WWW}/ && \
	mv release.bin $${WWW}/ && \
	cd $${WWW} && python -m http.server 8312 & \
	mosquitto_pub -h "${HUELIA_BROKER}" -t "huelia/update" -m \
            "(force \"http://${UPDATE_HOST}:8312/app.bin\")"; \
            "(force \"http://${UPDATE_HOST}:8312/release.bin\")"; \
	wait

app.bin: elf partitions.csv
	espflash save-image --chip esp32c3 app.bin target/riscv32imc-esp-espidf/release/huelia-performer
release.bin: elf-release partitions.csv
	espflash save-image --chip esp32c3 release.bin target/riscv32imc-esp-espidf/release/huelia-performer

debug.bin: elf-debug partitions.csv
	espflash save-image --chip esp32c3 debug.bin target/riscv32imc-esp-espidf/debug/huelia-performer

.PHONY: elf
elf:
.PHONY: elf-release
elf-release:
	cargo build --release

.PHONY: elf-debug
elf-debug:
	cargo build

M performer/src/ota.rs => performer/src/ota.rs +19 -6
@@ 7,10 7,11 @@ use embedded_svc::io::Write;
use esp_idf_svc::ota::EspOta;
use microcrisp::*;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, PartialEq, Eq)]
enum VersionCheck {
    Version([u16; 3]),
    Force,
    Debug,
}

fn parse(expr: &Lisp) -> Option<(VersionCheck, &str)> {


@@ 21,6 22,7 @@ fn parse(expr: &Lisp) -> Option<(VersionCheck, &str)> {
            VersionCheck::Version([vs.next()?, vs.next()?, vs.next()?])
        }
        Lisp::Symbol(symb) if *symb == Symbol::pack_str("force").unwrap() => VersionCheck::Force,
        Lisp::Symbol(symb) if *symb == Symbol::pack_str("debug").unwrap() => VersionCheck::Debug,
        _ => return None,
    };
    let url = url.as_string()?;


@@ 37,11 39,22 @@ pub fn system_update(expr: &Lisp) -> Result<()> {
    };

    log::info!("system update: version check = {version_check:?}, current version = {current_version:?}");
    if version_check > VersionCheck::Version(current_version) {
        log::info!("system update: received version check trumps current version")
    } else {
        log::info!("system update: ignoring this one, since version is not newer");
        return Ok(());
    match version_check {
        VersionCheck::Force => log::info!("system update: forced update"),
        VersionCheck::Version(v) =>
            if v > current_version {
                log::info!("system update: received version trumps current. updating")
            } else {
                log::info!("system update: ignoring this one, since version is not newer");
                return Ok(());
            },
        #[cfg(debug_assertions)]
        VersionCheck::Debug => log::info!("system update: debug update, and we're on a debug build"),
        #[cfg(not(debug_assertions))]
        VersionCheck::Debug => {
            log::info!("system update: debug update, but we're not on a debug build");
            return Ok(());
        }
    }

    let mut ota = EspOta::new()?;