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