Edit esp-espnow_test_transmitter1.yaml
This commit is contained in:
@@ -2,26 +2,51 @@
|
||||
# ESP-NOW Test Transmitter
|
||||
#:########################################################################################:#
|
||||
#
|
||||
# Hardware:
|
||||
# - ESP32-S3-Zero / ESP32-S3 Super Mini style board
|
||||
# DEVICE:
|
||||
# ESP32-S3-Zero / ESP32-S3 Super Mini
|
||||
#
|
||||
# Wiring:
|
||||
# - Button between GPIO4 and GND.
|
||||
# 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.
|
||||
#
|
||||
# Behaviour:
|
||||
# - Sleeps most of the time.
|
||||
# - Button press wakes the ESP32-S3.
|
||||
# - Sends ESP-NOW broadcast 3 times.
|
||||
# - Goes back to deep sleep.
|
||||
# WIRING:
|
||||
# GPIO4 ---- momentary 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.
|
||||
#
|
||||
# MESSAGE FORMAT:
|
||||
# REMOTE_A:BUTTON_1:123456789
|
||||
#
|
||||
# IMPORTANT:
|
||||
# - Set espnow.channel to the same 2.4 GHz Wi-Fi channel used by the receiver.
|
||||
# - 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.
|
||||
#
|
||||
#:########################################################################################:#
|
||||
|
||||
substitutions:
|
||||
device_name: espnow-test-transmitter
|
||||
friendly_name: "ESPNow Test Transmitter"
|
||||
device_name: esp-espnow-test-transmitter1
|
||||
friendly_name: "ESPNow Test Transmitter 1"
|
||||
|
||||
remote_id: "REMOTE_A"
|
||||
button_id: "BUTTON_1"
|
||||
|
||||
espnow_channel: "5"
|
||||
wake_pin: "4"
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESPHome Core
|
||||
#:########################################################################################:#
|
||||
|
||||
esphome:
|
||||
name: ${device_name}
|
||||
@@ -30,85 +55,180 @@ esphome:
|
||||
on_boot:
|
||||
priority: -100
|
||||
then:
|
||||
- logger.log: "Booted. Sending ESP-NOW test packet..."
|
||||
- logger.log:
|
||||
level: INFO
|
||||
format: "ESP-NOW transmitter booted."
|
||||
|
||||
- lambda: |-
|
||||
id(press_id) = esp_random();
|
||||
|
||||
char payload_buffer[96];
|
||||
snprintf(
|
||||
payload_buffer,
|
||||
sizeof(payload_buffer),
|
||||
"${remote_id}:${button_id}:%lu",
|
||||
static_cast<unsigned long>(id(press_id))
|
||||
);
|
||||
|
||||
id(transmit_payload) = payload_buffer;
|
||||
|
||||
ESP_LOGI(
|
||||
"espnow_tx",
|
||||
"Prepared payload: %s",
|
||||
id(transmit_payload).c_str()
|
||||
);
|
||||
|
||||
- script.execute: send_espnow_press
|
||||
- delay: 500ms
|
||||
- logger.log: "Going back to deep sleep."
|
||||
- script.wait: send_espnow_press
|
||||
|
||||
- logger.log:
|
||||
level: INFO
|
||||
format: "Transmission sequence finished. Entering deep sleep."
|
||||
|
||||
- delay: 250ms
|
||||
|
||||
- deep_sleep.enter: deep_sleep_control
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESP32 Hardware
|
||||
#:########################################################################################:#
|
||||
|
||||
esp32:
|
||||
board: esp32-s3-devkitc-1
|
||||
variant: esp32s3
|
||||
framework:
|
||||
type: arduino
|
||||
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
|
||||
|
||||
#:########################################################################################:#
|
||||
# No Wi-Fi on transmitter
|
||||
# ESP-NOW
|
||||
#:########################################################################################:#
|
||||
#
|
||||
# This keeps the transmitter fast and battery-friendly.
|
||||
# Upload over USB for this test.
|
||||
# The transmitter is not joining Wi-Fi, so the ESP-NOW radio channel must be
|
||||
# configured explicitly.
|
||||
#
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESP-NOW Transmit
|
||||
#:########################################################################################:#
|
||||
|
||||
espnow:
|
||||
channel: 6
|
||||
channel: ${espnow_channel}
|
||||
|
||||
#:########################################################################################:#
|
||||
# Globals
|
||||
#:########################################################################################:#
|
||||
|
||||
globals:
|
||||
- id: press_id
|
||||
type: uint32_t
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
|
||||
- id: transmit_payload
|
||||
type: std::string
|
||||
restore_value: false
|
||||
initial_value: '""'
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESP-NOW Transmission Script
|
||||
#:########################################################################################:#
|
||||
|
||||
script:
|
||||
- id: send_espnow_press
|
||||
mode: single
|
||||
then:
|
||||
- lambda: |-
|
||||
id(press_count) += 1;
|
||||
- logger.log:
|
||||
level: INFO
|
||||
format: "Sending ESP-NOW broadcast 1 of 3."
|
||||
|
||||
- espnow.broadcast:
|
||||
data: !lambda |-
|
||||
std::string msg = "REMOTE_A:BUTTON_1:" + to_string(id(press_count));
|
||||
return std::vector<uint8_t>(msg.begin(), msg.end());
|
||||
return std::vector<uint8_t>(
|
||||
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."
|
||||
on_error:
|
||||
- logger.log:
|
||||
level: WARN
|
||||
format: "Broadcast 1 reported an error."
|
||||
|
||||
- delay: 50ms
|
||||
|
||||
- logger.log:
|
||||
level: INFO
|
||||
format: "Sending ESP-NOW broadcast 2 of 3."
|
||||
|
||||
- espnow.broadcast:
|
||||
data: !lambda |-
|
||||
std::string msg = "REMOTE_A:BUTTON_1:" + to_string(id(press_count));
|
||||
return std::vector<uint8_t>(msg.begin(), msg.end());
|
||||
return std::vector<uint8_t>(
|
||||
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."
|
||||
on_error:
|
||||
- logger.log:
|
||||
level: WARN
|
||||
format: "Broadcast 2 reported an error."
|
||||
|
||||
- delay: 50ms
|
||||
|
||||
- logger.log:
|
||||
level: INFO
|
||||
format: "Sending ESP-NOW broadcast 3 of 3."
|
||||
|
||||
- espnow.broadcast:
|
||||
data: !lambda |-
|
||||
std::string msg = "REMOTE_A:BUTTON_1:" + to_string(id(press_count));
|
||||
return std::vector<uint8_t>(msg.begin(), msg.end());
|
||||
|
||||
globals:
|
||||
- id: press_count
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '0'
|
||||
return std::vector<uint8_t>(
|
||||
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."
|
||||
on_error:
|
||||
- logger.log:
|
||||
level: WARN
|
||||
format: "Broadcast 3 reported an error."
|
||||
|
||||
#:########################################################################################:#
|
||||
# Wake Button and Deep Sleep
|
||||
# Deep Sleep and Wake Button
|
||||
#:########################################################################################:#
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: wake_button
|
||||
name: "Wake Button"
|
||||
internal: true
|
||||
pin:
|
||||
number: GPIO4
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
#
|
||||
# GPIO4 is pulled HIGH internally.
|
||||
# Pressing the button connects GPIO4 to GND and wakes the ESP32.
|
||||
#
|
||||
# KEEP_AWAKE prevents an immediate sleep/wake loop if the button is still held
|
||||
# when the transmission sequence finishes.
|
||||
#
|
||||
|
||||
deep_sleep:
|
||||
id: deep_sleep_control
|
||||
|
||||
wakeup_pin:
|
||||
number: GPIO4
|
||||
mode: INPUT_PULLUP
|
||||
number: GPIO${wake_pin}
|
||||
mode:
|
||||
input: true
|
||||
pullup: true
|
||||
inverted: true
|
||||
sleep_duration: 365d
|
||||
|
||||
wakeup_pin_mode: KEEP_AWAKE
|
||||
Reference in New Issue
Block a user