Add reciever power

This commit is contained in:
2022-10-15 12:19:44 +03:00
parent 0aab4963c4
commit 5a1b30658d
6 changed files with 76 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ const char* mqtt_server = "192.168.1.111";
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
AsyncWebServer server(80);
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
@@ -105,7 +106,7 @@ void setup() {
}
//Serial1.println();
mhz19.begin(Serial);
mhz19.autoCalibration();
//mhz19.autoCalibration();
Wire.begin();
bool status = bme.begin(BME280_ADDRESS_ALTERNATE);
if (!status) {
@@ -138,6 +139,9 @@ void setup() {
cRun = millis();
cRunADC = millis();
firstRun = true;
WebSerial.begin(&server);
server.begin();
//Serial1.println(F("Start Loop"));
//(R_LED, HIGH);
}
@@ -155,6 +159,7 @@ void loop() {
if(mvDelay == -1){
g_led.start();
mqttClient.publish(TOPIC"/move", 1, false, "1");
WebSerial.println("Move On");
}
mvDelay = mvDelaySet;
}
@@ -187,12 +192,16 @@ void loop() {
if(mvDelay == 0) {
g_led.start();
mqttClient.publish(TOPIC"/move", 1, false, "0");
WebSerial.println("Move Off");
mvDelay = -1;
}
if(mvDelay > 0) mvDelay--;
if(minCnt % 10 == 0){
if(minCnt % 5 == 0){
co2 = mhz19.getCO2();
char s[20];
sprintf(s, "Ms=%lu,co2=%d", millis(), co2);
WebSerial.println(s);
// /* Serial1.print("CO2: ");
// Serial1.println(co2); */
// // Serial.println("Measure BME");
@@ -249,7 +258,7 @@ void loop() {
//Serial1.println("Publish2");
if(firstRun){
stDelay++;
if(stDelay > 3) firstRun = false;
if(stDelay > 2) firstRun = false;
}
if(!firstRun && (mhz19.errorCode == RESULT_OK)){
itoa(co2, v, 10);
@@ -345,6 +354,7 @@ void onMqttConnect(bool sessionPresent) {
mqttClient.subscribe(TOPIC"/ac/eco", 1);
mqttClient.publish(TOPIC"/ac/state", 1, false, ac.getPower() ? "1" : "0");
mqttClient.subscribe(TOPIC"/ac/state", 1);
mqttClient.subscribe(TOPIC"/co2cal", 1);
// ultoa(ESP.getFlashChipSize(), v, 10);
// mqttClient.publish(TOPIC"/chipsize", 1, false, v);
// ultoa(ESP.getFlashChipRealSize(), v, 10);
@@ -436,6 +446,12 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
else ac.setTurbo(false);
ac.send();
}
if(strcmp(topic, TOPIC"/co2cal") == 0){
char m = payload[0];
if(m == '1'){
mhz19.calibrate();
}
}
b_led.start();
}
/*