just comment

This commit is contained in:
2021-12-12 19:11:03 +03:00
parent 620e954716
commit 149cb3b5b6
16 changed files with 432 additions and 64 deletions

View File

@@ -15,5 +15,5 @@ framework = arduino
board_build.ldscript = eagle.flash.2m.ld
upload_protocol = espota
upload_port = 192.168.1.129
lib_deps =
joaolopesf/RemoteDebug @ ^3.0.5
;lib_deps =
; joaolopesf/RemoteDebug @ ^3.0.5

View File

@@ -6,11 +6,11 @@
#include <Bounce2.h>
//#define DEBUG_DISABLED true
#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
#ifndef DEBUG_DISABLED // Only if debug is not disabled (for production/release)
RemoteDebug Debug;
//#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
//#ifndef DEBUG_DISABLED // Only if debug is not disabled (for production/release)
//RemoteDebug Debug;
#endif
//#endif
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
@@ -110,12 +110,12 @@ void setup() {
connectToWifi();
cRun = millis();
Debug.begin("SW-BigRoom"); // Initialize the WiFi server
// Debug.begin("SW-BigRoom"); // Initialize the WiFi server
Debug.setResetCmdEnabled(true); // Enable the reset command
// Debug.setResetCmdEnabled(true); // Enable the reset command
Debug.showProfiler(true); // Profiler (Good to measure times, to optimize codes)
Debug.showColors(true); // Colors
// Debug.showProfiler(true); // Profiler (Good to measure times, to optimize codes)
// Debug.showColors(true); // Colors
}
void loop() {
@@ -137,7 +137,7 @@ void loop() {
mqttClient.publish("/home/bigroom/millislamp", 0, false, v);
//debugI("*Publish Millis: %u");
}
Debug.handle();
// Debug.handle();
yield();
}
@@ -149,8 +149,8 @@ bool switchLight(uint8_t nLamp, bool state, bool pub)
String topic = "/home/bigroom/lamp";
char n = nLamp == R_LED1 ? '1' : '2';
//if (pub){
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "true" : "false");
debugI("*Publish State %d-%s, lst1:%d, lst2%d", n, state ? "true" : "false", lStat1, lStat2);
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
// debugI("*Publish State %d-%s, lst1:%d, lst2%d", n, state ? "true" : "false", lStat1, lStat2);
//}
return state;
}
@@ -173,10 +173,10 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
}
void onMqttConnect(bool sessionPresent) {
mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "true" : "false");
mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "true" : "false");
mqttClient.publish("/home/bigroom/lamp1_set", 1, false, lStat1 ? "true" : "false");
mqttClient.publish("/home/bigroom/lamp2_set", 1, false, lStat2 ? "true" : "false");
mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp1_set", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp2_set", 1, false, lStat2 ? "1" : "0");
mqttClient.subscribe("/home/bigroom/lamp1_set", 1);
mqttClient.subscribe("/home/bigroom/lamp2_set", 1);
digitalWrite(B_LED, LOW);
@@ -194,27 +194,27 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
strncpy(s, payload, len);
if(String(topic) == "/home/bigroom/lamp1_set"){
// if (atoi(payload) == 1) switchLight(R_LED1, 1, false);
if (strncmp("true", payload, 4) == 0){
if (strncmp("1", payload, 1) == 0){
switchLight(R_LED1, true, false);
debugI("*Switch from MQTT T1: %s", s);
// debugI("*Switch from MQTT T1: %s", s);
}
//if (atoi(payload) == 1) switchLight(R_LED2, 1, false);
//lStat1 = true;
else{
switchLight(R_LED1, false, false);
debugI("*Switch from MQTT F1: %s", s);
// debugI("*Switch from MQTT F1: %s", s);
}
}
if(String(topic) == "/home/bigroom/lamp2_set"){
if (strncmp("true", payload, 4) == 0){
if (strncmp("1", payload, 1) == 0){
switchLight(R_LED2, true, false);
debugI("*Switch from MQTT T2: %s", s);
// debugI("*Switch from MQTT T2: %s", s);
}
//if (atoi(payload) == 1) switchLight(R_LED2, 1, false);
//lStat1 = true;
else{
switchLight(R_LED2, false, false);
debugI("*Switch from MQTT F2: %s", s);
// debugI("*Switch from MQTT F2: %s", s);
}
}
}