sx127x: add an option to fix the LNA gain (turn off AGC) #3898
Unanswered
Jeremy Pack (scriptengine)
asked this question in
Component enhancements
Replies: 1 comment
|
🏷️ I've automatically added the |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Component name
sx127x
Link to component documentation on our website
https://esphome.io/components/sx127x/
Describe the enhancement
Background
I humbly request that an option is added to the sx127x (radio) component that allows the
gain to be set to a specific value rather than "Automatic Gain Control" (AGC).
Basically the radio I want to receive is close and powerful but only transmits intermittently
and typically the AGC sets its gain from weak signals when it starts and keeps that setting and the
station I want to listen to never gets decoded.
I have working code that I could offer in a PR, but I'm way out of my depth here. The code
was developed by an AI (Claude Code), and I know the Home Assistant and I suspect the ESPHome
projects are (rightly) sensitive to AI contributions that have not been human-reviewed, and I could not
walk anyone through the code line by line.
In summary, I'm either asking a dev to develop this on their own, or I can offer my working code
changes in PR form (tested in my environment), which I'm asking someone else with more knowledge
than myself to review and if appropriate submit into ESPHome.
How can I best contribute this change within the limits of my ability?
Summary
The
sx127xcomponent always switches on the radio's AGC. With a strong transmitter close by,in FSK mode, the AGC regularly picks maximum gain, overloading the receiver, so nothing is
decoded. Fixing the gain solved it completely. I'd like to propose an optional
lna_gain:setting so this can be done in YAML. The default would keep today's behaviour.
Proposal
A new optional setting:
AUTO(the default) is the current behaviour, with AGC on, so existing configs don't change.G1–G6turns AGC off and writes that gain to RegLna duringconfigure().bit in RegModemConfig3, which the component already sets.
The change looks small:
configure();__init__.py;What I can offer
Questions for maintainers:
lna_gainwithAUTO/G1…G6the right shape and naming?The problem
Setup:
sx127xin FSK continuous mode, with data on DIO2 intoremote_receiver.The SX1276's AGC chooses the LNA gain once, when reception starts, from whatever signal
triggers it. That is usually background noise, so it picks G1 (maximum gain). The station's
strong signal then overloads the receiver, and the demodulated data is garbage. In my tests:
Several things that looked like the cause did not fix it: frequency offset, AFC, bandwidth,
packet mode and the RSSI threshold (
rx_floor).Evidence: fixed-gain sweep
AGC off, LNA gain fixed at each step (RegLna 0x0C bits 7-5), tested in two positions about
20 cm apart. The second position is indoors behind glass, with a noisier RF floor.
With G5, AGC off and AFC on (my other settings unchanged):
BTW as an aside, apparently RegRssiValue is not gain-compensated. With a fixed gain, the
reported RSSI steps with the gain setting (about -103 dBm at G1 to -61 dBm at G6).
Current workaround
To get this I copied the
sx127xcomponent locally and maderead_register_/write_register_public. A YAML script then clears AgcAutoOn (RegRxConfig 0x0D bit 3) andsets RegLna, with a 60-second check that re-applies it if anything resets the radio. This
works, but it means maintaining a forked copy of the component and re-checking it on every
ESPHome release.
The bigger goal, though, is to make this option available to the community.
Use cases
To receive data from a specific station that only works at a specific gain. (My example is a near by weather station that transmits infrequently, and the AGC is locking onto more frequent weaker transmisssions)
Anything else?
No response
All reactions