sx126x and sx127x Listeners Receive Packets as a Span
The sx126x and sx127x radios now receive each packet into a fixed buffer and hand listeners a
std::span<const uint8_t> instead of a std::vector<uint8_t>. External components that implement
SX126xListener or SX127xListener should change their on_packet() signature; the old one keeps compiling until
2027.6.0.
This is a developer breaking change for external components in ESPHome 2026.12.0 and later.
Background
Section titled “Background”PR #23493: Keep received packets in a fixed buffer
Each received packet was built in a std::vector<uint8_t>, and the on_packet trigger copied it again for every
automation. A packet from these chips is at most 255 bytes, so each radio now keeps one 255-byte buffer and passes
views of it. On a simulated radio this took a receive test from 6,764 heap allocations to one, and saved about 210
bytes of flash.
What’s Changing
Section titled “What’s Changing”SX126xListener::on_packet()andSX127xListener::on_packet()takestd::span<const uint8_t> packetinstead ofconst std::vector<uint8_t> &packet.- The old
on_packet(const std::vector<uint8_t> &, float, float)is deprecated. A listener that still overrides it keeps working: the default span method copies the packet into a vector and calls it, and logs one warning the first time it does. GCC and clang do not warn at compile time about overriding a deprecated virtual, so look for that log line. packet_interface::RadioLinkBase::receive_()takes astd::span<const uint8_t>. There is no deprecation path for it. ARadioLinksubclass that still overrides the vectoron_packet()no longer builds (“overriding final function”), since the radios only call the span form; override the span form instead. Callingon_packet()on a link with a vector still works.xin theon_packetautomation is aByteView: astd::span<const uint8_t>that also converts tostd::vector<uint8_t>and compares with one.
Who This Affects
Section titled “Who This Affects”- External components that implement
SX126xListenerorSX127xListener - External components that derive from
RadioLink
Most YAML configurations are not affected. x.size(), x[i], x.data(), for (auto b : x),
std::string(x.begin(), x.end()), format_hex(x), format_hex_pretty(x), format_hex_to(buf, x),
x == std::vector<uint8_t>{...}, return x; and passing x to a function or script that takes a vector all still
work. A lambda breaks only if it:
- changes
x(x.push_back(...),x.clear()) - calls
x.at(i) - keeps
xpast adelayor other wait: the buffer holds the next packet by then
Migration Guide
Section titled “Migration Guide”// Beforevoid on_packet(const std::vector<uint8_t> &packet, float rssi, float snr) override;
// Aftervoid on_packet(std::span<const uint8_t> packet, float rssi, float snr) override;The body usually needs no change: packet.size(), packet[i], packet.data() and range-for work on a span. Code
that needs a vector makes the copy itself: std::vector<uint8_t> data(packet.begin(), packet.end());. A helper that
took const std::vector<uint8_t> & can take std::span<const uint8_t> instead; a vector still converts to it.
In a YAML lambda, copy x first when you need to change or keep it:
on_packet: then: - lambda: |- std::vector<uint8_t> data = x; data.push_back(0x00);Supporting Multiple ESPHome Versions
Section titled “Supporting Multiple ESPHome Versions”Use the version macro to override the right form on each version, which avoids the copy per packet and the warning on 2026.12.0 and later:
#include "esphome/core/version.h"
#if ESPHOME_VERSION_CODE >= VERSION_CODE(2026, 12, 0)void on_packet(std::span<const uint8_t> packet, float rssi, float snr) override;#elsevoid on_packet(const std::vector<uint8_t> &packet, float rssi, float snr) override;#endifKeeping only the vector override also works on both until 2027.6.0: it is called directly before 2026.12.0, and through the deprecated default from 2026.12.0, at the cost of one copy per packet and the one-time warning.
Timeline
Section titled “Timeline”- ESPHome 2026.12.0 (December 2026): listeners receive a span; the vector override is deprecated and still called.
- ESPHome 2027.6.0 (June 2027): the vector override is removed.
Finding Code That Needs Updates
Section titled “Finding Code That Needs Updates”grep -rnE 'SX12[67]xListener|on_packet\(const std::vector' your_component/Questions?
Section titled “Questions?”If you have questions about migrating your external component, please ask in:
- ESPHome Discord - #devs channel
- ESPHome GitHub Discussions
Related Documentation
Section titled “Related Documentation”Copyright © 2026 ESPHome - A project from the Open Home Foundation
Comments
Feel free to leave a comment here to discuss this post with others. You can ask questions, share your experience, or suggest improvements. If you have a question about a specific feature or issue, please consider using the ESPHome Discord. Stick to English and follow ESPHome's code of conduct. These comments exist on a discussion on GitHub, so you can also comment there directly if you prefer.