├── .gitignore ├── esp32-cc1101-udp-example-noxmit.yaml ├── .editorconfig ├── components └── radiolib_cc1101 │ ├── hack_radiolib_buildopt.py │ ├── README.md │ ├── radiolib_cc1101.h │ ├── __init__.py │ ├── EHRLHal.h │ └── radiolib_cc1101.cpp ├── esp8266-cc1101.yaml ├── esp32-cc1101.yaml ├── README.md ├── .clang-format ├── .clang-tidy ├── esp32-cc1101-tcp-example.yaml ├── esp32-cc1101-udp-example.yaml └── cc1101-controls.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | # Gitignore settings for ESPHome 2 | /.esphome/ 3 | /secrets.yaml 4 | __pycache__/ 5 | .vscode/ 6 | /nodemcu_wifi.yaml 7 | -------------------------------------------------------------------------------- /esp32-cc1101-udp-example-noxmit.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | baseline: !include esp32-cc1101-udp-example.yaml 3 | 4 | # example for testing receive standalone 5 | remote_receiver: 6 | - id: !extend rf_receiver 7 | pin: 8 | allow_other_uses: false 9 | 10 | remote_transmitter: !remove 11 | button: !remove 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | # general 4 | [*] 5 | end_of_line = lf 6 | insert_final_newline = true 7 | charset = utf-8 8 | 9 | # python 10 | [*.py] 11 | indent_style = space 12 | indent_size = 4 13 | 14 | # C++ 15 | [*.{cpp,h,tcc}] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | # Web 20 | [*.{js,html,css}] 21 | indent_style = space 22 | indent_size = 2 23 | 24 | # YAML 25 | [*.{yaml,yml}] 26 | indent_style = space 27 | indent_size = 2 28 | quote_type = double 29 | 30 | # JSON 31 | [*.json] 32 | indent_style = space 33 | indent_size = 2 34 | -------------------------------------------------------------------------------- /components/radiolib_cc1101/hack_radiolib_buildopt.py: -------------------------------------------------------------------------------- 1 | import os 2 | from collections import deque 3 | 4 | Import("env") 5 | 6 | def update_build(env, node): 7 | if 'RadioLib' in node.get_abspath(): 8 | # Remove any Arduino defines for RadioLib 9 | env["CPPDEFINES"] = deque(x for x in env["CPPDEFINES"] 10 | if not ('ARDUINO' in x or 11 | (isinstance(x, (list, tuple)) and 'ARDUINO' in x[0]))) 12 | 13 | #print(f"node: {node}") 14 | return node 15 | 16 | env.AddBuildMiddleware(update_build) 17 | -------------------------------------------------------------------------------- /components/radiolib_cc1101/README.md: -------------------------------------------------------------------------------- 1 | ```yaml 2 | # example configuration: 3 | 4 | radiolib_cc1101: 5 | id: mycc1101 6 | cs_pin: D8 # # CC1101 pin 4 7 | filter: 150khz # 58-812khz, default=464kHz 8 | freq: 433.92MHz # 300-348, 387-464, 779-928MHz, default=433.92MHz 9 | rx_pin: 10 | number: D2 # # This is CC1101 GDO0 pin 3 11 | allow_other_uses: true 12 | tx_pin: 13 | number: D2 # This is also GDO0 14 | allow_other_uses: true 15 | 16 | spi: 17 | # these are the default SPI pins to use on ESP8266 18 | clk_pin: D5 # CC1001 pin 5 19 | mosi_pin: D7 # CC1001 pin 6 20 | miso_pin: D6 # CC1001 pin 7 21 | 22 | ``` 23 | -------------------------------------------------------------------------------- /esp8266-cc1101.yaml: -------------------------------------------------------------------------------- 1 | external_components: 2 | - source: 3 | type: git 4 | url: https://github.com/juanboro/esphome-radiolib-cc1101 5 | 6 | packages: 7 | cc1101_controls: !include cc1101-controls.yaml 8 | 9 | spi: 10 | # these are the default SPI pins to use on ESP8266 11 | clk_pin: D5 # CC1001 pin 5 12 | mosi_pin: D7 # CC1001 pin 6 13 | miso_pin: D6 # CC1001 pin 7 14 | 15 | radiolib_cc1101: 16 | id: mycc1101 17 | cs_pin: D8 # CC1101 pin 4 18 | rx_pin: 19 | number: D2 # This is CC1101 GDO0 pin 3 20 | allow_other_uses: true 21 | tx_pin: 22 | number: D2 # This is also GDO0 23 | allow_other_uses: true 24 | 25 | remote_receiver: 26 | - id: rf_receiver 27 | pin: 28 | number: D2 # This is also GDO0 29 | allow_other_uses: true 30 | id: cc1101_gd0_recv 31 | 32 | # dump: raw 33 | 34 | #on_raw: 35 | # Note on_raw... 36 | # The memory size of the esp8266 is VERY small, and on_raw can just crash on creating the integer vector on 37 | # the heap. So really, outside of either using the rc switch decoding, or writing a custom decoder, receiving is 38 | # pretty limited on the esp8266. 39 | 40 | remote_transmitter: 41 | - id: rf_transmitter 42 | pin: 43 | number: D2 # This is GDO0 44 | allow_other_uses: true 45 | id: cc1101_gd0_xmit 46 | on_transmit: 47 | then: 48 | - lambda: id(mycc1101).xmit(); 49 | on_complete: 50 | then: 51 | - lambda: id(mycc1101).recv(); 52 | carrier_duty_percent: 100% 53 | 54 | ota: 55 | platform: esphome 56 | on_begin: 57 | - lambda: id(mycc1101).standby(); 58 | -------------------------------------------------------------------------------- /esp32-cc1101.yaml: -------------------------------------------------------------------------------- 1 | substitutions: 2 | cs: "5" # CC1101 pin 4 3 | clk: "18" # CC1101 pin 5 4 | mosi: "23" # CC1101 pin 6 5 | miso: "19" # CC1101 pin 7 6 | rx: "32" # CC1101 pin 3 7 | tx: "32" # CC1101 pin 3 8 | tx_rx_shared: "true" 9 | 10 | external_components: 11 | - source: github://juanboro/esphome-radiolib-cc1101@main 12 | components: [ radiolib_cc1101 ] 13 | 14 | packages: 15 | cc1101_controls: !include cc1101-controls.yaml 16 | 17 | spi: 18 | # these are the default VSPI pins to use on ESP32 19 | clk_pin: $clk # CC1101 pin 5 20 | mosi_pin: $mosi # CC1101 pin 6 21 | miso_pin: $miso # CC1101 pin 7 22 | 23 | remote_receiver: 24 | - id: rf_receiver 25 | idle: 10ms 26 | filter: 20us # Some RF sources have pretty high BW - adjust as needed 27 | buffer_size: 2048 # This value is pretty large... default 10k is way too large 28 | pin: 29 | number: $rx 30 | allow_other_uses: true 31 | mode: 32 | output: false 33 | input: true 34 | pullup: $tx_rx_shared 35 | open_drain: false 36 | id: cc1101_gd0_recv 37 | 38 | remote_transmitter: 39 | - id: rf_transmitter 40 | pin: 41 | number: $tx 42 | allow_other_uses: ${tx_rx_shared} 43 | mode: 44 | output: true 45 | input: true 46 | pullup: true 47 | open_drain: true 48 | id: cc1101_gd0_xmit 49 | 50 | on_transmit: 51 | then: 52 | - lambda: |- 53 | id(mycc1101).xmit(); 54 | on_complete: 55 | then: 56 | - lambda: |- 57 | id(mycc1101).recv(); 58 | carrier_duty_percent: 100% 59 | 60 | radiolib_cc1101: 61 | id: mycc1101 62 | cs_pin: 5 # CC1101 pin 4 63 | 64 | # optionally define rx_pin to allow monitoring rx rssi 65 | rx_pin: 66 | number: $rx # This is CC1101 GDO0 pin 3 67 | allow_other_uses: true 68 | 69 | # other optional settings.. (use control settings to verify they work and then set) 70 | filter: 468khz # RX filter BW (58-812kHz) 71 | bitrate: 10 # bitrate (0.025-600kbps) 72 | reg_agcctrl0: 0xb2 # agcctrol0 register setting 73 | reg_agcctrl1: 0x00 # agcctrol1 register setting 74 | reg_agcctrl2: 0xc7 # agcctrol2 register setting 75 | 76 | # it's a good idea to turn off the CC1101 receiver when doing OTA updates 77 | ota: 78 | platform: esphome 79 | on_begin: 80 | - lambda: id(mycc1101).standby(); 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esphome-radiolib-cc1101 2 | Uses [Radiolib](https://github.com/jgromes/RadioLib) to enable a TI-CC1101 module as an ESPHome RF direct OOK remote receiver/transmitter. 3 | # Basics 4 | The included yaml files include configuration examples for ESP8266 and ESP32 micro-controllers. You should start by enabling dump_raw and making sure noise isn't being received when no transmissions are occurring. Adjusting bandwidth, data-rate, and AGC parameters can help with creating an optimal receive setup. The example includes the ability to expose these as controls in ESPHome or HomeAssistant. 5 | - More bandwidth will likely enable receiving more varying devices on the same frequency, but will increase noise and may decrease range. 6 | 7 | ## debugging signals 8 | The ESP32 example includes an example UDP dumper that can help with analyzing pulse data. 9 | - Use rtl_433 on a host with the socat tool to decode pulses streamed to udp broadcast: 10 | ```socat -u UDP4-RECV:5009 STDOUT | rtl_433 -r ook:-``` 11 | 12 | ## rtl_433 decoding with ESPHome directly 13 | See [esphome-rtl_433-decoder](https://github.com/juanboro/esphome-rtl_433-decoder) 14 | 15 | ## notes 16 | - Transmit/Receive was verified to work with esp8266 and ESP-32 board. 17 | - No longer an issue - Arduino platform now works great :-)... 18 | - ~~I cannot currently get transmit to reliably work with the Arduiono platform on esp32. Some have gotten this to work by setting remote_transmit/receive setup ordering and several other workarounds and these at one point worked for me - but with the latest ESPhome releases I don't see them working (the older remote transmit module appears to me to always drive zero and not an open-drain output) Current suggestions: If you need to have both transmit and receive on ESP-32 platforms, use the esp-idf platform, if you need only receive, then you can use either platform. If you must have transmit and the arduiono platform - more work will likely be required (see the Radiolib code - you can put the RX data on GDO2 and keep the RX and TX pins seperate)~~ 19 | 20 | # see also: 21 | - Direct cc1101 support in ESPHOME component (no radiolib dependency): https://github.com/esphome/esphome/pull/6300 22 | # based on: 23 | - https://github.com/dbuezas/esphome-cc1101 24 | - and https://github.com/NorthernMan54/rtl_433_ESP/blob/main/src/rtl_433_ESP.cpp 25 | - and https://github.com/smartoctopus/RadioLib-esphome/blob/master/examples/CC1101/CC1101_Settings/CC1101_Settings.ino 26 | - and https://github.com/LSatan/SmartRC-CC1101-Driver-Lib 27 | -------------------------------------------------------------------------------- /components/radiolib_cc1101/radiolib_cc1101.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esphome/core/component.h" 4 | #include "esphome/components/spi/spi.h" 5 | 6 | 7 | #define RADIOLIB_LOW_LEVEL 1 8 | #include "EHRLHal.h" 9 | 10 | namespace esphome { 11 | namespace radiolib_cc1101 { 12 | 13 | enum CC1101_state {CC1101_NOINIT,CC1101_STANDBY,CC1101_RECV,CC1101_XMIT}; 14 | enum CC1101Modulation {OOK_MODULATION=0, FSK_MODULATION}; 15 | 16 | class RadiolibCC1101Component : public Component, public EH_RL_SPI { 17 | public: 18 | void setup() override; 19 | void loop() override; 20 | void dump_config() override; 21 | int standby(); 22 | int xmit(); 23 | int recv(); 24 | void set_rx_pin(InternalGPIOPin *rx_pin) { _gd0_rx = rx_pin; } 25 | void set_tx_pin(InternalGPIOPin *tx_pin) { _gd0_tx = tx_pin; } 26 | void set_frequency(float freq) { _freq=freq/1e6; } 27 | void set_modulation(CC1101Modulation modulation) { _modulation=modulation; } 28 | void set_filter(float filter) { _bandwidth=filter/1e3; } 29 | void set_bitrate(float bitrate) { _bitrate=bitrate; } 30 | void set_reg_agcctrl0(uint8_t reg_agcctrl0) { _REG_AGCCTRL0 = reg_agcctrl0; } 31 | void set_reg_agcctrl1(uint8_t reg_agcctrl1) { _REG_AGCCTRL1 = reg_agcctrl1; } 32 | void set_reg_agcctrl2(uint8_t reg_agcctrl2) { _REG_AGCCTRL2 = reg_agcctrl2; } 33 | void set_registers(); 34 | void setup_direct_mode(); 35 | float getRSSI(); 36 | 37 | EH_RL_Hal* hal; 38 | CC1101 radio=NULL; 39 | int init_state=0; 40 | CC1101_state state=CC1101_NOINIT; 41 | float _freq=433.92; 42 | CC1101Modulation _modulation=OOK_MODULATION; 43 | float _bandwidth=464; 44 | 45 | // these are bandwidth specific 46 | u_int8_t _REG_FREND1=0xb6; 47 | u_int8_t _REG_TEST2=0x88; 48 | u_int8_t _REG_TEST1=0x31; 49 | u_int8_t _REG_FIFOTHR=0x07; 50 | 51 | // AGC settings from: LSatan/SmartRC-CC1101-Driver-Lib 52 | // They _generally_ seem to work well 53 | // AGCCTRL2[7:6] reduce maximum available DVGA gain: disable top three gain setting 54 | // AGCCTRL2[2:0] average amplitude target for filter: 42 dB 55 | // AGCCTRL1[6:6] LNA priority setting: LNA2 first 56 | u_int8_t _REG_AGCCTRL2=0xc7; 57 | u_int8_t _REG_AGCCTRL1=0x00; 58 | u_int8_t _REG_AGCCTRL0=0xb2; 59 | 60 | // datarate seems to be very crtitical to be around 5.0k sometimes, but 40k or 100k seems to make more sense 61 | // -- intertwined with AGC settings from smartRC below 62 | // see also DN022: https://www.ti.com/lit/an/swra215e/swra215e.pdf 63 | float _bitrate=5; 64 | 65 | InternalGPIOPin* _gd0_rx=nullptr; 66 | InternalGPIOPin* _gd0_tx=nullptr; 67 | 68 | // For RSSI rx average 69 | float last_rx_rssi=0; 70 | 71 | private: 72 | void adjustBW(float bandwidth); // rx filter bw snapper 73 | 74 | }; 75 | 76 | 77 | } // namespace empty_spi_component 78 | } // namespace esphome 79 | -------------------------------------------------------------------------------- /components/radiolib_cc1101/__init__.py: -------------------------------------------------------------------------------- 1 | import esphome.codegen as cg 2 | import esphome.config_validation as cv 3 | from esphome.components import spi 4 | from esphome import pins 5 | from esphome.const import * 6 | from esphome.cpp_helpers import gpio_pin_expression 7 | from esphome.core import CORE 8 | import os 9 | 10 | DEPENDENCIES = ["spi"] 11 | 12 | MULTI_CONF = True 13 | 14 | radiolib_cc1101_ns = cg.esphome_ns.namespace("radiolib_cc1101") 15 | RadiolibCC1101Component = radiolib_cc1101_ns.class_( 16 | "RadiolibCC1101Component", cg.Component, spi.SPIDevice 17 | ) 18 | 19 | CONF_MODULATION = "modulation" 20 | CC1101Modulation = radiolib_cc1101_ns.enum("CC1101Modulation") 21 | CC1101_MODULATIONS = { 22 | "OOK": CC1101Modulation.OOK_MODULATION, 23 | "FSK": CC1101Modulation.FSK_MODULATION, 24 | } 25 | 26 | CONFIG_SCHEMA = ( 27 | cv.Schema({ 28 | cv.GenerateID(): cv.declare_id(RadiolibCC1101Component), 29 | cv.Optional(CONF_RX_PIN): pins.internal_gpio_input_pin_schema, 30 | cv.Optional(CONF_FREQUENCY, default="433.92MHz"): cv.frequency, 31 | cv.Optional(CONF_MODULATION, default="ook"): cv.enum(CC1101_MODULATIONS, upper=True, space="_"), 32 | cv.Optional(CONF_FILTER, default="464kHz"): cv.frequency, 33 | cv.Optional('bitrate',default=5): cv.float_range(0.025,600), # 40k = 25us resolution, 5k=less noisy 34 | cv.Optional('reg_agcctrl0',default=0xb2): cv.hex_uint8_t, 35 | cv.Optional('reg_agcctrl1',default=0x00): cv.hex_uint8_t, 36 | cv.Optional('reg_agcctrl2',default=0xc7): cv.hex_uint8_t, 37 | }) 38 | .extend(cv.COMPONENT_SCHEMA) 39 | .extend(spi.spi_device_schema(cs_pin_required=True)) 40 | ) 41 | 42 | async def to_code(config): 43 | 44 | # When using Arduino, RadioLib includes SPI.h (even though we abstract out the SPI functions) 45 | # so we need RadioLib to be able to find it... 46 | if CORE.using_arduino: 47 | # This used to work ... but then deep+ got broken... https://github.com/esphome/esphome/issues/9672 48 | #cg.add_library("SPI",None) 49 | #cg.add_platformio_option("lib_ldf_mode", "deep+") 50 | 51 | # so now we do this... 52 | prescript=os.path.join(os.path.dirname(__file__), "hack_radiolib_buildopt.py") 53 | cg.add_platformio_option("extra_scripts", [f"pre:{prescript}"]) 54 | 55 | cg.add_library("RadioLib",None) 56 | 57 | var = cg.new_Pvariable(config[CONF_ID]) 58 | 59 | if CONF_RX_PIN in config: 60 | pin = await gpio_pin_expression(config[CONF_RX_PIN]) 61 | cg.add(var.set_rx_pin(pin)) 62 | 63 | cg.add(var.set_frequency(config[CONF_FREQUENCY])) 64 | cg.add(var.set_modulation(config[CONF_MODULATION])) 65 | cg.add(var.set_filter(config[CONF_FILTER])) 66 | cg.add(var.set_bitrate(config['bitrate'])) 67 | cg.add(var.set_reg_agcctrl0(config['reg_agcctrl0'])) 68 | cg.add(var.set_reg_agcctrl1(config['reg_agcctrl1'])) 69 | cg.add(var.set_reg_agcctrl2(config['reg_agcctrl2'])) 70 | 71 | await cg.register_component(var, config) 72 | await spi.register_spi_device(var, config) 73 | -------------------------------------------------------------------------------- /components/radiolib_cc1101/EHRLHal.h: -------------------------------------------------------------------------------- 1 | #ifndef EHRLHHAL_H 2 | #define EHRLHHAL_H 3 | 4 | #define RADIOLIB_LOW_LEVEL 1 5 | 6 | #include "esphome/components/spi/spi.h" 7 | 8 | #include 9 | 10 | // pretty much from EspHal.h / ArduinoHal.h 11 | // define Arduino-style macros 12 | #ifndef USE_ARDUINO 13 | #define LOW (0x0) 14 | #define HIGH (0x1) 15 | #define INPUT (0x01) 16 | #define OUTPUT (0x03) 17 | #define RISING (0x01) 18 | #define FALLING (0x02) 19 | #endif 20 | 21 | class EH_RL_SPI : public esphome::spi::SPIDevice {}; 23 | 24 | class EH_RL_Hal : public RadioLibHal { 25 | public: 26 | // default constructor - initializes the base HAL and any needed private members 27 | EH_RL_Hal(EH_RL_SPI* spi) 28 | : RadioLibHal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), spi(spi) {} 29 | 30 | void init() override { 31 | } 32 | 33 | void term() override { 34 | } 35 | 36 | void inline delay(RadioLibTime_t ms) override { 37 | esphome::delay(ms); 38 | } 39 | 40 | void inline delayMicroseconds(RadioLibTime_t us) override { 41 | esphome::delayMicroseconds(us); 42 | } 43 | 44 | unsigned long inline millis() override { 45 | return((unsigned long)esphome::millis()); 46 | } 47 | 48 | unsigned long inline micros() override { 49 | return((unsigned long)esphome::micros()); 50 | } 51 | 52 | void spiBegin() override { 53 | // ESPHome will do it with SPIDevice 54 | } 55 | void spiEnd() override { 56 | // ESPHome will do it with SPIDevice 57 | } 58 | void inline spiBeginTransaction() override { 59 | spi->enable(); 60 | } 61 | void inline spiEndTransaction() override { 62 | spi->disable(); 63 | } 64 | 65 | void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override { 66 | for(size_t i = 0; i < len; i++) { 67 | in[i] = spi->transfer_byte(out[i]); 68 | } 69 | } 70 | 71 | esphome::spi::SPIDevice* spi; 73 | 74 | void inline yield() override { 75 | ::esphome::yield(); 76 | } 77 | 78 | // this is *hopefully* temporary --- I should be able to provide this hal constructor a sparse pin mapping 79 | // to the esphome GPIOPin (assuming there is a way to get it via id()). Another slight challenge may 80 | // be with interrupts... we'll see. As it is --- for just using this with esphome remote_receiver and 81 | // remote_transmitter - only SPI stuff above is necessary - but there is alot more to radiolib that would 82 | // be nice to use with esphome and homeassistant :-) 83 | 84 | // GPIO-related methods (pinMode, digitalWrite etc.) should check 85 | // RADIOLIB_NC as an alias for non-connected pins 86 | void inline pinMode(uint32_t pin, uint32_t mode ) override { 87 | return; 88 | } 89 | 90 | void inline digitalWrite(uint32_t pin, uint32_t value) override { 91 | return; 92 | } 93 | 94 | uint32_t inline digitalRead(uint32_t pin) override { 95 | return 0; 96 | } 97 | 98 | void inline attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override { 99 | return; 100 | } 101 | 102 | void inline detachInterrupt(uint32_t interruptNum) override { 103 | return; 104 | } 105 | 106 | long inline pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout) override { 107 | return 0; 108 | } 109 | 110 | }; 111 | 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /components/radiolib_cc1101/radiolib_cc1101.cpp: -------------------------------------------------------------------------------- 1 | #include "esphome/core/log.h" 2 | #include "radiolib_cc1101.h" 3 | 4 | //based on: 5 | // https://github.com/dbuezas/esphome-cc1101 6 | // and https://github.com/NorthernMan54/rtl_433_ESP/blob/main/src/rtl_433_ESP.cpp 7 | // https://github.com/jgromes/RadioLib/blob/master/examples/CC1101/CC1101_Settings/CC1101_Settings.ino 8 | // https://github.com/mag1024/esphome-rtl433/ 9 | 10 | namespace esphome { 11 | namespace radiolib_cc1101 { 12 | 13 | static const char *TAG = "radiolib_cc1101.component"; 14 | 15 | void RadiolibCC1101Component::setup() { 16 | ESP_LOGI(TAG, "SPI Setup"); 17 | this->spi_setup(); 18 | 19 | // Use Radiolib CC1101 direct receive ASK-OOK 20 | hal = new EH_RL_Hal(this); 21 | radio = new Module(hal,RADIOLIB_NC, RADIOLIB_NC,RADIOLIB_NC); 22 | 23 | init_state = radio.begin(); 24 | ESP_LOGD(TAG, "CC1101 setup begin init_state =%d", state); 25 | 26 | // setup direct receive mode 27 | setup_direct_mode(); 28 | 29 | ESP_LOGD(TAG, "CC1101 setup end init_state =%d", state); 30 | 31 | } 32 | 33 | void RadiolibCC1101Component::loop() { 34 | if ((state==CC1101_RECV)&&(_gd0_rx!=nullptr)&&(_gd0_rx->digital_read())) last_rx_rssi=getRSSI(); 35 | } 36 | 37 | void RadiolibCC1101Component::dump_config(){ 38 | ESP_LOGCONFIG(TAG, "RadioLib-cc1101 component"); 39 | } 40 | 41 | void RadiolibCC1101Component::set_registers() { 42 | init_state|=radio.setFrequency(_freq); 43 | init_state|=radio.setBitRate(_bitrate); 44 | // set rx bw after datarate - and only specific ones make sense... 45 | adjustBW(_bandwidth); 46 | init_state|=radio.setRxBandwidth(_bandwidth); 47 | 48 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_FREND1,_REG_FREND1); 49 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_TEST2,_REG_TEST2); 50 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_TEST1,_REG_TEST1); 51 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_FIFOTHR, _REG_FIFOTHR); 52 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_AGCCTRL2,_REG_AGCCTRL2); 53 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_AGCCTRL1,_REG_AGCCTRL1); 54 | init_state|= radio.SPIsetRegValue(RADIOLIB_CC1101_REG_AGCCTRL0,_REG_AGCCTRL0); 55 | 56 | ESP_LOGD(TAG, "CC1101 set_registers() complete - freq, bitrate, bandwidth, registers set"); 57 | } 58 | 59 | void RadiolibCC1101Component::setup_direct_mode() { 60 | init_state|=standby(); 61 | 62 | // per DN022 adjust LNA as needed 63 | _REG_FREND1=(_bandwidth>101) ? 0xb6 : 0x56; 64 | // also per DN022 65 | _REG_TEST2= (_bandwidth>325) ? 0x88 : 0x81; 66 | _REG_TEST1= (_bandwidth>325) ? 0x31 : 0x35; 67 | _REG_FIFOTHR= (_bandwidth>325) ? 0x07 : 0x47; 68 | 69 | set_registers(); 70 | 71 | init_state|=radio.setOOK(_modulation==OOK_MODULATION); 72 | 73 | // start receiving onto GDO 74 | init_state|= recv(); 75 | 76 | } 77 | 78 | int RadiolibCC1101Component::standby() { 79 | // standby state: radio in standby 80 | init_state|=radio.standby(); 81 | state=init_state==0 ? CC1101_STANDBY : CC1101_NOINIT; 82 | return init_state; 83 | } 84 | 85 | int RadiolibCC1101Component::recv() { 86 | // receive state: radio doing receiveDirectAsync 87 | if (state==CC1101_XMIT) standby(); 88 | 89 | init_state|=radio.receiveDirectAsync(); 90 | state=init_state==0 ? CC1101_RECV : CC1101_NOINIT; 91 | return init_state; 92 | } 93 | 94 | int RadiolibCC1101Component::xmit() { 95 | // xmit state: gd0 is output 96 | standby(); 97 | 98 | init_state|=radio.transmitDirectAsync(); 99 | state=init_state==0 ? CC1101_XMIT : CC1101_NOINIT; 100 | 101 | return init_state; 102 | } 103 | 104 | void RadiolibCC1101Component::adjustBW(float bandwidth) { 105 | // set to a valid value 106 | float possibles[16] = {58, 68, 81, 102, 116, 135, 162, 203, 232, 270, 325, 406, 464, 541, 650, 812}; 107 | for(int i=0;i<15;i++) { 108 | if ((bandwidth>=possibles[i])&&(bandwidth<=possibles[i+1])) { 109 | _bandwidth=bandwidth-possibles[i]' 63 | Priority: 2 64 | - Regex: '^<.*\.h>' 65 | Priority: 1 66 | - Regex: '^<.*' 67 | Priority: 2 68 | - Regex: '.*' 69 | Priority: 3 70 | IncludeIsMainRegex: '([-_](test|unittest))?$' 71 | IndentCaseLabels: true 72 | IndentPPDirectives: None 73 | IndentWidth: 2 74 | IndentWrappedFunctionNames: false 75 | KeepEmptyLinesAtTheStartOfBlocks: false 76 | MacroBlockBegin: '' 77 | MacroBlockEnd: '' 78 | MaxEmptyLinesToKeep: 1 79 | NamespaceIndentation: None 80 | PenaltyBreakAssignment: 2 81 | PenaltyBreakBeforeFirstCallParameter: 1 82 | PenaltyBreakComment: 300 83 | PenaltyBreakFirstLessLess: 120 84 | PenaltyBreakString: 1000 85 | PenaltyBreakTemplateDeclaration: 10 86 | PenaltyExcessCharacter: 1000000 87 | PenaltyReturnTypeOnItsOwnLine: 2000 88 | PointerAlignment: Right 89 | RawStringFormats: 90 | - Language: Cpp 91 | Delimiters: 92 | - cc 93 | - CC 94 | - cpp 95 | - Cpp 96 | - CPP 97 | - 'c++' 98 | - 'C++' 99 | CanonicalDelimiter: '' 100 | BasedOnStyle: google 101 | - Language: TextProto 102 | Delimiters: 103 | - pb 104 | - PB 105 | - proto 106 | - PROTO 107 | EnclosingFunctions: 108 | - EqualsProto 109 | - EquivToProto 110 | - PARSE_PARTIAL_TEXT_PROTO 111 | - PARSE_TEST_PROTO 112 | - PARSE_TEXT_PROTO 113 | - ParseTextOrDie 114 | - ParseTextProtoOrDie 115 | CanonicalDelimiter: '' 116 | BasedOnStyle: google 117 | ReflowComments: true 118 | SortIncludes: false 119 | SortUsingDeclarations: false 120 | SpaceAfterCStyleCast: true 121 | SpaceAfterTemplateKeyword: false 122 | SpaceBeforeAssignmentOperators: true 123 | SpaceBeforeCpp11BracedList: false 124 | SpaceBeforeCtorInitializerColon: true 125 | SpaceBeforeInheritanceColon: true 126 | SpaceBeforeParens: ControlStatements 127 | SpaceBeforeRangeBasedForLoopColon: true 128 | SpaceInEmptyParentheses: false 129 | SpacesBeforeTrailingComments: 2 130 | SpacesInAngles: false 131 | SpacesInContainerLiterals: false 132 | SpacesInCStyleCastParentheses: false 133 | SpacesInParentheses: false 134 | SpacesInSquareBrackets: false 135 | Standard: Auto 136 | TabWidth: 2 137 | UseTab: Never 138 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: >- 3 | *, 4 | -abseil-*, 5 | -altera-*, 6 | -android-*, 7 | -boost-*, 8 | -bugprone-easily-swappable-parameters, 9 | -bugprone-implicit-widening-of-multiplication-result, 10 | -bugprone-narrowing-conversions, 11 | -bugprone-signed-char-misuse, 12 | -cert-dcl50-cpp, 13 | -cert-err33-c, 14 | -cert-err58-cpp, 15 | -cert-oop57-cpp, 16 | -cert-str34-c, 17 | -clang-analyzer-optin.cplusplus.UninitializedObject, 18 | -clang-analyzer-osx.*, 19 | -clang-diagnostic-delete-abstract-non-virtual-dtor, 20 | -clang-diagnostic-delete-non-abstract-non-virtual-dtor, 21 | -clang-diagnostic-ignored-optimization-argument, 22 | -clang-diagnostic-shadow-field, 23 | -clang-diagnostic-unused-const-variable, 24 | -clang-diagnostic-unused-parameter, 25 | -concurrency-*, 26 | -cppcoreguidelines-avoid-c-arrays, 27 | -cppcoreguidelines-avoid-magic-numbers, 28 | -cppcoreguidelines-init-variables, 29 | -cppcoreguidelines-macro-usage, 30 | -cppcoreguidelines-narrowing-conversions, 31 | -cppcoreguidelines-non-private-member-variables-in-classes, 32 | -cppcoreguidelines-prefer-member-initializer, 33 | -cppcoreguidelines-pro-bounds-array-to-pointer-decay, 34 | -cppcoreguidelines-pro-bounds-constant-array-index, 35 | -cppcoreguidelines-pro-bounds-pointer-arithmetic, 36 | -cppcoreguidelines-pro-type-const-cast, 37 | -cppcoreguidelines-pro-type-cstyle-cast, 38 | -cppcoreguidelines-pro-type-member-init, 39 | -cppcoreguidelines-pro-type-reinterpret-cast, 40 | -cppcoreguidelines-pro-type-static-cast-downcast, 41 | -cppcoreguidelines-pro-type-union-access, 42 | -cppcoreguidelines-pro-type-vararg, 43 | -cppcoreguidelines-special-member-functions, 44 | -cppcoreguidelines-virtual-class-destructor, 45 | -fuchsia-multiple-inheritance, 46 | -fuchsia-overloaded-operator, 47 | -fuchsia-statically-constructed-objects, 48 | -fuchsia-default-arguments-declarations, 49 | -fuchsia-default-arguments-calls, 50 | -google-build-using-namespace, 51 | -google-explicit-constructor, 52 | -google-readability-braces-around-statements, 53 | -google-readability-casting, 54 | -google-readability-namespace-comments, 55 | -google-readability-todo, 56 | -google-runtime-references, 57 | -hicpp-*, 58 | -llvm-else-after-return, 59 | -llvm-header-guard, 60 | -llvm-include-order, 61 | -llvm-qualified-auto, 62 | -llvmlibc-*, 63 | -misc-non-private-member-variables-in-classes, 64 | -misc-no-recursion, 65 | -misc-unused-parameters, 66 | -modernize-avoid-c-arrays, 67 | -modernize-avoid-bind, 68 | -modernize-concat-nested-namespaces, 69 | -modernize-return-braced-init-list, 70 | -modernize-use-auto, 71 | -modernize-use-default-member-init, 72 | -modernize-use-equals-default, 73 | -modernize-use-trailing-return-type, 74 | -modernize-use-nodiscard, 75 | -mpi-*, 76 | -objc-*, 77 | -readability-container-data-pointer, 78 | -readability-convert-member-functions-to-static, 79 | -readability-else-after-return, 80 | -readability-function-cognitive-complexity, 81 | -readability-implicit-bool-conversion, 82 | -readability-isolate-declaration, 83 | -readability-magic-numbers, 84 | -readability-make-member-function-const, 85 | -readability-redundant-string-init, 86 | -readability-uppercase-literal-suffix, 87 | -readability-use-anyofallof, 88 | WarningsAsErrors: '*' 89 | AnalyzeTemporaryDtors: false 90 | FormatStyle: google 91 | CheckOptions: 92 | - key: google-readability-function-size.StatementThreshold 93 | value: '800' 94 | - key: google-runtime-int.TypeSuffix 95 | value: '_t' 96 | - key: llvm-namespace-comment.ShortNamespaceLines 97 | value: '10' 98 | - key: llvm-namespace-comment.SpacesBeforeComments 99 | value: '2' 100 | - key: modernize-loop-convert.MaxCopySize 101 | value: '16' 102 | - key: modernize-loop-convert.MinConfidence 103 | value: reasonable 104 | - key: modernize-loop-convert.NamingStyle 105 | value: CamelCase 106 | - key: modernize-pass-by-value.IncludeStyle 107 | value: llvm 108 | - key: modernize-replace-auto-ptr.IncludeStyle 109 | value: llvm 110 | - key: modernize-use-nullptr.NullMacros 111 | value: 'NULL' 112 | - key: modernize-make-unique.MakeSmartPtrFunction 113 | value: 'make_unique' 114 | - key: modernize-make-unique.MakeSmartPtrFunctionHeader 115 | value: 'esphome/core/helpers.h' 116 | - key: readability-braces-around-statements.ShortStatementLines 117 | value: 2 118 | - key: readability-identifier-naming.LocalVariableCase 119 | value: 'lower_case' 120 | - key: readability-identifier-naming.ClassCase 121 | value: 'CamelCase' 122 | - key: readability-identifier-naming.StructCase 123 | value: 'CamelCase' 124 | - key: readability-identifier-naming.EnumCase 125 | value: 'CamelCase' 126 | - key: readability-identifier-naming.EnumConstantCase 127 | value: 'UPPER_CASE' 128 | - key: readability-identifier-naming.StaticConstantCase 129 | value: 'UPPER_CASE' 130 | - key: readability-identifier-naming.StaticVariableCase 131 | value: 'lower_case' 132 | - key: readability-identifier-naming.GlobalConstantCase 133 | value: 'UPPER_CASE' 134 | - key: readability-identifier-naming.ParameterCase 135 | value: 'lower_case' 136 | - key: readability-identifier-naming.PrivateMemberCase 137 | value: 'lower_case' 138 | - key: readability-identifier-naming.PrivateMemberSuffix 139 | value: '_' 140 | - key: readability-identifier-naming.PrivateMethodCase 141 | value: 'lower_case' 142 | - key: readability-identifier-naming.PrivateMethodSuffix 143 | value: '_' 144 | - key: readability-identifier-naming.ClassMemberCase 145 | value: 'lower_case' 146 | - key: readability-identifier-naming.ClassMemberCase 147 | value: 'lower_case' 148 | - key: readability-identifier-naming.ProtectedMemberCase 149 | value: 'lower_case' 150 | - key: readability-identifier-naming.ProtectedMemberSuffix 151 | value: '_' 152 | - key: readability-identifier-naming.FunctionCase 153 | value: 'lower_case' 154 | - key: readability-identifier-naming.ClassMethodCase 155 | value: 'lower_case' 156 | - key: readability-identifier-naming.ProtectedMethodCase 157 | value: 'lower_case' 158 | - key: readability-identifier-naming.ProtectedMethodSuffix 159 | value: '_' 160 | - key: readability-identifier-naming.VirtualMethodCase 161 | value: 'lower_case' 162 | - key: readability-identifier-naming.VirtualMethodSuffix 163 | value: '' 164 | - key: readability-qualified-auto.AddConstToQualified 165 | value: 0 166 | - key: readability-identifier-length.MinimumVariableNameLength 167 | value: 0 168 | - key: readability-identifier-length.MinimumParameterNameLength 169 | value: 0 170 | - key: readability-identifier-length.MinimumLoopCounterNameLength 171 | value: 0 172 | -------------------------------------------------------------------------------- /esp32-cc1101-tcp-example.yaml: -------------------------------------------------------------------------------- 1 | # Alternative example to udp, when tcp works and udp doesn't (i.e: WSL) 2 | # socat -T600 - TCP:esp32-cc1101-tcp.local:9000,fork,reuseaddr,max-children=1 | rtl_433 -r ook:- 3 | 4 | # or keep a log for later replay and analysis... 5 | # socat -T600 - TCP:esp32-dev1.local:9000,fork,reuseaddr,max-children=1 | tee -a esp32-cc1101-log.ook | rtl_433 -r ook:- 6 | 7 | esphome: 8 | name: esp32-cc1101-tcp 9 | friendly_name: ESP32 cc1101 tcp dump example 10 | 11 | packages: 12 | esp32-cc1101: !include esp32-cc1101.yaml 13 | 14 | external_components: 15 | - source: github://juanboro/esphome 16 | components: [ tcp_server ] 17 | 18 | wifi: 19 | ssid: !secret wifi_name 20 | password: !secret wifi_pass 21 | fast_connect: true 22 | 23 | esp32: 24 | board: esp32dev 25 | framework: 26 | # change as necessary - see the notes it esp32-cc1101.yaml about arduino if you must use that platform. 27 | type: esp-idf 28 | #type: arduino 29 | 30 | logger: 31 | # level: VERBOSE 32 | level: INFO 33 | 34 | captive_portal: 35 | 36 | api: 37 | 38 | time: 39 | # see esphome docs for more places to get time from... 40 | - platform: homeassistant 41 | id: timesrc 42 | 43 | web_server: 44 | port: 80 45 | 46 | tcp_server: 47 | port: 9000 48 | id: tcp 49 | 50 | remote_receiver: 51 | - id: !extend rf_receiver 52 | # TCP broadcast ook pulse data that rtl_433 can decode as input for debugging 53 | # 54 | # on the receive side: 55 | # socat -T10 - TCP:esp32-cc1101-tcp.local:9000,fork,reuseaddr,max-children=1 | rtl_433 -r ook:- 56 | on_raw: 57 | then: 58 | - lambda: |- 59 | int rawcount=x.size(); 60 | if (rawcount<10) return; // ignore noise 61 | 62 | char buffer[512]; 63 | size_t bwritten=0; 64 | 65 | bwritten+=snprintf(buffer,sizeof(buffer) - bwritten,";pulse data\n;version 1\n;timescale 1us\n;centerfreq %d Hz\n;rssi %0.1f dB\n",(uint32_t) (id(mycc1101)._freq*1e6),id(mycc1101).last_rx_rssi); 66 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,";received "); 67 | bwritten+=id(timesrc).now().strftime(buffer+bwritten,sizeof(buffer) - bwritten, "%Y-%m-%d %H:%M:%S"); 68 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,"\n"); 69 | 70 | int j=0; 71 | while (j0) { 73 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,"%d %d\n",x[j],(j490) { 79 | id(tcp).write(buffer,bwritten); 80 | bwritten=0; 81 | } 82 | } 83 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,";end\n"); 84 | id(tcp).write(buffer,bwritten); 85 | 86 | # ESP IDF new remote SPECIFIC (comment out out Arduino platform) 87 | # https://docs.espressif.com/projects/esp-idf/en/v5.4/esp32/api-reference/peripherals/rmt.html#rmt-resource-allocation 88 | # https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf#rmt 89 | # https://esphome.io/components/remote_receiver#esp32-idf-configuration-variables 90 | # the original esp-32 has 2k of symbol memory (512 symbols) 91 | # rmt_symbols sets mem_block_symbols in esp channel config - the esphome default will be 192 symbols/channel 92 | # In this example - we max things out at 448 symbols for the receive (the transmit can recycle symbol memory - so a smaller symbol size of the default 64 is ok) 93 | # note that if additional remotes are added (up to 8) - then the memory will need apportioned as necessary. Even 448 symbols (<1000 pulses) isn't real great 94 | # for some of what we'd like to receive on the cc1101. 95 | rmt_symbols: 448 96 | # generally - receive_symbols only makes sense to be bigger than rmt_symbols on systems w/ dma support (not the original esp32) 97 | # but should always be set to at least rmt_symbols... 98 | receive_symbols: 448 99 | 100 | # Alternativly with this pr: (or my branch: https://github.com/juanboro/esphome) -- use the software-interupt remote driver: 101 | #use_esp32_rmt: false 102 | 103 | 104 | button: 105 | - platform: template 106 | name: "Govee Leak Detector Test Button Press" 107 | on_press: 108 | - logger.log: 109 | format: "Press govee" 110 | level: INFO 111 | - remote_transmitter.transmit_raw: 112 | transmitter_id: rf_transmitter 113 | # prettier-ignore 114 | code: [1385,-820,805,-2849,290,-8618,283,-817,324,-799,305,-800,857,-276,270,-828,288,-834,842,-272,299,-827,838,-268,304,-824,287,-828,833,-273,293,-818,843,-282,822,-291,847,-252,293,-843,273,-823,839,-292,846,-279,268,-844,270,-821,293,-843,274,-818,293,-845,824,-281,291,-845,827,-262,294,-844,829,-270,284,-823,299,-809,299,-851,268,-824,269,-857,841,-269,842,-275,293,-818,864,-267,286,-801,860,-291,265,-823,296,-834,835,-272,289,-816,297,-840,825,-297,267,-1940,293,-8616,330,-799,291,-813,293,-831,842,-270,296,-816,291,-822,855,-284,274,-810,866,-265,276,-829,292,-825,842,-270,294,-820,843,-283,861,-248,844,-290,279,-818,285,-822,856,-268,853,-268,302,-805,309,-801,301,-832,289,-832,288,-812,842,-290,287,-811,838,-290,287,-811,840,-291,288,-812,290,-858,268,-814,290,-833,301,-818,828,-294,835,-264,286,-854,813,-290,262,-854,839,-262,284,-838,292,-823,862,-261,295,-818,268,-850,826,-274,291,-1949,281,-8611,355,-796,264,-824,318,-820,818,-285,312,-816,281,-848,825,-265,274,-851,847,-241,308,-824,290,-815,842,-296,291,-809,844,-293,844,-243,863,-266,275,-831,293,-824,839,-275,866,-263,276,-842,272,-849,264,-840,268,-851,270,-836,842,-291,273,-814,870,-265,274,-830,867,-265,261,-829,289,-835,291,-815,290,-836,294,-813,858,-269,834,-267,311,-809,841,-266,309,-810,842,-268,307,-814,293,-822,841,-274,293,-848,267,-839,836,-271,303,-4056,293,-8608,325,-805,287,-836,268,-846,846,-261,293,-821,299,-815,858,-244,308,-824,845,-270,293,-826,282,-824,839,-291,273,-840,817,-294,843,-273,842,-293,270,-815,290,-848,840,-251,845,-288,272,-839,268,-846,292,-820,298,-815,293,-821,866,-264,276,-811,866,-267,274,-831,866,-267,277,-827,290,-825,290,-813,291,-833,293,-819,869,-252,834,-284,268,-844,850,-262,319,-795,851,-261,309,-814,283,-823,851,-275,288,-812,317,-799,838,-293,280,-1971,266,-8637,293,-802,288,-848,290,-807,866,-267,281,-815,279,-858,817,-273,292,-846,821,-283,268,-845,272,-823,866,-254,312,-796,866,-281,835,-262,855,-266,311,-790,291,-847,831,-264,856,-268,304,-802,297,-832,293,-827,294,-832,271,-821,866,-252,293,-820,842,-286,292,-820,851,-262,291,-846,278,-829,289,-818,301,-820,269,-843,846,-265,856,-270,274,-822,874,-248,291,-833,860,-250,295,-820,265,-846,832,-291,273,-837,294,-821,866,-262,266,-1949,291,-8631,299,-797,320,-805,299,-806,864,-266,293,-822,287,-828,834,-291,273,-844,837,-269,295,-815,287,-834,843,-280,292,-819,851,-262,861,-247,845,-292,265,-848,278,-823,849,-269,842,-290,265,-848,278,-825,297,-813,299,-823,268,-848,850,-254,293,-849,826,-261,291,-823,854,-264,292,-822,300,-827,289,-821,296,-798,319,-819,825,-283,858,-247,295,-825,857,-269,274,-823,857,-272,299,-850,266,-813,842,-294,271,-830,290,-825,841,-274,293,-1947,293,-8607,290,-847,275,-822,266,-868,813,-290,274,-838,291,-820,865,-260,292,-798,864,-294,265,-818,273,-846,832,-275,317,-823,828,-272,850,-264,851,-243,331,-816,267,-841,842,-292,819,-295,293,-793,292,-840,288,-818,284,-851,265,-831,841,-293,271,-827,840,-293,271,-830,863,-268,274,-827,288,-826,292,-811,292,-849,268,-842,840,-295,818,-270,269,-844,843,-255,293,-844,832,-277,292,-844,277,-823,838,-275,291,-811,290,-847,831,-264,315,-1916,316,-8617,297,-808,277,-841,293,-821,835,-297,292,-792,293,-838,833,-267,306,-828,834,-273,294,-843,271,-819,868,-264,275,-817,869,-268,844,-272,839,-292,271,-812,291,-851,816,-275,867,-264,274,-813,292,-847,293,-818,290,-836,269,-822,867,-262,276,-838,850,-255,288,-838,838,-275,293,-808,312,-810,291,-833,288,-840,265,-831,845,-291,831,-271,306,-801,845,-290,292,-823,811,-300,286,-815,284,-845,825,-270,302,-824,291,-834,846,-271,270,-1981,276,-8618,325,-779,335,-814,288,-801,851,-290,293,-795,315,-817,842,-268,297,-812,842,-268,301,-833,289,-845,823,-265,293,-848,814,-285,841,-274,844,-260,292,-845,277,-823,864,-247,848,-287,265,-848,279,-824,293,-819,300,-821,269,-843,848,-262,291,-845,832,-259,291,-847,829,-264,291,-852,274,-821,267,-844,296,-822,293,-822,822,-285,856,-269,276,-827,863,-269,297,-815,837,-287,293,-791,317,-832,811,-294,293,-814,292,-845,834,-263,276,-1967,267,-8638,300,-825,292,-817,298,-830,813,-275,294,-843,270,-821,867,-264,274,-816,867,-295,245,-831,293,-855,809,-274,293,-844,819,-283,860,-254,839,-288,280,-820,285,-824,858,-268,859,-260,279,-845,261,-822,307,-821,282,-848,274,-844,815,-318,267,-825,845,-289,272,-823,841,-290,263,-833,287,-834,291,-815,290,-833,273,-839,863,-248,843,-268,288,-846,831,-264,292,-847,833,-260,290,-845,280,-822,838,-274,291,-825,289,-821,856,-259,292,-1947,301,-8595,324,-818,261,-833,317,-818,840,-277,286,-817,281,-819,839,-285,293,-793,868,-264,292,-822,846,-292,278,-812,307,-823,265,-830,317,-818,266,-840,844,-265,847,-271,318,-815,821,-308,265,-825,846,-289,278,-812,284,-849,824,-268,304,-823,289,-814,844,-293,272,-1955,291,-8605,325,-801,264,-857,294,-793,866,-283,293,-796,291,-847,824,-284,259,-863,838,-255,283,-845,293,-798,869,-291,255,-834,857,-268,824,-269,877,-269,273,-824,313,-816,838,-250,864,-264,293,-833,289,-812,293,-847,267,-839,270,-847,840,-253,294,-843,823,-284,292,-821,850,-263,292,-820,301,-810,275,-843,319,-794,289,-837,841,-267,872,-252,295,-819,866,-262,268,-819,867,-265,292,-822,269,-848,830,-264,296,-849,278,-813,861,-268,278,-1967,265,-8616,317,-829,292,-810,293,-848,839,-250,294,-843,269,-820,840,-292,296,-820,843,-262,289,-821,294,-846,819,-285,293,-818,848,-262,858,-268,826,-293,291,-824,282,-834,852,-271,833,-269,278,-841,291,-825,270,-851,291,-810,291,-837,839,-264,297,-822,847,-268,298,-811,842,-266,309,-812,290,-809,312,-838,261,-863,287,-808,837,-295,840,-263,275,-838,837,-263,286,-847,830,-274,291,-835,297,-821,840,-294,274,-820,289,-824,844,-268,286] 115 | -------------------------------------------------------------------------------- /esp32-cc1101-udp-example.yaml: -------------------------------------------------------------------------------- 1 | # on the receive side: 2 | # socat -u UDP4-RECV:5009 STDOUT | rtl_433 -r ook:- 3 | # or keep a log for later replay and analysis... 4 | # socat -u UDP4-RECV:5009 STDOUT | tee -a esp32-cc1101-log.ook | rtl_433 -r ook:- 5 | 6 | esphome: 7 | name: esp32-cc1101-udp 8 | friendly_name: ESP32 cc1101 udp dump example 9 | 10 | packages: 11 | esp32-cc1101: !include esp32-cc1101.yaml 12 | 13 | external_components: 14 | - source: github://juanboro/esphome 15 | components: [ udp_broadcast ] 16 | 17 | wifi: 18 | ssid: !secret wifi_name 19 | password: !secret wifi_pass 20 | fast_connect: true 21 | 22 | esp32: 23 | board: esp32dev 24 | framework: 25 | # change ONLY if necessary - see the notes it esp32-cc1101.yaml about arduino if you must use that platform. 26 | type: esp-idf 27 | # type: arduino 28 | 29 | logger: 30 | # level: VERBOSE 31 | level: INFO 32 | 33 | captive_portal: 34 | 35 | api: 36 | 37 | time: 38 | # see esphome docs for more places to get time from... 39 | - platform: homeassistant 40 | id: timesrc 41 | 42 | web_server: 43 | port: 80 44 | 45 | udp_broadcast: 46 | port: 5009 47 | id: udpbc 48 | 49 | remote_receiver: 50 | - id: !extend rf_receiver 51 | # UDP broadcast ook pulse data that rtl_433 can decode as input for debugging 52 | # 53 | 54 | on_raw: 55 | then: 56 | - lambda: |- 57 | int rawcount=x.size(); 58 | if (rawcount<10) return; // ignore noise 59 | 60 | char buffer[512]; 61 | size_t bwritten=0; 62 | 63 | bwritten+=snprintf(buffer,sizeof(buffer) - bwritten,";pulse data\n;version 1\n;timescale 1us\n;centerfreq %d Hz\n;rssi %0.1f dB\n",(uint32_t) (id(mycc1101)._freq*1e6),id(mycc1101).last_rx_rssi); 64 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,";received "); 65 | bwritten+=id(timesrc).now().strftime(buffer+bwritten,sizeof(buffer) - bwritten, "%Y-%m-%d %H:%M:%S"); 66 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,"\n"); 67 | 68 | int j=0; 69 | while (j0) { 71 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,"%d %d\n",x[j],(j490) { 77 | id(udpbc).send_data(buffer,bwritten); 78 | bwritten=0; 79 | } 80 | } 81 | bwritten+=snprintf(buffer+bwritten,sizeof(buffer) - bwritten,";end\n"); 82 | id(udpbc).send_data(buffer,bwritten); 83 | 84 | # ESP-32 Remote Handling Notes 85 | # Note: These notes are specific the platform: esp-idf --- similar but different settings exist for the arudiono platform as well. 86 | # You REALLY probably want to use the esp-idf platform (unless you can't) 87 | # https://docs.espressif.com/projects/esp-idf/en/v5.4/esp32/api-reference/peripherals/rmt.html#rmt-resource-allocation 88 | # https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf#rmt 89 | # https://esphome.io/components/remote_receiver#esp32-idf-configuration-variables 90 | # the original esp-32 has 2k of symbol memory (512 symbols) 91 | # rmt_symbols sets mem_block_symbols in esp channel config - the esphome default will be 192 symbols/channel 92 | # In this example - we max things out at 448 symbols for the receive (the transmit can recycle symbol memory - so a smaller symbol size of the default 64 is ok) 93 | # note that if additional remotes are added (up to 8) - then the memory will need apportioned as necessary. Even 448 symbols (<1000 pulses) isn't real great 94 | # for some of what we'd like to receive on the cc1101. 95 | rmt_symbols: 448 96 | # generally - receive_symbols only makes sense to be bigger than rmt_symbols on systems w/ dma support (not the original esp32) 97 | # but should always be set to at least rmt_symbols... 98 | # IF you have a newer/better ESP-32 device - you can make receive_symbols as large as the buffer you need, and rmt_symbols can be smaller. 99 | receive_symbols: 448 100 | 101 | # Alternativly with this pr: (or my branch: https://github.com/juanboro/esphome) -- use the software-interupt remote driver and tell it to allow rmt tx to manage the pin 102 | #use_esp32_rmt: false 103 | #esp32_share_rmt_tx: true 104 | 105 | button: 106 | - platform: template 107 | name: "Govee Leak Detector Test Button Press" 108 | on_press: 109 | - logger.log: 110 | format: "Press govee" 111 | level: INFO 112 | - remote_transmitter.transmit_raw: 113 | transmitter_id: rf_transmitter 114 | # prettier-ignore 115 | code: [1385,-820,805,-2849,290,-8618,283,-817,324,-799,305,-800,857,-276,270,-828,288,-834,842,-272,299,-827,838,-268,304,-824,287,-828,833,-273,293,-818,843,-282,822,-291,847,-252,293,-843,273,-823,839,-292,846,-279,268,-844,270,-821,293,-843,274,-818,293,-845,824,-281,291,-845,827,-262,294,-844,829,-270,284,-823,299,-809,299,-851,268,-824,269,-857,841,-269,842,-275,293,-818,864,-267,286,-801,860,-291,265,-823,296,-834,835,-272,289,-816,297,-840,825,-297,267,-1940,293,-8616,330,-799,291,-813,293,-831,842,-270,296,-816,291,-822,855,-284,274,-810,866,-265,276,-829,292,-825,842,-270,294,-820,843,-283,861,-248,844,-290,279,-818,285,-822,856,-268,853,-268,302,-805,309,-801,301,-832,289,-832,288,-812,842,-290,287,-811,838,-290,287,-811,840,-291,288,-812,290,-858,268,-814,290,-833,301,-818,828,-294,835,-264,286,-854,813,-290,262,-854,839,-262,284,-838,292,-823,862,-261,295,-818,268,-850,826,-274,291,-1949,281,-8611,355,-796,264,-824,318,-820,818,-285,312,-816,281,-848,825,-265,274,-851,847,-241,308,-824,290,-815,842,-296,291,-809,844,-293,844,-243,863,-266,275,-831,293,-824,839,-275,866,-263,276,-842,272,-849,264,-840,268,-851,270,-836,842,-291,273,-814,870,-265,274,-830,867,-265,261,-829,289,-835,291,-815,290,-836,294,-813,858,-269,834,-267,311,-809,841,-266,309,-810,842,-268,307,-814,293,-822,841,-274,293,-848,267,-839,836,-271,303,-4056,293,-8608,325,-805,287,-836,268,-846,846,-261,293,-821,299,-815,858,-244,308,-824,845,-270,293,-826,282,-824,839,-291,273,-840,817,-294,843,-273,842,-293,270,-815,290,-848,840,-251,845,-288,272,-839,268,-846,292,-820,298,-815,293,-821,866,-264,276,-811,866,-267,274,-831,866,-267,277,-827,290,-825,290,-813,291,-833,293,-819,869,-252,834,-284,268,-844,850,-262,319,-795,851,-261,309,-814,283,-823,851,-275,288,-812,317,-799,838,-293,280,-1971,266,-8637,293,-802,288,-848,290,-807,866,-267,281,-815,279,-858,817,-273,292,-846,821,-283,268,-845,272,-823,866,-254,312,-796,866,-281,835,-262,855,-266,311,-790,291,-847,831,-264,856,-268,304,-802,297,-832,293,-827,294,-832,271,-821,866,-252,293,-820,842,-286,292,-820,851,-262,291,-846,278,-829,289,-818,301,-820,269,-843,846,-265,856,-270,274,-822,874,-248,291,-833,860,-250,295,-820,265,-846,832,-291,273,-837,294,-821,866,-262,266,-1949,291,-8631,299,-797,320,-805,299,-806,864,-266,293,-822,287,-828,834,-291,273,-844,837,-269,295,-815,287,-834,843,-280,292,-819,851,-262,861,-247,845,-292,265,-848,278,-823,849,-269,842,-290,265,-848,278,-825,297,-813,299,-823,268,-848,850,-254,293,-849,826,-261,291,-823,854,-264,292,-822,300,-827,289,-821,296,-798,319,-819,825,-283,858,-247,295,-825,857,-269,274,-823,857,-272,299,-850,266,-813,842,-294,271,-830,290,-825,841,-274,293,-1947,293,-8607,290,-847,275,-822,266,-868,813,-290,274,-838,291,-820,865,-260,292,-798,864,-294,265,-818,273,-846,832,-275,317,-823,828,-272,850,-264,851,-243,331,-816,267,-841,842,-292,819,-295,293,-793,292,-840,288,-818,284,-851,265,-831,841,-293,271,-827,840,-293,271,-830,863,-268,274,-827,288,-826,292,-811,292,-849,268,-842,840,-295,818,-270,269,-844,843,-255,293,-844,832,-277,292,-844,277,-823,838,-275,291,-811,290,-847,831,-264,315,-1916,316,-8617,297,-808,277,-841,293,-821,835,-297,292,-792,293,-838,833,-267,306,-828,834,-273,294,-843,271,-819,868,-264,275,-817,869,-268,844,-272,839,-292,271,-812,291,-851,816,-275,867,-264,274,-813,292,-847,293,-818,290,-836,269,-822,867,-262,276,-838,850,-255,288,-838,838,-275,293,-808,312,-810,291,-833,288,-840,265,-831,845,-291,831,-271,306,-801,845,-290,292,-823,811,-300,286,-815,284,-845,825,-270,302,-824,291,-834,846,-271,270,-1981,276,-8618,325,-779,335,-814,288,-801,851,-290,293,-795,315,-817,842,-268,297,-812,842,-268,301,-833,289,-845,823,-265,293,-848,814,-285,841,-274,844,-260,292,-845,277,-823,864,-247,848,-287,265,-848,279,-824,293,-819,300,-821,269,-843,848,-262,291,-845,832,-259,291,-847,829,-264,291,-852,274,-821,267,-844,296,-822,293,-822,822,-285,856,-269,276,-827,863,-269,297,-815,837,-287,293,-791,317,-832,811,-294,293,-814,292,-845,834,-263,276,-1967,267,-8638,300,-825,292,-817,298,-830,813,-275,294,-843,270,-821,867,-264,274,-816,867,-295,245,-831,293,-855,809,-274,293,-844,819,-283,860,-254,839,-288,280,-820,285,-824,858,-268,859,-260,279,-845,261,-822,307,-821,282,-848,274,-844,815,-318,267,-825,845,-289,272,-823,841,-290,263,-833,287,-834,291,-815,290,-833,273,-839,863,-248,843,-268,288,-846,831,-264,292,-847,833,-260,290,-845,280,-822,838,-274,291,-825,289,-821,856,-259,292,-1947,301,-8595,324,-818,261,-833,317,-818,840,-277,286,-817,281,-819,839,-285,293,-793,868,-264,292,-822,846,-292,278,-812,307,-823,265,-830,317,-818,266,-840,844,-265,847,-271,318,-815,821,-308,265,-825,846,-289,278,-812,284,-849,824,-268,304,-823,289,-814,844,-293,272,-1955,291,-8605,325,-801,264,-857,294,-793,866,-283,293,-796,291,-847,824,-284,259,-863,838,-255,283,-845,293,-798,869,-291,255,-834,857,-268,824,-269,877,-269,273,-824,313,-816,838,-250,864,-264,293,-833,289,-812,293,-847,267,-839,270,-847,840,-253,294,-843,823,-284,292,-821,850,-263,292,-820,301,-810,275,-843,319,-794,289,-837,841,-267,872,-252,295,-819,866,-262,268,-819,867,-265,292,-822,269,-848,830,-264,296,-849,278,-813,861,-268,278,-1967,265,-8616,317,-829,292,-810,293,-848,839,-250,294,-843,269,-820,840,-292,296,-820,843,-262,289,-821,294,-846,819,-285,293,-818,848,-262,858,-268,826,-293,291,-824,282,-834,852,-271,833,-269,278,-841,291,-825,270,-851,291,-810,291,-837,839,-264,297,-822,847,-268,298,-811,842,-266,309,-812,290,-809,312,-838,261,-863,287,-808,837,-295,840,-263,275,-838,837,-263,286,-847,830,-274,291,-835,297,-821,840,-294,274,-820,289,-824,844,-268,286] 116 | -------------------------------------------------------------------------------- /cc1101-controls.yaml: -------------------------------------------------------------------------------- 1 | number: 2 | - platform: template 3 | id: cc1101_freq_num 4 | name: "CC1101 frequency" 5 | lambda: return id(mycc1101)._freq; 6 | set_action: 7 | then: 8 | - lambda: |- 9 | id(mycc1101)._freq=x; 10 | id(mycc1101).setup_direct_mode(); 11 | id(cc1101_freq_num).update(); 12 | min_value: 300.0 13 | max_value: 928.0 14 | step: 0.01 15 | unit_of_measurement: MHz 16 | - platform: template 17 | id: cc1101_bw_num 18 | name: "CC1101 filter bandwidth" 19 | lambda: return id(mycc1101)._bandwidth; 20 | set_action: 21 | then: 22 | - lambda: |- 23 | id(mycc1101)._bandwidth=x; 24 | id(mycc1101).setup_direct_mode(); 25 | id(cc1101_bw_num).update(); 26 | min_value: 58.0 27 | max_value: 818.0 28 | step: 10 29 | unit_of_measurement: kHz 30 | - platform: template 31 | id: cc1101_br_num 32 | name: "CC1101 bitrate" 33 | lambda: return id(mycc1101)._bitrate; 34 | set_action: 35 | then: 36 | - lambda: |- 37 | id(mycc1101)._bitrate=x; 38 | id(mycc1101).setup_direct_mode(); 39 | id(cc1101_br_num).update(); 40 | min_value: 0.025 41 | max_value: 600 42 | step: 0.025 43 | unit_of_measurement: kbps 44 | - platform: template 45 | id: cc1101_cs_abs_thr_num 46 | name: "CC1101 RSSI threshold to assert carrier sense, Thr = MAGN_TARGET + CARRIER_SENSE_ABS_TH [dB]" 47 | lambda: return -((-(id(mycc1101)._REG_AGCCTRL1&3))&3); 48 | set_action: 49 | then: 50 | - lambda: |- 51 | id(mycc1101)._REG_AGCCTRL1=((~((int)x))+1)&3; 52 | id(mycc1101).setup_direct_mode(); 53 | id(cc1101_sensor_reg_agcctrl1).update(); 54 | id(cc1101_cs_abs_thr_num).update(); 55 | min_value: -3 56 | max_value: 0 57 | step: 1 58 | unit_of_measurement: dB 59 | select: 60 | - platform: template 61 | id: cc1101_modulation 62 | name: "CC1101 modulation" 63 | options: 64 | - "OOK (default)" 65 | - "FSK" 66 | lambda: |- 67 | return id(cc1101_modulation).at(id(mycc1101)._modulation==esphome::radiolib_cc1101::OOK_MODULATION ? 0 : 1); 68 | set_action: 69 | then: 70 | - lambda: |- 71 | id(mycc1101)._modulation=id(cc1101_modulation).index_of(x).value()==0 ? esphome::radiolib_cc1101::OOK_MODULATION : esphome::radiolib_cc1101::FSK_MODULATION; 72 | id(mycc1101).setup_direct_mode(); 73 | id(cc1101_modulation).update(); 74 | - platform: template 75 | id: cc1101_dvga_gain_reduce 76 | name: "Reduce maximum available DVGA gain by:" 77 | options: 78 | - "no reduction (default)" 79 | - "disable top gain setting" 80 | - "disable top two gain setting" 81 | - "disable top three gain setting" 82 | lambda: return id(cc1101_dvga_gain_reduce).at(0x3&(id(mycc1101)._REG_AGCCTRL2>>6)).value(); 83 | set_action: 84 | then: 85 | - lambda: |- 86 | id(mycc1101)._REG_AGCCTRL2=(id(mycc1101)._REG_AGCCTRL2&0xc7)|(id(cc1101_dvga_gain_reduce).index_of(x).value()<<6); 87 | id(mycc1101).setup_direct_mode(); 88 | id(cc1101_sensor_reg_agcctrl2).update(); 89 | id(cc1101_dvga_gain_reduce).update(); 90 | - platform: template 91 | id: cc1101_lna_gain_reduce 92 | name: "Reduce maximum LNA gain by:" 93 | options: 94 | - "0 dB (default)" 95 | - "2.6 dB" 96 | - "6.1 dB" 97 | - "7.4 dB" 98 | - "9.2 dB" 99 | - "11.5 dB" 100 | - "14.6 dB" 101 | - "17.1 dB" 102 | lambda: return id(cc1101_lna_gain_reduce).at(0x7&(id(mycc1101)._REG_AGCCTRL2>>3)).value(); 103 | set_action: 104 | then: 105 | - lambda: |- 106 | id(mycc1101)._REG_AGCCTRL2=(id(mycc1101)._REG_AGCCTRL2&0xc7)|(id(cc1101_lna_gain_reduce).index_of(x).value()<<3); 107 | id(mycc1101).setup_direct_mode(); 108 | id(cc1101_sensor_reg_agcctrl2).update(); 109 | id(cc1101_lna_gain_reduce).update(); 110 | - platform: template 111 | id: cc1101_magn_target 112 | name: "Average amplitude target for filter (MAGN_TARGET):" 113 | options: 114 | - "24 dB" 115 | - "27 dB" 116 | - "30 dB" 117 | - "33 dB (default)" 118 | - "36 dB" 119 | - "38 dB" 120 | - "40 dB" 121 | - "42 dB" 122 | lambda: return id(cc1101_magn_target).at(0x7&(id(mycc1101)._REG_AGCCTRL2)).value(); 123 | set_action: 124 | then: 125 | - lambda: |- 126 | id(mycc1101)._REG_AGCCTRL2=(id(mycc1101)._REG_AGCCTRL2&0xc7)|(id(cc1101_magn_target).index_of(x).value()); 127 | id(mycc1101).setup_direct_mode(); 128 | id(cc1101_sensor_reg_agcctrl2).update(); 129 | id(cc1101_magn_target).update(); 130 | - platform: template 131 | id: cc1101_lna_priority 132 | name: "LNA priority setting:" 133 | options: 134 | - "LNA2 first" 135 | - "LNA first (default)" 136 | lambda: return id(cc1101_lna_priority).at(0x1&(id(mycc1101)._REG_AGCCTRL1>>6)).value(); 137 | set_action: 138 | then: 139 | - lambda: |- 140 | id(mycc1101)._REG_AGCCTRL1=(id(mycc1101)._REG_AGCCTRL1&0xbf)|(id(cc1101_lna_priority).index_of(x).value()<<6); 141 | id(mycc1101).setup_direct_mode(); 142 | id(cc1101_sensor_reg_agcctrl1).update(); 143 | id(cc1101_lna_priority).update(); 144 | - platform: template 145 | id: cc1101_carrier_sense_rel_thr 146 | name: "RSSI relative change to assert carrier sense:" 147 | options: 148 | - "disabled (default)" 149 | - "6 dB" 150 | - "10 dB" 151 | - "14 dB" 152 | lambda: return id(cc1101_carrier_sense_rel_thr).at(0x3&(id(mycc1101)._REG_AGCCTRL1>>4)).value(); 153 | set_action: 154 | then: 155 | - lambda: |- 156 | id(mycc1101)._REG_AGCCTRL2=(id(mycc1101)._REG_AGCCTRL1&0xcf)|(id(cc1101_carrier_sense_rel_thr).index_of(x).value()<<4); 157 | id(mycc1101).setup_direct_mode(); 158 | id(cc1101_sensor_reg_agcctrl1).update(); 159 | id(cc1101_carrier_sense_rel_thr).update(); 160 | # CARRIER_SENSE_ABS_THR is number template above 161 | - platform: template 162 | id: cc1101_hyst_level 163 | name: "AGC hysteresis level:" 164 | options: 165 | - "none" 166 | - "low" 167 | - "medium (default)" 168 | - "high" 169 | lambda: return id(cc1101_hyst_level).at(0x3&(id(mycc1101)._REG_AGCCTRL0>>6)).value(); 170 | set_action: 171 | then: 172 | - lambda: |- 173 | id(mycc1101)._REG_AGCCTRL0=(id(mycc1101)._REG_AGCCTRL0&0x3f)|(id(cc1101_hyst_level).index_of(x).value()<<6); 174 | id(mycc1101).setup_direct_mode(); 175 | id(cc1101_sensor_reg_agcctrl0).update(); 176 | id(cc1101_hyst_level).update(); 177 | - platform: template 178 | id: cc1101_wait_time 179 | name: "AGC wait time:" 180 | options: 181 | - "8 samples" 182 | - "16 samples (default)" 183 | - "24 samples" 184 | - "32 samples" 185 | lambda: return id(cc1101_wait_time).at(0x3&(id(mycc1101)._REG_AGCCTRL0>>4)).value(); 186 | set_action: 187 | then: 188 | - lambda: |- 189 | id(mycc1101)._REG_AGCCTRL0=(id(mycc1101)._REG_AGCCTRL0&0xcf)|(id(cc1101_wait_time).index_of(x).value()<<4); 190 | id(mycc1101).setup_direct_mode(); 191 | id(cc1101_sensor_reg_agcctrl0).update(); 192 | id(cc1101_wait_time).update(); 193 | - platform: template 194 | id: cc1101_agc_freeze 195 | name: "Freeze AGC gain:" 196 | options: 197 | - "never (default)" 198 | - "when sync word is found" 199 | - "manually freeze analog control" 200 | - "manually freeze analog and digital control" 201 | lambda: return id(cc1101_agc_freeze).at(0x3&(id(mycc1101)._REG_AGCCTRL0>>2)).value(); 202 | set_action: 203 | then: 204 | - lambda: |- 205 | id(mycc1101)._REG_AGCCTRL0=(id(mycc1101)._REG_AGCCTRL0&0xf3)|(id(cc1101_agc_freeze).index_of(x).value()<<2); 206 | id(mycc1101).setup_direct_mode(); 207 | id(cc1101_sensor_reg_agcctrl0).update(); 208 | id(cc1101_agc_freeze).update(); 209 | - platform: template 210 | id: cc1101_filter_length 211 | name: "Averaging length for channel filter:" 212 | options: 213 | - "8 samples" 214 | - "16 samples (default)" 215 | - "32 samples" 216 | - "64 samples" 217 | lambda: return id(cc1101_filter_length).at(0x3&(id(mycc1101)._REG_AGCCTRL0)).value(); 218 | set_action: 219 | then: 220 | - lambda: |- 221 | id(mycc1101)._REG_AGCCTRL0=(id(mycc1101)._REG_AGCCTRL0&0xfc)|(id(cc1101_filter_length).index_of(x).value()); 222 | id(mycc1101).setup_direct_mode(); 223 | id(cc1101_sensor_reg_agcctrl0).update(); 224 | id(cc1101_filter_length).update(); 225 | - platform: template 226 | id: cc1101_ask_ook_boundary 227 | name: "ASK/OOK decision boundary:" 228 | options: 229 | - "4 dB" 230 | - "8 dB (default)" 231 | - "12 dB" 232 | - "16 dB" 233 | lambda: return id(cc1101_ask_ook_boundary).at(0x3&(id(mycc1101)._REG_AGCCTRL0)).value(); 234 | set_action: 235 | then: 236 | - lambda: |- 237 | id(mycc1101)._REG_AGCCTRL0=(id(mycc1101)._REG_AGCCTRL0&0xfc)|(id(cc1101_ask_ook_boundary).index_of(x).value()); 238 | id(mycc1101).setup_direct_mode(); 239 | id(cc1101_sensor_reg_agcctrl0).update(); 240 | id(cc1101_ask_ook_boundary).update(); 241 | 242 | sensor: 243 | - platform: template 244 | id: cc1101_sensor_rssi 245 | name: "CC1101 RSSI" 246 | lambda: return id(mycc1101).getRSSI(); 247 | update_interval: 10s 248 | unit_of_measurement: dB 249 | - platform: template 250 | id: cc1101_sensor_rx_rssi 251 | name: "CC1101 Last RX RSSI" 252 | lambda: return id(mycc1101).last_rx_rssi; 253 | update_interval: 10s 254 | unit_of_measurement: dB 255 | 256 | text_sensor: 257 | - platform: template 258 | id: cc1101_sensor_reg_agcctrl2 259 | name: "CC1101 _REG_AGCCTRL2" 260 | lambda: return str_sprintf("0x%x",id(mycc1101)._REG_AGCCTRL2); 261 | - platform: template 262 | id: cc1101_sensor_reg_agcctrl1 263 | name: "CC1101 _REG_AGCCTRL1" 264 | lambda: return str_sprintf("0x%x",id(mycc1101)._REG_AGCCTRL1); 265 | - platform: template 266 | id: cc1101_sensor_reg_agcctrl0 267 | name: "CC1101 _REG_AGCCTRL0" 268 | lambda: return str_sprintf("0x%x",id(mycc1101)._REG_AGCCTRL0); 269 | --------------------------------------------------------------------------------