From 73f64b4bd7532947438d87607e60585d754ae167 Mon Sep 17 00:00:00 2001 From: jchasey <35230842+jchasey@users.noreply.github.com> Date: Thu, 1 Mar 2018 14:30:27 +0000 Subject: [PATCH 1/6] Add files via upload Added support for OTA password using the setPassword function, by default this not enabled and simply set with a line in the config.h file. --- KmanSonoff_v1.00mc.ino | 494 +++++++++++++++++++++++++++++++++++++++++ KmanSonoff_v1.00sc.ino | 392 ++++++++++++++++++++++++++++++++ config_mc.h | 33 +++ config_sc.h | 36 +++ 4 files changed, 955 insertions(+) create mode 100644 KmanSonoff_v1.00mc.ino create mode 100644 KmanSonoff_v1.00sc.ino create mode 100644 config_mc.h create mode 100644 config_sc.h diff --git a/KmanSonoff_v1.00mc.ino b/KmanSonoff_v1.00mc.ino new file mode 100644 index 0000000..1b39644 --- /dev/null +++ b/KmanSonoff_v1.00mc.ino @@ -0,0 +1,494 @@ +/* + Copyright (c) 2017 @KmanOz + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + **** Use this Firmware for: Sonoff 4CH, 4CH Pro & T1 (1, 2 and 3 Channel) **** + **** Make sure to select "Generic ESP8285 Module" from the BOARD menu in TOOLS **** + **** Flash Size "1M (64K SPIFFS)" **** + + =============================================================================================== + ATTENTION !!!!!! DO NOT CHANGE ANYTHING IN THIS SECTION. UPDATE YOUR DETAILS IN CONFIG.H + =============================================================================================== +*/ + +#include "config_mc.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define B_1 0 +#define B_2 9 +#define B_3 10 +#define B_4 14 +#define L_1 12 +#define L_2 5 +#define L_3 4 +#define L_4 15 +#define LED 13 +#define HOST_PREFIX "Sonoff_%s" +#define HEADER "\n\n-------------- KmanSonoff_v1.00mc --------------" +#define VER "ksmc_v1.00" + +bool requestRestart = false; +bool OTAupdate = false; +char ESP_CHIP_ID[8]; +char UID[16]; +long rssi; +unsigned long TTasks; +#ifdef CH_1 + bool sendStatus1 = false; + int SS1; + unsigned long count1 = 0; + Ticker btn_timer1; +#endif +#ifdef CH_2 + bool sendStatus2 = false; + int SS2; + unsigned long count2 = 0; + Ticker btn_timer2; +#endif +#ifdef CH_3 + bool sendStatus3 = false; + int SS3; + unsigned long count3 = 0; + Ticker btn_timer3; +#endif +#ifdef CH_4 + bool sendStatus4 = false; + int SS4; + unsigned long count4 = 0; + Ticker btn_timer4; +#endif +extern "C" { + #include "user_interface.h" +} +WiFiClient wifiClient; +PubSubClient mqttClient(wifiClient, MQTT_SERVER, MQTT_PORT); + +void callback(const MQTT::Publish& pub) { + if (pub.payload_string() == "stat") { + } + #ifdef CH_1 + else if (pub.payload_string() == "1on") { + digitalWrite(L_1, HIGH); + sendStatus1 = true; + } + else if (pub.payload_string() == "1off") { + digitalWrite(L_1, LOW); + sendStatus1 = true; + } + #endif + #ifdef CH_2 + else if (pub.payload_string() == "2on") { + digitalWrite(L_2, HIGH); + sendStatus2 = true; + } + else if (pub.payload_string() == "2off") { + digitalWrite(L_2, LOW); + sendStatus2 = true; + } + #endif + #ifdef CH_3 + else if (pub.payload_string() == "3on") { + digitalWrite(L_3, HIGH); + sendStatus3 = true; + } + else if (pub.payload_string() == "3off") { + digitalWrite(L_3, LOW); + sendStatus3 = true; + } + #endif + #ifdef CH_4 + else if (pub.payload_string() == "4on") { + digitalWrite(L_4, HIGH); + sendStatus4 = true; + } + else if (pub.payload_string() == "4off") { + digitalWrite(L_4, LOW); + sendStatus4 = true; + } + #endif + else if (pub.payload_string() == "reset") { + requestRestart = true; + } +} + +void setup() { + pinMode(LED, OUTPUT); + digitalWrite(LED, HIGH);; + Serial.begin(115200); + sprintf(ESP_CHIP_ID, "%06X", ESP.getChipId()); + sprintf(UID, HOST_PREFIX, ESP_CHIP_ID); + EEPROM.begin(8); + #ifdef CH_1 + pinMode(B_1, INPUT); + pinMode(L_1, OUTPUT); + digitalWrite(L_1, LOW); + SS1 = EEPROM.read(0); + if (rememberRelayState1 && SS1 == 1) { + digitalWrite(L_1, HIGH); + } + btn_timer1.attach(0.05, button1); + #endif + #ifdef CH_2 + pinMode(B_2, INPUT); + pinMode(L_2, OUTPUT); + digitalWrite(L_2, LOW); + SS2 = EEPROM.read(1); + if (rememberRelayState2 && SS2 == 1) { + digitalWrite(L_2, HIGH); + } + btn_timer2.attach(0.05, button2); + #endif + #ifdef CH_3 + pinMode(B_3, INPUT); + pinMode(L_3, OUTPUT); + digitalWrite(L_3, LOW); + SS3 = EEPROM.read(2); + if (rememberRelayState3 && SS3 == 1) { + digitalWrite(L_3, HIGH); + } + btn_timer3.attach(0.05, button3); + #endif + #ifdef CH_4 + pinMode(B_4, INPUT); + pinMode(L_4, OUTPUT); + digitalWrite(L_4, LOW); + SS4 = EEPROM.read(3); + if (rememberRelayState4 && SS4 == 1) { + digitalWrite(L_4, HIGH); + } + btn_timer4.attach(0.05, button4); + #endif + mqttClient.set_callback(callback); + WiFi.mode(WIFI_STA); + WiFi.hostname(UID); + WiFi.begin(WIFI_SSID, WIFI_PASS); + ArduinoOTA.setHostname(UID); + #ifdef OTA_PASS + ArduinoOTA.setPassword(OTA_PASS); + #endif + ArduinoOTA.onStart([]() { + OTAupdate = true; + blinkLED(LED, 400, 2); + digitalWrite(LED, HIGH); + Serial.println("OTA Update Initiated . . ."); + }); + ArduinoOTA.onEnd([]() { + Serial.println("\nOTA Update Ended . . .s"); + OTAupdate = false; + requestRestart = true; + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + digitalWrite(LED, LOW); + delay(5); + digitalWrite(LED, HIGH); + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }); + ArduinoOTA.onError([](ota_error_t error) { + blinkLED(LED, 40, 2); + OTAupdate = false; + Serial.printf("OTA Error [%u] ", error); + if (error == OTA_AUTH_ERROR) Serial.println(". . . . . . . . . . . . . . . Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println(". . . . . . . . . . . . . . . Begin Failed"); + else if (error == OTA_CONNECT_ERROR) Serial.println(". . . . . . . . . . . . . . . Connect Failed"); + else if (error == OTA_RECEIVE_ERROR) Serial.println(". . . . . . . . . . . . . . . Receive Failed"); + else if (error == OTA_END_ERROR) Serial.println(". . . . . . . . . . . . . . . End Failed"); + }); + ArduinoOTA.begin(); + Serial.println(HEADER); + Serial.print("\nUnit ID: "); + Serial.print(UID); + Serial.print("\nConnecting to "); Serial.print(WIFI_SSID); Serial.print(" Wifi"); + while ((WiFi.status() != WL_CONNECTED) && kRetries --) { + delay(500); + Serial.print(" ."); + } + if (WiFi.status() == WL_CONNECTED) { + Serial.println(" DONE"); + Serial.print("IP Address is: "); Serial.println(WiFi.localIP()); + Serial.print("Connecting to ");Serial.print(MQTT_SERVER);Serial.print(" Broker . ."); + delay(500); + while (!mqttClient.connect(MQTT::Connect(UID).set_keepalive(90).set_auth(MQTT_USER, MQTT_PASS)) && kRetries --) { + Serial.print(" ."); + delay(1000); + } + if(mqttClient.connected()) { + Serial.println(" DONE"); + Serial.println("\n--------------------- Logs ---------------------"); + Serial.println(); + mqttClient.subscribe(MQTT_TOPIC); + blinkLED(LED, 40, 8); + digitalWrite(LED, LOW); + } + else { + Serial.println(" FAILED!"); + Serial.println("\n--------------------------------------------------"); + Serial.println(); + } + } + else { + Serial.println(" WiFi FAILED!"); + Serial.println("\n--------------------------------------------------"); + Serial.println(); + } +} + +void loop() { + ArduinoOTA.handle(); + if (OTAupdate == false) { + mqttClient.loop(); + timedTasks(); + checkStatus(); + } +} + +void blinkLED(int pin, int duration, int n) { + for(int i=0; i 1 && count1 <= 40) { + digitalWrite(L_1, !digitalRead(L_1)); + sendStatus1 = true; + } + else if (count1 >40){ + Serial.println("\n\nSonoff Rebooting . . . . . . . . Please Wait"); + requestRestart = true; + } + count1=0; + } + } +#endif +#ifdef CH_2 + void button2() { + if (!digitalRead(B_2)) { + count2++; + } + else { + if (count2 > 1 && count2 <= 40) { + digitalWrite(L_2, !digitalRead(L_2)); + sendStatus2 = true; + } + count2=0; + } + } +#endif +#ifdef CH_3 + void button3() { + if (!digitalRead(B_3)) { + count3++; + } + else { + if (count3 > 1 && count3 <= 40) { + digitalWrite(L_3, !digitalRead(L_3)); + sendStatus3 = true; + } + count3=0; + } + } +#endif +#ifdef CH_4 + void button4() { + if (!digitalRead(B_4)) { + count4++; + } + else { + if (count4 > 1 && count4 <= 40) { + digitalWrite(L_4, !digitalRead(L_4)); + sendStatus4 = true; + } + count4=0; + } + } +#endif + +void checkConnection() { + if (WiFi.status() == WL_CONNECTED) { + if (mqttClient.connected()) { + Serial.println("mqtt broker connection . . . . . . . . . . OK"); + } + else { + Serial.println("mqtt broker connection . . . . . . . . . . LOST"); + requestRestart = true; + } + } + else { + Serial.println("WiFi connection . . . . . . . . . . LOST"); + requestRestart = true; + } +} + +void checkStatus() { + #ifdef CH_1 + if (sendStatus1) { + if(digitalRead(L_1) == LOW) { + if (rememberRelayState1) { + EEPROM.write(0, 0); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1off").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1off").set_retain().set_qos(QOS)); + } + Serial.println("Relay 1 . . . . . . . . . . . . . . . . . . OFF"); + } else { + if (rememberRelayState1) { + EEPROM.write(0, 1); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1on").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1on").set_retain().set_qos(QOS)); + } + Serial.println("Relay 1 . . . . . . . . . . . . . . . . . . ON"); + } + sendStatus1 = false; + } + #endif + #ifdef CH_2 + if (sendStatus2) { + if(digitalRead(L_2) == LOW) { + if (rememberRelayState2) { + EEPROM.write(1, 0); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2off").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2off").set_retain().set_qos(QOS)); + } + Serial.println("Relay 2 . . . . . . . . . . . . . . . . . . OFF"); + } else { + if (rememberRelayState2) { + EEPROM.write(1, 1); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2on").set_retain().set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2on").set_qos(QOS)); + } + Serial.println("Relay 2 . . . . . . . . . . . . . . . . . . ON"); + } + sendStatus2 = false; + } + #endif + #ifdef CH_3 + if (sendStatus3) { + if(digitalRead(L_3) == LOW) { + if (rememberRelayState3) { + EEPROM.write(2, 0); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3off").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3off").set_retain().set_qos(QOS)); + } + Serial.println("Relay 3 . . . . . . . . . . . . . . . . . . OFF"); + } else { + if (rememberRelayState3) { + EEPROM.write(2, 1); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3on").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3on").set_retain().set_qos(QOS)); + } + Serial.println("Relay 3 . . . . . . . . . . . . . . . . . . ON"); + } + sendStatus3 = false; + } + #endif + #ifdef CH_4 + if (sendStatus4) { + if(digitalRead(L_4) == LOW) { + if (rememberRelayState4) { + EEPROM.write(3, 0); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4off").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4off").set_retain().set_qos(QOS)); + } + Serial.println("Relay 4 . . . . . . . . . . . . . . . . . . OFF"); + } else { + if (rememberRelayState4) { + EEPROM.write(3, 1); + EEPROM.commit(); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4on").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4on").set_retain().set_qos(QOS)); + } + Serial.println("Relay 4 . . . . . . . . . . . . . . . . . . ON"); + } + sendStatus4 = false; + } + #endif + if (requestRestart) { + blinkLED(LED, 400, 4); + ESP.restart(); + } +} + +void doReport() { + rssi = WiFi.RSSI(); + char message_buff[120]; + String pubString = "{\"UID\": "+String(UID)+", "+"\"WiFi RSSI\": "+String(rssi)+"dBM"+", "+"\"Topic\": "+String(MQTT_TOPIC)+", "+"\"Ver\": "+String(VER)+"}"; + pubString.toCharArray(message_buff, pubString.length()+1); + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_qos(QOS)); + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_retain().set_qos(QOS)); + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_retain().set_qos(QOS)); + } +} + +void timedTasks() { + if ((millis() > TTasks + (kUpdFreq*60000)) || (millis() < TTasks)) { + TTasks = millis(); + doReport(); + checkConnection(); + } +} + diff --git a/KmanSonoff_v1.00sc.ino b/KmanSonoff_v1.00sc.ino new file mode 100644 index 0000000..ed502f3 --- /dev/null +++ b/KmanSonoff_v1.00sc.ino @@ -0,0 +1,392 @@ +/* + Copyright (c) 2017 @KmanOz + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + *** USE THIS Firmware for: Original Sonoff, Sonoff SV, Sonoff Touch, Sonoff S20 Smart Socket, Sonof TH Series *** + + ================================================================================================ + ATTENTION !!!!!! DO NOT CHANGE ANYTHING IN THIS SECTION UNLESS YOU KNOW WHAT YOU ARE DOING + ================================================================================================ +*/ + +#include "config_sc.h" +#ifdef TEMP +#include "DHT.h" +#endif +#include +#include +#include +#include +#include +#include +#include + +#define B_1 0 +#define L_1 12 +#define LED 13 +#if defined (TEMP) || defined (WS) +#define OPT_PIN 14 +#endif +#define HOST_PREFIX "Sonoff_%s" +#define HEADER "\n\n--------------------- KmanSonoff_v1.00sc -------------------" +#define VER "kssc_v1.00" + +bool OTAupdate = false; +bool sendStatus = false; +bool requestRestart = false; +bool tempReport = false; +char ESP_CHIP_ID[8]; +char UID[16]; +#ifdef WS +int wallSwitch = 1; +int lastWallSwitch = 1; +#endif +int lastRelayState; +long rssi; +unsigned long TTasks1; +unsigned long count = 0; +#ifdef TEMP +DHT dht(OPT_PIN, DHTTYPE, 11); +#endif +extern "C" { + #include "user_interface.h" +} +WiFiClient wifiClient; +PubSubClient mqttClient(wifiClient, MQTT_SERVER, MQTT_PORT); +Ticker btn_timer; + +void callback(const MQTT::Publish& pub) { + if (pub.payload_string() == "stat") { + } + else if (pub.payload_string() == "on") { + #ifdef ORIG + digitalWrite(LED, LOW); + #endif + digitalWrite(L_1, HIGH); + } + else if (pub.payload_string() == "off") { + #ifdef ORIG + digitalWrite(LED, HIGH); + #endif + digitalWrite(L_1, LOW); + } + else if (pub.payload_string() == "reset") { + requestRestart = true; + } + sendStatus = true; +} + +void setup() { + pinMode(LED, OUTPUT); + pinMode(L_1, OUTPUT); + pinMode(B_1, INPUT); + #ifdef WS + pinMode(OPT_PIN, INPUT_PULLUP); + #endif + digitalWrite(LED, HIGH); + digitalWrite(L_1, LOW); + Serial.begin(115200); + sprintf(ESP_CHIP_ID, "%06X", ESP.getChipId()); + sprintf(UID, HOST_PREFIX, ESP_CHIP_ID); + EEPROM.begin(8); + lastRelayState = EEPROM.read(0); + if (rememberRelayState && lastRelayState == 1) { + #ifdef ORIG + digitalWrite(LED, LOW); + #endif + digitalWrite(L_1, HIGH); + } + btn_timer.attach(0.05, button); + mqttClient.set_callback(callback); + WiFi.mode(WIFI_STA); + WiFi.hostname(UID); + WiFi.begin(WIFI_SSID, WIFI_PASS); + ArduinoOTA.setHostname(UID); + #ifdef OTA_PASS + ArduinoOTA.setPassword(OTA_PASS); + #endif + ArduinoOTA.onStart([]() { + OTAupdate = true; + blinkLED(LED, 400, 2); + digitalWrite(LED, HIGH); + Serial.println("OTA Update Initiated . . ."); + }); + ArduinoOTA.onEnd([]() { + Serial.println("\nOTA Update Ended . . .s"); + ESP.restart(); + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + digitalWrite(LED, LOW); + delay(5); + digitalWrite(LED, HIGH); + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }); + ArduinoOTA.onError([](ota_error_t error) { + blinkLED(LED, 40, 2); + OTAupdate = false; + Serial.printf("OTA Error [%u] ", error); + if (error == OTA_AUTH_ERROR) Serial.println(". . . . . . . . . . . . . . . Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println(". . . . . . . . . . . . . . . Begin Failed"); + else if (error == OTA_CONNECT_ERROR) Serial.println(". . . . . . . . . . . . . . . Connect Failed"); + else if (error == OTA_RECEIVE_ERROR) Serial.println(". . . . . . . . . . . . . . . Receive Failed"); + else if (error == OTA_END_ERROR) Serial.println(". . . . . . . . . . . . . . . End Failed"); + }); + ArduinoOTA.begin(); + Serial.println(HEADER); + Serial.print("\nUID: "); + Serial.print(UID); + Serial.print("\nConnecting to "); Serial.print(WIFI_SSID); Serial.print(" Wifi"); + while ((WiFi.status() != WL_CONNECTED) && kRetries --) { + delay(500); + Serial.print(" ."); + } + if (WiFi.status() == WL_CONNECTED) { + Serial.println(" DONE"); + Serial.print("IP Address is: "); Serial.println(WiFi.localIP()); + Serial.print("Connecting to ");Serial.print(MQTT_SERVER);Serial.print(" Broker . ."); + delay(500); + while (!mqttClient.connect(MQTT::Connect(UID).set_keepalive(90).set_auth(MQTT_USER, MQTT_PASS)) && kRetries --) { + Serial.print(" ."); + delay(1000); + } + if(mqttClient.connected()) { + Serial.println(" DONE"); + Serial.println("\n---------------------------- Logs ----------------------------"); + Serial.println(); + mqttClient.subscribe(MQTT_TOPIC); + blinkLED(LED, 40, 8); + #ifdef ORIG + if(digitalRead(L_1) == HIGH) { + digitalWrite(LED, LOW); + } else { + digitalWrite(LED, HIGH); + } + #endif + #ifdef TH + digitalWrite(LED, LOW); + #endif + } + else { + Serial.println(" FAILED!"); + Serial.println("\n----------------------------------------------------------------"); + Serial.println(); + } + } + else { + Serial.println(" WiFi FAILED!"); + Serial.println("\n----------------------------------------------------------------"); + Serial.println(); + } +} + +void loop() { + ArduinoOTA.handle(); + if (OTAupdate == false) { + mqttClient.loop(); + timedTasks1(); + checkStatus(); + #ifdef TEMP + if (tempReport) { + getTemp(); + } + #endif + #ifdef WS + checkWallSwitch(); + #endif + } +} + +void blinkLED(int pin, int duration, int n) { + for(int i=0; i 1 && count <= 40) { + #ifdef ORIG + digitalWrite(LED, !digitalRead(LED)); + #endif + digitalWrite(L_1, !digitalRead(L_1)); + sendStatus = true; + } + else if (count >40){ + Serial.println("\n\nSonoff Rebooting . . . . . . . . Please Wait"); + requestRestart = true; + } + count=0; + } +} + +void checkConnection() { + if (WiFi.status() == WL_CONNECTED) { + if (mqttClient.connected()) { + Serial.println("mqtt broker connection . . . . . . . . . . OK"); + } + else { + Serial.println("mqtt broker connection . . . . . . . . . . LOST"); + requestRestart = true; + } + } + else { + Serial.println("WiFi connection . . . . . . . . . . LOST"); + requestRestart = true; + } +} + +void checkStatus() { + if (sendStatus) { + #ifdef ORIG + if(digitalRead(LED) == LOW) { + if (rememberRelayState) { + EEPROM.write(0, 1); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_retain().set_qos(QOS)); + } + Serial.println("Relay . . . . . . . . . . . . . . . . . . ON"); + } else { + if (rememberRelayState) { + EEPROM.write(0, 0); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_retain().set_qos(QOS)); + } + Serial.println("Relay . . . . . . . . . . . . . . . . . . OFF"); + } + #endif + #ifdef TH + if(digitalRead(L_1) == LOW) { + if (rememberRelayState) { + EEPROM.write(0, 0); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_retain().set_qos(QOS)); + } + Serial.println("Relay . . . . . . . . . . . . . . . . . . OFF"); + } else { + if (rememberRelayState) { + EEPROM.write(0, 1); + } + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_retain().set_qos(QOS)); + } + Serial.println("Relay . . . . . . . . . . . . . . . . . . ON"); + } + #endif + if (rememberRelayState) { + EEPROM.commit(); + } + sendStatus = false; + } + if (requestRestart) { + blinkLED(LED, 400, 4); + ESP.restart(); + } +} + +#ifdef WS +void checkWallSwitch() { + wallSwitch = digitalRead(OPT_PIN); + if (wallSwitch != lastWallSwitch) { + digitalWrite(L_1, !digitalRead(L_1)); + digitalWrite(LED, !digitalRead(LED)); + sendStatus = true; + } + lastWallSwitch = wallSwitch; +} +#endif + +#ifdef TEMP +void getTemp() { + Serial.print("DHT read . . . . . . . . . . . . . . . . . "); + float dhtH, dhtT, dhtHI; + char message_buff[60]; + dhtH = dht.readHumidity(); + dhtT = dht.readTemperature(UseFahrenheit); + dhtHI = dht.computeHeatIndex(dhtT, dhtH, UseFahrenheit); + if(digitalRead(LED) == LOW) { + blinkLED(LED, 100, 1); + } else { + blinkLED(LED, 100, 1); + digitalWrite(LED, HIGH); + } + if (isnan(dhtH) || isnan(dhtT) || isnan(dhtHI)) { + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug","\"DHT Read Error\"").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug","\"DHT Read Error\"").set_retain().set_qos(QOS)); + } + Serial.println("ERROR"); + tempReport = false; + return; + } + String pubString = "{\"Temp\": "+String(dhtT)+", "+"\"Humidity\": "+String(dhtH)+", "+"\"HeatIndex\": "+String(dhtHI) + "}"; + pubString.toCharArray(message_buff, pubString.length()+1); + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/temp", message_buff).set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/temp", message_buff).set_retain().set_qos(QOS)); + } + Serial.println("OK"); + tempReport = false; +} +#endif + +void doReport() { + rssi = WiFi.RSSI(); + char message_buff[120]; + String pubString = "{\"UID\": "+String(UID)+", "+"\"WiFi RSSI\": "+String(rssi)+"dBM"+", "+"\"Topic\": "+String(MQTT_TOPIC)+", "+"\"Ver\": "+String(VER)+"}"; + pubString.toCharArray(message_buff, pubString.length()+1); + if (kRetain == 0) { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_qos(QOS)); + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_qos(QOS)); + } else { + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_retain().set_qos(QOS)); + mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_retain().set_qos(QOS)); + } +} + +void timedTasks1() { + if ((millis() > TTasks1 + (kUpdFreq*60000)) || (millis() < TTasks1)) { + TTasks1 = millis(); + checkConnection(); + doReport(); + #ifdef TEMP + tempReport = true; + #endif + } +} + diff --git a/config_mc.h b/config_mc.h new file mode 100644 index 0000000..833aa50 --- /dev/null +++ b/config_mc.h @@ -0,0 +1,33 @@ +/* + ====================================================================================================================================== + Modify all parameters below to suit you environment + ====================================================================================================================================== +*/ +bool rememberRelayState1 = true; // If 'true' remembers the state of relay 1 before power loss. +bool rememberRelayState2 = true; // If 'true' remembers the state of relay 2 before power loss. +bool rememberRelayState3 = true; // If 'true' remembers the state of relay 3 before power loss. +bool rememberRelayState4 = true; // If 'true' remembers the state of relay 4 before power loss. + // Each relay will be OFF evey time power is applied when set to 'false' + +int kRetain = 0; // Retain mqtt messages (0 for off, 1 for on) +int kUpdFreq = 1; // Update frequency in Mintes to check for mqtt connection. Defualt 1 min. +int kRetries = 10; // WiFi retry count (10 default). Increase if not connecting to your WiFi. +int QOS = 0; // QOS level for all mqtt messages. (0 or 1) + +#define CH_1 // Channel 1 (Default single channel. Do not comment out) +//#define CH_2 // Channel 2 (Uncomment to use 2nd Channel) +//#define CH_3 // Channel 3 (Uncomment to use 3rd Channel) +//#define CH_4 // Channel 4 (Uncomment to use 4th Channel) + +#define MQTT_SERVER "192.168.0.100" // Your mqtt server ip address +#define MQTT_PORT 1883 // Your mqtt port +#define MQTT_TOPIC "home/sonoff/living_room/1" // Base mqtt topic +#define MQTT_USER "mqtt_user" // mqtt username +#define MQTT_PASS "mqtt_pass" // mqtt password + +#define WIFI_SSID "wifissid" // Your WiFi ssid +#define WIFI_PASS "wifipass" // Your WiFi password +#define OTA_PASS 0 // OTA Password for reflashing - if 0 disabled +/* + ====================================================================================================================================== +*/ diff --git a/config_sc.h b/config_sc.h new file mode 100644 index 0000000..d619bd4 --- /dev/null +++ b/config_sc.h @@ -0,0 +1,36 @@ +/* + =========================================================================================================================================== + Modify all parameters below to suit you environment + =========================================================================================================================================== +*/ +bool rememberRelayState = true; // If 'true' remembers the state of the relay before power loss otherwise + // load will be OFF evey time power is applied. Set retain below to 0 if true. + +int kRetain = 0; // Retain mqtt messages (0 for off, 1 for on) +int kUpdFreq = 1; // Update frequency in Mintes to check for mqtt connection. Defualt 1 min. +int kRetries = 10; // WiFi retry count (10 default). Increase if not connecting to your WiFi. +int QOS = 0; // QOS level for all mqtt messages. (0 or 1) + +#define NONE // Set to NONE, TEMP, or WS (Cannot be blank) + // NONE for standard Sonoff relay only ON / OFF (default) + // TEMP for DHT11/22 Support on Pin 5 of header (GPIO 14) **Must install 'DHT sensor library' (Adafruit) & 'Adafruit Unified Sensor' library. + // WS for External Wallswitch Support on Pin 5 of header (GPIO 14) + +#define ORIG // ORIG or TH + // ORIG for Basic / Original Sonoff, TH for TH Series + +#define DHTTYPE DHT22 // Set to 'DHT11' or 'DHT22'. (Only applies if using TEMP) **Must connect to the mains power for temperature readings to be sent. +#define UseFahrenheit false // Set to 'true' to use Fahrenheit. (Only applies if using TEMP) + +#define MQTT_SERVER "192.168.0.100" // Your mqtt server ip address +#define MQTT_PORT 1883 // Your mqtt port +#define MQTT_TOPIC "home/sonoff/living_room/1" // Base mqtt topic +#define MQTT_USER "mqtt_user" // mqtt username +#define MQTT_PASS "mqtt_pass" // mqtt password + +#define WIFI_SSID "wifissid" // Your WiFi ssid +#define WIFI_PASS "wifipass" // Your WiFi password +#define OTA_PASS 0 // OTA Password for reflashing - if 0 disabled +/* + =========================================================================================================================================== +*/ From 630903ebb7ba8ab91ef105ca3969c3143e667953 Mon Sep 17 00:00:00 2001 From: jchasey Date: Thu, 1 Mar 2018 14:42:14 +0000 Subject: [PATCH 2/6] Added support for OTA Password --- arduino/KmanSonoff_v1.00mc/KmanSonoff_v1.00mc.ino | 3 +++ arduino/KmanSonoff_v1.00mc/config_mc.h | 1 + arduino/KmanSonoff_v1.00sc/KmanSonoff_v1.00sc.ino | 3 +++ arduino/KmanSonoff_v1.00sc/config_sc.h | 1 + 4 files changed, 8 insertions(+) diff --git a/arduino/KmanSonoff_v1.00mc/KmanSonoff_v1.00mc.ino b/arduino/KmanSonoff_v1.00mc/KmanSonoff_v1.00mc.ino index da91d96..1b39644 100755 --- a/arduino/KmanSonoff_v1.00mc/KmanSonoff_v1.00mc.ino +++ b/arduino/KmanSonoff_v1.00mc/KmanSonoff_v1.00mc.ino @@ -187,6 +187,9 @@ void setup() { WiFi.hostname(UID); WiFi.begin(WIFI_SSID, WIFI_PASS); ArduinoOTA.setHostname(UID); + #ifdef OTA_PASS + ArduinoOTA.setPassword(OTA_PASS); + #endif ArduinoOTA.onStart([]() { OTAupdate = true; blinkLED(LED, 400, 2); diff --git a/arduino/KmanSonoff_v1.00mc/config_mc.h b/arduino/KmanSonoff_v1.00mc/config_mc.h index a1b5a03..833aa50 100755 --- a/arduino/KmanSonoff_v1.00mc/config_mc.h +++ b/arduino/KmanSonoff_v1.00mc/config_mc.h @@ -27,6 +27,7 @@ int QOS = 0; // QOS level for a #define WIFI_SSID "wifissid" // Your WiFi ssid #define WIFI_PASS "wifipass" // Your WiFi password +#define OTA_PASS 0 // OTA Password for reflashing - if 0 disabled /* ====================================================================================================================================== */ diff --git a/arduino/KmanSonoff_v1.00sc/KmanSonoff_v1.00sc.ino b/arduino/KmanSonoff_v1.00sc/KmanSonoff_v1.00sc.ino index ed9afbc..ed502f3 100755 --- a/arduino/KmanSonoff_v1.00sc/KmanSonoff_v1.00sc.ino +++ b/arduino/KmanSonoff_v1.00sc/KmanSonoff_v1.00sc.ino @@ -119,6 +119,9 @@ void setup() { WiFi.hostname(UID); WiFi.begin(WIFI_SSID, WIFI_PASS); ArduinoOTA.setHostname(UID); + #ifdef OTA_PASS + ArduinoOTA.setPassword(OTA_PASS); + #endif ArduinoOTA.onStart([]() { OTAupdate = true; blinkLED(LED, 400, 2); diff --git a/arduino/KmanSonoff_v1.00sc/config_sc.h b/arduino/KmanSonoff_v1.00sc/config_sc.h index 557ec11..d619bd4 100755 --- a/arduino/KmanSonoff_v1.00sc/config_sc.h +++ b/arduino/KmanSonoff_v1.00sc/config_sc.h @@ -30,6 +30,7 @@ int QOS = 0; // QOS level for a #define WIFI_SSID "wifissid" // Your WiFi ssid #define WIFI_PASS "wifipass" // Your WiFi password +#define OTA_PASS 0 // OTA Password for reflashing - if 0 disabled /* =========================================================================================================================================== */ From 9778b7886b3202575b70dc858feb2e002492d56e Mon Sep 17 00:00:00 2001 From: jchasey <35230842+jchasey@users.noreply.github.com> Date: Thu, 1 Mar 2018 14:43:14 +0000 Subject: [PATCH 3/6] Delete config_sc.h --- config_sc.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 config_sc.h diff --git a/config_sc.h b/config_sc.h deleted file mode 100644 index d619bd4..0000000 --- a/config_sc.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - =========================================================================================================================================== - Modify all parameters below to suit you environment - =========================================================================================================================================== -*/ -bool rememberRelayState = true; // If 'true' remembers the state of the relay before power loss otherwise - // load will be OFF evey time power is applied. Set retain below to 0 if true. - -int kRetain = 0; // Retain mqtt messages (0 for off, 1 for on) -int kUpdFreq = 1; // Update frequency in Mintes to check for mqtt connection. Defualt 1 min. -int kRetries = 10; // WiFi retry count (10 default). Increase if not connecting to your WiFi. -int QOS = 0; // QOS level for all mqtt messages. (0 or 1) - -#define NONE // Set to NONE, TEMP, or WS (Cannot be blank) - // NONE for standard Sonoff relay only ON / OFF (default) - // TEMP for DHT11/22 Support on Pin 5 of header (GPIO 14) **Must install 'DHT sensor library' (Adafruit) & 'Adafruit Unified Sensor' library. - // WS for External Wallswitch Support on Pin 5 of header (GPIO 14) - -#define ORIG // ORIG or TH - // ORIG for Basic / Original Sonoff, TH for TH Series - -#define DHTTYPE DHT22 // Set to 'DHT11' or 'DHT22'. (Only applies if using TEMP) **Must connect to the mains power for temperature readings to be sent. -#define UseFahrenheit false // Set to 'true' to use Fahrenheit. (Only applies if using TEMP) - -#define MQTT_SERVER "192.168.0.100" // Your mqtt server ip address -#define MQTT_PORT 1883 // Your mqtt port -#define MQTT_TOPIC "home/sonoff/living_room/1" // Base mqtt topic -#define MQTT_USER "mqtt_user" // mqtt username -#define MQTT_PASS "mqtt_pass" // mqtt password - -#define WIFI_SSID "wifissid" // Your WiFi ssid -#define WIFI_PASS "wifipass" // Your WiFi password -#define OTA_PASS 0 // OTA Password for reflashing - if 0 disabled -/* - =========================================================================================================================================== -*/ From 014afbec920f6fa0cd30ddc8a28ae24c17174b7c Mon Sep 17 00:00:00 2001 From: jchasey <35230842+jchasey@users.noreply.github.com> Date: Thu, 1 Mar 2018 14:43:46 +0000 Subject: [PATCH 4/6] Delete KmanSonoff_v1.00mc.ino --- KmanSonoff_v1.00mc.ino | 494 ----------------------------------------- 1 file changed, 494 deletions(-) delete mode 100644 KmanSonoff_v1.00mc.ino diff --git a/KmanSonoff_v1.00mc.ino b/KmanSonoff_v1.00mc.ino deleted file mode 100644 index 1b39644..0000000 --- a/KmanSonoff_v1.00mc.ino +++ /dev/null @@ -1,494 +0,0 @@ -/* - Copyright (c) 2017 @KmanOz - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - - **** Use this Firmware for: Sonoff 4CH, 4CH Pro & T1 (1, 2 and 3 Channel) **** - **** Make sure to select "Generic ESP8285 Module" from the BOARD menu in TOOLS **** - **** Flash Size "1M (64K SPIFFS)" **** - - =============================================================================================== - ATTENTION !!!!!! DO NOT CHANGE ANYTHING IN THIS SECTION. UPDATE YOUR DETAILS IN CONFIG.H - =============================================================================================== -*/ - -#include "config_mc.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#define B_1 0 -#define B_2 9 -#define B_3 10 -#define B_4 14 -#define L_1 12 -#define L_2 5 -#define L_3 4 -#define L_4 15 -#define LED 13 -#define HOST_PREFIX "Sonoff_%s" -#define HEADER "\n\n-------------- KmanSonoff_v1.00mc --------------" -#define VER "ksmc_v1.00" - -bool requestRestart = false; -bool OTAupdate = false; -char ESP_CHIP_ID[8]; -char UID[16]; -long rssi; -unsigned long TTasks; -#ifdef CH_1 - bool sendStatus1 = false; - int SS1; - unsigned long count1 = 0; - Ticker btn_timer1; -#endif -#ifdef CH_2 - bool sendStatus2 = false; - int SS2; - unsigned long count2 = 0; - Ticker btn_timer2; -#endif -#ifdef CH_3 - bool sendStatus3 = false; - int SS3; - unsigned long count3 = 0; - Ticker btn_timer3; -#endif -#ifdef CH_4 - bool sendStatus4 = false; - int SS4; - unsigned long count4 = 0; - Ticker btn_timer4; -#endif -extern "C" { - #include "user_interface.h" -} -WiFiClient wifiClient; -PubSubClient mqttClient(wifiClient, MQTT_SERVER, MQTT_PORT); - -void callback(const MQTT::Publish& pub) { - if (pub.payload_string() == "stat") { - } - #ifdef CH_1 - else if (pub.payload_string() == "1on") { - digitalWrite(L_1, HIGH); - sendStatus1 = true; - } - else if (pub.payload_string() == "1off") { - digitalWrite(L_1, LOW); - sendStatus1 = true; - } - #endif - #ifdef CH_2 - else if (pub.payload_string() == "2on") { - digitalWrite(L_2, HIGH); - sendStatus2 = true; - } - else if (pub.payload_string() == "2off") { - digitalWrite(L_2, LOW); - sendStatus2 = true; - } - #endif - #ifdef CH_3 - else if (pub.payload_string() == "3on") { - digitalWrite(L_3, HIGH); - sendStatus3 = true; - } - else if (pub.payload_string() == "3off") { - digitalWrite(L_3, LOW); - sendStatus3 = true; - } - #endif - #ifdef CH_4 - else if (pub.payload_string() == "4on") { - digitalWrite(L_4, HIGH); - sendStatus4 = true; - } - else if (pub.payload_string() == "4off") { - digitalWrite(L_4, LOW); - sendStatus4 = true; - } - #endif - else if (pub.payload_string() == "reset") { - requestRestart = true; - } -} - -void setup() { - pinMode(LED, OUTPUT); - digitalWrite(LED, HIGH);; - Serial.begin(115200); - sprintf(ESP_CHIP_ID, "%06X", ESP.getChipId()); - sprintf(UID, HOST_PREFIX, ESP_CHIP_ID); - EEPROM.begin(8); - #ifdef CH_1 - pinMode(B_1, INPUT); - pinMode(L_1, OUTPUT); - digitalWrite(L_1, LOW); - SS1 = EEPROM.read(0); - if (rememberRelayState1 && SS1 == 1) { - digitalWrite(L_1, HIGH); - } - btn_timer1.attach(0.05, button1); - #endif - #ifdef CH_2 - pinMode(B_2, INPUT); - pinMode(L_2, OUTPUT); - digitalWrite(L_2, LOW); - SS2 = EEPROM.read(1); - if (rememberRelayState2 && SS2 == 1) { - digitalWrite(L_2, HIGH); - } - btn_timer2.attach(0.05, button2); - #endif - #ifdef CH_3 - pinMode(B_3, INPUT); - pinMode(L_3, OUTPUT); - digitalWrite(L_3, LOW); - SS3 = EEPROM.read(2); - if (rememberRelayState3 && SS3 == 1) { - digitalWrite(L_3, HIGH); - } - btn_timer3.attach(0.05, button3); - #endif - #ifdef CH_4 - pinMode(B_4, INPUT); - pinMode(L_4, OUTPUT); - digitalWrite(L_4, LOW); - SS4 = EEPROM.read(3); - if (rememberRelayState4 && SS4 == 1) { - digitalWrite(L_4, HIGH); - } - btn_timer4.attach(0.05, button4); - #endif - mqttClient.set_callback(callback); - WiFi.mode(WIFI_STA); - WiFi.hostname(UID); - WiFi.begin(WIFI_SSID, WIFI_PASS); - ArduinoOTA.setHostname(UID); - #ifdef OTA_PASS - ArduinoOTA.setPassword(OTA_PASS); - #endif - ArduinoOTA.onStart([]() { - OTAupdate = true; - blinkLED(LED, 400, 2); - digitalWrite(LED, HIGH); - Serial.println("OTA Update Initiated . . ."); - }); - ArduinoOTA.onEnd([]() { - Serial.println("\nOTA Update Ended . . .s"); - OTAupdate = false; - requestRestart = true; - }); - ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { - digitalWrite(LED, LOW); - delay(5); - digitalWrite(LED, HIGH); - Serial.printf("Progress: %u%%\r", (progress / (total / 100))); - }); - ArduinoOTA.onError([](ota_error_t error) { - blinkLED(LED, 40, 2); - OTAupdate = false; - Serial.printf("OTA Error [%u] ", error); - if (error == OTA_AUTH_ERROR) Serial.println(". . . . . . . . . . . . . . . Auth Failed"); - else if (error == OTA_BEGIN_ERROR) Serial.println(". . . . . . . . . . . . . . . Begin Failed"); - else if (error == OTA_CONNECT_ERROR) Serial.println(". . . . . . . . . . . . . . . Connect Failed"); - else if (error == OTA_RECEIVE_ERROR) Serial.println(". . . . . . . . . . . . . . . Receive Failed"); - else if (error == OTA_END_ERROR) Serial.println(". . . . . . . . . . . . . . . End Failed"); - }); - ArduinoOTA.begin(); - Serial.println(HEADER); - Serial.print("\nUnit ID: "); - Serial.print(UID); - Serial.print("\nConnecting to "); Serial.print(WIFI_SSID); Serial.print(" Wifi"); - while ((WiFi.status() != WL_CONNECTED) && kRetries --) { - delay(500); - Serial.print(" ."); - } - if (WiFi.status() == WL_CONNECTED) { - Serial.println(" DONE"); - Serial.print("IP Address is: "); Serial.println(WiFi.localIP()); - Serial.print("Connecting to ");Serial.print(MQTT_SERVER);Serial.print(" Broker . ."); - delay(500); - while (!mqttClient.connect(MQTT::Connect(UID).set_keepalive(90).set_auth(MQTT_USER, MQTT_PASS)) && kRetries --) { - Serial.print(" ."); - delay(1000); - } - if(mqttClient.connected()) { - Serial.println(" DONE"); - Serial.println("\n--------------------- Logs ---------------------"); - Serial.println(); - mqttClient.subscribe(MQTT_TOPIC); - blinkLED(LED, 40, 8); - digitalWrite(LED, LOW); - } - else { - Serial.println(" FAILED!"); - Serial.println("\n--------------------------------------------------"); - Serial.println(); - } - } - else { - Serial.println(" WiFi FAILED!"); - Serial.println("\n--------------------------------------------------"); - Serial.println(); - } -} - -void loop() { - ArduinoOTA.handle(); - if (OTAupdate == false) { - mqttClient.loop(); - timedTasks(); - checkStatus(); - } -} - -void blinkLED(int pin, int duration, int n) { - for(int i=0; i 1 && count1 <= 40) { - digitalWrite(L_1, !digitalRead(L_1)); - sendStatus1 = true; - } - else if (count1 >40){ - Serial.println("\n\nSonoff Rebooting . . . . . . . . Please Wait"); - requestRestart = true; - } - count1=0; - } - } -#endif -#ifdef CH_2 - void button2() { - if (!digitalRead(B_2)) { - count2++; - } - else { - if (count2 > 1 && count2 <= 40) { - digitalWrite(L_2, !digitalRead(L_2)); - sendStatus2 = true; - } - count2=0; - } - } -#endif -#ifdef CH_3 - void button3() { - if (!digitalRead(B_3)) { - count3++; - } - else { - if (count3 > 1 && count3 <= 40) { - digitalWrite(L_3, !digitalRead(L_3)); - sendStatus3 = true; - } - count3=0; - } - } -#endif -#ifdef CH_4 - void button4() { - if (!digitalRead(B_4)) { - count4++; - } - else { - if (count4 > 1 && count4 <= 40) { - digitalWrite(L_4, !digitalRead(L_4)); - sendStatus4 = true; - } - count4=0; - } - } -#endif - -void checkConnection() { - if (WiFi.status() == WL_CONNECTED) { - if (mqttClient.connected()) { - Serial.println("mqtt broker connection . . . . . . . . . . OK"); - } - else { - Serial.println("mqtt broker connection . . . . . . . . . . LOST"); - requestRestart = true; - } - } - else { - Serial.println("WiFi connection . . . . . . . . . . LOST"); - requestRestart = true; - } -} - -void checkStatus() { - #ifdef CH_1 - if (sendStatus1) { - if(digitalRead(L_1) == LOW) { - if (rememberRelayState1) { - EEPROM.write(0, 0); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1off").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1off").set_retain().set_qos(QOS)); - } - Serial.println("Relay 1 . . . . . . . . . . . . . . . . . . OFF"); - } else { - if (rememberRelayState1) { - EEPROM.write(0, 1); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1on").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "1on").set_retain().set_qos(QOS)); - } - Serial.println("Relay 1 . . . . . . . . . . . . . . . . . . ON"); - } - sendStatus1 = false; - } - #endif - #ifdef CH_2 - if (sendStatus2) { - if(digitalRead(L_2) == LOW) { - if (rememberRelayState2) { - EEPROM.write(1, 0); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2off").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2off").set_retain().set_qos(QOS)); - } - Serial.println("Relay 2 . . . . . . . . . . . . . . . . . . OFF"); - } else { - if (rememberRelayState2) { - EEPROM.write(1, 1); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2on").set_retain().set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "2on").set_qos(QOS)); - } - Serial.println("Relay 2 . . . . . . . . . . . . . . . . . . ON"); - } - sendStatus2 = false; - } - #endif - #ifdef CH_3 - if (sendStatus3) { - if(digitalRead(L_3) == LOW) { - if (rememberRelayState3) { - EEPROM.write(2, 0); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3off").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3off").set_retain().set_qos(QOS)); - } - Serial.println("Relay 3 . . . . . . . . . . . . . . . . . . OFF"); - } else { - if (rememberRelayState3) { - EEPROM.write(2, 1); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3on").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "3on").set_retain().set_qos(QOS)); - } - Serial.println("Relay 3 . . . . . . . . . . . . . . . . . . ON"); - } - sendStatus3 = false; - } - #endif - #ifdef CH_4 - if (sendStatus4) { - if(digitalRead(L_4) == LOW) { - if (rememberRelayState4) { - EEPROM.write(3, 0); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4off").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4off").set_retain().set_qos(QOS)); - } - Serial.println("Relay 4 . . . . . . . . . . . . . . . . . . OFF"); - } else { - if (rememberRelayState4) { - EEPROM.write(3, 1); - EEPROM.commit(); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4on").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "4on").set_retain().set_qos(QOS)); - } - Serial.println("Relay 4 . . . . . . . . . . . . . . . . . . ON"); - } - sendStatus4 = false; - } - #endif - if (requestRestart) { - blinkLED(LED, 400, 4); - ESP.restart(); - } -} - -void doReport() { - rssi = WiFi.RSSI(); - char message_buff[120]; - String pubString = "{\"UID\": "+String(UID)+", "+"\"WiFi RSSI\": "+String(rssi)+"dBM"+", "+"\"Topic\": "+String(MQTT_TOPIC)+", "+"\"Ver\": "+String(VER)+"}"; - pubString.toCharArray(message_buff, pubString.length()+1); - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_qos(QOS)); - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_retain().set_qos(QOS)); - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_retain().set_qos(QOS)); - } -} - -void timedTasks() { - if ((millis() > TTasks + (kUpdFreq*60000)) || (millis() < TTasks)) { - TTasks = millis(); - doReport(); - checkConnection(); - } -} - From 72613957d4a9455c36f983c80bfa147936d5fac0 Mon Sep 17 00:00:00 2001 From: jchasey <35230842+jchasey@users.noreply.github.com> Date: Thu, 1 Mar 2018 14:43:56 +0000 Subject: [PATCH 5/6] Delete KmanSonoff_v1.00sc.ino --- KmanSonoff_v1.00sc.ino | 392 ----------------------------------------- 1 file changed, 392 deletions(-) delete mode 100644 KmanSonoff_v1.00sc.ino diff --git a/KmanSonoff_v1.00sc.ino b/KmanSonoff_v1.00sc.ino deleted file mode 100644 index ed502f3..0000000 --- a/KmanSonoff_v1.00sc.ino +++ /dev/null @@ -1,392 +0,0 @@ -/* - Copyright (c) 2017 @KmanOz - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - - *** USE THIS Firmware for: Original Sonoff, Sonoff SV, Sonoff Touch, Sonoff S20 Smart Socket, Sonof TH Series *** - - ================================================================================================ - ATTENTION !!!!!! DO NOT CHANGE ANYTHING IN THIS SECTION UNLESS YOU KNOW WHAT YOU ARE DOING - ================================================================================================ -*/ - -#include "config_sc.h" -#ifdef TEMP -#include "DHT.h" -#endif -#include -#include -#include -#include -#include -#include -#include - -#define B_1 0 -#define L_1 12 -#define LED 13 -#if defined (TEMP) || defined (WS) -#define OPT_PIN 14 -#endif -#define HOST_PREFIX "Sonoff_%s" -#define HEADER "\n\n--------------------- KmanSonoff_v1.00sc -------------------" -#define VER "kssc_v1.00" - -bool OTAupdate = false; -bool sendStatus = false; -bool requestRestart = false; -bool tempReport = false; -char ESP_CHIP_ID[8]; -char UID[16]; -#ifdef WS -int wallSwitch = 1; -int lastWallSwitch = 1; -#endif -int lastRelayState; -long rssi; -unsigned long TTasks1; -unsigned long count = 0; -#ifdef TEMP -DHT dht(OPT_PIN, DHTTYPE, 11); -#endif -extern "C" { - #include "user_interface.h" -} -WiFiClient wifiClient; -PubSubClient mqttClient(wifiClient, MQTT_SERVER, MQTT_PORT); -Ticker btn_timer; - -void callback(const MQTT::Publish& pub) { - if (pub.payload_string() == "stat") { - } - else if (pub.payload_string() == "on") { - #ifdef ORIG - digitalWrite(LED, LOW); - #endif - digitalWrite(L_1, HIGH); - } - else if (pub.payload_string() == "off") { - #ifdef ORIG - digitalWrite(LED, HIGH); - #endif - digitalWrite(L_1, LOW); - } - else if (pub.payload_string() == "reset") { - requestRestart = true; - } - sendStatus = true; -} - -void setup() { - pinMode(LED, OUTPUT); - pinMode(L_1, OUTPUT); - pinMode(B_1, INPUT); - #ifdef WS - pinMode(OPT_PIN, INPUT_PULLUP); - #endif - digitalWrite(LED, HIGH); - digitalWrite(L_1, LOW); - Serial.begin(115200); - sprintf(ESP_CHIP_ID, "%06X", ESP.getChipId()); - sprintf(UID, HOST_PREFIX, ESP_CHIP_ID); - EEPROM.begin(8); - lastRelayState = EEPROM.read(0); - if (rememberRelayState && lastRelayState == 1) { - #ifdef ORIG - digitalWrite(LED, LOW); - #endif - digitalWrite(L_1, HIGH); - } - btn_timer.attach(0.05, button); - mqttClient.set_callback(callback); - WiFi.mode(WIFI_STA); - WiFi.hostname(UID); - WiFi.begin(WIFI_SSID, WIFI_PASS); - ArduinoOTA.setHostname(UID); - #ifdef OTA_PASS - ArduinoOTA.setPassword(OTA_PASS); - #endif - ArduinoOTA.onStart([]() { - OTAupdate = true; - blinkLED(LED, 400, 2); - digitalWrite(LED, HIGH); - Serial.println("OTA Update Initiated . . ."); - }); - ArduinoOTA.onEnd([]() { - Serial.println("\nOTA Update Ended . . .s"); - ESP.restart(); - }); - ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { - digitalWrite(LED, LOW); - delay(5); - digitalWrite(LED, HIGH); - Serial.printf("Progress: %u%%\r", (progress / (total / 100))); - }); - ArduinoOTA.onError([](ota_error_t error) { - blinkLED(LED, 40, 2); - OTAupdate = false; - Serial.printf("OTA Error [%u] ", error); - if (error == OTA_AUTH_ERROR) Serial.println(". . . . . . . . . . . . . . . Auth Failed"); - else if (error == OTA_BEGIN_ERROR) Serial.println(". . . . . . . . . . . . . . . Begin Failed"); - else if (error == OTA_CONNECT_ERROR) Serial.println(". . . . . . . . . . . . . . . Connect Failed"); - else if (error == OTA_RECEIVE_ERROR) Serial.println(". . . . . . . . . . . . . . . Receive Failed"); - else if (error == OTA_END_ERROR) Serial.println(". . . . . . . . . . . . . . . End Failed"); - }); - ArduinoOTA.begin(); - Serial.println(HEADER); - Serial.print("\nUID: "); - Serial.print(UID); - Serial.print("\nConnecting to "); Serial.print(WIFI_SSID); Serial.print(" Wifi"); - while ((WiFi.status() != WL_CONNECTED) && kRetries --) { - delay(500); - Serial.print(" ."); - } - if (WiFi.status() == WL_CONNECTED) { - Serial.println(" DONE"); - Serial.print("IP Address is: "); Serial.println(WiFi.localIP()); - Serial.print("Connecting to ");Serial.print(MQTT_SERVER);Serial.print(" Broker . ."); - delay(500); - while (!mqttClient.connect(MQTT::Connect(UID).set_keepalive(90).set_auth(MQTT_USER, MQTT_PASS)) && kRetries --) { - Serial.print(" ."); - delay(1000); - } - if(mqttClient.connected()) { - Serial.println(" DONE"); - Serial.println("\n---------------------------- Logs ----------------------------"); - Serial.println(); - mqttClient.subscribe(MQTT_TOPIC); - blinkLED(LED, 40, 8); - #ifdef ORIG - if(digitalRead(L_1) == HIGH) { - digitalWrite(LED, LOW); - } else { - digitalWrite(LED, HIGH); - } - #endif - #ifdef TH - digitalWrite(LED, LOW); - #endif - } - else { - Serial.println(" FAILED!"); - Serial.println("\n----------------------------------------------------------------"); - Serial.println(); - } - } - else { - Serial.println(" WiFi FAILED!"); - Serial.println("\n----------------------------------------------------------------"); - Serial.println(); - } -} - -void loop() { - ArduinoOTA.handle(); - if (OTAupdate == false) { - mqttClient.loop(); - timedTasks1(); - checkStatus(); - #ifdef TEMP - if (tempReport) { - getTemp(); - } - #endif - #ifdef WS - checkWallSwitch(); - #endif - } -} - -void blinkLED(int pin, int duration, int n) { - for(int i=0; i 1 && count <= 40) { - #ifdef ORIG - digitalWrite(LED, !digitalRead(LED)); - #endif - digitalWrite(L_1, !digitalRead(L_1)); - sendStatus = true; - } - else if (count >40){ - Serial.println("\n\nSonoff Rebooting . . . . . . . . Please Wait"); - requestRestart = true; - } - count=0; - } -} - -void checkConnection() { - if (WiFi.status() == WL_CONNECTED) { - if (mqttClient.connected()) { - Serial.println("mqtt broker connection . . . . . . . . . . OK"); - } - else { - Serial.println("mqtt broker connection . . . . . . . . . . LOST"); - requestRestart = true; - } - } - else { - Serial.println("WiFi connection . . . . . . . . . . LOST"); - requestRestart = true; - } -} - -void checkStatus() { - if (sendStatus) { - #ifdef ORIG - if(digitalRead(LED) == LOW) { - if (rememberRelayState) { - EEPROM.write(0, 1); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_retain().set_qos(QOS)); - } - Serial.println("Relay . . . . . . . . . . . . . . . . . . ON"); - } else { - if (rememberRelayState) { - EEPROM.write(0, 0); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_retain().set_qos(QOS)); - } - Serial.println("Relay . . . . . . . . . . . . . . . . . . OFF"); - } - #endif - #ifdef TH - if(digitalRead(L_1) == LOW) { - if (rememberRelayState) { - EEPROM.write(0, 0); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_retain().set_qos(QOS)); - } - Serial.println("Relay . . . . . . . . . . . . . . . . . . OFF"); - } else { - if (rememberRelayState) { - EEPROM.write(0, 1); - } - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_retain().set_qos(QOS)); - } - Serial.println("Relay . . . . . . . . . . . . . . . . . . ON"); - } - #endif - if (rememberRelayState) { - EEPROM.commit(); - } - sendStatus = false; - } - if (requestRestart) { - blinkLED(LED, 400, 4); - ESP.restart(); - } -} - -#ifdef WS -void checkWallSwitch() { - wallSwitch = digitalRead(OPT_PIN); - if (wallSwitch != lastWallSwitch) { - digitalWrite(L_1, !digitalRead(L_1)); - digitalWrite(LED, !digitalRead(LED)); - sendStatus = true; - } - lastWallSwitch = wallSwitch; -} -#endif - -#ifdef TEMP -void getTemp() { - Serial.print("DHT read . . . . . . . . . . . . . . . . . "); - float dhtH, dhtT, dhtHI; - char message_buff[60]; - dhtH = dht.readHumidity(); - dhtT = dht.readTemperature(UseFahrenheit); - dhtHI = dht.computeHeatIndex(dhtT, dhtH, UseFahrenheit); - if(digitalRead(LED) == LOW) { - blinkLED(LED, 100, 1); - } else { - blinkLED(LED, 100, 1); - digitalWrite(LED, HIGH); - } - if (isnan(dhtH) || isnan(dhtT) || isnan(dhtHI)) { - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug","\"DHT Read Error\"").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug","\"DHT Read Error\"").set_retain().set_qos(QOS)); - } - Serial.println("ERROR"); - tempReport = false; - return; - } - String pubString = "{\"Temp\": "+String(dhtT)+", "+"\"Humidity\": "+String(dhtH)+", "+"\"HeatIndex\": "+String(dhtHI) + "}"; - pubString.toCharArray(message_buff, pubString.length()+1); - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/temp", message_buff).set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/temp", message_buff).set_retain().set_qos(QOS)); - } - Serial.println("OK"); - tempReport = false; -} -#endif - -void doReport() { - rssi = WiFi.RSSI(); - char message_buff[120]; - String pubString = "{\"UID\": "+String(UID)+", "+"\"WiFi RSSI\": "+String(rssi)+"dBM"+", "+"\"Topic\": "+String(MQTT_TOPIC)+", "+"\"Ver\": "+String(VER)+"}"; - pubString.toCharArray(message_buff, pubString.length()+1); - if (kRetain == 0) { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_qos(QOS)); - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_qos(QOS)); - } else { - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/debug", message_buff).set_retain().set_qos(QOS)); - mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/heartbeat", "OK").set_retain().set_qos(QOS)); - } -} - -void timedTasks1() { - if ((millis() > TTasks1 + (kUpdFreq*60000)) || (millis() < TTasks1)) { - TTasks1 = millis(); - checkConnection(); - doReport(); - #ifdef TEMP - tempReport = true; - #endif - } -} - From a4e4ba1285af11c7cb30f299f26696eb441beffd Mon Sep 17 00:00:00 2001 From: jchasey <35230842+jchasey@users.noreply.github.com> Date: Thu, 1 Mar 2018 14:44:04 +0000 Subject: [PATCH 6/6] Delete config_mc.h --- config_mc.h | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 config_mc.h diff --git a/config_mc.h b/config_mc.h deleted file mode 100644 index 833aa50..0000000 --- a/config_mc.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - ====================================================================================================================================== - Modify all parameters below to suit you environment - ====================================================================================================================================== -*/ -bool rememberRelayState1 = true; // If 'true' remembers the state of relay 1 before power loss. -bool rememberRelayState2 = true; // If 'true' remembers the state of relay 2 before power loss. -bool rememberRelayState3 = true; // If 'true' remembers the state of relay 3 before power loss. -bool rememberRelayState4 = true; // If 'true' remembers the state of relay 4 before power loss. - // Each relay will be OFF evey time power is applied when set to 'false' - -int kRetain = 0; // Retain mqtt messages (0 for off, 1 for on) -int kUpdFreq = 1; // Update frequency in Mintes to check for mqtt connection. Defualt 1 min. -int kRetries = 10; // WiFi retry count (10 default). Increase if not connecting to your WiFi. -int QOS = 0; // QOS level for all mqtt messages. (0 or 1) - -#define CH_1 // Channel 1 (Default single channel. Do not comment out) -//#define CH_2 // Channel 2 (Uncomment to use 2nd Channel) -//#define CH_3 // Channel 3 (Uncomment to use 3rd Channel) -//#define CH_4 // Channel 4 (Uncomment to use 4th Channel) - -#define MQTT_SERVER "192.168.0.100" // Your mqtt server ip address -#define MQTT_PORT 1883 // Your mqtt port -#define MQTT_TOPIC "home/sonoff/living_room/1" // Base mqtt topic -#define MQTT_USER "mqtt_user" // mqtt username -#define MQTT_PASS "mqtt_pass" // mqtt password - -#define WIFI_SSID "wifissid" // Your WiFi ssid -#define WIFI_PASS "wifipass" // Your WiFi password -#define OTA_PASS 0 // OTA Password for reflashing - if 0 disabled -/* - ====================================================================================================================================== -*/