mirror of
https://github.com/esphome/esphome.git
synced 2026-11-18 02:55:59 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b5f99a60e | ||
|
|
6ba3c6b03b | ||
|
|
b9c5899ad4 | ||
|
|
ac0fed53a4 | ||
|
|
a769d6309b |
No files matched your search
@@ -40,14 +40,6 @@ Not shared code: the component's own platform files (`esphome/components/<c>/sen
|
||||
`text_sensor/__init__.py`, ...), its new `USE_*` lines in `esphome/core/defines.h`,
|
||||
and its `CODEOWNERS` entry.
|
||||
|
||||
## YAML language freeze
|
||||
|
||||
Until configurations move to yaml.rocks (esphome/backlog#201), flag any PR that adds to the YAML language: a new tag
|
||||
in `esphome/yaml_util.py`, new behaviour in the `packages` or `substitutions` components (a new entry in the Jinja
|
||||
`SAFE_GLOBALS` in `substitutions/jinja.py`, or a custom Jinja filter, counts), or new merge, override or remove
|
||||
semantics (`esphome/config_helpers.py`, `!extend`, `!remove`). Bug fixes to the existing features are fine. This
|
||||
covers how YAML files are read, included and combined, not a component's own configuration options.
|
||||
|
||||
## Memory and embedded constraints (highest value)
|
||||
|
||||
Heap allocation after `setup()` is treated as a reliability bug, not a
|
||||
|
||||
@@ -47,15 +47,6 @@ driven, what the logs show, and the same flow on a `dev` build when a quirk coul
|
||||
piped, or lines land minutes late. Bound every long command with `timeout` (coreutils) or
|
||||
`perl -e 'alarm shift; exec @ARGV' <seconds> <command>` on macOS without it. Save an exit code with `rc=$?`
|
||||
right after the command: in `echo "$(date +%T) rc=$?"` the command substitution runs first and `$?` reads 0.
|
||||
8. **Give builds a private PlatformIO directory when sessions may use different Pythons.** ESPHome stamps the
|
||||
PlatformIO core directory with the Python version that last built, and a build from another version wipes and
|
||||
reinstalls the shared packages under every other build. Set `PLATFORMIO_CORE_DIR=<scratch>/pio` on every
|
||||
compile and upload (`scripts/pio_build.sh` does). Old releases and framework A/B builds need one too
|
||||
(see `reference/boards.md`).
|
||||
9. **One ESP-IDF or LibreTiny build at a time on a shared machine.** Concurrent builds race over tool caches. Wrap
|
||||
compiles in a lock (`BUILD_LOCK` for `scripts/pio_build.sh`, for example a script that holds a `mkdir` lock).
|
||||
10. **Check that the stimulus ran.** A load or soak run where most requests failed was not loaded, and a capture
|
||||
that stopped early covers nothing; check the driver's own counters before reading the device's verdict.
|
||||
|
||||
## Workflow
|
||||
|
||||
@@ -65,9 +56,6 @@ driven, what the logs show, and the same flow on a `dev` build when a quirk coul
|
||||
them apart with a 10 s capture using `serial_capture.py --reset` (ESP8266 prints its ROM banner at
|
||||
74880 baud, LibreTiny boards print `[LT]` and ESPHome lines, BK7238 prints its bootloader version).
|
||||
`ports.py --wait 2e8a` blocks until a Pico re-enumerates.
|
||||
A change in validation or platform independent code needs no board: a `host:` build serves the API on
|
||||
port 6053 on every interface (reach it at 127.0.0.1, and add `api: encryption:` on a shared network); see
|
||||
recipes/homeassistant.md for one against a throwaway Home Assistant.
|
||||
2. **Make a scratch directory** outside the checkout, with `secrets.yaml` and the templates you need.
|
||||
One yaml per board per variant, file name equal to `name:`.
|
||||
3. **Compile** in the right tree:
|
||||
@@ -90,17 +78,7 @@ driven, what the logs show, and the same flow on a `dev` build when a quirk coul
|
||||
> Automated testing results
|
||||
```
|
||||
|
||||
Then one short sentence saying what was tested (builds and SHAs, board, what was driven), and on the next line a
|
||||
bold result, one of **Test result: PASS**, **Test result: FAIL**, **Test result: PASS WITH CAVEATS** or
|
||||
**Test result: UNCLEAR**, followed by one sentence with the key numbers (for example "the device closed none of 32
|
||||
streams, dev closed 12 of 16"). FAIL means a regression or a fix that does not work. PASS WITH CAVEATS means it works
|
||||
but something about the change itself needs a look; name the caveat in that sentence. A limit of the test (the
|
||||
original crash did not reproduce) or a device or network quirk the tooling reported correctly is not a caveat on
|
||||
the change; say it as a separate note. UNCLEAR means the run could not decide; say what is
|
||||
missing. A reader must not have to dig through the table or guess. Side findings that do not change the result (a
|
||||
bug already on `dev`, a one-off oddity) go in the bullets, marked as separate from the result.
|
||||
|
||||
Then a results table
|
||||
Then one short sentence saying what was tested (builds and SHAs, board, what was driven), a results table
|
||||
(build SHA, board and framework, what was driven, counts, result, plus the `dev` control row), short bullets
|
||||
for the findings, and the setup and exact flow in a collapsed `<details>` block. Answer any question asked on
|
||||
the PR directly in the comment. No credentials, SSIDs, IP addresses, port names or other bench details.
|
||||
@@ -137,13 +115,8 @@ ESP-IDF OTA image: `.esphome/build/<name>/build/firmware.ota.bin`. LibreTiny OTA
|
||||
and then; retry up to three times.
|
||||
- `api_button.py HOST KEY list|press NAME [...]`: list a device's template buttons or press them over the API; the
|
||||
recipes drive their test configs with it.
|
||||
- `apiconn.py`: `connect(host, tries, port, on_stop)` (API connect and login with retries, `API_KEY` from the env),
|
||||
`log_text()` (an API log line without ANSI codes), `stop_event()` (an Event set when the connection ends),
|
||||
`ble_connect()` (wait for an advert, connect through a proxy without a cache like Home Assistant) and
|
||||
`enable_notify()` (start notify and write the CCCD), imported by the API drivers.
|
||||
- `pio_build.sh compile|upload NAME YAML [DEVICE] [esphome options]`: build or upload YAML as `-s name NAME` from
|
||||
`TREE` with a private PlatformIO directory, an import check and an optional `BUILD_LOCK`; logs to `NAME-*.log`.
|
||||
- `resolve.sh NAME [TRIES]`: the address of `NAME.local` once it resolves and answers a ping.
|
||||
- `apiconn.py`: `connect(host, tries)` (API connect and login with retries, `API_KEY` from the env) and `log_text()`
|
||||
(an API log line without ANSI codes), imported by the newer API drivers.
|
||||
- `wifisave_hammer.sh KIND DUT_PORT DUT_YAML DUT_TREE CLIENT_PORT CLIENT_YAML CLIENT_TREE [SETTLE]`:
|
||||
the fallback AP plus captive portal hammer end to end (compile, flash, capture, counts) with the
|
||||
templates below. KIND is `esp`, `pico`, `bw15` or `bk`. It ends with `RESULT PASS` (exit 0),
|
||||
@@ -152,13 +125,12 @@ ESP-IDF OTA image: `.esphome/build/<name>/build/firmware.ota.bin`. LibreTiny OTA
|
||||
(exit 2: a precondition was missed, the stimulus was insufficient, or a capture did not last the run)
|
||||
or exits 1 when a build, flash or port step failed.
|
||||
|
||||
Per-topic scripts, each described in the matching `reference/recipes/<component>.md`: `heap_alloc/` (operator new caller
|
||||
recorder, dump saver and decoder, cover cycle driver), `online_image/`
|
||||
Per-topic scripts, each described in the matching `reference/recipes/<component>.md`: `online_image/`
|
||||
(server with prefixed misbehaviour cases, PNG, JPEG, BMP and QOI generators, API drivers, first pass timer), `zwave_proxy/` (checksum verifier, device info), `usb_cdc_acm/`
|
||||
(host driver, Zephyr driver probe), `rtsp_server/` (protocol client, raw rate reader, measurement set,
|
||||
API image grab), `cse7766/` (API observer with ping), `zephyr_coredump/` (reader flow, decode with the
|
||||
Zephyr tools), `libretiny_prefs/` (rtc preference harness header), `libretiny_crash/` (BK72xx crash probe header,
|
||||
capture decoder, RTL8720C ROM dump versus report matcher), `api_outgoing/` (wake cycle and Wi-Fi drop timing readers), `ld2450/` (zone number driver, loopback harness driver with number and binary sensor states and TX frame summarizer, frame stream harness with presence hold and link loss drivers, BT MAC driver), `api/` (raw plaintext native API client for user defined actions, store_yaml recovery client over Noise or plaintext), `http_request/` (update manifest server, update state driver, request test server, action case driver, concurrency, reboot, update check and OTA drivers, `ota_auth/` OTA request cases with basic auth), `modem/` (button and sensor driver over the plaintext API, also used for the BLE MIDI boards, AT commands for the UART passthrough), `dfrobot_sen0395/` (API driver and case runner), `homeassistant_light/` (direct bulb driver, held-report case driver), `usb_audio/` (URL player), `speaker_media_player/` (API player driver, pipeline task case runner), `web_server/` (SSE client, request mix, SSE and HTTPD case runners, per-session `/events` listing check with its config, `/events` head, multi-client, stall, Wi-Fi drop and churn modes with their config, head comparer and runner), `mqtt/` (`ha_discovery/`, `disable/`, `retained_burst/` and `reconnect/` runners; broker config with TLS, client-certificate and WebSocket listeners, test CA with server and client certificates, transport case runner, flash-and-drive runner, CLI TLS check without a board, MAC suffix runner with per-variant configs for two boards, `shutdown/` shutdown message runner and matcher), `udp/` (datagram recorder, `udp.write` payload checker and case driver), `entity_icons/` (icon and device class readback over the API, MQTT discovery, web_server and dump_config, with a comparer), `uart_sim/` (API driver and flash, capture and drive runner for the simulated UART sensors), `remote_base/` (loopback runner and API log decoder per sent frame), `xiaomi_ble/` (frame and header generator with the expected counts, injecting, advertising and receiving configs, counter and runner), `ble_terminate/` (proxy and peer configs, connect and disconnect driver, peer disconnect matcher, runner), `i2c_slave/` (D1 mini slave and BK7238 master configs), `wpa3_ap/` (PMF AP with join and leave logging, BK7238 and CB3S DUTs, runner and summary), `wisp_ap/` (WISP upstream with AP buttons, WISP and ALWAYS_ON DUTs, client, runner and per phase summary), `wifi_restart/` (WPA3 mixed WISP upstream, static IP DUTs with syslog, runner and summary), `ota_timing/` (OTA upload timer with deflate, raw and TCP modes, API build check, A/B runner and median summary, `inflate_bench/` on-device inflate benchmark with stream generator, configs and syslog runner), `gpio_hold/` (ISR pin hold self test with ESP32 and S3 configs), `ble_event_inject/` (GAP and GATTC event injector header and proxy package), `light_sleep_wake/` (LEDC wave and edge timer for light sleep wakeup on a C3, external wave generator and per-call edge detail probe for peripheral power-down on the P4), `manual_ip/` (station and AP manual IP configs, DNS probe and runners), `web_handlers/` (late handler, web_server, captive_portal and prometheus variants, web OTA runner), `bk72xx_flash/` (flash readback with retries, per partition diff of two dumps), `ble_server_security/` (secure GATT server and pairing client configs, driver, summary and runner), `prometheus/` (datetime metrics configs and driver), `zephyr_ble_server/` (nRF52 server, looping ESP32 client and UF2 flash and count runner), `ble_adv_triggers/` (advertiser with six raw frames, ESP32 and BK72xx receivers with eleven triggers, runner and checker), `sun/` (longitude sweep package, runner and checker), `sensor_filters/` (every filter shape with a fixed input sequence, per-board packages and runner), `led_driver_sniff/` (SPI slave capture header with selftest, config generator, window comparer and runner), `hub_input_sim/` (keypad, wiegand and rdm6300 simulation on a D1 mini, API log runner), `value_range/` (on_value_range sequence with a restart, runner), `ezo_fake_bus/` (fake EZO I2C bus and step config, runner), `twai_self/` (TWAI self-reception header, on_frame config and counter runner), `ota_automations/` (OTA automation package for both OTA platforms, four case runner, repeated web upload runner and per case summary), `output_button/` (pad edge timer header, button package and runner), `homeassistant_button/` (raw plaintext API client for action calls and wizard inputs, package and runner), `uart_button/` (UART0 loopback package, API driver with TX and RX counts, runner), `interval/` (plain and delayed interval package, timing summary and runner), `smp_udp_ota/` (SMP reset fault injector, OTA runner, per mode result check, MCUboot swap limit, running image check and slot blanking UF2, Thread device config), `ld2420_sim/` (fake LD2420 answering the hub's commands on a UART0 loopback, API state recorder, two-build comparer and runneLine truncated
|
||||
capture decoder, RTL8720C ROM dump versus report matcher), `api_outgoing/` (wake cycle and Wi-Fi drop timing readers), `ld2450/` (zone number driver, loopback harness driver with number and binary sensor states and TX frame summarizer, frame stream harness with presence hold and link loss drivers, BT MAC driver), `api/` (raw plaintext native API client for user defined actions, store_yaml recovery client over Noise or plaintext), `http_request/` (update manifest server, update state driver, request test server, action case driver, concurrency, reboot, update check and OTA drivers, `ota_auth/` OTA request cases with basic auth), `modem/` (button and sensor driver over the plaintext API, also used for the BLE MIDI boards), `dfrobot_sen0395/` (API driver and case runner), `homeassistant_light/` (direct bulb driver, held-report case driver), `usb_audio/` (URL player), `speaker_media_player/` (API player driver, pipeline task case runner), `web_server/` (SSE client, request mix, SSE and HTTPD case runners), `mqtt/` (`ha_discovery/`, `disable/`, `retained_burst/` and `reconnect/` runners; broker config with TLS, client-certificate and WebSocket listeners, test CA with server and client certificates, transport case runner, flash-and-drive runner, CLI TLS check without a board, MAC suffix runner with per-variant configs for two boards, `shutdown/` shutdown message runner and matcher), `udp/` (datagram recorder, `udp.write` payload checker and case driver), `entity_icons/` (icon and device class readback over the API, MQTT discovery, web_server and dump_config, with a comparer), `uart_sim/` (API driver and flash, capture and drive runner for the simulated UART sensors), `remote_base/` (loopback runner and API log decoder per sent frame), `xiaomi_ble/` (frame and header generator with the expected counts, injecting, advertising and receiving configs, counter and runner), `ble_terminate/` (proxy and peer configs, connect and disconnect driver, peer disconnect matcher, runner), `i2c_slave/` (D1 mini slave and BK7238 master configs), `wpa3_ap/` (PMF AP with join and leave logging, BK7238 and CB3S DUTs, runner and summary), `wisp_ap/` (WISP upstream with AP buttons, WISP and ALWAYS_ON DUTs, client, runner and per phase summary), `wifi_restart/` (WPA3 mixed WISP upstream, static IP DUTs with syslog, runner and summary), `ota_timing/` (OTA upload timer with deflate, raw and TCP modes, API build check, A/B runner and median summary, `inflate_bench/` on-device inflate benchmark with stream generator, configs and syslog runner), `gpio_hold/` (ISR pin hold self test with ESP32 and S3 configs), `ble_event_inject/` (GAP and GATTC event injector header and proxy package), `light_sleep_wake/` (LEDC wave and edge timer for light sleep wakeup on a C3, external wave generator and per-call edge detail probe for peripheral power-down on the P4), `manual_ip/` (station and AP manual IP configs, DNS probe and runners), `web_handlers/` (late handler, web_server, captive_portal and prometheus variants, web OTA runner), `bk72xx_flash/` (flash readback with retries, per partition diff of two dumps), `ble_server_security/` (secure GATT server and pairing client configs, driver, summary and runner), `prometheus/` (datetime metrics configs and driver), `zephyr_ble_server/` (nRF52 server, looping ESP32 client and UF2 flash and count runner), `ble_adv_triggers/` (advertiser with six raw frames, ESP32 and BK72xx receivers with eleven triggers, runner and checker), `sun/` (longitude sweep package, runner and checker), `sensor_filters/` (every filter shape with a fixed input sequence, per-board packages and runner), `led_driver_sniff/` (SPI slave capture header with selftest, config generator, window comparer and runner), `hub_input_sim/` (keypad, wiegand and rdm6300 simulation on a D1 mini, API log runner), `value_range/` (on_value_range sequence with a restart, runner), `ezo_fake_bus/` (fake EZO I2C bus and step config, runner), `twai_self/` (TWAI self-reception header, on_frame config and counter runner), `ota_automations/` (OTA automation package for both OTA platforms, four case runner, repeated web upload runner and per case summary), `output_button/` (pad edge timer header, button package and runner), `homeassistant_button/` (raw plaintext API client for action calls and wizard inputs, package and runner), `uart_button/` (UART0 loopback package, API driver with TX and RX counts, runner), `interval/` (plain and delayed interval package, timing summary and runner), `smp_udp_ota/` (SMP reset fault injector, OTA runner, per mode result check, MCUboot swap limit, running image check and slot blanking UF2, Thread device config), `ld2420_sim/` (fake LD2420 answering the hub's commands on a UART0 loopback, API state recorder, two-build comparer and runner), `nrf52_tcp_probe/` (TCP and UDP socket probe config, build and log check, API check over Thread), `rs485_frame/` (simulated DLE/STX/ETX bus device, frame and gate cases, runner), `hx711/` (fake HXLine truncated
|
||||
|
||||
## Templates in `$SKILL/templates`
|
||||
|
||||
@@ -167,8 +139,6 @@ capture decoder, RTL8720C ROM dump versus report matcher), `api_outgoing/` (wake
|
||||
- `client-wifisave.yaml` (package): joins that AP, posts N bogus `/wifisave` requests, then the real
|
||||
credentials from `!secret`. `example-client.yaml` is the per-run file. `bogus_saves: "1"` gives a
|
||||
plain provisioning check.
|
||||
- `diagnostics.yaml` (package): DEBUG logs, esphome OTA, uptime, free heap, reset reason and a 200 ms counter
|
||||
for soak and load tests.
|
||||
- Per-topic device configs, each described in `reference/recipes/<component>.md`: `online-image-dut.yaml`,
|
||||
`usb-cdc-acm-dongle-dut.yaml`, `nrf52-preferences-dut.yaml`, `rtsp-waveshare-s3-eth-dut.yaml`,
|
||||
`waveshare-s3-eth-camdiag.yaml`, `s31-cse7766-dut.yaml`, `nrf52-coredump-crash-dut.yaml`,
|
||||
@@ -222,10 +192,6 @@ comment quotes the exact commits. Fetch `origin dev` before computing a merge ba
|
||||
the shared `~/.platformio/platforms/libretiny`, so every later build on the machine uses the patched copy. Patch
|
||||
through the ESPHome side (a linker `-Wl,-wrap,<symbol>` or a define) instead, and if it happened, restore the
|
||||
directory from a clean copy of the same release.
|
||||
- Copying a .uf2 to a mounted bootloader drive (`RPI-RP2`, `ITSY840BOOT`) from a terminal on macOS can fail with
|
||||
"Operation not permitted" (the Removable Volumes privacy permission), and picotool then sees no device. Flash through
|
||||
the serial path instead (`esphome upload --device <port>`: the 1200 baud touch on RP2, serial DFU on Adafruit nRF52
|
||||
boards) or by OTA; a board that only shows the drive needs the file dragged in Finder.
|
||||
- `wc -l` pads its count on macOS, so `tail -n +$n0` needs `$((n0+0))` or an arithmetic expansion.
|
||||
- `api:` reboots a board after 15 min without a client: `reboot_timeout: 0s` on `api:` and `mqtt:` for
|
||||
soak tests.
|
||||
|
||||
@@ -25,13 +25,7 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
- AsyncMqttClient drops inbound topics over 128 characters; topics of 255 or more wrap a counter and
|
||||
stall the link until the broker drops TCP.
|
||||
- `Arduino.h` already declares `_heap_start`; a lambda can use `&_heap_start` directly, and a second `extern` fails.
|
||||
- `Hardware Watchdog` with `wDev_ProcessFiq` in the stack means interrupts were held off too long for the Wi-Fi
|
||||
interrupt handler; `Software Watchdog` with `pm_send_nullfunc` means the loop was busy too long. Code that takes
|
||||
interrupt locks needs a load run to show either (`scripts/esp8266_lock_load/`, see recipes/one_wire.md).
|
||||
- `GPI` bits 16 to 31 are strapping bits (mask with 0xFFFF). GPIO16 has no interrupt; read `GP16O` for an output.
|
||||
- Cover positions and other restored entity state live in RTC memory by default, so they survive `erase_flash`
|
||||
and a dev build's state carries into the next build's first boot. Set `esp8266: restore_from_flash: true` on A/B
|
||||
configs that erase between builds.
|
||||
|
||||
## ESP32 classic devkit
|
||||
|
||||
@@ -53,8 +47,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
- An ESP32 whose bootloader has no app rollback is protected only by `safe_mode` after a bad OTA. Before sending a
|
||||
change to such a device that nobody can reach by hand, boot the same code on a devkit first and keep a fallback
|
||||
image of the merge base built.
|
||||
- On modules where GPIO16 and GPIO17 are taken by the module itself (PSRAM on WROVER modules, for example), a
|
||||
`uart:` bus on those pins boot-loops with a watchdog reset during setup. Use GPIO21 and GPIO22.
|
||||
|
||||
## ESP32-S3, C3, C6, H2 with native USB
|
||||
|
||||
@@ -77,25 +69,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
- A board left in the ROM bootloader after an upload (BOOT held, or the USB JTAG reset landing in download mode
|
||||
again) starts its app without a replug through `esptool --port <port> --after watchdog-reset chip-id`; flash a
|
||||
minimal Wi-Fi plus API image first when recovering from a crash-looping one.
|
||||
- On macOS a software reboot of an ESP32-C3 does not drop its USB JTAG serial port: pyserial keeps reading and gets
|
||||
no error, so a client that watches for a port reset misses it. Count ESPHome's `Running through setup()` line
|
||||
instead.
|
||||
- W5500 SPI Ethernet with IPv6 on (seen on an ESP32-S3, #22676): every `safe_reboot()` (OTA, restart button)
|
||||
aborts while an API client is subscribed to logs. `mdns_free()` leaves the IPv6 group inside `tcpip_api_call`, the
|
||||
W5500 driver logs "IPv6 multicast is always filtered in by W5500", the logger sends that line to the API inline,
|
||||
and the nested `LwIPLock` in `setsockopt(TCP_NODELAY)` releases the core lock it did not take, so `udp_recv`
|
||||
asserts. No crash with IPv6 off, with no log subscriber (a connected client that does not subscribe is fine), or
|
||||
on RMII Ethernet. Reading the crash record afterwards: `recipes/crash_report.md`.
|
||||
- `usb_serial_jtag` holds a `NO_LIGHT_SLEEP` power lock by itself, so a light sleep soak on a native USB board logs
|
||||
to UART0 instead (see `recipes/light_sleep_gpio_wake.md`).
|
||||
- The Waveshare ESP32-P4-WIFI6 needs `engineering_sample: true`. Its Wi-Fi is an ESP32-C6 over SDIO through
|
||||
`esp32_hosted`; a test with no network logs over UART0 to the CH343 console.
|
||||
|
||||
## ESP32-C2 (ESP8684, 26 MHz crystal)
|
||||
|
||||
- Boards with a 26 MHz crystal print the ROM banner (`ESP-ROM:esp8684`) at 74880 baud; at 115200 it is garbage.
|
||||
- ESP-IDF builds need `esp32: framework: sdkconfig_options: {CONFIG_XTAL_FREQ_26: y}`, or the app console runs at
|
||||
the wrong baud rate (the upload log warns `Crystal frequency mismatch`).
|
||||
|
||||
## RP2040 / RP2350 (Pico W, Pico 2 W)
|
||||
|
||||
@@ -123,25 +96,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
each RD_REQ with one byte from a 256-byte register file, so any read length works (used for BME280/BMP280 in
|
||||
esphome#22236). The ESP32-S3 I2C slave v2 driver is not usable for register emulation: answering from a task or
|
||||
straight from the interrupt both gave shifted multi-byte reads.
|
||||
- RP2350 PIO instruction memory survives a reflash (the 1200 baud touch and the UF2 reboot), so a program loaded by
|
||||
the previous firmware can hide a missing `pio_add_program`. Clear it from an `on_boot` priority 1000 lambda
|
||||
(`pio1->instr_mem[i] = 0` for i < 32) to start from power-on state; `scripts/pio_probe/pio-common.yaml` does.
|
||||
- `RP2Preferences::reset()` erases the flash sector but not the RAM copy the preferences load from, so the LibreTiny
|
||||
`on_boot` wipe-once pattern still boots with the old saved Wi-Fi credentials. Use a fallback AP config with
|
||||
`networks:` and a fresh `name:` per build instead.
|
||||
- WIZnet W5100S-EVB-Pico (RP2040, `rp2: board: wiznet_5100s_evb_pico`): W5100S on SPI with CLK 18, MOSI 19, MISO 16,
|
||||
CS 17, INT 21, RST 20 (`ethernet: type: W5100`). ESPHome firmware gives it no USB CDC port; reach it over Ethernet,
|
||||
OTA by address, and flash it over USB only through BOOTSEL and the UF2 drive. Keep `interrupt_pin` in every build:
|
||||
without it OTA starves and never completes (`recipes/arduino_pico.md`), which strands the board until a USB flash.
|
||||
The W5100S answers ICMP in hardware, so a ping reply says nothing about the RP2040; probe TCP instead (OTA port
|
||||
2040, API 6053, HTTP 80). In safe mode only 2040 answers.
|
||||
- Through a Pico W `bluetooth_proxy`, about 1 to 2 in 5 BLE connects fail with 0x3E (`connect err=62` in the
|
||||
client) on every build; retry.
|
||||
- arduino-pico framework bumps and the RPAsyncTCP SSE stall: see `recipes/arduino_pico.md`.
|
||||
- USB CDC sends nothing until the host asserts DTR; a client that opens with DTR low (`improvcli.py` without
|
||||
`--keep-dtr`) sees silence.
|
||||
- Powering a breakout from the Pico: use 3V3(OUT), pin 36. Pin 37 is 3V3_EN, which switches the Pico off when pulled
|
||||
low.
|
||||
|
||||
## BW15 kit (RTL8720CF, LibreTiny rtl87xx)
|
||||
|
||||
@@ -183,12 +137,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
- Wrong-MD5 OTA test without changing firmware: monkeypatch `espota2.hashlib.md5` so only the image checksum (data
|
||||
over 64 KB) returns a wrong hexdigest. Give each build its own `name:` and read `device_info().name` after a
|
||||
restart to see which image booted.
|
||||
- Logger UART: `DEFAULT` is UART2 (the kit's USB serial). `hardware_uart: UART1` hangs after the boot banner and
|
||||
never joins Wi-Fi, on dev too. `UART0` moves both ESPHome and `lt_log` output off the kit's port. LibreTiny's own
|
||||
`LT_I` lines need `framework: loglevel: info` (the default is warn).
|
||||
- A config with no Wi-Fi network and no `ap:` resets about 10 s into setup when it has `web_server:` (dev too):
|
||||
`web_server` setup blocks with no interface up, and no crash record is left. VERBOSE logs show the last
|
||||
`Setup <component>` line.
|
||||
|
||||
## BK7238, WB3S, CB3S (BK7231N) (LibreTiny bk72xx, CH340, RTS on CEN)
|
||||
|
||||
@@ -314,10 +262,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
partition even when the upgrade state is still `UPG_STATE_DOWNLOAD_ING` (esphome#22111).
|
||||
- Without serial access to recover, never send a corrupted image; wrong-MD5 and cut-upload tests with valid
|
||||
images are safe.
|
||||
- On the WL2H-U `logger: hardware_uart: DEFAULT` resolves to UART1, LibreTiny's log port for that board.
|
||||
- Over a poor link (about 60 ms ping and 5 % loss) an ESPHome OTA takes anywhere from 50 to 445 s and a web `/update`
|
||||
of a UF2 can abort early while ESPHome OTA still works. Treat such a board's results as crash or no crash only, and
|
||||
settle questions about rates, heap after streams or OTA aborts on a BK7238 (same LibreTiny AsyncTCP).
|
||||
|
||||
## nRF52840
|
||||
|
||||
@@ -347,10 +291,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
the port open, and the logger warns `logger took a long time`. Print one line per `loop()` instead.
|
||||
- Zephyr settings survive a reflash: key a `restore_value` global by a `run` substitution when a test needs
|
||||
a never-saved value.
|
||||
- `2fe3:0100` is Zephyr's default USB VID:PID, so `ports.py` labels any board running a Zephyr ESPHome build as an
|
||||
nRF52840 Dongle. Tell an ItsyBitsy from a PCA10059 with a 1200 baud touch: the ItsyBitsy shows its `ITSY840BOOT`
|
||||
UF2 volume, the PCA10059 its Nordic DFU port.
|
||||
- nRF52 Zephyr builds use newlib; the nRF54LM20 builds use picolibc.
|
||||
- Thread: nRF52 `openthread:` accepts only `tlv:`; the individual keys (network_key, channel, ...) are rejected at
|
||||
validation. To list nearby networks with channel and PAN ID, call
|
||||
`otThreadDiscover(InstanceLock::acquire().get_instance(), 0, 0xFFFF, false, false, cb, nullptr)` from an
|
||||
@@ -404,16 +344,6 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
- BDK headers such as `power_save_pub.h` have no `extern "C"`; wrap them when including them from the Arduino
|
||||
core's C++ files.
|
||||
|
||||
## Shared PlatformIO directory
|
||||
|
||||
- The stamp file is `.esphome.pio.stamp.json`; a mismatch deletes `packages`, `platforms` and `.cache`.
|
||||
- Building an old release (2025.7.0, Arduino ESP32) against the shared directory swapped `tool-scons` for an older
|
||||
version and broke it midway (`No module named 'SCons.SConf'`) for every PlatformIO build until a newer build
|
||||
reinstalled it. Build old releases with their own `PLATFORMIO_CORE_DIR`.
|
||||
- Two arduino-pico framework versions share the plain `framework-arduinopico` package directory, so an A/B swaps the
|
||||
framework on every build; give each side its own `PLATFORMIO_CORE_DIR`.
|
||||
- The general rule (a private directory whenever sessions may use different Pythons) is ground rule 8 in `SKILL.md`.
|
||||
|
||||
## LibreTiny crash and abort() facts (esphome#21596, #22288)
|
||||
|
||||
- `abort()` on dev: the BK7238 hangs for good (the main loop stops and the watchdog never fires once Wi-Fi is up;
|
||||
@@ -493,33 +423,3 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
- LED0 P1.22, LED1 P1.25; BUTTON0 P1.26, BUTTON1 P1.09, BUTTON2 P1.08, BUTTON3 P0.05 (active low, pull-up). GPIO
|
||||
P1 registers at 0x500D8200 (IN +0x00C, PIN_CNF +0x080), P0 at 0x5010A200.
|
||||
- Binary sensor state changes are not logged at DEBUG; log the states or count `on_press` to see button presses.
|
||||
- FICR INFO.PART reads 0x054BC20B; the build target is `nrf54lm20dk`.
|
||||
- Zephyr `micros()` on nRF has 30.5 us resolution. Time short blocks with the DWT cycle counter instead; nRF54L idle
|
||||
clears `DWT_CTRL`, so enable it again before each timed block.
|
||||
- The nrf52 logger defaults to USB_CDC (the chip's own USB); set `logger: hardware_uart: UART0` to get the log on the
|
||||
J-Link VCOM port.
|
||||
- I2C (#22642): TWIM21 only takes pins on P1 or P3; P0 pins are rejected at config. BUTTON1 (P1.09) and BUTTON2
|
||||
(P1.08) pads work as SDA and SCL. A bus with no pull-ups times out (-116) on every scan address, so setup takes
|
||||
about 56 s. The JLinkExe `st` command reads VTref to check the I/O voltage.
|
||||
|
||||
## Seeed XIAO nRF54LM20A
|
||||
|
||||
- CMSIS-DAP probe (`2886:0068`) with one serial port that carries the console (uart20 on P1.11 and P1.10, #22599).
|
||||
It ships with a Seeed demo.
|
||||
- Flash with `esphome run` (pyOCD, MCUboot plus the signed app). A plain `esphome upload` flashed only the bare app
|
||||
on #22599, and the board stayed dark.
|
||||
- Reset: `<sdk-nrf python> -m pyocd reset -t nrf54lm20a -u <probe id>`.
|
||||
- nPM1300 PMIC at 0x6B on P1.18 (SDA) and P1.17 (SCL) (#22661; `i2c:` builds on i2c21 at 100 kHz). Per the upstream
|
||||
Zephyr board files, BUCK2 supplies VSYS_3V3, the nRF54 and the SAMD11 USB debugger: never switch it off (there is no
|
||||
way back without a power cycle, and the probe dies with it). LDO1 feeds the IMU and microphone (3.3 V, LDO mode) and
|
||||
is safe to toggle. BUCK1 and LDO2 are not described anywhere; leave them alone.
|
||||
- nPM1300 power-on state: BUCK2 on at 3.3 V, BUCK1 off, LDO1 and LDO2 off in load switch mode (enabling one as is
|
||||
passes VINLDO straight through), charger off, VBUS limit 100 mA, NTC select 10 k. Flows: `recipes/npm1300.md`.
|
||||
|
||||
## I2C and SPI breakouts
|
||||
|
||||
- GPIO switches on an I2C expander (XL9535 and others) write `value_or(false)` at setup even with
|
||||
`restore_mode: DISABLED`, so test pin retention on a pin no switch uses.
|
||||
- ADS1015: `sample_rate: 8` maps to 128 SPS at `12_BITS`.
|
||||
- A bus held low (`Performing bus recovery`, no devices found) on a new breakout can be a bad header joint; reflow
|
||||
it before blaming the driver.
|
||||
@@ -4,7 +4,7 @@ Each flow names the pull requests it was used on, so their result tables show wh
|
||||
|
||||
One file per component, named after it:
|
||||
|
||||
- [`api.md`](api.md): noise handshake and OTA encryption on the ESP8266, outgoing connection wake timing on deep sleep and after a Wi-Fi drop, user defined action listing and execution with a raw plaintext client, store_yaml recovery over Noise or plaintext, rapid connect/disconnect stress (`connstress.py`)
|
||||
- [`api.md`](api.md): noise handshake and OTA encryption on the ESP8266, outgoing connection wake timing on deep sleep and after a Wi-Fi drop, user defined action listing and execution with a raw plaintext client, store_yaml recovery over Noise or plaintext
|
||||
- [`ble_midi.md`](ble_midi.md): BLE MIDI client against a fake ESP32 instrument, every packet shape and the send actions
|
||||
- [`captive_portal.md`](captive_portal.md): fallback AP and /wifisave hammer
|
||||
- [`cse7766.md`](cse7766.md): Sonoff S31 parser check over the API
|
||||
@@ -15,30 +15,27 @@ One file per component, named after it:
|
||||
- [`ld2450.md`](ld2450.md): polygon zones, zone number round trip through the radar's readback, ESP8266 loopback harness without a radar, presence hold and link loss on a frame stream, BT MAC readback
|
||||
- [`ld2412.md`](ld2412.md): output pin level through the basic configuration command, held back writes
|
||||
- [`libretiny.md`](libretiny.md): rtc preference emulation, BK72xx and RTL8720C crash report on the next boot with a ROM dump matcher, BK7238 BLE bond store safety with a full flash backup and per partition diff, BK7238 OTA versus the board layout and bootloader, pulse counting, RTL8710B edge interrupts and millis timing
|
||||
- [`modem.md`](modem.md): PPPoS modem component boot check with no modem attached, loop blocking and disable timing, SIM7080G behaviour with no SIM and with no data plan through a raw UART passthrough
|
||||
- [`modem.md`](modem.md): PPPoS modem component boot check with no modem attached, loop blocking and disable timing
|
||||
- [`mqtt.md`](mqtt.md): broker bench, QoS, reconnect, crash log over MQTT, WebSocket transports with a local and a public broker, TLS trust sources (own CA, client certificate, certificate bundle, no verification) with the CLI check, MAC suffix topics and will messages on two boards, shutdown message delivery on restart, disable and deep sleep
|
||||
- [`nrf52.md`](nrf52.md): dongle board support, zephyr_ble_server connection slot under reordered callbacks, SMP over UDP OTA over Thread with reset faults, MCUboot swap limit and stuck slot recovery, TCP stack probe, sdk-nrf 3.4.1 build and USB notes
|
||||
- [`npm1300.md`](npm1300.md): nPM1300 PMIC on the XIAO nRF54LM20A: probe build, every entity with a register dump and regulator toggles, power-on state and no-battery readings
|
||||
- [`nrf52.md`](nrf52.md): dongle board support, zephyr_ble_server connection slot under reordered callbacks, SMP over UDP OTA over Thread with reset faults, MCUboot swap limit and stuck slot recovery, TCP stack probe
|
||||
- [`online_image.md`](online_image.md): stalled and malformed downloads, PNG, JPEG, BMP and QOI decode time per loop pass with large images and small buffers
|
||||
- [`openthread.md`](openthread.md): border router on the S3 host plus H2 RCP
|
||||
- [`ota.md`](ota.md): upload without a configuration and the refusal checks, overlap and lock, timeouts, deflate, upload timing A/B per build and board with deflate and raw, on-device inflate benchmark, OTA automations on two platforms
|
||||
- [`rtsp_server.md`](rtsp_server.md): camera streaming on the Waveshare ESP32-S3-ETH
|
||||
- [`scheduler.md`](scheduler.md): loop wake A/B, interval startup delay and control from lambdas, RP2 scheduler lock under IRQ and lwIP load
|
||||
- [`scheduler.md`](scheduler.md): loop wake A/B, interval startup delay and control from lambdas
|
||||
- [`udp.md`](udp.md): datagrams, multicast, sockets, `udp.write` payload shapes
|
||||
- [`usb_cdc_acm.md`](usb_cdc_acm.md): nRF52840 dongle host driver
|
||||
- [`wifi.md`](wifi.md): reboot_timeout with a fallback AP, DHCP lease cache, Easy Connect (DPP), WISP bridge with an ethernet upstream, reboots against a WPA2/WPA3 PMF access point, WISP and ALWAYS_ON AP switching, AP restarts with WPA3 mixed and LIGHT power save, soft AP clients with the BLE tracker scanning, ESP8266 power save after captive portal provisioning
|
||||
- [`wifi.md`](wifi.md): reboot_timeout with a fallback AP, DHCP lease cache, Easy Connect (DPP), WISP bridge with an ethernet upstream, reboots against a WPA2/WPA3 PMF access point, WISP and ALWAYS_ON AP switching, AP restarts with WPA3 mixed and LIGHT power save
|
||||
- [`zephyr.md`](zephyr.md): preferences on the nRF52840 dongle
|
||||
- [`zephyr_coredump.md`](zephyr_coredump.md): crash and decode on nRF52 boards
|
||||
- [`zwave_proxy.md`](zwave_proxy.md): frame checksums on a live proxy
|
||||
- [`one_wire.md`](one_wire.md): ESP8266 interrupt locks under Wi-Fi load with a DS18B20 search and a busy-wait control
|
||||
- [`cc1101.md`](cc1101.md): sleep and wake checks read directly from the chip (CHIP_RDYn, PATABLE loss, registers per setter)
|
||||
- [`globals.md`](globals.md): restoring globals with storage rtc and flash across every reset kind
|
||||
- [`homeassistant.md`](homeassistant.md): light platform mirrored from a local Home Assistant, held reports versus later calls, wizard-linked entities on every platform, homeassistant switch on a script with a host build
|
||||
- [`homeassistant.md`](homeassistant.md): light platform mirrored from a local Home Assistant, held reports versus later calls, wizard-linked entities on every platform
|
||||
- [`usb_audio.md`](usb_audio.md): USB audio speaker and microphone, the usb_host FIFO split, and Music Assistant playback through sendspin
|
||||
- [`dfrobot_sen0395.md`](dfrobot_sen0395.md): SEN0395 mmWave command flow, module quirks and overlong lines through its error reply
|
||||
- [`speaker.md`](speaker.md): media player pipeline tasks on the Connect AUX-2 with the `speaker` platform player
|
||||
- [`web_server.md`](web_server.md): state SSE stress and the HTTPD task stack on web_server_idf, entity icon and device class readback, per-session `/events` listing, `/events` head, stall, Wi-Fi drop and churn checks
|
||||
- [`uart_sim.md`](uart_sim.md): UART sensors simulated on a classic ESP32 with loopback and cross-wired UARTs, a Duco ventilation box model on a second UART
|
||||
- [`web_server.md`](web_server.md): state SSE stress and the HTTPD task stack on web_server_idf, entity icon and device class readback
|
||||
- [`uart_sim.md`](uart_sim.md): UART sensors simulated on a classic ESP32 with loopback and cross-wired UARTs
|
||||
- [`gpio_expander.md`](gpio_expander.md): interrupt driven expander inputs, loop idle checks, testing a device out of reach
|
||||
- [`led_strip.md`](led_strip.md): forcing a failed strip allocation, RMT symbols per chip, loop cost per strip
|
||||
- [`remote_base.md`](remote_base.md): remote_receiver protocol decoding through a one-pin loopback on ESP32 and ESP8266, no IR hardware
|
||||
@@ -64,11 +61,11 @@ One file per component, named after it:
|
||||
- [`rs485_frame.md`](rs485_frame.md): DLE/STX/ETX bus on an ESP32-C3 with a cross-wired simulated bus device (frame cases, gate timing)
|
||||
- [`hx711.md`](hx711.md): fake HX711 driven from the other core, every published value matched to the served conversion
|
||||
- [`automation_trace.md`](automation_trace.md): automation codegen A/B, a marker trace of chains, conditions, loops and script modes over the API
|
||||
- [`bluetooth_proxy.md`](bluetooth_proxy.md): held GATT link after a half-open API session, frozen Home Assistant stand-in, out-of-order GATT discovery responses injected on the proxy, GATT UUID forms (16 bit, 32-bit base, 128 bit) compared against an ESP32 proxy
|
||||
- [`bluetooth_proxy.md`](bluetooth_proxy.md): held GATT link after a half-open API session, frozen Home Assistant stand-in
|
||||
- [`crash_report.md`](crash_report.md): crash buttons, fetching the previous boot's crash report over the API, per-chip abort facts
|
||||
- [`https_idf.md`](https_idf.md): web_server_idf HTTPS test component, listener switch, stalled TLS clients, bad key
|
||||
- [`mdns.md`](mdns.md): legacy unicast mDNS dump, hammer and latency straight to the device
|
||||
- [`sim_buses.md`](sim_buses.md): PCF8574/HD44780, MAX7219, SPI spy, packet_interface and SN74HC165 simulators, status LED probe, fake Home Assistant, cg.static_buffer probes, a TRF7962A NFC reader chip behind a fake SPI bus
|
||||
- [`sim_buses.md`](sim_buses.md): PCF8574/HD44780, MAX7219, SPI spy, packet_interface and SN74HC165 simulators, status LED probe, fake Home Assistant, cg.static_buffer probes
|
||||
- [`sigma_delta.md`](sigma_delta.md): pulse density of the sigma_delta speaker pin read inside the ESP32-P4, rtttl note onset and release
|
||||
- [`microphone_http_stream.md`](microphone_http_stream.md): raw PCM over HTTP with a counter fake mic or a USB mic, multi-reader client
|
||||
- [`i2s_audio.md`](i2s_audio.md): I2S microphone fed by an I2S TX channel on the same S3 through three jumpers
|
||||
@@ -81,10 +78,3 @@ One file per component, named after it:
|
||||
- [`mcp23017.md`](mcp23017.md): MCP23017 IOCON aliasing and INT line behavior (open drain, push-pull, polling) on an ESP8266 with PA to PB jumpers
|
||||
- [`pwm_capture.md`](pwm_capture.md): every LEDC PWM period captured on the same ESP32-C6 through RMT receive and PCNT, with and without power save
|
||||
- [`spi.md`](spi.md): SPI bus capture on the same board with no chips (ESP32 SPI3 slave, edge interrupt snapshots on C3, ESP8266 and Pico 2 W), checked and diffed between builds
|
||||
- [`heap_alloc.md`](heap_alloc.md): operator new counting, and a ring of allocation callers decoded with addr2line to tell the first run after boot from repeats
|
||||
- [`wled.md`](wled.md): WLED realtime sender on a board's own access point
|
||||
- [`combination.md`](combination.md): combination sensor NaN behaviour from the last source
|
||||
- [`improv.md`](improv.md): Improv serial with stray bytes, scan, bad and good passwords from a client that reads frames out of the log stream, Improv over BLE, per board notes
|
||||
- [`arduino_pico.md`](arduino_pico.md): arduino-pico framework bump A/B: W5100S Ethernet soak, Pico W fallback AP client count, Pico W bluetooth_proxy GATT hold, web_server SSE stalls, `/events` churn crashes and never completed connects, W5100S OTA without `interrupt_pin`
|
||||
- [`bluedroid_gattc_queue.md`](bluedroid_gattc_queue.md): queued MTU request and execute write recursion that overflows BTU_TASK, ble_client central against an ESP32-S3 peer
|
||||
- [`tcp_link.md`](tcp_link.md): tcp packet_interface link, host to host pair on one computer, raw framing peer, entity_transport both ways
|
||||
@@ -56,25 +56,3 @@ include of random base64 lines with `include_secrets: true` gives four chunks (1
|
||||
0bd3738430: `include_secrets: true` fails the build when a package in another directory uses `!secret` and has no
|
||||
`secrets.yaml` beside it; a copy next to the package works around it.
|
||||
Results: https://github.com/esphome/esphome/pull/16445#issuecomment-6335435397
|
||||
|
||||
## Allocations of a connecting client (ratgdo/esphome-ratgdo#705)
|
||||
|
||||
An API client that connects allocates about 15 times on ESP32: the connection object, then the list entities and
|
||||
initial state batches growing the `DeferredBatch` vector. A log subscription adds more per line. Connect before a
|
||||
heap measurement and subscribe to logs only afterwards (`heap_alloc.md`).
|
||||
|
||||
## Native API connect/disconnect stress (#14679, #14687, #14706)
|
||||
|
||||
`scripts/api/connstress.py HOST [ITERATIONS] [CONCURRENCY]` (aioesphomeapi; `API_KEY` env for a noise key) opens and
|
||||
closes native API connections as fast as it can, 500 attempts with 4 at a time by default, and ends with
|
||||
`RESULT PASS` or `RESULT FAIL`. It is the test that found the raw lwIP socket heap corruption, so run it for any change to
|
||||
the socket layer, the scheduler or locking on RP2040/RP2350 and ESP8266, with a bounded serial capture on the device:
|
||||
the client only sees resets, the crash is in the log.
|
||||
|
||||
- RP2040/RP2350 before #14687: crashed after 3 or 4 iterations (`malloc` from the lwIP accept IRQ while the main loop
|
||||
was in `malloc`: double free in `~APIFrameHelper`, `_malloc_r` in `APIConnection()`); after: 500/500. #14679 first
|
||||
added the lwIP locking between the lwIP callbacks and the main loop on RP2040.
|
||||
- ESP8266 before #14706: crashed within about 50 iterations (`umm_malloc_core` LoadStoreError, use after free of a
|
||||
closed PCB's callbacks); after: 490/500, the 10 failures are connection resets from overload, which is expected there.
|
||||
- ESP32 (BSD sockets) passes 500/500 on both and is the control.
|
||||
- Compare against dev on the same board; count reboots and decode crash addresses as well as the client's failures.
|
||||
@@ -1,42 +0,0 @@
|
||||
# arduino-pico framework bumps (RP2040/RP2350)
|
||||
|
||||
Scripts: `scripts/rp2_web_ble/` (README there). Used for #22671 (6.1.1 to 6.3.2).
|
||||
|
||||
- Build PR and dev with a private `PLATFORMIO_CORE_DIR` (`scripts/pio_build.sh` does; see `reference/boards.md`).
|
||||
Check the compile log line `framework-arduinopico @ 1.60302.0` per build.
|
||||
- Wired Ethernet (W5100S EVB): 6.3.2 defines `LWIP_ASSERT_CORE_LOCKED()` as `async_context_lock_check` on the
|
||||
Ethernet context (`cores/rp2040/lwip_wrap.cpp`), so unlocked lwIP calls panic there. Soak the API (200 ms template
|
||||
counter, 1 s uptime, logs subscribed), load pages, OTA and reboot; the rp2 crash handler shows a panic as
|
||||
`Crash (HardFault)` in the debug reset reason on the next boot.
|
||||
- Fallback AP client count: `ap_clients_` is protected and `WiFiComponent` is final; read it from an
|
||||
`esphome: includes:` header through an explicitly instantiated member pointer (`appeek.hpp`). Join raises it to 1.
|
||||
- bluetooth_proxy on the Pico W: `rp2_ble_tracker:` + `bluetooth_proxy: active: true`. Drive with `gatthold.py`
|
||||
against the ESP32-S3 server in `scripts/ble_notify/server.yaml`. UUID forms and the 0x3E connect failures are in
|
||||
`bluetooth_proxy.md`. A "Failed to send notify data response" warning at each disconnect is normal.
|
||||
- web_server SSE on the W5100S (dev 2a6a1a050e4, 6.1.1): every `/events` stream stops after 0.3 to 11 s (alone, with
|
||||
the API, or with page loads alike), then the EVB closes it with a FIN 5.8 to 6.3 s after its last data segment, so
|
||||
curl exits 0. The pcap shows every byte ACKed by the host, window 65535, no retransmits, nothing sent in the gap:
|
||||
the device simply stops writing. The 5 s gap matches RPAsyncTCP `ASYNC_MAX_ACK_TIME` (likely `_pcb_busy` not
|
||||
cleared, then `_onTimeout` closes). A new `/events`, GET / and the API keep working. Pico W: 60 s steady. On macOS
|
||||
`tcpdump` runs without sudo once your account is in the bpf group. Tools: `sserun.sh HOST TAG SECS alone|api|pages
|
||||
N` (pcap, netstat poll, API VERBOSE log, probes) and `pcapsum.py PCAP DEVICE_IP` (per connection last data, FIN/RST,
|
||||
retx). Confirmed with counters patched into the build's `.piolibdeps` copy of RPAsyncTCP: every stall is one
|
||||
`_sent()` underflow with `_tx_unacked_len` 0 and the pcb idle after `send()`; ESPAsyncWebServer 3.12.1 does not
|
||||
help. The esphome-libs RPAsyncTCP fork (`esphome-1.3.2`, 8efb83c) streams 16 x 30 s with no stall. `stallctr.py PCAP
|
||||
IP APILOG` lines the counters up with each stall.
|
||||
- `H=<device ip> churn.sh TAG SECS` (4 loops of 0.2 to 1.5 s `/events` connections) crashes the rp2 web_server: dev on
|
||||
the EVB, the fork build on the EVB and the Pico W. HardFault in `AsyncEventSource::send` from
|
||||
`deferrable_send_state`, about one reboot every 10 to 20 s. Ten quick reboots put the board in safe mode (ping and
|
||||
OTA port 2040 only); OTA a build to recover.
|
||||
- **Never flash the W5100S EVB a build without `interrupt_pin`** unless you can reach BOOTSEL: arduino-pico then polls
|
||||
the W5100 from an async_context timer that every lwIP call pushes back, so the esphome OTA read loop starves the
|
||||
poller and OTA never completes (the device ACKs the hello, then never the features byte). Web and API still work.
|
||||
The board has no USB CDC port with ESPHome firmware, so the only way back is BOOTSEL and the UF2 drive.
|
||||
- `churnflow.sh` (in `rp2_web_ble/`) repeats `churn.sh` with heap and main loop checks and reflashes by OTA when a
|
||||
round left the board in safe mode.
|
||||
- `leakflow.sh` with `neverconn.py HOST N rst|head`: ESPAsyncWebServer 3.9.6 leaks about 175 B per `/events` client
|
||||
that resets before the response head is ACKed (52 KB per 300); 3.12.1 stays flat.
|
||||
- `/events` churn also hangs the BK7238 main loop or drops it off the network on dev; recover with a serial reset.
|
||||
- The API has 3 sockets on these builds: connstress at concurrency 4 always shows some "dropped after hello" failures;
|
||||
use 2 for a clean 500/500.
|
||||
- IRQ context scheduler test for #22688: `scripts/rp2_sched_lock/`, described in `scheduler.md`.
|
||||
@@ -42,7 +42,6 @@ comparison accepted automatically) and a classic ESP32 devkit runs `esp32central
|
||||
phase B reads the MITM characteristic with no numeric comparison and no `Deleting unpaired device` line.
|
||||
- On ESP-IDF 5.5.6 every other reconnect pairs again (`Deleting unpaired device` on the disconnect after a bonded
|
||||
reconnect), the regression #22081 describes.
|
||||
#22559 fixes it: the bond survived 15 reconnects and a reset of both boards with no new pairing.
|
||||
|
||||
## Bluedroid hex parsing bench (#22081)
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
# Bluedroid GATT client command queue
|
||||
|
||||
## Queued MTU request recursion overflows BTU_TASK (#17954, #22670)
|
||||
|
||||
Bluedroid's `bta_gattc_pop_command_to_send()` runs the head of `p_cmd_list` and removes it only after
|
||||
`bta_gattc_sm_execute()` returns. When that head is an MTU request (or an execute write) whose send fails at once,
|
||||
the failure path pops again with the same command still at the head, so it recurses until the BTU task stack
|
||||
overflows. Every ESP-IDF release so far; PR #22670 fixes it in ESPHome with linker wraps
|
||||
(`bluedroid_gattc_queue.c`).
|
||||
|
||||
Rig, `scripts/bluedroid_mtu_recursion/`:
|
||||
|
||||
- Peer: an ESP32-S3 with `btusrv.yaml` (`esp32_ble_server`, one readable and writable characteristic, advertising).
|
||||
- Central: a classic ESP32 devkit with `btu-common.yaml` plus a per-build file like `btucli-example.yaml` (set
|
||||
`peer_mac` to the peer's Bluetooth MAC, which is its Wi-Fi MAC + 2, and give each build its own name).
|
||||
`CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK: y` makes the overflow panic at the write:
|
||||
`Stack canary watchpoint triggered (BTU_TASK)`.
|
||||
- Each connection: `on_connect` looks up the characteristic handle right away (a `ble_client` with no child nodes
|
||||
releases services and cleans the GATT cache in the same SEARCH_CMPL event, so a lookup after a delay finds
|
||||
nothing), waits 1.5 s, then suspends `BTU_TASK`, calls `esp_ble_gap_disconnect`, queues 4 reads and one MTU
|
||||
request, waits 30 ms and resumes. The batch is the key: sent one at a time, the BTU task handles each request
|
||||
before the next arrives and nothing waits in the queue. The reads fail and keep the command slot busy so the MTU
|
||||
request is queued; when popped, `GATTC_ConfigureMTU` fails with "BT_GATT: connection not established".
|
||||
`ble_client` reconnects on its own and the next round starts.
|
||||
- `analyze.py CAPTURE` counts rounds, BTU canary crashes, boots, reconnects with and without a reboot and MTU 517.
|
||||
- Decode with the IDF `xtensa-esp32-elf-addr2line -pfiaC`; the overflow shows the repeating
|
||||
`pop_command_to_send (act.c:1739/1746) -> sm_execute -> cfg_mtu (act.c:1042)` frames.
|
||||
|
||||
Results on ESP-IDF 5.5.6: dev at 46844d3631 crashed 73 of 73 rounds in 5.5 min (every round, about 4.5 s per
|
||||
reboot cycle); the PR at ad787163fd ran with no crash and reconnected without a reboot each time. Check the wraps are
|
||||
linked with `nm firmware.elf | grep __wrap_GATTC_ConfigureMTU` (native ESP-IDF builds only; the define is
|
||||
`USE_ESP32_BLE_BLUEDROID_GATTC_QUEUE`).
|
||||
|
||||
### Execute write variant
|
||||
|
||||
`btuxw-example.yaml` sets `exec_write: "true"`, which sends `esp_ble_gattc_execute_write(gattc_if, conn_id, true)`
|
||||
in place of the MTU request. No prepare write is needed: Bluedroid does not check for prepared writes, and
|
||||
`GATTC_ExecuteWrite` fails synchronously with the same "connection not established" error. The variant also sets
|
||||
`CONFIG_BT_LOG_GATT_TRACE_LEVEL_API: y`, so each send logs `BT_GATT: GATTC_ExecuteWrite conn_id=... is_execute=1`,
|
||||
and those lines are counted per round with awk between the `ROUND n start` lines. In a few rounds (about 3 to 14%)
|
||||
the controller reports the disconnect before the command is popped. Those rounds log no execute send and never
|
||||
crash, so count "rounds that reached the send", not all rounds. Most dev backtraces in this variant are cut off in
|
||||
`vTaskSwitchContext` (the extra trace logging makes task switches more likely at the moment of overflow). Use the
|
||||
complete ones to decode the `bta_gattc_execute (act.c:1352)` cycle.
|
||||
|
||||
Results: dev 46844d3631 had 81 rounds, 70 reached the send, and all 70 crashed. PR e51f0b8321 had 151
|
||||
rounds, 147 reached the send with exactly one execute line each, and there were 0 crashes and 1 boot.
|
||||
@@ -26,44 +26,3 @@ swap fails when a round never connects. An owner that never got the link also fa
|
||||
- Before #22077, case H holds the link for good: 0 adverts, and the address stays in the slot report. With #22077 the
|
||||
link is released in the same millisecond as the `replaces` warning. In case 4 the first request logs `Connection
|
||||
request ignored, state: DISCONNECTING` (connected=false at 0.2 s) and the retry connects at 0.5 to 0.7 s.
|
||||
|
||||
## Out-of-order GATT discovery responses (#22518)
|
||||
|
||||
Some peripherals answer a characteristic discovery (Read By Type) with records out of handle order. ESP-IDF 5.5.6
|
||||
rejects that (`gatt_process_read_by_type_rsp invalid handle ...`) and ends the whole discovery; 5.5.5, Android and
|
||||
BlueZ accept it. `scripts/att_reorder/` reproduces it with no such device:
|
||||
|
||||
- `server.yaml` (ESP32-S3) serves `FFF0` with six characteristics, then `1826`.
|
||||
- `proxy.yaml` (classic ESP32, `idf` substitution; keep per-build files such as `example-proxy.yaml` in the same
|
||||
directory) links `components/attswap`, which wraps Bluedroid's
|
||||
`l2c_rcv_acl_data` (`-Wl,--wrap`); `attswap.hpp` swaps the first two records of the response whose first record
|
||||
declares `FFF1`, and logs a swap count.
|
||||
- `gattget.py PROXY PEER_MAC ROUNDS` reads the services through the proxy like Home Assistant (no cache);
|
||||
`run.sh PROXY_YAML [ROUNDS]` flashes both boards and prints the services per round and the discovery errors.
|
||||
|
||||
On 5.5.6 Home Assistant gets `fff0` with no characteristics and no `1826`, while the proxy still logs
|
||||
`Service discovery complete` (the proxy ignores the error status); on 5.5.5 every service arrives. To find the order a
|
||||
real device uses, decode an Android HCI snoop: a Read By Type response lists its records in the order sent.
|
||||
|
||||
- Handles, reads and notifies after a reordered response: flash `server-notify.yaml` (`SERVER_YAML` on `run.sh`) and run
|
||||
`gattcheck.py PROXY PEER_MAC`. It prints every service, characteristic and descriptor handle, reads FFF1, FFF2 and
|
||||
FFF3 by the received handles (each holds its own value), and enables notify on FFF1, FFF2 and 2ACD. Compare the table
|
||||
with a run of a proxy built without `attswap`. On ESP-IDF 5.5.5, which accepts the unsorted response, FFF1's
|
||||
descriptor range runs over FFF2's declaration, value and CCCD, so FFF2 has no CCCD (#22576).
|
||||
- `bluetooth_gatt_start_notify` only registers the notify on the proxy; the client writes the CCCD itself, as Home
|
||||
Assistant does. Without that write no notification arrives.
|
||||
- Give the proxy an `api` encryption key (`API_KEY` for the scripts). A Home Assistant on the same network connected to
|
||||
a plaintext test proxy and took over its Bluetooth subscription (`Subscription from Home Assistant ... replaces
|
||||
aioesphomeapi`), dropping the test client's connection mid-run.
|
||||
|
||||
## GATT UUID forms through a proxy (#22679)
|
||||
|
||||
`scripts/gatt_uuid/`: `server.yaml` (the `ble_notify` server plus a service with 128 bit, 32-bit base and 16 bit
|
||||
UUIDs on characteristics and descriptors, and 2901 and 2902; set the name with `-s name`), `gattlist.py PROXY PEER
|
||||
OUT.json` (lists every UUID, reads, notifies 10 s, retries 0x3E), `cmp.py REF.json OTHER.json` (entry by entry diff,
|
||||
exits 1 on a difference) and `run.sh NAME` (Pico W proxy from `rp2_web_ble/picow.yaml`, list, compare). Take the
|
||||
reference from an ESP32 proxy (unset `API_KEY` for a plaintext API).
|
||||
|
||||
- On rp2 before #22679, BTstack truncated 32-bit base UUIDs with a nonzero low half to 16 bits (`5ec10001-...` came
|
||||
out as `00000001-...`); a zero low half (5ec10000) came through intact.
|
||||
- Connects through the Pico W proxy fail with 0x3E now and then (see `reference/boards.md`); the scripts retry.
|
||||
@@ -1,53 +0,0 @@
|
||||
# cc1101
|
||||
|
||||
## Sleep and wake checks read from the chip (#22519)
|
||||
|
||||
`scripts/cc1101_sleep/`: `cc1101-sleep.yaml` runs an ESP32-S3 (ESP-IDF) with an E07-M1101D module on SPI and runs
|
||||
tests T0 to T6 4 s after boot; `cctest.hpp` reads every config register and the PATABLE directly over SPI. The log
|
||||
ends with `DONE fails=N`, and T6 prints whether each setter woke a sleeping chip.
|
||||
|
||||
- Proof that the chip sleeps: with CSn low, SO (MISO) stays high until the crystal runs, so it is high after
|
||||
`power_down()` and low at once when awake. PATABLE entries 1 to 7 are also lost in SLEEP, so write marks to them
|
||||
before `power_down()` and check that they are gone.
|
||||
- Selecting the chip to check it wakes it, so after the check the chip is awake while the component still thinks it
|
||||
sleeps. Call `wake_up()` and `begin_rx()` before the next case.
|
||||
- Leave FSCAL3 to FSCAL1 (0x23 to 0x25), FSTEST (0x29) and AGCTEST (0x2B) out of register comparisons: calibration
|
||||
and the chip itself change them.
|
||||
- Results: on 7e6b90d08b, `set_frequency`, `set_channel` and `set_modulation_type` woke a sleeping chip and left it
|
||||
in RX. 9e65d0c327 fixed that; every other check passed on both, and 200 sleep and wake cycles took about 1 s.
|
||||
|
||||
## Long packets and lambda length, two radios (#17578)
|
||||
|
||||
`scripts/cc1101_long/`: `cccommon.yaml` (package, API actions `cfg`, `send`, `rate`, `pdown`, `wup`, `setlen`,
|
||||
`pmode`, `idle_rx`, `tx_rx`, `hf` and more; logs every packet as `RX len= b0= seq= ok= rssi= lqi= fo=`), `cclong.hpp`
|
||||
(raw register helpers and `long_tx()`, which streams packets longer than the TX FIFO per datasheet 15.2.2, since the
|
||||
component only sends up to 64 bytes), example board files `c3-long.yaml` / `s3-long.yaml` / `c3-lambda.yaml` (plen 32 =
|
||||
plain, 1024 = long, lambda `x[0] + 1` with 0xEE meaning -1), `ccdrive.py TXHOST RXHOST MODE OUT TXLABEL RXLABEL`
|
||||
(modes `short`, `long`, `r2long`, `r2mid`, `lambda`, `r2lambda`, `fast`, plus the dev bug repros `crc`, `rxtx`,
|
||||
`txback`, `txrx` and `txset` (begin_tx then begin_rx, with setters between them, #22636) and `nocrc64` (100 packets of
|
||||
64 bytes with and without CRC, #22635)), `flashmac.sh NAME BOARD` (BOARD is a port or the USB serial number from
|
||||
`ports.py`; flashes, then waits for the API with `ota_timing/apiinfo.py`), `buildall.sh NAME...`, `runall.sh A B`
|
||||
(both roles, boards as for flashmac.sh). Needs `secrets.yaml` with `api_key` and an `apikey.txt` file with the same key next
|
||||
to the configs.
|
||||
|
||||
- Two boards with an E07-M1101D each, 433.92 MHz GFSK 4800. Ports change after a replug; flash by USB serial number.
|
||||
- Both radios on the PR: one plain, one long and one lambda build per board; the sender runs the long build (raw TX
|
||||
does not care). A full both-roles run is about 45 min including builds.
|
||||
- Order matters: `tx_rx` (begin_tx then begin_rx) kills reception until reflash or `set_packet_mode(true)` on dev
|
||||
(#22636), so run `long` last on a build and keep it out of `lambda`; `r2lambda` sets a fixed length, which drops
|
||||
the lambda, so run it after `lambda`. Fixed 64 with CRC is 0/20 on dev too (#22635).
|
||||
- `ccdrive.py` waits for the RX and TX `CFG` log line before sending; without that a slow API reply leaves the
|
||||
receiver on the previous length and shows "wrong length" packets.
|
||||
A result line is marked INVALID when an action failed or a `CFG`, `RATE` or `SENT` line never came since the
|
||||
previous result, and shows the sender's `txerr` from its `SENT` line, so send failures are not read as lost packets.
|
||||
A case is MISSED, and ccdrive.py exits non-zero, when the sender reports send errors (or no SENT line), when fewer
|
||||
than 80 % of its packets arrive good, or when any arrives for the cases that expect none (asleep, lambda discard);
|
||||
the dev bug repros, 64 bytes with CRC (#22635) and the receiver after begin_tx plus begin_rx (#22636) are reported
|
||||
but not judged.
|
||||
- High rate (`fast`): the `rate` action sets modulation, symbol rate, deviation, filter and sync at run time on both
|
||||
radios, and `long_tx` polls at 20 to 50 us. Use sync 30/32: with 16/16 at 100 kBaud noise syncs about once a second
|
||||
and collides with real packets. At 100 kBaud a stable RXBYTES read alone overflowed at the first drain
|
||||
(`received=0 expected=300 fifo=65`, 10/20 at 300 B on the C3) and the GDO0 drain got 20/20; 38.4k showed no
|
||||
difference. The C3 shows the overflow more than the S3.
|
||||
- A strong RSSI (about -29 dBm) with ok=0 is a real corruption; ok=0 at -90 dBm, LQI 127 is a noise sync.
|
||||
- An API drop mid-run can be a Wi-Fi roam scan, not a restart (check serial); rerun.
|
||||
@@ -1,7 +0,0 @@
|
||||
# combination
|
||||
|
||||
## NaN from the last source (#22510)
|
||||
|
||||
A combination sensor defers each update and uses the value of the source that published last. A NaN from that
|
||||
source drops the whole update, so when testing NaN handling keep the last-publishing source finite, and compare
|
||||
rows one update late. Heap churn per update: see `heap_alloc.md`.
|
||||
@@ -24,11 +24,3 @@ put `scripts/` on `PYTHONPATH`):
|
||||
- Quick crash reboots count toward BK72xx safe mode, so space out back-to-back crash tests on those boards.
|
||||
- A device that keeps the previous crash replays it to every new log client until the next crash; that is one
|
||||
record, not two.
|
||||
|
||||
## Crash records and log subscribers
|
||||
|
||||
The record is replayed and cleared by the first log subscribe (`on_subscribe_logs_request`), so drain it on the
|
||||
first boot after an OTA, or a stale record from the previous build shows up. Moving `api: port:` keeps Home Assistant
|
||||
off the board while testing. `scripts/crash_report/quiet_then_subscribe.py HOST PORT OUT N` drains the record, stays
|
||||
connected without a log subscription for N reboots, then subscribes and records the replayed record; it tells a crash
|
||||
that needs a log subscriber (like the W5500 IPv6 reboot abort in `reference/boards.md`) from one that does not.
|
||||
@@ -5,48 +5,3 @@
|
||||
The NONOS SDK only delivers broadcast ESP-NOW frames while the station is associated or a soft-AP is
|
||||
up; a hidden, open, client-less soft-AP (60 s beacon, DHCP stopped) makes broadcasts arrive. In AP-only
|
||||
mode the device transmits from the soft-AP MAC.
|
||||
|
||||
## ESP-NOW and UDP packet_interface links (#21120)
|
||||
|
||||
Files in `scripts/espnow_link/` (a D1 mini and a classic ESP32; copy each `*.example.yaml`, set `name`, the peer's name
|
||||
and its MAC or address):
|
||||
|
||||
- `enlink.yaml` + `en32.example.yaml`/`en66.example.yaml`: ESP-NOW without Wi-Fi on a fixed channel. Links `p2p`
|
||||
(peer_address, xxtea, hdlc, session, fragmentation), `bc` (broadcast, addressing with a reliable rolling code port
|
||||
`bc_rel` and a broadcast port `bc_all`), `raw` (size sweep, sent size in the header) and `raw_small` (100 bytes,
|
||||
oversize warning). `entity_transport` on three stacks (ETRX and SESS log lines) and checked 12/200/600 byte streams
|
||||
on the reliable tops. `chaos: "true"` makes the board hop channel for 3 s and later 15 s (`espnow.set_channel`), a
|
||||
clean way to lose frames without touching the other board.
|
||||
- `entest.hpp`: `entest::Stream` checked stream (seq, sent size, pattern; counts ok/bad/gap/dup/trunc/foreign, `STAT`
|
||||
line). A stream on the top of a stack that also carries `entity_transport` starts with 0x1E (version 1, unknown
|
||||
type), so entity_transport drops it silently. The UDP only streams `P2PF` and `P2PT` are there too.
|
||||
- `udplink.yaml` + `ud32.example.yaml`: six udp components (unicast peer, subnet broadcast, multicast with
|
||||
`listen_address`, peer plus test host, `point_to_point: false`, `point_to_point: true` on the broadcast). Multicast
|
||||
needs `listen_address: <group>` on the udp component or nothing is received. `udpraw.py SECS HOST...` sends a
|
||||
datagram per second to ports 21121/21125/21126 of each board from the computer and counts what the boards send to it
|
||||
on 21124 (exits 1 when none arrived). Its datagrams start with 0xA5 0x5D, no stream's magic, so the links that
|
||||
accept third-party traffic count them as foreign. The `tick` and `stream_interval` substitutions set the load.
|
||||
- `pairrun.sh PREFIX E32V D1V [SECS] [RUN]`: flashes `<PREFIX>32<E32V>.yaml` on the ESP32 and `<PREFIX>66<D1V>.yaml`
|
||||
on the D1 mini (build letter p from `PR_TREE`, any other from `BASE_TREE`), captures both from a reset and prints a
|
||||
summary per board for the prefix. It exits 1 when a capture fails, or a board logs no STAT line, reboots during the
|
||||
capture or logs a crash.
|
||||
- `urlink.yaml` (prefix `ur`): minimal unicast A/B (one raw link plus `on_receive`), PR against base.
|
||||
- `rglink.yaml` (prefix `rg`): existing users (packet_transport over UDP multicast and ESP-NOW, udp.write,
|
||||
espnow send and broadcast actions and triggers); remote entities for both peer names so one image serves four
|
||||
pairings.
|
||||
- `encheck.py LOG...`: per link counts, gaps and bad float values from ETRX lines, last STAT per stream, warning
|
||||
histogram; exits 1 on a reboot or crash during a capture, a value never sent, a stream with bad payloads, an ETRX
|
||||
line it cannot parse, no STAT line or no counter value on any link.
|
||||
`validation_cases.py`: writes 41 ok_/bad_ configs into `out-valid/`; run `esphome config` on each.
|
||||
|
||||
Facts:
|
||||
- ESP-NOW v2 frames above 250 bytes from an ESP32 (IDF 5.5) arrive on an ESP8266 cut to 250 bytes, not dropped.
|
||||
- On the ESP8266 a peer link hears the peer's broadcasts (no destination reported), so with a chatty broadcaster it
|
||||
logs "10 packets in a row could not be understood".
|
||||
- The espnow send pool fills under a few hundred packets a minute; each refused send logs `[E] Failed to allocate
|
||||
send packet from pool`.
|
||||
- On a busy Wi-Fi network about half of the broadcasts between a D1 mini and an ESP32 can be lost, the D1 logs
|
||||
`sendto() error 5` (lwIP ERR_IF) under load, and reliable UDP links on the broadcast address flap on dev too;
|
||||
unicast is about 95 to 100 %. Keep UDP loads light (counter tick 5 s, streams every 2 s) or the test measures the
|
||||
Wi-Fi. With Wi-Fi joined, `espnow.send` from the D1 to the ESP32 fails almost always (dev too).
|
||||
- The subnet broadcast address guess assumes .255; on a wider subnet (a /21, say) check it really ends in .255.
|
||||
@@ -1,41 +0,0 @@
|
||||
# Heap allocation counts and callers (#22509, #22510, ratgdo/esphome-ratgdo#705)
|
||||
|
||||
## Counting
|
||||
|
||||
Replace the global `operator new` in an `esphome: includes:` header on ESP32 (Arduino or ESP-IDF) and log the
|
||||
delta from an `interval`. Compare a PR build with its base on the same flow; the rate per second shows churn.
|
||||
- The ESP8266 core defines `operator new` non-weak. `-Wl,--wrap=_Znwj` worked in a sensor-only config but
|
||||
boot-looped a neopixelbus config (alignment fault in the wrapper), so report free heap only there.
|
||||
- `vec = {}` keeps a std::vector's capacity (it is an initializer_list assignment); only
|
||||
`std::vector<T>().swap(vec)` or `clear()` plus `shrink_to_fit()` frees it. Seen as heap that did not come back
|
||||
after a WLED effect stopped.
|
||||
|
||||
## Callers
|
||||
|
||||
`scripts/heap_alloc/`:
|
||||
- `allocring.hpp` counts every `operator new` and, once armed, keeps the first 1024 with their size, time and
|
||||
five caller PCs, about 28 KB of RAM. It disarms itself when full. The frame walker
|
||||
(`esp_backtrace_get_next_frame`) exists only on Xtensa (ESP32, S2, S3); on RISC-V chips entries keep size and
|
||||
time without callers. Aligned `operator new` (`std::align_val_t`) is not replaced, so it is not counted;
|
||||
nothrow `new` goes through the replaced one.
|
||||
- `allocring.yaml` (package, substitution `alloc_arm_s`) arms it that many seconds after boot and adds a
|
||||
"Dump allocations" button that logs what was kept. The press stops recording until the next reboot, so
|
||||
reboot (or reflash) before each run; a second press returns the same entries.
|
||||
- `alloc_marker(a, b)` from a lambda writes a marker entry, for example on each cover operation change, so the
|
||||
dump splits into phases.
|
||||
- `dump.py HOST OUT` presses the button and writes the dump to a fresh OUT, pressing again until the header
|
||||
and every entry arrived (a late log subscription or dropped log lines). `decode.py LOG ELF [ADDR2LINE]` prints each entry with its callers as function and file:line, and exits 2
|
||||
when the recorder never armed, an entry was still being written, entries are missing, repeated or out of
|
||||
range, no Xtensa entry has a caller, the ELF is from another build (the buffer address in the header differs), or the buffer
|
||||
filled. A PR build and its base can share that address, so copy each build's `firmware.elf` next to its dump. On RISC-V it prints sizes and times only. It reads only the newest dump in the file. The ESP-IDF ELF is `.esphome/build/<name>/build/firmware.elf`.
|
||||
- `cycles_cover.py HOST N OUT` waits for the "Allocation recorder armed" binary sensor, then moves the first
|
||||
cover to the far end and back N times (`cover_command(position=...)`, waiting for idle each way) with a states-only API client, then saves the dump the same way. It exits 2 when a move
|
||||
never reached its position.
|
||||
|
||||
Findings:
|
||||
- Arm well after boot: the scheduler regrows its storage once after the freelist trim (see `scheduler.md`).
|
||||
- Repeat the action several times in one session and count only what comes back. On a ratgdo cover (an external
|
||||
component, ESP32 ESP-IDF) the first door open after boot allocated 18 times: four 36 B SchedulerItems,
|
||||
`to_add_` and `items_` growth, and the API `DeferredBatch` vector. Cycles 2 and 3 allocated nothing.
|
||||
- Keep the API client out of the count (see `api.md`): connect before the run, subscribe to states only, and
|
||||
subscribe to logs only for the dump.
|
||||
@@ -66,23 +66,3 @@ only its current ID.
|
||||
`No entity ID set yet` check; nothing is sent either way.
|
||||
- Field 3 of LightStateResponse is brightness, not `missing_state`; SwitchStateResponse has no missing flag.
|
||||
- A light publishes only changes, so a report of the state it already has publishes nothing.
|
||||
|
||||
## homeassistant switch on a script, host build against a throwaway Home Assistant (#22548)
|
||||
|
||||
No board is needed when the change is in validation or platform independent code: an ESPHome `host:` build serves the
|
||||
API on 127.0.0.1:6053. `scripts/homeassistant_script_switch/`:
|
||||
|
||||
- `ha-configuration.yaml` is the Home Assistant config (port 8129, a 20 s `long_job` script that sets and clears
|
||||
`input_boolean.script_ran`, a `quick_job` toggle script). Onboard it with `scripts/mqtt/ha_discovery/onboard.py DIR`.
|
||||
- `hsw.yaml` mirrors both scripts and the flag with homeassistant switches, with template buttons that call
|
||||
`switch.turn_on` and `switch.turn_off`.
|
||||
- `haflow.py TOKENFILE` adds the device with the esphome config flow and turns on `allow_service_calls` in the options
|
||||
flow; without it the device's action calls are refused.
|
||||
- `drive.py TOKENFILE NAME` presses the buttons through the REST API and prints the script and flag states after each
|
||||
step.
|
||||
|
||||
Notes:
|
||||
- homeassistant import entities default to `internal: true`, so the mirrors are not Home Assistant entities; read
|
||||
them from the device's `Got state` log lines.
|
||||
- Turning a script off stops it mid run (the flag stays on). A script that finishes at once reports on, then off, in
|
||||
the same second.
|
||||
@@ -1,46 +0,0 @@
|
||||
# Improv serial and BLE (#22597)
|
||||
|
||||
`scripts/improv/` drives Improv on a freshly erased board with no saved network:
|
||||
|
||||
- `improvcli.py PORT OUT --secrets FILE`: Improv serial client. It shares the console with the logs and parses
|
||||
frames out of the log stream. The flow: 300 stray bytes with no `I` in them, state, info, network state, scan, a
|
||||
bad password (expect `unable_to_connect` after about 30 s), the real password, then state and network state
|
||||
again. It ends with a count of frames, bad frames, port resets, reboots and log lines. Credentials come from the
|
||||
secrets file and are never printed, and the SSID is masked in scan results. It reopens a native USB port that
|
||||
re-enumerates. A reboot is counted from each new `Running through setup()` log line after the settle, so a board
|
||||
behind a USB-UART bridge that reboots without a port reset is caught too.
|
||||
Every request must get its reply; a missing reply, an unexpected error, a malformed frame, a port reset or a
|
||||
reboot fails the run. `--skip-bad` leaves out the bad password case, `--keep-dtr` leaves DTR asserted,
|
||||
`--allow-reset` accepts a reboot.
|
||||
- `improvble.py NAME SECRETS`: Improv BLE client (bleak). Finds the device by name, sends WIFI_SETTINGS and prints
|
||||
the state changes and the RPC result URLs. Needs `improv_ble` (formerly `esp32_improv`) with `authorizer: none`
|
||||
and a `next_url`; the result must carry a URL.
|
||||
- `common.yaml`: package with Wi-Fi and no network, `web_server`, `improv_serial` with a `next_url` (so the
|
||||
provisioned reply carries URLs) and an ALIVE line every 5 s. `example-esp32.yaml` uses it on a classic ESP32.
|
||||
- `run.sh NAME [improvcli args]` (env `TREE`, `PORT`, `SECRETS`, `PY`): compile, erase, flash and run the client.
|
||||
It erases with esptool, so ESP chips only; on LibreTiny or RP2040 erase and flash with that platform's tools and
|
||||
run `improvcli.py` directly. Both clients end with PASS or FAIL and exit non-zero on FAIL.
|
||||
|
||||
Per board:
|
||||
|
||||
- Improv serial uses the logger's UART, so the client must open the port the log is on. On LibreTiny check which
|
||||
UART `logger: hardware_uart: DEFAULT` resolves to (see the board notes).
|
||||
- BW15: drop `web_server:` or add an `ap:` (it resets during setup otherwise), and pass `--allow-reset` for the known
|
||||
reboot after `Disabling AP`; the provisioned reply usually goes out first, not always. See `reference/boards.md`.
|
||||
- ESP32-C3 on USB_SERIAL_JTAG: passes with and without `--keep-dtr`; its reboots only show in the
|
||||
`Running through setup()` count (see `reference/boards.md`). The scan returns only the last scan's results, which
|
||||
are empty in the first seconds after boot; use `--settle 10` or more when the target network should be listed.
|
||||
- Pico 2 W: run with `--keep-dtr` (see `reference/boards.md`). Its Improv scan lists no networks, on dev and PR alike.
|
||||
- Erase the flash between builds: a saved network skips the provisioning path entirely. Both clients fail at once
|
||||
when the board already reports `provisioned`; erase the flash first. A new config name does not help: the
|
||||
network is saved under a fixed key when the config has no `networks:`. A provisioned board also stops advertising
|
||||
Improv over BLE, so `improvble.py` reports the device as not found.
|
||||
- If the real password fails right after the bad password case, rerun once before blaming the change: on the C3 it
|
||||
failed once (`Auth Leave` while Wi-Fi was still retrying the bad network) and passed on every rerun.
|
||||
|
||||
When posting results:
|
||||
|
||||
- Scan results list the neighbours' SSIDs; filter `RPC cmd=4 len=[1-9]` lines out of anything you post.
|
||||
- Mask IP addresses in the result URLs.
|
||||
- Cover a long password too: provision once against a network whose password is 20 characters or more (the client
|
||||
prints the length).
|
||||
@@ -61,10 +61,3 @@ frame of two LEDs set to `Color(0xA5, 0x3C, 0x0F)` reads `3ca50f3ca50f`.
|
||||
- An RP2350 `panic()` escalates to a HardFault and the rp2 crash handler reboots within about a second, so a panic
|
||||
during component setup boot-loops before USB CDC enumerates and the board looks dead (no port, no BOOTSEL drive).
|
||||
Hold BOOTSEL while plugging it in and flash the UF2 drive. To see such a fault, trigger it after boot.
|
||||
|
||||
## Counting a PIO strip's edges on its own pin (#16243)
|
||||
|
||||
A GPIO interrupt on the strip's own data pin (`gpio_set_irq_enabled_with_callback(pin, GPIO_IRQ_EDGE_RISE, ...)`)
|
||||
counts every bit the PIO program sends, with no wires or LEDs; a strip that sends nothing shows 0 edges per report.
|
||||
Log the PIO block's state machine enable mask and program counters next to the count. `pio_probe/pio-common.yaml`
|
||||
clears PIO1 instruction memory at boot because it survives a reflash (see `reference/boards.md`).
|
||||
@@ -34,11 +34,3 @@ wave on the same pad no longer reaches the input (the pad reads 0).
|
||||
- Result on #21074 at 2ef417bd81 with peripherals powered down: the PR caught all 644 real edges (dev 66) but added
|
||||
4642 calls while the line was high, one per sleep cycle (about 16 ms), with the level read correctly. Peripherals
|
||||
on: both builds caught every edge. https://github.com/esphome/esphome/pull/21074#issuecomment-6503939850
|
||||
|
||||
## Power lock check
|
||||
|
||||
`power_management: esp32_power_management` with `profiling: true` and an `interval` lambda that calls
|
||||
`esp_pm_dump_locks(stdout);` prints the lock and mode tables on the USB console (not through the ESPHome logger).
|
||||
Compare lock lists between builds: `usb_serial_jtag` holds `NO_LIGHT_SLEEP` by itself. For a soak that the USB console
|
||||
must not keep awake, set `logger: hardware_uart: UART0`, dump the locks into `open_memstream()` and log the SLEEP,
|
||||
CPU_MAX and light sleep count lines, read over the API.
|
||||
@@ -16,18 +16,3 @@ states, saves the device log). Before 8cc8df4a1f a modem only config with `api:`
|
||||
config dependent `AUTO_LOAD` added `network` after the dependency check; an explicit `network:` block was the
|
||||
workaround. Results: https://github.com/esphome/esphome/pull/6721#issuecomment-6347395159 and
|
||||
https://github.com/esphome/esphome/pull/6721#issuecomment-6348520416
|
||||
|
||||
## SIM7080G on an M5Stack Atom Lite (#6721)
|
||||
|
||||
The M5 Unit CatM (SIM7080G) on the Atom Lite's Grove port: RX GPIO32, TX GPIO26, `model: SIM7080`.
|
||||
`templates/modem/modem-passthrough.yaml` is a raw UART passthrough with both directions logged, and
|
||||
`scripts/modem/mdrive.py HOST LOGFILE text:AT+CPIN? wait:5 ...` sends AT commands through it and saves the
|
||||
replies, to check what the module does with no component in the way.
|
||||
|
||||
- With no SIM, the component sets the `SIM not ready` warning and polls `AT+CPIN?` once a second.
|
||||
- With a SIM that has no data plan, `AT+CGATT=1` blocks the AT channel for about 141 s and then answers `ERROR`.
|
||||
The module answers nothing meanwhile, so the component logs `Network attachment request refused` and then `Modem not
|
||||
responding`, and loops every 2 minutes 22 seconds.
|
||||
- `AT+CFUN=1,1` leaves the module silent for about 2.5 minutes. It comes back without a power cycle.
|
||||
- A module left in CMUX (`AT+CMUX=0`, then an ESP restart) recovered 10 of 10 times (`Autodetect mode: 5`).
|
||||
- PPP and a warm reboot during PPP need a SIM with a working data plan.
|
||||
@@ -1,29 +0,0 @@
|
||||
# nPM1300 PMIC on the Seeed XIAO nRF54LM20A (#22661)
|
||||
|
||||
Scripts: `scripts/npm1300/`. The board's nPM1300 sits at 0x6B on P1.18 (SDA) and P1.17 (SCL); board facts, including
|
||||
which rails must never be switched off, are in `reference/boards.md`.
|
||||
|
||||
- Probe first: `npmprobe.yaml` has the hub with no regulator or charger settings, scans the bus and dumps the
|
||||
registers every 20 s, so you see what is on before any setting is written.
|
||||
- `npm-all.yaml` (with `npmcommon.yaml`) has every sensor, binary sensor, text sensor and switch, logs each value from
|
||||
`on_value` and `on_state` lambdas (entity state lines are VERBOSE on dev, so DEBUG shows nothing without them), dumps
|
||||
the registers and switch states, and toggles the charger and LDO1. Put a setting under test (the VBUS limit, the
|
||||
charger values) in `npmcommon.yaml`, not in the per-run file.
|
||||
- `regdump.yaml` reads a fixed register list with `id(pmic).read_register16()` and logs `REGS 0201=.. ...`; compare two
|
||||
builds' dumps after stripping timestamps and source line numbers.
|
||||
- `runone.sh NAME CONFIG PORT [SECS]` flashes with `esphome run --no-logs` (pyOCD) while a serial capture stays open on
|
||||
the same port. Builds without `ota:` have no MCUboot.
|
||||
|
||||
Findings:
|
||||
|
||||
- With no battery and the charger on, VBAT reads about 4.23 V, IBAT about 0.2 mA, battery detected is ON and the status
|
||||
flips between Trickle Charge and Constant Current; with the charger off it says No Battery, and it can drop to Not
|
||||
Charging for one update on its own. The battery temperature stays at 24.6 C (a fixed 10 k on the NTC pin). Charge
|
||||
current scale and sign need a real cell.
|
||||
- ADCIBATMEASSTATUS (0x0510) reads 0x0C (charge) most of the time with no cell and the charger on, sometimes 0x08 or
|
||||
0x0F.
|
||||
- `vbus_current_limit: 300mA` writes ILIM0 and ILIMSTARTUP as 0x03 and the board stays up on USB.
|
||||
- BUCKSWCTRLSEL (0x040F) keeps its value across reflashes until a power cycle, so a setup write to it shows no change on
|
||||
a warm board.
|
||||
- To prove a setup priority change, add `on_boot` hooks at 1001, 950 and 900 that log markers and see where the
|
||||
component's first publishes land between them.
|
||||
@@ -101,14 +101,3 @@ once on a build without TCP, or `tcp ok udp ok` twice and no error with it. Add
|
||||
come back, and connect with `apicheck.py ADDR` over Thread. Measured on the ItsyBitsy: 12.9 KB less flash and 17.1 KB
|
||||
less RAM without TCP (Zephyr's default pools, 16/16 instead of 24/48), and SMP over UDP OTA still works with them.
|
||||
Results: https://github.com/esphome/esphome/pull/21910#issuecomment-6518287139
|
||||
|
||||
## sdk-nrf 3.4.1 on the ItsyBitsy (#22233, #22558)
|
||||
|
||||
- Set `framework: version: 3.4.1` and `board: adafruit_itsybitsy`.
|
||||
- Trees before #22233 include `<nrf.h>` in `logger_zephyr.cpp`, which 3.4.1 no longer has on the include path, so
|
||||
Adafruit bootloader boards fail to build (`nrf.h: No such file or directory`). To test such a tree on 3.4.1, change
|
||||
that include to `<nrfx.h>` locally.
|
||||
- On the new USB stack, `usb_cdc_acm` bulk echo ran at about half the legacy rate (67 against 121 KiB/s for 64 KiB),
|
||||
and `flush()` returned `3`. The logger, DTR, line coding and the 1200 baud touch worked.
|
||||
- The zephyr_ble_server flow above, on 3.4.1: before #22558 advertising failed to restart after the first disconnect
|
||||
(`Advertising failed to start (rc -12)`); with it the server took 39 connections in 120 s.
|
||||
@@ -1,32 +0,0 @@
|
||||
# one_wire
|
||||
|
||||
## ESP8266 interrupt locks under Wi-Fi load (#22452, #22453)
|
||||
|
||||
Code that holds interrupts off for long on the ESP8266 starves the Wi-Fi interrupt handler (reset signatures in
|
||||
`reference/boards.md`). `scripts/esp8266_lock_load/` is the shared harness for any component that takes such locks:
|
||||
|
||||
- `base.yaml` is the shared DUT base: reset reason and info logged at boot, `power_save_mode: none`, `web_server` for
|
||||
the HTTP load, `api: reboot_timeout: 0s`.
|
||||
- `one-wire.yaml` reads a DS18B20 on GPIO4 every 2 s and runs a bus search every `search_interval`; `busy_control:
|
||||
"true"` replaces the search with the same busy time (13 ms) and no 1-Wire traffic.
|
||||
- `ir-one-pin.yaml` is the remote_transmitter case (see [remote_base.md](remote_base.md)).
|
||||
- `wifi_load.py HOST SECONDS PPS` sends 512 byte UDP datagrams to port 9 at a fixed rate plus back to back GETs of
|
||||
the web_server page.
|
||||
- `run.sh` builds and flashes a DUT, captures the serial log, runs the load and prints every reset reason (usage in its
|
||||
header). A clean run has one BOOT line.
|
||||
|
||||
Make one file per build with `substitutions: {name: ...}` and `packages: {t: !include one-wire.yaml}`, with
|
||||
`secrets.yaml` next to it, and give dev and the PR different names.
|
||||
|
||||
Notes:
|
||||
- Run each build for 45 minutes at 500 packets per second. Shorter or lighter runs often show no reset on either
|
||||
build: one search every 5 s survived on both.
|
||||
- The busy-wait control separates the lock from the CPU time. On #22452 it had no Hardware Watchdog in 45 minutes,
|
||||
while the PR still had 2 (dev had 6), so the remaining resets came from the slot locks. All three builds had one
|
||||
Software Watchdog, which is the busy time plus the load.
|
||||
- A search with no sensor answering is much shorter than one with a sensor (about 190 slot locks per search with
|
||||
one DS18B20), so test with a real sensor on the bus.
|
||||
- A stale `secrets.yaml` gives `No networks found` and the run has no IP to load.
|
||||
- The 1-Wire bus code is shared by every platform, so check a lock change on an ESP32 too: the same DS18B20 search
|
||||
config on ESP-IDF with `bluetooth_proxy` scanning and the same load gave 0 resets and no missed searches on dev and
|
||||
on #22452.
|
||||
@@ -12,8 +12,7 @@ markers and prints what each sent frame decoded as.
|
||||
- ESP32: `remote_transmitter` and two `remote_receiver`s on the same GPIO (`allow_other_uses`), carrier 100%, no
|
||||
inversion. RMT reads its own output, every frame decodes. Second receiver `dump: [nec, raw]` shows raw runs only
|
||||
where no primary matched.
|
||||
- ESP8266 before #22453: the transmitter sends the whole frame with interrupts off, so a receiver on the same pin
|
||||
sees nothing (from #22453 on it decodes, see below). For older trees, `softtx.hpp`
|
||||
- ESP8266: the transmitter sends with interrupts off, so a receiver on the same pin sees nothing. `softtx.hpp`
|
||||
bit-bangs frames built with each protocol's `encode()` with interrupts on, and an `interval` sets the pin back to
|
||||
OUTPUT after the receiver's setup. Bit-banged NEC decodes as NEC about 2 of 3 times (timing), on every build.
|
||||
- Dish never decodes in loopback on dev either. Pronto matches every frame, so raw on `dump: all` never prints.
|
||||
@@ -29,18 +28,3 @@ Results: https://github.com/esphome/esphome/pull/21563#issuecomment-6381304387
|
||||
Retest of the moved stack with 5 rounds per build: https://github.com/esphome/esphome/pull/21563#issuecomment-6382075726.
|
||||
A D1 mini CH340 sometimes fails the 460800 baud upload; esphome retries at 115200 by itself, but a runner that reads
|
||||
only the last line sees "Failed to upload" first, so rerun before blaming the build.
|
||||
|
||||
## ESP8266 transmitter to receiver on the same board (#22453)
|
||||
|
||||
- Wire the `remote_transmitter` pin to a `remote_receiver` pin (GPIO12 to GPIO14 on a D1 mini), `inverted: false`.
|
||||
- Keep the receiver's default `idle`. `idle: 4ms` is shorter than the NEC leader space (4.5 ms), so every frame is
|
||||
split and nothing decodes.
|
||||
- Dev before #22453 sends the whole frame inside one `InterruptLock`, so a receiver on the same chip decodes 0
|
||||
frames. That is expected on old builds, not a wiring fault. With locks per edge, 3,692 of 3,695 frames decoded
|
||||
under Wi-Fi load.
|
||||
- Count with `on_nec` matching a counter in the command, and log the counts on an `interval`.
|
||||
- Without a jumper, put both on GPIO12 with `allow_other_uses: true` and call `pinMode(12, OUTPUT)` before each frame
|
||||
(the receiver's setup leaves the shared pin as an input); the receiver's edge interrupt sees the transmitter's own
|
||||
output. `scripts/esp8266_lock_load/ir-one-pin.yaml` does this, and its `run.sh` adds Wi-Fi load (see
|
||||
[one_wire.md](one_wire.md)). Under load, the build that sends the whole frame in one lock hit a Hardware Watchdog in
|
||||
`wDev_ProcessFiq` after 11 minutes.
|
||||
@@ -21,19 +21,3 @@ captures 40 s from boot and runs `ivsum.py`, which prints the run count, first r
|
||||
runs), so do not compare those offsets between builds.
|
||||
- `main.cpp` shows the class each interval gets (`IntervalTrigger` or `DelayedIntervalTrigger` on #21799).
|
||||
- Results: https://github.com/esphome/esphome/pull/21799#issuecomment-6516798398
|
||||
|
||||
## Freelist trim after boot (ratgdo/esphome-ratgdo#705)
|
||||
|
||||
10 s after setup the scheduler frees its item pool and shrinks its `to_add_` and `items_` vectors
|
||||
(`SCHEDULER_FREELIST_TRIM_DELAY_MS` in `application.cpp`). The first burst of timers after that allocates new
|
||||
items and regrows the vectors once, so heap or timing measurements should skip the first run after boot.
|
||||
|
||||
## RP2 scheduler lock under IRQ and lwIP load (#22688)
|
||||
|
||||
`scripts/rp2_sched_lock/` (README there). The `irq_sched_stress` external component calls `defer()` and `set_timeout()`
|
||||
from a 300 us pico-sdk repeating timer while the main loop does the same; the removed item race integration fixture
|
||||
runs on the board as an API action. `flow.sh` runs the actions, API connect churn (`../api/connstress.py`), REST POST
|
||||
churn and both together, then the actions again, and fails on a failed action, a failed connstress 500x2 or a reboot.
|
||||
Judge by counts, not order: RP2 is `ESPHOME_THREAD_SINGLE`, so `defer()` order is not FIFO on any build. Keep
|
||||
`debug_scheduler` off, it logs from the IRQ. Dev before #22688 failed the defer count on the Pico W; the PR passed.
|
||||
`looptime.sh` compares the 16 ms interval gaps with the API and page loads running between two builds.
|
||||
@@ -73,98 +73,3 @@ address they do not simulate.
|
||||
- An `addressable_light` display writes nothing until its light is turned on.
|
||||
- Before calling a rebased PR's change trivial, diff the PR's own diff (head against its parent) old against new: a
|
||||
move that looks like a merge only can carry real commits from below.
|
||||
|
||||
## TRF7962A fake chip (#22188)
|
||||
|
||||
`scripts/trf7962a_sim/`: `trfsim.hpp` replaces the SPI component's bus (`SPIComponent` is final, so `spi_bus_` is
|
||||
reached through the explicit-instantiation member pointer trick) with a `FakeBus` from `on_boot` priority 800, between
|
||||
the bus (1000) and the reader's setup (600). The bus hands both of the reader's clients (MODE0 write, MODE1 read)
|
||||
delegates on one register, FIFO and IRQ model; the IRQ pad is switched to input/output after setup and driven by the
|
||||
model. `trfpr.yaml` runs the tag scenarios (none, present, slow, flaky, swap, collision, CRC, error flag, bad MSB,
|
||||
TX only, stuck IRQ) and prints per-phase counters (CS, field timing, TX payload, reads without an address). The
|
||||
same FakeBus approach works for any SPI chip whose reply depends on the address byte inside one CS window, which the
|
||||
ESP32 SPI slave cannot fake.
|
||||
The header targets the SPI API of the #22188 branch (`SPIBus` and `SPIComponent::spi_bus_`); dev has since dropped
|
||||
`SPIBus`, so on a newer tree the bus hook has to move to the new delegate creation before it builds.
|
||||
|
||||
## SX127x fake chip (#22733)
|
||||
|
||||
`scripts/sx127x_sim/`: `sxsim.hpp` is a fake SX1276, `sxrun.hpp` the scenario runner, `sxsim.yaml` the ESP32-PICO-D4
|
||||
config (no Wi-Fi; `sxpr.yaml` and `sxbase.yaml` are two-line wrappers setting `substitutions: flags: -DSXSIM_PR` or
|
||||
`-DSXSIM_BASE` and `packages: sim: !include sxsim.yaml`, since `-s flags -D...` is parsed as an option).
|
||||
- Hook, no private access needed on the current SPI API (`SPIBus` is gone; `register_device()` builds the delegate in
|
||||
the client's `spi_setup()`): the bus is `interface: software`, and at on_boot 800 `set_clk/set_mosi/set_miso` on the
|
||||
bus and `set_cs_pin` on the radio swap in fake `GPIOPin`s, so the real `SPIDelegateBitBash` clocks every bit into
|
||||
the model (the MISO read drives the bit engine, as the PR's own gtest helper does). Works on any driver revision.
|
||||
The fake pins live in `spibits.hpp` (`PinSet` bound to a `SpiChip` with per byte reply and receive hooks, a lock
|
||||
hook and an `after_end()` that runs outside the lock), shared by `sxsim.hpp`, `sxair.hpp` and `sxrec.hpp` and
|
||||
buildable on the host; ESPHome copies only the files in `includes:`, so every config lists it.
|
||||
`InternalGPIOPin` is a final platform class alias, so rst and DIO0 cannot be faked on old drivers; rst is a real
|
||||
pad and a RegVersion read resets the model instead. DIO0 is GPIO4 with pulldown, switched to INPUT_OUTPUT at on_boot
|
||||
399 and driven by the model, so the rising edge interrupt really fires.
|
||||
- Send completion runs from a one-shot `esp_timer` (`M.tx_ms`), because a blocking `transmit_packet()` spins on the
|
||||
DIO0 pad with no SPI traffic and no loop; model state is shared under a `portMUX`.
|
||||
- Faults: `M.fail_mode_writes = N` (RegOpMode writes ignored, mode reads back old), `M.tx_never`,
|
||||
`sxsim::arm_rx_on_standby({...})` (a packet completes just as a send writes standby), `M.version`, CRC error inject.
|
||||
The chip ignores mode requests other than standby/sleep while a send is still going out (counter `ign_tx`).
|
||||
- The FSK FIFO is one 64 byte queue for TX and RX, cleared on sleep and on entering RX, so a send that writes over a
|
||||
waiting FSK packet transmits the received bytes (dev did that in #22733's test). LoRa TX leaves the chip in standby
|
||||
with TX_DONE set; FSK stays in TX with PacketSent.
|
||||
- `sxrun.hpp` boot cases use `RTC_NOINIT` plus `esp_reset_reason() == ESP_RST_SW` (a flash or EN reset starts at case
|
||||
0): 0 LoRa and FSK sequence (traces of one blocking send per modulation as `TRACE` lines, receive, rx before send, raw
|
||||
set_mode_tx, async OK/BUSY/INVALID/timeout/cancel, actions during a send, runtime mode failure with a 6 s watch),
|
||||
1 blocking send that never completes, 2 wrong version, 3 mode failure at setup, 4 `ALLDONE`. One 75 s capture with
|
||||
`--reset` covers all of it. `STATE` lines print the model counters.
|
||||
- On #22733, dev lost a packet waiting at send start (LoRa) or sent it as its own (FSK), delivered a stale packet after
|
||||
raw TX mode (LoRa) or two empty ones (FSK), and was marked failed after a blocking send timed out because RX is
|
||||
refused while the chip is still in TX. The PR passed every case.
|
||||
|
||||
## Two radios and a simulated air (#21110)
|
||||
|
||||
`scripts/sx127x_sim/sxair.hpp` (models and air), `sxlink.hpp` (runner), `gen_pair.py OUTDIR` (writes `lpair` two SX127x
|
||||
LoRa, `fpair` two SX127x FSK, `xpair` SX127x plus SX126x LoRa, each with a `<name>_glue.h`, and copies the shared
|
||||
headers next to them). One ESP32-PICO-D4
|
||||
firmware, two software SPI buses; at on_boot 1100 (before the buses' setup at 1000) the bus pins, CS, reset and SX126x
|
||||
busy are swapped for fake pins (needs the `GPIOPin *` reset setter from #22733), so the only pads used are the interrupt
|
||||
lines GPIO4 (A) and GPIO22 (B), switched to input/output at on_boot 300. Shared real pin numbers need
|
||||
`allow_other_uses`.
|
||||
- SX126x fake: command parser on CS rise (SetPacketType, SetModulationParams, SetPacketParams, SetDioIrqParams,
|
||||
ClrIrqStatus, WriteBuffer, SetTx/SetRx/SetStandby/SetSleep), replies per byte position for ReadRegister (version
|
||||
string at 0x0320), ReadBuffer, GetIrqStatus, GetRxBufferStatus, GetPacketStatus; BUSY is a fake pin that is always
|
||||
low; IRQ bits latch only when in the IRQ mask, DIO1 = irq & dio1 mask.
|
||||
- Air: airtime from the sender's own registers and commands (Semtech LoRa formula; FSK bytes at the bitrate), delivery
|
||||
to every receiver that stayed in RX, RSSI and SNR per receiver, collisions give a CRC error, knobs `AIR.drop_next`,
|
||||
`AIR.corrupt_next`, `jam(radio, ms or UINT32_MAX)`, `tx_never`. A receiver shows a signal while a packet is on air
|
||||
(SX127x LoRa ModemStat, FSK IrqFlags1 sync match held until read, SX126x preamble/sync/header IRQs).
|
||||
- Gotcha: both radios share one main loop, so while one radio's blocking send runs the other cannot read its FIFO
|
||||
and the next packet overwrites the unread one (first runs lost 12 of 53 and no HDLC link came up). The model
|
||||
holds a packet that lands while the previous one is unread and hands it over from the 1 ms air tick once the
|
||||
driver has read the previous one and 3 ms passed with no SPI on that radio (draining at the flag clear corrupts
|
||||
the read in progress). A held packet must clear the receiver's signal, or listen before talk sees a phantom busy
|
||||
radio. Counters `held` say how often it happened; say in results that this is a simulator artifact.
|
||||
- Raw links share the radios with the layered links, so a raw send can be refused by listen before talk while the
|
||||
layered links talk; retry. Raw test packets start with 0xEE and carry a length-derived pattern.
|
||||
- `tx_over_signal` counts sends started while the sender showed a signal: 0 outside the hold cap phase means listen
|
||||
before talk never sent over a packet.
|
||||
- The run ends with `DONE fails=N`: values that never arrived, refused sends of valid sizes, accepted oversize sends, a
|
||||
refused peer send in the listen before talk phase, held sends never released, no release in the hold cap phase and
|
||||
raw packets with a bad pattern or that did not arrive exactly once at their size. `AIR` lines also count FSK FIFO
|
||||
writes dropped when full and reads when empty (`fifo_over`, `fifo_under`).
|
||||
|
||||
## SX127x SPI byte stream A/B (#22776)
|
||||
|
||||
- Host: copy `scripts/sx127x_sim/sx127x_spi_record_test.cpp.example` as a `.cpp` into `tests/components/sx127x/` of
|
||||
each tree and run `SX127X_RECORD=<file> script/cpp_unit_test.py sx127x` (the env var reaches the test binary). It
|
||||
sweeps FSK and LoRa frequency, bitrate, deviation and preamble edges through setup, configure() and 1 byte and
|
||||
largest sends against a register file with burst auto-increment (FIFO address fixed), and writes CASE/T/REGS/FIFO
|
||||
records. Case labels must be unique (an index is prefixed) or the compare silently drops cases. `compare_spi.py BASE
|
||||
PR` checks register files and FIFO exactly and compares the transactions flattened into per-register operations, so
|
||||
only grouping may differ.
|
||||
- Device: `sxrec.hpp` with `recsw.yaml` (software bus, fake pins at on_boot 1100) or `rechw.yaml` (ESP-IDF hardware bus
|
||||
`interface: spi2`), two short wrappers setting the substitutions of `rec.yaml`: a tee delegate robbed into `SPIClient::delegate_` at on_boot 800 sends every byte through the
|
||||
real SPIDelegateHw and feeds the model; the radio's own spi_setup() then logs "Device already registered" once and
|
||||
keeps the tee. SPI3 as a slave sniffer (CLK 18, MOSI 23, CS 5 routed in, nominal CS GPIO14 high) captures each chip
|
||||
select window up to 64 bytes and compares it with what the driver sent ("WIRE ok/differ" line). Records print as
|
||||
"REC ..." lines; compare_spi.py reads the two device logs directly (it cuts each line at "REC " and joins the
|
||||
"REC +" continuation lines) and fails a log whose WIRE line counts differing or uncaptured windows. The host
|
||||
harness keeps its own register file and pins, so the copy step stays one file.
|
||||
@@ -1,52 +0,0 @@
|
||||
# tcp packet_interface link (#21119)
|
||||
|
||||
The `tcp` link carries `packet_interface` packets over one TCP connection: 2 byte little endian length, then the
|
||||
packet; a zero length packet is a keep-alive. Most of it can be tested with no board: the component works on `host:`,
|
||||
so two host builds on one computer talk over 127.0.0.1, and a raw Python peer covers what ESPHome cannot do on purpose.
|
||||
|
||||
Files in `scripts/tcp_link/`:
|
||||
|
||||
- `tcplink.yaml` (package): per device an `et_srv` and `et_cli` link carrying `entity_transport` both ways over xxtea
|
||||
plus fragmentation (nine 191 char broadcast ids so the dictionary is larger than one 1022 byte TCP frame), a
|
||||
`raw_srv`/`raw_cli` pair with no layers running a size sweep up to 1022 with checked payloads and sequence numbers
|
||||
(`STAT` line every 10 s: tx, refused, rx, bad, gap), a `probe_srv` (with `allowed_ips`) and a `probe_cli` for the
|
||||
Python peer, `CONN <link> 0/1` from every `connected` sensor, `ETRX` lines for remote states, and a 1023 byte send
|
||||
20 s after boot (must be refused). API on `${api_port}` with an encryption key from secrets.
|
||||
- `host-peer.example.yaml`, `esp32-peer.example.yaml`: the per device substitutions (ports, peer host, allow list).
|
||||
The ESP32 one adds `deny_srv` with an allow list that excludes the test computer, for the refused connect.
|
||||
- `tcp_peer.py client HOST PORT | server PORT`: raw peer. `--silent-after S` stops sending (receive timeout and
|
||||
reconnect), `--oversize-after S N` sends a header of N bytes (must close), `--send 1,1022` sends checked sizes,
|
||||
`--bind ADDR` picks the source address, `--hold S` closes after S. Prints keep-alive gap min/max per connection.
|
||||
- `apiwatch.py HOST PORT SECS [LOGFILE]` (`API_KEY` from `apikey.txt`): state changes with timestamps from connect;
|
||||
shows the `connected` sensors read False (not unknown) at boot, and writes the device's log lines at DEBUG and above
|
||||
(the level of the `CONN` and `ETRX` markers) to LOGFILE. The API coalesces a fast off/on, so judge edges from the
|
||||
`CONN` log lines.
|
||||
- `run_pair.sh host|esp32 [RUN]`: the timeline (boot states, SIGSTOP/SIGCONT of the host peer, kill -9 and restart,
|
||||
silent and oversize raw servers, one client at a time, a refused client, oversize from a client) against host build
|
||||
`tcph1` (peer `tcph2`, refused client from the LAN address; `LAN` overrides the macOS `ipconfig` guess) or the ESP32
|
||||
`tcpe1` (`NAME` overrides it, found with `resolve.sh`; peer `tcph3`, refused client on `deny_srv`). Build the host
|
||||
configs here first. Ports default to the example configs (`API_PORT`, `PROBE_PORT`, `PROBE_CLI_PORT`, `DENY_PORT`).
|
||||
Logs: `<RUN>-dut.txt` (the host build's output, or the board's log over the API in esp32 mode), `-peer-a.txt` and
|
||||
`-peer-b.txt` (before and after the kill), `-api.txt`, the raw peers and `-events.txt`, without ANSI colours. It
|
||||
exits 1 when a job ends with the wrong status (`apiwatch.py` fails on a dropped API connection, `tcp_peer.py` on no
|
||||
connection or a missed close), any device log (the device under test's included) shows bad raw packets or an
|
||||
accepted 1023 byte send, or a size the raw clients sent never reached the device's `probe_srv` with its sum.
|
||||
- `validation_cases.py`: writes one config per validation rule into `out-valid/`, named ok_ or bad_ by the expected
|
||||
outcome; run `esphome config` on each from the tree under test.
|
||||
|
||||
Facts:
|
||||
|
||||
- Source address trick: a server with `allowed_ips: 127.0.0.0/8` accepts `127.0.0.1` and rejects a connect to the
|
||||
computer's own LAN address with `--bind <LAN address>` (`Rejected <address>` in the log). No second
|
||||
machine needed.
|
||||
- A server accepts one client; the kernel completes a second client's handshake (backlog 1), the second gets nothing
|
||||
until the first closes, then it is accepted and its queued packets are delivered.
|
||||
- SIGSTOP of a host peer: the other side closes after `timeout`, the client reconnects after `reconnect_interval` and
|
||||
connects to the stopped process's backlog, then times out again. kill -9 closes at once (EOF/RST).
|
||||
- One packet accepted by the socket just before a drop can be lost (the raw sweep shows one sequence gap per
|
||||
direction per drop); the session goes down and `entity_transport` resends everything on reconnect, so states are
|
||||
not lost.
|
||||
- Host builds bind every interface; give each host build its own API port and link ports (6053 may be taken).
|
||||
- ESP32 pair (`run_pair.sh esp32`): the host peer reaches the board by its mDNS name; set `HOST_LAN_IP` in the ESP32 example to the computer's address.
|
||||
Over Wi-Fi with `power_save_mode: none`, the raw peer saw keep-alive gaps of 1.65 to 2.26 s. A hardware reset (`esptool --after hard_reset chip_id` with the capture stopped) sends no FIN, so the host closes
|
||||
on its own receive timeout and then reconnects.
|
||||
@@ -72,23 +72,3 @@ case, and `T1 X` shows which frames got through.
|
||||
about 49 s after reset. Only the second boot logs `CASE done`, so a skipped reboot fails the run.
|
||||
|
||||
See `rs485_frame.md` for the same cross-wired UART trick on an ESP32-C3.
|
||||
|
||||
## Duco ventilation box (#22560)
|
||||
|
||||
`scripts/uart_sim/duco/`: `ducosim.hpp` is the box model from `tests/integration/fixtures/uart_mock_duco.yaml` (ack
|
||||
plus answer, AA 01 stuffing, CRC16) on a second UART of the same board; on an ESP32-C6 the hub used tx 18 rx 19 and
|
||||
the box tx 19 rx 18 at 57600, wired across. `gen.py NAME pr|dev` writes the config (every text sensor, sensors, mode,
|
||||
comfort, sntp clock) with an `on_value` log per entity (`STATE id = '...'`, newlines as `\n`); `DUCO_VERBOSE=1` shows
|
||||
`Found node`, `DUCO_SERIAL_SIZE=18` gives the dev fixture's short serial answer. `run.sh NAME KIND SECONDS` (env
|
||||
`TREE`, `DUCO_PORT`, `PY`, optional `BUILD_LOCK`), run from a scratch directory with a copy of `ducosim.hpp`,
|
||||
generates, builds through `scripts/pio_build.sh`, flashes and captures with `scripts/serial_capture.py`; a pr build
|
||||
ends with `check.py` against `expected.txt` (exit 1 on a mismatch), and the model logs requests it has no answer for.
|
||||
- Answer one request per poll call. Answering a 26 request burst in one pass blocks about 100 ms and overflows the
|
||||
hub's 256 byte UART RX buffer, which silently drops the serial and version answers every round.
|
||||
- Dev's hub frame is 32 bytes: the PR model's 34 byte serial answer is dropped there and duco sets "No answer".
|
||||
- Error cases 7 (three long, 210 B) and 8 (four short, 148 B) check that the code-only fallback goes by length.
|
||||
|
||||
## ESP8266 software serial byte checks
|
||||
|
||||
The worst case for an unlock after a trailing run of high bits is a frame of bytes all below 0x80; a mixed frame
|
||||
hides it.
|
||||
@@ -24,8 +24,3 @@ identical payloads share one table, a lambda is sent from its vector. An empty c
|
||||
(`sendto() error 22` in the log, no datagram) until it accepted `nullptr` with a zero length; the old
|
||||
`TemplatableBytes::visit` had passed a zero length stack buffer instead. Compare sizes against the stacked PR's own
|
||||
head when the PR is stacked, not against dev. Results: https://github.com/esphome/esphome/pull/21263
|
||||
|
||||
## Two sockets on one port (#22509)
|
||||
|
||||
lwIP lets two sockets bind one UDP port when `SO_REUSEADDR` is set, and unicast then goes to the socket opened
|
||||
last; without it the second bind fails with errno 112.
|
||||
@@ -59,46 +59,3 @@ valve, update, alarm_control_panel or water_heater entity reboots with `Exceptio
|
||||
`json::linked(const char *)` (the ROM `strlen` on a flash address), fixed by #21316. The cover in the template keeps
|
||||
that path covered; before #21316 is merged, apply its one line change to both trees or the web_server comparison
|
||||
cannot run.
|
||||
|
||||
## Basic auth on the async web servers (ESP8266, RP2040, LibreTiny)
|
||||
|
||||
`scripts/web_auth/` (see its README) fuzzes Basic auth over raw sockets: functional routes with and without
|
||||
credentials, wrong credentials, other schemes, a tampered hash, spacing and case, then large headers, many failed
|
||||
attempts next to an authenticated `/events` stream, and a timing comparison of wrong first and last bytes. It also
|
||||
has a captive portal client package that probes `/`, `/config.json`, POST with and without credentials and
|
||||
`/wifisave`. `compare.py` lines a dev run up with a PR run. These scripts were still being extended when copied here.
|
||||
The README also covers the newer flows: the heap under paced connection churn (`heap_churn.py`, the LibreTiny TIME_WAIT
|
||||
check for #22696) and the main task stack high-water mark with the JSON arena (`arena/`, #22699).
|
||||
|
||||
## Per-session /events listing on ESP32 (#22691)
|
||||
|
||||
Checks that a new `/events` client's entity listing goes only to that client. Config
|
||||
`scripts/web_server/sse-listing.yaml` (ESP32 ESP-IDF, web_server version 3, 19 entities, 3 sorting groups, heap logged
|
||||
every 5 s); build each head with a different `-s name` through `pio_build.sh`. Driver:
|
||||
`python -I scripts/web_server/sse_listing.py DEVICE_IP --rounds 4 --out events.jsonl`. Each round opens streams 1 and
|
||||
2, waits for their listing, connects stream 3 and counts for 10 s per stream. A `state` event that carries `domain`
|
||||
is a full detail (detail_all) entry; a `ping` with only `uptime` is the 10 s keepalive, any other `ping` the greeting
|
||||
(config JSON). The greeting and `sorting_group` events always go only to the new session, so only the detail_all
|
||||
count tells the builds apart. Ends `RESULT PASS` or `RESULT FAIL` (exit 0 or 1).
|
||||
|
||||
On an ESP32-PICO-D4 the control sent all 19 detail_all entries to streams 1 and 2 on every round, the PR none; stream 3
|
||||
was ordered on both.
|
||||
|
||||
## /events stream rework checks (#21973)
|
||||
|
||||
Config `scripts/web_server/stream-dut.yaml` (ESP32 ESP-IDF, 20 ms template sensor, a "Wifi Drop" button that runs
|
||||
`wifi.disable`, 8 s, `wifi.enable`, heap every 5 s). `scripts/web_server/stream_retest.py HOST MODE` has five modes:
|
||||
`head` (raw bytes of the first 3 s; compare two builds with `head_compare.py A B NAME_A NAME_B`, which masks numbers
|
||||
and the device name), `multi` (4 clients 20 s, events and longest gap), `stall` (a client with a 2 KB receive buffer
|
||||
stops reading for 35 s; read the close time from `Closing stuck stream`, or `Closing stuck EventSource connection` on
|
||||
older builds), `wifidrop` (REST press, the client reconnects after 5 s idle like a browser `EventSource`) and `churn`
|
||||
(40 connects, 20 of them reset, then a fresh client). `stream_runall.sh NAME PORT` uploads, captures and runs every
|
||||
mode. Both builds should close the stalled stream at about 20 s and close the stream at the Wi-Fi drop.
|
||||
|
||||
- `sse_listing.py` prints stream 3's TCP connect and first event times. A late greeting (3 to 4 s) was TCP connect
|
||||
time on the network (SYN retransmits), seen on the control too, not the device.
|
||||
- On a noisy Wi-Fi network multi-client runs fell to 110 to 900 events per client with every client pausing together,
|
||||
and a stalled client sometimes missed the EOF although the device logged `Closing stuck stream`. Alternate the
|
||||
builds (flash A, 4 multi runs, flash B, repeat) before calling a rate difference.
|
||||
- Log text check for refactors: collect every `[web_server*]` line from all captures, mask timestamps, source line
|
||||
numbers and digits, `sort -u`, and diff the two builds' sets.
|
||||
@@ -93,27 +93,3 @@ connected channel starts and ends on the bench channel with another channel in b
|
||||
- Dropping the AP under a connected device gives a `Beacon Timeout` link loss.
|
||||
- The 90 s interval fires once right after boot.
|
||||
- A `Disconnected ... Association Leave` right after `Connecting to` is the aborted attempt, not a missed connect.
|
||||
|
||||
## Soft AP with the BLE tracker scanning (#22534, #22566)
|
||||
|
||||
`scripts/ble_scan_soft_ap/`: `dut.yaml` runs only `wifi: ap:` with `captive_portal:` and `bluetooth_proxy:`, and
|
||||
`client.yaml` (on a second ESP32) joins that AP and fetches the portal page every 5 s, logging `JOIN` and `STAT`
|
||||
lines. `run.sh` erases and flashes the DUT, resets the client and prints the generated scan window, the first join, the
|
||||
page counts and the client's disconnect reasons (usage in its header).
|
||||
|
||||
- A scan window equal to the scan interval (320 ms of 320 ms) leaves the radio no time for the soft AP: on dev no
|
||||
client joined on the classic ESP32, S3, C3 or C6. With #22566 the tracker uses its 30 ms connection window while
|
||||
the AP runs, and every chip took a client in about 4 s.
|
||||
- Only one AP with the test SSID may be up at a time; list the other AP boards in `PARK` so they wait in their ROM
|
||||
bootloader.
|
||||
- To check that the full window comes back after provisioning, log `esp32_ble_tracker` at VERBOSE and provision
|
||||
with `templates/client-wifisave.yaml` (set `ap_ssid` to the DUT's and `ap_password: ""`, the DUT's AP is open): `Connection or AP active, using 48 unit scan window` must stop once the AP stops.
|
||||
- Some clients do not join an ESP8266 AP at all (the C6 failed on dev too with `Too Many Associations`); use a C3.
|
||||
|
||||
## ESP8266 power save after captive portal provisioning (#22542, #22564)
|
||||
|
||||
The DUT runs `ap:` plus `captive_portal:` with no station network and logs `wifi_get_sleep_type()` every 5 s (0 is
|
||||
`NONE_SLEEP_T`, 2 is `MODEM_SLEEP_T`); an ESP32-C3 with `templates/client-wifisave.yaml` posts the real credentials.
|
||||
Erase the flash before each run so no saved credentials skip the portal. On dev the sleep type stayed 2 after
|
||||
provisioning although the config asked for none; with #22564 it read 0 from the moment the AP started, and the
|
||||
`networks:` path still read 0.
|
||||
@@ -1,9 +0,0 @@
|
||||
# wled
|
||||
|
||||
## Realtime sender on the bench (#22509)
|
||||
|
||||
When the access point stops passing traffic between clients (lwIP `sendto` on the sender fails with errno 12
|
||||
because ARP never resolves), run the sender on a board instead of the host: an ESP32-S3 runs `wifi: ap:` and a
|
||||
25 ms interval lambda sends WARLS, DRGB or DNRGB frames with lwIP `sendto` to the devices under test, which join
|
||||
that AP with `manual_ip`. Two lights on the same port: see `udp.md`. Heap after an effect stops: see
|
||||
`heap_alloc.md`.
|
||||
@@ -21,24 +21,3 @@ uart_button/uartbtn*.yaml
|
||||
value_range/rng*.yaml
|
||||
ld2420_sim/ldenergy*.yaml
|
||||
ld2420_sim/ldsimple*.yaml
|
||||
apikey.txt
|
||||
pio/
|
||||
rp2_web_ble/*.log
|
||||
rp2_web_ble/*.txt
|
||||
rp2_web_ble/*.pcap
|
||||
gatt_uuid/*.json
|
||||
gatt_uuid/*.txt
|
||||
web_auth/configs/*.log
|
||||
web_auth/configs/*.txt
|
||||
web_auth/configs/*.json
|
||||
improv/*.log
|
||||
npm1300/*-cap.txt
|
||||
npm1300/*-cap.err
|
||||
npm1300/*-run.log
|
||||
rp2_sched_lock/*.txt
|
||||
rp2_sched_lock/*.log
|
||||
cc1101_long/*.log
|
||||
espnow_link/*.log
|
||||
espnow_link/*.err
|
||||
tcp_link/*.txt
|
||||
sx127x_sim/*pair/
|
||||
@@ -1,88 +0,0 @@
|
||||
"""
|
||||
Rapid native API connect/disconnect stress test (from esphome#14687 and esphome#14706).
|
||||
|
||||
usage: connstress.py HOST [ITERATIONS] [CONCURRENCY] (default 500 iterations, 4 at a time)
|
||||
env: API_KEY (base64 noise key; unset, empty or - for plaintext), API_PORT (default 6053), API_PASSWORD
|
||||
Each attempt connects with login, disconnects and counts a failure on any error or a 10 s timeout on either step.
|
||||
Exits 1 when any attempt failed. Watch the serial log for crashes: the client only sees resets.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import APIClient
|
||||
|
||||
HOST = sys.argv[1] if len(sys.argv) > 1 else sys.exit(__doc__)
|
||||
PORT = int(os.environ.get("API_PORT", "6053"))
|
||||
PASSWORD = os.environ.get("API_PASSWORD", "")
|
||||
NOISE_PSK = (
|
||||
None if os.environ.get("API_KEY") in (None, "", "-") else os.environ["API_KEY"]
|
||||
)
|
||||
|
||||
|
||||
async def connect_disconnect(client_id: int, iteration: int) -> tuple[int, bool, str]:
|
||||
cli = APIClient(HOST, PORT, PASSWORD, noise_psk=NOISE_PSK)
|
||||
try:
|
||||
await asyncio.wait_for(cli.connect(login=True), timeout=10)
|
||||
# a disconnect that hangs on a wedged device is a failure too, not a stuck slot
|
||||
await asyncio.wait_for(cli.disconnect(), timeout=10)
|
||||
return iteration, True, ""
|
||||
except Exception as e: # noqa: BLE001 every failure is a counted result
|
||||
return (
|
||||
iteration,
|
||||
False,
|
||||
f"client{client_id} iter{iteration}: {type(e).__name__}: {e}",
|
||||
)
|
||||
finally:
|
||||
with contextlib.suppress(Exception):
|
||||
await asyncio.wait_for(cli.disconnect(force=True), timeout=10)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
iterations = int(sys.argv[2]) if len(sys.argv) > 2 else 500
|
||||
concurrency = int(sys.argv[3]) if len(sys.argv) > 3 else 4
|
||||
print(f"Iterations: {iterations}, Concurrency: {concurrency}", flush=True)
|
||||
|
||||
success = fail = 0
|
||||
errors: list[str] = []
|
||||
start = time.monotonic()
|
||||
sem = asyncio.Semaphore(concurrency)
|
||||
|
||||
async def run(client_id: int, iteration: int) -> tuple[int, bool, str]:
|
||||
async with sem:
|
||||
return await connect_disconnect(client_id, iteration)
|
||||
|
||||
tasks = [asyncio.create_task(run(i % concurrency, i)) for i in range(iterations)]
|
||||
for coro in asyncio.as_completed(tasks):
|
||||
_, ok, err = await coro
|
||||
if ok:
|
||||
success += 1
|
||||
else:
|
||||
fail += 1
|
||||
errors.append(err)
|
||||
total = success + fail
|
||||
if total % 10 == 0 or not ok:
|
||||
rate = total / max(time.monotonic() - start, 1e-6)
|
||||
print(
|
||||
f"[{total}/{iterations}] ok={success} fail={fail} ({rate:.1f}/s)",
|
||||
flush=True,
|
||||
)
|
||||
if err:
|
||||
print(f" ERROR: {err}", flush=True)
|
||||
|
||||
elapsed = time.monotonic() - start
|
||||
print(f"\nDone in {elapsed:.1f}s")
|
||||
print(f"Success: {success}, Failed: {fail}, Rate: {iterations / elapsed:.1f}/s")
|
||||
if errors:
|
||||
print("\nLast 10 errors:")
|
||||
for e in errors[-10:]:
|
||||
print(f" {e}")
|
||||
print("RESULT", "PASS" if fail == 0 else "FAIL")
|
||||
sys.exit(1 if fail else 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -4,7 +4,6 @@ Import it with this directory on sys.path (the drivers add their parent director
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Awaitable, Callable
|
||||
import contextlib
|
||||
import os
|
||||
import re
|
||||
@@ -28,32 +27,19 @@ FATAL = (
|
||||
)
|
||||
|
||||
|
||||
async def connect(
|
||||
host: str,
|
||||
tries: int = 30,
|
||||
timeout: float = 10,
|
||||
port: int = 6053,
|
||||
on_stop: Callable[[bool], Awaitable[None]] | None = None,
|
||||
) -> APIClient:
|
||||
async def connect(host: str, tries: int = 30, timeout: float = 10) -> APIClient:
|
||||
"""Connect and log in, retrying once a second; exits after TRIES failures with the last error.
|
||||
|
||||
API_KEY in the env selects Noise; unset, empty or - is plaintext. ON_STOP is called when the connection ends.
|
||||
API_KEY in the env selects Noise; unset, empty or - is plaintext.
|
||||
"""
|
||||
key = os.environ.get("API_KEY")
|
||||
last: BaseException | None = None
|
||||
for _ in range(tries):
|
||||
c = APIClient(
|
||||
host, port, None, noise_psk=None if key in (None, "", "-") else key
|
||||
host, 6053, None, noise_psk=None if key in (None, "", "-") else key
|
||||
)
|
||||
live = [False]
|
||||
|
||||
# a failed attempt's cleanup may call on_stop too; pass on only stops of the returned client
|
||||
async def stop(expected: bool, live: list[bool] = live) -> None:
|
||||
if live[0] and on_stop is not None:
|
||||
await on_stop(expected)
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(c.connect(on_stop=stop, login=True), timeout)
|
||||
await asyncio.wait_for(c.connect(login=True), timeout)
|
||||
except FATAL as e:
|
||||
sys.exit(f"no API connection to {host}: {type(e).__name__}: {e}")
|
||||
except Exception as e: # noqa: BLE001
|
||||
@@ -63,7 +49,6 @@ async def connect(
|
||||
await c.disconnect(force=True)
|
||||
await asyncio.sleep(1)
|
||||
else:
|
||||
live[0] = True
|
||||
return c
|
||||
sys.exit(
|
||||
f"no API connection to {host} after {tries} tries: {type(last).__name__}: {last}"
|
||||
@@ -73,80 +58,3 @@ async def connect(
|
||||
def log_text(msg) -> str:
|
||||
"""The message of a subscribe_logs callback as text, without ANSI colour codes."""
|
||||
return ANSI.sub("", msg.message.decode(errors="replace"))
|
||||
|
||||
|
||||
def stop_event() -> tuple[asyncio.Event, Callable[[bool], Awaitable[None]]]:
|
||||
"""An Event and an on_stop callback for connect() that sets it when the connection ends."""
|
||||
ev = asyncio.Event()
|
||||
|
||||
async def on_stop(expected: bool) -> None:
|
||||
ev.set()
|
||||
|
||||
return ev, on_stop
|
||||
|
||||
|
||||
async def ble_connect(
|
||||
cli: APIClient,
|
||||
addr: int,
|
||||
on_lost: Callable[[int], None] | None = None,
|
||||
advert_timeout: float = 60,
|
||||
timeout: float = 30,
|
||||
) -> tuple[bool, int, int, Callable[[], None]]:
|
||||
"""Wait for an advert from ADDR, then connect through the proxy without a cache (like Home Assistant).
|
||||
|
||||
Returns (connected, mtu, error, cancel); a missing advert or a connect timeout gives (False, 0, -1, cancel), so
|
||||
callers can retry. ON_LOST(error) is called when the link drops later.
|
||||
"""
|
||||
seen = asyncio.Event()
|
||||
unsub = cli.subscribe_bluetooth_le_raw_advertisements(
|
||||
lambda m: (
|
||||
seen.set() if any(a.address == addr for a in m.advertisements) else None
|
||||
)
|
||||
)
|
||||
try:
|
||||
await asyncio.wait_for(seen.wait(), advert_timeout)
|
||||
except TimeoutError:
|
||||
return False, 0, -1, lambda: None
|
||||
finally:
|
||||
unsub()
|
||||
first: asyncio.Queue = asyncio.Queue()
|
||||
pending = True
|
||||
|
||||
def on_state(connected: bool, mtu: int, err: int) -> None:
|
||||
nonlocal pending
|
||||
if pending:
|
||||
pending = False
|
||||
first.put_nowait((connected, mtu, err))
|
||||
elif not connected and on_lost is not None:
|
||||
on_lost(err)
|
||||
|
||||
cancel = await cli.bluetooth_device_connect(
|
||||
addr,
|
||||
on_state,
|
||||
timeout=timeout,
|
||||
address_type=0,
|
||||
feature_flags=0xFF,
|
||||
has_cache=False,
|
||||
)
|
||||
try:
|
||||
connected, mtu, err = await asyncio.wait_for(first.get(), timeout + 5)
|
||||
except TimeoutError:
|
||||
return False, 0, -1, cancel
|
||||
return connected, mtu, err, cancel
|
||||
|
||||
|
||||
async def enable_notify(
|
||||
cli: APIClient, addr: int, ch, on_notify: Callable[[int, bytearray], None]
|
||||
) -> bool:
|
||||
"""Start notify on characteristic CH and write its first CCCD (2902) like Home Assistant.
|
||||
|
||||
Returns False when the characteristic lists no CCCD.
|
||||
"""
|
||||
await cli.bluetooth_gatt_start_notify(addr, ch.handle, on_notify)
|
||||
cccd = next(
|
||||
(d for d in ch.descriptors if d.uuid.lower().startswith("00002902")), None
|
||||
)
|
||||
if cccd is None:
|
||||
return False
|
||||
await cli.bluetooth_gatt_write_descriptor(addr, cccd.handle, b"\x01\x00")
|
||||
return True
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
// Test only: swaps the first two records of an ATT Read By Type Response whose first record declares characteristic
|
||||
// 0xFFF1, the way some peripherals answer out of handle order (esphome#22518). Count of swaps in attswap_count.
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
struct AttSwapHdr {
|
||||
uint16_t event, len, offset, layer_specific;
|
||||
};
|
||||
extern "C" void __real_l2c_rcv_acl_data(void *p_msg);
|
||||
static volatile uint32_t attswap_count = 0;
|
||||
|
||||
extern "C" void __wrap_l2c_rcv_acl_data(void *p_msg) {
|
||||
auto *h = static_cast<AttSwapHdr *>(p_msg);
|
||||
uint8_t *p = reinterpret_cast<uint8_t *>(h + 1) + h->offset;
|
||||
// HCI ACL header (4), L2CAP header (4), then ATT: opcode, record length, records
|
||||
if (h->len >= 4 + 4 + 2 + 14) {
|
||||
uint16_t cid = p[6] | (p[7] << 8);
|
||||
uint8_t *att = p + 8;
|
||||
// record: handle(2) properties(1) value handle(2) uuid16(2)
|
||||
if (cid == 0x0004 && att[0] == 0x09 && att[1] == 7 && att[2 + 5] == 0xF1 && att[2 + 6] == 0xFF) {
|
||||
uint8_t tmp[7];
|
||||
memcpy(tmp, att + 2, 7);
|
||||
memcpy(att + 2, att + 9, 7);
|
||||
memcpy(att + 9, tmp, 7);
|
||||
attswap_count = attswap_count + 1;
|
||||
}
|
||||
}
|
||||
__real_l2c_rcv_acl_data(p_msg);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
"""Test only: wrap Bluedroid's l2c_rcv_acl_data so attswap.h can reorder a Read By Type response."""
|
||||
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.types import ConfigType
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({})
|
||||
|
||||
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
cg.add_build_flag("-Wl,--wrap=l2c_rcv_acl_data")
|
||||
@@ -1,5 +0,0 @@
|
||||
substitutions:
|
||||
name: attprx6
|
||||
idf: 5.5.6
|
||||
packages:
|
||||
c: !include proxy.yaml
|
||||
@@ -1,125 +0,0 @@
|
||||
"""Through the proxy (no cache): print the full GATT table, read FFF1/FFF2/FFF3 by handle, and enable notify on
|
||||
FFF1, FFF2 and 2ACD (writing the CCCD the way Home Assistant does), counting what arrives per handle for 6 s.
|
||||
usage: gattcheck.py PROXY PEER_MAC env: API_KEY (the proxy's api encryption key)
|
||||
Exits 1 when a characteristic or CCCD is missing, a read or notification carries another characteristic's value,
|
||||
a notify fails, or a notifying characteristic sends nothing."""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
|
||||
from aioesphomeapi import APIClient
|
||||
|
||||
SFX = "-0000-1000-8000-00805f9b34fb"
|
||||
|
||||
|
||||
def short(u: str) -> str:
|
||||
return u[4:8] if u.endswith(SFX) else u
|
||||
|
||||
|
||||
async def main(host: str, peer: str) -> None:
|
||||
addr = int(peer.replace(":", ""), 16)
|
||||
cli = APIClient(host, 6053, None, noise_psk=os.environ["API_KEY"])
|
||||
await cli.connect(login=True)
|
||||
seen = asyncio.Event()
|
||||
cli.subscribe_bluetooth_le_raw_advertisements(
|
||||
lambda m: (
|
||||
seen.set() if any(a.address == addr for a in m.advertisements) else None
|
||||
)
|
||||
)
|
||||
await asyncio.wait_for(seen.wait(), 30)
|
||||
state: asyncio.Queue = asyncio.Queue()
|
||||
cancel = await cli.bluetooth_device_connect(
|
||||
addr,
|
||||
lambda c, mtu, err: state.put_nowait((c, mtu, err)),
|
||||
timeout=20,
|
||||
address_type=0,
|
||||
feature_flags=0xFF,
|
||||
has_cache=False,
|
||||
)
|
||||
c, mtu, err = await asyncio.wait_for(state.get(), 25)
|
||||
if not c:
|
||||
sys.exit(f"connect failed err={err}")
|
||||
svcs = await cli.bluetooth_gatt_get_services(addr)
|
||||
chars = {}
|
||||
for s in svcs.services:
|
||||
print(f"SVC {short(s.uuid)} 0x{s.handle:04X}", flush=True)
|
||||
for ch in s.characteristics:
|
||||
chars[short(ch.uuid)] = ch
|
||||
print(
|
||||
f" CHR {short(ch.uuid)} 0x{ch.handle:04X} props=0x{ch.properties:02X}",
|
||||
flush=True,
|
||||
)
|
||||
for d in ch.descriptors:
|
||||
print(f" DSC {short(d.uuid)} 0x{d.handle:04X}", flush=True)
|
||||
wanted = ("fff1", "fff2", "fff3", "2acc", "2acd")
|
||||
problems = [f"{u} missing" for u in wanted if u not in chars]
|
||||
for u in ("fff1", "fff2", "fff3", "2acc"):
|
||||
if u in chars:
|
||||
v = bytes(await cli.bluetooth_gatt_read(addr, chars[u].handle))
|
||||
text = v.decode(errors="replace")
|
||||
print(f"READ {u} 0x{chars[u].handle:04X} -> {text}", flush=True)
|
||||
# every server value starts with its own UUID, so a mixed-up handle shows here
|
||||
if not text.startswith(f"{u}-"):
|
||||
problems.append(f"{u} read returned {text!r}")
|
||||
got: dict[int, list[str]] = {}
|
||||
|
||||
def on_notify(handle: int, data: bytearray) -> None:
|
||||
got.setdefault(handle, []).append(bytes(data).decode(errors="replace"))
|
||||
|
||||
for u in ("fff1", "fff2", "2acd"):
|
||||
if u in chars:
|
||||
try:
|
||||
await cli.bluetooth_gatt_start_notify(addr, chars[u].handle, on_notify)
|
||||
# like Home Assistant's client: write the first CCCD listed under the characteristic
|
||||
cccd = next(
|
||||
(d for d in chars[u].descriptors if short(d.uuid) == "2902"), None
|
||||
)
|
||||
if cccd is None:
|
||||
print(
|
||||
f"NOTIFY {u} 0x{chars[u].handle:04X} NO CCCD in its descriptor list",
|
||||
flush=True,
|
||||
)
|
||||
problems.append(f"{u} has no CCCD")
|
||||
continue
|
||||
await cli.bluetooth_gatt_write_descriptor(
|
||||
addr, cccd.handle, b"\x01\x00"
|
||||
)
|
||||
print(
|
||||
f"NOTIFY {u} 0x{chars[u].handle:04X} enabled, CCCD 0x{cccd.handle:04X} written",
|
||||
flush=True,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(
|
||||
f"NOTIFY {u} 0x{chars[u].handle:04X} FAILED {type(exc).__name__}: {exc}",
|
||||
flush=True,
|
||||
)
|
||||
problems.append(f"{u} notify failed")
|
||||
await asyncio.sleep(6)
|
||||
if not got:
|
||||
print("GOT nothing", flush=True)
|
||||
for h, vals in sorted(got.items()):
|
||||
name = next((u for u, ch in chars.items() if ch.handle == h), "?")
|
||||
print(
|
||||
f"GOT 0x{h:04X} ({name}) x{len(vals)}: {vals[0]} .. {vals[-1]}", flush=True
|
||||
)
|
||||
problems.extend(
|
||||
f"0x{h:04X} ({name}) notified {v!r}"
|
||||
for v in vals
|
||||
if name == "?" or not v.startswith(f"{name}-")
|
||||
)
|
||||
# the server notifies FFF1 and 2ACD every second
|
||||
problems.extend(
|
||||
f"{u} sent nothing"
|
||||
for u in ("fff1", "2acd")
|
||||
if u in chars and chars[u].handle not in got
|
||||
)
|
||||
await cli.bluetooth_device_disconnect(addr)
|
||||
cancel()
|
||||
await cli.disconnect()
|
||||
if problems:
|
||||
sys.exit("FAIL: " + ", ".join(problems))
|
||||
print("PASS", flush=True)
|
||||
|
||||
|
||||
asyncio.run(main(sys.argv[1], sys.argv[2]))
|
||||
@@ -1,56 +0,0 @@
|
||||
"""Connect to PEER_MAC through the proxy like Home Assistant (v3 without cache) and print the services it returns.
|
||||
usage: gattget.py PROXY PEER_MAC ROUNDS env: API_KEY (the proxy's api encryption key)"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
|
||||
from aioesphomeapi import APIClient
|
||||
|
||||
|
||||
async def main(host: str, peer: str, rounds: int) -> None:
|
||||
addr = int(peer.replace(":", ""), 16)
|
||||
cli = APIClient(host, 6053, None, noise_psk=os.environ["API_KEY"])
|
||||
await cli.connect(login=True)
|
||||
seen = asyncio.Event()
|
||||
|
||||
def adv(msg) -> None:
|
||||
if any(a.address == addr for a in msg.advertisements):
|
||||
seen.set()
|
||||
|
||||
cli.subscribe_bluetooth_le_raw_advertisements(adv)
|
||||
await asyncio.wait_for(seen.wait(), 30)
|
||||
failed = 0
|
||||
for r in range(1, rounds + 1):
|
||||
state: asyncio.Queue = asyncio.Queue()
|
||||
cancel = await cli.bluetooth_device_connect(
|
||||
addr,
|
||||
lambda c, mtu, err, q=state: q.put_nowait((c, mtu, err)),
|
||||
timeout=20,
|
||||
address_type=0,
|
||||
feature_flags=0xFF,
|
||||
has_cache=False,
|
||||
)
|
||||
c, mtu, err = await asyncio.wait_for(state.get(), 25)
|
||||
if not c:
|
||||
print(f"R{r} connect failed err={err}", flush=True)
|
||||
failed += 1
|
||||
cancel()
|
||||
await asyncio.sleep(5)
|
||||
continue
|
||||
svcs = await cli.bluetooth_gatt_get_services(addr)
|
||||
sfx = "-0000-1000-8000-00805f9b34fb"
|
||||
out = [
|
||||
f"{s.uuid[4:8] if s.uuid.endswith(sfx) else s.uuid}({len(s.characteristics)})"
|
||||
for s in svcs.services
|
||||
]
|
||||
print(f"R{r} mtu={mtu} services: {' '.join(out)}", flush=True)
|
||||
await cli.bluetooth_device_disconnect(addr)
|
||||
cancel()
|
||||
await asyncio.sleep(5)
|
||||
await cli.disconnect()
|
||||
if failed:
|
||||
sys.exit(f"{failed} of {rounds} rounds did not connect")
|
||||
|
||||
|
||||
asyncio.run(main(sys.argv[1], sys.argv[2], int(sys.argv[3])))
|
||||
@@ -1,37 +0,0 @@
|
||||
# Proxy (classic ESP32): bluetooth_proxy without service cache, encrypted API, the reorder wrapper.
|
||||
# Substitutions: name, idf.
|
||||
# Keep the per-build file in this directory: attswap.hpp and components/ are found relative to it.
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes: [attswap.hpp]
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
version: ${idf}
|
||||
logger:
|
||||
level: DEBUG
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
# a plaintext proxy can be taken over by any Home Assistant on the network mid-test
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
ota:
|
||||
- platform: esphome
|
||||
external_components:
|
||||
- source: {type: local, path: components}
|
||||
components: [attswap]
|
||||
attswap:
|
||||
esp32_ble_tracker:
|
||||
scan_parameters:
|
||||
active: true
|
||||
bluetooth_proxy:
|
||||
active: true
|
||||
cache_services: false
|
||||
interval:
|
||||
- interval: 5s
|
||||
then:
|
||||
- lambda: 'ESP_LOGI("swap", "attswap swaps=%u", (unsigned) attswap_count);'
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
# run.sh PROXY_YAML [ROUNDS]: build server.yaml and PROXY_YAML from TREE, flash both, capture the proxy and read the
|
||||
# server's services through it ROUNDS times (default 3). Prints the services per round and the Bluedroid discovery
|
||||
# errors. Exit 0: every round got all services; 1: a round got a partial table (the bug); 2: setup failed, a round
|
||||
# did not connect, or the swap never fired (the result would be meaningless). PROXY_YAML must sit in this
|
||||
# directory, next to attswap.hpp and components/.
|
||||
# env: TREE, SERVER_YAML (default server.yaml), API_KEY (proxy api key), SERVER_PORT, PROXY_PORT, SERVER_BLE_MAC
|
||||
# (the server's BLE address), SC (path to serial_capture.py), PY
|
||||
D=$(cd "$(dirname "$0")" && pwd); Y=$(cd "$(dirname "${1:?proxy yaml}")" && pwd)/$(basename "$1"); R=${2:-3}
|
||||
W=${TREE:?set TREE}; SP=${SERVER_PORT:?set SERVER_PORT}; PP=${PROXY_PORT:?set PROXY_PORT}; MAC=${SERVER_BLE_MAC:?set SERVER_BLE_MAC}
|
||||
API_KEY=${API_KEY:?set API_KEY}; SC=${SC:?set SC}; PY=${PY:-$W/venv/bin/python}; N=$(basename "$Y" .yaml); O=$D/out-$N; mkdir -p "$O"
|
||||
(cd "$W" && PYTHONPATH=$W $PY -m esphome -s name attsrv run --no-logs "$D/${SERVER_YAML:-server.yaml}" --device "$SP") > "$O/server.log" 2>&1 ||
|
||||
{ echo "server build or upload failed"; exit 2; }
|
||||
(cd "$W" && PYTHONPATH=$W $PY -m esphome run --no-logs "$Y" --device "$PP") > "$O/proxy-upload.log" 2>&1 ||
|
||||
{ echo "$N build or upload failed"; exit 2; }
|
||||
rm -f "$O/proxy.txt"
|
||||
$PY "$SC" "$PP" $((R * 30 + 160)) "$O/proxy.txt" --reset > "$O/capture.log" 2>&1 &
|
||||
CAP=$!
|
||||
IP=""
|
||||
for _ in $(seq 40); do
|
||||
IP=$(LC_ALL=C grep -a -o -E "IP Address: [0-9.]+" "$O/proxy.txt" | tail -1 | cut -d' ' -f3)
|
||||
[ -n "$IP" ] && break; sleep 2
|
||||
done
|
||||
[ -n "$IP" ] || { kill "$CAP"; echo "$N no IP"; exit 2; }
|
||||
sleep 5
|
||||
timeout $((R * 30 + 60)) $PY "$D/gattget.py" "$IP" "$MAC" "$R" | tee "$O/client.txt"
|
||||
[ "${PIPESTATUS[0]}" = 0 ] || { kill "$CAP"; echo "$N client failed"; exit 2; }
|
||||
wait "$CAP" || { echo "$N capture failed (see $O/capture.log)"; exit 2; }
|
||||
echo "== $N"
|
||||
LC_ALL=C grep -a -E "invalid handle|Service discovery complete|attswap swaps=[1-9]" "$O/proxy.txt" | sed 's/^\[[0-9:]*\]//' |
|
||||
sort | uniq -c
|
||||
grep -a -q -E "attswap swaps=[1-9]" "$O/proxy.txt" || { echo "$N INVALID: the reorder never fired"; exit 2; }
|
||||
# every round must list the reordered service (fff0) and the one after it (1826) with all their characteristics
|
||||
grep -a -q "^R[0-9]* mtu=" "$O/client.txt" || { echo "$N no client output"; exit 2; }
|
||||
grep -a "^R[0-9]* mtu=" "$O/client.txt" | grep -v -q "fff0(6) 1826(2)" && exit 1
|
||||
exit 0
|
||||
@@ -1,45 +0,0 @@
|
||||
# Peripheral (ESP32-S3) for gattcheck.py: FFF1 to FFF6 each hold their own value, FFF1, FFF2 and 2ACD can notify,
|
||||
# and FFF1 and 2ACD send a changing value every second. Substitution: name.
|
||||
esphome:
|
||||
name: ${name}
|
||||
esp32:
|
||||
variant: esp32s3
|
||||
framework:
|
||||
type: esp-idf
|
||||
logger:
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
esp32_ble:
|
||||
name: ${name}
|
||||
esp32_ble_server:
|
||||
manufacturer: ESPHome
|
||||
model: attcheck
|
||||
services:
|
||||
- uuid: FFF0
|
||||
advertise: true
|
||||
characteristics:
|
||||
- {id: c1, uuid: FFF1, read: true, notify: true, value: "fff1-v"}
|
||||
- {uuid: FFF2, read: true, notify: true, value: "fff2-v"}
|
||||
- {uuid: FFF3, read: true, value: "fff3-v"}
|
||||
- {uuid: FFF4, read: true, value: "fff4-v"}
|
||||
- {uuid: FFF5, read: true, value: "fff5-v"}
|
||||
- {uuid: FFF6, read: true, value: "fff6-v"}
|
||||
- uuid: "1826"
|
||||
characteristics:
|
||||
- {uuid: 2ACC, read: true, value: "2acc-v"}
|
||||
- {id: cd, uuid: 2ACD, read: true, notify: true, value: "2acd-0"}
|
||||
on_connect:
|
||||
- logger.log: {format: "SRV connected", level: INFO}
|
||||
globals:
|
||||
- {id: n, type: int, initial_value: "0"}
|
||||
interval:
|
||||
- interval: 1s
|
||||
then:
|
||||
- lambda: id(n)++;
|
||||
- ble_server.characteristic.set_value:
|
||||
id: cd
|
||||
value: !lambda 'std::string v = "2acd-" + to_string(id(n)); return std::vector<uint8_t>(v.begin(), v.end());'
|
||||
- ble_server.characteristic.notify: {id: cd}
|
||||
- ble_server.characteristic.set_value:
|
||||
id: c1
|
||||
value: !lambda 'std::string v = "fff1-n" + to_string(id(n)); return std::vector<uint8_t>(v.begin(), v.end());'
|
||||
- ble_server.characteristic.notify: {id: c1}
|
||||
@@ -1,32 +0,0 @@
|
||||
# Peripheral (ESP32-S3): a 6-characteristic service 0xFFF0, then an FTMS-like 0x1826 service. Substitution: name.
|
||||
esphome:
|
||||
name: ${name}
|
||||
esp32:
|
||||
variant: esp32s3
|
||||
framework:
|
||||
type: esp-idf
|
||||
logger:
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
esp32_ble:
|
||||
name: ${name}
|
||||
esp32_ble_server:
|
||||
manufacturer: ESPHome
|
||||
model: g22518
|
||||
services:
|
||||
- uuid: FFF0
|
||||
advertise: true
|
||||
characteristics:
|
||||
- {uuid: FFF1, read: true, value: [1]}
|
||||
- {uuid: FFF2, read: true, value: [2]}
|
||||
- {uuid: FFF3, read: true, value: [3]}
|
||||
- {uuid: FFF4, read: true, value: [4]}
|
||||
- {uuid: FFF5, read: true, value: [5]}
|
||||
- {uuid: FFF6, read: true, value: [6]}
|
||||
- uuid: "1826"
|
||||
characteristics:
|
||||
- {uuid: 2ACC, read: true, value: [0, 0, 0, 0]}
|
||||
- {uuid: 2ACD, read: true, notify: true, value: [0, 0]}
|
||||
on_connect:
|
||||
- logger.log: {format: "SRV connected", level: INFO}
|
||||
on_disconnect:
|
||||
- logger.log: {format: "SRV disconnected", level: INFO}
|
||||
@@ -1,48 +0,0 @@
|
||||
# Joins the DUT's open AP, fetches the portal page every 5 s and logs JOIN and STAT lines. Substitutions: name, board,
|
||||
# logger_uart, ap_ssid (same as dut.yaml).
|
||||
substitutions:
|
||||
board: esp32-c3-devkitm-1
|
||||
logger_uart: USB_SERIAL_JTAG
|
||||
ap_ssid: bleaptest
|
||||
esphome:
|
||||
name: ${name}
|
||||
esp32:
|
||||
board: ${board}
|
||||
framework:
|
||||
type: esp-idf
|
||||
logger:
|
||||
hardware_uart: ${logger_uart}
|
||||
wifi:
|
||||
ssid: ${ap_ssid}
|
||||
reboot_timeout: 0s
|
||||
on_connect:
|
||||
- lambda: |-
|
||||
id(joins)++;
|
||||
ESP_LOGI("cli", "JOIN %d at %u ms", id(joins), (unsigned) millis());
|
||||
on_disconnect:
|
||||
- lambda: ESP_LOGI("cli", "LEFT at %u ms", (unsigned) millis());
|
||||
http_request:
|
||||
timeout: 5s
|
||||
globals:
|
||||
- {id: joins, type: int, initial_value: "0"}
|
||||
- {id: pages_ok, type: int, initial_value: "0"}
|
||||
- {id: pages_fail, type: int, initial_value: "0"}
|
||||
interval:
|
||||
- interval: 5s
|
||||
then:
|
||||
- if:
|
||||
condition: wifi.connected
|
||||
then:
|
||||
- http_request.get:
|
||||
url: http://192.168.4.1/
|
||||
on_response:
|
||||
then:
|
||||
- lambda: if (response->status_code == 200) id(pages_ok)++; else id(pages_fail)++;
|
||||
on_error:
|
||||
then:
|
||||
- lambda: id(pages_fail)++;
|
||||
- interval: 15s
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGI("cli", "STAT up=%u joins=%d connected=%d pages_ok=%d pages_fail=%d", (unsigned) (millis() / 1000),
|
||||
id(joins), (int) wifi::global_wifi_component->is_connected(), id(pages_ok), id(pages_fail));
|
||||
@@ -1,23 +0,0 @@
|
||||
# Soft AP only (no station network) with captive_portal and bluetooth_proxy, as in #22534. Substitutions: name,
|
||||
# board, logger_uart (USB_SERIAL_JTAG on native USB chips, UART0 on a classic devkit), ap_ssid.
|
||||
substitutions:
|
||||
board: esp32dev
|
||||
logger_uart: UART0
|
||||
ap_ssid: bleaptest
|
||||
esphome:
|
||||
name: ${name}
|
||||
esp32:
|
||||
board: ${board}
|
||||
framework:
|
||||
type: esp-idf
|
||||
logger:
|
||||
hardware_uart: ${logger_uart}
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
ota:
|
||||
- platform: esphome
|
||||
wifi:
|
||||
ap:
|
||||
ssid: ${ap_ssid}
|
||||
captive_portal:
|
||||
bluetooth_proxy:
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
# run.sh DUT_YAML SECONDS: erase and flash DUT_YAML from TREE, let it boot, then reset the client (already flashed with
|
||||
# client.yaml) and capture both for SECONDS. Prints the generated scan window, the client's first JOIN and last STAT
|
||||
# lines, its disconnect reasons and the DUT's resets. One AP with this SSID at a time: ports in PARK are held in their
|
||||
# ROM bootloader first. The yaml file name must equal its `name:` (the build directory is found by it).
|
||||
# Exit 0: pass; 1: the run finished and failed the checks; 2: setup or capture failed.
|
||||
# env: TREE, DUT_PORT, CLIENT_PORT, PARK (space separated ports, optional), SC (path to serial_capture.py), PY
|
||||
Y=$(cd "$(dirname "${1:?dut yaml}")" && pwd)/$(basename "$1"); T=${2:?seconds}; N=$(basename "$Y" .yaml)
|
||||
W=${TREE:?set TREE}; DUT=${DUT_PORT:?set DUT_PORT}; CLI=${CLIENT_PORT:?set CLIENT_PORT}; SC=${SC:?set SC}
|
||||
PY=${PY:-$W/venv/bin/python}; O=$(dirname "$Y")/out-$N; mkdir -p "$O"
|
||||
for p in $PARK; do $PY -m esptool --port "$p" --after no-reset chip-id > /dev/null 2>&1 || { echo "park $p failed"; exit 2; }; done
|
||||
(cd "$W" && PYTHONPATH=$W $PY -m esphome compile "$Y") > "$O/compile.log" 2>&1 || { echo "$N compile failed"; exit 2; }
|
||||
$PY -m esptool --port "$DUT" erase_flash > "$O/erase.log" 2>&1 || { echo "$N erase failed"; exit 2; }
|
||||
(cd "$W" && PYTHONPATH=$W $PY -m esphome upload "$Y" --device "$DUT") > "$O/upload.log" 2>&1 || { echo "$N upload failed"; exit 2; }
|
||||
$PY "$SC" "$DUT" $((T + 40)) "$O/dut.txt" --reset > "$O/dut-capture.log" 2>&1 &
|
||||
CAP=$!
|
||||
trap 'kill $CAP 2>/dev/null' EXIT
|
||||
sleep 30
|
||||
$PY "$SC" "$CLI" "$T" "$O/cli.txt" --reset > "$O/cli-capture.log" 2>&1 || { echo "$N client capture failed"; exit 2; }
|
||||
wait "$CAP" || { echo "$N DUT capture failed"; exit 2; }
|
||||
B=$(dirname "$Y")/.esphome/build/$N/src/main.cpp
|
||||
[ -f "$B" ] || { echo "$N: $B not found (file name differs from name:?)"; exit 2; }
|
||||
echo "== $N window=$(grep -o 'set_scan_window([0-9]*)' "$B" || echo none)"
|
||||
J=$(grep -a -m1 "JOIN 1" "$O/cli.txt" | cut -c1-100); echo "${J:-$N NO JOIN}"
|
||||
STAT=$(grep -a "STAT" "$O/cli.txt" | tail -1 | cut -c1-140); echo "$STAT"
|
||||
echo "client disconnect reasons: $(grep -a -o "reason='[^']*'" "$O/cli.txt" | sort | uniq -c | tr '\n' ' ')"
|
||||
echo "dut resets: $(grep -a -c 'rst:' "$O/dut.txt")"
|
||||
# pass: the client joined and fetched pages, and the DUT reset exactly once (the capture's own reset)
|
||||
[ -n "$J" ] && [ -n "$STAT" ] && [[ "$STAT" != *"pages_ok=0 "* ]] && [ "$(grep -a -c 'rst:' "$O/dut.txt")" = 1 ]
|
||||
@@ -1,57 +0,0 @@
|
||||
"""Count rounds, BTU_TASK crashes, reconnects without reboot and MTU 517 in a central capture.
|
||||
|
||||
analyze.py CAPTURE
|
||||
A round counts from its "start" line (a crashing round never logs "fired"); rounds that log "not queued" or
|
||||
"aborted" are taken back out and listed apart. Exits 1 when no round counts, since such a capture tested nothing.
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
lines = (
|
||||
pathlib.Path(sys.argv[1]).read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
)
|
||||
rounds = crashes = other_panics = boots = connects = mtu517 = mtu_other = 0
|
||||
not_queued = aborted = skipped = 0
|
||||
reconnect_ok = reconnect_reboot = 0
|
||||
pending = False # a round fired and we wait for the next connect
|
||||
for ln in lines:
|
||||
if "Stack canary watchpoint triggered (BTU_TASK)" in ln:
|
||||
crashes += 1
|
||||
elif "Guru Meditation" in ln or "abort() was called" in ln:
|
||||
other_panics += 1
|
||||
if "rst:0x" in ln:
|
||||
boots += 1
|
||||
if pending:
|
||||
reconnect_reboot += 1
|
||||
pending = False
|
||||
if "CLI connected" in ln:
|
||||
connects += 1
|
||||
if pending:
|
||||
reconnect_ok += 1
|
||||
pending = False
|
||||
if re.search(r"ROUND \d+ start", ln):
|
||||
rounds += 1
|
||||
pending = True
|
||||
if re.search(r"ROUND \d+ (not queued|aborted)", ln):
|
||||
rounds -= 1
|
||||
pending = False
|
||||
not_queued += "not queued" in ln
|
||||
aborted += "aborted" in ln
|
||||
skipped += "ROUND skipped" in ln
|
||||
if m := re.search(r"cfg_mtu status 0, mtu (\d+)", ln):
|
||||
if m.group(1) == "517":
|
||||
mtu517 += 1
|
||||
else:
|
||||
mtu_other += 1
|
||||
print(
|
||||
f"rounds={rounds} btu_canary_crashes={crashes} other_panics={other_panics} boots={boots}"
|
||||
)
|
||||
print(
|
||||
f"connects={connects} reconnect_without_reboot={reconnect_ok} reconnect_after_reboot={reconnect_reboot}"
|
||||
)
|
||||
print(f"mtu517={mtu517} mtu_other={mtu_other}")
|
||||
print(f"not_queued={not_queued} aborted={aborted} skipped={skipped}")
|
||||
if rounds <= 0:
|
||||
sys.exit("FAIL: no round reached the BTU queue")
|
||||
@@ -1,75 +0,0 @@
|
||||
# Central for the Bluedroid queued MTU recursion repro (esphome#17954). Every connection: wait 1.5 s, then
|
||||
# suspend BTU_TASK, local disconnect, 4 reads + 1 MTU request (or execute write with exec_write: "true") in one
|
||||
# batch, resume. ble_client reconnects.
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
sdkconfig_options:
|
||||
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK: y
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
|
||||
esp32_ble_tracker:
|
||||
scan_parameters:
|
||||
active: false
|
||||
|
||||
globals:
|
||||
- {id: rounds, type: int, initial_value: "0"}
|
||||
- {id: chr_handle, type: uint16_t, initial_value: "0"}
|
||||
|
||||
ble_client:
|
||||
- mac_address: ${peer_mac}
|
||||
id: srv
|
||||
on_connect:
|
||||
- logger.log: {format: "CLI connected", level: INFO}
|
||||
# Runs inside SEARCH_CMPL, before ble_client releases the GATT cache (it has no other nodes)
|
||||
- lambda: |-
|
||||
esp_bt_uuid_t uuid = esp32_ble_tracker::ESPBTUUID::from_raw("5ec10001-0000-1000-8000-00805f9b34fb").get_uuid();
|
||||
esp_gattc_char_elem_t elem;
|
||||
uint16_t count = 1;
|
||||
id(chr_handle) = 0;
|
||||
if (esp_ble_gattc_get_char_by_uuid(id(srv)->get_gattc_if(), id(srv)->get_conn_id(), 1, 0xFFFF, uuid, &elem,
|
||||
&count) == ESP_GATT_OK && count > 0)
|
||||
id(chr_handle) = elem.char_handle;
|
||||
- delay: 1500ms
|
||||
- lambda: |-
|
||||
if (!id(srv)->connected()) return;
|
||||
esp_gatt_if_t gattc_if = id(srv)->get_gattc_if();
|
||||
uint16_t conn_id = id(srv)->get_conn_id();
|
||||
uint16_t handle = id(chr_handle);
|
||||
if (handle == 0) {
|
||||
ESP_LOGW("btu", "ROUND skipped, no characteristic");
|
||||
return;
|
||||
}
|
||||
int n = ++id(rounds);
|
||||
ESP_LOGI("btu", "ROUND %d start conn_id=%u handle=0x%04x", n, conn_id, handle);
|
||||
TaskHandle_t btu = xTaskGetHandle("BTU_TASK");
|
||||
if (btu == nullptr) {
|
||||
// vTaskSuspend(nullptr) would suspend this task forever
|
||||
ESP_LOGE("btu", "ROUND %d aborted, no BTU_TASK", n);
|
||||
return;
|
||||
}
|
||||
vTaskSuspend(btu);
|
||||
// a rejected disconnect leaves the link up, so the queued calls never take the failing send path
|
||||
esp_err_t err = esp_ble_gap_disconnect(id(srv)->get_remote_bda());
|
||||
for (int i = 0; i < 4; i++) {
|
||||
esp_err_t e = esp_ble_gattc_read_char(gattc_if, conn_id, handle, ESP_GATT_AUTH_REQ_NONE);
|
||||
if (e != ESP_OK)
|
||||
err = e;
|
||||
}
|
||||
esp_err_t e = ${exec_write} ? esp_ble_gattc_execute_write(gattc_if, conn_id, true)
|
||||
: esp_ble_gattc_send_mtu_req(gattc_if, conn_id);
|
||||
if (e != ESP_OK)
|
||||
err = e;
|
||||
delay(30);
|
||||
vTaskResume(btu);
|
||||
// a round whose calls were rejected never reached the BTU queue, so it tests nothing
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW("btu", "ROUND %d not queued: %s", n, esp_err_to_name(err));
|
||||
} else {
|
||||
ESP_LOGI("btu", "ROUND %d fired", n);
|
||||
}
|
||||
on_disconnect:
|
||||
- logger.log: {format: "CLI disconnected", level: INFO}
|
||||
@@ -1,9 +0,0 @@
|
||||
esphome:
|
||||
name: btuclibase # one name per build (btuclibase, btuclipr)
|
||||
|
||||
substitutions:
|
||||
peer_mac: "AA:BB:CC:DD:EE:FF" # the peer S3 Bluetooth MAC (Wi-Fi MAC + 2)
|
||||
exec_write: "false"
|
||||
|
||||
packages:
|
||||
common: !include btu-common.yaml
|
||||
@@ -1,31 +0,0 @@
|
||||
# Peer for the Bluedroid queued MTU recursion repro: a GATT server with one readable and writable characteristic
|
||||
esphome:
|
||||
name: btusrv
|
||||
|
||||
esp32:
|
||||
variant: esp32s3
|
||||
board: esp32-s3-devkitc-1
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
|
||||
esp32_ble:
|
||||
name: btusrv
|
||||
|
||||
esp32_ble_server:
|
||||
on_connect:
|
||||
- logger.log: {format: "SRV connected", level: INFO}
|
||||
on_disconnect:
|
||||
- logger.log: {format: "SRV disconnected", level: INFO}
|
||||
services:
|
||||
- uuid: 5ec10000-0000-1000-8000-00805f9b34fb
|
||||
advertise: true
|
||||
characteristics:
|
||||
- id: numc
|
||||
uuid: 5ec10001-0000-1000-8000-00805f9b34fb
|
||||
read: true
|
||||
write: true
|
||||
value: [42]
|
||||
@@ -1,15 +0,0 @@
|
||||
esphome:
|
||||
name: btuxwbase # one name per build (btuxwbase, btuxwpr)
|
||||
|
||||
substitutions:
|
||||
peer_mac: "AA:BB:CC:DD:EE:FF" # the peer S3 Bluetooth MAC (Wi-Fi MAC + 2)
|
||||
exec_write: "true"
|
||||
|
||||
esp32:
|
||||
framework:
|
||||
sdkconfig_options:
|
||||
# GATT API trace prints one "GATTC_ExecuteWrite conn_id=" line per execute send
|
||||
CONFIG_BT_LOG_GATT_TRACE_LEVEL_API: y
|
||||
|
||||
packages:
|
||||
common: !include btu-common.yaml
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
# buildall.sh NAME...: compile each NAME.yaml in this directory from TREE and show whether the long packet define and
|
||||
# the GDO0 drain made it into the build. env: TREE, PY, BUILD_LOCK (optional)
|
||||
D=$(cd "$(dirname "$0")" && pwd); S=$(dirname "$D")
|
||||
export PIO_CORE=${PIO_CORE:-$D/pio}
|
||||
FAILED=0
|
||||
for n in "$@"; do
|
||||
echo "== $n $(git -C "${TREE:?set TREE}" rev-parse --short=10 HEAD)"
|
||||
bash "$S/pio_build.sh" compile "$n" "$D/$n.yaml" || { echo "BUILD FAILED $n"; FAILED=$((FAILED + 1)); continue; }
|
||||
echo "long define: $(grep -c USE_CC1101_LONG_PACKET "$D/.esphome/build/$n/src/esphome/core/defines.h")" \
|
||||
"gdo0 drain: $(grep -c RX_FIFO_THRESHOLD "$D/.esphome/build/$n/src/esphome/components/cc1101/cc1101.cpp")"
|
||||
done
|
||||
[ "$FAILED" = 0 ] || { echo "$FAILED builds failed"; exit 1; }
|
||||
@@ -1,20 +0,0 @@
|
||||
# Example wiring as in c3-long.yaml; packet length from a lambda, 0xEE in the first byte means -1 (drop).
|
||||
substitutions:
|
||||
name: cc-c3-lambda
|
||||
clk: GPIO6
|
||||
mosi: GPIO7
|
||||
miso: GPIO10
|
||||
cs: GPIO3
|
||||
gdo0: GPIO4
|
||||
plen: "1"
|
||||
packages:
|
||||
c: !include cccommon.yaml
|
||||
esp32:
|
||||
variant: esp32c3
|
||||
framework:
|
||||
type: esp-idf
|
||||
cc1101:
|
||||
packet_length: !lambda |-
|
||||
if (x.size() < 1) return 0;
|
||||
if (x[0] == 0xEE) return -1;
|
||||
return x[0] + 1;
|
||||
@@ -1,16 +0,0 @@
|
||||
# Example wiring for an E07-M1101D (CC1101) module; change the pins to match your board. plen 1024 = long packets,
|
||||
# 32 = plain fixed length (copy the file and set plen and name for a plain build).
|
||||
substitutions:
|
||||
name: cc-c3-long
|
||||
clk: GPIO6
|
||||
mosi: GPIO7
|
||||
miso: GPIO10
|
||||
cs: GPIO3
|
||||
gdo0: GPIO4
|
||||
plen: "1024"
|
||||
packages:
|
||||
c: !include cccommon.yaml
|
||||
esp32:
|
||||
variant: esp32c3
|
||||
framework:
|
||||
type: esp-idf
|
||||
@@ -1,135 +0,0 @@
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes: [cclong.hpp]
|
||||
logger:
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
spi:
|
||||
clk_pin: ${clk}
|
||||
mosi_pin: ${mosi}
|
||||
miso_pin: ${miso}
|
||||
globals:
|
||||
- {id: seq, type: uint8_t, initial_value: "0"}
|
||||
- {id: txerr, type: uint32_t, initial_value: "0"}
|
||||
- {id: txpoll, type: uint32_t, initial_value: "300"}
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
actions:
|
||||
- action: cfg
|
||||
variables: {len: int, crc: bool}
|
||||
then:
|
||||
- lambda: |-
|
||||
auto *c = id(radio);
|
||||
c->set_idle();
|
||||
c->set_crc_enable(crc);
|
||||
c->set_packet_length(len);
|
||||
c->begin_rx();
|
||||
ESP_LOGI("cct", "CFG len=%d crc=%d PKTLEN=%u PKTCTRL0=0x%02X MARC=0x%02X", len, (int) crc, ccl::rd(c, 0x06), ccl::rd(c, 0x08), ccl::rdst(c, 0x35) & 0x1F);
|
||||
- action: send
|
||||
variables: {count: int, len: int, b0: int, gap_ms: int}
|
||||
then:
|
||||
- lambda: 'id(txerr) = 0;'
|
||||
- repeat:
|
||||
count: !lambda return count;
|
||||
then:
|
||||
- lambda: |-
|
||||
std::vector<uint8_t> b;
|
||||
ccl::fill(b, len, b0, id(seq)++);
|
||||
if (len <= 64) {
|
||||
if (id(radio).transmit_packet(b) != cc1101::CC1101Error::NONE) id(txerr)++;
|
||||
} else if (ccl::long_tx(id(radio), b.data(), b.size(), id(txpoll)) != 0) {
|
||||
id(txerr)++;
|
||||
}
|
||||
- delay: !lambda return gap_ms;
|
||||
- lambda: 'ESP_LOGI("cct", "SENT count=%d len=%d b0=%d errors=%u", count, len, b0, (unsigned) id(txerr));'
|
||||
- action: rate
|
||||
variables: {sr: float, mod: int, dev: float, bw: float, poll: int, sync: int}
|
||||
then:
|
||||
- lambda: |-
|
||||
auto *c = id(radio);
|
||||
c->set_idle();
|
||||
c->set_modulation_type(static_cast<cc1101::Modulation>(mod));
|
||||
c->set_symbol_rate(sr);
|
||||
c->set_fsk_deviation(dev);
|
||||
c->set_filter_bandwidth(bw);
|
||||
c->set_sync_mode(static_cast<cc1101::SyncMode>(sync));
|
||||
c->begin_rx();
|
||||
id(txpoll) = poll;
|
||||
ESP_LOGI("cct", "RATE sync=%d sr=%.0f mod=%d dev=%.0f bw=%.0f MDMCFG4=0x%02X MDMCFG3=0x%02X MDMCFG2=0x%02X DEVIATN=0x%02X MARC=0x%02X", sync, sr, mod, dev, bw, ccl::rd(c, 0x10), ccl::rd(c, 0x11), ccl::rd(c, 0x12), ccl::rd(c, 0x15), ccl::rdst(c, 0x35) & 0x1F);
|
||||
- action: pdown
|
||||
then:
|
||||
- lambda: 'id(radio).power_down(); ESP_LOGI("cct", "POWER_DOWN");'
|
||||
- action: wup
|
||||
then:
|
||||
- lambda: 'id(radio).wake_up(); id(radio).begin_rx(); ESP_LOGI("cct", "WAKE_UP MARC=0x%02X", ccl::rdst(id(radio), 0x35) & 0x1F);'
|
||||
- action: setlen
|
||||
variables: {len: int}
|
||||
then:
|
||||
- lambda: 'id(radio).set_packet_length(len); ESP_LOGI("cct", "SETLEN %d PKTLEN=%u PKTCTRL0=0x%02X", len, ccl::rd(id(radio), 0x06), ccl::rd(id(radio), 0x08));'
|
||||
- action: pmode
|
||||
variables: {enable: bool}
|
||||
then:
|
||||
- lambda: 'id(radio).set_packet_mode(enable); ESP_LOGI("cct", "PMODE %d PKTCTRL0=0x%02X", (int) enable, ccl::rd(id(radio), 0x08));'
|
||||
- action: whiten
|
||||
variables: {enable: bool}
|
||||
then:
|
||||
- lambda: 'id(radio).set_idle(); id(radio).set_whitening(enable); id(radio).begin_rx(); ESP_LOGI("cct", "WHITEN %d PKTCTRL0=0x%02X", (int) enable, ccl::rd(id(radio), 0x08));'
|
||||
- action: tx_idle_rx
|
||||
then:
|
||||
- lambda: 'id(radio).begin_tx(); delay(5); id(radio).set_idle(); id(radio).begin_rx(); ESP_LOGI("cct", "TX_IDLE_RX MARC=0x%02X", ccl::rdst(id(radio), 0x35) & 0x1F);'
|
||||
- action: tx_reset
|
||||
then:
|
||||
- lambda: 'id(radio).begin_tx(); delay(5); id(radio).reset(); ESP_LOGI("cct", "TX_RESET MARC=0x%02X", ccl::rdst(id(radio), 0x35) & 0x1F);'
|
||||
- action: tx_setters
|
||||
then:
|
||||
- lambda: |-
|
||||
auto *c = id(radio);
|
||||
c->begin_tx();
|
||||
delay(5);
|
||||
const uint8_t before = ccl::rd(c, 0x08);
|
||||
c->set_crc_enable(false);
|
||||
c->set_whitening(false);
|
||||
c->set_packet_length(32);
|
||||
const uint8_t after = ccl::rd(c, 0x08);
|
||||
ESP_LOGI("cct", "TX_SETTERS PKTCTRL0 before=0x%02X after=0x%02X MARC=0x%02X", before, after, ccl::rdst(c, 0x35) & 0x1F);
|
||||
c->begin_rx();
|
||||
ESP_LOGI("cct", "TX_SETTERS begin_rx PKTCTRL0=0x%02X MARC=0x%02X", ccl::rd(c, 0x08), ccl::rdst(c, 0x35) & 0x1F);
|
||||
- action: tx_only
|
||||
then:
|
||||
- lambda: 'id(radio).begin_tx(); delay(5); ESP_LOGI("cct", "TX_ONLY MARC=0x%02X", ccl::rdst(id(radio), 0x35) & 0x1F);'
|
||||
- action: hf
|
||||
then:
|
||||
- lambda: 'ESP_LOGI("cct", "HF %d", (int) esphome::HighFrequencyLoopRequester::is_high_frequency());'
|
||||
- action: idle_rx
|
||||
then:
|
||||
- lambda: |-
|
||||
id(radio).set_idle();
|
||||
id(radio).begin_rx();
|
||||
ESP_LOGI("cct", "IDLE_RX MARC=0x%02X", ccl::rdst(id(radio), 0x35) & 0x1F);
|
||||
- action: tx_rx
|
||||
then:
|
||||
- lambda: |-
|
||||
id(radio).begin_tx();
|
||||
delay(5);
|
||||
id(radio).begin_rx();
|
||||
ESP_LOGI("cct", "TX_RX MARC=0x%02X", ccl::rdst(id(radio), 0x35) & 0x1F);
|
||||
cc1101:
|
||||
id: radio
|
||||
cs_pin: ${cs}
|
||||
gdo0_pin: ${gdo0}
|
||||
frequency: 433.92MHz
|
||||
modulation_type: GFSK
|
||||
symbol_rate: 4800
|
||||
packet_mode: true
|
||||
packet_length: ${plen}
|
||||
sync_mode: "16/16"
|
||||
output_power: 0
|
||||
on_packet:
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGI("cct", "RX len=%u b0=%u seq=%u ok=%d rssi=%.1f lqi=%u fo=%.1f", (unsigned) x.size(), x.empty() ? 0 : x[0], x.size() > 1 ? x[1] : 0, (int) ccl::check(x), rssi, lqi, freq_offset);
|
||||
@@ -1,501 +0,0 @@
|
||||
"""ccdrive.py TXHOST RXHOST MODE OUT [TXLABEL RXLABEL]: drives both radios over API actions and counts the packets
|
||||
each receiver logs. Writes all log lines to OUT and prints one summary line per case.
|
||||
|
||||
MODE: short, long, r2long, r2mid, lambda, r2lambda, fast (fast38, fast100 for one rate), and the dev bug repros crc,
|
||||
rxtx, txback, txrx, txset and nocrc64 (see recipes/cc1101.md).
|
||||
|
||||
Exits 1 on a failed action, a missing CFG/RATE/SENT line or a lost API connection (INVALID), a MISSED case, or error
|
||||
lines from the radios outside the repros."""
|
||||
|
||||
import asyncio
|
||||
import pathlib
|
||||
import re
|
||||
import statistics
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import LogLevel
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from apiconn import connect, log_text # noqa: E402
|
||||
|
||||
TXH, RXH, MODE, OUT = sys.argv[1:5]
|
||||
TXN, RXN = (sys.argv[5:7] + ["TX", "RX"][len(sys.argv[5:7]) :])[:2]
|
||||
out = pathlib.Path(OUT).open("w", encoding="utf-8", buffering=1) # noqa: SIM115
|
||||
RX_RE = re.compile(
|
||||
r"RX len=(\d+) b0=(\d+) seq=(\d+) ok=(\d) rssi=(-?[\d.]+) lqi=(\d+) fo=(-?[\d.]+)"
|
||||
)
|
||||
|
||||
|
||||
class Dev:
|
||||
def __init__(self, host, tag):
|
||||
self.host, self.tag, self.rx, self.lines = host, tag, [], []
|
||||
self.failed = (
|
||||
0 # actions that could not be sent and CFG/RATE lines that never came
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
self.cli = await connect(self.host, on_stop=self.on_stop)
|
||||
_, svcs = await self.cli.list_entities_services()
|
||||
self.svc = {s.name: s for s in svcs}
|
||||
self.cli.subscribe_logs(self.on_log, log_level=LogLevel.LOG_LEVEL_INFO)
|
||||
|
||||
async def on_stop(self, expected: bool) -> None:
|
||||
if (
|
||||
not expected
|
||||
): # a reboot or Wi-Fi drop: the rest of the run is not trustworthy
|
||||
self.failed += 1
|
||||
print(f" INVALID: API connection to {self.tag} lost", flush=True)
|
||||
|
||||
def on_log(self, m):
|
||||
line = log_text(m)
|
||||
out.write(f"{time.strftime('%H:%M:%S')} {self.tag} {line}\n")
|
||||
if r := RX_RE.search(line):
|
||||
self.rx.append(tuple(float(v) for v in r.groups()))
|
||||
if "cct" in line or "cc1101" in line:
|
||||
self.lines.append(line)
|
||||
|
||||
async def act(self, name, **kw):
|
||||
try:
|
||||
await self.cli.execute_service(self.svc[name], kw)
|
||||
except Exception as e: # noqa: BLE001
|
||||
self.failed += 1
|
||||
print(
|
||||
f" ACTION FAILED {self.tag} {name}: {type(e).__name__}: {e}",
|
||||
flush=True,
|
||||
)
|
||||
await asyncio.sleep(0.3)
|
||||
|
||||
|
||||
async def wait_mark(dev, mark, before, timeout=8.0):
|
||||
t = time.monotonic()
|
||||
while (
|
||||
sum(1 for line in dev.lines if mark in line) <= before
|
||||
and time.monotonic() - t < timeout
|
||||
):
|
||||
await asyncio.sleep(0.1)
|
||||
if sum(1 for line in dev.lines if mark in line) <= before:
|
||||
dev.failed += 1
|
||||
print(f" INVALID: {dev.tag} never logged {mark.strip()}", flush=True)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
REPORTED = 0 # failures already shown on a result line
|
||||
# The dev bug repros measure a known failure, so their counts are reported but not judged
|
||||
REPROS = {"crc", "rxtx", "txback", "txrx", "txset", "nocrc64"}
|
||||
MISSED: list[str] = [] # cases whose good count missed what they expect
|
||||
|
||||
|
||||
def verdict(tx, rx):
|
||||
"""INVALID when an action or an awaited log line failed since the last result line."""
|
||||
global REPORTED
|
||||
total = tx.failed + rx.failed
|
||||
bad, REPORTED = total > REPORTED, total
|
||||
return "INVALID " if bad else ""
|
||||
|
||||
|
||||
async def configure(dev, length, crc=False):
|
||||
n = sum(1 for line in dev.lines if "CFG " in line)
|
||||
await dev.act("cfg", len=length, crc=crc)
|
||||
await wait_mark(dev, "CFG ", n)
|
||||
|
||||
|
||||
def sent_count(dev):
|
||||
return sum(1 for line in dev.lines if "SENT " in line)
|
||||
|
||||
|
||||
async def tx_errors(tx, before):
|
||||
"""The errors= of the sender's SENT line for the last send, or ? when it never came."""
|
||||
if not await wait_mark(tx, "SENT ", before):
|
||||
return "?"
|
||||
m = re.search(
|
||||
r"SENT .* errors=(\d+)", [line for line in tx.lines if "SENT " in line][-1]
|
||||
)
|
||||
return m[1] if m else "?"
|
||||
|
||||
|
||||
async def case(
|
||||
tx,
|
||||
rx,
|
||||
label,
|
||||
count,
|
||||
length,
|
||||
b0,
|
||||
gap_ms,
|
||||
rx_len=None,
|
||||
tx_len=None,
|
||||
crc=False,
|
||||
wait=None,
|
||||
want=None,
|
||||
):
|
||||
"""WANT: "most" (80 % good), "none" (no packet at all) or "any" (not judged); judged cases need txerr=0."""
|
||||
want = want or ("any" if MODE in REPROS else "most")
|
||||
nr, nt = (
|
||||
sum(1 for line in rx.lines if "CFG " in line),
|
||||
sum(1 for line in tx.lines if "CFG " in line),
|
||||
)
|
||||
if rx_len != -1:
|
||||
await rx.act("cfg", len=rx_len if rx_len is not None else length, crc=crc)
|
||||
if tx_len != -1:
|
||||
await tx.act(
|
||||
"cfg", len=tx_len if tx_len is not None else min(length, 64), crc=crc
|
||||
)
|
||||
if rx_len != -1:
|
||||
await wait_mark(rx, "CFG ", nr)
|
||||
if tx_len != -1:
|
||||
await wait_mark(tx, "CFG ", nt)
|
||||
await asyncio.sleep(0.5)
|
||||
rx.rx.clear()
|
||||
ns = sent_count(tx)
|
||||
await tx.act("send", count=count, len=length, b0=b0, gap_ms=gap_ms)
|
||||
await asyncio.sleep(
|
||||
wait if wait is not None else count * (gap_ms / 1000 + length / 600 + 0.15) + 2
|
||||
)
|
||||
txerr = await tx_errors(tx, ns)
|
||||
got = [p for p in rx.rx if int(p[1]) == (b0 & 0xFF)]
|
||||
good = [p for p in got if int(p[0]) == length and p[3] == 1]
|
||||
other = len(rx.rx) - len(got)
|
||||
|
||||
def stat(i):
|
||||
return f"{statistics.mean(p[i] for p in good):.1f}" if good else "-"
|
||||
|
||||
lens = sorted({int(p[0]) for p in got})
|
||||
# a judged case also needs every packet to have gone out: "nothing arrived" proves nothing otherwise
|
||||
missed = want != "any" and (
|
||||
txerr != "0"
|
||||
or (want == "most" and len(good) * 5 < count * 4)
|
||||
or (want == "none" and len(got) > 0)
|
||||
)
|
||||
if missed:
|
||||
MISSED.append(label)
|
||||
print(
|
||||
f"{label:34} {verdict(tx, rx)}{'MISSED ' if missed else ''}sent={count} txerr={txerr} good={len(good)} wrong={len(got) - len(good)} lens={lens} other={other} "
|
||||
f"rssi={stat(4)} lqi={stat(5)} fo={stat(6)}",
|
||||
flush=True,
|
||||
)
|
||||
return len(good)
|
||||
|
||||
|
||||
async def main():
|
||||
tx, rx = Dev(TXH, "TX"), Dev(RXH, "RX")
|
||||
await asyncio.gather(tx.start(), rx.start())
|
||||
await asyncio.sleep(1)
|
||||
if MODE.startswith("fast"):
|
||||
rates = {
|
||||
"fast38": (38400, 1, 20000, 135000, 50),
|
||||
"fast100": (100000, 0, 50000, 325000, 20),
|
||||
}
|
||||
if MODE not in (*rates, "fast"):
|
||||
sys.exit(f"unknown mode {MODE}")
|
||||
for key in [MODE] if MODE in rates else list(rates):
|
||||
sr, mod, dev, bw, poll = rates[key]
|
||||
for d in (tx, rx):
|
||||
n = sum(1 for line in d.lines if "RATE " in line)
|
||||
await d.act("rate", sr=sr, mod=mod, dev=dev, bw=bw, poll=poll, sync=3)
|
||||
await wait_mark(d, "RATE ", n)
|
||||
await asyncio.sleep(0.5)
|
||||
print(
|
||||
"RATE",
|
||||
[line.split("RATE ")[1] for line in rx.lines if "RATE " in line][-1:],
|
||||
flush=True,
|
||||
)
|
||||
k = sr / 4800
|
||||
await case(tx, rx, f"{key} len=32", 20, 32, 70, 100)
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
f"{key} len=300",
|
||||
20,
|
||||
300,
|
||||
71,
|
||||
100,
|
||||
wait=20 * (0.1 + 0.3 + 300 / 600 / k) + 3,
|
||||
)
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
f"{key} len=1024",
|
||||
10,
|
||||
1024,
|
||||
72,
|
||||
100,
|
||||
wait=10 * (0.1 + 0.4 + 1024 / 600 / k) + 3,
|
||||
)
|
||||
await case(tx, rx, f"{key} burst 300 x5", 5, 300, 73, 0, wait=8)
|
||||
ov_before = len([line for line in rx.lines if "overflow" in line])
|
||||
print(f"{key} RX overflow warnings so far: {ov_before}", flush=True)
|
||||
for d in (tx, rx):
|
||||
await d.act("rate", sr=4800, mod=1, dev=47607, bw=203000, poll=300, sync=2)
|
||||
elif MODE == "short":
|
||||
for direction, a, b in ((f"{TXN}->{RXN}", tx, rx), (f"{RXN}->{TXN}", rx, tx)):
|
||||
for length in (32, 64):
|
||||
for crc in (False, True):
|
||||
await case(
|
||||
a,
|
||||
b,
|
||||
f"{direction} len={length} crc={int(crc)}",
|
||||
20,
|
||||
length,
|
||||
1,
|
||||
150,
|
||||
crc=crc,
|
||||
want="any"
|
||||
if length == 64 and crc
|
||||
else None, # 0/20 on dev too, #22635
|
||||
)
|
||||
elif MODE == "long":
|
||||
await case(tx, rx, f"{TXN}->{RXN} len=32 (runtime, long build)", 10, 32, 1, 200)
|
||||
for length in (100, 255, 300, 1024):
|
||||
await case(tx, rx, f"{TXN}->{RXN} long len={length}", 10, length, 2, 300)
|
||||
await rx.act("idle_rx")
|
||||
await case(tx, rx, "after set_idle+begin_rx len=100", 5, 100, 3, 300, wait=None)
|
||||
await rx.act("tx_rx")
|
||||
await case(
|
||||
tx, rx, "after begin_tx+begin_rx len=300", 5, 300, 4, 300, want="any"
|
||||
) # dead reception on dev, #22636
|
||||
elif MODE == "r2long":
|
||||
await case(tx, rx, "burst 300 x5, no gap", 5, 300, 10, 0)
|
||||
await case(tx, rx, "burst 65 x10, no gap", 10, 65, 11, 0)
|
||||
await case(tx, rx, "burst 1024 x3, no gap", 3, 1024, 12, 0)
|
||||
# power down in the middle of a run of 300-byte packets, wake 1 s later
|
||||
await configure(rx, 300)
|
||||
await configure(tx, 64)
|
||||
rx.rx.clear()
|
||||
ns = sent_count(tx)
|
||||
await tx.act("send", count=10, len=300, b0=13, gap_ms=300)
|
||||
await asyncio.sleep(1.6)
|
||||
await rx.act("pdown")
|
||||
await asyncio.sleep(1.0)
|
||||
await rx.act("wup")
|
||||
await asyncio.sleep(10 * 0.85 + 2)
|
||||
got = [p for p in rx.rx if int(p[1]) == 13]
|
||||
good = sum(1 for p in got if int(p[0]) == 300 and p[3] == 1)
|
||||
txerr = await tx_errors(tx, ns)
|
||||
print(
|
||||
f"{'power_down mid-run, wake 1 s later':34} {verdict(tx, rx)}sent=10 txerr={txerr} good={good} "
|
||||
f"wrong={len(got) - good}",
|
||||
flush=True,
|
||||
)
|
||||
await case(tx, rx, "after power_down/wake_up 300", 5, 300, 14, 300, rx_len=-1)
|
||||
await rx.act("pdown")
|
||||
await asyncio.sleep(0.5)
|
||||
await rx.act("wup")
|
||||
await case(tx, rx, "power_down/wake_up between, 1024", 3, 1024, 15, 300)
|
||||
elif MODE == "r2mid":
|
||||
await configure(rx, 1024)
|
||||
await configure(tx, 64)
|
||||
await asyncio.sleep(0.5)
|
||||
await tx.act("send", count=1, len=1024, b0=40, gap_ms=0)
|
||||
await asyncio.sleep(0.6)
|
||||
await rx.act("hf")
|
||||
await rx.act("setlen", len=32)
|
||||
await asyncio.sleep(0.6)
|
||||
await rx.act("hf")
|
||||
await asyncio.sleep(1.5)
|
||||
await case(
|
||||
tx, rx, "after setlen 32 mid-packet, len 32", 5, 32, 41, 200, rx_len=-1
|
||||
)
|
||||
await configure(rx, 1024)
|
||||
await tx.act("send", count=1, len=1024, b0=42, gap_ms=0)
|
||||
await asyncio.sleep(0.6)
|
||||
await rx.act("hf")
|
||||
await rx.act("pmode", enable=False)
|
||||
await asyncio.sleep(0.6)
|
||||
await rx.act("hf")
|
||||
await rx.act("pmode", enable=True)
|
||||
await asyncio.sleep(1.5)
|
||||
await case(
|
||||
tx, rx, "after packet_mode off/on mid-packet, len 100", 5, 100, 43, 300
|
||||
)
|
||||
await rx.act("pdown")
|
||||
await rx.act("setlen", len=300)
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
"asleep after setlen 300 (expect 0)",
|
||||
3,
|
||||
300,
|
||||
44,
|
||||
300,
|
||||
rx_len=-1,
|
||||
wait=5,
|
||||
want="none",
|
||||
)
|
||||
await rx.act("wup")
|
||||
await case(tx, rx, "after wake_up, len 300", 5, 300, 45, 300, rx_len=-1)
|
||||
hf = [line for line in rx.lines if "HF " in line]
|
||||
print("HF lines:", [line.split("HF ")[1][:2] for line in hf], flush=True)
|
||||
elif MODE == "txset":
|
||||
await case(tx, rx, "32 before", 10, 32, 60, 150)
|
||||
await rx.act("tx_setters")
|
||||
await case(tx, rx, "begin_tx, setters, begin_rx", 20, 32, 61, 150, rx_len=-1)
|
||||
print(
|
||||
"lines:",
|
||||
[
|
||||
line.split("TX_SETTERS ")[1][:60]
|
||||
for line in rx.lines
|
||||
if "TX_SETTERS" in line
|
||||
],
|
||||
flush=True,
|
||||
)
|
||||
elif MODE == "txback":
|
||||
await case(tx, rx, f"{TXN}->{RXN} before", 10, 32, 50, 150)
|
||||
await case(
|
||||
rx,
|
||||
tx,
|
||||
f"{RXN} send (plain) -> {TXN}",
|
||||
10,
|
||||
32,
|
||||
51,
|
||||
150,
|
||||
rx_len=-1,
|
||||
tx_len=-1,
|
||||
)
|
||||
await case(
|
||||
tx, rx, f"{TXN}->{RXN} after plain sends", 20, 32, 52, 150, rx_len=-1
|
||||
)
|
||||
await rx.act("tx_only")
|
||||
await case(
|
||||
rx,
|
||||
tx,
|
||||
f"begin_tx, then {RXN} send -> {TXN}",
|
||||
10,
|
||||
32,
|
||||
53,
|
||||
150,
|
||||
rx_len=-1,
|
||||
tx_len=-1,
|
||||
)
|
||||
await case(tx, rx, f"{TXN}->{RXN} after that", 20, 32, 54, 150, rx_len=-1)
|
||||
elif MODE == "nocrc64":
|
||||
await case(tx, rx, "64 no CRC x100", 100, 64, 55, 150)
|
||||
await case(tx, rx, "64 CRC x100", 100, 64, 56, 150, crc=True)
|
||||
elif MODE == "r2lambda":
|
||||
await case(tx, rx, "lambda 40 before", 5, 40, 39, 200, rx_len=-1, tx_len=40)
|
||||
await rx.act("setlen", len=100)
|
||||
await case(
|
||||
tx, rx, "runtime setlen 100 (clears lambda)", 5, 100, 16, 300, rx_len=-1
|
||||
)
|
||||
await rx.act("setlen", len=32)
|
||||
await case(tx, rx, "runtime setlen 32", 5, 32, 17, 200, rx_len=-1, tx_len=32)
|
||||
await rx.act("pmode", enable=False)
|
||||
await rx.act("pmode", enable=True)
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
"after packet_mode off/on, len 32",
|
||||
5,
|
||||
32,
|
||||
18,
|
||||
200,
|
||||
rx_len=-1,
|
||||
tx_len=32,
|
||||
)
|
||||
await rx.act("setlen", len=300)
|
||||
await case(tx, rx, "runtime setlen 300", 5, 300, 19, 300, rx_len=-1)
|
||||
elif MODE == "crc":
|
||||
await case(tx, rx, "64 CRC", 20, 64, 20, 150, crc=True)
|
||||
await case(tx, rx, "32 CRC", 20, 32, 21, 150, crc=True)
|
||||
await case(tx, rx, "64 no CRC", 20, 64, 22, 150)
|
||||
await tx.act("whiten", enable=True)
|
||||
await case(
|
||||
tx, rx, "64 CRC, TX whitening only (bad)", 5, 64, 23, 200, crc=True, wait=4
|
||||
)
|
||||
await tx.act("whiten", enable=False)
|
||||
await case(tx, rx, "64 CRC after the bad ones", 10, 64, 24, 150, crc=True)
|
||||
elif MODE == "rxtx":
|
||||
await case(tx, rx, "32 before", 10, 32, 30, 150)
|
||||
await rx.act("tx_rx")
|
||||
await case(tx, rx, "begin_tx + begin_rx", 20, 32, 31, 150, rx_len=-1)
|
||||
await rx.act("tx_idle_rx")
|
||||
await case(tx, rx, "begin_tx + set_idle + begin_rx", 20, 32, 32, 150, rx_len=-1)
|
||||
await rx.act("tx_reset")
|
||||
await case(tx, rx, "begin_tx + reset", 20, 32, 33, 150, rx_len=-1)
|
||||
await rx.act("tx_only")
|
||||
await case(
|
||||
rx,
|
||||
tx,
|
||||
f"begin_tx, then {RXN} send -> {TXN}",
|
||||
10,
|
||||
32,
|
||||
34,
|
||||
150,
|
||||
rx_len=-1,
|
||||
tx_len=-1,
|
||||
)
|
||||
await case(tx, rx, f"{TXN}->{RXN} after that", 20, 32, 35, 150, rx_len=-1)
|
||||
elif MODE == "txrx":
|
||||
await case(tx, rx, "len=32 before", 5, 32, 6, 200)
|
||||
await rx.act("tx_rx")
|
||||
await case(tx, rx, "len=32 after begin_tx+begin_rx", 5, 32, 7, 200, rx_len=-1)
|
||||
await rx.act("idle_rx")
|
||||
await case(tx, rx, "len=32 after set_idle+begin_rx", 5, 32, 8, 200, rx_len=-1)
|
||||
await case(tx, rx, "len=32 after cfg", 5, 32, 9, 200)
|
||||
elif MODE == "lambda":
|
||||
for length in (10, 40, 64):
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
f"{TXN}->{RXN} lambda len={length}",
|
||||
10,
|
||||
length,
|
||||
length - 1,
|
||||
200,
|
||||
rx_len=-1,
|
||||
tx_len=length,
|
||||
)
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
f"{TXN}->{RXN} lambda discard (b0=0xEE)",
|
||||
3,
|
||||
40,
|
||||
0xEE,
|
||||
200,
|
||||
rx_len=-1,
|
||||
tx_len=40,
|
||||
want="none",
|
||||
)
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
f"{TXN}->{RXN} lambda after discard len=40",
|
||||
5,
|
||||
40,
|
||||
39,
|
||||
200,
|
||||
rx_len=-1,
|
||||
tx_len=40,
|
||||
)
|
||||
await rx.act("idle_rx")
|
||||
await case(
|
||||
tx,
|
||||
rx,
|
||||
"lambda after set_idle+begin_rx len=40",
|
||||
5,
|
||||
40,
|
||||
39,
|
||||
200,
|
||||
rx_len=-1,
|
||||
tx_len=40,
|
||||
)
|
||||
else:
|
||||
sys.exit(f"unknown mode {MODE}")
|
||||
errors = 0
|
||||
for d in (tx, rx):
|
||||
warn = [line for line in d.lines if "[W]" in line or "[E]" in line]
|
||||
print(f"{d.tag} warnings/errors: {len(warn)}", *warn[:10], sep="\n ")
|
||||
errors += sum("[E]" in line for line in warn)
|
||||
await d.cli.disconnect()
|
||||
if errors and MODE not in REPROS:
|
||||
sys.exit(f"FAIL: {errors} error lines from the radios")
|
||||
if tx.failed or rx.failed:
|
||||
sys.exit(
|
||||
f"INVALID: {tx.failed + rx.failed} failed actions or missing CFG/RATE lines"
|
||||
)
|
||||
if MISSED:
|
||||
sys.exit(f"MISSED: {len(MISSED)} cases below their expected count: {MISSED}")
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -1,106 +0,0 @@
|
||||
// Raw CC1101 helpers for the #17578 test: register readback and a TX that streams packets longer than the TX FIFO.
|
||||
#pragma once
|
||||
#include "esphome/components/cc1101/cc1101.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace ccl {
|
||||
using esphome::cc1101::CC1101Component;
|
||||
inline uint8_t rd(CC1101Component *c, uint8_t a) {
|
||||
c->enable();
|
||||
c->write_byte(a | 0x80);
|
||||
uint8_t v = c->read_byte();
|
||||
c->disable();
|
||||
return v;
|
||||
}
|
||||
inline uint8_t rdst(CC1101Component *c, uint8_t a) { return rd(c, a | 0x40); }
|
||||
inline void wr(CC1101Component *c, uint8_t a, uint8_t v) {
|
||||
c->enable();
|
||||
c->write_byte(a);
|
||||
c->write_byte(v);
|
||||
c->disable();
|
||||
}
|
||||
inline void strobe(CC1101Component *c, uint8_t s) {
|
||||
c->enable();
|
||||
c->write_byte(s);
|
||||
c->disable();
|
||||
}
|
||||
inline void fifo(CC1101Component *c, const uint8_t *d, size_t n) {
|
||||
c->enable();
|
||||
c->write_byte(0x7F);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
c->write_byte(d[i]);
|
||||
c->disable();
|
||||
}
|
||||
// Datasheet 15.2.2: infinite mode with PKTLEN = n mod 256, fixed mode once fewer than 256 bytes remain.
|
||||
// Returns 0 on success, 1 on an early underflow, 2 on a timeout, 3 on an underflow after the last byte in fixed length
|
||||
// mode (the switch from infinite mode came too late). A length that is a multiple of 256 stays in infinite mode and
|
||||
// ends on the underflow after its last byte.
|
||||
inline int long_tx(CC1101Component *c, const uint8_t *d, size_t n, uint32_t poll_us = 300) {
|
||||
c->set_idle();
|
||||
const uint8_t p0 = rd(c, 0x08), plen = rd(c, 0x06);
|
||||
strobe(c, 0x3B); // SFTX
|
||||
bool inf = n > 255;
|
||||
wr(c, 0x06, n & 0xFF);
|
||||
wr(c, 0x08, (p0 & ~3) | (inf ? 2 : 0));
|
||||
size_t w = std::min<size_t>(n, 64);
|
||||
fifo(c, d, w);
|
||||
strobe(c, 0x35); // STX
|
||||
int err = 0;
|
||||
const uint32_t t0 = millis();
|
||||
while (true) {
|
||||
uint8_t tb = rdst(c, 0x3A);
|
||||
if (tb & 0x80) {
|
||||
if (w < n)
|
||||
err = 1;
|
||||
else if (!inf)
|
||||
err = 3;
|
||||
break;
|
||||
}
|
||||
tb &= 0x7F;
|
||||
const size_t sent = w - tb;
|
||||
if (inf && (n & 0xFF) != 0 && n - sent < 256) {
|
||||
wr(c, 0x08, p0 & ~3);
|
||||
inf = false;
|
||||
}
|
||||
if (w < n && tb < 48) {
|
||||
const size_t k = std::min<size_t>(n - w, 63 - tb);
|
||||
fifo(c, d + w, k);
|
||||
w += k;
|
||||
}
|
||||
const uint8_t marc = rdst(c, 0x35) & 0x1F;
|
||||
if (w == n && tb == 0 && marc != 0x13 && marc != 0x14) // not TX or TX_END
|
||||
break;
|
||||
if (millis() - t0 > 4000) {
|
||||
err = 2;
|
||||
break;
|
||||
}
|
||||
esphome::App.feed_wdt();
|
||||
delayMicroseconds(poll_us);
|
||||
}
|
||||
delay(5);
|
||||
c->set_idle();
|
||||
strobe(c, 0x3B);
|
||||
wr(c, 0x06, plen);
|
||||
wr(c, 0x08, p0);
|
||||
c->begin_rx();
|
||||
return err;
|
||||
}
|
||||
inline void fill(std::vector<uint8_t> &b, size_t len, int b0, uint8_t seq) {
|
||||
b.resize(len);
|
||||
for (size_t i = 0; i < len; i++)
|
||||
b[i] = (uint8_t) (seq * 31 + i * 7);
|
||||
b[0] = (uint8_t) b0;
|
||||
if (len > 1)
|
||||
b[1] = seq;
|
||||
}
|
||||
inline bool check(const std::vector<uint8_t> &x) {
|
||||
if (x.size() < 2)
|
||||
return true;
|
||||
const uint8_t seq = x[1];
|
||||
for (size_t i = 2; i < x.size(); i++)
|
||||
if (x[i] != (uint8_t) (seq * 31 + i * 7))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
} // namespace ccl
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
# flashmac.sh NAME BOARD: upload NAME.yaml from TREE to BOARD (a port such as /dev/cu.usbserial-0001, or the board's
|
||||
# USB serial number, `ports.py` lists it, so a port that moved after a replug is still found), then wait until
|
||||
# NAME.local answers on the API with that name. Needs apikey.txt (the api_key secret) next to the configs.
|
||||
# env: TREE, PY
|
||||
D=$(cd "$(dirname "$0")" && pwd); S=$(dirname "$D"); N=${1:?name}; BOARD=${2:?port or USB serial number}
|
||||
T=${TREE:?set TREE}; PY=${PY:-$T/venv/bin/python}; cd "$D" || exit 1
|
||||
export API_KEY=${API_KEY:-$(cat apikey.txt)}
|
||||
case $BOARD in
|
||||
/dev/*) P=$BOARD ;;
|
||||
*) P=$($PY "$S/ports.py" --serial "$BOARD" --timeout 10) || { echo "no port for $BOARD"; exit 1; } ;;
|
||||
esac
|
||||
echo "flash $N to $BOARD on $P"
|
||||
PIO_CORE=${PIO_CORE:-$D/pio} bash "$S/pio_build.sh" upload "$N" "$D/$N.yaml" "$P" || exit 1
|
||||
IP=$(bash "$S/resolve.sh" "$N" 40) || { echo "$N did not come up"; exit 1; }
|
||||
$PY "$S/ota_timing/apiinfo.py" "$IP" | grep " $N " || { echo "$N did not answer on the API"; exit 1; }
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
# runall.sh A B: both roles; A and B are the boards' ports or USB serial numbers (see flashmac.sh). Phase A: board A
|
||||
# receives (long build, then the lambda build) while board B sends from its long build; phase B swaps them.
|
||||
# Configs: cc-a-long.yaml, cc-a-lambda.yaml, cc-b-long.yaml, cc-b-lambda.yaml (copies of the c3/s3 examples with
|
||||
# `name:` set to the file name). Order matters, see recipes/cc1101.md.
|
||||
# env: TREE, PY
|
||||
D=$(cd "$(dirname "$0")" && pwd); cd "$D" || exit 1; A=${1:?board a}; B=${2:?board b}
|
||||
PY=${PY:-${TREE:?set TREE}/venv/bin/python}
|
||||
export API_KEY=${API_KEY:-$(cat apikey.txt)}
|
||||
FAILED=0
|
||||
drive() { # TXNAME RXNAME MODE TXLABEL RXLABEL
|
||||
echo "--- $3 TX=$1 RX=$2"
|
||||
timeout 1200 $PY ccdrive.py "$1.local" "$2.local" "$3" "$2-$3.log" "$4" "$5" 2>&1 | grep -v "^\s*$"
|
||||
local rc=${PIPESTATUS[0]}
|
||||
[ "$rc" = 0 ] || { echo "MODE FAILED $3 TX=$1 RX=$2 exit=$rc (124 is the timeout)"; FAILED=$((FAILED + 1)); }
|
||||
}
|
||||
fl() { ./flashmac.sh "$1" "$2" || { echo "FLASH FAIL $1"; exit 1; }; }
|
||||
phase() { # TX RX TXBOARD RXBOARD TXLABEL RXLABEL: RX receives (long build, then the lambda build), TX sends
|
||||
fl "cc-$1-long" "$3"
|
||||
fl "cc-$2-long" "$4"; for m in fast r2long r2mid long; do drive "cc-$1-long" "cc-$2-long" $m "$5" "$6"; done
|
||||
fl "cc-$2-lambda" "$4"; for m in lambda r2lambda; do drive "cc-$1-long" "cc-$2-lambda" $m "$5" "$6"; done
|
||||
}
|
||||
echo "===== Phase A: A receives, B sends"
|
||||
phase b a "$B" "$A" B A
|
||||
echo "===== Phase B: B receives, A sends"
|
||||
phase a b "$A" "$B" A B
|
||||
echo "RUNDONE failed_modes=$FAILED"
|
||||
[ "$FAILED" = 0 ]
|
||||
@@ -1,16 +0,0 @@
|
||||
# Example wiring for an E07-M1101D (CC1101) module; change the pins to match your board. plen 1024 = long packets,
|
||||
# 32 = plain fixed length (copy the file and set plen and name for a plain build).
|
||||
substitutions:
|
||||
name: cc-s3-long
|
||||
clk: GPIO12
|
||||
mosi: GPIO11
|
||||
miso: GPIO13
|
||||
cs: GPIO10
|
||||
gdo0: GPIO9
|
||||
plen: "1024"
|
||||
packages:
|
||||
c: !include cccommon.yaml
|
||||
esp32:
|
||||
board: esp32-s3-devkitc-1
|
||||
framework:
|
||||
type: esp-idf
|
||||
@@ -1,170 +0,0 @@
|
||||
# CC1101 sleep and wake checks T0 to T6 on an ESP32-S3 (SPI on GPIO12/11/13, CS GPIO10, GDO0 GPIO9), run 4 s after
|
||||
# boot; the result is the "DONE fails=N" line. Substitution: name.
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes: [cctest.hpp]
|
||||
on_boot:
|
||||
- priority: -100
|
||||
then:
|
||||
- delay: 4s
|
||||
- script.execute: run_tests
|
||||
esp32:
|
||||
variant: esp32s3
|
||||
framework:
|
||||
type: esp-idf
|
||||
logger:
|
||||
level: DEBUG
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
spi:
|
||||
clk_pin: GPIO12
|
||||
mosi_pin: GPIO11
|
||||
miso_pin: GPIO13
|
||||
cc1101:
|
||||
id: transceiver
|
||||
cs_pin: GPIO10
|
||||
gdo0_pin: GPIO9
|
||||
frequency: 433.92MHz
|
||||
modulation_type: GFSK
|
||||
symbol_rate: 4800
|
||||
packet_mode: true
|
||||
packet_length: 8
|
||||
crc_enable: true
|
||||
sync_mode: "16/16"
|
||||
output_power: 0
|
||||
on_packet:
|
||||
then:
|
||||
- lambda: ESP_LOGI("cct", "RX packet %s rssi %.1f", format_hex(x).c_str(), rssi);
|
||||
script:
|
||||
- id: run_tests
|
||||
then:
|
||||
- lambda: |-
|
||||
using namespace cct;
|
||||
auto *c = id(transceiver);
|
||||
Snap base, s;
|
||||
int fails = 0;
|
||||
snap(c, base);
|
||||
ESP_LOGI("cct", "T0 baseline MARCSTATE=%02X FREQ=%02X%02X%02X TEST2=%02X TEST1=%02X TEST0=%02X so_high_awake=%d",
|
||||
base.marc, base.reg[0x0D], base.reg[0x0E], base.reg[0x0F], base.reg[0x2C], base.reg[0x2D],
|
||||
base.reg[0x2E], cs_low_so_high(c));
|
||||
hexpa("T0 baseline", base.pa);
|
||||
// the sleep checks below need a probe that sees an awake chip as awake
|
||||
if (cs_low_so_high(c)) {
|
||||
ESP_LOGW("cct", "T0 FAIL: SO reads high on an awake chip, the sleep checks cannot be trusted");
|
||||
fails++;
|
||||
}
|
||||
|
||||
// T1: mark PATABLE 1-7, sleep, wake by hand: lost entries prove the chip slept
|
||||
const uint8_t marks[8] = {base.pa[0], 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
|
||||
write_pa(c, marks);
|
||||
snap(c, s); hexpa("T1 marked", s.pa);
|
||||
c->power_down();
|
||||
bool so = cs_low_so_high(c);
|
||||
snap(c, s);
|
||||
hexpa("T1 after raw wake", s.pa);
|
||||
bool lost = s.pa[1] != 0x11;
|
||||
ESP_LOGI("cct", "T1 sleep proof: so_high_on_cs=%d pa_lost=%d MARCSTATE=%02X TEST0=%02X -> %s", so, lost, s.marc,
|
||||
s.reg[0x2E], (so && lost) ? "PASS" : "FAIL");
|
||||
if (!(so && lost)) fails++;
|
||||
// the component still thinks it sleeps
|
||||
c->wake_up();
|
||||
snap(c, s);
|
||||
int d = diff(base, s, "T1 restore");
|
||||
ESP_LOGI("cct", "T1 restore after wake_up: %d differences, MARCSTATE=%02X -> %s", d, s.marc, d == 0 ? "PASS" : "FAIL");
|
||||
if (d) fails++;
|
||||
c->begin_rx();
|
||||
|
||||
// T2: change settings while asleep, compare with the same change made awake
|
||||
Snap awake;
|
||||
c->set_frequency(433.42e6); c->set_output_power(5); c->set_symbol_rate(9600);
|
||||
snap(c, awake);
|
||||
c->set_frequency(433.92e6); c->set_output_power(0); c->set_symbol_rate(4800);
|
||||
c->power_down();
|
||||
c->set_frequency(433.42e6); c->set_output_power(5); c->set_symbol_rate(9600);
|
||||
bool so2 = cs_low_so_high(c); // wakes the chip by hand; component still asleep
|
||||
c->wake_up();
|
||||
c->begin_rx();
|
||||
snap(c, s);
|
||||
awake.marc = s.marc;
|
||||
d = diff(awake, s, "T2 asleep vs awake");
|
||||
ESP_LOGI("cct", "T2 settings changed asleep: so_high=%d %d differences FREQ=%02X%02X%02X MARCSTATE=%02X -> %s", so2, d,
|
||||
s.reg[0x0D], s.reg[0x0E], s.reg[0x0F], s.marc, (so2 && d == 0) ? "PASS" : "FAIL");
|
||||
if (!(so2 && d == 0)) fails++;
|
||||
c->set_frequency(433.92e6); c->set_output_power(0); c->set_symbol_rate(4800);
|
||||
c->begin_rx();
|
||||
snap(c, base);
|
||||
|
||||
// T3: send while asleep wakes the radio by itself
|
||||
c->power_down();
|
||||
uint8_t pkt[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
int err = (int) c->transmit_packet(pkt, sizeof(pkt));
|
||||
snap(c, s);
|
||||
d = diff(base, s, "T3 after send");
|
||||
ESP_LOGI("cct", "T3 send while asleep: err=%d MARCSTATE=%02X TXBYTES=%02X %d differences -> %s", err, s.marc,
|
||||
status(c, 0x3A), d, (err == 0 && d == 0) ? "PASS" : "FAIL");
|
||||
if (!(err == 0 && d == 0)) fails++;
|
||||
|
||||
// T4: begin_rx while asleep
|
||||
c->power_down();
|
||||
c->begin_rx();
|
||||
snap(c, s);
|
||||
d = diff(base, s, "T4 begin_rx");
|
||||
ESP_LOGI("cct", "T4 begin_rx while asleep: MARCSTATE=%02X %d differences -> %s", s.marc, d,
|
||||
(s.marc == 0x0D && d == 0) ? "PASS" : "FAIL");
|
||||
if (!(s.marc == 0x0D && d == 0)) fails++;
|
||||
|
||||
// T5: 200 cycles, each one proven asleep and restored
|
||||
int bad = 0, notslept = 0;
|
||||
uint32_t t0 = micros();
|
||||
for (int i = 0; i < 200; i++) {
|
||||
write_pa(c, marks);
|
||||
c->power_down();
|
||||
if (!cs_low_so_high(c)) notslept++;
|
||||
c->wake_up();
|
||||
c->begin_rx();
|
||||
snap(c, s);
|
||||
if (diff(base, s, "T5") != 0) bad++;
|
||||
if ((i & 31) == 0) App.feed_wdt();
|
||||
}
|
||||
ESP_LOGI("cct", "T5 200 cycles: not_slept=%d restore_fail=%d in %u ms heap=%u -> %s", notslept, bad,
|
||||
(unsigned) ((micros() - t0) / 1000), (unsigned) esp_get_free_heap_size(),
|
||||
(notslept == 0 && bad == 0) ? "PASS" : "FAIL");
|
||||
if (notslept || bad) fails++;
|
||||
// T6: each setter on its own while asleep: does it wake the chip, and in which state does it leave it
|
||||
struct Case { const char *name; int kind; };
|
||||
const Case cases[] = {{"set_frequency", 0}, {"set_channel", 1}, {"set_modulation_type", 2}, {"set_symbol_rate", 3},
|
||||
{"set_output_power", 4}, {"set_filter_bandwidth", 5}, {"set_fsk_deviation", 6}};
|
||||
for (auto &k : cases) {
|
||||
c->begin_rx();
|
||||
c->power_down();
|
||||
switch (k.kind) {
|
||||
case 0: c->set_frequency(433.92e6); break;
|
||||
case 1: c->set_channel(0); break;
|
||||
case 2: c->set_modulation_type(cc1101::Modulation::MODULATION_GFSK); break;
|
||||
case 3: c->set_symbol_rate(4800); break;
|
||||
case 4: c->set_output_power(0); break;
|
||||
case 5: c->set_filter_bandwidth(203e3); break;
|
||||
case 6: c->set_fsk_deviation(1.5e3); break;
|
||||
}
|
||||
bool asleep = cs_low_so_high(c);
|
||||
uint8_t marc = status(c, 0x35) & 0x1F;
|
||||
ESP_LOGI("cct", "T6 %-20s while asleep: chip %s, MARCSTATE=%02X", k.name, asleep ? "still asleep" : "AWAKE", marc);
|
||||
if (!asleep) fails++;
|
||||
c->wake_up();
|
||||
}
|
||||
c->begin_rx();
|
||||
uint8_t agc_rx = rd(c, 0x2B);
|
||||
c->set_idle();
|
||||
uint8_t agc_idle = rd(c, 0x2B);
|
||||
ESP_LOGI("cct", "AGCTEST in RX=%02X in IDLE=%02X", agc_rx, agc_idle);
|
||||
c->begin_rx();
|
||||
ESP_LOGI("cct", "DONE fails=%d", fails);
|
||||
button:
|
||||
- platform: template
|
||||
id: yaml_actions
|
||||
name: Yaml actions
|
||||
on_press:
|
||||
- cc1101.power_down: transceiver
|
||||
- cc1101.wake_up: transceiver
|
||||
- cc1101.power_down: transceiver
|
||||
- cc1101.send_packet: [0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef]
|
||||
- lambda: ESP_LOGI("cct", "YAML actions done MARCSTATE=%02X", cct::status(id(transceiver), 0x35) & 0x1F);
|
||||
@@ -1,70 +0,0 @@
|
||||
// Register and PATABLE snapshots plus the CHIP_RDYn sleep check for the cc1101 sleep tests in cc1101-sleep.yaml.
|
||||
#pragma once
|
||||
#include "esphome/components/cc1101/cc1101.h"
|
||||
#include "driver/gpio.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace cct {
|
||||
using esphome::cc1101::CC1101Component;
|
||||
static constexpr gpio_num_t MISO = GPIO_NUM_13; // the SPI MISO pin in cc1101-sleep.yaml
|
||||
static constexpr uint8_t NREG = 0x2F; // IOCFG2..TEST0
|
||||
|
||||
struct Snap {
|
||||
uint8_t reg[NREG];
|
||||
uint8_t pa[8];
|
||||
uint8_t marc;
|
||||
};
|
||||
|
||||
// Chip ready flag: with CSn low, SO stays high until the crystal runs (SLEEP), low at once otherwise
|
||||
inline bool cs_low_so_high(CC1101Component *c) {
|
||||
c->enable();
|
||||
bool high = gpio_get_level(MISO);
|
||||
delayMicroseconds(300);
|
||||
c->disable();
|
||||
return high;
|
||||
}
|
||||
inline uint8_t rd(CC1101Component *c, uint8_t a) {
|
||||
c->enable();
|
||||
c->write_byte(a | 0x80);
|
||||
uint8_t v = c->read_byte();
|
||||
c->disable();
|
||||
return v;
|
||||
}
|
||||
inline uint8_t status(CC1101Component *c, uint8_t a) { return rd(c, a | 0x40); }
|
||||
inline void snap(CC1101Component *c, Snap &s) {
|
||||
for (uint8_t i = 0; i < NREG; i++)
|
||||
s.reg[i] = rd(c, i);
|
||||
c->enable();
|
||||
c->write_byte(0x3E | 0xC0);
|
||||
for (auto &b : s.pa)
|
||||
b = c->read_byte();
|
||||
c->disable();
|
||||
s.marc = status(c, 0x35) & 0x1F;
|
||||
}
|
||||
inline void write_pa(CC1101Component *c, const uint8_t *pa) {
|
||||
c->enable();
|
||||
c->write_byte(0x3E | 0x40);
|
||||
for (int i = 0; i < 8; i++)
|
||||
c->write_byte(pa[i]);
|
||||
c->disable();
|
||||
}
|
||||
inline int diff(const Snap &a, const Snap &b, const char *what) {
|
||||
int n = 0;
|
||||
for (uint8_t i = 0; i < NREG; i++)
|
||||
// FSCAL3..FSCAL1 hold calibration results, FSTEST and AGCTEST are chip owned test registers
|
||||
if (i != 0x23 && i != 0x24 && i != 0x25 && i != 0x29 && i != 0x2B && a.reg[i] != b.reg[i]) {
|
||||
ESP_LOGW("cct", "%s reg 0x%02X: %02X vs %02X", what, i, a.reg[i], b.reg[i]);
|
||||
n++;
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (a.pa[i] != b.pa[i]) {
|
||||
ESP_LOGW("cct", "%s pa[%d]: %02X vs %02X", what, i, a.pa[i], b.pa[i]);
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
inline void hexpa(const char *tag, const uint8_t *pa) {
|
||||
ESP_LOGI("cct", "%s PA %02X %02X %02X %02X %02X %02X %02X %02X", tag, pa[0], pa[1], pa[2], pa[3], pa[4], pa[5], pa[6],
|
||||
pa[7]);
|
||||
}
|
||||
} // namespace cct
|
||||
@@ -1,102 +0,0 @@
|
||||
"""quiet_then_subscribe.py HOST PORT OUT QUIET_BOOTS: on the first boot drain any crash record (the first log
|
||||
subscribe replays and clears it), then stay connected without a log subscription for QUIET_BOOTS reboots, then
|
||||
subscribe on the next boot and record the log (including a crash record replayed on subscribe) until a line with
|
||||
REBOOT. The drain connection is dropped and replaced by one without a subscription before boot 1 reboots, so a crash
|
||||
that needs a log subscriber is not recorded as a quiet one; a reboot during the drain, or a reconnect slow enough to
|
||||
hide one, fails the run instead of shifting the boot count. Exits 1 when that line never comes or a quiet boot does
|
||||
not reboot within QUIET_REBOOT_WAIT seconds (default 900). Every lost connection counts as a reboot, so run it on a
|
||||
stable link.
|
||||
env: API_KEY (unset for a plaintext API), QUIET_REBOOT_WAIT."""
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import LogLevel
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from apiconn import connect, log_text, stop_event # noqa: E402
|
||||
|
||||
# how long a quiet boot may run before its reboot; QUIET_REBOOT_WAIT in the env overrides it
|
||||
REBOOT_WAIT = float(os.environ.get("QUIET_REBOOT_WAIT", "900"))
|
||||
# a reconnect slower than this may have waited out a reboot (connect() retries once a second)
|
||||
RECONNECT_MAX_S = 5.0
|
||||
|
||||
|
||||
async def main(host: str, port: int, outf: str, quiet: int) -> None:
|
||||
with pathlib.Path(outf).open("a", encoding="utf-8") as f:
|
||||
|
||||
def w(t: str) -> None:
|
||||
f.write(f"{time.strftime('%H:%M:%S')} {t}\n")
|
||||
f.flush()
|
||||
|
||||
boots = 0
|
||||
while True:
|
||||
lost, on_stop = stop_event()
|
||||
cli = await connect(host, tries=300, timeout=5, port=port, on_stop=on_stop)
|
||||
boots += 1
|
||||
info = await cli.device_info()
|
||||
w(
|
||||
f"=== CONNECTED boot {boots} name={info.name} quiet={1 < boots <= quiet + 1}"
|
||||
)
|
||||
if boots > quiet + 1:
|
||||
done = asyncio.Event()
|
||||
|
||||
def on_log(m, done: asyncio.Event = done) -> None:
|
||||
t = log_text(m)
|
||||
w(t)
|
||||
if "REBOOT" in t:
|
||||
done.set()
|
||||
|
||||
cli.subscribe_logs(
|
||||
on_log, log_level=LogLevel.LOG_LEVEL_DEBUG, dump_config=False
|
||||
)
|
||||
try:
|
||||
await asyncio.wait_for(done.wait(), 120)
|
||||
except TimeoutError:
|
||||
w("=== no REBOOT within 120 s")
|
||||
with contextlib.suppress(Exception):
|
||||
await cli.disconnect()
|
||||
if not done.is_set():
|
||||
sys.exit("FAIL: no REBOOT line within 120 s of subscribing")
|
||||
return
|
||||
if boots == 1:
|
||||
# drain any crash record left by the reboot that brought this build up
|
||||
cli.subscribe_logs(
|
||||
lambda m: w("drain " + log_text(m)),
|
||||
log_level=LogLevel.LOG_LEVEL_DEBUG,
|
||||
dump_config=False,
|
||||
)
|
||||
await asyncio.sleep(3)
|
||||
if lost.is_set():
|
||||
w("=== boot 1 rebooted during the drain")
|
||||
sys.exit("FAIL: boot 1 rebooted with the drain subscriber attached")
|
||||
with contextlib.suppress(Exception):
|
||||
await cli.disconnect()
|
||||
lost, on_stop = stop_event()
|
||||
t = time.monotonic()
|
||||
cli = await connect(
|
||||
host, tries=300, timeout=5, port=port, on_stop=on_stop
|
||||
)
|
||||
if (dt := time.monotonic() - t) > RECONNECT_MAX_S:
|
||||
w(f"=== boot 1 reconnect took {dt:.1f} s")
|
||||
sys.exit(
|
||||
f"FAIL: the reconnect after the drain took {dt:.1f} s, boot 1 may have rebooted"
|
||||
)
|
||||
w("=== boot 1 reconnected without a log subscription")
|
||||
# quiet: wait for the device to drop the connection (its reboot)
|
||||
try:
|
||||
await asyncio.wait_for(lost.wait(), REBOOT_WAIT)
|
||||
except TimeoutError:
|
||||
w(f"=== boot {boots}: no reboot within {REBOOT_WAIT:.0f} s")
|
||||
sys.exit(
|
||||
f"FAIL: boot {boots} did not reboot within {REBOOT_WAIT:.0f} s"
|
||||
)
|
||||
w("=== connection lost")
|
||||
await asyncio.sleep(2)
|
||||
|
||||
|
||||
asyncio.run(main(sys.argv[1], int(sys.argv[2]), sys.argv[3], int(sys.argv[4])))
|
||||
@@ -1,20 +0,0 @@
|
||||
# Shared ESP8266 base for the lock load DUTs: reset reason at boot, no Wi-Fi sleep, web_server for the HTTP load.
|
||||
esphome:
|
||||
name: ${name}
|
||||
on_boot:
|
||||
- priority: 800
|
||||
then:
|
||||
- lambda: ESP_LOGI("lock", "BOOT reason=%s info=%s", ESP.getResetReason().c_str(), ESP.getResetInfo().c_str());
|
||||
esp8266:
|
||||
board: ${board}
|
||||
logger:
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
ota:
|
||||
- platform: esphome
|
||||
web_server:
|
||||
port: 80
|
||||
@@ -1,39 +0,0 @@
|
||||
# remote_transmitter and remote_receiver on the same pin (GPIO12), no jumper: one NEC frame every 250 ms, each one
|
||||
# checked by the receiver's edge interrupt. Substitutions: name, board.
|
||||
substitutions:
|
||||
board: d1_mini
|
||||
packages:
|
||||
base: !include base.yaml
|
||||
globals:
|
||||
- {id: sent, type: uint32_t, initial_value: "0"}
|
||||
- {id: rx_ok, type: uint32_t, initial_value: "0"}
|
||||
- {id: rx_bad, type: uint32_t, initial_value: "0"}
|
||||
remote_transmitter:
|
||||
id: irtx
|
||||
pin:
|
||||
number: GPIO12
|
||||
allow_other_uses: true
|
||||
carrier_duty_percent: 100%
|
||||
remote_receiver:
|
||||
pin:
|
||||
number: GPIO12
|
||||
allow_other_uses: true
|
||||
on_nec:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.address == 0x1234 && x.command == (uint16_t) (0x7800 | (id(sent) & 0xFF))) id(rx_ok)++; else id(rx_bad)++;
|
||||
interval:
|
||||
- interval: 250ms
|
||||
then:
|
||||
# The receiver's setup leaves the shared pin as an input; drive it again before each frame
|
||||
- lambda: |-
|
||||
pinMode(12, OUTPUT);
|
||||
id(sent)++;
|
||||
- remote_transmitter.transmit_nec:
|
||||
address: 0x1234
|
||||
command: !lambda return (uint16_t) (0x7800 | (id(sent) & 0xFF));
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGI("lock", "ALIVE up=%u sent=%u rx_ok=%u rx_bad=%u heap=%u", (unsigned) (millis() / 1000),
|
||||
(unsigned) id(sent), (unsigned) id(rx_ok), (unsigned) id(rx_bad), (unsigned) ESP.getFreeHeap());
|
||||
@@ -1,43 +0,0 @@
|
||||
# DS18B20 on GPIO4 with a bus search every ${search_interval}. Set busy_control to "true" to replace the search with
|
||||
# the same busy time and no 1-Wire traffic (the control run). Substitutions: name, board, search_interval, busy_control.
|
||||
substitutions:
|
||||
board: d1_mini
|
||||
search_interval: 100ms
|
||||
busy_control: "false"
|
||||
packages:
|
||||
base: !include base.yaml
|
||||
one_wire:
|
||||
- platform: gpio
|
||||
pin: GPIO4
|
||||
id: owbus
|
||||
globals:
|
||||
- {id: searches, type: uint32_t, initial_value: "0"}
|
||||
- {id: search_bad, type: uint32_t, initial_value: "0"}
|
||||
- {id: reads_ok, type: uint32_t, initial_value: "0"}
|
||||
- {id: reads_nan, type: uint32_t, initial_value: "0"}
|
||||
sensor:
|
||||
- platform: dallas_temp
|
||||
one_wire_id: owbus
|
||||
id: t1
|
||||
name: Temp
|
||||
update_interval: 2s
|
||||
on_raw_value:
|
||||
- lambda: if (std::isnan(x)) id(reads_nan)++; else id(reads_ok)++;
|
||||
interval:
|
||||
- interval: ${search_interval}
|
||||
then:
|
||||
- lambda: |-
|
||||
if (${busy_control}) {
|
||||
delayMicroseconds(13000); // about one search with one sensor answering
|
||||
return;
|
||||
}
|
||||
id(owbus)->search();
|
||||
id(searches)++;
|
||||
if (id(owbus)->get_devices().size() != 1)
|
||||
id(search_bad)++;
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGI("lock", "ALIVE up=%u ok=%u nan=%u searches=%u search_bad=%u heap=%u t=%.2f",
|
||||
(unsigned) (millis() / 1000), (unsigned) id(reads_ok), (unsigned) id(reads_nan),
|
||||
(unsigned) id(searches), (unsigned) id(search_bad), (unsigned) ESP.getFreeHeap(), id(t1).state);
|
||||
@@ -1,47 +0,0 @@
|
||||
#!/bin/bash
|
||||
# run.sh NAME SECONDS PPS: build NAME.yaml (next to this script, or a path) from TREE, flash it over serial, capture
|
||||
# the log for SECONDS plus 160 (boot, up to 120 s for the IP, the load) and run wifi_load.py at PPS packets per second
|
||||
# (0: no load). Prints the boot count, every reset reason and the last ALIVE line. Exit 0: a clean run (exactly one
|
||||
# BOOT line); 1: the run finished and saw resets; 2: setup failed or the run is invalid (no load, capture cut short,
|
||||
# or the sensor or IR loopback never worked).
|
||||
# env: TREE (checkout under test), PORT, SC (path to serial_capture.py), PY (checkout python)
|
||||
D=$(cd "$(dirname "$0")" && pwd); N=${1:?name}; T=${2:?seconds}; P=${3:?pps}
|
||||
W=${TREE:?set TREE}; PORT=${PORT:?set PORT}; SC=${SC:?set SC}; PY=${PY:-$W/venv/bin/python}
|
||||
Y=$N; [ -f "$Y" ] || Y=$D/$N.yaml; Y=$(cd "$(dirname "$Y")" && pwd)/$(basename "$Y"); N=$(basename "$Y" .yaml)
|
||||
O=$D/out-$N; mkdir -p "$O"
|
||||
pkill -f "[s]erial_capture.py $PORT "
|
||||
rm -f "$O/serial.txt" "$O/load.txt"
|
||||
(cd "$W" && PYTHONPATH=$W $PY -m esphome compile "$Y") > "$O/compile.log" 2>&1 || { echo "$N compile failed"; exit 2; }
|
||||
(cd "$W" && PYTHONPATH=$W $PY -m esphome upload "$Y" --device "$PORT") > "$O/upload.log" 2>&1 || { echo "$N upload failed"; exit 2; }
|
||||
$PY "$SC" "$PORT" $((T + 160)) "$O/serial.txt" --reset > "$O/capture.log" 2>&1 &
|
||||
CAP=$!
|
||||
for _ in $(seq 60); do
|
||||
IP=$(LC_ALL=C grep -a -o -E "IP Address: [0-9.]+" "$O/serial.txt" | tail -1 | cut -d' ' -f3)
|
||||
[ -n "$IP" ] && break; sleep 2
|
||||
done
|
||||
if [ "$P" -gt 0 ]; then
|
||||
[ -n "$IP" ] || { kill "$CAP"; echo "$N no IP (check the secrets file)"; exit 2; }
|
||||
python3 "$D/wifi_load.py" "$IP" "$T" "$P" > "$O/load.txt" 2>&1 || { echo "$N INVALID: load failed (see $O/load.txt)"; BAD=1; }
|
||||
else
|
||||
sleep "$T"
|
||||
fi
|
||||
wait "$CAP" || { echo "$N INVALID: capture failed (see $O/capture.log)"; BAD=1; }
|
||||
BOOTS=$(LC_ALL=C grep -a -c 'BOOT reason' "$O/serial.txt")
|
||||
echo "== $N pps=$P boots=$BOOTS"
|
||||
LC_ALL=C grep -a "BOOT reason" "$O/serial.txt" | cut -c1-150
|
||||
LC_ALL=C grep -a "ALIVE" "$O/serial.txt" | tail -1 | cut -c1-200
|
||||
tail -1 "$O/load.txt" 2>/dev/null
|
||||
ALIVE=$(LC_ALL=C grep -a "ALIVE" "$O/serial.txt" | tail -1)
|
||||
# the workload must have run: a sensor answering searches, or decoded IR frames
|
||||
case "$ALIVE" in
|
||||
*" ok=0 "*|*" rx_ok=0 "*|"") echo "$N INVALID: no ALIVE line or the workload did not run"; BAD=1 ;;
|
||||
esac
|
||||
# one-wire: the searches must find the sensor (busy_control runs no searches)
|
||||
S=$(echo "$ALIVE" | sed -n 's/.* searches=\([0-9]*\) search_bad=\([0-9]*\).*/\1 \2/p')
|
||||
if [ -n "$S" ]; then
|
||||
set -- $S
|
||||
[ "$1" -gt 0 ] && [ "$2" -ge "$1" ] && { echo "$N INVALID: no search found the sensor"; BAD=1; }
|
||||
fi
|
||||
# resets are a failure even when they also broke the load or the workload
|
||||
[ "$BOOTS" -gt 1 ] && exit 1
|
||||
[ -z "$BAD" ] && [ "$BOOTS" = 1 ] || exit 2
|
||||
@@ -1,60 +0,0 @@
|
||||
"""Wi-Fi load on an ESP8266 under test: a fixed rate UDP flood to port 9 plus back to back web_server GETs.
|
||||
|
||||
usage: wifi_load.py HOST SECONDS PPS
|
||||
Prints the counts every minute and a final "done" line.
|
||||
"""
|
||||
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
host, secs, pps = sys.argv[1], float(sys.argv[2]), int(sys.argv[3])
|
||||
end = time.monotonic() + secs
|
||||
stats = {"udp": 0, "udp_err": 0, "http_ok": 0, "http_err": 0, "http_gap_s": 0}
|
||||
|
||||
|
||||
last_ok = [time.monotonic()]
|
||||
|
||||
|
||||
def http_load() -> None:
|
||||
while time.monotonic() < end:
|
||||
try:
|
||||
with urllib.request.urlopen(f"http://{host}/", timeout=5) as r:
|
||||
r.read()
|
||||
stats["http_ok"] += 1
|
||||
now = time.monotonic()
|
||||
stats["http_gap_s"] = max(stats["http_gap_s"], round(now - last_ok[0]))
|
||||
last_ok[0] = now
|
||||
except Exception: # noqa: BLE001 any failure counts; the thread must not die
|
||||
stats["http_err"] += 1
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
threading.Thread(target=http_load, daemon=True).start()
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
payload = b"x" * 512
|
||||
nxt = last = time.monotonic()
|
||||
while (now := time.monotonic()) < end:
|
||||
try:
|
||||
s.sendto(payload, (host, 9))
|
||||
stats["udp"] += 1
|
||||
except OSError: # mostly ENOBUFS when the host outruns the network
|
||||
stats["udp_err"] += 1
|
||||
time.sleep(0.01)
|
||||
nxt += 1 / pps
|
||||
if (d := nxt - time.monotonic()) > 0:
|
||||
time.sleep(d)
|
||||
if now - last > 60:
|
||||
last = now
|
||||
print(time.strftime("%H:%M:%S"), stats, flush=True)
|
||||
stats["http_gap_s"] = max(stats["http_gap_s"], round(time.monotonic() - last_ok[0]))
|
||||
print("done", stats, flush=True)
|
||||
if (
|
||||
stats["http_ok"] == 0
|
||||
or stats["http_gap_s"] > 60 # the device stopped answering for over a minute
|
||||
or stats["http_err"] > stats["http_ok"]
|
||||
or stats["udp"] < secs * pps / 2
|
||||
):
|
||||
sys.exit("the load did not reach the device; the run is invalid")
|
||||
@@ -1,17 +0,0 @@
|
||||
substitutions:
|
||||
name: en32p
|
||||
peer: en66p
|
||||
peer_mac: AA:BB:CC:00:00:66 # the D1 mini peer's station MAC
|
||||
my_addr: "0x0032"
|
||||
peer_addr: "0x0066"
|
||||
raw_max: "1470"
|
||||
payload_max: "1470"
|
||||
sizes: "16, 100, 249, 250, 251, 600, 1470"
|
||||
long_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
chaos: "true"
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
packages:
|
||||
link: !include enlink.yaml
|
||||
@@ -1,15 +0,0 @@
|
||||
substitutions:
|
||||
name: en66p
|
||||
peer: en32p
|
||||
peer_mac: AA:BB:CC:00:00:32 # the ESP32 peer's station MAC
|
||||
my_addr: "0x0066"
|
||||
peer_addr: "0x0032"
|
||||
raw_max: "250"
|
||||
payload_max: "250"
|
||||
sizes: "16, 100, 249, 250"
|
||||
long_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
chaos: "false"
|
||||
esp8266:
|
||||
board: d1_mini
|
||||
packages:
|
||||
link: !include enlink.yaml
|
||||
@@ -1,117 +0,0 @@
|
||||
"""encheck.py LOG [LOG...]: summarise an entity_transport link test capture.
|
||||
|
||||
Reads ETRX <link> <field>=<value>, SESS <link> 0/1, STAT, CHAOS and warning lines; ETRX lines it cannot parse are
|
||||
counted. Per link: cnt updates, gaps in the received count (a gap is a step other than +1), values never sent (flt not
|
||||
equal to the sender's formula), binary transitions, long sensor updates, session edges. Prints one block per log.
|
||||
Exits 1 on a reboot or crash during a capture (more than one boot), a value never sent, a checked stream with bad
|
||||
payloads, an ETRX line it cannot parse (other than the cut last line), no STAT line, or no counter value on any link.
|
||||
"""
|
||||
|
||||
import collections
|
||||
import pathlib
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
def f32(v):
|
||||
return struct.unpack("<f", struct.pack("<f", v))[0]
|
||||
|
||||
|
||||
def expect(t): # 12345.678f + t * 0.001f - (t % 7) * 1000.5f in single precision
|
||||
return f32(f32(f32(12345.678) + f32(f32(t) * f32(0.001))) - f32((t % 7) * 1000.5))
|
||||
|
||||
|
||||
VALID = {f"{expect(t):.3f}" for t in range(20000)}
|
||||
TS = re.compile(r"^\[(\d\d):(\d\d):(\d\d)")
|
||||
|
||||
|
||||
def secs(line):
|
||||
m = TS.match(line)
|
||||
return int(m[1]) * 3600 + int(m[2]) * 60 + int(m[3]) if m else None
|
||||
|
||||
|
||||
CRASH = re.compile(r"Guru Meditation|Exception \(\d+\)|abort\(\)|panic|Backtrace:")
|
||||
failures = []
|
||||
for path in sys.argv[1:]:
|
||||
crashes = 0
|
||||
links = collections.defaultdict(
|
||||
lambda: {"cnt": [], "flt": [], "bin": [], "long": [], "sess": []}
|
||||
)
|
||||
warns = collections.Counter()
|
||||
stats, chaos, boots, unparsed = [], [], 0, 0
|
||||
with pathlib.Path(path).open(encoding="utf-8", errors="replace") as fh:
|
||||
for line in fh:
|
||||
t = secs(line)
|
||||
if "ETRX" in line:
|
||||
m = re.search(r"ETRX (\S+) (\w+)=(\S+)", line)
|
||||
if m:
|
||||
links[m[1]][m[2]].append((t, m[3]))
|
||||
elif "[partial]" not in line: # the capture cuts a line at its end
|
||||
unparsed += 1
|
||||
elif "SESS" in line:
|
||||
m = re.search(r"SESS (\S+) (\d)", line)
|
||||
if m:
|
||||
links[m[1]]["sess"].append((t, m[2]))
|
||||
elif "STAT" in line:
|
||||
stats.append(line.strip())
|
||||
elif "CHAOS" in line:
|
||||
chaos.append((line[1:9], line.strip().split("CHAOS")[1]))
|
||||
if "Running through setup" in line:
|
||||
boots += 1
|
||||
if CRASH.search(line):
|
||||
crashes += 1
|
||||
if re.search(r"\]\[[WE]\]", line):
|
||||
msg = re.sub(r"^\[[^\]]*\]", "", line.strip())
|
||||
msg = re.sub(r"\d+", "N", msg)
|
||||
warns[msg] += 1
|
||||
print(f"== {path} boots={boots} crashes={crashes} unparsed_etrx={unparsed}")
|
||||
if boots > 1 or crashes:
|
||||
failures.append(f"{path}: {boots} boots, {crashes} crash lines")
|
||||
if unparsed:
|
||||
failures.append(f"{path}: {unparsed} ETRX lines that could not be parsed")
|
||||
if not stats:
|
||||
failures.append(f"{path}: no STAT line")
|
||||
if not any(d["cnt"] for d in links.values()):
|
||||
failures.append(f"{path}: no link received a counter value")
|
||||
for c in chaos:
|
||||
print(" chaos", c)
|
||||
for name, d in sorted(links.items()):
|
||||
tc = [(t, int(float(v))) for t, v in d["cnt"] if v != "nan"]
|
||||
cnts = [c for _, c in tc]
|
||||
gaps = [
|
||||
(tc[i][0], cnts[i - 1], cnts[i])
|
||||
for i in range(1, len(cnts))
|
||||
if cnts[i] not in (cnts[i - 1], cnts[i - 1] + 1)
|
||||
]
|
||||
bad_flt = [v for _, v in d["flt"] if v not in VALID and v != "nan"]
|
||||
bins = [v for _, v in d["bin"]]
|
||||
trans = sum(1 for i in range(1, len(bins)) if bins[i] != bins[i - 1])
|
||||
print(
|
||||
f" {name}: cnt updates={len(cnts)} first={cnts[:1]} last={cnts[-1:]} gaps={len(gaps)} "
|
||||
f"flt={len(d['flt'])} bad_flt={len(bad_flt)} bin_trans={trans} long={len(d['long'])} "
|
||||
f"sess={[s for _, s in d['sess']]}"
|
||||
)
|
||||
for g in gaps[:12]:
|
||||
at = (
|
||||
"?"
|
||||
if g[0] is None
|
||||
else f"{g[0] // 3600:02d}:{g[0] // 60 % 60:02d}:{g[0] % 60:02d}"
|
||||
)
|
||||
print(f" gap at {at}: {g[1]} -> {g[2]}")
|
||||
if bad_flt:
|
||||
print(" bad flt", bad_flt[:5])
|
||||
failures.append(f"{path}: {name} received {len(bad_flt)} values never sent")
|
||||
last = {}
|
||||
for s in stats:
|
||||
body = s[s.find("STAT") :]
|
||||
last[body.split()[1]] = body
|
||||
for body in last.values():
|
||||
print(" " + body)
|
||||
if (m := re.search(r" bad=(\d+)", body)) and int(m[1]):
|
||||
failures.append(f"{path}: {body.split()[1]} bad={m[1]}")
|
||||
for w, n in warns.most_common(15):
|
||||
print(f" W x{n}: {w[:170]}")
|
||||
for f in failures:
|
||||
print("FAIL", f)
|
||||
sys.exit(1 if failures else 0)
|
||||
@@ -1,239 +0,0 @@
|
||||
# ESP-NOW packet_interface link test (esphome#21120), shared part. No Wi-Fi; espnow on a fixed channel.
|
||||
# Links per device:
|
||||
# p2p : peer_address = the other board, xxtea + hdlc reliability + session + fragmentation, entity_transport et_p2p
|
||||
# bc : broadcast, addressing (address ${my_addr}) with two ports:
|
||||
# bc_rel : destination ${peer_addr}, xxtea with rolling code + reliability + session + fragmentation (et_bcrel)
|
||||
# bc_all : destination broadcast, no layers (et_bcall, small dictionary)
|
||||
# raw : broadcast, no layers, max_packet_size ${raw_max}; size sweep with magic, seq and checked payload
|
||||
# substitutions: name, peer (peer's name), peer_mac, my_addr, peer_addr, raw_max, payload_max, long_id
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes:
|
||||
- entest.hpp
|
||||
on_boot:
|
||||
- priority: 600
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::RAW.listen(id(raw));
|
||||
entest::P2P.listen(id(p2p)->top());
|
||||
entest::BCR.listen(id(bc_rel)->top());
|
||||
- priority: -100
|
||||
then:
|
||||
- delay: 20s
|
||||
- lambda: |-
|
||||
bool r = entest::RAW.send(id(raw), ${raw_max} + 1);
|
||||
ESP_LOGI("raw", "OVERSEND %u byte send returned %d", (unsigned) (${raw_max} + 1), r);
|
||||
- if:
|
||||
condition:
|
||||
lambda: return ${chaos};
|
||||
then:
|
||||
- delay: 60s
|
||||
- logger.log: "CHAOS short start"
|
||||
- espnow.set_channel: 6
|
||||
- delay: 3s
|
||||
- espnow.set_channel: 1
|
||||
- logger.log: "CHAOS short end"
|
||||
- delay: 80s
|
||||
- logger.log: "CHAOS long start"
|
||||
- espnow.set_channel: 6
|
||||
- delay: 15s
|
||||
- espnow.set_channel: 1
|
||||
- logger.log: "CHAOS long end"
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
baud_rate: 115200
|
||||
|
||||
espnow:
|
||||
id: espnow_c
|
||||
channel: 1
|
||||
max_payload_size: ${payload_max}
|
||||
|
||||
globals:
|
||||
- {id: counter, type: int, initial_value: "0"}
|
||||
|
||||
packet_interface:
|
||||
- platform: espnow
|
||||
id: p2p
|
||||
peer_address: ${peer_mac}
|
||||
encryption: p2p key 21120
|
||||
reliability:
|
||||
timeout: 300ms
|
||||
max_retries: 20
|
||||
max_queue_length: 6
|
||||
session:
|
||||
keep_alive: 2s
|
||||
timeout: 8s
|
||||
binary_sensor:
|
||||
id: p2p_sess
|
||||
on_state:
|
||||
- logger.log: {format: "SESS p2p %d", args: ["x ? 1 : 0"]}
|
||||
fragmentation:
|
||||
max_packet_size: 1024
|
||||
- platform: espnow
|
||||
id: bc
|
||||
addressing:
|
||||
address: ${my_addr}
|
||||
peers:
|
||||
- id: bc_rel
|
||||
destination: ${peer_addr}
|
||||
encryption:
|
||||
key: bc key 21120
|
||||
rolling_code_enable: true
|
||||
reliability:
|
||||
timeout: 300ms
|
||||
max_retries: 20
|
||||
max_queue_length: 6
|
||||
session:
|
||||
keep_alive: 2s
|
||||
timeout: 8s
|
||||
binary_sensor:
|
||||
id: bcrel_sess
|
||||
on_state:
|
||||
- logger.log: {format: "SESS bc_rel %d", args: ["x ? 1 : 0"]}
|
||||
fragmentation:
|
||||
max_packet_size: 1024
|
||||
- id: bc_all
|
||||
destination: broadcast
|
||||
- platform: espnow
|
||||
id: raw
|
||||
max_packet_size: ${raw_max}
|
||||
# hears every broadcast; larger ones must be dropped with a warning at most once a minute
|
||||
- platform: espnow
|
||||
id: raw_small
|
||||
max_packet_size: 100
|
||||
|
||||
interval:
|
||||
- interval: 1s
|
||||
then:
|
||||
- lambda: id(counter)++;
|
||||
- interval: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
static const uint16_t SIZES[] = {${sizes}};
|
||||
static const uint16_t RSIZES[] = {12, 200, 600};
|
||||
entest::RAW.send(id(raw), SIZES[entest::RAW.idx++ % (sizeof(SIZES) / sizeof(SIZES[0]))]);
|
||||
entest::P2P.send(id(p2p)->top(), RSIZES[entest::P2P.idx++ % 3]);
|
||||
entest::BCR.send(id(bc_rel)->top(), RSIZES[entest::BCR.idx++ % 3]);
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::RAW.log();
|
||||
entest::P2P.log();
|
||||
entest::BCR.log();
|
||||
ESP_LOGI("stat", "STAT cnt=%d sess=%d/%d", id(counter), id(p2p_sess).state, id(bcrel_sess).state);
|
||||
|
||||
sensor:
|
||||
- platform: template
|
||||
id: cnt
|
||||
lambda: return id(counter);
|
||||
update_interval: 1s
|
||||
- platform: template
|
||||
id: flt
|
||||
lambda: |-
|
||||
int t = id(counter);
|
||||
return 12345.678f + t * 0.001f - (t % 7) * 1000.5f;
|
||||
update_interval: 1s
|
||||
accuracy_decimals: 3
|
||||
- platform: template
|
||||
id: longa
|
||||
lambda: return id(counter) * 0.5f;
|
||||
update_interval: 5s
|
||||
# p2p
|
||||
- platform: entity_transport
|
||||
id: rx1
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX p2p cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx2
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX p2p flt=%.3f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx3
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: ${long_id}8
|
||||
on_value: [logger.log: {format: "ETRX p2p long=%.1f", args: [x]}]
|
||||
# bc_rel
|
||||
- platform: entity_transport
|
||||
id: rx4
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX bcrel cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx5
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX bcrel flt=%.3f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx6
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: ${long_id}8
|
||||
on_value: [logger.log: {format: "ETRX bcrel long=%.1f", args: [x]}]
|
||||
# bc_all
|
||||
- platform: entity_transport
|
||||
id: rx7
|
||||
entity_transport_id: et_bcall
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX bcall cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx8
|
||||
entity_transport_id: et_bcall
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX bcall flt=%.3f", args: [x]}]
|
||||
|
||||
binary_sensor:
|
||||
- platform: template
|
||||
id: bin
|
||||
lambda: return (id(counter) / 3) % 2;
|
||||
- platform: entity_transport
|
||||
id: rx9
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX p2p bin=%d", args: ["x ? 1 : 0"]}]
|
||||
- platform: entity_transport
|
||||
id: rx10
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX bcrel bin=%d", args: ["x ? 1 : 0"]}]
|
||||
- platform: entity_transport
|
||||
id: rx11
|
||||
entity_transport_id: et_bcall
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX bcall bin=%d", args: ["x ? 1 : 0"]}]
|
||||
|
||||
entity_transport:
|
||||
- id: et_p2p
|
||||
packet_interface: p2p
|
||||
sensors: &big_sensors
|
||||
- cnt
|
||||
- flt
|
||||
- {id: longa, broadcast_id: "${long_id}1"}
|
||||
- {id: longa, broadcast_id: "${long_id}2"}
|
||||
- {id: longa, broadcast_id: "${long_id}3"}
|
||||
- {id: longa, broadcast_id: "${long_id}4"}
|
||||
- {id: longa, broadcast_id: "${long_id}5"}
|
||||
- {id: longa, broadcast_id: "${long_id}6"}
|
||||
- {id: longa, broadcast_id: "${long_id}7"}
|
||||
- {id: longa, broadcast_id: "${long_id}8"}
|
||||
binary_sensors: [bin]
|
||||
- id: et_bcrel
|
||||
packet_interface: bc_rel
|
||||
sensors: *big_sensors
|
||||
binary_sensors: [bin]
|
||||
- id: et_bcall
|
||||
packet_interface: bc_all
|
||||
sensors: [cnt, flt]
|
||||
binary_sensors: [bin]
|
||||
@@ -1,99 +0,0 @@
|
||||
#pragma once
|
||||
// Checked packet streams for the packet_interface link tests (esphome#21120).
|
||||
// Packet: magic (2) | seq (2, LE) | sent size (2, LE) | bytes (seq + i). A reliable stream starts with 0x1E so
|
||||
// entity_transport on the same stack drops it as an unknown packet type.
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/packet_interface/packet_interface.h"
|
||||
|
||||
namespace entest {
|
||||
using esphome::packet_interface::PacketBuffer;
|
||||
using esphome::packet_interface::PacketInterface;
|
||||
using esphome::packet_interface::PacketMetaData;
|
||||
|
||||
struct Stream {
|
||||
const char *name;
|
||||
uint8_t m0, m1;
|
||||
uint32_t tx{0}, ref{0}, rx{0}, ok{0}, bad{0}, gap{0}, dup{0}, trunc{0}, foreign{0}, big{0}, maxsz{0};
|
||||
int32_t last{-1};
|
||||
uint16_t seq{0};
|
||||
uint32_t idx{0};
|
||||
|
||||
Stream(const char *n, uint8_t a, uint8_t b) : name(n), m0(a), m1(b) {}
|
||||
|
||||
void listen(PacketInterface *link) {
|
||||
link->add_packet_interface_listener([this](const PacketBuffer &d, const PacketMetaData &) { this->on_rx(d); });
|
||||
}
|
||||
void on_rx(const PacketBuffer &d) {
|
||||
static uint8_t buf[1600];
|
||||
size_t n = d.size();
|
||||
if (n > sizeof(buf))
|
||||
n = sizeof(buf);
|
||||
d.copy_to(buf, n);
|
||||
this->rx++;
|
||||
if (n < 6 || buf[0] != this->m0 || buf[1] != this->m1) {
|
||||
this->foreign++;
|
||||
return;
|
||||
}
|
||||
uint16_t seq = buf[2] | (buf[3] << 8);
|
||||
uint16_t sent = buf[4] | (buf[5] << 8);
|
||||
if (n != sent) {
|
||||
this->trunc++;
|
||||
ESP_LOGW("entest", "%s size %u received as %u (seq %u)", this->name, sent, (unsigned) n, seq);
|
||||
}
|
||||
for (size_t i = 6; i < n; i++)
|
||||
if (buf[i] != (uint8_t) (seq + i)) {
|
||||
this->bad++;
|
||||
ESP_LOGW("entest", "%s bad payload seq=%u size=%u", this->name, seq, (unsigned) n);
|
||||
return;
|
||||
}
|
||||
this->ok++;
|
||||
if (n > 250)
|
||||
this->big++;
|
||||
if (n > this->maxsz)
|
||||
this->maxsz = n;
|
||||
if (this->last >= 0) {
|
||||
if (seq == (uint16_t) this->last) {
|
||||
this->dup++;
|
||||
return;
|
||||
}
|
||||
if (seq != (uint16_t) (this->last + 1)) {
|
||||
this->gap++;
|
||||
ESP_LOGI("entest", "%s seq gap %d -> %u", this->name, (int) this->last, seq);
|
||||
}
|
||||
}
|
||||
this->last = seq;
|
||||
}
|
||||
bool send(PacketInterface *link, uint16_t size) {
|
||||
static uint8_t buf[1600];
|
||||
buf[0] = this->m0;
|
||||
buf[1] = this->m1;
|
||||
buf[2] = this->seq;
|
||||
buf[3] = this->seq >> 8;
|
||||
buf[4] = size;
|
||||
buf[5] = size >> 8;
|
||||
for (size_t i = 6; i < size; i++)
|
||||
buf[i] = (uint8_t) (this->seq + i);
|
||||
if (link->send_to_interface(PacketBuffer(buf, size), {})) {
|
||||
this->seq++;
|
||||
this->tx++;
|
||||
return true;
|
||||
}
|
||||
this->ref++;
|
||||
return false;
|
||||
}
|
||||
void log() {
|
||||
ESP_LOGI("stat", "STAT %s tx=%u ref=%u rx=%u ok=%u bad=%u gap=%u dup=%u trunc=%u big=%u maxsz=%u foreign=%u",
|
||||
this->name, this->tx, this->ref, this->rx, this->ok, this->bad, this->gap, this->dup, this->trunc,
|
||||
this->big, this->maxsz, this->foreign);
|
||||
}
|
||||
};
|
||||
|
||||
inline Stream RAW("raw", 0xA5, 0x5A);
|
||||
inline Stream P2P("p2p_seq", 0x1E, 0x5A);
|
||||
inline Stream BCR("bcrel_seq", 0x1E, 0x5B);
|
||||
// UDP only: the point_to_point false and true links
|
||||
inline Stream P2PF("p2pf_raw", 0xA5, 0x5B);
|
||||
inline Stream P2PT("p2pt_raw", 0xA5, 0x5C);
|
||||
} // namespace entest
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
# pairrun.sh PREFIX E32V D1V [SECS] [RUN]: flash <PREFIX>32<E32V>.yaml (ESP32) and <PREFIX>66<D1V>.yaml (D1 mini), each
|
||||
# from the tree of its build letter (p = PR_TREE, anything else = BASE_TREE), capture both boards SECS seconds (default
|
||||
# 150) from a reset into <PREFIX>-<E32V><D1V>[-RUN]-<board>.log and print a summary per board. Exits 1 when a capture
|
||||
# fails, a board logs no STAT line, reboots during the capture or logs a crash.
|
||||
# PREFIX ur (urlink.yaml): last p2pf STAT and on_receive lines, sendto error count. PREFIX rg (rglink.yaml): last
|
||||
# STAT rg line, packet_transport status, warning and error count. Make the files from ur32.example.yaml or
|
||||
# rg32.example.yaml (the 66 file is the same with esp8266 and the peer swapped).
|
||||
# env: PR_TREE, BASE_TREE, PORT_D1, PORT_E32, PY
|
||||
D=$(cd "$(dirname "$0")" && pwd); S=$(dirname "$D"); cd "$D" || exit 1
|
||||
X=${1:?prefix ur or rg}; E=${2:?esp32 build}; B=${3:?d1 build}; SECS=${4:-150}; L=$X-$E$B${5:+-$5}
|
||||
tree() { if [ "$1" = p ]; then echo "${PR_TREE:?set PR_TREE}"; else echo "${BASE_TREE:?set BASE_TREE}"; fi; }
|
||||
P1=${PORT_D1:?set PORT_D1}; P2=${PORT_E32:?set PORT_E32}; PY=${PY:-$(tree p)/venv/bin/python}
|
||||
TREE=$(tree "$B") bash "$S/pio_build.sh" upload "${X}66$B" "${X}66$B.yaml" "$P1" || exit 1
|
||||
TREE=$(tree "$E") bash "$S/pio_build.sh" upload "${X}32$E" "${X}32$E.yaml" "$P2" || exit 1
|
||||
$PY "$S/serial_capture.py" "$P1" "$SECS" "$L-d1.log" --reset > "$L-d1.err" 2>&1 &
|
||||
C1=$!
|
||||
$PY "$S/serial_capture.py" "$P2" "$SECS" "$L-e32.log" --reset > "$L-e32.err" 2>&1 &
|
||||
C2=$!
|
||||
OK=1
|
||||
wait $C1 || { echo "capture failed on the D1 mini:"; cat "$L-d1.err"; OK=0; }
|
||||
wait $C2 || { echo "capture failed on the ESP32:"; cat "$L-e32.err"; OK=0; }
|
||||
[ $OK = 1 ] || exit 1
|
||||
MISSING=0
|
||||
CRASH_RE="Guru Meditation|Exception \\([0-9]+\\)|abort\\(\\)|panic|Backtrace:"
|
||||
for b in e32 d1; do
|
||||
F=$L-$b.log
|
||||
if [ "$X" = rg ]; then STAT='STAT rg'; else STAT='STAT p2pf'; fi
|
||||
grep -a -q "$STAT" "$F" || { echo "e32=$E d1=$B $b: NO STAT line in $F"; MISSING=1; continue; }
|
||||
BOOTS=$(grep -a -c "Running through setup" "$F"); CRASH=$(grep -a -c -E "$CRASH_RE" "$F")
|
||||
[ "$BOOTS" -le 1 ] && [ "$CRASH" = 0 ] || { echo "e32=$E d1=$B $b: $BOOTS boots, $CRASH crash lines"; MISSING=1; }
|
||||
if [ "$X" = rg ]; then
|
||||
echo "e32=$E d1=$B $b: $(grep -a 'STAT rg' "$F" | tail -1 | sed 's/.*STAT rg //')" \
|
||||
"status=$(grep -a PTSTATUS "$F" | awk '{print $NF}' | tr -d '\n') W=$(grep -a -c '\[W\]\|\[E\]' "$F")"
|
||||
else
|
||||
echo "e32=$E d1=$B $b: $(grep -a 'STAT p2pf' "$F" | tail -1 | sed 's/.*STAT //')" \
|
||||
"$(grep -a 'on_receive' "$F" | tail -1 | sed 's/.*STAT //') senderr=$(grep -a -c 'sendto' "$F")"
|
||||
fi
|
||||
done
|
||||
exit $MISSING
|
||||
@@ -1,15 +0,0 @@
|
||||
substitutions:
|
||||
name: rg32p
|
||||
peer_p: rg66p
|
||||
peer_b: rg66b
|
||||
peer_ip: 192.0.2.66 # the D1 mini peer's address
|
||||
peer_mac: AA:BB:CC:00:00:66 # the D1 mini peer's station MAC
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
packages:
|
||||
link: !include rglink.yaml
|
||||
espnow:
|
||||
on_broadcast:
|
||||
- lambda: id(e_bcb)++;
|
||||
@@ -1,129 +0,0 @@
|
||||
# Regression image for existing users (esphome#21120): packet_transport over UDP (multicast, xxtea, rolling code,
|
||||
# ping-pong), a plain udp listener with on_receive and udp.write to the peer, plain espnow send/broadcast actions with
|
||||
# on_receive/on_broadcast/on_sent/on_error, and packet_transport over espnow. Remote entities are declared for both
|
||||
# the base and the PR name of the peer, so one image serves all four pairings.
|
||||
# substitutions: name, peer_p, peer_b, peer_ip, peer_mac
|
||||
esphome:
|
||||
name: ${name}
|
||||
logger:
|
||||
level: DEBUG
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
globals:
|
||||
- {id: counter, type: uint32_t, initial_value: "0"}
|
||||
- {id: u_rx, type: uint32_t, initial_value: "0"}
|
||||
- {id: u_bad, type: uint32_t, initial_value: "0"}
|
||||
- {id: u_gap, type: uint32_t, initial_value: "0"}
|
||||
- {id: u_last, type: int32_t, initial_value: "-1"}
|
||||
- {id: e_rx, type: uint32_t, initial_value: "0"}
|
||||
- {id: e_brx, type: uint32_t, initial_value: "0"}
|
||||
- {id: e_gap, type: uint32_t, initial_value: "0"}
|
||||
- {id: e_last, type: int32_t, initial_value: "-1"}
|
||||
- {id: e_bcb, type: uint32_t, initial_value: "0"}
|
||||
- {id: e_unk, type: uint32_t, initial_value: "0"}
|
||||
- {id: e_sent, type: uint32_t, initial_value: "0"}
|
||||
- {id: e_err, type: uint32_t, initial_value: "0"}
|
||||
- {id: pt_u, type: uint32_t, initial_value: "0"}
|
||||
- {id: pt_e, type: uint32_t, initial_value: "0"}
|
||||
udp:
|
||||
- id: udp_pt
|
||||
port: 21130
|
||||
listen_address: 239.0.60.53
|
||||
addresses: ["239.0.60.53"]
|
||||
- id: udp_plain
|
||||
port: 21131
|
||||
addresses: ["${peer_ip}"]
|
||||
on_receive:
|
||||
- lambda: |-
|
||||
id(u_rx)++;
|
||||
if (data.size() != 8 || data[0] != 'U') { id(u_bad)++; return; }
|
||||
int32_t seq = data[1] | (data[2] << 8) | (data[3] << 16);
|
||||
if (id(u_last) >= 0 && seq != id(u_last) + 1) id(u_gap)++;
|
||||
id(u_last) = seq;
|
||||
espnow:
|
||||
auto_add_peer: false
|
||||
peers: ["${peer_mac}"]
|
||||
on_receive:
|
||||
- address: ${peer_mac}
|
||||
then:
|
||||
- lambda: |-
|
||||
if (size >= 4 && data[0] == 'S') {
|
||||
id(e_rx)++;
|
||||
int32_t seq = data[1] | (data[2] << 8) | (data[3] << 16);
|
||||
if (id(e_last) >= 0 && seq != id(e_last) + 1) id(e_gap)++;
|
||||
id(e_last) = seq;
|
||||
} else if (size >= 4 && data[0] == 'B') {
|
||||
id(e_brx)++;
|
||||
}
|
||||
on_unknown_peer:
|
||||
- lambda: id(e_unk)++;
|
||||
packet_transport:
|
||||
- platform: udp
|
||||
id: pt_udp
|
||||
udp_id: udp_pt
|
||||
update_interval: 5s
|
||||
encryption: rg udp key
|
||||
rolling_code_enable: true
|
||||
ping_pong_enable: true
|
||||
sensors: [cnt]
|
||||
binary_sensors: [bin]
|
||||
providers:
|
||||
- {name: "${peer_p}", encryption: rg udp key}
|
||||
- {name: "${peer_b}", encryption: rg udp key}
|
||||
- platform: espnow
|
||||
id: pt_espnow
|
||||
peer_address: FF:FF:FF:FF:FF:FF
|
||||
update_interval: 5s
|
||||
encryption: {key: rg espnow key}
|
||||
sensors: [cnt]
|
||||
binary_sensors: [bin]
|
||||
providers:
|
||||
- {name: "${peer_p}", encryption: {key: rg espnow key}}
|
||||
- {name: "${peer_b}", encryption: {key: rg espnow key}}
|
||||
interval:
|
||||
- interval: 1s
|
||||
then:
|
||||
- lambda: id(counter)++;
|
||||
- espnow.send:
|
||||
address: ${peer_mac}
|
||||
data: !lambda |-
|
||||
uint32_t c = id(counter);
|
||||
return std::vector<uint8_t>{'S', (uint8_t) c, (uint8_t) (c >> 8), (uint8_t) (c >> 16)};
|
||||
wait_for_sent: true
|
||||
continue_on_error: true
|
||||
on_sent: [lambda: id(e_sent)++;]
|
||||
on_error: [lambda: id(e_err)++;]
|
||||
- espnow.broadcast:
|
||||
data: !lambda |-
|
||||
uint32_t c = id(counter);
|
||||
return std::vector<uint8_t>{'B', (uint8_t) c, (uint8_t) (c >> 8), (uint8_t) (c >> 16)};
|
||||
- udp.write:
|
||||
id: udp_plain
|
||||
data: !lambda |-
|
||||
uint32_t c = id(counter);
|
||||
return std::vector<uint8_t>{'U', (uint8_t) c, (uint8_t) (c >> 8), (uint8_t) (c >> 16), 1, 2, 3, 4};
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGI("stat", "STAT rg cnt=%u udp rx=%u bad=%u gap=%u | espnow rx=%u gap=%u brx=%u onbcast=%u unknown=%u sent=%u err=%u | pt udp=%u espnow=%u",
|
||||
id(counter), id(u_rx), id(u_bad), id(u_gap), id(e_rx), id(e_gap), id(e_brx), id(e_bcb), id(e_unk),
|
||||
id(e_sent), id(e_err), id(pt_u), id(pt_e));
|
||||
sensor:
|
||||
- platform: template
|
||||
id: cnt
|
||||
lambda: return id(counter);
|
||||
update_interval: 1s
|
||||
- {platform: packet_transport, id: rpu_p, transport_id: pt_udp, provider: "${peer_p}", remote_id: cnt, on_value: [lambda: 'id(pt_u)++; ESP_LOGD("main", "PTRX udp cnt=%.0f", x);']}
|
||||
- {platform: packet_transport, id: rpu_b, transport_id: pt_udp, provider: "${peer_b}", remote_id: cnt, on_value: [lambda: 'id(pt_u)++; ESP_LOGD("main", "PTRX udp cnt=%.0f", x);']}
|
||||
- {platform: packet_transport, id: rpe_p, transport_id: pt_espnow, provider: "${peer_p}", remote_id: cnt, on_value: [lambda: 'id(pt_e)++; ESP_LOGD("main", "PTRX espnow cnt=%.0f", x);']}
|
||||
- {platform: packet_transport, id: rpe_b, transport_id: pt_espnow, provider: "${peer_b}", remote_id: cnt, on_value: [lambda: 'id(pt_e)++; ESP_LOGD("main", "PTRX espnow cnt=%.0f", x);']}
|
||||
binary_sensor:
|
||||
- platform: template
|
||||
id: bin
|
||||
lambda: return (id(counter) / 3) % 2;
|
||||
- {platform: packet_transport, id: rbu_p, transport_id: pt_udp, provider: "${peer_p}", remote_id: bin}
|
||||
- {platform: packet_transport, id: rbu_b, transport_id: pt_udp, provider: "${peer_b}", remote_id: bin}
|
||||
- {platform: packet_transport, id: stu_p, transport_id: pt_udp, provider: "${peer_p}", type: status, on_state: [logger.log: {format: "PTSTATUS udp %d", args: ["x ? 1 : 0"]}]}
|
||||
- {platform: packet_transport, id: stu_b, transport_id: pt_udp, provider: "${peer_b}", type: status, on_state: [logger.log: {format: "PTSTATUS udp %d", args: ["x ? 1 : 0"]}]}
|
||||
@@ -1,18 +0,0 @@
|
||||
substitutions:
|
||||
name: ud32p
|
||||
peer: ud66p
|
||||
peer_ip: 192.0.2.66 # the D1 mini peer's address
|
||||
host_ip: 192.0.2.10 # the computer running udpraw.py
|
||||
bcast_ip: 192.0.2.255 # the subnet broadcast address
|
||||
my_addr: "0x0032"
|
||||
peer_addr: "0x0066"
|
||||
stream_interval: 2s
|
||||
rel_timeout: 1s
|
||||
tick: 5s
|
||||
long_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
packages:
|
||||
link: !include udplink.yaml
|
||||
@@ -1,287 +0,0 @@
|
||||
# UDP packet_interface point to point test (esphome#21120), shared part. Joins Wi-Fi; logs on serial.
|
||||
# u1 p2p : one unicast address (the peer) -> point to point; xxtea + reliability + session + fragmentation
|
||||
# u2 bc : the subnet broadcast address (ends in .255) -> addressing; bc_rel (rolling code) and bc_all ports
|
||||
# u3 mc : multicast -> addressing, destination broadcast
|
||||
# u4 multi: the peer and the test host -> several addresses -> addressing, destination broadcast
|
||||
# u5 p2pf : the peer, point_to_point: false -> accepts every sender, raw stream
|
||||
# u6 p2pt : the subnet broadcast address, point_to_point: true -> only from that address, so the peer is dropped
|
||||
# substitutions: name, peer, peer_ip, host_ip, bcast_ip, my_addr, peer_addr, long_id
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes:
|
||||
- entest.hpp
|
||||
on_boot:
|
||||
- priority: 600
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::P2P.listen(id(p2p)->top());
|
||||
entest::BCR.listen(id(bc_rel)->top());
|
||||
entest::P2PF.listen(id(p2pf));
|
||||
entest::P2PT.listen(id(p2pt));
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
baud_rate: 115200
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
on_connect:
|
||||
- lambda: |-
|
||||
char b[esphome::network::IP_ADDRESS_BUFFER_SIZE];
|
||||
ESP_LOGI("main", "WIFI IP %s", esphome::network::get_ip_addresses()[0].str_to(b));
|
||||
|
||||
globals:
|
||||
- {id: counter, type: int, initial_value: "0"}
|
||||
|
||||
udp:
|
||||
- {id: u1, port: 21121, addresses: ["${peer_ip}"]}
|
||||
- {id: u2, port: 21122, addresses: ["${bcast_ip}"]}
|
||||
- {id: u3, port: 21123, addresses: ["239.0.60.53"], listen_address: 239.0.60.53}
|
||||
- {id: u4, port: 21124, addresses: ["${peer_ip}", "${host_ip}"]}
|
||||
- {id: u5, port: 21125, addresses: ["${peer_ip}"]}
|
||||
- {id: u6, port: 21126, addresses: ["${bcast_ip}"]}
|
||||
|
||||
packet_interface:
|
||||
- platform: udp
|
||||
id: p2p
|
||||
udp_id: u1
|
||||
encryption: p2p key 21120
|
||||
reliability:
|
||||
max_queue_length: 6
|
||||
timeout: ${rel_timeout}
|
||||
session:
|
||||
keep_alive: 2s
|
||||
timeout: 8s
|
||||
binary_sensor:
|
||||
id: p2p_sess
|
||||
on_state: [logger.log: {format: "SESS p2p %d", args: ["x ? 1 : 0"]}]
|
||||
fragmentation:
|
||||
max_packet_size: 1024
|
||||
- platform: udp
|
||||
id: bc
|
||||
udp_id: u2
|
||||
addressing:
|
||||
address: ${my_addr}
|
||||
peers:
|
||||
- id: bc_rel
|
||||
destination: ${peer_addr}
|
||||
encryption:
|
||||
key: bc key 21120
|
||||
rolling_code_enable: true
|
||||
reliability:
|
||||
max_queue_length: 6
|
||||
timeout: ${rel_timeout}
|
||||
session:
|
||||
keep_alive: 2s
|
||||
timeout: 8s
|
||||
binary_sensor:
|
||||
id: bcrel_sess
|
||||
on_state: [logger.log: {format: "SESS bc_rel %d", args: ["x ? 1 : 0"]}]
|
||||
fragmentation:
|
||||
max_packet_size: 1024
|
||||
- id: bc_all
|
||||
destination: broadcast
|
||||
- platform: udp
|
||||
id: mc
|
||||
udp_id: u3
|
||||
addressing:
|
||||
address: ${my_addr}
|
||||
destination: broadcast
|
||||
- platform: udp
|
||||
id: multi
|
||||
udp_id: u4
|
||||
addressing:
|
||||
address: ${my_addr}
|
||||
destination: broadcast
|
||||
- platform: udp
|
||||
id: p2pf
|
||||
udp_id: u5
|
||||
point_to_point: false
|
||||
- platform: udp
|
||||
id: p2pt
|
||||
udp_id: u6
|
||||
point_to_point: true
|
||||
|
||||
interval:
|
||||
- interval: ${tick}
|
||||
then:
|
||||
- lambda: id(counter)++;
|
||||
- interval: ${stream_interval}
|
||||
then:
|
||||
- lambda: |-
|
||||
static const uint16_t RSIZES[] = {12, 200, 600};
|
||||
entest::P2P.send(id(p2p)->top(), RSIZES[entest::P2P.idx++ % 3]);
|
||||
entest::BCR.send(id(bc_rel)->top(), RSIZES[entest::BCR.idx++ % 3]);
|
||||
entest::P2PF.send(id(p2pf), 100);
|
||||
entest::P2PT.send(id(p2pt), 100);
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::P2P.log();
|
||||
entest::BCR.log();
|
||||
entest::P2PF.log();
|
||||
entest::P2PT.log();
|
||||
ESP_LOGI("stat", "STAT cnt=%d sess=%d/%d", id(counter), id(p2p_sess).state, id(bcrel_sess).state);
|
||||
|
||||
sensor:
|
||||
- platform: template
|
||||
id: cnt
|
||||
lambda: return id(counter);
|
||||
update_interval: 1s
|
||||
- platform: template
|
||||
id: flt
|
||||
lambda: |-
|
||||
int t = id(counter);
|
||||
return 12345.678f + t * 0.001f - (t % 7) * 1000.5f;
|
||||
update_interval: 1s
|
||||
accuracy_decimals: 3
|
||||
- platform: template
|
||||
id: longa
|
||||
lambda: return id(counter) * 0.5f;
|
||||
update_interval: 5s
|
||||
# p2p
|
||||
- platform: entity_transport
|
||||
id: rx1
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX p2p cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx2
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX p2p flt=%.3f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx3
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: ${long_id}8
|
||||
on_value: [logger.log: {format: "ETRX p2p long=%.1f", args: [x]}]
|
||||
# bc_rel
|
||||
- platform: entity_transport
|
||||
id: rx4
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX bcrel cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx5
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX bcrel flt=%.3f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx6
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: ${long_id}8
|
||||
on_value: [logger.log: {format: "ETRX bcrel long=%.1f", args: [x]}]
|
||||
# bc_all
|
||||
- platform: entity_transport
|
||||
id: rx7
|
||||
entity_transport_id: et_bcall
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX bcall cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx8
|
||||
entity_transport_id: et_bcall
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX bcall flt=%.3f", args: [x]}]
|
||||
|
||||
- platform: entity_transport
|
||||
id: rx_mc_cnt
|
||||
entity_transport_id: et_mc
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX mc cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx_mc_flt
|
||||
entity_transport_id: et_mc
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX mc flt=%.3f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx_multi_cnt
|
||||
entity_transport_id: et_multi
|
||||
provider: ${peer}
|
||||
remote_id: cnt
|
||||
on_value: [logger.log: {format: "ETRX multi cnt=%.0f", args: [x]}]
|
||||
- platform: entity_transport
|
||||
id: rx_multi_flt
|
||||
entity_transport_id: et_multi
|
||||
provider: ${peer}
|
||||
remote_id: flt
|
||||
on_value: [logger.log: {format: "ETRX multi flt=%.3f", args: [x]}]
|
||||
|
||||
binary_sensor:
|
||||
- platform: template
|
||||
id: bin
|
||||
lambda: return (id(counter) / 3) % 2;
|
||||
- platform: entity_transport
|
||||
id: rx9
|
||||
entity_transport_id: et_p2p
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX p2p bin=%d", args: ["x ? 1 : 0"]}]
|
||||
- platform: entity_transport
|
||||
id: rx10
|
||||
entity_transport_id: et_bcrel
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX bcrel bin=%d", args: ["x ? 1 : 0"]}]
|
||||
- platform: entity_transport
|
||||
id: rx11
|
||||
entity_transport_id: et_bcall
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX bcall bin=%d", args: ["x ? 1 : 0"]}]
|
||||
|
||||
- platform: entity_transport
|
||||
id: rx_mc_bin
|
||||
entity_transport_id: et_mc
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX mc bin=%d", args: ["x ? 1 : 0"]}]
|
||||
- platform: entity_transport
|
||||
id: rx_multi_bin
|
||||
entity_transport_id: et_multi
|
||||
provider: ${peer}
|
||||
remote_id: bin
|
||||
on_state: [logger.log: {format: "ETRX multi bin=%d", args: ["x ? 1 : 0"]}]
|
||||
|
||||
entity_transport:
|
||||
- id: et_p2p
|
||||
packet_interface: p2p
|
||||
sensors: &big_sensors
|
||||
- cnt
|
||||
- flt
|
||||
- {id: longa, broadcast_id: "${long_id}1"}
|
||||
- {id: longa, broadcast_id: "${long_id}2"}
|
||||
- {id: longa, broadcast_id: "${long_id}3"}
|
||||
- {id: longa, broadcast_id: "${long_id}4"}
|
||||
- {id: longa, broadcast_id: "${long_id}5"}
|
||||
- {id: longa, broadcast_id: "${long_id}6"}
|
||||
- {id: longa, broadcast_id: "${long_id}7"}
|
||||
- {id: longa, broadcast_id: "${long_id}8"}
|
||||
binary_sensors: [bin]
|
||||
- id: et_bcrel
|
||||
packet_interface: bc_rel
|
||||
sensors: *big_sensors
|
||||
binary_sensors: [bin]
|
||||
- id: et_bcall
|
||||
packet_interface: bc_all
|
||||
sensors: [cnt, flt]
|
||||
binary_sensors: [bin]
|
||||
- id: et_mc
|
||||
packet_interface: mc
|
||||
sensors: [cnt, flt]
|
||||
binary_sensors: [bin]
|
||||
- id: et_multi
|
||||
packet_interface: multi
|
||||
sensors: [cnt, flt]
|
||||
binary_sensors: [bin]
|
||||
@@ -1,31 +0,0 @@
|
||||
"""udpraw.py SECONDS HOST [HOST...]: every second send a 16 byte datagram from this host to ports 21121, 21125 and
|
||||
21126 of each HOST, and count datagrams arriving on port 21124 (the boards' several-address link). Exits 1 when none
|
||||
arrived."""
|
||||
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
# Not the magic of any entest stream, so a link that accepts third-party datagrams counts these as foreign
|
||||
MAGIC = b"\xa5\x5d"
|
||||
secs, hosts = float(sys.argv[1]), sys.argv[2:]
|
||||
tx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
rx.bind(("0.0.0.0", 21124))
|
||||
rx.settimeout(0.05)
|
||||
end, nxt, sent, got, src = time.time() + secs, 0, 0, 0, {}
|
||||
while time.time() < end:
|
||||
if time.time() >= nxt:
|
||||
for h in hosts:
|
||||
for p in (21121, 21125, 21126):
|
||||
tx.sendto(MAGIC + bytes(14), (h, p))
|
||||
sent += 1
|
||||
nxt = time.time() + 1
|
||||
try:
|
||||
d, a = rx.recvfrom(2048)
|
||||
got += 1
|
||||
src[a[0]] = src.get(a[0], 0) + 1
|
||||
except TimeoutError:
|
||||
pass
|
||||
print(f"sent={sent} received_on_21124={got} by_source={src}")
|
||||
sys.exit(0 if got else "FAIL nothing arrived on port 21124")
|
||||
@@ -1,10 +0,0 @@
|
||||
substitutions:
|
||||
name: ur32p
|
||||
peer_ip: 192.0.2.66 # the D1 mini peer's address
|
||||
stream_interval: 500ms
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
packages:
|
||||
link: !include urlink.yaml
|
||||
@@ -1,36 +0,0 @@
|
||||
# Minimal UDP A/B: one udp component sending to the peer only, a raw packet_interface link (point to point on the
|
||||
# PR, accept-all on the base) with a checked stream, and a plain udp on_receive counter.
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes: [entest.hpp]
|
||||
on_boot:
|
||||
- priority: 600
|
||||
then:
|
||||
- lambda: entest::P2PF.listen(id(lnk));
|
||||
logger:
|
||||
level: DEBUG
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
globals:
|
||||
- {id: onrx, type: uint32_t, initial_value: "0"}
|
||||
udp:
|
||||
- id: u5
|
||||
port: 21125
|
||||
addresses: ["${peer_ip}"]
|
||||
on_receive:
|
||||
- lambda: id(onrx)++;
|
||||
packet_interface:
|
||||
- platform: udp
|
||||
id: lnk
|
||||
udp_id: u5
|
||||
interval:
|
||||
- interval: ${stream_interval}
|
||||
then:
|
||||
- lambda: entest::P2PF.send(id(lnk), 100);
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::P2PF.log();
|
||||
ESP_LOGI("stat", "STAT on_receive=%u", id(onrx));
|
||||
@@ -1,139 +0,0 @@
|
||||
"""Writes one config per validation case into out-valid/; expected outcome in the file name prefix (ok_ / bad_).
|
||||
|
||||
Run `esphome config` on each from the tree under test.
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import textwrap
|
||||
|
||||
OUT = pathlib.Path(__file__).parent / "out-valid"
|
||||
E32 = "esp32:\n board: esp32dev\n framework:\n type: esp-idf\n"
|
||||
E66 = "esp8266:\n board: d1_mini\n"
|
||||
WIFI = "wifi:\n ssid: x\n password: yyyyyyyy\n"
|
||||
|
||||
|
||||
def write(name: str, plat: str, middle: str, link: str) -> None:
|
||||
node = name.replace("_", "-")[:31]
|
||||
(OUT / f"{name}.yaml").write_text(
|
||||
f"esphome:\n name: {node}\n{plat}{middle}packet_interface:\n"
|
||||
+ textwrap.indent(textwrap.dedent(link), " ").replace(" ", " - ", 1),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def en(name: str, link: str, plat: str = E32, extra: str = "") -> None:
|
||||
write(
|
||||
name,
|
||||
plat,
|
||||
f"espnow:\n channel: 1\n{extra}",
|
||||
"platform: espnow\nid: l\n" + link,
|
||||
)
|
||||
|
||||
|
||||
def udp(name: str, addrs: str, link: str, plat: str = E32) -> None:
|
||||
write(
|
||||
name,
|
||||
plat,
|
||||
f"{WIFI}udp:\n - id: u\n addresses: {addrs}\n",
|
||||
"platform: udp\nid: l\nudp_id: u\n" + link,
|
||||
)
|
||||
|
||||
|
||||
OUT.mkdir(exist_ok=True)
|
||||
ADDR = "addressing:\n address: 1\n destination: 2\n"
|
||||
ADDR_BC = "addressing:\n address: 1\n destination: broadcast\n"
|
||||
# ESP-NOW
|
||||
en("bad_en_peer_addressing", "peer_address: 12:22:33:44:55:66\n" + ADDR)
|
||||
en(
|
||||
"ok_en_peer_rel_sess",
|
||||
"peer_address: 12:22:33:44:55:66\nreliability:\nsession:\nencryption:\n key: k\n rolling_code_enable: true\n",
|
||||
)
|
||||
en("ok_en_bc_addressing", ADDR)
|
||||
en("bad_en_bc_reliability", "reliability:\n")
|
||||
en("bad_en_bc_session", "session:\n")
|
||||
en("bad_en_bc_rolling", "encryption:\n key: k\n rolling_code_enable: true\n")
|
||||
en("ok_en_bc_plain_encryption", "encryption: k\n")
|
||||
en(
|
||||
"ok_en_bc_addr_rel_sess_rolling",
|
||||
ADDR
|
||||
+ "reliability:\nsession:\nencryption:\n key: k\n rolling_code_enable: true\n",
|
||||
)
|
||||
en("bad_en_bc_addr_bcdest_reliability", ADDR_BC + "reliability:\n")
|
||||
en("ok_en_size_250", "max_packet_size: 250\n")
|
||||
en("bad_en_size_251_payload_250", "max_packet_size: 251\n")
|
||||
en(
|
||||
"ok_en_size_1470_payload_1470",
|
||||
"max_packet_size: 1470\n",
|
||||
extra=" max_payload_size: 1470\n",
|
||||
)
|
||||
en(
|
||||
"bad_en_size_1471_payload_1470",
|
||||
"max_packet_size: 1471\n",
|
||||
extra=" max_payload_size: 1470\n",
|
||||
)
|
||||
en(
|
||||
"bad_en_size_1000_payload_800",
|
||||
"max_packet_size: 1000\n",
|
||||
extra=" max_payload_size: 800\n",
|
||||
)
|
||||
en(
|
||||
"bad_en8266_payload_300",
|
||||
"max_packet_size: 300\n",
|
||||
plat=E66,
|
||||
extra=" max_payload_size: 300\n",
|
||||
)
|
||||
en("ok_en8266_peer_rel", "peer_address: 12:22:33:44:55:66\nreliability:\n", plat=E66)
|
||||
# UDP
|
||||
udp("bad_udp_p2p_addressing", '["192.0.2.60"]', ADDR)
|
||||
udp(
|
||||
"ok_udp_p2p_rel_sess_rolling",
|
||||
'["192.0.2.60"]',
|
||||
"reliability:\nsession:\nencryption:\n key: k\n rolling_code_enable: true\n",
|
||||
)
|
||||
udp("ok_udp_255_addressing", '["192.0.2.255"]', ADDR)
|
||||
udp("bad_udp_255_reliability", '["192.0.2.255"]', "reliability:\n")
|
||||
udp("bad_udp_255_session", '["192.0.2.255"]', "session:\n")
|
||||
udp(
|
||||
"bad_udp_255_rolling",
|
||||
'["192.0.2.255"]',
|
||||
"encryption:\n key: k\n rolling_code_enable: true\n",
|
||||
)
|
||||
udp("ok_udp_255_addr_rel", '["192.0.2.255"]', ADDR + "reliability:\nsession:\n")
|
||||
udp("bad_udp_mcast_reliability", '["239.0.60.53"]', "reliability:\n")
|
||||
udp("ok_udp_mcast_addressing", '["239.0.60.53"]', ADDR_BC)
|
||||
udp("bad_udp_two_session", '["192.0.2.60", "192.0.2.61"]', "session:\n")
|
||||
udp("ok_udp_two_addressing", '["192.0.2.60", "192.0.2.61"]', ADDR)
|
||||
udp("ok_udp_default_bcast_addressing", '["255.255.255.255"]', ADDR_BC)
|
||||
udp("bad_udp_default_bcast_reliability", '["255.255.255.255"]', "reliability:\n")
|
||||
udp(
|
||||
"bad_udp_p2p_true_255_addressing",
|
||||
'["192.0.2.255"]',
|
||||
"point_to_point: true\n" + ADDR,
|
||||
)
|
||||
udp(
|
||||
"ok_udp_p2p_true_255_reliability",
|
||||
'["192.0.2.255"]',
|
||||
"point_to_point: true\nreliability:\n",
|
||||
)
|
||||
udp(
|
||||
"ok_udp_p2p_false_unicast_addressing",
|
||||
'["192.0.2.60"]',
|
||||
"point_to_point: false\n" + ADDR,
|
||||
)
|
||||
udp(
|
||||
"bad_udp_p2p_false_unicast_reliability",
|
||||
'["192.0.2.60"]',
|
||||
"point_to_point: false\nreliability:\n",
|
||||
)
|
||||
udp("bad_udp_p2p_true_mcast", '["239.0.60.53"]', "point_to_point: true\n")
|
||||
udp("bad_udp_p2p_true_two", '["192.0.2.60", "192.0.2.61"]', "point_to_point: true\n")
|
||||
udp("ok_udp_p2p_8266", '["192.0.2.60"]', "reliability:\nsession:\n", plat=E66)
|
||||
# peer address and all-ones broadcast cases
|
||||
en("bad_en_peer_group_mac", "peer_address: 01:22:33:44:55:66\n")
|
||||
en("bad_en_peer_zero_mac", "peer_address: 00:00:00:00:00:00\n")
|
||||
en(
|
||||
"ok_en_peer_explicit_broadcast_addressing",
|
||||
"peer_address: FF:FF:FF:FF:FF:FF\n" + ADDR,
|
||||
)
|
||||
udp("bad_udp_allones_p2p_true", '["255.255.255.255"]', "point_to_point: true\n")
|
||||
udp("ok_udp_allones_addressing", '["255.255.255.255"]', ADDR)
|
||||
@@ -1,62 +0,0 @@
|
||||
"""cmp.py REF.json OTHER.json : list each UUID (service / characteristic / descriptor, in order) where OTHER differs
|
||||
from REF, whether reads match (static characteristics), whether every notifying characteristic notified and
|
||||
whether OTHER lost its link before the final disconnect. Exits 1 on any difference."""
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
|
||||
def flat(p):
|
||||
d = json.loads(pathlib.Path(p).read_text(encoding="utf-8"))
|
||||
rows = []
|
||||
for s in d["services"]:
|
||||
rows.append(("svc", s["uuid"].lower()))
|
||||
for c in s["characteristics"]:
|
||||
rows.append(("chr", c["uuid"].lower()))
|
||||
rows += [("dsc", x.lower()) for x in c["descriptors"]]
|
||||
return d, rows
|
||||
|
||||
|
||||
rd, ref = flat(sys.argv[1])
|
||||
od, oth = flat(sys.argv[2])
|
||||
diff = [(a, b) for a, b in zip(ref, oth, strict=False) if a != b]
|
||||
print(
|
||||
f"entries ref={len(ref)} other={len(oth)} differing={len(diff) + abs(len(ref) - len(oth))}"
|
||||
)
|
||||
for a, b in diff:
|
||||
print(f" {a[0]} ref {a[1]} other {b[1]}")
|
||||
|
||||
|
||||
def chars(d: dict) -> list[dict]:
|
||||
return [c for s in d["services"] for c in s["characteristics"]]
|
||||
|
||||
|
||||
# compare by position: a UUID form bug renames the keys, so values and notify counts are matched by table order
|
||||
problems = []
|
||||
rc, oc = chars(rd), chars(od)
|
||||
for i, (a, b) in enumerate(zip(rc, oc, strict=False)):
|
||||
if a["props"] != b["props"]:
|
||||
problems.append(
|
||||
f"props {i} {b['uuid']} 0x{b['props']:02X} != ref 0x{a['props']:02X}"
|
||||
)
|
||||
rv, ov = rd["reads"].get(a["uuid"]), od["reads"].get(b["uuid"])
|
||||
if str(ov).startswith("FAILED"):
|
||||
problems.append(f"read {i} {b['uuid']} {ov}")
|
||||
elif not a["props"] & 0x10 and rv is not None and ov != rv:
|
||||
problems.append(f"read {i} {b['uuid']} {ov!r} != ref {rv!r}")
|
||||
if a["props"] & 0x10:
|
||||
n = od["notify"].get(b["uuid"])
|
||||
if not isinstance(n, int) or n <= 0:
|
||||
problems.append(f"notify {i} {b['uuid']} {n}")
|
||||
# a link that dropped after the first notification still has counts, so the drop itself fails the run
|
||||
if od.get("lost"):
|
||||
problems.append(f"link lost before the disconnect: {od['lost']}")
|
||||
print(f"notify {od['notify']}")
|
||||
for x in problems:
|
||||
print(" ", x)
|
||||
if diff or len(ref) != len(oth) or problems:
|
||||
sys.exit(
|
||||
f"FAIL: {len(diff)} differing entries, {len(problems)} read or notify problems"
|
||||
)
|
||||
print("PASS")
|
||||
@@ -1,100 +0,0 @@
|
||||
"""List every service, characteristic and descriptor UUID a bluetooth_proxy reports for a peer, read each readable
|
||||
characteristic, enable notify (CCCD write) on each notifying one and count 10 s of notifications, then disconnect.
|
||||
A link lost before that disconnect is recorded as "lost" in the JSON, which cmp.py fails on.
|
||||
usage: gattlist.py PROXY PEER_MAC OUT_JSON env: API_KEY (unset for a plaintext API). Retries 0x3E connect failures."""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from apiconn import ble_connect, connect, enable_notify # noqa: E402
|
||||
|
||||
|
||||
async def once(host: str, addr: int) -> dict | None:
|
||||
cli = await connect(host)
|
||||
lost: list[int] = []
|
||||
closing = False
|
||||
|
||||
def on_lost(e: int) -> None:
|
||||
if not closing:
|
||||
lost.append(e)
|
||||
print(f"LINK LOST err={e}", flush=True)
|
||||
|
||||
c, _mtu, err, cancel = await ble_connect(cli, addr, on_lost)
|
||||
if not c:
|
||||
print(f"connect err={err}", flush=True)
|
||||
cancel()
|
||||
await cli.disconnect()
|
||||
return None
|
||||
svcs = await cli.bluetooth_gatt_get_services(addr)
|
||||
out = {"services": [], "reads": {}, "notify": {}}
|
||||
notif: dict[str, int] = {}
|
||||
for s in svcs.services:
|
||||
so = {"uuid": s.uuid, "characteristics": []}
|
||||
for ch in s.characteristics:
|
||||
so["characteristics"].append(
|
||||
{
|
||||
"uuid": ch.uuid,
|
||||
"props": ch.properties,
|
||||
"descriptors": [d.uuid for d in ch.descriptors],
|
||||
}
|
||||
)
|
||||
if ch.properties & 0x02:
|
||||
try:
|
||||
out["reads"][ch.uuid] = bytes(
|
||||
await cli.bluetooth_gatt_read(addr, ch.handle)
|
||||
).hex()
|
||||
except Exception as e: # noqa: BLE001
|
||||
out["reads"][ch.uuid] = f"FAILED {type(e).__name__}"
|
||||
if ch.properties & 0x10:
|
||||
notif[ch.uuid] = 0
|
||||
try:
|
||||
if not await enable_notify(
|
||||
cli,
|
||||
addr,
|
||||
ch,
|
||||
lambda h, d, u=ch.uuid: (
|
||||
notif.__setitem__(u, notif[u] + 1)
|
||||
if isinstance(notif[u], int)
|
||||
else None
|
||||
),
|
||||
):
|
||||
notif[ch.uuid] = "FAILED no CCCD"
|
||||
except Exception as e: # noqa: BLE001
|
||||
notif[ch.uuid] = f"FAILED {type(e).__name__}"
|
||||
out["services"].append(so)
|
||||
await asyncio.sleep(10)
|
||||
out["notify"] = notif
|
||||
out["lost"] = lost
|
||||
closing = True
|
||||
await cli.bluetooth_device_disconnect(addr)
|
||||
await asyncio.sleep(2)
|
||||
cancel()
|
||||
await cli.disconnect()
|
||||
return out
|
||||
|
||||
|
||||
async def main(host: str, peer: str, path: str) -> None:
|
||||
addr = int(peer.replace(":", ""), 16)
|
||||
for _attempt in range(6):
|
||||
res = await once(host, addr)
|
||||
if res:
|
||||
break
|
||||
await asyncio.sleep(10)
|
||||
else:
|
||||
sys.exit("FAIL: no connection")
|
||||
pathlib.Path(path).write_text(json.dumps(res, indent=1), encoding="utf-8")
|
||||
for s in res["services"]:
|
||||
print(f"SVC {s['uuid']}")
|
||||
for c in s["characteristics"]:
|
||||
print(
|
||||
f" CHR {c['uuid']} props=0x{c['props']:02X} read={res['reads'].get(c['uuid'], '-')}"
|
||||
f" notify={res['notify'].get(c['uuid'], '-')}"
|
||||
)
|
||||
for d in c["descriptors"]:
|
||||
print(f" DSC {d}")
|
||||
|
||||
|
||||
asyncio.run(main(sys.argv[1], sys.argv[2], sys.argv[3]))
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/zsh
|
||||
# run.sh NAME: build ../rp2_web_ble/picow.yaml as NAME, USB flash the Pico W proxy, list the GATT UUID server
|
||||
# (server.yaml here) through it and compare with the ESP32 reference. Exit 0 only when the lists match.
|
||||
# env: TREE, PY, PICO_SN, PEER_MAC (the server); esp32ref.json (gattlist.py through an ESP32 proxy) and apikey.txt here
|
||||
D=${0:A:h}; N=$1; S=$D/..; T=${TREE:?set TREE}; PY=${PY:-$T/venv/bin/python}; C=$S/rp2_web_ble/picow.yaml
|
||||
$S/pio_build.sh compile $N $C || exit 1
|
||||
PORT=$($PY $S/ports.py --wait 2e8a --serial ${PICO_SN:?set PICO_SN} --timeout 30) || { echo "no pico"; exit 1; }
|
||||
$S/pio_build.sh upload $N $C $PORT || exit 1
|
||||
H=$($S/resolve.sh $N) || exit 1; sleep 5
|
||||
rm -f $D/$N.json
|
||||
API_KEY=$(cat $D/apikey.txt) timeout 600 $PY -I $D/gattlist.py $H ${PEER_MAC:?set PEER_MAC} $D/$N.json > $D/$N-list.txt
|
||||
RC=$?; grep -v "^ *CHR 00002a\|DSC 00002902\|SVC 000018" $D/$N-list.txt
|
||||
[ $RC = 0 ] && [ -s $D/$N.json ] || { echo "FAIL: gattlist.py exited $RC"; exit 1; }
|
||||
$PY $D/cmp.py $D/esp32ref.json $D/$N.json
|
||||
@@ -1,27 +0,0 @@
|
||||
# GATT server (ESP32-S3) for the UUID form check: the ble_notify server (16 bit and 32-bit base UUIDs, notify) plus a
|
||||
# 128 bit service whose characteristics and descriptors use 128 bit, 32-bit base (zero and nonzero low half) and
|
||||
# 16 bit UUIDs, with a 2901 user description. Set the name with -s name.
|
||||
packages:
|
||||
notify: !include ../ble_notify/server.yaml
|
||||
esp32_ble_server:
|
||||
services:
|
||||
- uuid: 0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0
|
||||
characteristics:
|
||||
- uuid: 0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f1
|
||||
read: true
|
||||
value: "c128"
|
||||
description: "text value"
|
||||
descriptors:
|
||||
- uuid: 5ec1ab01-0000-1000-8000-00805f9b34fb
|
||||
value: "d32"
|
||||
- uuid: 7d3e0a51-9c1b-4f2e-8a6d-1c2b3a4d5e6f
|
||||
value: "d128"
|
||||
- uuid: 5ec20000-0000-1000-8000-00805f9b34fb
|
||||
read: true
|
||||
value: "c32zero"
|
||||
- uuid: 5ec2abcd-0000-1000-8000-00805f9b34fb
|
||||
read: true
|
||||
value: "c32"
|
||||
- uuid: 2a19
|
||||
read: true
|
||||
value: [77]
|
||||
@@ -1,79 +0,0 @@
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#ifdef __XTENSA__
|
||||
#include "esp_cpu_utils.h"
|
||||
#include "esp_debug_helpers.h"
|
||||
#endif
|
||||
#include "esp_timer.h"
|
||||
// Counts every global operator new and, once armed, keeps the first ALLOC_CAP of them with five caller PCs
|
||||
// (callers on Xtensa only; RISC-V entries keep size and time). Aligned operator new is not counted.
|
||||
// See reference/recipes/heap_alloc.md.
|
||||
struct AllocEntry {
|
||||
uint32_t ms;
|
||||
uint32_t size; // ALLOC_MARKER for a marker: pc[0] and pc[1] then hold its two values
|
||||
uint32_t pc[5];
|
||||
};
|
||||
static constexpr uint32_t ALLOC_CAP = 1024;
|
||||
static constexpr uint32_t ALLOC_MARKER = UINT32_MAX;
|
||||
AllocEntry g_allocs[ALLOC_CAP];
|
||||
std::atomic<uint32_t> g_alloc_n{0};
|
||||
std::atomic<uint32_t> g_new_count{0};
|
||||
// seq_cst with g_alloc_busy: the dump stores false then loads busy, a recorder adds busy then loads this
|
||||
std::atomic<bool> g_alloc_armed{false};
|
||||
uint32_t g_alloc_armed_ms = 0; // when recording started, 0 if it never did
|
||||
// Recorders between claiming a slot and filling it; the dump waits for 0 after disarming.
|
||||
std::atomic<uint32_t> g_alloc_busy{0};
|
||||
|
||||
// Claims the next slot, or returns nullptr and disarms once the buffer is full.
|
||||
static inline AllocEntry *alloc_claim(uint32_t size) {
|
||||
uint32_t i = g_alloc_n.fetch_add(1);
|
||||
if (i >= ALLOC_CAP) {
|
||||
g_alloc_armed = false;
|
||||
return nullptr;
|
||||
}
|
||||
AllocEntry &e = g_allocs[i];
|
||||
e.ms = (uint32_t) (esp_timer_get_time() / 1000);
|
||||
e.size = size;
|
||||
return &e;
|
||||
}
|
||||
|
||||
void *operator new(size_t size) {
|
||||
g_new_count.fetch_add(1, std::memory_order_relaxed);
|
||||
g_alloc_busy.fetch_add(1); // before the armed check, so a dump that disarmed first sees it
|
||||
AllocEntry *e = g_alloc_armed ? alloc_claim(size) : nullptr;
|
||||
if (e != nullptr) {
|
||||
e->pc[0] = e->pc[1] = e->pc[2] = e->pc[3] = e->pc[4] = 0;
|
||||
#ifdef __XTENSA__
|
||||
esp_backtrace_frame_t f;
|
||||
esp_backtrace_get_start(&f.pc, &f.sp, &f.next_pc);
|
||||
// The start frame is this function; record the five callers above it.
|
||||
// Stop at the first frame that does not unwind; the slots after it stay 0.
|
||||
for (int k = 0; k < 5 && f.next_pc != 0 && esp_backtrace_get_next_frame(&f); k++)
|
||||
e->pc[k] = esp_cpu_process_stack_pc(f.pc);
|
||||
#endif
|
||||
}
|
||||
g_alloc_busy.fetch_sub(1);
|
||||
void *p = malloc(size ? size : 1);
|
||||
if (p == nullptr)
|
||||
abort();
|
||||
return p;
|
||||
}
|
||||
void *operator new[](size_t size) { return operator new(size); }
|
||||
void operator delete(void *p) noexcept { free(p); }
|
||||
void operator delete[](void *p) noexcept { free(p); }
|
||||
void operator delete(void *p, size_t) noexcept { free(p); }
|
||||
void operator delete[](void *p, size_t) noexcept { free(p); }
|
||||
|
||||
// Splits the dump into phases, for example on each change of an entity's state.
|
||||
static inline void alloc_marker(uint32_t a, uint32_t b) {
|
||||
g_alloc_busy.fetch_add(1);
|
||||
if (AllocEntry *e = g_alloc_armed ? alloc_claim(ALLOC_MARKER) : nullptr) {
|
||||
e->pc[0] = a;
|
||||
e->pc[1] = b;
|
||||
e->pc[2] = e->pc[3] = e->pc[4] = 0;
|
||||
}
|
||||
g_alloc_busy.fetch_sub(1);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
# Package for allocring.hpp: arms it ${alloc_arm_s} s after boot, reports that on a binary sensor and adds the
|
||||
# dump button. See heap_alloc.md.
|
||||
esphome:
|
||||
includes:
|
||||
- allocring.hpp
|
||||
on_boot:
|
||||
then:
|
||||
- delay: ${alloc_arm_s}s
|
||||
- lambda: |-
|
||||
g_alloc_armed_ms = millis();
|
||||
g_alloc_armed = true;
|
||||
ESP_LOGI("allocs", "ARMED total=%u", g_new_count.load());
|
||||
|
||||
binary_sensor:
|
||||
# Drivers wait for this before the first action, so no step runs before recording starts
|
||||
- platform: template
|
||||
name: Allocation recorder armed
|
||||
lambda: return g_alloc_armed.load();
|
||||
|
||||
interval:
|
||||
- interval: 30s
|
||||
then:
|
||||
- lambda: |-
|
||||
ESP_LOGI("allocs", "total=%u kept=%u heap=%u", g_new_count.load(), (unsigned) g_alloc_n.load(),
|
||||
(unsigned) heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
|
||||
|
||||
button:
|
||||
- platform: template
|
||||
name: Dump allocations
|
||||
on_press:
|
||||
# Recording stops for good; reboot before the next run, or a second press returns the same entries.
|
||||
- lambda: |-
|
||||
g_alloc_armed = false;
|
||||
// let recorders on other tasks finish the entry they claimed
|
||||
for (int w = 0; w < 100 && g_alloc_busy.load() != 0; w++)
|
||||
delay(1);
|
||||
uint32_t claimed = g_alloc_n.load();
|
||||
uint32_t n = std::min<uint32_t>(claimed, ALLOC_CAP);
|
||||
// claimed > n means the buffer filled and recording stopped early
|
||||
// armed_ms=0: the recorder never ran; busy>0: an entry may still be half written;
|
||||
// buf is the buffer's address, which decode.py matches against the ELF
|
||||
ESP_LOGI("allocs", "DUMP n=%u claimed=%u total=%u armed_ms=%u busy=%u buf=%08x", n, claimed,
|
||||
g_new_count.load(), g_alloc_armed_ms, g_alloc_busy.load(), (unsigned) (uintptr_t) g_allocs);
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
const AllocEntry &e = g_allocs[i];
|
||||
ESP_LOGI("allocs", "E %u %u %u %08x %08x %08x %08x %08x", i, e.ms, e.size, e.pc[0], e.pc[1], e.pc[2],
|
||||
e.pc[3], e.pc[4]);
|
||||
if ((i & 15) == 15) {
|
||||
delay(20); // let the log drain
|
||||
App.feed_wdt(); // a full dump over a 115200 baud UART log outlasts the task watchdog
|
||||
}
|
||||
}
|
||||
ESP_LOGI("allocs", "DUMP END");
|
||||
@@ -1,108 +0,0 @@
|
||||
"""Move the device's first cover to the far end and back N times with a states-only client, then save the dump.
|
||||
|
||||
usage: cycles_cover.py HOST CYCLES OUT env: API_KEY (unset for a plaintext API)
|
||||
Waits for the recorder's armed binary sensor first. Exits 2 when a move did not reach its position (the
|
||||
cover never moved, so the dump proves nothing).
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import pathlib
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import (
|
||||
BinarySensorInfo,
|
||||
BinarySensorState,
|
||||
CoverInfo,
|
||||
CoverOperation,
|
||||
CoverState,
|
||||
)
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from apiconn import connect # noqa: E402
|
||||
from heap_alloc.dump import dump # noqa: E402
|
||||
|
||||
# After each move, so allocations that come once the cover has stopped land in the same cycle
|
||||
SETTLE_S = 8
|
||||
ARM_WAIT_S = 600
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
host, cycles, out = sys.argv[1], int(sys.argv[2]), sys.argv[3]
|
||||
with pathlib.Path(out).open("w", encoding="utf-8") as f:
|
||||
|
||||
def w(s: str) -> None:
|
||||
f.write(time.strftime("%H:%M:%S ") + s + "\n")
|
||||
f.flush()
|
||||
|
||||
c = await connect(host)
|
||||
ents, _ = await c.list_entities_services()
|
||||
cover = next(e for e in ents if isinstance(e, CoverInfo))
|
||||
armed_info = next(
|
||||
e
|
||||
for e in ents
|
||||
if isinstance(e, BinarySensorInfo)
|
||||
and e.object_id == "allocation_recorder_armed"
|
||||
)
|
||||
states: asyncio.Queue = asyncio.Queue()
|
||||
armed = asyncio.Event()
|
||||
|
||||
def on_state(s) -> None:
|
||||
if isinstance(s, CoverState) and s.key == cover.key:
|
||||
states.put_nowait(s)
|
||||
elif (
|
||||
isinstance(s, BinarySensorState) and s.key == armed_info.key and s.state
|
||||
):
|
||||
armed.set()
|
||||
|
||||
c.subscribe_states(on_state)
|
||||
latest = await asyncio.wait_for(states.get(), 10)
|
||||
# moves made before recording starts would be missing from the dump
|
||||
await asyncio.wait_for(armed.wait(), ARM_WAIT_S)
|
||||
w("ARMED")
|
||||
|
||||
def drain() -> CoverState:
|
||||
"""The newest queued state, so no stale one is read as this command's result."""
|
||||
nonlocal latest
|
||||
while not states.empty():
|
||||
latest = states.get_nowait()
|
||||
return latest
|
||||
|
||||
async def move(pos: float) -> bool:
|
||||
drain()
|
||||
w(f"CMD {pos}")
|
||||
c.cover_command(cover.key, position=pos)
|
||||
moved = False
|
||||
deadline = time.monotonic() + 60
|
||||
while (left := deadline - time.monotonic()) > 0:
|
||||
try:
|
||||
s = await asyncio.wait_for(states.get(), left)
|
||||
except TimeoutError:
|
||||
break
|
||||
idle = s.current_operation == CoverOperation.IDLE
|
||||
moved |= not idle
|
||||
if moved and idle and abs(s.position - pos) < 0.01:
|
||||
w(f"IDLE pos={s.position:.3f}")
|
||||
return True
|
||||
w("TIMEOUT")
|
||||
return False
|
||||
|
||||
timeouts = 0
|
||||
# start toward the far end, so the first command always moves the cover
|
||||
order = (0.0, 1.0) if drain().position > 0.5 else (1.0, 0.0)
|
||||
for i in range(cycles):
|
||||
w(f"CYCLE {i + 1}")
|
||||
for pos in order:
|
||||
timeouts += not await move(pos)
|
||||
await asyncio.sleep(SETTLE_S)
|
||||
if timeouts:
|
||||
# before the dump, which exits on its own failure
|
||||
print(f"{timeouts} moves timed out", file=sys.stderr)
|
||||
await dump(c, w)
|
||||
await c.disconnect()
|
||||
if timeouts:
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1,159 +0,0 @@
|
||||
"""Decode an allocring dump into callers: decode.py LOG ELF [ADDR2LINE]
|
||||
|
||||
Prints each entry with its caller frames as function and file:line, and markers (size 0xFFFFFFFF, ALLOC_MARKER) as phase
|
||||
separators.
|
||||
ADDR2LINE defaults to an Xtensa one found in ESPHome's ESP-IDF tools cache, ~/.platformio or ~/.espressif.
|
||||
Exits 2 when the dump is incomplete (missing header or entries, or the buffer filled during the run).
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ENTRY = re.compile(r"\bE (\d+) (\d+) (\d+) ((?:[0-9a-f]{8} ?){5})")
|
||||
HEADER = re.compile(
|
||||
r"\bDUMP n=(\d+) claimed=(\d+) total=\d+ armed_ms=(\d+) busy=(\d+) buf=([0-9a-f]{8})"
|
||||
)
|
||||
MARKER = 0xFFFFFFFF
|
||||
XTENSA = 94 # ELF e_machine; the recorder walks frames only on Xtensa
|
||||
|
||||
|
||||
def tool_roots() -> list[Path]:
|
||||
roots = [Path.home() / ".platformio", Path.home() / ".espressif"]
|
||||
try:
|
||||
from esphome.espidf.framework import get_idf_tools_path
|
||||
except ImportError:
|
||||
return roots
|
||||
return [get_idf_tools_path(), *roots]
|
||||
|
||||
|
||||
def is_xtensa(elf: str) -> bool:
|
||||
return int.from_bytes(Path(elf).read_bytes()[18:20], "little") == XTENSA
|
||||
|
||||
|
||||
def find_addr2line() -> str:
|
||||
for root in tool_roots():
|
||||
for path in root.glob("**/bin/xtensa-esp*-elf-addr2line"):
|
||||
if path.is_file():
|
||||
return str(path)
|
||||
sys.exit("no addr2line found; pass it as the third argument")
|
||||
|
||||
|
||||
def short(path: str) -> str:
|
||||
for marker in ("esphome/components/", "esphome/core/", "esp-idf/", "include/c++/"):
|
||||
if marker in path:
|
||||
return marker + path.split(marker, 1)[1]
|
||||
return path
|
||||
|
||||
|
||||
def decode(
|
||||
addr2line: str, elf: str, pcs: list[str]
|
||||
) -> dict[str, list[tuple[str, str]]]:
|
||||
"""Every PC's frames (inlined ones too); -a prints each address before its frames."""
|
||||
out = subprocess.run(
|
||||
[addr2line, "-afiC", "-e", elf, *(f"0x{pc}" for pc in pcs)],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.splitlines()
|
||||
names: dict[str, list[tuple[str, str]]] = {}
|
||||
frames: list[tuple[str, str]] = []
|
||||
i = 0
|
||||
while i < len(out):
|
||||
if out[i].startswith("0x"):
|
||||
frames = names.setdefault(f"{int(out[i], 16):08x}", [])
|
||||
i += 1
|
||||
else:
|
||||
frames.append((out[i], short(out[i + 1])))
|
||||
i += 2
|
||||
return names
|
||||
|
||||
|
||||
def last_dump(text: str) -> str:
|
||||
"""The newest dump in the file (a retried press or an appended file holds several); check() rejects it if cut off."""
|
||||
start = max((m.start() for m in HEADER.finditer(text)), default=len(text))
|
||||
return text[start:]
|
||||
|
||||
|
||||
def check(dump: str, entries: list, xtensa: bool) -> list[str]:
|
||||
"""Reasons the dump is incomplete, empty when it is whole."""
|
||||
if not (header := HEADER.search(dump)):
|
||||
return ["no DUMP header (log subscription started late?)"]
|
||||
n, claimed, armed_ms, busy = (int(header[i]) for i in range(1, 5))
|
||||
problems = []
|
||||
if not armed_ms:
|
||||
problems.append("the recorder was never armed (pressed before alloc_arm_s?)")
|
||||
if busy:
|
||||
problems.append(f"{busy} recorders were still writing an entry")
|
||||
indexes = [int(e[0]) for e in entries]
|
||||
if missing := sorted(set(range(n)) - set(indexes)):
|
||||
problems.append(f"{len(missing)} of {n} entries missing, first {missing[:10]}")
|
||||
if len(indexes) != len(set(indexes)):
|
||||
problems.append("duplicate entries")
|
||||
if stray := sorted(i for i in set(indexes) if i >= n):
|
||||
problems.append(f"entries past n={n}: {stray[:10]}")
|
||||
allocs = [pcs for _, _, size, pcs in entries if size != MARKER]
|
||||
if xtensa and allocs and all(pcs[0] == "00000000" for pcs in allocs):
|
||||
problems.append("no entry has a caller (frame walk failed?)")
|
||||
if claimed > n:
|
||||
problems.append(f"buffer filled: recording stopped after {n} entries")
|
||||
if "DUMP END" not in dump:
|
||||
problems.append("no DUMP END")
|
||||
return problems
|
||||
|
||||
|
||||
def main() -> None:
|
||||
log, elf = sys.argv[1], sys.argv[2]
|
||||
text = last_dump(Path(log).read_text(encoding="utf-8", errors="replace"))
|
||||
entries = [
|
||||
(idx, int(ms), int(size), pcs.split())
|
||||
for idx, ms, size, pcs in ENTRY.findall(text)
|
||||
]
|
||||
wanted = {
|
||||
pc
|
||||
for _, _, size, pcs in entries
|
||||
if size != MARKER
|
||||
for pc in pcs
|
||||
if pc != "00000000"
|
||||
}
|
||||
# Only Xtensa dumps carry callers; RISC-V ones still print sizes and times
|
||||
names = {}
|
||||
if wanted:
|
||||
addr2line = sys.argv[3] if len(sys.argv) > 3 else find_addr2line()
|
||||
names = decode(addr2line, elf, sorted(wanted))
|
||||
for idx, ms, size, pcs in entries:
|
||||
if size == MARKER:
|
||||
print(
|
||||
f"--- marker at {ms / 1000:.3f} s: {int(pcs[0], 16)} {int(pcs[1], 16)}"
|
||||
)
|
||||
continue
|
||||
print(f"#{idx} {ms / 1000:.3f} s {size} B")
|
||||
for pc in pcs:
|
||||
if pc == "00000000":
|
||||
break
|
||||
for func, loc in names[pc]:
|
||||
print(f" {func[:110]} {loc}")
|
||||
problems = check(text, entries, is_xtensa(elf))
|
||||
# addr2line names any address, so check the ELF is the build that made the dump
|
||||
if wanted and (header := HEADER.search(text)):
|
||||
nm = addr2line[: -len("addr2line")] + "nm"
|
||||
if not Path(nm).is_file():
|
||||
problems.append(f"cannot check the ELF: no {nm} next to addr2line")
|
||||
elif not re.search(
|
||||
rf"^0*{int(header[5], 16):x} [bBdD] g_allocs$",
|
||||
subprocess.run(
|
||||
[nm, elf], capture_output=True, text=True, check=True
|
||||
).stdout,
|
||||
re.MULTILINE,
|
||||
):
|
||||
problems.append(
|
||||
"the ELF is not the build that made this dump (g_allocs address differs)"
|
||||
)
|
||||
if problems:
|
||||
print("INCOMPLETE DUMP: " + "; ".join(problems), file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,84 +0,0 @@
|
||||
"""Press the "Dump allocations" button from allocring.yaml and save the dump.
|
||||
|
||||
usage: dump.py HOST OUT env: API_KEY (unset for a plaintext API)
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
import contextlib
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
from aioesphomeapi import APIClient, ButtonInfo
|
||||
from aioesphomeapi.model import LogLevel
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from apiconn import connect, log_text # noqa: E402
|
||||
|
||||
HEADER = re.compile(r"\bDUMP n=(\d+) claimed=\d+ total=\d+ armed_ms=(\d+) busy=(\d+)")
|
||||
ENTRY = re.compile(r"\bE (\d+) \d+ \d+ ")
|
||||
|
||||
|
||||
async def dump(c: APIClient, write: Callable[[str], None], tries: int = 3) -> None:
|
||||
"""Subscribe to logs, press the dump button and pass every line to WRITE until DUMP END.
|
||||
|
||||
subscribe_logs does not confirm the subscription and the device drops log lines when busy, so the press is
|
||||
repeated (the dump is repeatable) until the header and all n entries arrived; exits 2 after TRIES presses.
|
||||
"""
|
||||
ents, _ = await c.list_entities_services()
|
||||
button = next(
|
||||
e
|
||||
for e in ents
|
||||
if isinstance(e, ButtonInfo) and e.object_id == "dump_allocations"
|
||||
)
|
||||
seen: dict = {"n": None, "idx": set()}
|
||||
done = asyncio.Event()
|
||||
|
||||
def on_log(msg) -> None:
|
||||
text = log_text(msg)
|
||||
write(text)
|
||||
if m := HEADER.search(text):
|
||||
seen["n"], seen["idx"] = int(m[1]), set()
|
||||
seen["armed"], seen["busy"] = int(m[2]) != 0, int(m[3])
|
||||
elif m := ENTRY.search(text):
|
||||
seen["idx"].add(int(m[1]))
|
||||
elif "DUMP END" in text and seen["n"] is not None:
|
||||
# without this press's header it is a late end from an earlier press
|
||||
done.set()
|
||||
|
||||
c.subscribe_logs(on_log, log_level=LogLevel.LOG_LEVEL_INFO)
|
||||
for _ in range(tries):
|
||||
await asyncio.sleep(2)
|
||||
seen["n"] = None
|
||||
done.clear()
|
||||
c.button_command(button.key)
|
||||
with contextlib.suppress(TimeoutError):
|
||||
await asyncio.wait_for(done.wait(), 120)
|
||||
# the device drops log lines when its send buffer is full, so require every entry
|
||||
if done.is_set() and seen["n"] is not None and not seen["armed"]:
|
||||
print(
|
||||
"the recorder was never armed (pressed before alloc_arm_s?)",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(2)
|
||||
if (
|
||||
done.is_set()
|
||||
and seen["n"] is not None
|
||||
and not seen["busy"]
|
||||
and seen["idx"] == set(range(seen["n"]))
|
||||
):
|
||||
return
|
||||
print(f"no whole dump after {tries} presses", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
c = await connect(sys.argv[1])
|
||||
with pathlib.Path(sys.argv[2]).open("w", encoding="utf-8") as f:
|
||||
await dump(c, lambda s: f.write(s + "\n"))
|
||||
await c.disconnect()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1,51 +0,0 @@
|
||||
"""Press the device's buttons through Home Assistant and print the script and flag states after each step.
|
||||
|
||||
usage: drive.py TOKENFILE NAME env: HA_URL (default http://127.0.0.1:8129)
|
||||
NAME is the device name from hsw.yaml (button entity ids are button.<NAME>_long_on and so on).
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(
|
||||
0, str(pathlib.Path(__file__).resolve().parent.parent / "mqtt" / "ha_discovery")
|
||||
)
|
||||
from ha_rest import req_or_exit # noqa: E402
|
||||
|
||||
tok = pathlib.Path(sys.argv[1]).read_text(encoding="utf-8").strip()
|
||||
name = sys.argv[2].replace("-", "_") # entity ids use underscores
|
||||
t0 = time.monotonic()
|
||||
|
||||
|
||||
def state(entity: str) -> str:
|
||||
return req_or_exit(f"/api/states/{entity}", token=tok)["state"]
|
||||
|
||||
|
||||
def show(tag: str) -> None:
|
||||
print(
|
||||
f"{time.monotonic() - t0:6.1f}s {tag:30s} long_job={state('script.long_job'):4s}"
|
||||
f" quick_job={state('script.quick_job'):4s} flag={state('input_boolean.script_ran')}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
|
||||
def call(domain: str, action: str, entity: str, wait: float = 3) -> None:
|
||||
req_or_exit(f"/api/services/{domain}/{action}", {"entity_id": entity}, token=tok)
|
||||
time.sleep(wait)
|
||||
|
||||
|
||||
show("start")
|
||||
call("button", "press", f"button.{name}_long_on")
|
||||
show("device Long on")
|
||||
call("button", "press", f"button.{name}_long_off")
|
||||
show("device Long off")
|
||||
call("input_boolean", "turn_off", "input_boolean.script_ran", 1)
|
||||
call("button", "press", f"button.{name}_long_on")
|
||||
show("device Long on again")
|
||||
time.sleep(20)
|
||||
show("script finished on its own")
|
||||
call("button", "press", f"button.{name}_quick_on")
|
||||
show("device Quick on")
|
||||
call("script", "turn_on", "script.long_job")
|
||||
show("HA starts the script")
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
# Throwaway Home Assistant on port 8129: a 20 s script that sets and clears a flag, and a toggle script.
|
||||
http:
|
||||
server_port: 8129
|
||||
api:
|
||||
config:
|
||||
onboarding:
|
||||
frontend:
|
||||
input_boolean:
|
||||
script_ran:
|
||||
script:
|
||||
long_job:
|
||||
alias: Long job
|
||||
mode: single
|
||||
sequence:
|
||||
- action: input_boolean.turn_on
|
||||
target:
|
||||
entity_id: input_boolean.script_ran
|
||||
- delay: 20
|
||||
- action: input_boolean.turn_off
|
||||
target:
|
||||
entity_id: input_boolean.script_ran
|
||||
quick_job:
|
||||
alias: Quick job
|
||||
sequence:
|
||||
- action: input_boolean.toggle
|
||||
target:
|
||||
entity_id: input_boolean.script_ran
|
||||
logger:
|
||||
default: warning
|
||||
logs:
|
||||
homeassistant.components.esphome: debug
|
||||
homeassistant.components.script: debug
|
||||
homeassistant.helpers.script: info
|
||||
@@ -1,36 +0,0 @@
|
||||
"""Add a host build's API to a throwaway Home Assistant and allow it to call actions.
|
||||
|
||||
usage: haflow.py TOKENFILE env: HA_URL (default http://127.0.0.1:8129)
|
||||
Runs the esphome config flow against 127.0.0.1:6053, then turns on allow_service_calls in the options flow.
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(
|
||||
0, str(pathlib.Path(__file__).resolve().parent.parent / "mqtt" / "ha_discovery")
|
||||
)
|
||||
from ha_rest import req_or_exit # noqa: E402
|
||||
|
||||
tok = pathlib.Path(sys.argv[1]).read_text(encoding="utf-8").strip()
|
||||
flow = "/api/config/config_entries/flow"
|
||||
f = req_or_exit(flow, {"handler": "esphome"}, token=tok)
|
||||
r = req_or_exit(
|
||||
f"{flow}/{f['flow_id']}", {"host": "127.0.0.1", "port": 6053}, token=tok
|
||||
)
|
||||
if r.get("type") == "form" and r.get("errors"):
|
||||
sys.exit(f"config flow step {r.get('step_id')} failed: {r['errors']}")
|
||||
if r.get("type") == "form": # confirmation step
|
||||
r = req_or_exit(f"{flow}/{r['flow_id']}", {}, token=tok)
|
||||
if r.get("type") != "create_entry":
|
||||
sys.exit(
|
||||
f"config flow ended with {r.get('type')} {r.get('errors') or r.get('reason')}"
|
||||
)
|
||||
opts = "/api/config/config_entries/options/flow"
|
||||
o = req_or_exit(opts, {"handler": r["result"]["entry_id"]}, token=tok)
|
||||
o = req_or_exit(f"{opts}/{o['flow_id']}", {"allow_service_calls": True}, token=tok)
|
||||
if o.get("type") != "create_entry":
|
||||
sys.exit(
|
||||
f"options flow ended with {o.get('type')} {o.get('errors') or o.get('reason')}"
|
||||
)
|
||||
print("added", r.get("title"), "with allow_service_calls")
|
||||
@@ -1,39 +0,0 @@
|
||||
# Host build mirroring two Home Assistant scripts and the flag they set. Substitution: name.
|
||||
esphome:
|
||||
name: ${name}
|
||||
host:
|
||||
logger:
|
||||
level: DEBUG
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
switch:
|
||||
- platform: homeassistant
|
||||
id: sw_long
|
||||
name: "Long job mirror"
|
||||
entity_id: script.long_job
|
||||
on_turn_on:
|
||||
- logger.log: "EV long ON"
|
||||
on_turn_off:
|
||||
- logger.log: "EV long OFF"
|
||||
- platform: homeassistant
|
||||
id: sw_quick
|
||||
name: "Quick job mirror"
|
||||
entity_id: script.quick_job
|
||||
- platform: homeassistant
|
||||
id: sw_bool
|
||||
name: "Ran flag mirror"
|
||||
entity_id: input_boolean.script_ran
|
||||
on_turn_on:
|
||||
- logger.log: "EV flag ON"
|
||||
on_turn_off:
|
||||
- logger.log: "EV flag OFF"
|
||||
button:
|
||||
- platform: template
|
||||
name: "Long on"
|
||||
on_press: [switch.turn_on: sw_long]
|
||||
- platform: template
|
||||
name: "Long off"
|
||||
on_press: [switch.turn_off: sw_long]
|
||||
- platform: template
|
||||
name: "Quick on"
|
||||
on_press: [switch.turn_on: sw_quick]
|
||||
@@ -1,18 +0,0 @@
|
||||
# Package for Improv tests: Wi-Fi with no network saved, web_server and improv_serial with a next_url, and an ALIVE
|
||||
# line every 5 s. Substitution: name. Drop web_server on a LibreTiny board with no ap: (it boot-loops, see
|
||||
# reference/recipes/improv.md).
|
||||
esphome:
|
||||
name: ${name}
|
||||
|
||||
wifi:
|
||||
power_save_mode: none
|
||||
|
||||
web_server:
|
||||
|
||||
improv_serial:
|
||||
next_url: https://example.com/?device_name={{device_name}}&ip_address={{ip_address}}
|
||||
|
||||
interval:
|
||||
- interval: 5s
|
||||
then:
|
||||
- logger.log: "ALIVE"
|
||||
@@ -1,15 +0,0 @@
|
||||
# Classic ESP32 devkit with Improv over serial (UART0, shared with the log) and BLE. Copy it per build with its own
|
||||
# name; run.sh wants the file name to match name.
|
||||
substitutions:
|
||||
name: improv32
|
||||
packages:
|
||||
common: !include common.yaml
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
logger:
|
||||
hardware_uart: UART0
|
||||
improv_ble:
|
||||
authorizer: none
|
||||
next_url: https://example.com/?device_name={{device_name}}&ip_address={{ip_address}}
|
||||
@@ -1,96 +0,0 @@
|
||||
"""Improv over BLE: find the device by name, send WIFI_SETTINGS and print state, errors and the RPC result URLs.
|
||||
usage: improvble.py NAME SECRETS (needs bleak; the device needs improv_ble authorizer: none and a next_url)"""
|
||||
|
||||
import asyncio
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from bleak import BleakClient, BleakScanner
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
from improvcli import load_wifi_secrets, strings # noqa: E402
|
||||
|
||||
BASE = "00467768-6228-2272-4663-2774782680"
|
||||
STATE, ERROR, RPC, RESULT = BASE + "01", BASE + "02", BASE + "03", BASE + "04"
|
||||
STATES = {1: "awaiting_auth", 2: "authorized", 3: "provisioning", 4: "provisioned"}
|
||||
|
||||
|
||||
def pkt(cmd: int, data: bytes) -> bytes:
|
||||
b = bytes([cmd, len(data)]) + data
|
||||
return b + bytes([sum(b) & 0xFF])
|
||||
|
||||
|
||||
async def main(name: str, secrets: str) -> None:
|
||||
ssid, pw = (x.encode() for x in load_wifi_secrets(secrets))
|
||||
dev = await BleakScanner.find_device_by_name(name, timeout=30)
|
||||
if dev is None:
|
||||
sys.exit(
|
||||
"FAIL: device not found (a provisioned board stops advertising Improv)"
|
||||
)
|
||||
loop = asyncio.get_running_loop()
|
||||
t0 = loop.time()
|
||||
done = asyncio.Event()
|
||||
errors: list = []
|
||||
states: list[int] = []
|
||||
async with BleakClient(dev) as c:
|
||||
|
||||
def on_state(_, d: bytearray) -> None:
|
||||
if not d:
|
||||
errors.append("empty state")
|
||||
return
|
||||
states.append(d[0])
|
||||
print(f"{loop.time() - t0:6.2f} STATE {STATES.get(d[0], d[0])}", flush=True)
|
||||
|
||||
def on_error(_, d: bytearray) -> None:
|
||||
if not d:
|
||||
errors.append("empty error")
|
||||
elif d[0]:
|
||||
errors.append(d[0])
|
||||
print(f"{loop.time() - t0:6.2f} ERROR {d[0]}", flush=True)
|
||||
|
||||
def on_result(_, d: bytearray) -> None:
|
||||
if len(d) < 3 or d[1] != len(d) - 3 or sum(d[:-1]) & 0xFF != d[-1]:
|
||||
errors.append("bad result frame")
|
||||
print(
|
||||
f"{loop.time() - t0:6.2f} BAD RESULT {bytes(d).hex()}", flush=True
|
||||
)
|
||||
return
|
||||
try:
|
||||
strs = strings(bytes(d[2:-1]))
|
||||
except ValueError:
|
||||
errors.append("string overruns the result")
|
||||
strs = []
|
||||
print(f"{loop.time() - t0:6.2f} RESULT cmd={d[0]} {strs}", flush=True)
|
||||
if (
|
||||
d[0] == 1
|
||||
): # the WIFI_SETTINGS reply; the example sets next_url, so it carries a URL
|
||||
if not any(x.startswith("http") for x in strs):
|
||||
errors.append("no URL in result")
|
||||
done.set()
|
||||
|
||||
await c.start_notify(STATE, on_state)
|
||||
await c.start_notify(ERROR, on_error)
|
||||
await c.start_notify(RESULT, on_result)
|
||||
s = await c.read_gatt_char(STATE)
|
||||
print(f"initial state {STATES.get(s[0], s[0]) if s else 'empty'}")
|
||||
if not s or s[0] == 4:
|
||||
sys.exit(
|
||||
"FAIL: board already provisioned or no state; erase the flash first"
|
||||
)
|
||||
payload = bytes([len(ssid)]) + ssid + bytes([len(pw)]) + pw
|
||||
await c.write_gatt_char(RPC, pkt(1, payload), response=True)
|
||||
try:
|
||||
await asyncio.wait_for(done.wait(), 45)
|
||||
except TimeoutError:
|
||||
print("no result within 45 s")
|
||||
await asyncio.sleep(1)
|
||||
last = await c.read_gatt_char(STATE)
|
||||
states.append(last[0] if last else 0)
|
||||
if not done.is_set() or errors or states[-1] != 4:
|
||||
sys.exit(
|
||||
f"FAIL (errors {errors}, last state {STATES.get(states[-1], states[-1])})"
|
||||
)
|
||||
print("PASS")
|
||||
|
||||
|
||||
asyncio.run(main(sys.argv[1], sys.argv[2]))
|
||||
@@ -1,339 +0,0 @@
|
||||
"""Improv serial client that reads frames out of the log stream on the same port.
|
||||
usage: improvcli.py PORT OUT --secrets FILE [--baud N] [--keep-dtr] [--settle S] [--skip-bad] [--allow-reset]
|
||||
Runs: 300 stray bytes, state, info, network state, scan, provision with a bad password, provision with the real one,
|
||||
state and network state again. Prints parsed frames; the raw stream overwrites OUT.
|
||||
Exit 2 when the port does not open or the secrets file lacks a key. Exit 1 when any request goes unanswered, an
|
||||
unexpected error or a malformed frame arrives, or the port resets or the log shows a reboot (unless --allow-reset).
|
||||
Credentials come from the secrets file (wifi_ssid, wifi_password) and are never printed; the SSID is masked in scan
|
||||
results."""
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
import yaml
|
||||
|
||||
STATES = {
|
||||
0: "stopped",
|
||||
1: "awaiting_auth",
|
||||
2: "authorized",
|
||||
3: "provisioning",
|
||||
4: "provisioned",
|
||||
}
|
||||
ERRORS = {
|
||||
0: "none",
|
||||
1: "invalid_rpc",
|
||||
2: "unknown_rpc",
|
||||
3: "unable_to_connect",
|
||||
4: "not_authorized",
|
||||
0xFF: "unknown",
|
||||
}
|
||||
|
||||
|
||||
def frame(cmd: int, payload: bytes = b"") -> bytes:
|
||||
data = bytes([cmd, len(payload)]) + payload
|
||||
body = b"IMPROV" + bytes([1, 3, len(data)]) + data
|
||||
return body + bytes([sum(body) & 0xFF])
|
||||
|
||||
|
||||
BOOT_MARKER = (
|
||||
b"Running through setup()" # ESPHome logs it once per boot on every platform
|
||||
)
|
||||
|
||||
|
||||
def rpc_strings(data: bytes) -> bytes:
|
||||
return data[2 : 2 + data[1]]
|
||||
|
||||
|
||||
def strings(p: bytes) -> list[str]:
|
||||
"""Split length-prefixed strings; raise ValueError when a prefix runs past the end."""
|
||||
out = []
|
||||
while p:
|
||||
if 1 + p[0] > len(p):
|
||||
raise ValueError("string overruns the payload")
|
||||
out.append(p[1 : 1 + p[0]].decode(errors="replace"))
|
||||
p = p[1 + p[0] :]
|
||||
return out
|
||||
|
||||
|
||||
def load_wifi_secrets(path: str) -> tuple[str, str]:
|
||||
"""wifi_ssid and wifi_password from a secrets file; exits 2 (setup error) when it cannot be used."""
|
||||
try:
|
||||
with pathlib.Path(path).open(encoding="utf-8") as f:
|
||||
sec = yaml.safe_load(f)
|
||||
except (OSError, yaml.YAMLError) as exc:
|
||||
print(f"cannot read secrets file: {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
try:
|
||||
raw = (sec["wifi_ssid"], sec["wifi_password"])
|
||||
except (KeyError, TypeError) as exc:
|
||||
print(f"secrets file lacks {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
if not all(
|
||||
isinstance(x, (str, int, float)) and not isinstance(x, bool) for x in raw
|
||||
):
|
||||
print("wifi_ssid and wifi_password must be plain values", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
return str(raw[0]), str(raw[1]) # YAML reads an unquoted number as int
|
||||
|
||||
|
||||
class Dev:
|
||||
def __init__(
|
||||
self, port: str, baud: int, out: str, keep_dtr: bool, ssid: str
|
||||
) -> None:
|
||||
self.ser = serial.Serial()
|
||||
self.ser.port, self.ser.baudrate, self.ser.timeout = port, baud, 0.05
|
||||
if not keep_dtr:
|
||||
self.ser.dtr = False
|
||||
self.ser.rts = False
|
||||
self.reopen(setup=True)
|
||||
self.buf = bytearray()
|
||||
try:
|
||||
self.log = pathlib.Path(out).open("wb") # noqa: SIM115
|
||||
except OSError as exc:
|
||||
print(f"cannot open output file: {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
self.t0 = time.time()
|
||||
self.events: list[tuple[float, int, bytes, bool]] = []
|
||||
self.loglines = 0
|
||||
self.reopens = 0
|
||||
self.boots = 0
|
||||
self.tail = b""
|
||||
self.ssid = ssid
|
||||
|
||||
def reopen(self, setup: bool = False) -> None:
|
||||
# Native USB ports re-enumerate on reset; wait up to 10 s for them.
|
||||
err: Exception | None = None
|
||||
for _ in range(40):
|
||||
try:
|
||||
if self.ser.is_open:
|
||||
self.ser.close()
|
||||
self.ser.open()
|
||||
return
|
||||
except (serial.SerialException, OSError) as exc:
|
||||
err = exc
|
||||
time.sleep(0.25)
|
||||
print(
|
||||
f"port did not {'open' if setup else 'come back'}: {err}", file=sys.stderr
|
||||
)
|
||||
sys.exit(2 if setup else 1)
|
||||
|
||||
def pump(self, dur: float) -> None:
|
||||
end = time.time() + dur
|
||||
while time.time() < end:
|
||||
try:
|
||||
d = self.ser.read(4096)
|
||||
except serial.SerialException:
|
||||
# A dropped native USB port usually means the board reset; make that visible.
|
||||
self.reopens += 1
|
||||
print(
|
||||
f"{time.time() - self.t0:7.2f} PORT RESET (reopen {self.reopens})",
|
||||
flush=True,
|
||||
)
|
||||
self.reopen()
|
||||
continue
|
||||
if d:
|
||||
seen = self.tail + d
|
||||
self.boots += seen.count(BOOT_MARKER)
|
||||
self.tail = seen[-(len(BOOT_MARKER) - 1) :]
|
||||
self.log.write(d)
|
||||
self.log.flush()
|
||||
self.buf += d
|
||||
self.parse()
|
||||
|
||||
def parse(self) -> None:
|
||||
while True:
|
||||
i = self.buf.find(b"IMPROV")
|
||||
if i < 0:
|
||||
keep = max(0, len(self.buf) - 6)
|
||||
self.loglines += self.buf[:keep].count(b"\n")
|
||||
del self.buf[:keep]
|
||||
return
|
||||
self.loglines += self.buf[:i].count(b"\n")
|
||||
del self.buf[:i]
|
||||
if len(self.buf) < 9:
|
||||
return
|
||||
if self.buf[6] != 1: # not a version 1 header: "IMPROV" in log text
|
||||
del self.buf[:6]
|
||||
continue
|
||||
ln = self.buf[8]
|
||||
if len(self.buf) < 10 + ln:
|
||||
return
|
||||
body, ck = bytes(self.buf[: 9 + ln]), self.buf[9 + ln]
|
||||
del self.buf[: 10 + ln]
|
||||
typ, data = body[7], body[9:]
|
||||
ok = (sum(body) & 0xFF) == ck
|
||||
# A malformed frame is counted as bad, so the predicates never index past it.
|
||||
short = len(data) < {1: 1, 2: 1, 4: 2}.get(typ, 0)
|
||||
if typ == 4 and not short:
|
||||
try:
|
||||
# ESPHome sends one trailing byte after the strings (an unused checksum slot).
|
||||
short = data[1] > len(data) - 2
|
||||
strings(rpc_strings(data))
|
||||
except ValueError:
|
||||
short = True
|
||||
self.events.append((time.time() - self.t0, typ, data, ok and not short))
|
||||
self.show(typ, data, ok, short)
|
||||
|
||||
def show(self, typ: int, data: bytes, ok: bool, short: bool) -> None:
|
||||
t = f"{time.time() - self.t0:7.2f}"
|
||||
tag = "" if ok else " BADCHECKSUM"
|
||||
if short:
|
||||
print(f"{t} TYPE{typ} {data.hex()} MALFORMED{tag}")
|
||||
elif typ == 1:
|
||||
print(f"{t} STATE {STATES.get(data[0], data[0])}{tag}")
|
||||
elif typ == 2:
|
||||
print(f"{t} ERROR {ERRORS.get(data[0], data[0])}{tag}")
|
||||
elif typ == 4:
|
||||
strs = [
|
||||
"<ssid>" if x == self.ssid else x for x in strings(rpc_strings(data))
|
||||
]
|
||||
print(f"{t} RPC cmd={data[0]} len={data[1]} {strs}{tag}")
|
||||
else:
|
||||
print(f"{t} TYPE{typ} {data.hex()}{tag}")
|
||||
|
||||
def send(self, cmd: int, payload: bytes = b"", wait: float = 2.0) -> None:
|
||||
self.ser.write(frame(cmd, payload))
|
||||
self.ser.flush()
|
||||
self.pump(wait)
|
||||
|
||||
def wait_for(self, pred, timeout: float, start: int) -> tuple | None:
|
||||
end = time.time() + timeout
|
||||
while time.time() < end:
|
||||
self.pump(0.2)
|
||||
for e in self.events[start:]:
|
||||
if pred(e):
|
||||
return e
|
||||
return None
|
||||
|
||||
|
||||
def ask(
|
||||
d: Dev, label: str, cmd: int, pred, timeout: float = 1.5, payload: bytes = b""
|
||||
) -> bool:
|
||||
"""Send one request and require a reply matching pred; any other nonzero ERROR frame fails it."""
|
||||
print(f"== {label}")
|
||||
start = len(d.events) # before sending, so an immediate reply counts
|
||||
t = time.time()
|
||||
d.send(cmd, payload, wait=0)
|
||||
e = d.wait_for(pred, timeout, start)
|
||||
print(
|
||||
f"reply after {time.time() - t:.1f}s"
|
||||
if e
|
||||
else f"NO reply within {timeout:.0f}s"
|
||||
)
|
||||
errs = [
|
||||
x for x in d.events[start:] if x[1] == 2 and x[3] and x[2][0] and not pred(x)
|
||||
]
|
||||
if errs:
|
||||
print(f"unexpected errors: {[ERRORS.get(x[2][0], x[2][0]) for x in errs]}")
|
||||
return e is not None and not errs
|
||||
|
||||
|
||||
def rpc(cmd: int):
|
||||
return lambda e: e[1] == 4 and e[3] and e[2][0] == cmd
|
||||
|
||||
|
||||
def state(e: tuple) -> bool:
|
||||
return e[1] == 1 and e[3]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
a = argparse.ArgumentParser()
|
||||
a.add_argument("port")
|
||||
a.add_argument("out")
|
||||
a.add_argument("--baud", type=int, default=115200)
|
||||
a.add_argument(
|
||||
"--keep-dtr",
|
||||
action="store_true",
|
||||
help="leave DTR asserted (Pico 2 W CDC sends nothing without)",
|
||||
)
|
||||
a.add_argument("--secrets", required=True)
|
||||
a.add_argument("--settle", type=float, default=3)
|
||||
a.add_argument("--skip-bad", action="store_true")
|
||||
a.add_argument(
|
||||
"--allow-reset",
|
||||
action="store_true",
|
||||
help="a port reset or a reboot in the log does not fail the run",
|
||||
)
|
||||
o = a.parse_args()
|
||||
ssid, pw = load_wifi_secrets(o.secrets)
|
||||
s, w = ssid.encode(), pw.encode()
|
||||
print(f"password length {len(w)} bytes")
|
||||
d = Dev(o.port, o.baud, o.out, o.keep_dtr, ssid)
|
||||
d.pump(o.settle)
|
||||
boots_at_start = d.boots
|
||||
before = d.loglines
|
||||
print("== stray bytes")
|
||||
j = len(d.events)
|
||||
junk = bytes(
|
||||
random.choice([b for b in range(256) if b != 0x49]) for _ in range(300)
|
||||
)
|
||||
d.ser.write(junk)
|
||||
d.ser.flush()
|
||||
d.pump(1.0)
|
||||
# Stray bytes must be ignored silently; the state reply below shows the parser recovered.
|
||||
ok = not any(e[1] == 2 and e[3] and e[2][0] for e in d.events[j:])
|
||||
# A saved network skips provisioning: the board must start unprovisioned.
|
||||
ok &= ask(d, "state", 2, lambda e: state(e) and e[2][0] != 4)
|
||||
if any(state(e) and e[2][0] == 4 for e in d.events[j:]):
|
||||
# The rest of the flow means nothing on a provisioned board; stop before re-provisioning it.
|
||||
print(
|
||||
"board is already provisioned: erase the flash first (a new config name keeps the saved network)"
|
||||
)
|
||||
print("FAIL")
|
||||
sys.exit(1)
|
||||
ok &= ask(d, "info", 3, rpc(3))
|
||||
ok &= ask(d, "netstate", 7, rpc(7))
|
||||
# The scan sends one reply per network and ends with an empty one.
|
||||
ok &= ask(d, "scan", 4, lambda e: rpc(4)(e) and e[2][1] == 0, timeout=10)
|
||||
seen = any(e[1] == 4 and e[3] and e[2][0] == 4 and s in e[2] for e in d.events)
|
||||
print(f"target network in scan: {seen}")
|
||||
creds = bytes([len(s)]) + s
|
||||
if not o.skip_bad:
|
||||
bad_pw = b"wrong-password-0123456789"
|
||||
ok &= ask(
|
||||
d,
|
||||
"provision bad password",
|
||||
1,
|
||||
lambda e: e[1] == 2 and e[3] and e[2][0] == 3,
|
||||
timeout=60,
|
||||
payload=creds + bytes([len(bad_pw)]) + bad_pw,
|
||||
)
|
||||
d.pump(2)
|
||||
# common.yaml sets next_url, so the provisioned reply must carry a URL.
|
||||
ok &= ask(
|
||||
d,
|
||||
"provision good",
|
||||
1,
|
||||
lambda e: (
|
||||
rpc(1)(e) and any(x.startswith("http") for x in strings(rpc_strings(e[2])))
|
||||
),
|
||||
timeout=60,
|
||||
payload=creds + bytes([len(w)]) + w,
|
||||
)
|
||||
d.pump(3)
|
||||
ok &= ask(d, "state is provisioned", 2, lambda e: state(e) and e[2][0] == 4)
|
||||
ok &= ask(d, "netstate", 7, rpc(7))
|
||||
d.pump(2)
|
||||
bad = sum(1 for e in d.events if not e[3])
|
||||
# Errors outside an ask() window, boot included: only the bad password case may report one.
|
||||
errors = sum(1 for e in d.events if e[1] == 2 and e[3] and e[2][0])
|
||||
if errors > (0 if o.skip_bad else 1):
|
||||
print(f"unexpected error frames: {errors}")
|
||||
ok = False
|
||||
reboots = d.boots - boots_at_start
|
||||
if (d.reopens or reboots) and not o.allow_reset:
|
||||
ok = False
|
||||
print(
|
||||
f"frames={len(d.events)} badframes={bad} reopens={d.reopens} reboots={reboots} loglines={d.loglines} "
|
||||
f"(before stray {before})"
|
||||
)
|
||||
print("PASS" if ok and not bad else "FAIL")
|
||||
sys.exit(0 if ok and not bad else 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
# run.sh NAME [improvcli.py args...]: build NAME.yaml (next to this script, or a path) from TREE, erase the flash so no
|
||||
# credentials are saved, flash it over serial and run improvcli.py on PORT. Output lands in out-NAME/.
|
||||
# env: TREE (checkout under test), PORT, PY (checkout python), SECRETS (secrets.yaml with wifi_ssid, wifi_password),
|
||||
# BUILD_LOCK (optional); builds go through ../pio_build.sh with a private PlatformIO directory
|
||||
# ESP chips only (esptool erase). On LibreTiny or RP2040 erase and flash with that platform's tools, then run
|
||||
# improvcli.py directly. Exit status is improvcli.py's: 0 pass, 1 fail, 2 setup failed.
|
||||
set -o pipefail
|
||||
D=$(cd "$(dirname "$0")" && pwd); N=${1:?name}; shift
|
||||
W=${TREE:?set TREE}; PORT=${PORT:?set PORT}; S=${SECRETS:?set SECRETS}; PY=${PY:-$W/venv/bin/python}
|
||||
Y=$N; [ -f "$Y" ] || Y=$D/$N.yaml; Y=$(cd "$(dirname "$Y")" && pwd)/$(basename "$Y"); N=$(basename "$Y" .yaml)
|
||||
O=$D/out-$N; mkdir -p "$O"
|
||||
REV=$(git -C "$W" rev-parse --short=10 HEAD) || { echo "TREE is not a git checkout: $W"; exit 2; }
|
||||
echo "== $N $REV"
|
||||
# the erase runs while the firmware compiles
|
||||
$PY -m esptool --port "$PORT" erase_flash > "$O/erase.log" 2>&1 &
|
||||
ERASE=$!
|
||||
"$(dirname "$D")/pio_build.sh" compile "$N" "$Y" || { wait $ERASE; exit 2; }
|
||||
wait $ERASE || { echo "$N erase failed"; exit 2; }
|
||||
"$(dirname "$D")/pio_build.sh" upload "$N" "$Y" "$PORT" || exit 2
|
||||
sleep 1
|
||||
rm -f "$O/raw.bin"
|
||||
$PY "$D/improvcli.py" "$PORT" "$O/raw.bin" --secrets "$S" "$@" 2>&1 | tee "$O/improv.txt"
|
||||
Loaded 100 of 1102 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user