Skip to content

Commit 2aebe2c

Browse files
committed
ESP32 fixes
1 parent 2f84cbf commit 2aebe2c

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

hampton_bay_fan_mqtt/hampton_bay_fan_mqtt.ino

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <ELECHOUSE_CC1101_SRC_DRV.h>
22
#include <RCSwitch.h>
3-
#include <ESP8266WiFi.h>
3+
#ifdef ESP32
4+
#include <WiFi.h>
5+
#elif ESP8266
6+
#include <ESP8266WiFi.h>
7+
#endif
48
#include <PubSubClient.h>
59

610
// Configure wifi settings
@@ -27,6 +31,10 @@
2731
#ifdef ESP32 // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
2832
#define RX_PIN 4
2933
#define TX_PIN 2
34+
#define SCK_PIN 18
35+
#define SS_PIN 5
36+
#define MISO_PIN 19
37+
#define MOSI_PIN 23
3038
#elif ESP8266 // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
3139
#define RX_PIN 4
3240
#define TX_PIN 5
@@ -259,11 +267,22 @@ void setup() {
259267
fans[i].fanSpeed = FAN_OFF;
260268
}
261269

270+
#ifdef ESP32 // Override Spi pin assignments for ESP32 only
271+
ELECHOUSE_cc1101.setSpiPin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
272+
ELECHOUSE_cc1101.setGDO(TX_PIN, RX_PIN);
273+
#endif
274+
262275
ELECHOUSE_cc1101.Init();
263276
ELECHOUSE_cc1101.setMHZ(FREQUENCY);
264277
ELECHOUSE_cc1101.SetRx();
265278
mySwitch.enableReceive(RX_PIN);
266279

280+
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
281+
Serial.println("CC1101 Connection OK");
282+
}else{
283+
Serial.println("CC1101 Connection Error");
284+
}
285+
267286
setup_wifi();
268287
client.setServer(MQTT_HOST, MQTT_PORT);
269288
client.setCallback(callback);

0 commit comments

Comments
 (0)