Add reciever power
This commit is contained in:
33
ESP_MidRoom/include/html.h
Normal file
33
ESP_MidRoom/include/html.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
const char index_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html>
|
||||
<head>
|
||||
<title>ESP Web Server</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="data:,">
|
||||
<style>
|
||||
html {font-family: Arial; display: inline-block; text-align: center;}
|
||||
h2 {font-size: 3.0rem;}
|
||||
p {font-size: 3.0rem;}
|
||||
body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}
|
||||
.switch {position: relative; display: inline-block; width: 120px; height: 68px}
|
||||
.switch input {display: none}
|
||||
.slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 6px}
|
||||
.slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 3px}
|
||||
input:checked+.slider {background-color: #b30000}
|
||||
input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>ESP Web Server</h2>
|
||||
%BUTTONPLACEHOLDER%
|
||||
<script>function toggleCheckbox(element) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
if(element.checked){ xhr.open("GET", "/update?output="+element.id+"&state=1", true); }
|
||||
else { xhr.open("GET", "/update?output="+element.id+"&state=0", true); }
|
||||
xhr.send();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
@@ -2,6 +2,9 @@
|
||||
#include <ArduinoOTA.h>
|
||||
#include <Ticker.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WebSerial.h>
|
||||
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <MHZ19.h>
|
||||
|
||||
@@ -23,5 +23,7 @@ lib_deps =
|
||||
jwrw/ESP_EEPROM @ ^2.0.0
|
||||
robtillaart/RunningMedian @ ^0.3.3
|
||||
crankyoldgit/IRremoteESP8266 @ ^2.8.2
|
||||
ayushsharma82/WebSerial @ ^1.3.0
|
||||
ottowinter/ESPAsyncWebServer-esphome @ ^3.0.0
|
||||
;joaolopesf/RemoteDebug @ 3.0.5
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user