Edit esp-espnow_test_transmitter1.yaml

This commit is contained in:
ESPHome Device Builder
2026-07-11 18:19:37 +12:00
parent 893ed9dcfc
commit 0377bf0b08
+108 -48
View File
@@ -1,36 +1,46 @@
#:########################################################################################:#
# ESP-NOW Test Transmitter
# ESP-NOW Test Transmitter 1
#:########################################################################################:#
#
# DEVICE:
# ESP32-S3-Zero / ESP32-S3 Super Mini
#
# VERSION:
# 1.1 - 2026-07-11
# - Removed duplicate GPIO4 binary sensor declaration.
# - GPIO4 is now used only as the deep-sleep wake pin.
# - Added KEEP_AWAKE handling while the wake button remains pressed.
# - Uses a random press ID rather than flash-backed press counting.
# - Sends each button press three times for improved reliability.
# - Configured ESP-NOW to use Wi-Fi channel 5.
# 1.2 - 2026-07-11
# - Changed GPIO4 wake source to ESP32 EXT1 ANY_LOW.
# - Added delay to allow ESP-NOW to initialise before transmission.
# - Added GPIO4 input and pull-up initialisation.
# - Waits for the wake button to be released before entering deep sleep.
# - Logs the ESP32 wake cause.
# - Sends each message three times for improved broadcast reliability.
#
# WIRING:
# GPIO4 ---- momentary button ---- GND
#
# 3.3 V
# |
# 10 kΩ
# |
# +-------- GPIO4
# |
# Push button
# |
# GND
#
# OPERATION:
# - Initial power-up or reset causes one test transmission.
# - The ESP32 then enters deep sleep.
# - Pressing the button pulls GPIO4 LOW and wakes the ESP32.
# - The ESP32 broadcasts the same message three times.
# - It waits until the button is released and returns to deep sleep.
# - Power-up or reset causes one transmission.
# - The transmitter sends the same ESP-NOW message three times.
# - It waits for GPIO4 to return HIGH.
# - It then enters deep sleep.
# - Pulling GPIO4 LOW wakes the transmitter and repeats the sequence.
#
# MESSAGE FORMAT:
# REMOTE_A:BUTTON_1:123456789
# REMOTE_A:BUTTON_1:<random press ID>
#
# IMPORTANT:
# - The receiver must be operating on Wi-Fi channel 5.
# - This transmitter intentionally has no Wi-Fi, API or OTA configuration.
# - Future updates will normally be installed by USB.
# - ESP-NOW channel must match the receiver network channel.
# - The receiver is currently operating on channel 5.
# - This transmitter deliberately does not connect to normal Wi-Fi.
# - Firmware updates are performed by USB.
#
#:########################################################################################:#
@@ -42,7 +52,7 @@ substitutions:
button_id: "BUTTON_1"
espnow_channel: "5"
wake_pin: "4"
wake_gpio: "4"
#:########################################################################################:#
# ESPHome Core
@@ -55,14 +65,40 @@ esphome:
on_boot:
priority: -100
then:
- logger.log:
level: INFO
format: "ESP-NOW transmitter booted."
- lambda: |-
// Explicitly configure GPIO4 as an input with a pull-up.
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT);
gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY);
const esp_sleep_wakeup_cause_t wake_cause =
esp_sleep_get_wakeup_cause();
ESP_LOGI(
"wake",
"ESP-NOW transmitter booted. Wake cause: %d",
static_cast<int>(wake_cause)
);
if (wake_cause == ESP_SLEEP_WAKEUP_EXT1) {
ESP_LOGI("wake", "Wake was caused by the GPIO4 EXT1 input.");
} else if (wake_cause == ESP_SLEEP_WAKEUP_UNDEFINED) {
ESP_LOGI("wake", "Wake was caused by power-up or reset.");
} else {
ESP_LOGI(
"wake",
"Wake was caused by another source: %d",
static_cast<int>(wake_cause)
);
}
# Allow all ESPHome components, including ESP-NOW, to finish setup.
- delay: 750ms
- lambda: |-
id(press_id) = esp_random();
char payload_buffer[96];
snprintf(
payload_buffer,
sizeof(payload_buffer),
@@ -83,9 +119,25 @@ esphome:
- logger.log:
level: INFO
format: "Transmission sequence finished. Entering deep sleep."
format: "Transmission sequence completed."
- delay: 250ms
# Do not enter sleep while GPIO4 is still held LOW.
- logger.log:
level: INFO
format: "Waiting for GPIO4 button release."
- wait_until:
condition:
lambda: |-
return gpio_get_level(GPIO_NUM_4) == 1;
- delay: 100ms
- logger.log:
level: INFO
format: "GPIO4 released. Entering deep sleep."
- delay: 100ms
- deep_sleep.enter: deep_sleep_control
@@ -94,17 +146,14 @@ esphome:
#:########################################################################################:#
esp32:
variant: esp32s3
board: esp32-s3-devkitc-1
framework:
type: esp-idf
#:########################################################################################:#
# Logging
#:########################################################################################:#
#
# USB serial logging is useful during initial testing.
# It does consume some power while the device is awake, but awake time is brief.
#
logger:
level: DEBUG
@@ -113,12 +162,13 @@ logger:
# ESP-NOW
#:########################################################################################:#
#
# The transmitter is not joining Wi-Fi, so the ESP-NOW radio channel must be
# configured explicitly.
# The transmitter does not connect to Wi-Fi, so its radio channel is set
# explicitly. Both transmitter and receiver must use the same channel.
#
espnow:
channel: ${espnow_channel}
enable_on_boot: true
#:########################################################################################:#
# Globals
@@ -142,6 +192,7 @@ globals:
script:
- id: send_espnow_press
mode: single
then:
- logger.log:
level: INFO
@@ -153,18 +204,21 @@ script:
id(transmit_payload).begin(),
id(transmit_payload).end()
);
wait_for_sent: true
continue_on_error: true
on_sent:
- logger.log:
level: DEBUG
format: "Broadcast 1 sent."
format: "Broadcast 1 submitted successfully."
on_error:
- logger.log:
level: WARN
format: "Broadcast 1 reported an error."
- delay: 50ms
- delay: 75ms
- logger.log:
level: INFO
@@ -176,18 +230,21 @@ script:
id(transmit_payload).begin(),
id(transmit_payload).end()
);
wait_for_sent: true
continue_on_error: true
on_sent:
- logger.log:
level: DEBUG
format: "Broadcast 2 sent."
format: "Broadcast 2 submitted successfully."
on_error:
- logger.log:
level: WARN
format: "Broadcast 2 reported an error."
- delay: 50ms
- delay: 75ms
- logger.log:
level: INFO
@@ -199,36 +256,39 @@ script:
id(transmit_payload).begin(),
id(transmit_payload).end()
);
wait_for_sent: true
continue_on_error: true
on_sent:
- logger.log:
level: DEBUG
format: "Broadcast 3 sent."
format: "Broadcast 3 submitted successfully."
on_error:
- logger.log:
level: WARN
format: "Broadcast 3 reported an error."
- delay: 75ms
#:########################################################################################:#
# Deep Sleep and Wake Button
# Deep Sleep and GPIO4 Wake
#:########################################################################################:#
#
# GPIO4 is pulled HIGH internally.
# Pressing the button connects GPIO4 to GND and wakes the ESP32.
# ESP32-S3 supports EXT1 ANY_LOW wake.
#
# KEEP_AWAKE prevents an immediate sleep/wake loop if the button is still held
# when the transmission sequence finishes.
# With one configured pin, ANY_LOW means:
# Wake when GPIO4 is pulled LOW.
#
# An external 10 kΩ pull-up between GPIO4 and 3.3 V is recommended.
#
deep_sleep:
id: deep_sleep_control
wakeup_pin:
number: GPIO${wake_pin}
mode:
input: true
pullup: true
inverted: true
esp32_ext1_wakeup:
pins:
- GPIO${wake_gpio}
wakeup_pin_mode: KEEP_AWAKE
mode: ANY_LOW