esphome-cc1101
esphome-cc1101 copied to clipboard
On ESP32 transceiver stops receiving after first transmission
Hi,
Thanks for the awesome work, I would really love to see this implemented as official component for ESPHome.
The only issue i have is that on ESP32 the transceiver stops receiving after the first transmission...I tested both basic and advanced .yaml configs from your repo so the issue seems to be in CC1101.h code
If you can give any clues about what can cause the issue i can test it
Regards
Hey! The chip is probably stuck in transmission mode. Did you make sure to call "endTransmission" via a lambda after transmitting? Btw, I only tested it on esp8266, but it shouldn't make a difference.
May the force be with you obi wan
Hi,
Thx for your reply.
The cover actions from my config look like this:
open_action:
- lambda: get_cc1101(transciver).beginTransmission();
- remote_transmitter.transmit_raw:
code: [-****** ****** -******]
repeat:
times: 10
- lambda: get_cc1101(transciver).endTransmission();
- delay: 80s
- cover.template.publish:
id: gate
state: CLOSED
So I am calling the "endTransmission" via lambda but somehow it might not be setting the transceiver back to RX
May the force be with you too :)
Hi! I finally managed to fix the issue by modifying CC1101.h code adding GDO2 configuration for RX...after some testing i think the issue was in the constant change of pinMode for GDO0 switching from input to output back and forth...setting GDO0 for output and GDO2 for input made it work for me. I also added a block called setRX so you can decide from yaml file if you want to set it back to rx after transmission or leave it idle
this is my version of cc1101.h if you're interested
#ifndef CC1101TRANSCIVER_H
#define CC1101TRANSCIVER_H
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int CC1101_module_count = 0;
#define get_cc1101(id) (*((CC1101 *)id))
class CC1101 : public PollingComponent, public Sensor {
int _SCK;
int _MISO;
int _MOSI;
int _CSN;
int _GDO0;
int _GDO2;
float _bandwidth;
float _moduleNumber;
int _last_rssi = 0;
void setup() {
ELECHOUSE_cc1101.setGDO(_GDO0, _GDO2);
ELECHOUSE_cc1101.addSpiPin(_SCK, _MISO, _MOSI, _CSN, _moduleNumber);
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setRxBW(_bandwidth);
ELECHOUSE_cc1101.setMHZ(_freq);
ELECHOUSE_cc1101.SetRx();
}
public:
float _freq;
CC1101(int SCK, int MISO, int MOSI, int CSN, int GDO0, int GDO2, float bandwidth,
float freq)
: PollingComponent(100) {
_SCK = SCK;
_MISO = MISO;
_MOSI = MOSI;
_CSN = CSN;
_GDO0 = GDO0;
_GDO2 = GDO2;
_bandwidth = bandwidth;
_freq = freq;
_moduleNumber = CC1101_module_count++;
}
void beginTransmission() {
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.SetTx();
noInterrupts();
}
void endTransmission() {
interrupts();
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.setSidle();
}
void setRX() {
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.SetRx();
}
void setBW(float bandwidth) {
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.setRxBW(bandwidth);
}
void setFreq(float freq) {
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.setMHZ(freq);
}
bool rssi_on;
void update() override {
int rssi = 0;
if (rssi_on) {
ELECHOUSE_cc1101.setModul(_moduleNumber);
rssi = ELECHOUSE_cc1101.getRssi();
}
if (rssi != _last_rssi) {
publish_state(rssi);
_last_rssi = rssi;
}
}
};
#endif
Hi! I finally managed to fix the issue by modifying CC1101.h code adding GDO2 configuration for RX...after some testing i think the issue was in the constant change of pinMode for GDO0 switching from input to output back and forth...setting GDO0 for output and GDO2 for input made it work for me. I also added a block called setRX so you can decide from yaml file if you want to set it back to rx after transmission or leave it idle
this is my version of cc1101.h if you're interested
Do i still need to call the start transmission and stop transmission ?
Hi! I finally managed to fix the issue by modifying CC1101.h code adding GDO2 configuration for RX...after some testing i think the issue was in the constant change of pinMode for GDO0 switching from input to output back and forth...setting GDO0 for output and GDO2 for input made it work for me. I also added a block called setRX so you can decide from yaml file if you want to set it back to rx after transmission or leave it idle this is my version of cc1101.h if you're interested
Do i still need to call the start transmission and stop transmission ?
Yes, you absolutely do. You also have to call setRX the same way from yaml file if you want to set it back to RX mode after transmission.
I'm new to HA and ESPHome. I already installed ESPHome to my ESP32 devkit C4. I connected my CC1101 like this because I had success with this config with another firmware.
Could you please post your complete ESP32 yaml file? Where to put the cc1101.h? Where can I follow arbitrary RF signals being received? Once I found the interesting signal (like key presses from a remote) - how to define a "button" in HA to send (repeat) this signal?
The complete yaml is any of the two yaml files in this repo. The cc1101.h file goes in the same folder as the yaml file. To pick arbitrary signals take a look at "dump: raw" in the EspHome docs here: https://esphome.io/components/remote_receiver.html
Here's a utility to analyze raw signals btw: https://github.com/dbuezas/esphome-remote_receiver-oscilloscope
I haven't tried it with the esp32 myself, but somebody did in the issues of this repo, try searching in the issues of this repo :)
Regarding the file, you'll have to copy it to where EspHome stores its yaml files (google HomeAssistant file explorer or ssh), or maybe try including the the GitHub url of the file, it may work
ssh'd into HA, placed @ob1w4nken0b1's cc1101.h
in /config/esphome
but validation fails with:
INFO Reading configuration /config/esphome/esphome-web-2c7b48.yaml...
Failed config
remote_transmitter: [source /config/esphome/esphome-web-2c7b48.yaml:54]
-
Cannot resolve pin name 'D4' for board esp32dev.
pin: D4
carrier_duty_percent: 100%
remote_receiver: [source /config/esphome/esphome-web-2c7b48.yaml:58]
-
Cannot resolve pin name 'D13' for board esp32dev.
pin: D13
dump:
- raw
Use GPIO numbers: https://esphome.io/devices/nodemcu_esp32.html?highlight=esp32+pins
Eventually I used GPIOx and bare numbers in new CC1101(...)
. Now I can see signal noise in the logs. When I push a button of a remote there's a block of numbers. How to go from here?
I could decode the signal using rtl_433 using this flex decoder.
From there i suggest you read the remote_receiver and remote_transmitter components in the esphome docs abd then take a look at the utility I posted above. Good luck!
Hello there, just a little piece of advice, I've the 433Mhz module, same yours, I've 8 pin, but I don't find any information about connection to esp32.
Thanks
ps:
Do you think it's correct this:
- platform: custom
lambda: |-
auto my_sensor = new CC1101(
GPIO18, // SCK
GPIO19, // MISO
GPIO23, // MOSI
GPIO02, // CSN
GPIO16, // GDO0
200, // bandwidth_in_khz
433.92 // freq_in_mhz
);
App.register_component(my_sensor);
return {my_sensor};
sensors:
id: transciver_1
name: "${name} RF RSSI"
unit_of_measurement: dBm
entity_category: diagnostic
remote_transmitter:
- id: transmitter_1
pin: GPIO16
carrier_duty_percent: 100%
remote_receiver:
- id: receiver_1
pin: GPIO16
dump:
- raw
class CC1101 : public PollingComponent, public Sensor { int _SCK; int _MISO; int _MOSI; int _CSN; int _GDO0; int _GDO2; float _bandwidth;
What do we need to add in the YAML with this?
Thanks
See the yaml file in this repo
HI , Any chance of getting a copy of your yaml file as well please.
The complete yaml is any of the two yaml files in this repo. The cc1101.h file goes in the same folder as the yaml file. To pick arbitrary signals take a look at "dump: raw" in the EspHome docs here: https://esphome.io/components/remote_receiver.html
Except you would have to modify the yaml to define the GDO2 pin, correct?
Hello there, just a little piece of advice, I've the 433Mhz module, same yours, I've 8 pin, but I don't find any information about connection to esp32.
Thanks
ps:
Do you think it's correct this:
- platform: custom lambda: |- auto my_sensor = new CC1101( GPIO18, // SCK GPIO19, // MISO GPIO23, // MOSI GPIO02, // CSN GPIO16, // GDO0 200, // bandwidth_in_khz 433.92 // freq_in_mhz ); App.register_component(my_sensor); return {my_sensor}; sensors: id: transciver_1 name: "${name} RF RSSI" unit_of_measurement: dBm entity_category: diagnostic remote_transmitter: - id: transmitter_1 pin: GPIO16 carrier_duty_percent: 100% remote_receiver: - id: receiver_1 pin: GPIO16 dump: - raw
did you make it work for esp32?
Never got mine working.
@brunopiras I believe CSN should be GPIO5 as shown here
That said, I tried for a few days to get an ESP 32S working and gave up and just hooked up another 8266 and it worked right away.
I never tried. You can google if the library I'm using is compatible with the esp32. The library is called ELECHOUSE_CC1101_SRC_DRV
Sorry it is this one: https://github.com/LSatan/SmartRC-CC1101-Driver-Lib which derives from the one I mentioned. It states in the readme that the author made some fixes for the esp32. You may want to dig there
Try the new cc1101 and yaml files. GDO2 not necessary in esp32 anymore.
I can confirm ESP32 to be working with esphome with seperate RX/TX pins.