Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sx127x component #7490

Draft
wants to merge 31 commits into
base: dev
Choose a base branch
from
Draft

Add sx127x component #7490

wants to merge 31 commits into from

Conversation

swoboda1337
Copy link
Contributor

@swoboda1337 swoboda1337 commented Sep 24, 2024

What does this implement/fix?

The SX127X component allows you to configure/control the SX1276, SX1277, SX1278 and SX1279 transceivers in ESPHome. Supported frequencies range from 137 MHz to 1020 MHz. Supported modulations include OOK, FSK, GFSK, MSK and GMSK. Support for both receive and transmit. These chips contain two modems. The LoRa modem is not supported by this component, only the FSK/OOK modem.

Datasheet: https://www.semtech.com/products/wireless-rf/lora-connect/sx1278#documentation

There are many devices in the market with an ESP32 already packaged with these radios, examples: https://www.lilygo.cc/en-ca/products/lora3, https://heltec.org/project/wifi-lora-32v2/ and https://shop.m5stack.com/products/m5stack-lora-module-433mhz-v1-1

There are already about a dozen or so people using my component. I currently use it for my 433 MHz AcuRite weather sensors (https://github.com/swoboda1337/acurite-esphome). It would be nice to get these radios officially supported.

Docs can be found here: https://deploy-preview-4278--esphome.netlify.app/components/sx127x

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): #7483

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#4278

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

Docs can be found here: https://deploy-preview-4278--esphome.netlify.app/components/sx127x

external_components:
  - source: github://pr#7490
    components: [ sx127x ]
    refresh: 5min
    
sx127x:
  nss_pin: GPIO18
  rst_pin: GPIO23
  frequency: 433920000
  modulation: OOK
  rx_start: true
  rx_bandwidth: 50_0kHz
  rx_floor: -90

remote_receiver:
  pin: GPIO32
  dump: raw

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

Hey there @swoboda1337,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.
In __init__.py of the integration, please add:

CODEOWNERS = ["@swoboda1337"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.81%. Comparing base (4d8b5ed) to head (49f71e8).
Report is 1571 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #7490      +/-   ##
==========================================
+ Coverage   53.70%   53.81%   +0.10%     
==========================================
  Files          50       50              
  Lines        9408     9795     +387     
  Branches     1654     1351     -303     
==========================================
+ Hits         5053     5271     +218     
- Misses       4056     4198     +142     
- Partials      299      326      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lboue
Copy link
Contributor

lboue commented Sep 24, 2024

Build is OK for M5stack Cores3 and Module-LoRa868_V1.1.

[19:20:18][C][spi:064]: SPI bus:
[19:20:18][C][spi:065]:   CLK Pin: GPIO36
[19:20:18][C][spi:066]:   SDI Pin: GPIO35
[19:20:18][C][spi:067]:   SDO Pin: GPIO37
[19:20:18][C][spi:072]:   Using HW SPI: SPI
[19:20:18][C][sx127x:128]: SX127x:
[19:20:18][C][sx127x:129]:   NSS Pin: GPIO6
[19:20:18][C][sx127x:130]:   RST Pin: GPIO5
[19:20:18][C][sx127x:131]:   PA Pin: BOOST
[19:20:18][C][sx127x:132]:   PA Power: 17 dBm
[19:20:18][C][sx127x:133]:   Frequency: 869.524963 MHz
[19:20:18][C][sx127x:134]:   Modulation: OOK
[19:20:18][C][sx127x:135]:   Rx Bandwidth: 50.0 kHz
[19:20:18][C][sx127x:136]:   Rx Start: true
[19:20:18][C][sx127x:137]:   Rx Floor: -90.0 dBm
[19:20:18][C][sx127x:138]:   FSK Fdev: 5000 Hz
[19:20:18][C][sx127x:139]:   FSK Ramp: 40 us
[19:20:18][C][sx127x:147]:   FSK Shaping: NONE

@swoboda1337 swoboda1337 marked this pull request as ready for review September 24, 2024 17:53
@swoboda1337
Copy link
Contributor Author

swoboda1337 commented Sep 30, 2024

Converted to draft temporarily to do more fsk testing,

@herostrat
Copy link

No review, just a thank you for writing this component.
It works for me (heltec lora 32 v2)!

@swoboda1337
Copy link
Contributor Author

swoboda1337 commented Oct 20, 2024

Packet mode is done, works great with fsk there is an on_packet trigger. M5stack can be used now as it only supports packet mode. Need to add a few automations and it's done.

@swoboda1337 swoboda1337 marked this pull request as ready for review October 21, 2024 14:40
@swoboda1337
Copy link
Contributor Author

Everything is done, will be updating the docs this week.

Copy link
Contributor

@paravoid paravoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I know very little about the SX127s, so consider this a mostly uninformed review.

Broadly speaking, there are a lot of magic numbers in the code (some I've left comments at, but there are plenty more) and I had to go back and forth to the datasheet to unpack the code. So for clueless folks like me 😁, perahps it would be useful to add names to many (most?) of them, especially when the datasheet already has names defined for them (e.g. FXOSC).

Hope this review helps!

esphome/components/sx127x/sx127x.cpp Outdated Show resolved Hide resolved
esphome/components/sx127x/sx127x.cpp Outdated Show resolved Hide resolved
esphome/components/sx127x/sx127x.cpp Outdated Show resolved Hide resolved
esphome/components/sx127x/sx127x.h Show resolved Hide resolved
esphome/components/sx127x/__init__.py Outdated Show resolved Hide resolved
esphome/components/sx127x/__init__.py Outdated Show resolved Hide resolved
@swoboda1337
Copy link
Contributor Author

Docs are done and I made some updates after review comments. Should be ready to go

@swoboda1337 swoboda1337 requested a review from paravoid November 20, 2024 02:36
@swoboda1337 swoboda1337 marked this pull request as draft December 12, 2024 16:11
@swoboda1337
Copy link
Contributor Author

Moved to draft until new RMT drivers are integrated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants