Closed holtiwilan closed 3 years ago
My Fault. EPROM was not Working. Now it does
Sorry for maybe stupid question, but can I use your code if I will be using D1 mini with C1101? I wand to integrate Somfy Report in my existing home assistant instance using MQTT, but I couldn't find code, which includes both "MQTT" and CC1101, only your code seems to be considering everything what I need. Many thanks for your reply
Hi There. I'm using a CC1101 on a Node-MCU Device.
I used the following Code to Use MQTT to move my awning.
The Programming seemed to work (Awning moved after sening PROG)
But now, when i send Up or Down nothing happens.
I checked, that there is traffic on 433.42 with SDR-Sharp.
Any ideas?
`
include
include "Adafruit_MQTT.h"
include "Adafruit_MQTT_Client.h"
include
include
include
include
define DEBUG
define AIO_SERVER "192.168.178.177" //IP of your mqtt server
define AIO_SERVERPORT 1883 //port of mqtt server - use 8883 for SSL
define AIO_USERNAME "mqtt_username"
define AIO_KEY "mqtt_password"
define RF_SENDER D1 //this is where you connected the RF sender data pin
define EMITTER_GPIO 5
define EEPROM_ADDRESS 0
//#define REMOTE 0x5184c8
define REMOTE 0x65dc00
define CC1101_FREQUENCY 433.42
const bool TEST = 0; const int MAXTRIES = 5; // how many times should we try to reconnent to host const char ssid = "MyWifi"; const char password = "MyPassword;
// Create an ESP8266 WiFiClient class to connect to the MQTT server. WiFiClient client; // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); Adafruit_MQTT_Subscribe mqttSomfy = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/garage/blinds"); Adafruit_MQTT_Subscribe *subscription;
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS); SomfyRemote somfyRemote(EMITTER_GPIO, REMOTE, &rollingCodeStorage);
void setup() {
Serial.begin(115200);
somfyRemote.setup();
ELECHOUSE_cc1101.Init(); ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
Serial.begin(115200); Serial.flush();
ReconnectToWiFi("setup");
Serial.println(""); mqtt.subscribe(&mqttSomfy);
Serial.println("Setup completed"); }
void sendCC1101Command(Command command) { ELECHOUSE_cc1101.SetTx(); somfyRemote.sendCommand(command); ELECHOUSE_cc1101.setSidle(); }
void loop() { MQTT_connect(); while ((subscription = mqtt.readSubscription(1000))) { if (subscription == &mqttSomfy) { Serial.println("Message in blinds topic: " + String((char)mqttSomfy.lastread)); const Command command = getSomfyCommand((char)mqttSomfy.lastread); sendCC1101Command(command); }
} }
void ReconnectToWiFi(String task) { WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.print("Connecting to "); Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); }
// Function to connect and reconnect as necessary to the MQTT server. // Should be called in the loop function and it will take care if connecting. void MQTT_connect() { // Stop if already connected. if (mqtt.connected()) { return; }
int8_t ret; uint8_t retries = 3;
Serial.print("Connecting to MQTT... ");
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected Serial.println(mqtt.connectErrorString(ret)); Serial.println("Retrying MQTT connection in 5 seconds..."); mqtt.disconnect(); delay(5000); // wait 5 seconds retries--; if (retries == 0) { // basically die and wait for WDT to reset me while (1); } } Serial.println("MQTT Connected!"); }`