Skip to content

Add HLW8012 monitoring CI support and fix cargo deny issues#4

Merged
MDr164 merged 5 commits intomainfrom
sensor
Mar 18, 2026
Merged

Add HLW8012 monitoring CI support and fix cargo deny issues#4
MDr164 merged 5 commits intomainfrom
sensor

Conversation

@MDr164
Copy link
Copy Markdown
Collaborator

@MDr164 MDr164 commented Mar 17, 2026

No description provided.

MDr164 and others added 5 commits March 17, 2026 15:30
When an admin changes their password the first_login flag was never
cleared, so the UI would keep prompting for a password change on
every subsequent login.

Write KEY_ADMIN_FIRST_LOGIN = b"0" inside the same write transaction
before the password key to satisfy ekv's lexicographic ordering
requirement ("admin/first_login" < "u/…/pw").

Co-authored-by: Claude <noreply@anthropic.com>
This updates the pins according to the carrier PCB layout

Signed-off-by: Marvin Drees <marvin.drees@9elements.com>
The HLW8012 outputs two 50% duty-cycle square waves whose frequencies
are proportional to active power (CF) and current/voltage RMS (CF1).
Two RP2040 PIO state machines measure the HIGH half-period of each
signal by counting down a 32-bit register at 2 clock cycles per loop
iteration, then pushing the result to the RX FIFO asynchronously.

The driver (Hlw8012Driver<'d>) ties to PIO0 SM0 (CF) and SM1 (CF1).
Calibration multipliers are pre-computed from the datasheet §3.2
formulas using the µs/unit convention of the Arduino reference
library: value = multiplier / T_half_µs / 2.

Circuit defaults (config.rs):
  GPIO 8  = CF  (active power)
  GPIO 9  = CF1 (current/voltage RMS)
  GPIO 10 = SEL (LOW = current mode, HIGH = voltage mode)
  R_sense = 1 mΩ, V_ratio = 1881 (4×470 kΩ + 1 kΩ divider)

A minimum-frequency guard (0.1 Hz) clamps spurious no-load pulses
to zero, matching behaviour observed in the Arduino reference
implementation. Absolute accuracy is ±15% without calibration due
to the chip's internal oscillator tolerance.

Co-authored-by: Claude <noreply@anthropic.com>
Replace the stub voltage/current fields in SensorData with real
measurements from the HLW8012 driver:

  - SensorData: remove current_a:[f32;8] stub; add voltage_v, current_total_a,
    power_w (all driven by the HLW8012).
  - sensor_task: add Hlw8012Driver<'static> parameter; measure power,
    current, and voltage each cycle (voltage read toggles SEL and waits
    2 s for stabilisation).
  - main.rs: bind PIO0_IRQ_0, initialise Hlw8012Driver on GPIO 8/9/10,
    pass it to sensor_task.
  - GET /api/sensors: replace current_a array with current_total_a and
    power_w fields.
  - index.html: add Current and Power tiles to the sensor bar; remove
    per-relay current stubs (HLW8012 measures total input only).

Co-authored-by: Claude <noreply@anthropic.com>
Five errors were reported by cargo deny:

1. 0BSD not in license allow-list: managed + smoltcp (both transitive
   deps of embassy-net) use this OSI-approved permissive license.
   Added "0BSD" to [licenses].allow.

2. CDLA-Permissive-2.0 not in allow-list: webpki-roots is pulled in
   only by ureq inside the host-only xtask crate. Added xtask to
   [graph].exclude so its host-only transitive deps are not audited
   against the embedded firmware license policy.

3. xtask unlicensed: added license = "Apache-2.0" to xtask/Cargo.toml.

4. RUSTSEC-2024-0436 (paste unmaintained): paste is a transitive
   build-time dep via pio-core -> pio -> embassy-rp. No safe upgrade
   path exists until pio-core migrates upstream. Added an
   [[advisories.ignore]] entry with a documented rationale.

5. keccak 0.1.5 yanked: bumped to 0.1.6 via cargo update -p keccak.
   This is a build-time dep (lalrpop -> sha3 -> keccak).

Co-authored-by: Claude <noreply@anthropic.com>
@MDr164 MDr164 merged commit 0eae0e4 into main Mar 18, 2026
22 of 26 checks passed
@MDr164 MDr164 deleted the sensor branch March 18, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant