-
Notifications
You must be signed in to change notification settings - Fork 19
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
Receives but doesn't send commands #28
Comments
Looking at the h file, I think |
Hmm I'm not familiar enough with esphome's yaml and how that the whole thing works. Is that something that should be added to the yaml? In theory I can compare my function calls to my C code to know what's missing, but not really familiar with esphome at a Code level. |
The cc1101.h file. |
Yah I concur with the discussion follow up that you had #25 . I managed to make mine work by changing your code to essentially ignore the USE_ESP32 specific code. Moreover, I've removed all of the ESP32 conditional code and treated it using the regular path and that managed to work. I can send & receive no problem now. Caveat however is that whenever I send something. Although I can send & receive, sending a stream always results in an immediate crash
|
I just tested an esp32 with the code as is and both sending and receiving work fine for me. |
I found a way to use a single pin in the esp32, I'll update the repository soon |
Try this, you only need to connect GDO0 in an esp32 and let me know. // cc1101.h
// https://github.com/dbuezas/esphome-cc1101
#ifndef CC1101TRANSCIVER_H
#define CC1101TRANSCIVER_H
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include "esphome/components/remote_transmitter/remote_transmitter.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; // TX and also RX
float _bandwidth;
esphome::remote_transmitter::RemoteTransmitterComponent* _remote_transmitter;
float _moduleNumber;
int _last_rssi = 0;
void setup() {
pinMode(_GDO0, INPUT);
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, float bandwidth, float freq,
esphome::remote_transmitter::RemoteTransmitterComponent* remote_transmitter)
: PollingComponent(100) {
_SCK = SCK;
_MISO = MISO;
_MOSI = MOSI;
_CSN = CSN;
_GDO0 = GDO0;
_bandwidth = bandwidth;
_freq = freq;
_moduleNumber = CC1101_module_count++;
_remote_transmitter = remote_transmitter;
}
void beginTransmission() {
ELECHOUSE_cc1101.setModul(_moduleNumber);
ELECHOUSE_cc1101.SetTx();
pinMode(_GDO0, OUTPUT);
_remote_transmitter->setup();
}
void endTransmission() {
digitalWrite(_GDO0, 0);
pinMode(_GDO0, INPUT);
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 = false;
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 # cc1101-esp32.yaml
esphome:
name: fan-test
friendly_name: Fan test
includes:
- cc1101.h
libraries:
- SPI
- "SmartRC-CC1101-Driver-Lib"
esp32:
board: esp32dev
wifi:
ssid: !secret wifi_name
password: !secret wifi_pass
fast_connect: true
power_save_mode: HIGH
logger:
level: VERBOSE
api:
ota:
web_server:
port: 80
number:
- platform: template
max_value: 812
min_value: 58
step: 1
mode: slider
optimistic: true
unit_of_measurement: "kHz"
name: BW
on_value:
then:
- lambda: get_cc1101(transciver).setBW(x);
- platform: template
# if your cc1101 board is tuned for ~320MHz
# min_value: 300
# max_value: 348
# if your cc1101 board is tuned for ~433MHz
min_value: 378
max_value: 464
# if your cc1101 board is tuned for ~868Hz
# min_value: 799
# max_value: 928
step: .001
mode: box
optimistic: true
unit_of_measurement: "MHz"
name: FREQ
on_value:
then:
- lambda: get_cc1101(transciver).setFreq(x);
sensor:
- platform: custom
lambda: |-
auto my_sensor = new CC1101(
18, // SCK
19, // MISO
23, // MOSI
5, // CSN
32, // GDO0
200, // bandwidth_in_khz
433.92, // freq_in_mhz
id(transmitter) // id of remote_transmitter
);
App.register_component(my_sensor);
return {my_sensor};
sensors:
id: transciver
internal: true
remote_transmitter:
- id: transmitter
pin:
number: GPIO32 # This is GDO0
allow_other_uses: true
carrier_duty_percent: 100%
remote_receiver:
- id: receiver
pin:
number: GPIO32 # This is GDO0
allow_other_uses: true
# on the esp8266 use any of D1,D2,D5,D6,D7,Rx
# Don't use D3,D4,D8,TX, boot often fails.
# Can't be D0 or GPIO17 b/c no interrupts
dump:
- raw
binary_sensor:
- platform: remote_receiver
name: Garage
raw:
code: [990,-330,330,-990,990,-330,330,-990,330,-990,330,-990,330,-990,330,-990,330,-990,990,-330,330,-990,990,-330,330,-990,330,-990,330,-990,330,-990,330,-990,330,-990,990,-330,990,-330,330,-990,330,-990,990,-330,330,-990,330]
switch:
- platform: template
name: "RSSI"
entity_category: diagnostic
lambda: return get_cc1101(transciver).rssi_on;
turn_on_action:
lambda: get_cc1101(transciver).rssi_on = true;
turn_off_action:
lambda: get_cc1101(transciver).rssi_on = false;
button:
- platform: template
name: Garage
on_press:
- lambda: get_cc1101(transciver).beginTransmission();
- remote_transmitter.transmit_raw:
code: [990,-330,330,-990,990,-330,330,-990,330,-990,330,-990,330,-990,330,-990,330,-990,990,-330,330,-990,990,-330,330,-990,330,-990,330,-990,330,-990,330,-990,330,-990,990,-330,990,-330,330,-990,330,-990,990,-330,330,-990,330]
repeat:
times: 3
wait_time: 4.733ms
- lambda: get_cc1101(transciver).endTransmission(); |
Try the new cc1101 and yaml files. GDO2 not necessary in esp32 anymore. |
Thanks. I'll give that a try. |
I was able to configure my WROVER-B device, have it register to Home Assistant and I have no problem receiving data according to the serial console, but for some reason it doesn't actually send anything according to my SDR & Universal Radio Hacker. Given that I can receive, I'm guessing that the issue is with my configuration. My GDO pins re slightly different given that I'm using a slightly different esp32. My understanding is that GDO2 isn't used in this case as the CC1101 chip can only Tx or Rx at any point in time but not both.
My own C app written in Arduino & using the same library works, so I know that the hardware is connected fine and can work as expected.
When I use the remote control I see the following which closely resembles the code I want to send (aka: with some errors):
When I press the button in Home Assistant:
My yaml configuration:
The text was updated successfully, but these errors were encountered: