mirror of
https://github.com/esphome/esphome.git
synced 2026-11-17 02:25:58 +00:00
Compare commits
94
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcc177acbf | ||
|
|
94cb20d9e1 | ||
|
|
82f2203cc3 | ||
|
|
23a83a9f3d | ||
|
|
59f6affb51 | ||
|
|
4a02a0d4ba | ||
|
|
85f0011e6b | ||
|
|
b617926576 | ||
|
|
34881c3e3c | ||
|
|
71f55f270e | ||
|
|
1a9cce8bb8 | ||
|
|
b6c5a6e7c2 | ||
|
|
149b9280eb | ||
|
|
7a09548cdc | ||
|
|
1a07f39062 | ||
|
|
4c99a0f1ed | ||
|
|
875b8faf43 | ||
|
|
47b27a93a6 | ||
|
|
3c8940bfef | ||
|
|
4886238892 | ||
|
|
d611d9a3ca | ||
|
|
aa2a31647d | ||
|
|
f18de29d20 | ||
|
|
4eb24d78b0 | ||
|
|
1658efa9e7 | ||
|
|
feebc28853 | ||
|
|
86385ea2fe | ||
|
|
9bee9629c6 | ||
|
|
422ba0662e | ||
|
|
4b4d787884 | ||
|
|
34d68a0fa0 | ||
|
|
7caa7de696 | ||
|
|
9b23184e10 | ||
|
|
2f9abefe3f | ||
|
|
84079c07e2 | ||
|
|
110f854246 | ||
|
|
b7dbf17469 | ||
|
|
b91750c325 | ||
|
|
6c5bdd9251 | ||
|
|
92d2a457fa | ||
|
|
be41bc41e4 | ||
|
|
c0cf8f6b19 | ||
|
|
49d1f61df7 | ||
|
|
95c67a5523 | ||
|
|
8045a11909 | ||
|
|
208d0021a9 | ||
|
|
1da90be339 | ||
|
|
4b48ff0255 | ||
|
|
fed2b2995e | ||
|
|
ae48c7ab4c | ||
|
|
6f6e34ca40 | ||
|
|
0561d90334 | ||
|
|
78ef1fd104 | ||
|
|
a6bca49020 | ||
|
|
2e68c56908 | ||
|
|
a1fecebb09 | ||
|
|
32b9d4cbe7 | ||
|
|
c53401a28d | ||
|
|
6b7d17c762 | ||
|
|
93a3306d82 | ||
|
|
54d3477240 | ||
|
|
5f9d83d293 | ||
|
|
43864283b4 | ||
|
|
4efbb38b86 | ||
|
|
045374965f | ||
|
|
39a939720f | ||
|
|
a79e51e784 | ||
|
|
517f0d6d48 | ||
|
|
1327d0ddc5 | ||
|
|
2adb544e7a | ||
|
|
48905beb96 | ||
|
|
ed401814bf | ||
|
|
0245db6285 | ||
|
|
07ee0f9f04 | ||
|
|
3d34ad572b | ||
|
|
5c9033e04d | ||
|
|
e91934e4bd | ||
|
|
602cbff184 | ||
|
|
da274f92d3 | ||
|
|
c6f330458a | ||
|
|
dbb4ba769a | ||
|
|
0eb4a09935 | ||
|
|
ed9e5cff58 | ||
|
|
7acd023079 | ||
|
|
5623a5d511 | ||
|
|
4f8c2239dd | ||
|
|
07bbad4061 | ||
|
|
1cd99ce6d6 | ||
|
|
91db9d86d0 | ||
|
|
2f900f23d7 | ||
|
|
373224c141 | ||
|
|
1dff22f578 | ||
|
|
c2eb540b37 | ||
|
|
fad21e3f14 |
No files matched your search
@@ -47,6 +47,15 @@ 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
|
||||
|
||||
@@ -81,7 +90,17 @@ 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), a results table
|
||||
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
|
||||
(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.
|
||||
@@ -118,8 +137,13 @@ 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)` (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.
|
||||
- `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.
|
||||
- `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),
|
||||
@@ -134,7 +158,7 @@ recorder, dump saver and decoder, cover cycle driver), `online_image/`
|
||||
(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), `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 Line 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, 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
|
||||
|
||||
## Templates in `$SKILL/templates`
|
||||
|
||||
@@ -143,6 +167,8 @@ 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`,
|
||||
@@ -159,7 +185,8 @@ capture decoder, RTL8720C ROM dump versus report matcher), `api_outgoing/` (wake
|
||||
action package with per-board files and an OTA flash variant), `led_wire/` (DUT config and header that reads the
|
||||
LED strip pads back with RMT RX and an SPI slave), `uart_sim/` (simulator header, common package, per-build parts and run files) and `remote_base/` (common
|
||||
package, transmit script, per-board templates and the ESP8266 software sender), `i2c_fake/` (fake I2C device
|
||||
headers with their test configs, see `fake_i2c.md`).
|
||||
headers with their test configs, see `fake_i2c.md`), `network_dns/` (DNS loss diagnostics for
|
||||
`network: priority`, see `network_dns.md`).
|
||||
- `microphone_http_stream/`: base config, fake counter and USB microphone variants and the multi-reader client,
|
||||
described in `reference/recipes/microphone_http_stream.md`.
|
||||
|
||||
@@ -196,6 +223,10 @@ 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.
|
||||
|
||||
@@ -29,6 +29,17 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
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.
|
||||
- The ROM `rijndaelKeySetupEnc` at 0x40009300 builds a correct 128-bit schedule (FIPS-197 A.1 words match) but does not
|
||||
return the round count, so the SDK's `aes_encrypt` loops on garbage rounds and the board Soft WDT resets in
|
||||
`rijndaelEncrypt`. Do not `--defsym` it over the libcrypto copy; a wrapper in the SDK signature (returns -1 unless
|
||||
128 bits, calls the ROM, returns 10) passed the FIPS vectors and a WPA2 soft AP join.
|
||||
- A CH340 D1 mini can give garbage at 921600 baud; `logger: baud_rate: 460800` with `serial_capture.py --baud 460800`
|
||||
carries long `dump: raw` frames cleanly.
|
||||
- Opening a CH340 port resets the boards that wire RTS to reset, even with `--released`; the first boot in a capture
|
||||
can be that reset.
|
||||
|
||||
## ESP32 classic devkit
|
||||
|
||||
@@ -50,6 +61,8 @@ 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
|
||||
|
||||
@@ -72,6 +85,27 @@ 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-S3: GPIO43/44 cannot be used to cross-wire two UARTs: the UART0 IOMUX TX is lost when another UART takes the
|
||||
pad as RX. TX17/RX16 and TX16/RX17 work. A task woken by `vTaskDelay` runs about 0.5 ms after the tick, on dev too.
|
||||
|
||||
## 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)
|
||||
|
||||
@@ -99,6 +133,27 @@ 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.
|
||||
- W5100S-EVB-Pico with its USB attached shows a CDC port (`2e8a:1027`) while it runs ESPHome, so `esphome upload
|
||||
--device <that port>` (picotool) flashes it with or without `interrupt_pin`.
|
||||
|
||||
## BW15 kit (RTL8720CF, LibreTiny rtl87xx)
|
||||
|
||||
@@ -140,6 +195,14 @@ 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.
|
||||
- A BW15 kit whose CH340 drops off the bus at "Initializing WIFI" on every boot (a boot loop on any image) is short of
|
||||
USB power: use another hub port or a powered hub. Read the results over API logs between resets meanwhile.
|
||||
|
||||
## BK7238, WB3S, CB3S (BK7231N) (LibreTiny bk72xx, CH340, RTS on CEN)
|
||||
|
||||
@@ -191,6 +254,9 @@ Ports are not listed on purpose: they follow the USB hub port and change on ever
|
||||
... !=`) and the old image stays.
|
||||
- Power save: on the BK7238, `power_save_mode: light` with LibreTiny 1.14.0 gives ping times of 3 to 6 s because
|
||||
the BDK sets a listen interval of 30 beacons when `CFG_LOW_VOLTAGE_PS` is 1 (esphome#19491).
|
||||
- LibreTiny's builder adds `-D'delay(ms)=delayMilliseconds(ms)'`, so `esphome::delay` is really
|
||||
`esphome::delayMilliseconds` on BK72xx and a YAML lambda calling `delay()` fails to compile on dev. In a header use
|
||||
`(esphome::micros)()` to dodge the `main.cpp` function-like macros.
|
||||
|
||||
## BW12 and other AmebaZ boards (RTL8710BX, LibreTiny rtl87xx)
|
||||
|
||||
@@ -265,6 +331,10 @@ 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
|
||||
|
||||
@@ -294,6 +364,10 @@ 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
|
||||
@@ -347,6 +421,16 @@ 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;
|
||||
@@ -426,3 +510,55 @@ 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`.
|
||||
- nPM1300 charger registers with the reset-value defaults (32 mA, 3.6 V, 10 %, 2.9 V, 1000 mA; #22769): 0x0308/09 =
|
||||
08/00, 0x030A/0B = CF/01, 0x030C = 0x030D = 02, 0x030E = 0x030F = 00. BCHGDISABLESET (0x0306) reads back 0x02 when
|
||||
the NTC check is off (`thermistor_resistance: none`, ADCNTCRSEL 0x050A = 0) and 0x00 with 10k.
|
||||
- No cell, charger on: BCHGCHARGESTATUS 0x05 (bit 0 plus trickle), VBAT about 3.61 V with VTERM 3.6 V (4.23 V with
|
||||
4.2 V), 0.02 V with the charger off. NTCSTATUS (0x0332) and DIETEMPSTATUS (0x0333) read 00 throughout, so the NTC
|
||||
hot and cold states cannot be reached on this board. BCHGERRREASON stays 00 across on/off toggles.
|
||||
- A bare `charger:` key fails validation ("expected a dictionary"); use `charger: {}`. `esphome compile
|
||||
--only-generate` with a private PLATFORMIO_CORE_DIR is enough to check the generated NPM1300Config initializer
|
||||
without a board; a fresh private PlatformIO dir builds four nRF54 configs in about 10 min. A capture started before
|
||||
the flash holds the old firmware first; cut at the last `Log initialized`.
|
||||
|
||||
## 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.
|
||||
|
||||
## Harness tricks and old releases
|
||||
|
||||
- Protected members and methods can be reached from a test header listed in `esphome: includes:` with the explicit
|
||||
instantiation access trick (`template struct Rob<Tag, &C::member>;`), even on `final` classes; declare the robbers at
|
||||
global scope.
|
||||
- API driven light effects that write template outputs every loop (about 5k writes/s) can lag API commands by seconds:
|
||||
wait for the API state to show each command before reading results.
|
||||
- Building ESPHome 2025.10.x (pioarduino ESP-IDF 5.4.2) from a path under `/tmp` on macOS fails with "Multiple ways to
|
||||
build the same target" (the /tmp to /private/tmp alias); put the yaml, build and PLATFORMIO_CORE_DIR elsewhere. Its
|
||||
IDF penv under Python 3.14 lacks the tools: install `-r packages/framework-espidf/tools/requirements/requirements.core.txt`,
|
||||
then pin `idf-component-manager~=2.1.0 esp-idf-kconfig~=2.5.0` (newer ones reject interface_version 3).
|
||||
@@ -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
|
||||
- [`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`)
|
||||
- [`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
|
||||
@@ -18,11 +18,12 @@ One file per component, named after it:
|
||||
- [`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
|
||||
- [`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
|
||||
- [`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
|
||||
- [`scheduler.md`](scheduler.md): loop wake A/B, interval startup delay and control from lambdas, RP2 scheduler lock under IRQ and lwIP load
|
||||
- [`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
|
||||
@@ -36,8 +37,8 @@ One file per component, named after it:
|
||||
- [`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
|
||||
- [`uart_sim.md`](uart_sim.md): UART sensors simulated on a classic ESP32 with loopback and cross-wired UARTs
|
||||
- [`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
|
||||
- [`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
|
||||
@@ -63,11 +64,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
|
||||
- [`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
|
||||
- [`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
|
||||
- [`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
|
||||
- [`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
|
||||
@@ -83,3 +84,10 @@ One file per component, named after it:
|
||||
- [`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
|
||||
- [`tuya.md`](tuya.md): Tuya MCU simulator on a cross-wired second UART (handshake, every datapoint type, command frames logged), hub vs entity order, dump A/B
|
||||
- [`serial_proxy.md`](serial_proxy.md): simulated serial device on a cross-wired UART, byte-exact client with read pauses, ASH tap ACK timing
|
||||
- [`tcp_link.md`](tcp_link.md): tcp packet_interface link, host to host pair on one computer, raw framing peer, entity_transport both ways
|
||||
- [`network_dns.md`](network_dns.md): network.priority Ethernet plus Wi-Fi losing lwIP DNS servers (#19805)
|
||||
@@ -62,3 +62,40 @@ Results: https://github.com/esphome/esphome/pull/16445#issuecomment-6335435397
|
||||
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.
|
||||
|
||||
## API overflow buffer driven and counted on the device (#22771)
|
||||
|
||||
`scripts/api/overflow/`: `ovfwrap.hpp` wraps `APIOverflowBuffer::enqueue_iov` and `try_drain` with `-Wl,--wrap` and
|
||||
counts calls and bytes; the `try_drain` symbol differs per platform (`...6socket11LWIPRawImplE` on ESP8266,
|
||||
`...6socket13BSDSocketImplE` on ESP32 IDF), so pass it as a substitution and check `nm` shows both `__wrap_` symbols
|
||||
(a wrong name silently drops the wrapper). ESP-IDF builds keep `nm` in the IDF tools cache
|
||||
(`xtensa-esp-elf/*/xtensa-esp-elf/bin/`), not under the PlatformIO directory. `putbe-common.yaml` (60 sensors, four
|
||||
800 char text sensors flooded every 50 ms, counters as sensors, plus two udp `entity_transport` links) and
|
||||
`apitest.py HOST OUT` (2 KB receive buffer, 3 x 6 s `pause_reading`, validates every burst state and the final states;
|
||||
key in `.apikey`). Result on #22771: 82 to 159 enqueues per run on a D1 mini and an ESP32, no drops.
|
||||
|
||||
`scripts/entity_transport/trcheck.py` compares remote entity values with the sender's published ones over the API on
|
||||
both boards; it accepts late updates and checks floats by the formula the sender uses, so only values the sender never
|
||||
published fail. Declare remote entities for both the base and the PR name of the peer so one image serves all four
|
||||
pairings. Facts from that run:
|
||||
- Xtensa GCC (lx106 and esp32) defines `__CHAR_UNSIGNED__`; macOS host builds use signed `char`, so a host harness
|
||||
can miss a sign bug in byte handling.
|
||||
- udp `packet_interface` with broadcast between a D1 mini and an ESP32 loses most hdlc acks; unicast `addresses:` still
|
||||
resets the reliability session a few times a minute (dev and PR alike). A D1 mini's API can deliver states 5 to 11 s
|
||||
late under that load.
|
||||
@@ -0,0 +1,42 @@
|
||||
# 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`.
|
||||
@@ -0,0 +1,47 @@
|
||||
# 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.
|
||||
@@ -55,3 +55,38 @@ real device uses, decode an Android HCI snoop: a Read By Type response lists its
|
||||
- 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.
|
||||
|
||||
## Scan complete never arrives (#22770)
|
||||
|
||||
`scripts/ble_scan_complete/`: `scan.yaml` is a proxy config like the report's (ESP32-C6, interval = window = 1100 ms,
|
||||
debug sensors, `api: reboot_timeout: 0s`, a `duration` substitution, 5 s by default; the validator wants at least
|
||||
three intervals, so 2 s is refused). The tracker watchdog is `duration * 2`, so a short duration shortens it too.
|
||||
`scaninst.yaml` adds `scan_inst.hpp` and five `-Wl,--wrap` flags that count one scan's duration timer through
|
||||
Bluedroid: `BTM_BleScan` starts and stops, `btu_start_timer(BTU_TTYPE_BLE_SCAN)`, the timer's alarm firing (a shim on
|
||||
its `osi_alarm_new` callback, BTC task), `btm_ble_timeout` (BTU task) and the INQ_CMPL handed to `btc_transfer_context`
|
||||
(PID 5, act 3; the param is 108 bytes in libbt, so do not compare with the C++ `sizeof`). A 30 s interval logs them as
|
||||
`scaninst`; a lost completion shows where the chain stopped (timer > fire + 1, fire > timeout, timeout > cmpl_post, or
|
||||
cmpl_post above the ESPHome-side `ends / 2`). `ha.py HOST OUT SECONDS [--toggle S --jitter J]` is the Home Assistant
|
||||
stand-in (raw adverts, scanner state, set mode passive once, optional active/passive toggles). `soak.sh TAG HOST
|
||||
SECONDS [ha.py options]` (env PORT) runs a bounded serial capture plus ha.py, with the API key in `apikey.txt`.
|
||||
`wait.sh CAPTURE SECONDS [FROM_LINE]` blocks until a timeout, drop or unexpected-state line and prints the counters.
|
||||
- Bluedroid and IDF log lines reach the ESPHome log as tag `esp-idf` at VERBOSE (`[V][esp-idf:000][BTU_TASK]: E ...`),
|
||||
so a user capturing at INFO over the API never sees a Bluedroid error.
|
||||
- A stop from Home Assistant landing just after the timer fired (toggle period 5.03 s with 0.08 s jitter against 5 s
|
||||
scans hits it about once per 20 minutes) gives `Unexpected state: STOPPING on scan complete`, `stop complete -
|
||||
status 1`, `BTM_BleScan scan not active`; the tracker recovers. A stop while STARTING logs `Cannot stop scan:
|
||||
STARTING` and the mode change waits for the next restart.
|
||||
- With about 55 devices around (about 95 adverts/s), no lost completion in about 2800 natural 5 s cycles on 2026.10.2
|
||||
(VERBOSE and INFO builds) plus about 670 toggled stops, and none on dev.
|
||||
@@ -15,3 +15,31 @@ ends with `DONE fails=N`, and T6 prints whether each setter woke a sleeping chip
|
||||
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`), `flashmac.sh NAME MAC` (finds the port by MAC, flashes, waits for the API), `buildall.sh NAME...`,
|
||||
`runall.sh A_MAC B_MAC` (both roles). Needs `secrets.yaml` with `api_key` and a `.apikey` file with the same key next
|
||||
to the configs.
|
||||
|
||||
- Two boards with an E07-M1101D each, 433.92 MHz GFSK 4800. Ports change; flash by MAC.
|
||||
- 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.
|
||||
- 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.
|
||||
@@ -24,3 +24,11 @@ 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,3 +5,41 @@
|
||||
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. `udtest.hpp` adds the UDP streams.
|
||||
- `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. The `tick` and `stream_interval` substitutions set the load.
|
||||
- `urlink.yaml` + `abrun.sh V RUN`: minimal unicast A/B (one raw link plus `on_receive`), PR against base.
|
||||
- `rglink.yaml` + `rgrun.sh E32V D1V`: 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. `validation_cases.py`: writes 41 ok_/bad_ configs; 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.
|
||||
@@ -151,3 +151,43 @@ Prefer this to glitching the wire. Holding SDA low by rerouting the pin (`esp_ro
|
||||
`SIG_GPIO_OUT_IDX` and back to `I2CEXT0_SDA_OUT_IDX`) wedges the ESP-IDF controller, which then needs
|
||||
`i2c_master_bus_reset()` after each glitch, and glitches timed onto writes left the VL53L0X answering 0x00 until a
|
||||
power cycle.
|
||||
|
||||
## WeiKai WK2168 on I2C (#22759)
|
||||
|
||||
`templates/i2c_fake/wkfake.hpp` + `wk-common.yaml`: answers 0x10 to 0x17 (`0 A1 A0 1 0 C1 C0 F`), keeps only A3..A0 of
|
||||
the register byte and builds the 6 bit address C1C0A3..A0, models the globals (a GRST write resets the channels in its
|
||||
low nibble and logs `!!!!! GRST WRITE`), per-channel SCR/LCR/FCR/baud/RFCNT/FSR and FIFOs (TX logged, RX injected with
|
||||
`inject_rx`, dropped when SCR is off), GPDIR/GPDAT with `set_input()`. It classifies each transaction W / P (1 byte
|
||||
pointer) / R / WR (repeated start); `fail_reads`, `fail_ptr` and `every_n` inject NACKs and the fake counts whether
|
||||
the next read is a retry of the same register. The hub sets up at BUS - 0.1, so the `on_boot` that swaps the bus uses
|
||||
priority 999.95, not 700. The driver polls RFCNT and FSR of every channel and GPDAT every loop: log only writes,
|
||||
changes and a `trace` window, never every read. `wk-map-check.cpp.example` is the host check that extracts
|
||||
`i2c_address()`/`i2c_register()` from both trees with awk and compares all registers. On #22759 the base build's
|
||||
GPIO writes hit GRST and reset UART channel 0.
|
||||
|
||||
## BMI270 config upload and BMM150 aux (#22778)
|
||||
|
||||
`bmi270fake.hpp` + `bmi270-common.yaml` + `bmi270-motion-aux.yaml`: BMI270 register file with reset values; config
|
||||
upload port (INIT_ADDR word address, INIT_DATA into 8 KB) where INTERNAL_STATUS reads 0x01 only when every byte was
|
||||
written once and FNV-1a equals `expected_fnv` (0x95BB75B5 for the current table, computed on the host from
|
||||
bmi270_config.h), else 0x02. Aux interface: AUX_DEV_ID selects the BMM150, manual mode turns AUX_WR_ADDR/AUX_RD_ADDR
|
||||
writes into BMM150 writes and 1/2/6/8 byte reads into AUX_X.., STATUS.aux_busy for two polls, auto mode mirrors the
|
||||
BMM150 data. Fault knobs: `bmm_mode` (absent, wrong chip id), `busy_stuck`, `stuck_from_aux_op` (busy stuck from the
|
||||
Nth aux transfer: 1 power-on, 2 soft reset, 3 chip id, 4 to 6 trim, 7 normal mode), `nack_at` (main-bus transaction
|
||||
N). `norm_fnv` hashes register-level effects and leaves STATUS polls out (their count depends on timing). Heap is
|
||||
sampled at INIT_CTRL=0/1 and inside each INIT_DATA burst; `-DBMI_FAKE_WRAP_MALLOC` with `-Wl,--wrap=malloc` in
|
||||
`platformio_options: build_flags` counts malloc() during the upload (works on ESP8266 and native ESP-IDF builds; the
|
||||
link fails without the wrap, so a clean link proves it applied).
|
||||
- Host side: copy `bmi270-host-harness.cpp.example` (as a `.cpp`) and the fake into `tests/components/bmi270/` of both
|
||||
worktrees, plus a `benchmark.yaml` with `esphome: build_flags: [-DUSE_BMI270_BMM150, -DUSE_LOG_LISTENERS,
|
||||
-DESPHOME_LOG_MAX_LISTENERS=4]` (the unit test build does not use defines.h; this is how to get a component's
|
||||
optional code and log capture into it); the base also needs the PR's `__init__.py` manifest override.
|
||||
`bmi270-setters.py` turns each tree's generated main.cpp (`esphome compile --only-generate`) into the setter list
|
||||
the harness applies, so codegen changes (setters skipped at defaults) are tested as generated.
|
||||
`bmi270-host-run.sh.example TREE NAME SETTERS [32]` runs it (32 forces the Arduino burst branch);
|
||||
`bmi270-host-compare.py BASE.report PR.report` merges base's split INIT_ADDR writes, compares every config, fault and
|
||||
per-step scenario, maps the NACK sweep through the merged stream and lists every log difference.
|
||||
`bmm150-sweep.cpp.example` compares a decoder against a namespace-renamed copy of the base header bit for bit.
|
||||
- A planted one byte burst offset gave INTERNAL_STATUS 0x02 and "Config file upload failed" at both burst sizes.
|
||||
- Sensor publishes log at VERBOSE now, so log entity states from an interval lambda.
|
||||
- In zsh, `git show $H:esphome/...` applies the `:e` history modifier: write `"${H}:esphome/..."`.
|
||||
@@ -86,3 +86,14 @@ Notes:
|
||||
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.
|
||||
|
||||
## Subscription order and dump order (#22725)
|
||||
|
||||
- `hadrive.py` also prints `<phase> SUBORDER NNN <line>` in the order the device sent the subscriptions (the SUB lines
|
||||
are sorted). `grep -v SUBORDER drive.txt` diffs the sets, `grep SUBORDER` the order.
|
||||
- Dump block order per build: `grep -a -E "\[C\]\[" boot1.txt | sed -E 's/^.*\[C\]\[([a-z_.0-9]+):[0-9]+\]: (.{0,40}).*/\1 | \2/' |
|
||||
awk -F' [|] ' '{ if ($1!=p) {print $1 " :: " $2; p=$1} }'` prints one line per component run; strip the `:NNN`
|
||||
line numbers before diffing dump text between builds.
|
||||
- Idle ESP8266 free heap in this config swings by 2 kB between readings; compare the steady reading (the fifth one
|
||||
after boot) per boot, which matched the heap_size change exactly (+168 B for 15 import entities on #22725).
|
||||
- The wizard light (`l_wiz`) needs #21908; a stack based before it needs it dropped on both builds (`NO_LIGHT=1`).
|
||||
@@ -14,3 +14,37 @@ On the NiceMCU WB3S V1 board (BK7238), P26 and P24 are on the right-hand header.
|
||||
|
||||
Fake devices that need no real chip (in-firmware buses, the Pico 2 W target, the DS2482-800 simulator, NACK
|
||||
injection) are in [fake_i2c.md](fake_i2c.md).
|
||||
|
||||
## I2C wire A/B of a bus change (#22780, write_prefixed)
|
||||
|
||||
`scripts/i2c_wire_ab/`.
|
||||
- Host (`host/run.sh TREE OUT`, then `host/compare.py BASE PR`): copies a harness into the tree's
|
||||
`tests/components/i2c/` (removed again afterwards) and runs `script/cpp_unit_test.py i2c`. `extract.py` cuts the
|
||||
Arduino and ESP-IDF `write_readv`/`transfer_` bodies out of the tree and compiles them against the tree's real headers
|
||||
with stub `Wire.h` (esp8266 core 3.1.2 and arduino-pico 6.3.2 buffer rules, 128 and 256 bytes) and a stub
|
||||
`driver/i2c_master.h` (IDF 5.5.5 checks: at most SOC_I2C_CMD_REG_NUM jobs, NACK before STOP); the software bus is
|
||||
compiled whole with `#define InternalGPIOPin wab::FakePin` over a bit-level target. Every bus emits one token stream
|
||||
(`S 90+ 02+ ... P`, `Sr`, `rA0+`), with mallocs counted through macOS `malloc_logger` (ASan is dropped on macOS).
|
||||
Stub headers must live outside the test dir (a subfolder there is taken as a platform domain) and reach the build
|
||||
through a `benchmark.yaml` `esphome: build_flags: [-I...]`; `.h` files in the test dir are included into main.cpp, so
|
||||
generated bodies are `.inc`. Explicit-instantiation member robbers must be declared at global scope. The sources are
|
||||
stored as `.cpp.example`, `.h.example` and `.hpp` so the repo's C++ lints skip them; `run.sh` copies them back.
|
||||
- Device: `dev/snf.hpp` is a GPIO interrupt sniffer on the I2C pads (an ESP32-C2 with an ADS1015: SDA 4, SCL 5,
|
||||
`dev/c2common.yaml`) plus the same case sweep and `-Wl,--wrap=malloc`; at 10 to 20 kHz on the C2 it still drops a bit
|
||||
in about 0.5 % of transactions (mostly at the chip's NACK), so capture three runs per build and judge with
|
||||
`clean.py`/`maj.py`. On the software bus it is exact. `dev/pdslave.hpp` + `snfpd.hpp` (`pdcommon.yaml`) turn an
|
||||
ESP32-PICO-D4 into its own target at 0x48 on GPIO32/33 (ACKs every byte, so 300-byte writes reach the wire): exact on
|
||||
6 of 6 captures at 25 kHz once one warm-up probe runs before the sweep (the ISR runs from flash; IRAM_ATTR on header
|
||||
inline functions fails to link with l32r literal errors). `mksw.py` turns a tree's LibreTiny-only software bus into
|
||||
a header so an ESP32 build can run it on real pins. The ADS1015 NACKs the third byte after the pointer, so long
|
||||
writes on that chip end there on every build.
|
||||
- `ard/swp.hpp` is the same sweep for ESP8266 (GPIO interrupt sniffer on GPIO4/5), RP2 (raw IO_IRQ_BANK0 handler) and
|
||||
BK72xx (no sniffer), with `ard/common.yaml` plus a board file (`d1.yaml`, `pico.yaml`, `bk.yaml`). Heap counters per
|
||||
platform: ESP8266 `-Wl,--wrap=malloc` with `__wrap_malloc` marked IRAM_ATTR (in flash it crash-loops with
|
||||
IllegalInst at the wrapper's first instruction); arduino-pico already wraps malloc and `_malloc_r` (a second wrap is
|
||||
a duplicate symbol), so wrap `__malloc_lock` (malloc and free each count once); LibreTiny already wraps malloc into
|
||||
pvPortMalloc, so wrap `pvPortMalloc`. Each image checks itself with `ALLOC_PROBE 1`.
|
||||
- Facts: on a D1 mini without a target, register writes up to 128 bytes total show `S 90- P`, longer ones fail with
|
||||
rc 6 and nothing on the wire; a write+read whose address is NACKed leaves no STOP (`S 90-`), dev too.
|
||||
arduino-pico: after a register write over 256 bytes, the next empty write (a probe) sends the stale buffer to the
|
||||
failed write's address.
|
||||
@@ -0,0 +1,65 @@
|
||||
# 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).
|
||||
|
||||
## Improv serial scan reply over the logger UART (#22758)
|
||||
|
||||
- `scripts/improv_scan/improvscan.py PORT OUT` sends an Improv RPC request scan (command 0x04) and parses each reply
|
||||
frame (checksum, strings, auth field bytes and length). It opens the port with DTR and RTS low, but a D1 mini and a
|
||||
classic ESP32 still reset, so it waits 30 s before sending.
|
||||
- A connected device frees its scan list, so the reply is just the end-of-list frame. Add a `wifi_info:`
|
||||
`scan_results:` text sensor to keep the list.
|
||||
- For an auth `NO` entry you need an open network in range: run an AP-only build without a password on a second board
|
||||
(`scripts/log_macros/openap32.yaml`).
|
||||
- Scan replies list the neighbours' SSIDs; filter them out of anything you post.
|
||||
|
||||
## Log macro rewrites, A/B by log text (#22758)
|
||||
|
||||
`scripts/log_macros/`: `lm-common.yaml` (one entity of every common platform plus `improv_serial` and `web_server`),
|
||||
`drive.py HOST OUT` (presses the exercise button, reads API sensor states and web_server JSON) and `norm.py SERIAL`
|
||||
(keeps config dump lines, `lm` lines and state lines, strips addresses, timings and other volatile text) so two
|
||||
builds' captures diff cleanly. Recent ESPHome logs sensor states and switch, light and fan calls only at VERBOSE; at
|
||||
DEBUG a log diff sees none of them.
|
||||
@@ -61,3 +61,10 @@ 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,3 +34,11 @@ 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.
|
||||
@@ -31,3 +31,49 @@ replies, to check what the module does with no component in the way.
|
||||
- `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.
|
||||
|
||||
### SIM7080G with a live SIM
|
||||
|
||||
- A SIM whose plan does not cover LTE-M or NB-IoT never registers on the SIM7080G: CEREG goes 0 (not searching) right
|
||||
after CFUN=1, 2 (searching) for about 60 s, then 3 (denied) for a minute or two, then searching again, with CSQ 19 to
|
||||
31. COPS=? lists the Cat-M networks; manual COPS fails (ERROR or denied), so don't retry it. PPP, attach timing and a
|
||||
warm reboot during PPP need a SIM whose plan covers LTE-M.
|
||||
- esp_modem 2.1.0 sends `AT+CGATT=1`, `AT+CGATT?` and `AT+CEREG?` with a 500 ms timeout. Unregistered, `CGATT=1`
|
||||
holds the AT channel (15.6 s denied in the passthrough, about 40 s in the component, over 2 minutes with a SIM that
|
||||
has no data plan) and the module drops every command sent meanwhile: no echo, no reply (an `AT+CMUX=0` sent then is
|
||||
lost).
|
||||
- `ATD*99#` sometimes answers `CONNECT 150000000` without an attach. The module then sits in data mode, sends no LCP,
|
||||
ignores AT for minutes, and esp_modem's autodetect returns 0 forever (dev logs the wiring hint). A guarded `+++`
|
||||
(1.1 s silence, `+++`, 1.1 s) returns OK at once; give the passthrough an `Escape` template button doing
|
||||
`write_str("+++")` between two 1200 ms delays.
|
||||
- `AT+CFUN=0` powers the SIM down only about 1.7 s after OK (`+CPIN: NOT READY` URC), and the component reads
|
||||
`+CPIN: READY` before that, so `init_at: [AT+CFUN=0]` cannot fake a missing SIM. There is no reliable no-SIM path
|
||||
without removing the SIM.
|
||||
- `AT+CFUN=1,1` left the module silent for 20 s to 2.5 min.
|
||||
- Pins that reach nothing, for the no-modem path on an M5Stack Atom (or any ESP32): `rx_pin: GPIO22`, `tx_pin: GPIO19`.
|
||||
- Drive the component build with send_at buttons (`AT DIAL` = `ATD*99#`, `AT CFUN1`, `AT+CMGR=9` for an error text)
|
||||
and the `Restart` button; `mdrive.py press:NAME`. A `send_at` needs about 3 s before a restart to go out.
|
||||
|
||||
## SIM7670G on the Waveshare ESP32-S3-SIM7670G-4G (#22581)
|
||||
|
||||
- Board: ESP32-S3 console on a CH343 (UART0, so `logger: hardware_uart: UART0`; the default USB logger prints
|
||||
nothing). Modem UART: ESP TX GPIO18, ESP RX GPIO17, 115200, `model: SIM7670`. The modem is powered by the "4G" DIP
|
||||
switch, no GPIO power-up needed. Module SIM7670G-MNGV, firmware V1.9.05.
|
||||
- The module's own USB enumerates as four `05c6:9330` ports; one of them is an AT port that works next to the
|
||||
component's UART (another is a binary diag stream). Send AT lines there to read CEREG, CGDCONT, CEER or SMS while the
|
||||
ESP runs. Run AT experiments with an idle ESP image (a hex passthrough), or the component's own reconnects (CFUN=4,
|
||||
CGDCONT) get mixed into the results.
|
||||
- Hex passthrough with frame buttons: `uart: debug: after: timeout: 40ms` with `log_hex`, buttons that `uart.write`
|
||||
SABM/DISC/CLD/AT frames per DLCI (FCS: CRC-8 reversed poly 0xE0 over address, control, length, then 0xFF minus it)
|
||||
and buttons that write runs of 0xF9.
|
||||
- Findings: echo is on after power-up or an AT channel reset, and esp_modem's mode guess takes the echoed LCP probe for
|
||||
a PPP reply (`Autodetect mode: 2`), the start of #22581. After an ESP reset during PPP the module stays in CMUX and
|
||||
ignores SABM/DISC/CLD/AT/+++ (it answers SABM0 with a UA only now and then); a burst of 4 KB of 0xF9 usually makes it
|
||||
print `QCRDY` and fall back to command mode with echo on (worked 10 times, failed 4 tries once after a reflash).
|
||||
- A PDP context written at CFUN=4 makes the next attach fail with `+CEER: EMM_CAUSE_ESM_FAILURE` (CEREG 3) until a
|
||||
CFUN=0 cycle; written at CFUN=0 it attaches in about 8 s. After each attach the network can rewrite context 1's APN to
|
||||
its own name. An empty `apn: ""` validates and attaches (the network picks the APN).
|
||||
- A SIM can attach and get an IP and DNS while no TCP or ICMP traffic comes back, through PPP (CMUX and data mode) and
|
||||
through the module's own `AT+HTTPACTION` (706) and `AT+CPING`: that is the carrier side, not the component.
|
||||
- SMS: when the SIM's SM store is full, set the receive store to ME with `AT+CPMS="SM","SM","ME"`. Messages are UCS2
|
||||
hex in text mode; decode in memory only, never into a log, and keep SIM data (numbers, identifiers) out of results.
|
||||
@@ -0,0 +1,33 @@
|
||||
# network.priority DNS loss (#19805, espressif/esp-idf#19082)
|
||||
|
||||
With two interfaces in `network: priority:` on ESP32, ESPHome sets CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF and pins
|
||||
the default with `esp_netif_set_default_netif()`. In that mode a DHCP ACK only fills the netif's own DNS cache; lwIP's
|
||||
global table is written only by `esp_netif_set_default_netif_internal()`. `esp_netif_dhcpc_start()` and
|
||||
`esp_netif_set_ip_info()` (DHCP client stopped) on ANY netif call `dns_clear_servers(true)` on the global table, and the
|
||||
pin makes IDF skip re-election, so the table stays empty until the app re-asserts the default. Lookups then fail at once
|
||||
with getaddrinfo 202 (lwIP ERR_VAL, no server set). Unfixed on IDF master when this was written.
|
||||
|
||||
Triggers: Wi-Fi joining or reconnecting while Ethernet is the default (ESPHome's `wifi_sta_ip_config_` and IDF's
|
||||
`esp_netif_action_connected` start DHCP); Ethernet with no link while Wi-Fi is the default (the 15 s
|
||||
`Connecting failed; reconnecting` retry runs `set_ip_info` plus `dhcpc_start` every time).
|
||||
|
||||
Harness: `templates/network_dns/dnsrepro.yaml` + `dnsdiag.hpp` for the Waveshare ESP32-S3-ETH (W5500). Every 3 s a `DIAG`
|
||||
line classifies the global DNS slots against each netif's cache (0 empty, E eth's, W wifi's, B both, X other) and names
|
||||
the IDF default and lwIP `netif_default`; every 5 s a `LOOKUP` resolves a fresh `*.10.0.0.1.nip.io` name (a public
|
||||
wildcard name, never cached). Timeline: Wi-Fi off at boot, enabled at 40 s, disabled and enabled at 100 and 110 s, W5500
|
||||
PHY powered off at 170 s (a software link down, no unplugging) and on at 250 s. Set the `first`/`second` substitutions
|
||||
for both priority orders; `phy_boot: "false"` starts with the PHY down (a stand-in for no cable). Needs Wi-Fi and, for
|
||||
the full matrix, a live Ethernet link. The DIAG lines carry no addresses, so captures can be quoted.
|
||||
|
||||
- The W5500 PHY driver's `pwrctl()` is a no-op; `dnsdiag::phy_power()` writes PHYCFGR (OPMD=1, OPMDC 110 off and 111
|
||||
on, RST low then high) and pokes `phy->get_link()`. Power down alone is not reported as a link loss (traffic kept
|
||||
flowing); the PHY reset at power on is, so the 250 s step is a short link drop and return.
|
||||
- Harness trap: `lwip_getaddrinfo` on the loop task with DNS servers set and no interface up blocks until the DNS
|
||||
timeout and trips the task watchdog; `lookup()` skips while offline.
|
||||
- Counts on #22800 (lookups ok/failed, PR against its merge base): Ethernet first with link 66/1 vs 23/43, Wi-Fi first
|
||||
with the PHY down until 250 s 57/0 vs 1/56, Ethernet first with the PHY down 58/0 vs 20/36. Dev empties DNS on every
|
||||
Wi-Fi join with Ethernet as the default, and on the Ethernet lease with Wi-Fi as the default.
|
||||
- While the PHY is powered down the W5500 MAC logs `send command timeout` every 2 s on any build (driver noise from
|
||||
the test).
|
||||
- Compare build sizes only between names of equal length: the name is stored several times, so two names that differ
|
||||
in length move the flash delta by tens of bytes.
|
||||
@@ -0,0 +1,29 @@
|
||||
# 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.
|
||||
@@ -104,3 +104,13 @@ Gotchas: an ESP-IDF image can contain `E7 02` at a 4 KiB boundary by chance; fin
|
||||
instead of "no signature block": the partition still holds the old signature sector past the new image's end.
|
||||
|
||||
Results: https://github.com/esphome/esphome/pull/22398#issuecomment-6716330334
|
||||
|
||||
## ESP8266 web_server OTA interruption and SSE (#22682)
|
||||
|
||||
`scripts/web_server/async_bump/otacases.py` (README there). Facts from a D1 mini on dev and on ESPAsyncWebServer 3.12.1:
|
||||
- A cut upload logs `OTA upload interrupted; aborting`, keeps the old image and serves again within a second; the
|
||||
next full upload works without waiting for a lock release. No heap lost per cut.
|
||||
- Uploads stop by themselves on the network about 1 in 6 to 1 in 15 (curl `000`, old image kept), and about 1 in 25
|
||||
boots the new image while curl never gets the reply (it waits 30 to 60 s). Both builds; classify, do not fail on it.
|
||||
- At OTA reboot the device does not close `/events`: a held client sees silence, rarely a FIN. Detect by idle time.
|
||||
- Max free block drops from about 45 kB to about 37 kB after the first OTA and stays (both builds).
|
||||
@@ -44,3 +44,113 @@ only the last line sees "Failed to upload" first, so rerun before blaming the bu
|
||||
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.
|
||||
|
||||
## Climate IR loopback over the API (#22704 whirlpool, #22709 climate_ir)
|
||||
|
||||
- Pattern: one image with a sending climate and a receiving climate (`receiver_id`) per platform on one shared pin, an
|
||||
aioesphomeapi script that sends climate calls and reads every climate's state after each step. Several platforms can
|
||||
share one receiver; each rejects the others' frames. Scripts in `scripts/climate_ir_loop/`: `drive.py`
|
||||
(steps `Name:mode=cool,t=24,fan=low,swing=vertical,preset=eco` or `svc:action?flag=1`), `run.sh NAME PORT [STEPS]`
|
||||
with `steps.sh` (prelude and steps), `frames.py NAME` (splits the `dump: raw` lines per step), `compare.py A B [TOL]`
|
||||
(per step), `flatcmp.py A B TOL` (the whole sequence, timing by timing), `c-common.yaml` (Samsung, Friedrich,
|
||||
Siemens IRA211 and Mistral senders and receivers), `esp32-ir.yaml` / `esp8266-ir.yaml` (one-pin loopback),
|
||||
`c32pr.yaml` (an example run file) and `whirlpool-inject-common.yaml` (injected frame actions).
|
||||
- ESP32-PICO-D4 kit: GPIO4 does not loop back cleanly (every mark reads 162 µs short, a -162 space leads the frame, so
|
||||
nothing decodes). GPIO27 gives exact timings (572/553/1659 µs). Try another pin before suspecting the code.
|
||||
- RMT ends a frame on any level longer than `idle`, mark or space. A whirlpool 14 byte frame ends after a 7,960 µs gap,
|
||||
so its decoder needs the trailing idle to be within 25% of that, but the 9 ms header mark must stay below idle:
|
||||
`idle: 9500us` works, 8500 cuts the header off.
|
||||
- Restored climate state changes the first frames (power toggles, Samsung power section): start every run with a
|
||||
prelude that puts each sender in a fixed state (every field each sender supports, such as humidity for daikin_arc
|
||||
or a fan mode daikin_brc supports), and compare only the frames after it. ESP8266 restore lives in RTC memory, so a
|
||||
receiver's state can carry over from the previous image.
|
||||
- Inject frames a sender cannot produce (an out of range temperature code, a short frame) from an API action lambda with
|
||||
`item_bytes<BitTimings>` and `call.perform()`.
|
||||
- Assigning frames to steps by host timestamps is fragile on the D1 mini (a log line can land after the next step
|
||||
starts); compare the whole frame sequence in order instead. Two frames sent back to back (siemens_ira211 power plus
|
||||
sync) come out as one dump, and the gap between them varies by up to 1 ms on ESP8266.
|
||||
- Samsung power frames are 347 timings: an ESP32 receiver needs `rmt_symbols: 384` and `receive_symbols: 384`.
|
||||
|
||||
## Protocol A/B with `dump: all` (#22711)
|
||||
|
||||
- One button per `transmit_<protocol>` action, one binary sensor and one `on_<protocol>` trigger per protocol, each
|
||||
logging a marker; count markers and compare the dumper lines of the dev and PR runs in order. All of nec, dooya,
|
||||
nexus, aok and cardin_s438 decode in the ESP32 GPIO27 loopback with the default idle.
|
||||
- Cardin S438 picks a random seed per frame (`random_uint32()`), so its pronto and cardin lines differ between any two
|
||||
runs; compare code and channel only. Each press sends 3 repeats, so its trigger and binary sensor fire 3 times.
|
||||
- Start the dump extraction at the first `MARK tx` of any protocol: the API lists buttons by name, not config order.
|
||||
- A Python-only change can still move generated code: diff `src/main.cpp` of the two builds (field order in action
|
||||
setters, defaults now written explicitly).
|
||||
|
||||
## Large climate frames in the loopback (#22710)
|
||||
|
||||
- At 115200 baud the serial log cannot keep up with long `dump: raw` frames (hitachi_ac344 is 691 timings, daikin
|
||||
sends 3 frames per command). Lines get lost or merged, frames show up under the wrong step, and the script reads the
|
||||
receiver state before it has decoded the frame. Use `logger: baud_rate: 921600`, capture with `--baud 921600`, and
|
||||
wait 4 s per step (`BAUD=921600 STEP_S=4 run.sh ...`). A CH340 D1 mini can garble 921600; 460800 carries the long
|
||||
frames cleanly there.
|
||||
- On the classic ESP32 the receiver has no RX ping-pong, so a whole frame has to fit `rmt_symbols`. With a 64 symbol
|
||||
transmitter, `rmt_symbols: 448` and `receive_symbols: 448` hold hitachi_ac344.
|
||||
- Receivers that keep state the frame does not carry (climate_ir_lg swing is a toggle, zhlt01 keeps its preset on
|
||||
"none") start each run from restored state, so compare them without those fields or erase the preferences first.
|
||||
- Script pitfalls: in zsh `${BAUD:+--baud $BAUD}` is one word, so argparse rejects it. A stale capture file can feed
|
||||
the IP lookup and leave the run with no capture at all, so `run.sh` deletes the capture file first and kills
|
||||
whatever holds the port (`lsof -t`).
|
||||
|
||||
## Whirlpool A/B by hex lines (#22710 retest)
|
||||
|
||||
- whirlpool logs every frame at VERBOSE (`Sending:` and `Received:` hex), so on the D1 mini compare those bytes line by
|
||||
line instead of raw timings. One image per model (DG11J1-3A, HITACHI_HCRA31NEWH, HISENSE_ARG; "Hisense ARG" is a
|
||||
whirlpool model, not its own component). `scripts/climate_ir_loop/whirlpool/`: `wc.yaml` (common), `cl-*.yaml` (one
|
||||
per model), `steps.sh`, and `all.sh PORT BASE_TREE PR_TREE`, which builds and runs base then PR per model so the
|
||||
board ends on a PR build.
|
||||
- The HISENSE_ARG receiver reports fan medium for fan_only while the sender says auto (dev too).
|
||||
|
||||
## Pronto dump A/B with `dump: all` (#22752)
|
||||
|
||||
- Scripts in `scripts/remote_base/pronto/`: `gen.py` writes `gen-common.yaml` (buttons for NEC and raw frames of
|
||||
21/41/43/121/245 timings, a soak button with heap logs, a `pronto:` binary sensor), `esp32-ir.yaml` (GPIO27) and
|
||||
`d1-ir.yaml` (GPIO12) include it, `run.sh NAME TREE YAML PORT BAUD ROUNDS` flashes, captures and runs `drive.py`,
|
||||
`extract.py` strips timestamps and source line numbers, `consist.py` checks every dump against the `on_pronto` text,
|
||||
`jit.py` counts frames that differ between two runs.
|
||||
- The received frame ends with the idle gap as an extra timing (`0181` for the 10 ms idle), so a `pronto:` binary sensor
|
||||
built from the sent timings needs one more number at the end, or the length check rejects every frame. A 41 timing
|
||||
frame is then exactly 230 characters, one full log chunk: a good boundary case.
|
||||
- ESP32 RMT loopback gives byte-identical Pronto text across builds. The D1 mini edge interrupt moves timings by one
|
||||
Pronto unit between any two runs (about half the frames), so compare D1 runs by dump against trigger consistency.
|
||||
- `dump: all` prints NEC lines between the `on_pronto` trigger output and the Pronto dump; the API binary sensor
|
||||
ON/OFF pair can arrive collapsed, so count `on_press` log lines on serial instead.
|
||||
|
||||
## Protocol decode A/B on the host, climate fuzz, AEHA/Haier/Mirage loopback (#22773)
|
||||
|
||||
- `scripts/remote_base/hostharness/`: a `host:` config (`rbhost.yaml`) with a local `rbtest` component (AUTO_LOAD
|
||||
remote_base, `request_protocol()` for the protocols) and `rbh.hpp` called from `on_boot`; it encodes, mutates, decodes
|
||||
and dumps, then `exit(0)`. Run the `program` binary and compare stdout with timestamps and `:line` stripped. The Haier
|
||||
and Mirage decoders want one more item after the last mark (the receiver's idle gap): append `-20000` to transmitter
|
||||
timings or every clean frame fails.
|
||||
- AEHA frames longer than 35 bytes decode as their first 35 bytes (the trailer mark equals a bit mark).
|
||||
- `scripts/climate_ir_fuzz/`: copy `climate_fuzz.hpp` plus the matching `*_fuzz.cpp.example` (as `.cpp`) into
|
||||
`tests/components/<climate>/` of each tree (haier_tundra also needs `haier_init.py` as `__init__.py`), run
|
||||
`script/cpp_unit_test.py`, diff the `FUZZ` lines. All tests of one run share one main.cpp: use a macro include guard,
|
||||
not `#pragma once`, for a header copied to several test dirs.
|
||||
- Lambda idiom checks: compile `void f(AEHAData x) { ... }` snippets with `-fsyntax-only -I<host build>/src` and
|
||||
`#include "esphome.h"` (format_hex lives in alloc_helpers.h).
|
||||
- Loopback config `ir-common.yaml` (AEHA 2 to 35 bytes, Haier, Mirage from an API button, `press.py`). An ESP32-PICO-D4
|
||||
on GPIO27 never decodes 34 or 35 byte AEHA, even with `rmt_symbols: 384`, `buffer_size: 8kb` (dev too); a D1 mini on
|
||||
GPIO12 decodes all of them.
|
||||
|
||||
## Every dumper over a saved corpus, on the host (#22814)
|
||||
|
||||
`scripts/remote_base/dumpall/`: the `rbtest` component requests every `_PROTOCOL_STEMS` source; `rbh.hpp` needs a
|
||||
`dumpers.h` generated from the `DECLARE_REMOTE_PROTOCOL(...)` lines of the tree (plus Pronto, RCSwitch, ABBWelcome;
|
||||
Raw only when nothing matched). Encoders that randomise (Cardin S438 picks a random seed) make two builds see
|
||||
different inputs: run once with `RBH_CORPUS=<file>` to write the corpus, then replay that file on both builds.
|
||||
Merge back-to-back marks or spaces before decoding (Drayton never decodes otherwise). Nudging a quarter of all
|
||||
timings to the tolerance edges proves nothing (the frame fails elsewhere): put only the sync mark at lo-1, lo, hi,
|
||||
hi+1 and keep the rest exact; that variant caught a planted `< max` in 1,000 decodes per protocol.
|
||||
`cmp.sh` compares the DEBUG and VERBOSE outputs (`rbhost-DEBUG.yaml`, `rbhost-VERBOSE.yaml`) with timestamps and line
|
||||
numbers removed.
|
||||
- Loopback with `dump: all` (`ir-common.yaml`, `drive.py`): Beo4 never decodes on one pin (needs its carrier) and
|
||||
Drayton's channel/command form has no checksum; compare decoded lines, raw and Pronto timings jitter between runs.
|
||||
- `cc-common.yaml`: an ESP32-C3 with a CC1101 in async OOK at 433.92 MHz, GDO0 into remote_receiver, for the RF
|
||||
dumpers on real air (a quiet band gives only a few Pronto dumps a minute and no protocol hits).
|
||||
@@ -27,3 +27,13 @@ captures 40 s from boot and runs `ivsum.py`, which prints the run count, first r
|
||||
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.
|
||||
@@ -0,0 +1,21 @@
|
||||
# serial_proxy with a simulated device (#22687)
|
||||
|
||||
`scripts/serial_proxy/`: no external device. On an ESP32-C3 (logger on USB_SERIAL_JTAG) the proxy UART is tx 4 rx 5
|
||||
and the simulator UART tx 5 rx 4 (GPIO matrix, `allow_other_uses` on all four pins). `spsim.hpp` is the device; the
|
||||
client drives it through the proxy with 7E-framed commands: `R` one 88 byte reply (A5, seq u32 BE, 83 bytes
|
||||
(seq + j) % 251), `S` stream replies back to back, `A` ASH DATA frames every 50 ms with ACK latency timing (for
|
||||
`ezsp_proxy_tap` in PROTOCOL mode), `X` log `SIMDONE` totals and reset, `B<baud>` change the sim's baud. SIMSTAT and
|
||||
ASHWIN lines each second carry `backlog_max`, the proxy UART's RX backlog (bytes held back).
|
||||
|
||||
- `spclient.py HOST --baud B --mode reply|stream|ash [--interval MS] [--duration S | --pauses N --pause S --read S]
|
||||
[--protocol]`: raw plaintext API client (no encryption in the config), subscribes, brings the sim and the proxy to
|
||||
the baud, pauses reads on a schedule and prints a RESULT line (complete and broken replies, received bytes). Compare
|
||||
`received` with the sim's `SIMDONE bytes`.
|
||||
- `suite.sh BUILD TREE` (env PORT) flashes `spBUILD.yaml` (a copy of `example-run.yaml` with its own `name`),
|
||||
captures, runs every case (`CASES="a b"` picks some).
|
||||
- `rx_buffer_size` on the proxy UART decides how long a blocked client can stall before the UART overflows
|
||||
(32768 used; at 115200 a 5 s pause peaks near it).
|
||||
- macOS ignores a small SO_RCVBUF after connect (reads back 36000), so a pause needs a few seconds to back up.
|
||||
- Dev at 1920 baud loses bytes even with the client reading: the proxy sends 1 byte API messages (the UART wakes
|
||||
the loop per byte) and the TCP queue fills; #22687's wait coalesces them. A tap in PROTOCOL mode keeps that loss.
|
||||
- Stream mode at 115200 (11.5 KB/s) is more than the proxy forwards over Wi-Fi; both builds lose there.
|
||||
@@ -73,3 +73,88 @@ 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.
|
||||
`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`). 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.
|
||||
|
||||
## 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`): 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; `rec_extract.py` strips the log prefix, then feed both builds to compare_spi.py.
|
||||
@@ -0,0 +1,43 @@
|
||||
# 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 [KEYFILE]`: state changes with timestamps from connect; shows the `connected` sensors
|
||||
read False (not unknown) at boot. The API coalesces a fast off/on, so judge edges from the `CONN` log lines.
|
||||
- `run_host_pair.sh RUN`: the host to host timeline (boot states, SIGSTOP/SIGCONT of the peer, kill -9 and restart,
|
||||
silent and oversize raw servers, one client at a time, refused source, oversize from a client). Build the host
|
||||
configs `tcph1` and `tcph2` here first; `LAN` overrides the computer's own LAN address (macOS `ipconfig` otherwise).
|
||||
- `validation_cases.py`: writes one config per validation rule; 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_esp32_pair.sh`, reads the board address from `.eip` and runs against host config `tcph3`): 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.
|
||||
@@ -0,0 +1,31 @@
|
||||
# Tuya MCU simulator (#22724)
|
||||
|
||||
No Tuya device needed. `scripts/tuya_sim/`: `tuyasim.hpp` is a Tuya MCU on a second UART of the same ESP32, cross-wired
|
||||
through the GPIO matrix to the hub's UART (hub tx 9 rx 10, MCU tx 10 rx 9 on an ESP32-PICO-D4, `board: pico32`,
|
||||
`allow_other_uses: true` on all four pins, 9600 baud). It answers heartbeat (0x00 first, then 0x01), product query,
|
||||
conf query with an empty payload (so the hub takes the WIFI_STATE path), wifi state and datapoint query (one report with
|
||||
all 14 datapoints), echoes each DATAPOINT_DELIVER back as a report like a real MCU, and logs every hub frame as
|
||||
`SIM RX #n cmd XX: <hex>`. `tuyasim::start()` (the "Sim start" button) plays 18 scripted steps 1.5 s apart: every
|
||||
datapoint type (bool, value incl. negative, string, enum, 1/2/4 byte bitmask, raw), a four datapoint frame, one
|
||||
DATAPOINT_REPORT_SYNC (the hub must ack with 0x23), a repeated value.
|
||||
|
||||
- `tuya.yaml`: hub plus binary_sensor, switch, three sensors (int, enum, bitmask), three text sensors (string, enum,
|
||||
raw), three selects (enum, string, int), water heater (switch/target/current/mode), number and fan. Hub
|
||||
`on_datapoint_update` lambdas log `HUB dpN x=.. <entity>=..` with the entity's state, and entity triggers log
|
||||
`ENT <id> <value>`, so the hub-before-entity order and the old state the hub sees are visible per datapoint.
|
||||
`name: ${name}`, built with `pio_build.sh compile <name>` per tree.
|
||||
- `tuyadrive.py HOST OUT.json` (API_KEY env): subscribes states, presses Sim start, then sends switch, select,
|
||||
water heater (on, target, mode eco/electric, off), number and fan commands 2 s apart; prints per phase counts.
|
||||
- `run.sh NAME TREE` (env PORT, API_KEY): upload, 130 s serial capture with a reset, drive.
|
||||
- `compare.sh A B`: diffs API states, the entity dump block, the 1 s re-dump, the HUB/ENT order and the non-heartbeat
|
||||
frames the simulator received. Heartbeats move with timing, so they are left out.
|
||||
|
||||
Facts from the run:
|
||||
- At init the fan delivers its own state (`1f01000100`) before DP31 is known and the hub logs `Setting unknown
|
||||
datapoint 31`; same on dev.
|
||||
- The API coalesces states published in one loop pass: the four datapoint water heater frame gives one state.
|
||||
- A switch or select command for the value it already has sends no frame.
|
||||
- Water heater target 55 with multiplier 0.5 is sent as 110 (`15 02 0004 0000006e`); eco/electric as enum 0/2 on DP23.
|
||||
- Generate an `api_key` for `secrets.yaml` with `openssl rand -base64 32` if you have none.
|
||||
- #22724 changed only the dump order (children now print right after the hub's own lines); `setup_priority:` on a
|
||||
tuya sensor is rejected on the PR and accepted on dev.
|
||||
@@ -72,3 +72,23 @@ 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.
|
||||
@@ -59,3 +59,66 @@ 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.
|
||||
|
||||
## ESPAsyncWebServer / AsyncTCP bump A/B (#22682)
|
||||
|
||||
Scripts: `scripts/web_server/async_bump/` (README there). ESP32 never uses ESPAsyncWebServer: `web_server_base` loads
|
||||
`web_server_idf` for every ESP32 build, Arduino included, so only ESP8266, RP2040/RP2350 and LibreTiny need a run.
|
||||
Per board: page loads, a 180 s SSE client, REST control, `/update` OTA with the build's own image, restart button,
|
||||
then the captive portal hammer (`scripts/wifisave_hammer.sh`, `bogus_saves: "5"`) on one board per family.
|
||||
- Library check: ESP8266 builds use the native toolchain; the library copies sit in
|
||||
`.esphome/pio_components/arduino8266/<hash>/esp32async/*/library.json`, not in `.piolibdeps`.
|
||||
- Restart button over REST on LibreTiny: the HTTP reply is often lost (curl 000 after 5 to 10 s) although the board
|
||||
restarts, on dev too. Not a regression signal.
|
||||
- LibreTiny AsyncTCP 3.5.0 does not build with `framework: loglevel: debug` (or more verbose): `AsyncTCP.cpp:332` logs
|
||||
`xPortGetCoreID()`, undeclared on LibreTiny; `log_d` is empty at the default level, so normal builds pass. Any
|
||||
library bump for LibreTiny needs one build with the framework loglevel at debug.
|
||||
- SSE rates on a board with a weak radio (a CB3S, say) are unreliable; decide SSE questions on a board with a good
|
||||
link and the same SDK.
|
||||
- `/events` churn (`rp2_web_ble/churn.sh`) faults `AsyncEventSource::send` in `AsyncClient::connected()` from
|
||||
`deferrable_send_state` on the Pico W and the W5500-EVB-Pico; 3.12.1 and the RPAsyncTCP fork do not fix it.
|
||||
- Stalled-reader runs need about 150 s: the client's receive window can take about 60 s to close, so a 60 s stall run
|
||||
ends before the 20 s device timeout even starts.
|
||||
@@ -117,3 +117,66 @@ The DUT runs `ap:` plus `captive_portal:` with no station network and logs `wifi
|
||||
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.
|
||||
|
||||
## Counting the Disassociation burst at reboot (#22715)
|
||||
|
||||
`scripts/wpa3_sniff/`: `w15ap.yaml` is a WPA3-SAE only AP with PMF required (any ESP32, set `board:`) that also turns
|
||||
on promiscuous mode with the management filter (`sniff_inc.hpp`) and logs each assoc request, auth, disassoc and deauth
|
||||
frame with transmitter, sequence number, Retry and Protected bits. The AP's own sniffer does see retransmitted copies
|
||||
addressed to it. `st-common.yaml` reboots 10 s after connect (alternating `App.reboot()`/`safe_reboot()`),
|
||||
`stearly-common.yaml` reboots on the first loop pass after `WIFI_EVENT_STA_CONNECTED` (0.15 to 0.46 ms later, before
|
||||
the Wi-Fi component handles the event), `ds-common.yaml` deep sleeps 5 s. `run.sh BUILD TREE SECONDS` (env ST, AP)
|
||||
flashes the station and captures both; `an15.py BUILD STA_MAC` groups the copies per reboot.
|
||||
- On ESP-IDF 5.5.6 the ESP32-C6 station sends 27 to 32 protected Disassociation copies on every reboot while
|
||||
associated (espressif/esp-idf#19443); the classic ESP32 sends 1. Use a C6 (or C3) as the station.
|
||||
- Deep sleep on dev sends no Disassociation at all; the AP finds out only when the station returns (reason 2).
|
||||
- `esp_wifi_sta_get_ap_info()` already returns OK during the SAE exchange, before association completes.
|
||||
- A capture over the C6 USB-JTAG console loses the last log line before deep sleep; count from the AP side.
|
||||
- Serial capture timestamps are quantized to about 200 ms on a CH340, too coarse to time a 100 ms shutdown wait.
|
||||
|
||||
## Configured credentials from flash (#22757)
|
||||
|
||||
- Flows: two `networks:` with a hidden bogus one at higher priority, then the real one; the `wifisave_hammer.sh` flow
|
||||
with `bogus_saves: 3`, long AP SSID and password (over 18 characters, the `CompactString` inline capacity), then an
|
||||
RTS reset and an API restart; `wifi.configure` from `on_boot` after 25 s if not connected, then a reset (prints
|
||||
"skipped"); a lambda building `WiFiAP` from runtime `std::string` and calling `set_sta()` + `start_connecting()`.
|
||||
- The ESP-IDF API client sees `Connection reset by peer` on disconnect after a button that reconnects Wi-Fi; harmless.
|
||||
|
||||
## ESP32 with a hidden network first never joins (#22764)
|
||||
|
||||
- On dev an ESP32 with a hidden bogus network listed first ends every attempt on the real network at once with
|
||||
"Unspecified" or "Auth Leave" and never joins; without `hidden: true` it joins. An ESP8266 joins either way.
|
||||
- Cause, confirmed with debug prints: after the EXPLICIT_HIDDEN probe fails, the first real attempt calls
|
||||
`esp_wifi_disconnect()` (config changed, not associated, nothing marked expected). The hidden attempt's leave event
|
||||
(reason 36 STA_LEAVING, shown as "Unspecified", the bogus SSID, a zero BSSID) is then charged to the real attempt.
|
||||
Attempt 2 gets reason 36 too, and the adapter restart aborts its auth (reason 3 "Auth Leave"). This loops forever on
|
||||
ESP-IDF 5.5.6, with the esp-idf and arduino frameworks alike.
|
||||
- ESPHome does not print numeric reasons; add one log line in the STA_DISCONNECTED handler and one before
|
||||
`esp_wifi_set_config` to see them. `esp32: framework: log_level: INFO` shows the IDF `state: init -> auth` lines.
|
||||
- Regression check: 2025.10.5 joins the hidden-first config (no explicit hidden phase); 2026.10.2 and dev loop.
|
||||
- Soft AP outage on demand without touching the real AP: a D1 mini AP-only config with `enable_on_boot: false` and an
|
||||
`on_boot` delay of 20 s before `wifi.enable`; an RTS reset of the D1 gives a 20+ s outage (an ESP32 station sees
|
||||
Beacon Timeout). The ESP8266 soft AP DHCP can take about 20 s to answer after association.
|
||||
- A soft AP that still holds an ESP32 from its previous boot rejects the first association with 'Too Many
|
||||
Associations' (dev too), and some APs reject the first auth after a reset ("Authentication Failed" about 10 ms in,
|
||||
attempt 2 joins).
|
||||
|
||||
## Router outages timed into the portal cooldown (#22797)
|
||||
|
||||
`scripts/wifi_outage/`: `rtr.yaml` makes a D1 mini an AP-only test router (its own SSID and password from secrets
|
||||
`t_ssid`/`t_pw`) that logs `AP client connected/disconnected`, `AP Distribute Station IP` and a 1 s `RTR` station list.
|
||||
`dut-common.yaml` is a BK7238 DUT (one network, `ap:` with `ap_timeout: 10s`, `captive_portal:`, UART1 log, `ALIVE`
|
||||
line) with `dhcpwrap.hpp`, a `-Wl,--wrap=udp_sendto_if`/`udp_sendto_if_src` hook that counts DHCP DISCOVER, REQUEST
|
||||
and RELEASE and logs `DHCPRELEASE sent n= up=` (`up` = netif still up). `c3-common.yaml` is an ESP-IDF C3 DUT without
|
||||
AP. `outage.py DUT_PORT RTR_PORT LABEL N [--no-ap]` owns both ports: waits for 20 s of `conn=1`, holds the D1 in reset
|
||||
(RTS on EN), waits for `→ RESTARTING` after `Starting fallback AP` (or `Restarting adapter` with `--no-ap`), lets the
|
||||
router boot 1 s later and watches 40 s. `an.py LABEL...` prints per outage skip, cooldown length, driver association
|
||||
and address inside the cooldown, Connected-then-lost, held, releases after the router was back and router-side leaves.
|
||||
- The D1 router is back about 1 s after release and hands out the address in about 0.2 s, but the BK7238 only reports
|
||||
it 7 to 8 s after associating; the 30 s portal cooldown leaves plenty of room.
|
||||
- BK7238 on dev: the Beken supplicant keeps trying after the skip branch's `WiFi.disconnect()` and joins about 5 s into
|
||||
the cooldown on every outage; base then logs Connected and, 200 ms later, Connection lost (20/20), #22797 0/20. The
|
||||
BK station never deauths on that teardown: the ESP8266 router logs `err already associed!` and only then the leave.
|
||||
The release is issued with the netif already down (`up=0`), so it is not proof it hit the air.
|
||||
- Opening the D1 mini port resets it once, so the first `Connection lost` in a capture is that reset, not an outage.
|
||||
- About 2 min per outage; run blocks of 10 interleaved base/PR with a reflash between.
|
||||
@@ -36,3 +36,21 @@ tracker as scan results: everything after the radio runs as normal.
|
||||
first one it hears.
|
||||
- Each frame arrives about 4 times; the counts matched the injection run exactly apart from one radio loss, so the
|
||||
over the air comparison allows two missing publishes per tag.
|
||||
|
||||
## Every Xiaomi platform at once (#22727)
|
||||
|
||||
- `gen_all.py` writes `frames_all.hpp`, `xball_entities.yaml` and `expected_all.json`: one device per platform
|
||||
(the 20 listener-only platforms, `xiaomi_mue4094rt`, `xiaomi_rtcgq02lm` hub, `xiaomi_body_scale`, ATC, PVVX),
|
||||
10 cycles, every frame sent twice. Each entity logs `PUB <dev>.<key> <value>` on publish (binary sensors with
|
||||
`trigger_on_initial_state: true`). Frame shapes that parse: long encrypted (fc 0x58) only up to 24 bytes, so
|
||||
a 7 byte `th` object needs the short 19 byte frame, which only lywsd02mmc, xmwsdj04mmc, mjyd02yla, cgpr1 and
|
||||
rtcgq02lm accept; hhccjcy10 is FD50 9 bytes and miscale v1 181D 10 bytes (no counter, the repeat publishes
|
||||
again); mue4094rt is a plain fc 0x40 frame; body_scale an S200 0x4E16 object in a 24 byte short frame.
|
||||
`xiaomi_mccgq02hl` publishes 9 of 10: the first frame is "closed", which equals its initial off state.
|
||||
- `xball.yaml` is an ESP32-S3 (ESP-IDF, no network, USB_SERIAL_JTAG log) that injects one cycle per second from
|
||||
20 s and logs free heap before and after (`IDLE` lines). `run_all.sh TREE NAME PORT` builds, flashes, captures
|
||||
and counts; `count_all.py cap1 cap2 ...` also says whether the values are identical across builds.
|
||||
- `xbsetup_priority.yaml`: `esphome config` with `setup_priority:` on a moved sensor, a moved binary sensor and
|
||||
mue4094rt (still a component); remove one at a time, since validation stops at the first platform error.
|
||||
- On #22727: 441 publishes on the PR, its stacked base and dev, identical values; dump text identical, the PR prints
|
||||
the 20 listener dumps after `BLE Tracker:`.
|
||||
@@ -21,3 +21,52 @@ 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
|
||||
.apikey
|
||||
.eip
|
||||
climate_ir_loop/*-*.txt
|
||||
climate_ir_loop/*-frames.json
|
||||
climate_ir_loop/whirlpool/w??base.yaml
|
||||
climate_ir_loop/whirlpool/w??pr.yaml
|
||||
cc1101_long/*.log
|
||||
espnow_link/*.log
|
||||
i2c_wire_ab/*/*-ser*.txt
|
||||
i2c_wire_ab/*/*-flash.log
|
||||
i2c_wire_ab/host/gen/
|
||||
i2c_wire_ab/host/stubs/
|
||||
tcp_link/*.txt
|
||||
tuya_sim/*.txt
|
||||
tuya_sim/*.json
|
||||
serial_proxy/*.txt
|
||||
serial_proxy/*.log
|
||||
remote_base/pronto/*.txt
|
||||
remote_base/pronto/gen-common.yaml
|
||||
remote_base/dumpall/dumpers.h
|
||||
sx127x_sim/*pair/
|
||||
web_server/async_bump/*.log
|
||||
web_server/async_bump/*.txt
|
||||
web_server/async_bump/*.pcap
|
||||
web_server/async_bump/img-*.bin
|
||||
wifi_outage/*.txt
|
||||
wpa3_sniff/*.txt
|
||||
xiaomi_ble/*-cap.txt
|
||||
xiaomi_ble/frames_all.hpp
|
||||
xiaomi_ble/xball_entities.yaml
|
||||
xiaomi_ble/expected_all.json
|
||||
ble_scan_complete/*.txt
|
||||
ble_scan_complete/*.err
|
||||
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
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())
|
||||
@@ -0,0 +1,165 @@
|
||||
"""apitest.py HOST OUT.json: Noise API check (entities, states, button) then a flood with a stalled reader
|
||||
so the device's API overflow buffer fills and drains. Validates every received burst state."""
|
||||
|
||||
import asyncio
|
||||
import gc
|
||||
import json
|
||||
import math
|
||||
import pathlib
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import APIClient, APIConnectionError, SensorState, TextSensorState
|
||||
import aioesphomeapi.connection as conn_mod
|
||||
|
||||
HOST, OUT = sys.argv[1], sys.argv[2]
|
||||
KEY = pathlib.Path(".apikey").read_text(encoding="utf-8").strip()
|
||||
TL = 800
|
||||
|
||||
|
||||
class SmallSock(socket.socket):
|
||||
def setsockopt(self, level, opt, *a):
|
||||
if level == socket.SOL_SOCKET and opt == socket.SO_RCVBUF and a[0] != 2048:
|
||||
return None
|
||||
return super().setsockopt(level, opt, *a)
|
||||
|
||||
|
||||
async def start_small(addr_infos, **kw):
|
||||
fam, typ, proto, _, addr = addr_infos[0]
|
||||
s = SmallSock(fam, typ, proto)
|
||||
s.setblocking(False)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2048)
|
||||
await asyncio.get_running_loop().sock_connect(s, addr)
|
||||
return s
|
||||
|
||||
|
||||
conn_mod.aiohappyeyeballs.start_connection = start_small
|
||||
|
||||
|
||||
def txt_ok(s, slot):
|
||||
if len(s) != TL or s[8] != "|" or not s[:8].isdigit():
|
||||
return None
|
||||
n = int(s[:8])
|
||||
for i in range(9, TL):
|
||||
if s[i] != chr(ord("A") + (n * 7 + slot * 3 + i) % 26):
|
||||
return None
|
||||
return n
|
||||
|
||||
|
||||
async def main():
|
||||
res = {"host": HOST}
|
||||
stopped = {"t": None}
|
||||
|
||||
async def on_stop(expected):
|
||||
stopped["t"] = time.monotonic()
|
||||
stopped["expected"] = expected
|
||||
|
||||
cli = APIClient(HOST, 6053, None, noise_psk=KEY)
|
||||
for _ in range(30):
|
||||
try:
|
||||
await asyncio.wait_for(cli.connect(on_stop=on_stop, login=True), 10)
|
||||
break
|
||||
except (OSError, APIConnectionError) as e:
|
||||
last = e
|
||||
await asyncio.sleep(1)
|
||||
else:
|
||||
sys.exit(f"connect failed: {last}")
|
||||
info = await cli.device_info()
|
||||
res["device"] = info.name
|
||||
res["version"] = info.esphome_version
|
||||
ents, _ = await cli.list_entities_services()
|
||||
res["entities"] = len(ents)
|
||||
by_key = {e.key: e for e in ents}
|
||||
names = {e.object_id: e for e in ents}
|
||||
flood = names["flood"]
|
||||
bump = names["bump"]
|
||||
state = {}
|
||||
stats = {"states": 0, "bad_sensor": 0, "bad_text": 0, "burst_states": 0}
|
||||
|
||||
def on_state(s):
|
||||
e = by_key.get(s.key)
|
||||
if e is None:
|
||||
return
|
||||
stats["states"] += 1
|
||||
oid = e.object_id
|
||||
if isinstance(s, SensorState) and oid.startswith("s") and oid[1:].isdigit():
|
||||
i = int(oid[1:])
|
||||
stats["burst_states"] += 1
|
||||
if not s.missing_state and (
|
||||
int(s.state) % 100 != i or s.state != int(s.state)
|
||||
):
|
||||
stats["bad_sensor"] += 1
|
||||
if isinstance(s, TextSensorState) and oid.startswith("t") and oid[1:].isdigit():
|
||||
stats["burst_states"] += 1
|
||||
if not s.missing_state and txt_ok(s.state, int(oid[1:])) is None:
|
||||
stats["bad_text"] += 1
|
||||
state[oid] = s.state
|
||||
|
||||
cli.subscribe_states(on_state)
|
||||
await asyncio.sleep(3)
|
||||
res["initial_states"] = len(state)
|
||||
b0 = state.get("bump_count")
|
||||
b0 = 0 if b0 is None or math.isnan(b0) else int(b0)
|
||||
for _ in range(5):
|
||||
cli.button_command(bump.key)
|
||||
await asyncio.sleep(0.5)
|
||||
await asyncio.sleep(3)
|
||||
res["bump_delta"] = int(state.get("bump_count", 0)) - b0
|
||||
o0 = (
|
||||
state.get("ovf_enqueue"),
|
||||
state.get("ovf_drain"),
|
||||
state.get("ovf_enqueue_bytes"),
|
||||
)
|
||||
sock = cli._connection._socket
|
||||
transport = next(
|
||||
o
|
||||
for o in gc.get_objects()
|
||||
if isinstance(o, asyncio.Transport)
|
||||
and not o.is_closing()
|
||||
and o.get_extra_info("socket") is not None
|
||||
and o.get_extra_info("socket").fileno() == sock.fileno()
|
||||
)
|
||||
cli.switch_command(flood.key, True)
|
||||
await asyncio.sleep(3)
|
||||
for _ in range(3):
|
||||
transport.pause_reading()
|
||||
await asyncio.sleep(6)
|
||||
transport.resume_reading()
|
||||
await asyncio.sleep(4)
|
||||
cli.switch_command(flood.key, False)
|
||||
await asyncio.sleep(6)
|
||||
fN = state.get("flood_n")
|
||||
final_ok = (
|
||||
fN is not None
|
||||
and not math.isnan(fN)
|
||||
and all(state.get(f"s{i}") == fN * 100 + i for i in range(60))
|
||||
and all(txt_ok(state.get(f"t{j}", ""), j) == int(fN) for j in range(4))
|
||||
)
|
||||
o1 = (
|
||||
state.get("ovf_enqueue"),
|
||||
state.get("ovf_drain"),
|
||||
state.get("ovf_enqueue_bytes"),
|
||||
)
|
||||
res.update(stats)
|
||||
res["flood_n"] = fN
|
||||
res["final_states_match"] = final_ok
|
||||
res["ovf_enqueue_delta"] = o1[0] - o0[0]
|
||||
res["ovf_drain_delta"] = o1[1] - o0[1]
|
||||
res["ovf_enqueue_bytes_delta"] = o1[2] - o0[2]
|
||||
res["dropped"] = stopped["t"] is not None
|
||||
await cli.disconnect()
|
||||
res["pass"] = (
|
||||
not res["dropped"]
|
||||
and final_ok
|
||||
and res["bump_delta"] == 5
|
||||
and stats["bad_sensor"] == 0
|
||||
and stats["bad_text"] == 0
|
||||
and res["ovf_enqueue_delta"] > 0
|
||||
and res["ovf_drain_delta"] > 0
|
||||
)
|
||||
print(json.dumps(res))
|
||||
pathlib.Path(OUT).write_text(json.dumps(res, indent=1), encoding="utf-8")
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
// Counts calls into the API overflow buffer through -Wl,--wrap (test only).
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
struct iovec;
|
||||
extern "C" {
|
||||
uint32_t ovf_enq_calls = 0;
|
||||
uint32_t ovf_enq_bytes = 0;
|
||||
uint32_t ovf_drain_calls = 0;
|
||||
bool __real__ZN7esphome3api17APIOverflowBuffer11enqueue_iovEPK5iovecijj(void *self, const iovec *iov, int n,
|
||||
size_t total, size_t skip);
|
||||
bool __wrap__ZN7esphome3api17APIOverflowBuffer11enqueue_iovEPK5iovecijj(void *self, const iovec *iov, int n,
|
||||
size_t total, size_t skip) {
|
||||
bool ok = __real__ZN7esphome3api17APIOverflowBuffer11enqueue_iovEPK5iovecijj(self, iov, n, total, skip);
|
||||
if (ok) {
|
||||
ovf_enq_calls++;
|
||||
ovf_enq_bytes += total - skip;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
ssize_t OVF_DRAIN_REAL(void *self, void *sock);
|
||||
ssize_t OVF_DRAIN_WRAP(void *self, void *sock) {
|
||||
ovf_drain_calls++;
|
||||
return OVF_DRAIN_REAL(self, sock);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,601 @@
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes:
|
||||
- ovfwrap.hpp
|
||||
- txt.hpp
|
||||
build_flags:
|
||||
- -Wl,--wrap=_ZN7esphome3api17APIOverflowBuffer11enqueue_iovEPK5iovecijj
|
||||
- -Wl,--wrap=${drain_sym}
|
||||
- -DOVF_DRAIN_WRAP=__wrap_${drain_sym}
|
||||
- -DOVF_DRAIN_REAL=__real_${drain_sym}
|
||||
logger:
|
||||
level: DEBUG
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
ota:
|
||||
- platform: esphome
|
||||
globals:
|
||||
- id: flood_n
|
||||
type: uint32_t
|
||||
initial_value: "0"
|
||||
- id: bump_n
|
||||
type: uint32_t
|
||||
initial_value: "0"
|
||||
- id: tick
|
||||
type: uint32_t
|
||||
initial_value: "0"
|
||||
switch:
|
||||
- platform: template
|
||||
id: flood
|
||||
name: Flood
|
||||
optimistic: true
|
||||
button:
|
||||
- platform: template
|
||||
name: Bump
|
||||
on_press:
|
||||
- lambda: |-
|
||||
id(bump_n)++;
|
||||
ESP_LOGI("bump", "press %u", (unsigned) id(bump_n));
|
||||
id(bump_sensor).publish_state(id(bump_n));
|
||||
interval:
|
||||
- interval: 50ms
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
switch.is_on: flood
|
||||
then:
|
||||
- lambda: |-
|
||||
uint32_t n = ++id(flood_n);
|
||||
id(bs0).publish_state(n * 100 + 0);
|
||||
id(bs1).publish_state(n * 100 + 1);
|
||||
id(bs2).publish_state(n * 100 + 2);
|
||||
id(bs3).publish_state(n * 100 + 3);
|
||||
id(bs4).publish_state(n * 100 + 4);
|
||||
id(bs5).publish_state(n * 100 + 5);
|
||||
id(bs6).publish_state(n * 100 + 6);
|
||||
id(bs7).publish_state(n * 100 + 7);
|
||||
id(bs8).publish_state(n * 100 + 8);
|
||||
id(bs9).publish_state(n * 100 + 9);
|
||||
id(bs10).publish_state(n * 100 + 10);
|
||||
id(bs11).publish_state(n * 100 + 11);
|
||||
id(bs12).publish_state(n * 100 + 12);
|
||||
id(bs13).publish_state(n * 100 + 13);
|
||||
id(bs14).publish_state(n * 100 + 14);
|
||||
id(bs15).publish_state(n * 100 + 15);
|
||||
id(bs16).publish_state(n * 100 + 16);
|
||||
id(bs17).publish_state(n * 100 + 17);
|
||||
id(bs18).publish_state(n * 100 + 18);
|
||||
id(bs19).publish_state(n * 100 + 19);
|
||||
id(bs20).publish_state(n * 100 + 20);
|
||||
id(bs21).publish_state(n * 100 + 21);
|
||||
id(bs22).publish_state(n * 100 + 22);
|
||||
id(bs23).publish_state(n * 100 + 23);
|
||||
id(bs24).publish_state(n * 100 + 24);
|
||||
id(bs25).publish_state(n * 100 + 25);
|
||||
id(bs26).publish_state(n * 100 + 26);
|
||||
id(bs27).publish_state(n * 100 + 27);
|
||||
id(bs28).publish_state(n * 100 + 28);
|
||||
id(bs29).publish_state(n * 100 + 29);
|
||||
id(bs30).publish_state(n * 100 + 30);
|
||||
id(bs31).publish_state(n * 100 + 31);
|
||||
id(bs32).publish_state(n * 100 + 32);
|
||||
id(bs33).publish_state(n * 100 + 33);
|
||||
id(bs34).publish_state(n * 100 + 34);
|
||||
id(bs35).publish_state(n * 100 + 35);
|
||||
id(bs36).publish_state(n * 100 + 36);
|
||||
id(bs37).publish_state(n * 100 + 37);
|
||||
id(bs38).publish_state(n * 100 + 38);
|
||||
id(bs39).publish_state(n * 100 + 39);
|
||||
id(bs40).publish_state(n * 100 + 40);
|
||||
id(bs41).publish_state(n * 100 + 41);
|
||||
id(bs42).publish_state(n * 100 + 42);
|
||||
id(bs43).publish_state(n * 100 + 43);
|
||||
id(bs44).publish_state(n * 100 + 44);
|
||||
id(bs45).publish_state(n * 100 + 45);
|
||||
id(bs46).publish_state(n * 100 + 46);
|
||||
id(bs47).publish_state(n * 100 + 47);
|
||||
id(bs48).publish_state(n * 100 + 48);
|
||||
id(bs49).publish_state(n * 100 + 49);
|
||||
id(bs50).publish_state(n * 100 + 50);
|
||||
id(bs51).publish_state(n * 100 + 51);
|
||||
id(bs52).publish_state(n * 100 + 52);
|
||||
id(bs53).publish_state(n * 100 + 53);
|
||||
id(bs54).publish_state(n * 100 + 54);
|
||||
id(bs55).publish_state(n * 100 + 55);
|
||||
id(bs56).publish_state(n * 100 + 56);
|
||||
id(bs57).publish_state(n * 100 + 57);
|
||||
id(bs58).publish_state(n * 100 + 58);
|
||||
id(bs59).publish_state(n * 100 + 59);
|
||||
id(bt0).publish_state(make_txt(n, 0));
|
||||
id(bt1).publish_state(make_txt(n, 1));
|
||||
id(bt2).publish_state(make_txt(n, 2));
|
||||
id(bt3).publish_state(make_txt(n, 3));
|
||||
id(flood_sensor).publish_state(n);
|
||||
- interval: 1s
|
||||
then:
|
||||
- lambda: |-
|
||||
uint32_t t = ++id(tick);
|
||||
id(loc_count).publish_state(t);
|
||||
id(loc_float).publish_state(12345.678f + t * 0.001f - (t % 7) * 1000.5f);
|
||||
id(loc_bin).publish_state((t / 3) % 2 == 1);
|
||||
id(ovf_enq).publish_state(ovf_enq_calls);
|
||||
id(ovf_enq_b).publish_state(ovf_enq_bytes);
|
||||
id(ovf_drain).publish_state(ovf_drain_calls);
|
||||
udp:
|
||||
- id: udp_plain
|
||||
port: 18611
|
||||
addresses: ["${peer_ip}"]
|
||||
- id: udp_full
|
||||
port: 18612
|
||||
addresses: ["${peer_ip}"]
|
||||
packet_interface:
|
||||
- platform: udp
|
||||
id: pi_plain
|
||||
udp_id: udp_plain
|
||||
- platform: udp
|
||||
id: pi_full
|
||||
udp_id: udp_full
|
||||
addressing:
|
||||
address: ${my_addr}
|
||||
destination: ${peer_addr}
|
||||
encryption:
|
||||
key: putbe test key
|
||||
rolling_code_enable: true
|
||||
reliability:
|
||||
fragmentation:
|
||||
session:
|
||||
entity_transport:
|
||||
- id: et_plain
|
||||
packet_interface: pi_plain
|
||||
update_interval: 2s
|
||||
sensors:
|
||||
- id: loc_count
|
||||
broadcast_id: count
|
||||
- id: loc_float
|
||||
broadcast_id: flt
|
||||
binary_sensors:
|
||||
- id: loc_bin
|
||||
broadcast_id: bin
|
||||
- id: et_full
|
||||
packet_interface: pi_full
|
||||
sensors:
|
||||
- id: loc_count
|
||||
broadcast_id: count
|
||||
- id: loc_float
|
||||
broadcast_id: flt
|
||||
binary_sensors:
|
||||
- id: loc_bin
|
||||
broadcast_id: bin
|
||||
text_sensor:
|
||||
- platform: template
|
||||
id: bt0
|
||||
name: T0
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: bt1
|
||||
name: T1
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: bt2
|
||||
name: T2
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: bt3
|
||||
name: T3
|
||||
update_interval: never
|
||||
sensor:
|
||||
- platform: template
|
||||
id: flood_sensor
|
||||
name: Flood N
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: bump_sensor
|
||||
name: Bump count
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: loc_count
|
||||
name: Local count
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: loc_float
|
||||
name: Local float
|
||||
accuracy_decimals: 3
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: ovf_enq
|
||||
name: Ovf enqueue
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: ovf_enq_b
|
||||
name: Ovf enqueue bytes
|
||||
update_interval: never
|
||||
- platform: template
|
||||
id: ovf_drain
|
||||
name: Ovf drain
|
||||
update_interval: never
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_plain
|
||||
id: r_plain_b_count
|
||||
name: R plain b count
|
||||
provider: ${peer}b
|
||||
remote_id: count
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_plain
|
||||
id: r_plain_b_flt
|
||||
name: R plain b flt
|
||||
provider: ${peer}b
|
||||
remote_id: flt
|
||||
accuracy_decimals: 3
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_plain
|
||||
id: r_plain_p_count
|
||||
name: R plain p count
|
||||
provider: ${peer}p
|
||||
remote_id: count
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_plain
|
||||
id: r_plain_p_flt
|
||||
name: R plain p flt
|
||||
provider: ${peer}p
|
||||
remote_id: flt
|
||||
accuracy_decimals: 3
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_full
|
||||
id: r_full_b_count
|
||||
name: R full b count
|
||||
provider: ${peer}b
|
||||
remote_id: count
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_full
|
||||
id: r_full_b_flt
|
||||
name: R full b flt
|
||||
provider: ${peer}b
|
||||
remote_id: flt
|
||||
accuracy_decimals: 3
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_full
|
||||
id: r_full_p_count
|
||||
name: R full p count
|
||||
provider: ${peer}p
|
||||
remote_id: count
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_full
|
||||
id: r_full_p_flt
|
||||
name: R full p flt
|
||||
provider: ${peer}p
|
||||
remote_id: flt
|
||||
accuracy_decimals: 3
|
||||
- platform: template
|
||||
id: bs0
|
||||
name: S0
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs1
|
||||
name: S1
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs2
|
||||
name: S2
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs3
|
||||
name: S3
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs4
|
||||
name: S4
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs5
|
||||
name: S5
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs6
|
||||
name: S6
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs7
|
||||
name: S7
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs8
|
||||
name: S8
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs9
|
||||
name: S9
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs10
|
||||
name: S10
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs11
|
||||
name: S11
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs12
|
||||
name: S12
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs13
|
||||
name: S13
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs14
|
||||
name: S14
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs15
|
||||
name: S15
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs16
|
||||
name: S16
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs17
|
||||
name: S17
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs18
|
||||
name: S18
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs19
|
||||
name: S19
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs20
|
||||
name: S20
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs21
|
||||
name: S21
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs22
|
||||
name: S22
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs23
|
||||
name: S23
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs24
|
||||
name: S24
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs25
|
||||
name: S25
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs26
|
||||
name: S26
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs27
|
||||
name: S27
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs28
|
||||
name: S28
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs29
|
||||
name: S29
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs30
|
||||
name: S30
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs31
|
||||
name: S31
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs32
|
||||
name: S32
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs33
|
||||
name: S33
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs34
|
||||
name: S34
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs35
|
||||
name: S35
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs36
|
||||
name: S36
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs37
|
||||
name: S37
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs38
|
||||
name: S38
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs39
|
||||
name: S39
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs40
|
||||
name: S40
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs41
|
||||
name: S41
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs42
|
||||
name: S42
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs43
|
||||
name: S43
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs44
|
||||
name: S44
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs45
|
||||
name: S45
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs46
|
||||
name: S46
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs47
|
||||
name: S47
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs48
|
||||
name: S48
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs49
|
||||
name: S49
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs50
|
||||
name: S50
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs51
|
||||
name: S51
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs52
|
||||
name: S52
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs53
|
||||
name: S53
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs54
|
||||
name: S54
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs55
|
||||
name: S55
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs56
|
||||
name: S56
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs57
|
||||
name: S57
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs58
|
||||
name: S58
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
- platform: template
|
||||
id: bs59
|
||||
name: S59
|
||||
update_interval: never
|
||||
accuracy_decimals: 0
|
||||
binary_sensor:
|
||||
- platform: template
|
||||
id: loc_bin
|
||||
name: Local bin
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_plain
|
||||
id: r_plain_b_bin
|
||||
name: R plain b bin
|
||||
provider: ${peer}b
|
||||
remote_id: bin
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_plain
|
||||
id: r_plain_p_bin
|
||||
name: R plain p bin
|
||||
provider: ${peer}p
|
||||
remote_id: bin
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_full
|
||||
id: r_full_b_bin
|
||||
name: R full b bin
|
||||
provider: ${peer}b
|
||||
remote_id: bin
|
||||
- platform: entity_transport
|
||||
entity_transport_id: et_full
|
||||
id: r_full_p_bin
|
||||
name: R full p bin
|
||||
provider: ${peer}p
|
||||
remote_id: bin
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
// 800 chars: 8 digit n, '|', then letters from n and the slot
|
||||
static std::string make_txt(uint32_t n, int slot) {
|
||||
std::string s(800, ' ');
|
||||
char head[16];
|
||||
snprintf(head, sizeof(head), "%08u|", (unsigned) n);
|
||||
for (int i = 0; i < 9; i++)
|
||||
s[i] = head[i];
|
||||
for (int i = 9; i < 800; i++)
|
||||
s[i] = 'A' + (n * 7 + slot * 3 + i) % 26;
|
||||
return s;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ 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
|
||||
@@ -27,19 +28,32 @@ FATAL = (
|
||||
)
|
||||
|
||||
|
||||
async def connect(host: str, tries: int = 30, timeout: float = 10) -> APIClient:
|
||||
async def connect(
|
||||
host: str,
|
||||
tries: int = 30,
|
||||
timeout: float = 10,
|
||||
port: int = 6053,
|
||||
on_stop: Callable[[bool], Awaitable[None]] | None = None,
|
||||
) -> 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.
|
||||
API_KEY in the env selects Noise; unset, empty or - is plaintext. ON_STOP is called when the connection ends.
|
||||
"""
|
||||
key = os.environ.get("API_KEY")
|
||||
last: BaseException | None = None
|
||||
for _ in range(tries):
|
||||
c = APIClient(
|
||||
host, 6053, None, noise_psk=None if key in (None, "", "-") else key
|
||||
host, port, 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(login=True), timeout)
|
||||
await asyncio.wait_for(c.connect(on_stop=stop, 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
|
||||
@@ -49,6 +63,7 @@ async def connect(host: str, tries: int = 30, timeout: float = 10) -> APIClient:
|
||||
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}"
|
||||
@@ -58,3 +73,80 @@ async def connect(host: str, tries: int = 30, timeout: float = 10) -> APIClient:
|
||||
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
|
||||
@@ -0,0 +1,119 @@
|
||||
"""Home Assistant stand-in for a bluetooth_proxy scan soak (esphome#22770).
|
||||
|
||||
usage: ha.py HOST OUT SECONDS [--toggle SECS [--jitter SECS]] [--mode passive|active|none]
|
||||
|
||||
Subscribes to raw advertisements and the scanner state like Home Assistant, sets the scanner mode once after connect
|
||||
(passive by default, as HA does for its proxies) and with --toggle flips active/passive every SECS seconds to stress
|
||||
the stop/restart path. Writes one line per event to OUT: scanner state changes, a per-second advert count, mode
|
||||
requests, connection drops. Reconnects after a drop (device reboot) and keeps going until SECONDS have passed.
|
||||
API_KEY in the env selects Noise.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import pathlib
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
_here = pathlib.Path(__file__).resolve().parent
|
||||
# apiconn.py: copied next to it, or the skill scripts dir
|
||||
sys.path[:0] = [str(_here), str(_here.parent)]
|
||||
|
||||
from apiconn import connect, stop_event # noqa: E402
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("host")
|
||||
ap.add_argument("out")
|
||||
ap.add_argument("seconds", type=float)
|
||||
ap.add_argument("--toggle", type=float, default=0)
|
||||
ap.add_argument(
|
||||
"--jitter",
|
||||
type=float,
|
||||
default=0,
|
||||
help="random +- seconds added to each toggle period",
|
||||
)
|
||||
ap.add_argument("--mode", default="passive", choices=["passive", "active", "none"])
|
||||
a = ap.parse_args()
|
||||
asyncio.run(run(a))
|
||||
|
||||
|
||||
async def run(a: argparse.Namespace) -> None:
|
||||
from aioesphomeapi import BluetoothScannerMode
|
||||
|
||||
end = time.monotonic() + a.seconds
|
||||
f = pathlib.Path(a.out).open("a", encoding="utf-8", buffering=1) # noqa: SIM115
|
||||
|
||||
def w(s: str) -> None:
|
||||
f.write(
|
||||
f"{time.strftime('%H:%M:%S')}.{int(time.time() * 1000) % 1000:03d} {s}\n"
|
||||
)
|
||||
|
||||
session = 0
|
||||
while time.monotonic() < end:
|
||||
session += 1
|
||||
stopped, on_stop = stop_event()
|
||||
try:
|
||||
c = await connect(a.host, tries=600, on_stop=on_stop)
|
||||
except SystemExit as e:
|
||||
w(f"CONNECT FAILED {e}")
|
||||
await asyncio.sleep(5)
|
||||
continue
|
||||
w(f"CONNECTED session={session}")
|
||||
adv = [0]
|
||||
macs: set[int] = set()
|
||||
|
||||
def on_raw(resp, adv=adv, macs=macs) -> None:
|
||||
for x in resp.advertisements:
|
||||
adv[0] += 1
|
||||
macs.add(x.address)
|
||||
|
||||
def on_state(st) -> None:
|
||||
w(f"SCANNER state={st.state.name} mode={st.mode.name}")
|
||||
|
||||
unsub_raw = c.subscribe_bluetooth_le_raw_advertisements(on_raw)
|
||||
unsub_state = c.subscribe_bluetooth_scanner_state(on_state)
|
||||
if a.mode != "none":
|
||||
m = (
|
||||
BluetoothScannerMode.PASSIVE
|
||||
if a.mode == "passive"
|
||||
else BluetoothScannerMode.ACTIVE
|
||||
)
|
||||
c.bluetooth_scanner_set_mode(m)
|
||||
w(f"SET_MODE {a.mode}")
|
||||
last_toggle = time.monotonic()
|
||||
period = a.toggle
|
||||
active = a.mode == "active"
|
||||
last_report = time.monotonic()
|
||||
while time.monotonic() < end and not stopped.is_set():
|
||||
await asyncio.sleep(0.05)
|
||||
now = time.monotonic()
|
||||
if a.toggle and now - last_toggle >= period:
|
||||
active = not active
|
||||
c.bluetooth_scanner_set_mode(
|
||||
BluetoothScannerMode.ACTIVE
|
||||
if active
|
||||
else BluetoothScannerMode.PASSIVE
|
||||
)
|
||||
w(f"SET_MODE {'active' if active else 'passive'}")
|
||||
last_toggle = now
|
||||
period = a.toggle + random.uniform(-a.jitter, a.jitter)
|
||||
if now - last_report >= 10:
|
||||
w(f"ADV {adv[0]} in {now - last_report:.1f}s devices={len(macs)}")
|
||||
adv[0] = 0
|
||||
macs.clear()
|
||||
last_report = now
|
||||
if stopped.is_set():
|
||||
w("DISCONNECTED")
|
||||
await asyncio.sleep(2)
|
||||
continue
|
||||
unsub_raw()
|
||||
unsub_state()
|
||||
await c.disconnect()
|
||||
w("DONE")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,78 @@
|
||||
substitutions:
|
||||
name: scan2610
|
||||
duration: 5s
|
||||
|
||||
esphome:
|
||||
name: ${name}
|
||||
|
||||
esp32:
|
||||
board: esp32-c6-devkitc-1
|
||||
variant: esp32c6
|
||||
flash_size: 4MB
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
logger:
|
||||
level: VERBOSE
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
logs:
|
||||
esp32_ble_tracker: VERBOSE
|
||||
esp32_ble: DEBUG
|
||||
bluetooth_proxy: DEBUG
|
||||
api: DEBUG
|
||||
api.connection: DEBUG
|
||||
api.service: DEBUG
|
||||
sensor: INFO
|
||||
text_sensor: INFO
|
||||
debug: INFO
|
||||
wifi: DEBUG
|
||||
scheduler: DEBUG
|
||||
component: DEBUG
|
||||
|
||||
ota:
|
||||
- platform: esphome
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
|
||||
esp32_ble_tracker:
|
||||
scan_parameters:
|
||||
interval: 1100ms
|
||||
window: 1100ms
|
||||
active: true
|
||||
duration: ${duration}
|
||||
|
||||
bluetooth_proxy:
|
||||
active: true
|
||||
|
||||
sensor:
|
||||
- platform: wifi_signal
|
||||
name: WiFi signal
|
||||
update_interval: 60s
|
||||
- platform: uptime
|
||||
name: Uptime
|
||||
- platform: debug
|
||||
free:
|
||||
name: Free memory
|
||||
block:
|
||||
name: Largest free block
|
||||
min_free:
|
||||
name: Lowest free memory
|
||||
loop_time:
|
||||
name: Loop time
|
||||
|
||||
debug:
|
||||
update_interval: 60s
|
||||
|
||||
text_sensor:
|
||||
- platform: version
|
||||
name: ESPHome version
|
||||
- platform: debug
|
||||
reset_reason:
|
||||
name: Reset reason
|
||||
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
// esphome#22770 instrumentation: follows one scan's duration timer through Bluedroid.
|
||||
// Link with -Wl,--wrap= for BTM_BleScan, btu_start_timer, btm_ble_timeout, osi_alarm_new, btc_transfer_context.
|
||||
#include <cstdint>
|
||||
#include <esp_gap_ble_api.h>
|
||||
#include <esp_timer.h>
|
||||
|
||||
extern "C" {
|
||||
struct scan_inst_t {
|
||||
volatile uint32_t ble_scan_start; // BTM_BleScan(TRUE) calls
|
||||
volatile uint32_t ble_scan_start_bad; // ... that did not return BTM_CMD_STARTED
|
||||
volatile uint32_t ble_scan_stop; // BTM_BleScan(FALSE) calls
|
||||
volatile uint32_t timer_start; // btu_start_timer(BTU_TTYPE_BLE_SCAN)
|
||||
volatile uint32_t alarm_fire; // esp_timer fired for the scan timer entry (btc thread)
|
||||
volatile uint32_t ble_timeout; // btm_ble_timeout for the scan timer entry (btu thread)
|
||||
volatile uint32_t inq_cmpl_post; // INQ_CMPL handed to btc_transfer_context
|
||||
volatile uint32_t inq_cmpl_post_fail; // ... that failed
|
||||
volatile uint8_t pid;
|
||||
void *volatile scan_tle;
|
||||
volatile int64_t last_timer_start_us;
|
||||
volatile int64_t last_fire_us;
|
||||
volatile int64_t last_timeout_us;
|
||||
volatile int64_t last_inq_cmpl_us;
|
||||
};
|
||||
scan_inst_t g_scan_inst{};
|
||||
|
||||
typedef void (*scan_inst_cb_t)(void *);
|
||||
// the scan timer entry's original alarm callback (btu_general_alarm_cb)
|
||||
static scan_inst_cb_t s_orig_cb = nullptr;
|
||||
|
||||
static void scan_inst_shim(void *data) {
|
||||
g_scan_inst.alarm_fire++;
|
||||
g_scan_inst.last_fire_us = esp_timer_get_time();
|
||||
s_orig_cb(data);
|
||||
}
|
||||
|
||||
uint8_t __real_BTM_BleScan(uint8_t start, uint32_t duration, void *a, void *b, void *c);
|
||||
uint8_t __wrap_BTM_BleScan(uint8_t start, uint32_t duration, void *a, void *b, void *c) {
|
||||
uint8_t r = __real_BTM_BleScan(start, duration, a, b, c);
|
||||
if (start) {
|
||||
g_scan_inst.ble_scan_start++;
|
||||
if (r != 1 /* BTM_CMD_STARTED */)
|
||||
g_scan_inst.ble_scan_start_bad++;
|
||||
} else {
|
||||
g_scan_inst.ble_scan_stop++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void __real_btu_start_timer(void *p_tle, uint16_t type, uint32_t timeout_sec);
|
||||
void __wrap_btu_start_timer(void *p_tle, uint16_t type, uint32_t timeout_sec) {
|
||||
if (type == 109 /* BTU_TTYPE_BLE_SCAN */) {
|
||||
g_scan_inst.scan_tle = p_tle;
|
||||
g_scan_inst.timer_start++;
|
||||
g_scan_inst.last_timer_start_us = esp_timer_get_time();
|
||||
}
|
||||
__real_btu_start_timer(p_tle, type, timeout_sec);
|
||||
}
|
||||
|
||||
void __real_btm_ble_timeout(void *p_tle);
|
||||
void __wrap_btm_ble_timeout(void *p_tle) {
|
||||
if (p_tle == g_scan_inst.scan_tle) {
|
||||
g_scan_inst.ble_timeout++;
|
||||
g_scan_inst.last_timeout_us = esp_timer_get_time();
|
||||
}
|
||||
__real_btm_ble_timeout(p_tle);
|
||||
}
|
||||
|
||||
void *__real_osi_alarm_new(const char *name, scan_inst_cb_t cb, void *data, uint64_t expire);
|
||||
void *__wrap_osi_alarm_new(const char *name, scan_inst_cb_t cb, void *data, uint64_t expire) {
|
||||
// btu_start_timer's wrap records the scan entry before the real one creates its alarm
|
||||
if (data != nullptr && data == g_scan_inst.scan_tle && s_orig_cb == nullptr) {
|
||||
s_orig_cb = cb;
|
||||
return __real_osi_alarm_new(name, scan_inst_shim, data, expire);
|
||||
}
|
||||
return __real_osi_alarm_new(name, cb, data, expire);
|
||||
}
|
||||
|
||||
struct scan_inst_msg_t {
|
||||
uint8_t sig, aid, pid, act;
|
||||
};
|
||||
int __real_btc_transfer_context(scan_inst_msg_t *msg, void *arg, int arg_len, void *cp, void *fr);
|
||||
int __wrap_btc_transfer_context(scan_inst_msg_t *msg, void *arg, int arg_len, void *cp, void *fr) {
|
||||
bool cmpl = msg != nullptr && arg != nullptr && msg->sig == 1 && msg->act == ESP_GAP_BLE_SCAN_RESULT_EVT &&
|
||||
arg_len >= 4 && msg->pid == 5 /* BTC_PID_GAP_BLE */ &&
|
||||
static_cast<esp_ble_gap_cb_param_t *>(arg)->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT;
|
||||
int r = __real_btc_transfer_context(msg, arg, arg_len, cp, fr);
|
||||
if (cmpl) {
|
||||
g_scan_inst.pid = msg->pid;
|
||||
g_scan_inst.inq_cmpl_post++;
|
||||
g_scan_inst.last_inq_cmpl_us = esp_timer_get_time();
|
||||
if (r != 0)
|
||||
g_scan_inst.inq_cmpl_post_fail++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
substitutions:
|
||||
name: scaninst
|
||||
duration: 5s
|
||||
|
||||
esphome:
|
||||
name: ${name}
|
||||
includes:
|
||||
- scan_inst.hpp
|
||||
platformio_options:
|
||||
build_flags:
|
||||
- -Wl,--wrap=BTM_BleScan
|
||||
- -Wl,--wrap=btu_start_timer
|
||||
- -Wl,--wrap=btm_ble_timeout
|
||||
- -Wl,--wrap=osi_alarm_new
|
||||
- -Wl,--wrap=btc_transfer_context
|
||||
|
||||
esp32:
|
||||
board: esp32-c6-devkitc-1
|
||||
variant: esp32c6
|
||||
flash_size: 4MB
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
logger:
|
||||
level: VERBOSE
|
||||
hardware_uart: USB_SERIAL_JTAG
|
||||
logs:
|
||||
esp32_ble_tracker: VERBOSE
|
||||
esp32_ble: DEBUG
|
||||
bluetooth_proxy: DEBUG
|
||||
api: DEBUG
|
||||
api.connection: DEBUG
|
||||
api.service: DEBUG
|
||||
sensor: INFO
|
||||
text_sensor: INFO
|
||||
debug: INFO
|
||||
wifi: DEBUG
|
||||
scheduler: DEBUG
|
||||
component: DEBUG
|
||||
|
||||
ota:
|
||||
- platform: esphome
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
|
||||
esp32_ble_tracker:
|
||||
scan_parameters:
|
||||
interval: 1100ms
|
||||
window: 1100ms
|
||||
active: true
|
||||
duration: ${duration}
|
||||
|
||||
on_scan_end:
|
||||
- lambda: id(scan_ends)++;
|
||||
|
||||
bluetooth_proxy:
|
||||
active: true
|
||||
|
||||
globals:
|
||||
- id: scan_ends
|
||||
type: uint32_t
|
||||
initial_value: '0'
|
||||
|
||||
interval:
|
||||
- interval: 30s
|
||||
then:
|
||||
- lambda: |-
|
||||
auto &g = g_scan_inst;
|
||||
int64_t now = esp_timer_get_time();
|
||||
ESP_LOGI("scaninst", "start=%u bad=%u stop=%u timer=%u fire=%u timeout=%u cmpl_post=%u cmpl_fail=%u pid=%u ends=%u "
|
||||
"ago_ms timer=%lld fire=%lld timeout=%lld cmpl=%lld",
|
||||
(unsigned) g.ble_scan_start, (unsigned) g.ble_scan_start_bad, (unsigned) g.ble_scan_stop,
|
||||
(unsigned) g.timer_start, (unsigned) g.alarm_fire, (unsigned) g.ble_timeout,
|
||||
(unsigned) g.inq_cmpl_post, (unsigned) g.inq_cmpl_post_fail, (unsigned) g.pid, (unsigned) id(scan_ends),
|
||||
(now - g.last_timer_start_us) / 1000, (now - g.last_fire_us) / 1000,
|
||||
(now - g.last_timeout_us) / 1000, (now - g.last_inq_cmpl_us) / 1000);
|
||||
|
||||
sensor:
|
||||
- platform: wifi_signal
|
||||
name: WiFi signal
|
||||
update_interval: 60s
|
||||
- platform: uptime
|
||||
name: Uptime
|
||||
- platform: debug
|
||||
free:
|
||||
name: Free memory
|
||||
block:
|
||||
name: Largest free block
|
||||
min_free:
|
||||
name: Lowest free memory
|
||||
loop_time:
|
||||
name: Loop time
|
||||
|
||||
debug:
|
||||
update_interval: 60s
|
||||
|
||||
text_sensor:
|
||||
- platform: version
|
||||
name: ESPHome version
|
||||
- platform: debug
|
||||
reset_reason:
|
||||
name: Reset reason
|
||||
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
encryption:
|
||||
key: !secret api_key
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
# usage: soak.sh TAG HOST SECONDS [ha.py options] serial capture plus HA stand-in, both bounded
|
||||
# env: PORT (serial port), PY; the API key is read from apikey.txt next to the script
|
||||
W=$(cd "$(dirname "$0")" && pwd); cd "$W" || exit 1; T=$1; H=$2; S=$3; shift 3
|
||||
PY=${PY:-python3}
|
||||
PORT=${PORT:?serial port}
|
||||
$PY "$(dirname "$W")/serial_capture.py" "$PORT" "$S" "$T.txt" > /dev/null 2>&1 &
|
||||
sleep 8
|
||||
API_KEY=$(cat apikey.txt) PYTHONUNBUFFERED=1 $PY ha.py $H $T-ha.txt $S "$@" > $T-ha.err 2>&1 &
|
||||
wait
|
||||
echo "$T done"
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
# usage: wait.sh CAPTURE SECONDS [FROM_LINE] block until an anomaly after FROM_LINE or SECONDS pass, then print status
|
||||
C=$1; E=$(( $(date +%s) + $2 )); L=${3:-1}
|
||||
P="Scan timeout exceeded|Scan never terminated|Dropped [0-9]+ BLE|Guru|Backtrace|Unexpected|cmpl_fail=[1-9]|bad=[1-9]"
|
||||
while [ $(date +%s) -lt $E ]; do tail -n +$L $C | grep -a -q -E "$P" && break; sleep 15; done
|
||||
tail -n +$L $C | grep -a -E "$P" | head -5
|
||||
echo "$(date +%T) starts=$(tail -n +$L $C | grep -a -c 'Starting scan') completes=$(tail -n +$L $C | grep -a -c 'Scan complete, set')"
|
||||
grep -a scaninst $C | tail -1 | cut -c1-260
|
||||
@@ -0,0 +1,57 @@
|
||||
"""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")
|
||||
@@ -0,0 +1,75 @@
|
||||
# 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}
|
||||
@@ -0,0 +1,9 @@
|
||||
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
|
||||
@@ -0,0 +1,31 @@
|
||||
# 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]
|
||||
@@ -0,0 +1,15 @@
|
||||
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
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/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}
|
||||
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" || 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
|
||||
@@ -0,0 +1,20 @@
|
||||
# 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;
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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
|
||||
@@ -0,0 +1,135 @@
|
||||
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);
|
||||
@@ -0,0 +1,405 @@
|
||||
"""ccdrive.py TXHOST RXHOST MODE OUT: MODE short | long | lambda. 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."""
|
||||
|
||||
import asyncio
|
||||
import pathlib
|
||||
import re
|
||||
import statistics
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import APIClient, LogLevel
|
||||
|
||||
TXH, RXH, MODE, OUT = sys.argv[1:5]
|
||||
TXN, RXN = (sys.argv[5:7] + ["TX", "RX"])[:2] if len(sys.argv) >= 7 else ("TX", "RX")
|
||||
KEY = pathlib.Path(".apikey").read_text(encoding="utf-8").strip()
|
||||
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, [], []
|
||||
|
||||
async def start(self):
|
||||
self.cli = APIClient(self.host, 6053, None, noise_psk=KEY)
|
||||
await self.cli.connect(login=True)
|
||||
_, 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)
|
||||
|
||||
def on_log(self, m):
|
||||
line = m.message.decode(errors="replace")
|
||||
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):
|
||||
r = self.cli.execute_service(self.svc[name], kw)
|
||||
if asyncio.iscoroutine(r):
|
||||
asyncio.ensure_future(r)
|
||||
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:
|
||||
print(f" ({dev.tag} never logged {mark.strip()})", flush=True)
|
||||
|
||||
|
||||
async def case(
|
||||
tx,
|
||||
rx,
|
||||
label,
|
||||
count,
|
||||
length,
|
||||
b0,
|
||||
gap_ms,
|
||||
rx_len=None,
|
||||
tx_len=None,
|
||||
crc=False,
|
||||
wait=None,
|
||||
):
|
||||
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()
|
||||
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
|
||||
)
|
||||
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})
|
||||
print(
|
||||
f"{label:34} sent={count} 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 tx.start()
|
||||
await rx.start()
|
||||
await asyncio.sleep(1)
|
||||
if MODE.startswith("fast"):
|
||||
rates = {
|
||||
"fast38": (38400, 1, 20000, 135000, 50),
|
||||
"fast100": (100000, 0, 50000, 325000, 20),
|
||||
}
|
||||
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,
|
||||
)
|
||||
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)
|
||||
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 rx.act("cfg", len=300, crc=False)
|
||||
await tx.act("cfg", len=64, crc=False)
|
||||
rx.rx.clear()
|
||||
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]
|
||||
print(
|
||||
f"{'power_down mid-run, wake 1 s later':34} sent=10 good={sum(1 for p in got if int(p[0]) == 300 and p[3] == 1)} wrong={sum(1 for p in got if not (int(p[0]) == 300 and p[3] == 1))}",
|
||||
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 rx.act("cfg", len=1024, crc=False)
|
||||
await tx.act("cfg", len=64, crc=False)
|
||||
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 rx.act("cfg", len=1024, crc=False)
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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,
|
||||
)
|
||||
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 ")
|
||||
await d.cli.disconnect()
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,102 @@
|
||||
// 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.
|
||||
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;
|
||||
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
|
||||
@@ -0,0 +1,25 @@
|
||||
import asyncio
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from aioesphomeapi import APIClient, APIConnectionError
|
||||
|
||||
KEY = pathlib.Path(sys.argv[1]).read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
async def one(h):
|
||||
c = APIClient(h, 6053, None, noise_psk=KEY)
|
||||
try:
|
||||
await asyncio.wait_for(c.connect(login=True), 8)
|
||||
i = await c.device_info()
|
||||
print(h, i.name, i.mac_address, i.model, i.compilation_time, i.esphome_version)
|
||||
await c.disconnect()
|
||||
except (OSError, APIConnectionError) as e:
|
||||
print(h, "ERR", type(e).__name__, e)
|
||||
|
||||
|
||||
async def main():
|
||||
await asyncio.gather(*(one(h) for h in sys.argv[2:]))
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# flashmac.sh NAME MAC: find the board's port by MAC (ports.py lists it), upload NAME.yaml from TREE and wait until
|
||||
# NAME.local answers on the API with that name. Needs .apikey (the base64 key from secrets.yaml) next to the configs.
|
||||
# env: TREE, PY
|
||||
D=$(cd "$(dirname "$0")" && pwd); S=$(dirname "$D"); N=${1:?name}; MAC=${2:?mac}
|
||||
T=${TREE:?set TREE}; PY=${PY:-$T/venv/bin/python}; cd "$D" || exit 1
|
||||
P=$($PY "$S/ports.py" | grep -i -F " $MAC " | awk '{print $1}')
|
||||
[ -n "$P" ] || { echo "no port for $MAC"; exit 1; }
|
||||
echo "flash $N to $MAC on $P"
|
||||
PIO_CORE=${PIO_CORE:-$D/pio} bash "$S/pio_build.sh" upload "$N" "$D/$N.yaml" "$P" || exit 1
|
||||
for _ in $(seq 1 40); do
|
||||
if $PY devinfo.py .apikey "$N.local" 2>/dev/null | grep -q "$N "; then
|
||||
$PY devinfo.py .apikey "$N.local" 2>/dev/null | grep -v Warning; exit 0
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
echo "$N did not come up on the API"; exit 1
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# runall.sh A_MAC B_MAC: both roles. 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:?a mac}; B=${2:?b mac}
|
||||
PY=${PY:-${TREE:?set TREE}/venv/bin/python}
|
||||
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 "Warning\|tracemalloc\|self.cli\|^\s*$"
|
||||
}
|
||||
fl() { ./flashmac.sh "$1" "$2" || { echo "FLASH FAIL $1"; exit 1; }; sleep 8; }
|
||||
echo "===== Phase A: A receives, B sends"
|
||||
fl cc-b-long "$B"
|
||||
fl cc-a-long "$A"; for m in fast r2long r2mid long; do drive cc-b-long cc-a-long $m B A; done
|
||||
fl cc-a-lambda "$A"; for m in lambda r2lambda; do drive cc-b-long cc-a-lambda $m B A; done
|
||||
echo "===== Phase B: B receives, A sends"
|
||||
fl cc-a-long "$A"
|
||||
fl cc-b-long "$B"; for m in fast r2long r2mid long; do drive cc-a-long cc-b-long $m A B; done
|
||||
fl cc-b-lambda "$B"; for m in lambda r2lambda; do drive cc-a-long cc-b-lambda $m A B; done
|
||||
echo RUNDONE
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifndef FUZZ22773_CLIMATE_FUZZ_H
|
||||
#define FUZZ22773_CLIMATE_FUZZ_H
|
||||
// Test only (esphome#22773 A/B): feeds a climate's own frames, mutated copies and random frames to on_receive
|
||||
// and prints whether each was accepted and the state that followed.
|
||||
#include <cstdio>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include "esphome/components/climate_ir/climate_ir.h"
|
||||
#include "esphome/components/remote_base/remote_base.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
|
||||
namespace esphome::fuzz22773 {
|
||||
|
||||
class Cap : public remote_base::RemoteTransmitterBase {
|
||||
public:
|
||||
Cap() : RemoteTransmitterBase(nullptr) {}
|
||||
std::vector<remote_base::RawTimings> frames;
|
||||
|
||||
protected:
|
||||
void send_internal(uint32_t, uint32_t) override { this->frames.push_back(this->temp_.get_data()); }
|
||||
};
|
||||
|
||||
template<typename C> void prep(C &c, Cap &tx) {
|
||||
if (global_preferences != nullptr)
|
||||
global_preferences->reset();
|
||||
static char name[] = "fuzz";
|
||||
static char fn[] = "";
|
||||
App.pre_setup(name, sizeof(name) - 1, fn, 0);
|
||||
c.set_transmitter(&tx);
|
||||
static_cast<Component &>(c).setup();
|
||||
}
|
||||
|
||||
template<typename C> void print_state(const char *tag, int i, bool ok, C &c) {
|
||||
printf("FUZZ %s %d ok=%d mode=%d t=%.2f fan=%d swing=%d\n", tag, i, ok ? 1 : 0, (int) c.mode,
|
||||
(double) c.target_temperature, c.fan_mode.has_value() ? (int) *c.fan_mode : -1, (int) c.swing_mode);
|
||||
}
|
||||
|
||||
// make() returns a fresh climate; random_frame(rng, raw) fills raw with a random frame of the protocol
|
||||
template<typename Make, typename Rand> void run(const char *tag, Make make, Rand random_frame) {
|
||||
std::mt19937 rng(22773);
|
||||
// Valid frames: everything the climate itself sends
|
||||
std::vector<remote_base::RawTimings> valid;
|
||||
{
|
||||
Cap tx;
|
||||
auto c = make();
|
||||
prep(*c, tx);
|
||||
for (auto mode : {climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_COOL, climate::CLIMATE_MODE_HEAT,
|
||||
climate::CLIMATE_MODE_DRY, climate::CLIMATE_MODE_FAN_ONLY, climate::CLIMATE_MODE_HEAT_COOL})
|
||||
for (float t : {16.0f, 18.0f, 21.0f, 24.0f, 27.0f, 30.0f, 60.0f, 66.0f, 72.0f, 80.0f, 88.0f})
|
||||
for (auto fan : {climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM,
|
||||
climate::CLIMATE_FAN_HIGH}) {
|
||||
auto call = c->make_call();
|
||||
call.set_mode(mode);
|
||||
call.set_target_temperature(t);
|
||||
call.set_fan_mode(fan);
|
||||
call.perform();
|
||||
}
|
||||
valid = tx.frames;
|
||||
for (auto &v : valid)
|
||||
v.push_back(-20000); // the idle gap a receiver records after the last mark
|
||||
}
|
||||
int i = 0;
|
||||
auto feed = [&](const remote_base::RawTimings &raw, const char *kind) {
|
||||
Cap tx;
|
||||
auto c = make();
|
||||
prep(*c, tx);
|
||||
remote_base::RemoteReceiveData data(raw, 25, remote_base::TOLERANCE_MODE_PERCENTAGE);
|
||||
bool ok = static_cast<remote_base::RemoteReceiverListener &>(*c).on_receive(data);
|
||||
printf("%s ", kind);
|
||||
print_state(tag, i++, ok, *c);
|
||||
};
|
||||
for (const auto &v : valid) {
|
||||
feed(v, "valid");
|
||||
for (int m = 0; m < 4; m++) {
|
||||
auto raw = v;
|
||||
if (raw.size() < 8)
|
||||
continue;
|
||||
// a space swapped with another space's length flips a bit (or does nothing when they are equal)
|
||||
size_t a = 3 + rng() % (raw.size() - 3), b = 3 + rng() % (raw.size() - 3);
|
||||
if (raw[a] < 0 && raw[b] < 0)
|
||||
std::swap(raw[a], raw[b]);
|
||||
else
|
||||
raw[a] = raw[a] < 0 ? -int32_t(100 + rng() % 3000) : int32_t(100 + rng() % 3000);
|
||||
feed(raw, "mut");
|
||||
}
|
||||
auto t = v;
|
||||
t.resize(rng() % t.size());
|
||||
feed(t, "trunc");
|
||||
}
|
||||
for (int r = 0; r < 3000; r++) {
|
||||
remote_base::RawTimings raw;
|
||||
random_frame(rng, raw);
|
||||
feed(raw, "rand");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
} // namespace esphome::fuzz22773
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
#include "climate_fuzz.hpp"
|
||||
#include "esphome/components/friedrich/friedrich.h"
|
||||
#include "esphome/components/remote_base/aeha_protocol.h"
|
||||
namespace esphome::fuzz22773 {
|
||||
TEST(Fuzz22773, Friedrich) {
|
||||
run("friedrich", [] { return std::make_unique<friedrich::FriedrichClimate>(); },
|
||||
[](std::mt19937 &rng, remote_base::RawTimings &raw) {
|
||||
uint8_t d[35];
|
||||
size_t len = (rng() % 3 == 0) ? 2 + rng() % 34 : ((rng() & 1) ? 14 : 5);
|
||||
for (auto &b : d) b = rng();
|
||||
if (rng() % 2) { d[0] = 0x00; d[1] = 0x08; d[2] = 0x08; }
|
||||
remote_base::RemoteTransmitData tx;
|
||||
remote_base::AEHAProtocol().encode(&tx, (rng() % 4) ? 0x28C6 : uint16_t(rng()), d, len);
|
||||
raw = tx.get_data();
|
||||
});
|
||||
}
|
||||
} // namespace esphome::fuzz22773
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
#include "climate_fuzz.hpp"
|
||||
#include "esphome/components/haier_tundra/haier_tundra.h"
|
||||
#include "esphome/components/remote_base/haier_protocol.h"
|
||||
namespace esphome::fuzz22773 {
|
||||
TEST(Fuzz22773, HaierTundra) {
|
||||
run("haier_tundra", [] { return std::make_unique<haier_tundra::HaierTundra>(haier_tundra::HAIER_HEADER_UNIT_A); },
|
||||
[](std::mt19937 &rng, remote_base::RawTimings &raw) {
|
||||
uint8_t d[16];
|
||||
size_t len = (rng() % 3 == 0) ? 1 + rng() % 16 : 13;
|
||||
for (auto &b : d) b = rng();
|
||||
if (rng() % 2) d[0] = haier_tundra::HAIER_HEADER_UNIT_A;
|
||||
remote_base::RemoteTransmitData tx;
|
||||
remote_base::HaierProtocol().encode(&tx, d, len);
|
||||
raw = tx.get_data();
|
||||
raw.push_back(-20000);
|
||||
});
|
||||
}
|
||||
} // namespace esphome::fuzz22773
|
||||
@@ -0,0 +1,12 @@
|
||||
from esphome.components import remote_base
|
||||
from esphome.types import ConfigType
|
||||
from tests.testing_helpers import ComponentManifestOverride
|
||||
|
||||
|
||||
def override_manifest(manifest: ComponentManifestOverride) -> None:
|
||||
manifest.auto_load = ["climate_ir", "climate"]
|
||||
|
||||
async def to_code_testing(config: ConfigType) -> None:
|
||||
remote_base.request_protocol("haier")
|
||||
|
||||
manifest.to_code = to_code_testing
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
#include "climate_fuzz.hpp"
|
||||
#include "esphome/components/mistral_ir/mistral_ir.h"
|
||||
#include "esphome/components/remote_base/aeha_protocol.h"
|
||||
namespace esphome::fuzz22773 {
|
||||
TEST(Fuzz22773, MistralIR) {
|
||||
run("mistral", [] { return std::make_unique<mistral_ir::MistralIR>(); },
|
||||
[](std::mt19937 &rng, remote_base::RawTimings &raw) {
|
||||
uint8_t d[35];
|
||||
size_t len = (rng() % 3 == 0) ? 2 + rng() % 34 : 12;
|
||||
for (auto &b : d) b = rng();
|
||||
if (rng() % 2) { d[0] = 0x56; d[2] = 0x08; }
|
||||
remote_base::RemoteTransmitData tx;
|
||||
remote_base::AEHAProtocol().encode(&tx, (rng() % 4) ? mistral_ir::MISTRAL_ADDRESS : uint16_t(rng()), d, len);
|
||||
raw = tx.get_data();
|
||||
});
|
||||
}
|
||||
} // namespace esphome::fuzz22773
|
||||
@@ -0,0 +1,35 @@
|
||||
esphome:
|
||||
name: ${name}
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
logger:
|
||||
level: VERBOSE
|
||||
logs:
|
||||
wifi: DEBUG
|
||||
api: DEBUG
|
||||
api.service: DEBUG
|
||||
api.connection: DEBUG
|
||||
scheduler: DEBUG
|
||||
component: DEBUG
|
||||
esp32.preferences: DEBUG
|
||||
esp8266.preferences: DEBUG
|
||||
preferences: DEBUG
|
||||
mdns: DEBUG
|
||||
remote_receiver: DEBUG
|
||||
remote_transmitter: DEBUG
|
||||
climate: DEBUG
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
ota:
|
||||
- platform: esphome
|
||||
climate:
|
||||
- {platform: samsung, id: sam_tx, name: SAM TX, transmitter_id: irtx}
|
||||
- {platform: samsung, id: sam_rx, name: SAM RX, transmitter_id: irtx, receiver_id: irrx}
|
||||
- {platform: friedrich, id: fr_tx, name: FR TX, transmitter_id: irtx}
|
||||
- {platform: friedrich, id: fr_rx, name: FR RX, transmitter_id: irtx, receiver_id: irrx}
|
||||
- {platform: siemens_ira211, id: si_tx, name: SI TX, transmitter_id: irtx}
|
||||
- {platform: siemens_ira211, id: si_rx, name: SI RX, transmitter_id: irtx, receiver_id: irrx}
|
||||
- {platform: mistral_ir, id: mi_tx, name: MI TX, transmitter_id: irtx}
|
||||
- {platform: mistral_ir, id: mi_rx, name: MI RX, transmitter_id: irtx, receiver_id: irrx}
|
||||
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
name: c32pr
|
||||
packages:
|
||||
common: !include c-common.yaml
|
||||
board: !include esp32-ir.yaml
|
||||
@@ -0,0 +1,45 @@
|
||||
"""compare.py A B [TOL]: per step, frames equal (within TOL us) and RX states equal."""
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
a = json.loads(pathlib.Path(f"{sys.argv[1]}-frames.json").read_text(encoding="utf-8"))
|
||||
b = json.loads(pathlib.Path(f"{sys.argv[2]}-frames.json").read_text(encoding="utf-8"))
|
||||
tol = int(sys.argv[3]) if len(sys.argv) > 3 else 0
|
||||
same_f = same_s = 0
|
||||
maxdev = 0
|
||||
for x, y in zip(a, b, strict=False):
|
||||
assert x["step"] == y["step"]
|
||||
fa, fb = x["frames"], y["frames"]
|
||||
ok = len(fa) == len(fb) and all(
|
||||
len(p) == len(q)
|
||||
and all(
|
||||
(u > 0) == (v > 0) and abs(u - v) <= tol for u, v in zip(p, q, strict=False)
|
||||
)
|
||||
for p, q in zip(fa, fb, strict=False)
|
||||
)
|
||||
if ok:
|
||||
for p, q in zip(fa, fb, strict=False):
|
||||
for u, v in zip(p, q, strict=False):
|
||||
maxdev = max(maxdev, abs(u - v))
|
||||
same_f += ok
|
||||
st = x["rx"] == y["rx"]
|
||||
same_s += st
|
||||
if not ok or not st:
|
||||
print(
|
||||
"DIFF",
|
||||
x["step"],
|
||||
"frames",
|
||||
len(fa),
|
||||
len(fb),
|
||||
[len(p) for p in fa],
|
||||
[len(q) for q in fb],
|
||||
)
|
||||
if not st:
|
||||
for k in x["rx"]:
|
||||
if x["rx"][k] != y["rx"].get(k):
|
||||
print(" ", k, x["rx"][k], "|", y["rx"].get(k))
|
||||
print(
|
||||
f"steps {len(a)}/{len(b)} frames_equal {same_f} rx_states_equal {same_s} total_frames {sum(len(s['frames']) for s in a)}/{sum(len(s['frames']) for s in b)} max_dev_us {maxdev}"
|
||||
)
|
||||
@@ -0,0 +1,73 @@
|
||||
"""drive.py IP STEP...: STEP is 'Name:mode=cool,t=24,fan=low,swing=vertical' or 'svc:action'; prints climate states after each."""
|
||||
|
||||
import asyncio
|
||||
import pathlib
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from aioesphomeapi import (
|
||||
ClimateFanMode,
|
||||
ClimateInfo,
|
||||
ClimateMode,
|
||||
ClimatePreset,
|
||||
ClimateSwingMode,
|
||||
)
|
||||
from apiconn import connect
|
||||
|
||||
MODES = {m.name.lower(): m for m in ClimateMode}
|
||||
FANS = {m.name.lower(): m for m in ClimateFanMode}
|
||||
SWINGS = {m.name.lower(): m for m in ClimateSwingMode}
|
||||
PRESETS = {m.name.lower(): m for m in ClimatePreset}
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
c = await connect(sys.argv[1])
|
||||
ents, svcs = await c.list_entities_services()
|
||||
clim = {e.name: e for e in ents if isinstance(e, ClimateInfo)}
|
||||
byk = {e.key: e.name for e in clim.values()}
|
||||
st = {}
|
||||
c.subscribe_states(
|
||||
lambda s: st.__setitem__(byk[s.key], s) if s.key in byk else None
|
||||
)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
def show(tag):
|
||||
for n in sorted(st):
|
||||
s = st[n]
|
||||
print(
|
||||
f" {tag} {n:11s} mode={s.mode.name} target={s.target_temperature:g} fan={s.fan_mode.name} swing={s.swing_mode.name} preset={s.preset.name}"
|
||||
)
|
||||
|
||||
show("init")
|
||||
for step in sys.argv[2:]:
|
||||
name, _, args = step.partition(":")
|
||||
print(time.strftime("%H:%M:%S"), "STEP", step, flush=True)
|
||||
if name == "svc":
|
||||
sname, _, sargs = args.partition("?")
|
||||
data = {
|
||||
k: v == "1"
|
||||
for k, v in (a.split("=") for a in filter(None, sargs.split("&")))
|
||||
}
|
||||
await c.execute_service(next(s for s in svcs if s.name == sname), data)
|
||||
else:
|
||||
kw = {}
|
||||
for a in filter(None, args.split(",")):
|
||||
k, v = a.split("=")
|
||||
if k == "mode":
|
||||
kw["mode"] = MODES[v]
|
||||
elif k == "t":
|
||||
kw["target_temperature"] = float(v)
|
||||
elif k == "fan":
|
||||
kw["fan_mode"] = FANS[v]
|
||||
elif k == "swing":
|
||||
kw["swing_mode"] = SWINGS[v]
|
||||
elif k == "preset":
|
||||
kw["preset"] = PRESETS[v]
|
||||
c.climate_command(clim[name].key, **kw)
|
||||
await asyncio.sleep(float(__import__("os").environ.get("STEP_S", "2.5")))
|
||||
show("after")
|
||||
await c.disconnect()
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,18 @@
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
remote_transmitter:
|
||||
id: irtx
|
||||
pin:
|
||||
number: GPIO27
|
||||
allow_other_uses: true
|
||||
carrier_duty_percent: 100%
|
||||
remote_receiver:
|
||||
id: irrx
|
||||
pin:
|
||||
number: GPIO27
|
||||
allow_other_uses: true
|
||||
dump: raw
|
||||
rmt_symbols: 384
|
||||
receive_symbols: 384
|
||||
@@ -0,0 +1,19 @@
|
||||
esp8266:
|
||||
board: d1_mini
|
||||
remote_transmitter:
|
||||
id: irtx
|
||||
pin:
|
||||
number: GPIO12
|
||||
allow_other_uses: true
|
||||
carrier_duty_percent: 100%
|
||||
remote_receiver:
|
||||
id: irrx
|
||||
pin:
|
||||
number: GPIO12
|
||||
allow_other_uses: true
|
||||
dump: raw
|
||||
interval:
|
||||
# the receiver's setup leaves the shared pin an input; drive it so the transmitter reaches the pad
|
||||
- interval: 250ms
|
||||
then:
|
||||
- lambda: pinMode(12, OUTPUT);
|
||||
@@ -0,0 +1,38 @@
|
||||
"""flatcmp.py A B TOL: compare the whole raw frame sequence; report items over TOL and the largest deviation elsewhere."""
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
fa = [
|
||||
f
|
||||
for s in json.loads(
|
||||
pathlib.Path(f"{sys.argv[1]}-frames.json").read_text(encoding="utf-8")
|
||||
)
|
||||
for f in s["frames"]
|
||||
]
|
||||
fb = [
|
||||
f
|
||||
for s in json.loads(
|
||||
pathlib.Path(f"{sys.argv[2]}-frames.json").read_text(encoding="utf-8")
|
||||
)
|
||||
for f in s["frames"]
|
||||
]
|
||||
tol = int(sys.argv[3])
|
||||
mx = 0
|
||||
bad = 0
|
||||
items = 0
|
||||
print("frames", len(fa), len(fb))
|
||||
for i, (p, q) in enumerate(zip(fa, fb, strict=False)):
|
||||
if len(p) != len(q):
|
||||
print("frame", i, "length", len(p), len(q))
|
||||
bad += 1
|
||||
continue
|
||||
for j, (u, v) in enumerate(zip(p, q, strict=False)):
|
||||
items += 1
|
||||
if (u > 0) != (v > 0) or abs(u - v) > tol:
|
||||
print("frame", i, "item", j, u, v)
|
||||
bad += 1
|
||||
else:
|
||||
mx = max(mx, abs(u - v))
|
||||
print(f"items {items} over_tol {bad} max_dev_within_tol {mx}")
|
||||
@@ -0,0 +1,54 @@
|
||||
"""frames.py NAME: per step, the raw frames and the RX states. Prints JSON to NAME-frames.json."""
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
n = sys.argv[1]
|
||||
steps = []
|
||||
cur = None
|
||||
with pathlib.Path(f"{n}-drive.txt").open(encoding="utf-8") as fh:
|
||||
for text in fh:
|
||||
m = re.match(r"(\d\d:\d\d:\d\d) STEP (.*)", text)
|
||||
if m:
|
||||
cur = {"t": m[1], "step": m[2], "rx": {}, "tx": {}, "frames": []}
|
||||
steps.append(cur)
|
||||
m = re.match(r"\s+after (\S+ \S+)\s+(.*)", text)
|
||||
if m and cur:
|
||||
(cur["rx"] if m[1].endswith("RX") else cur["tx"])[m[1]] = m[2]
|
||||
frames = []
|
||||
buf = None
|
||||
with pathlib.Path(f"{n}-ser.txt").open(encoding="utf-8", errors="replace") as fh:
|
||||
for text in fh:
|
||||
m = re.match(r"\[(\d\d:\d\d:\d\d)\]\[I\]\[remote\.raw:(\d+)\]: ?(.*)", text)
|
||||
if not m:
|
||||
continue
|
||||
ts, line, body = m[1], m[2], m[3]
|
||||
if body.startswith("Received Raw:"):
|
||||
buf = [ts, body[len("Received Raw:") :]]
|
||||
elif buf is not None:
|
||||
buf[1] += body
|
||||
if buf is not None and line != "026":
|
||||
frames.append(
|
||||
(
|
||||
buf[0],
|
||||
[
|
||||
int(x)
|
||||
for x in buf[1].replace(" ", "").strip(",").split(",")
|
||||
if x
|
||||
],
|
||||
)
|
||||
)
|
||||
buf = None
|
||||
elif buf is not None and body.startswith("Received Raw:") and False:
|
||||
pass
|
||||
for ts, f in frames:
|
||||
owner = None
|
||||
for s in steps:
|
||||
if s["t"] <= ts:
|
||||
owner = s
|
||||
if owner:
|
||||
owner["frames"].append(f)
|
||||
pathlib.Path(f"{n}-frames.json").write_text(json.dumps(steps), encoding="utf-8")
|
||||
print(n, "steps", len(steps), "frames", sum(len(s["frames"]) for s in steps))
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# run.sh NAME PORT [STEPS_FILE]: serial capture with a reset, then the prelude and steps of STEPS_FILE (default
|
||||
# steps.sh here, which sets the PRE and STEPS arrays) through drive.py; writes NAME-ser.txt, NAME-pre.txt and
|
||||
# NAME-drive.txt. env: PY, BAUD (default 115200; use 921600 for long climate frames), STEP_S (default 2.5)
|
||||
D=$(cd "$(dirname "$0")" && pwd); S=$(dirname "$D"); N=${1:?name}; P=${2:?port}; PY=${PY:-python3}
|
||||
# shellcheck source=/dev/null
|
||||
source "${3:-$D/steps.sh}"
|
||||
cd "$D" || exit 1
|
||||
for k in $(lsof -t "$P" 2>/dev/null); do kill "$k"; done; sleep 1
|
||||
rm -f "$D/$N-ser.txt"
|
||||
nohup $PY "$S/serial_capture.py" "$P" 1000 "$D/$N-ser.txt" --reset --baud "${BAUD:-115200}" > /dev/null 2>&1 &
|
||||
IP=
|
||||
for _ in $(seq 1 60); do
|
||||
IP=$(LC_ALL=C grep -a -o -E "IP Address: [0-9.]+" "$N-ser.txt" 2>/dev/null | tail -1 | cut -d' ' -f3)
|
||||
[ -n "$IP" ] && break; sleep 2
|
||||
done
|
||||
[ -z "$IP" ] && { echo "no IP in $N-ser.txt"; exit 1; }
|
||||
sleep 3
|
||||
STEP_S=2.5 $PY drive.py "$IP" "${PRE[@]}" > "$N-pre.txt" 2>&1
|
||||
STEP_S=${STEP_S:-2.5} $PY drive.py "$IP" "${STEPS[@]}" > "$N-drive.txt" 2>&1
|
||||
sleep 2; for k in $(lsof -t "$P" 2>/dev/null); do kill "$k"; done; sleep 1
|
||||
echo "$N steps=$(grep -c STEP "$N-drive.txt") raw=$(LC_ALL=C grep -a -c 'Received Raw' "$N-ser.txt")" \
|
||||
"boots=$(LC_ALL=C grep -a -c 'Running through setup\|rst cause' "$N-ser.txt")"
|
||||
@@ -0,0 +1,14 @@
|
||||
# prelude puts every sender in the same state on both builds; frames before the first MARK step are not compared
|
||||
PRE=("SAM TX:mode=off,t=24,fan=auto,swing=off" "FR TX:mode=off,t=72,fan=auto,swing=off" "SI TX:mode=off,t=21,fan=auto,preset=comfort" "MI TX:mode=off,t=24,fan=auto")
|
||||
STEPS=()
|
||||
for p in "SAM TX" "FR TX" "MI TX"; do
|
||||
for m in heat_cool cool dry fan_only heat off; do STEPS+=("${p}:mode=$m"); done
|
||||
STEPS+=("${p}:mode=cool")
|
||||
if [ "$p" = "FR TX" ]; then fans=(high medium low quiet auto); else fans=(low medium high auto); fi
|
||||
for f in "${fans[@]}"; do STEPS+=("${p}:fan=$f"); done
|
||||
[ "$p" = "SAM TX" ] && for s in vertical horizontal both off; do STEPS+=("${p}:swing=$s"); done
|
||||
STEPS+=("${p}:mode=off")
|
||||
done
|
||||
STEPS+=("SI TX:mode=heat_cool" "SI TX:preset=eco" "SI TX:preset=comfort")
|
||||
for f in low medium high auto; do STEPS+=("SI TX:fan=$f"); done
|
||||
STEPS+=("SI TX:mode=off")
|
||||
@@ -0,0 +1,70 @@
|
||||
esphome:
|
||||
name: ${name}
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
logger:
|
||||
level: VERBOSE
|
||||
logs:
|
||||
wifi: DEBUG
|
||||
api: DEBUG
|
||||
api.service: DEBUG
|
||||
api.connection: DEBUG
|
||||
scheduler: DEBUG
|
||||
component: DEBUG
|
||||
esp32.preferences: DEBUG
|
||||
esp8266.preferences: DEBUG
|
||||
preferences: DEBUG
|
||||
mdns: DEBUG
|
||||
sensor: DEBUG
|
||||
remote_receiver: DEBUG
|
||||
remote_transmitter: DEBUG
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
actions:
|
||||
# A Hitachi frame the sender cannot produce: temperature nibble 15 (16 + 15 = 31 C, above the 30 C max), cool, fan low
|
||||
- action: inject_t15
|
||||
then:
|
||||
- lambda: |-
|
||||
static constexpr remote_base::BitTimings T{.bit_mark = 572, .one_space = 1659, .zero_space = 553};
|
||||
uint8_t s[21] = {0};
|
||||
s[0] = 0xA9; s[1] = 0x59; s[2] = 0x03; s[3] = 0xF2; s[6] = 0x80; s[10] = 0x20; s[15] = 0x02;
|
||||
s[18] = 0x38; s[19] = 0x08;
|
||||
s[13] = xor_bytes(&s[2], 11);
|
||||
s[20] = xor_bytes(&s[14], 6);
|
||||
ESP_LOGI("w22704", "inject t15");
|
||||
auto call = id(irtx).transmit();
|
||||
auto *d = call.get_data();
|
||||
d->set_carrier_frequency(38000);
|
||||
d->mark(9000); d->space(4494);
|
||||
for (int i = 0; i < 21; i++) {
|
||||
if (i == 6 || i == 14) { d->mark(572); d->space(7960); }
|
||||
d->item_bytes<T>(s + i, 1);
|
||||
}
|
||||
d->mark(572);
|
||||
call.perform();
|
||||
# A 14-byte frame (what some whirlpool remotes send): bytes 0 to 13, the second divider, then silence
|
||||
- action: inject_short
|
||||
variables:
|
||||
hitachi: bool
|
||||
then:
|
||||
- lambda: |-
|
||||
static constexpr remote_base::BitTimings T{.bit_mark = 572, .one_space = 1659, .zero_space = 553};
|
||||
uint8_t s[14] = {0};
|
||||
s[0] = hitachi ? 0xA9 : 0x83; s[1] = hitachi ? 0x59 : 0x06; s[2] = 0x03; s[3] = 0xE2; s[6] = 0x80;
|
||||
if (hitachi) s[10] = 0x20;
|
||||
s[13] = xor_bytes(&s[2], 11);
|
||||
ESP_LOGI("w22704", "inject short hitachi=%d", (int) hitachi);
|
||||
auto call = id(irtx).transmit();
|
||||
auto *d = call.get_data();
|
||||
d->set_carrier_frequency(38000);
|
||||
d->mark(9000); d->space(4494);
|
||||
for (int i = 0; i < 14; i++) {
|
||||
if (i == 6) { d->mark(572); d->space(7960); }
|
||||
d->item_bytes<T>(s + i, 1);
|
||||
}
|
||||
d->mark(572);
|
||||
call.perform();
|
||||
ota:
|
||||
- platform: esphome
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# all.sh PORT BASE_TREE PR_TREE: per whirlpool model (cl-dg, cl-hi, cl-hs), build wc.yaml + the model + the D1 mini
|
||||
# one-pin loopback from the base tree, then the PR tree, flash, run the whirlpool steps and split the frames. Base
|
||||
# runs first per model, so the board ends on a PR build. Compare the hex lines with `grep -a "Sending:\|Received:"`.
|
||||
# env: PY, BUILD_LOCK (optional)
|
||||
W=$(cd "$(dirname "$0")" && pwd); L=$(dirname "$W"); S=$(dirname "$L"); P=${1:?port}
|
||||
export PIO_CORE=${PIO_CORE:-$W/pio}
|
||||
for m in dg hi hs; do
|
||||
for v in base pr; do
|
||||
if [ $v = base ]; then T=${2:?base tree}; else T=${3:?pr tree}; fi
|
||||
N=w$m$v
|
||||
printf 'substitutions:\n name: %s\npackages:\n common: !include wc.yaml\n model: !include cl-%s.yaml\n board: !include ../esp8266-ir.yaml\n' \
|
||||
"$N" "$m" > "$W/$N.yaml"
|
||||
echo "== $N"
|
||||
TREE=$T bash "$S/pio_build.sh" compile "$N" "$W/$N.yaml" || continue
|
||||
TREE=$T bash "$S/pio_build.sh" upload "$N" "$W/$N.yaml" "$P" || continue
|
||||
PY=${PY:-$T/venv/bin/python}
|
||||
(cd "$L" && STEP_S=4 PY=$PY bash run.sh "$N" "$P" "$W/steps.sh" && $PY frames.py "$N")
|
||||
done
|
||||
done
|
||||
echo DONE
|
||||
@@ -0,0 +1,3 @@
|
||||
climate:
|
||||
- {platform: whirlpool, id: w_tx, name: W TX, model: DG11J1-3A, transmitter_id: irtx}
|
||||
- {platform: whirlpool, id: w_rx, name: W RX, model: DG11J1-3A, transmitter_id: irtx, receiver_id: irrx}
|
||||
@@ -0,0 +1,3 @@
|
||||
climate:
|
||||
- {platform: whirlpool, id: w_tx, name: W TX, model: HITACHI_HCRA31NEWH, transmitter_id: irtx}
|
||||
- {platform: whirlpool, id: w_rx, name: W RX, model: HITACHI_HCRA31NEWH, transmitter_id: irtx, receiver_id: irrx}
|
||||
@@ -0,0 +1,3 @@
|
||||
climate:
|
||||
- {platform: whirlpool, id: w_tx, name: W TX, model: HISENSE_ARG, transmitter_id: irtx}
|
||||
- {platform: whirlpool, id: w_rx, name: W RX, model: HISENSE_ARG, transmitter_id: irtx, receiver_id: irrx}
|
||||
@@ -0,0 +1,6 @@
|
||||
PRE=("W TX:mode=off,t=24,fan=auto,swing=off")
|
||||
STEPS=()
|
||||
for m in heat_cool heat cool dry fan_only off; do STEPS+=("W TX:mode=${m}"); done
|
||||
STEPS+=("W TX:mode=cool")
|
||||
for f in low medium high auto; do STEPS+=("W TX:fan=${f}"); done
|
||||
STEPS+=("W TX:mode=off")
|
||||
@@ -0,0 +1,27 @@
|
||||
esphome:
|
||||
name: ${name}
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
power_save_mode: none
|
||||
logger:
|
||||
level: VERBOSE
|
||||
logs:
|
||||
wifi: DEBUG
|
||||
api: DEBUG
|
||||
api.service: DEBUG
|
||||
api.connection: DEBUG
|
||||
scheduler: DEBUG
|
||||
component: DEBUG
|
||||
esp32.preferences: DEBUG
|
||||
esp8266.preferences: DEBUG
|
||||
preferences: DEBUG
|
||||
mdns: DEBUG
|
||||
sensor: DEBUG
|
||||
remote_receiver: DEBUG
|
||||
remote_transmitter: DEBUG
|
||||
climate: DEBUG
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
ota:
|
||||
- platform: esphome
|
||||
@@ -0,0 +1,102 @@
|
||||
"""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])))
|
||||
@@ -0,0 +1,179 @@
|
||||
"""trcheck.py D1HOST D1VAR E32HOST E32VAR SECONDS OUT.json: watch the entity_transport remote entities on both
|
||||
boards over the API and compare each received value with the sender's own published values."""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import math
|
||||
import pathlib
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
from aioesphomeapi import APIClient, APIConnectionError
|
||||
|
||||
D1, D1V, E32, E32V, SECS, OUT = (
|
||||
sys.argv[1],
|
||||
sys.argv[2],
|
||||
sys.argv[3],
|
||||
sys.argv[4],
|
||||
float(sys.argv[5]),
|
||||
sys.argv[6],
|
||||
)
|
||||
KEY = pathlib.Path(".apikey").read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
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))
|
||||
|
||||
|
||||
async def conn(host):
|
||||
c = APIClient(host, 6053, None, noise_psk=KEY)
|
||||
for _ in range(30):
|
||||
try:
|
||||
await asyncio.wait_for(c.connect(login=True), 10)
|
||||
return c
|
||||
except (OSError, APIConnectionError):
|
||||
await asyncio.sleep(1)
|
||||
sys.exit(f"no connection to {host}")
|
||||
|
||||
|
||||
async def main():
|
||||
boards = {"d1": (D1, D1V), "e32": (E32, E32V)}
|
||||
hist = {
|
||||
b: {"count": [], "float": set(), "bin": [], "count_to_float": {}}
|
||||
for b in boards
|
||||
}
|
||||
obs = {} # (receiver, kind, field) -> list of (t, value, missing)
|
||||
clients = {}
|
||||
for b, (host, _) in boards.items():
|
||||
c = await conn(host)
|
||||
clients[b] = c
|
||||
ents, _ = await c.list_entities_services()
|
||||
keys = {e.key: e.object_id for e in ents}
|
||||
peer_var = boards["e32" if b == "d1" else "d1"][1]
|
||||
last = {}
|
||||
|
||||
def cb(s, b=b, keys=keys, peer_var=peer_var, last=last):
|
||||
oid = keys.get(s.key)
|
||||
t = time.monotonic()
|
||||
if oid is None:
|
||||
return
|
||||
miss = bool(s.missing_state) or (
|
||||
isinstance(s.state, float) and math.isnan(s.state)
|
||||
)
|
||||
h = hist[b]
|
||||
if oid == "local_count" and not miss:
|
||||
h["count"].append((t, int(s.state)))
|
||||
last["count"] = int(s.state)
|
||||
elif oid == "local_float" and not miss:
|
||||
h["float"].add(f32(s.state))
|
||||
if "count" in last:
|
||||
h["count_to_float"][last["count"]] = f32(s.state)
|
||||
elif oid == "local_bin":
|
||||
h["bin"].append((t, bool(s.state)))
|
||||
elif oid.startswith("r_"):
|
||||
_, kind, var, field = oid.split("_")
|
||||
if var == peer_var:
|
||||
obs.setdefault(f"{b}<-{kind}:{field}", []).append(
|
||||
(t, s.state, miss)
|
||||
)
|
||||
elif not miss:
|
||||
obs.setdefault(f"{b}<-{kind}:{field}:otherpeer", []).append(
|
||||
(t, s.state, False)
|
||||
)
|
||||
|
||||
c.subscribe_states(cb)
|
||||
await asyncio.sleep(SECS)
|
||||
for c in clients.values():
|
||||
await c.disconnect()
|
||||
res = {"d1": D1V, "e32": E32V, "seconds": SECS, "links": {}}
|
||||
for key, lst in sorted(obs.items()):
|
||||
recv, rest = key.split("<-")
|
||||
kind, field = rest.split(":")[:2]
|
||||
sender = "e32" if recv == "d1" else "d1"
|
||||
h = hist[sender]
|
||||
if key.endswith("otherpeer"):
|
||||
res["links"][key] = {"values_after_initial": len(lst) - 1}
|
||||
continue
|
||||
vals = [(t, v) for t, v, m in lst if not m][
|
||||
1:
|
||||
] # the first is the state from before the run
|
||||
missing_after_first = sum(
|
||||
1
|
||||
for i, (t, v, m) in enumerate(lst)
|
||||
if m and any(not mm for _, _, mm in lst[:i])
|
||||
)
|
||||
r = {"updates": len(vals), "missing_after_first": missing_after_first}
|
||||
if field == "count":
|
||||
sent = {c for _, c in h["count"]}
|
||||
first = min(sent) if sent else 0
|
||||
r["before_run"] = sum(1 for _, v in vals if int(v) < first)
|
||||
last_sent = max(sent) if sent else 0
|
||||
r["not_sent"] = sum(
|
||||
1
|
||||
for _, v in vals
|
||||
if int(v) < first - 0
|
||||
and False
|
||||
or int(v) > last_sent + 60
|
||||
or int(v) != v
|
||||
)
|
||||
r["api_gap_values"] = sum(
|
||||
1
|
||||
for _, v in vals
|
||||
if first <= int(v) <= last_sent and int(v) not in sent
|
||||
)
|
||||
lags = []
|
||||
for t, v in vals:
|
||||
prior = [c for tt, c in h["count"] if tt <= t]
|
||||
if prior:
|
||||
lags.append(prior[-1] - int(v))
|
||||
r["max_lag_s"] = max(lags) if lags else None
|
||||
elif field == "flt":
|
||||
ok_t = [
|
||||
t
|
||||
for t, v, _m in obs[key.replace("flt", "count")]
|
||||
if not (isinstance(v, float) and math.isnan(v))
|
||||
and int(v) >= min(c for _, c in h["count"])
|
||||
]
|
||||
t0 = min(ok_t) if ok_t else 0
|
||||
lo, hi = min(c for _, c in h["count"]), max(c for _, c in h["count"]) + 60
|
||||
allowed = {expect(c) for c in range(max(1, lo - 30), hi + 1)}
|
||||
r["not_sent"] = sum(1 for t, v in vals if t >= t0 and f32(v) not in allowed)
|
||||
r["sender_float_mismatch"] = sum(
|
||||
1 for c, fv in h["count_to_float"].items() if fv != expect(c)
|
||||
)
|
||||
else:
|
||||
sent = [v for _, v in h["bin"]]
|
||||
r["transitions"] = sum(
|
||||
1 for i in range(1, len(vals)) if vals[i][1] != vals[i - 1][1]
|
||||
)
|
||||
r["sender_transitions"] = sum(
|
||||
1 for i in range(1, len(sent)) if sent[i] != sent[i - 1]
|
||||
)
|
||||
res["links"][key] = r
|
||||
ok = True
|
||||
for k, r in res["links"].items():
|
||||
if k.endswith("otherpeer"):
|
||||
ok = ok and r["values_after_initial"] == 0
|
||||
continue
|
||||
if (
|
||||
r["updates"] < 3
|
||||
or r.get("not_sent", 0)
|
||||
or r.get("sender_float_mismatch", 0)
|
||||
):
|
||||
ok = False
|
||||
if "transitions" in r and r["transitions"] < 2:
|
||||
ok = False
|
||||
res["expected_links_present"] = (
|
||||
len([k for k in res["links"] if not k.endswith("otherpeer")]) == 12
|
||||
)
|
||||
res["pass"] = ok and res["expected_links_present"]
|
||||
print(json.dumps(res, indent=1))
|
||||
pathlib.Path(OUT).write_text(json.dumps(res, indent=1), encoding="utf-8")
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
# abrun.sh V RUN [SECS]: flash ur66V.yaml (D1 mini) and ur32V.yaml (ESP32) from the tree of build V (p = PR_TREE,
|
||||
# anything else = BASE_TREE), capture both boards SECS seconds (default 150) from a reset and print the last STAT and
|
||||
# on_receive lines and the sendto error count per board. Make urNNV.yaml from ur32.example.yaml (set name and peer).
|
||||
# env: PR_TREE, BASE_TREE, PORT_D1, PORT_E32, PY
|
||||
D=$(cd "$(dirname "$0")" && pwd); S=$(dirname "$D"); cd "$D" || exit 1
|
||||
V=${1:?build}; R=${2:?run}; SECS=${3:-150}
|
||||
if [ "$V" = p ]; then export TREE=${PR_TREE:?set PR_TREE}; else export TREE=${BASE_TREE:?set BASE_TREE}; fi
|
||||
P1=${PORT_D1:?set PORT_D1}; P2=${PORT_E32:?set PORT_E32}; PY=${PY:-$TREE/venv/bin/python}
|
||||
bash "$S/pio_build.sh" upload "ur66$V" "ur66$V.yaml" "$P1" || exit 1
|
||||
bash "$S/pio_build.sh" upload "ur32$V" "ur32$V.yaml" "$P2" || exit 1
|
||||
$PY "$S/serial_capture.py" "$P1" "$SECS" "ab$R-$V-d1.log" --reset > /dev/null 2>&1 &
|
||||
$PY "$S/serial_capture.py" "$P2" "$SECS" "ab$R-$V-e32.log" --reset > /dev/null 2>&1 &
|
||||
wait
|
||||
for b in e32 d1; do
|
||||
F=ab$R-$V-$b.log
|
||||
echo "$V $R $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")"
|
||||
done
|
||||
@@ -0,0 +1,17 @@
|
||||
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
|
||||
@@ -0,0 +1,15 @@
|
||||
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
|
||||
@@ -0,0 +1,93 @@
|
||||
"""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. 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.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
|
||||
for path in sys.argv[1:]:
|
||||
links = collections.defaultdict(
|
||||
lambda: {"cnt": [], "flt": [], "bin": [], "long": [], "sess": []}
|
||||
)
|
||||
warns = collections.Counter()
|
||||
stats, chaos, boots = [], [], 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 False:
|
||||
pass
|
||||
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 or False:
|
||||
boots += 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}")
|
||||
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]:
|
||||
print(
|
||||
f" gap at {g[0] // 3600:02d}:{g[0] // 60 % 60:02d}:{g[0] % 60:02d}: {g[1]} -> {g[2]}"
|
||||
)
|
||||
if bad_flt:
|
||||
print(" bad flt", bad_flt[:5])
|
||||
last = {}
|
||||
for s in stats:
|
||||
body = s[s.find("STAT") :]
|
||||
last[body.split()[1]] = body
|
||||
for body in last.values():
|
||||
print(" " + body)
|
||||
for w, n in warns.most_common(15):
|
||||
print(f" W x{n}: {w[:170]}")
|
||||
@@ -0,0 +1,239 @@
|
||||
# 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]
|
||||
@@ -0,0 +1,99 @@
|
||||
#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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace entest
|
||||
|
||||
namespace entest {
|
||||
inline Stream RAW("raw", 0xA5, 0x5A);
|
||||
inline Stream P2P("p2p_seq", 0x1E, 0x5A);
|
||||
inline Stream BCR("bcrel_seq", 0x1E, 0x5B);
|
||||
} // namespace entest
|
||||
@@ -0,0 +1,15 @@
|
||||
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)++;
|
||||
@@ -0,0 +1,129 @@
|
||||
# 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"]}]}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
# rgrun.sh E32V D1V: flash rg32<E32V>.yaml and rg66<D1V>.yaml (p = PR_TREE, b = BASE_TREE), capture 150 s on both
|
||||
# and print the last STAT lines, the packet_transport status and the warning count. Make the files from
|
||||
# rg32.example.yaml (rg66 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
|
||||
E=${1:?esp32 build}; B=${2:?d1 build}; SECS=150
|
||||
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 "rg66$B" "rg66$B.yaml" "$P1" || exit 1
|
||||
TREE=$(tree "$E") bash "$S/pio_build.sh" upload "rg32$E" "rg32$E.yaml" "$P2" || exit 1
|
||||
$PY "$S/serial_capture.py" "$P1" $SECS "rg-$E$B-d1.log" --reset > /dev/null 2>&1 &
|
||||
$PY "$S/serial_capture.py" "$P2" $SECS "rg-$E$B-e32.log" --reset > /dev/null 2>&1 &
|
||||
wait
|
||||
for b in e32 d1; do
|
||||
F=rg-$E$B-$b.log
|
||||
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")"
|
||||
done
|
||||
@@ -0,0 +1,18 @@
|
||||
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
|
||||
@@ -0,0 +1,288 @@
|
||||
# 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
|
||||
- udtest.hpp
|
||||
on_boot:
|
||||
- priority: 600
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::UP2P.listen(id(p2p)->top());
|
||||
entest::UBCR.listen(id(bc_rel)->top());
|
||||
entest::UP2PF.listen(id(p2pf));
|
||||
entest::UP2PT.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::UP2P.send(id(p2p)->top(), RSIZES[entest::UP2P.idx++ % 3]);
|
||||
entest::UBCR.send(id(bc_rel)->top(), RSIZES[entest::UBCR.idx++ % 3]);
|
||||
entest::UP2PF.send(id(p2pf), 100);
|
||||
entest::UP2PT.send(id(p2pt), 100);
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::UP2P.log();
|
||||
entest::UBCR.log();
|
||||
entest::UP2PF.log();
|
||||
entest::UP2PT.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]
|
||||
@@ -0,0 +1,27 @@
|
||||
"""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)."""
|
||||
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
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(b"\xa5\x5b" + 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}")
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "entest.hpp"
|
||||
namespace entest {
|
||||
inline Stream UP2P("p2p_seq", 0x1E, 0x5A);
|
||||
inline Stream UBCR("bcrel_seq", 0x1E, 0x5B);
|
||||
inline Stream UP2PF("p2pf_raw", 0xA5, 0x5B);
|
||||
inline Stream UP2PT("p2pt_raw", 0xA5, 0x5C);
|
||||
} // namespace entest
|
||||
@@ -0,0 +1,11 @@
|
||||
substitutions:
|
||||
name: ur32p
|
||||
peer: ud66p
|
||||
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
|
||||
@@ -0,0 +1,36 @@
|
||||
# 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, udtest.hpp]
|
||||
on_boot:
|
||||
- priority: 600
|
||||
then:
|
||||
- lambda: entest::UP2PF.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::UP2PF.send(id(lnk), 100);
|
||||
- interval: 10s
|
||||
then:
|
||||
- lambda: |-
|
||||
entest::UP2PF.log();
|
||||
ESP_LOGI("stat", "STAT on_receive=%u", id(onrx));
|
||||
@@ -0,0 +1,124 @@
|
||||
"""Writes one config per validation case; expected outcome in the file name prefix (ok_ / bad_)."""
|
||||
|
||||
import pathlib
|
||||
import textwrap
|
||||
|
||||
E32 = "esp32:\n board: esp32dev\n framework:\n type: esp-idf\n"
|
||||
E66 = "esp8266:\n board: d1_mini\n"
|
||||
EN = "espnow:\n channel: 1\n{extra}"
|
||||
WIFI = "wifi:\n ssid: x\n password: yyyyyyyy\n"
|
||||
|
||||
|
||||
def en(name, link, plat=E32, extra=""):
|
||||
pathlib.Path(f"{name}.yaml").write_text(
|
||||
f"esphome:\n name: v{abs(hash(name)) % 10**6}\n{plat}{EN.format(extra=extra)}packet_interface:\n - platform: espnow\n id: l\n"
|
||||
+ textwrap.indent(textwrap.dedent(link), " "),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def udp(name, addrs, link, plat=E32):
|
||||
pathlib.Path(f"{name}.yaml").write_text(
|
||||
f"esphome:\n name: v{abs(hash(name)) % 10**6}\n{plat}{WIFI}udp:\n - id: u\n addresses: {addrs}\npacket_interface:\n - platform: udp\n id: l\n udp_id: u\n"
|
||||
+ textwrap.indent(textwrap.dedent(link), " "),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
# added for head f12e235cdd
|
||||
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)
|
||||
@@ -0,0 +1,62 @@
|
||||
"""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")
|
||||
@@ -0,0 +1,100 @@
|
||||
"""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]))
|
||||
Loaded 100 of 638 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user