Removed comments
This commit is contained in:
@@ -9,15 +9,7 @@ BME280::PresUnit presUnit(BME280::PresUnit_Pa);
|
|||||||
|
|
||||||
LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
||||||
|
|
||||||
//Adafruit_BME280 bme280; // use I2C interface
|
|
||||||
//Adafruit_Sensor *bme_temp = bme280.getTemperatureSensor();
|
|
||||||
//Adafruit_Sensor *bme_pressure = bme280.getPressureSensor();
|
|
||||||
//Adafruit_Sensor *bme_humidity = bme280.getHumiditySensor();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
//PubSubClient client(espClient);
|
|
||||||
|
|
||||||
Bounce butt = Bounce();
|
Bounce butt = Bounce();
|
||||||
|
|
||||||
@@ -25,9 +17,6 @@ float tempC;
|
|||||||
char f[4];
|
char f[4];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Serial.begin(9600);
|
|
||||||
//Serial.println("Booting"); // "Загрузка"
|
|
||||||
|
|
||||||
pinMode(RED, OUTPUT);
|
pinMode(RED, OUTPUT);
|
||||||
pinMode(GREEN, OUTPUT);
|
pinMode(GREEN, OUTPUT);
|
||||||
pinMode(BLUE, OUTPUT);
|
pinMode(BLUE, OUTPUT);
|
||||||
@@ -45,7 +34,6 @@ void setup() {
|
|||||||
//Serial.print(error);
|
//Serial.print(error);
|
||||||
|
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
//Serial.println(": LCD found.");
|
|
||||||
lcd.begin(16, 2); // initialize the lcd
|
lcd.begin(16, 2); // initialize the lcd
|
||||||
lcd.clear();
|
lcd.clear();
|
||||||
lcd.setBacklight(255);
|
lcd.setBacklight(255);
|
||||||
@@ -57,18 +45,6 @@ void setup() {
|
|||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.hostname("ESP-Kuh");
|
WiFi.hostname("ESP-Kuh");
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// WiFi.begin(ssid, password);
|
|
||||||
// while (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
|
||||||
// //Serial.println("Connection Failed! Rebooting...");
|
|
||||||
// // "Соединиться не удалось! Перезагрузка..."
|
|
||||||
// delay(5000);
|
|
||||||
// ESP.restart();
|
|
||||||
// }
|
|
||||||
// lcd.setCursor(0, 0);
|
|
||||||
// lcd.print("Connected");
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
|
|
||||||
ArduinoOTA.onStart([]() { /*Serial.println("Start");*/}); // "Начало OTA-апдейта"
|
ArduinoOTA.onStart([]() { /*Serial.println("Start");*/}); // "Начало OTA-апдейта"
|
||||||
ArduinoOTA.onEnd([]() { /*Serial.println("\nEnd");*/}); // "Завершение OTA-апдейта"
|
ArduinoOTA.onEnd([]() { /*Serial.println("\nEnd");*/}); // "Завершение OTA-апдейта"
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { /*Serial.printf("Progress: %u%%\r", (progress / (total / 100)));*/ });
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { /*Serial.printf("Progress: %u%%\r", (progress / (total / 100)));*/ });
|
||||||
@@ -82,10 +58,6 @@ void setup() {
|
|||||||
});
|
});
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
//Serial.println("Ready"); // "Готово"
|
|
||||||
//Serial.print("IP address: "); // "IP-адрес: "
|
|
||||||
//Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
bme.begin();
|
bme.begin();
|
||||||
|
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
@@ -96,31 +68,24 @@ void setup() {
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
lcd.print("Measure done... ");
|
lcd.print("Measure done... ");
|
||||||
//tempOut = sensors.getTempCByIndex(0);
|
|
||||||
tempOut = sensors.getTempC(da[0]);
|
tempOut = sensors.getTempC(da[0]);
|
||||||
if (tempOut == DEVICE_DISCONNECTED_C){
|
if (tempOut == DEVICE_DISCONNECTED_C){
|
||||||
tempOut = NAN;
|
tempOut = NAN;
|
||||||
stat[0] = 0;
|
stat[0] = 0;
|
||||||
}
|
}
|
||||||
else stat[0] = 1;
|
else stat[0] = 1;
|
||||||
//delay(100);
|
|
||||||
//tempHol = sensors.getTempCByIndex(1);
|
|
||||||
tempHol = sensors.getTempC(da[1]);
|
tempHol = sensors.getTempC(da[1]);
|
||||||
if (tempHol == DEVICE_DISCONNECTED_C){
|
if (tempHol == DEVICE_DISCONNECTED_C){
|
||||||
tempHol = NAN;
|
tempHol = NAN;
|
||||||
stat[1] = 0;
|
stat[1] = 0;
|
||||||
}
|
}
|
||||||
else stat[1] = 1;
|
else stat[1] = 1;
|
||||||
//delay(100);
|
|
||||||
//tempHoM = sensors.getTempCByIndex(2);
|
|
||||||
tempHoM = sensors.getTempC(da[2]);
|
tempHoM = sensors.getTempC(da[2]);
|
||||||
if (tempHoM == DEVICE_DISCONNECTED_C){
|
if (tempHoM == DEVICE_DISCONNECTED_C){
|
||||||
tempHoM = NAN;
|
tempHoM = NAN;
|
||||||
stat[2] = 0;
|
stat[2] = 0;
|
||||||
}
|
}
|
||||||
else stat[2] = 1;
|
else stat[2] = 1;
|
||||||
//delay(100);
|
|
||||||
//tempMor = sensors.getTempCByIndex(3);
|
|
||||||
tempMor = sensors.getTempC(da[3]);
|
tempMor = sensors.getTempC(da[3]);
|
||||||
if (tempMor == DEVICE_DISCONNECTED_C){
|
if (tempMor == DEVICE_DISCONNECTED_C){
|
||||||
tempMor = NAN;
|
tempMor = NAN;
|
||||||
@@ -128,30 +93,17 @@ void setup() {
|
|||||||
}
|
}
|
||||||
else stat[3] = 1;
|
else stat[3] = 1;
|
||||||
|
|
||||||
//client.setServer(mqtt_server, 1883);
|
|
||||||
//client.setCallback(callback);
|
|
||||||
|
|
||||||
EEPROM.begin(64);
|
EEPROM.begin(64);
|
||||||
EEPROM.get(0, lightData);
|
EEPROM.get(0, lightData);
|
||||||
|
|
||||||
lightSP = lightData.SP;
|
lightSP = lightData.SP;
|
||||||
lightDB = lightData.DB;
|
lightDB = lightData.DB;
|
||||||
/*lightData.DB = 20;
|
|
||||||
lightData.SP = 100;
|
|
||||||
EEPROM.put(0, lightData);
|
|
||||||
EEPROM.commit();*/
|
|
||||||
|
|
||||||
minCount = 0;
|
minCount = 0;
|
||||||
LCDpage = 0;
|
LCDpage = 0;
|
||||||
lightOn = false;
|
lightOn = false;
|
||||||
mv = prMV = digitalRead(MOVE_S);
|
mv = prMV = digitalRead(MOVE_S);
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// if (!client.connected()) {
|
|
||||||
// reconnect();
|
|
||||||
// }
|
|
||||||
// if (client.connected())
|
|
||||||
// client.publish("/home/kuh/move", String(mv).c_str());
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
|
||||||
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
|
||||||
|
|
||||||
@@ -162,10 +114,8 @@ void setup() {
|
|||||||
mqttClient.setClientId("ESPKuh");
|
mqttClient.setClientId("ESPKuh");
|
||||||
|
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
|
|
||||||
crun = millis();
|
crun = millis();
|
||||||
// bmeread = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -188,19 +138,11 @@ void loop() {
|
|||||||
//mv = true;
|
//mv = true;
|
||||||
lcd.setBacklight(255);
|
lcd.setBacklight(255);
|
||||||
mqttClient.publish("/home/kuh/move", 1, false, "1");
|
mqttClient.publish("/home/kuh/move", 1, false, "1");
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// if (client.connected())
|
|
||||||
// client.publish("/home/kuh/move", String(mv).c_str());
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//mv = false;
|
//mv = false;
|
||||||
lcd.setBacklight(0);
|
lcd.setBacklight(0);
|
||||||
mqttClient.publish("/home/kuh/move", 1, false, "0");
|
mqttClient.publish("/home/kuh/move", 1, false, "0");
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// if (client.connected())
|
|
||||||
// client.publish("/home/kuh/move", String(mv).c_str());
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
}
|
}
|
||||||
prMV = mv;
|
prMV = mv;
|
||||||
}
|
}
|
||||||
@@ -244,44 +186,26 @@ void loop() {
|
|||||||
|
|
||||||
void showLCD(int page, bool l_on)
|
void showLCD(int page, bool l_on)
|
||||||
{
|
{
|
||||||
//char s[5];
|
|
||||||
char outS[20];
|
char outS[20];
|
||||||
//String s1, s2;
|
|
||||||
/*if(l_on) lcd.setBacklight(255);
|
|
||||||
else lcd.setBacklight(0);*/
|
|
||||||
switch (page)
|
switch (page)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
//s1 = String(tempOut, 1);
|
|
||||||
//s2 = String(tempIn, 1);
|
|
||||||
|
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
//snprintf(outS, 17, "O:%5sC I:%4sC ", s1.c_str(), s2.c_str());
|
|
||||||
lcd.printf("O:%5.1fC I:%4.1fC ", tempOut, tempIn);
|
lcd.printf("O:%5.1fC I:%4.1fC ", tempOut, tempIn);
|
||||||
lcd.setCursor(0, 1);
|
lcd.setCursor(0, 1);
|
||||||
//s1 = String(hum, 1);
|
|
||||||
//s2 = String(press, 0);
|
|
||||||
//snprintf(outS, 17, "H:%4s%% Pr:%3smm", s1.c_str(), s2.c_str());
|
|
||||||
lcd.printf("H:%4.1f%% Pr:%3.0fmm", hum, press);
|
lcd.printf("H:%4.1f%% Pr:%3.0fmm", hum, press);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//s1 = String(tempHol, 1);
|
|
||||||
//s2 = String(tempHoM, 1);
|
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
//snprintf(outS, 17, "H:%4sC M:%5sC ", s1.c_str(), s2.c_str());
|
|
||||||
lcd.printf("H:%4.1fC M:%5.1fC ", tempHol, tempHoM);
|
lcd.printf("H:%4.1fC M:%5.1fC ", tempHol, tempHoM);
|
||||||
//s1 = String(tempMor, 1);
|
|
||||||
lcd.setCursor(0, 1);
|
lcd.setCursor(0, 1);
|
||||||
//snprintf(outS, 17, "Mor:%5sC ", s1.c_str());
|
|
||||||
lcd.printf("Mor:%5.1fC ", tempMor);
|
lcd.printf("Mor:%5.1fC ", tempMor);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
//snprintf(outS, 17, "L: %3d SP: %3d ", adc, lightSP);
|
|
||||||
lcd.printf("L: %3d SP: %3d ", adc, lightSP);
|
lcd.printf("L: %3d SP: %3d ", adc, lightSP);
|
||||||
lcd.print(outS);
|
lcd.print(outS);
|
||||||
lcd.setCursor(0, 1);
|
lcd.setCursor(0, 1);
|
||||||
//snprintf(outS, 17, "DB: %2d MS: %1d L:%1d", lightDB, mv, lightOn);
|
|
||||||
lcd.printf("DB: %2u MS: %1u L:%1d", lightDB, mv, lightOn);
|
lcd.printf("DB: %2u MS: %1u L:%1d", lightDB, mv, lightOn);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@@ -295,43 +219,8 @@ void showLCD(int page, bool l_on)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void callback(char* topic, byte* message, unsigned int length) {
|
|
||||||
// bool w = false;
|
|
||||||
// //Serial.print("Message arrived on topic: ");
|
|
||||||
// // "Сообщение прибыло в топик: "
|
|
||||||
// //Serial.print(topic);
|
|
||||||
// //Serial.print(". Message: "); // ". Сообщение: "
|
|
||||||
// String messageTemp;
|
|
||||||
|
|
||||||
// for (unsigned int i = 0; i < length; i++) {
|
|
||||||
// //Serial.print((char)message[i]);
|
|
||||||
// messageTemp += (char)message[i];
|
|
||||||
// }
|
|
||||||
// if(strcmp(topic, "/home/kuh/light_sp_set") == 0){
|
|
||||||
// lightSP = messageTemp.toInt();
|
|
||||||
// w = true;
|
|
||||||
// }
|
|
||||||
// if(strcmp(topic, "/home/kuh/light_db_set") == 0){
|
|
||||||
// lightDB = messageTemp.toInt();
|
|
||||||
// w = true;
|
|
||||||
// }
|
|
||||||
// if(w){
|
|
||||||
// lightData.SP = lightSP;
|
|
||||||
// lightData.DB = lightDB;
|
|
||||||
// EEPROM.put(0, lightData);
|
|
||||||
// EEPROM.commit();
|
|
||||||
// }
|
|
||||||
// Serial.println();
|
|
||||||
// }
|
|
||||||
|
|
||||||
void publishSec()
|
void publishSec()
|
||||||
{
|
{
|
||||||
// if (!client.connected()) {
|
|
||||||
// reconnect();
|
|
||||||
// }
|
|
||||||
// if(!client.loop())
|
|
||||||
// client.connect("ESPKuh");
|
|
||||||
// if (client.connected()) {
|
|
||||||
digitalWrite(GREEN, HIGH);
|
digitalWrite(GREEN, HIGH);
|
||||||
dtostrf(tempOut, 6, 1, strFVal);
|
dtostrf(tempOut, 6, 1, strFVal);
|
||||||
mqttClient.publish("/hometest/kuh1s/temp_out", 1, false, strFVal);
|
mqttClient.publish("/hometest/kuh1s/temp_out", 1, false, strFVal);
|
||||||
@@ -357,12 +246,6 @@ void publishSec()
|
|||||||
|
|
||||||
void publishMin()
|
void publishMin()
|
||||||
{
|
{
|
||||||
// if (!client.connected()) {
|
|
||||||
// reconnect();
|
|
||||||
// }
|
|
||||||
// if(!client.loop())
|
|
||||||
// client.connect("ESPKuh");
|
|
||||||
// if (client.connected()) {
|
|
||||||
digitalWrite(BLUE, HIGH);
|
digitalWrite(BLUE, HIGH);
|
||||||
if(!isnan(tempOut)){
|
if(!isnan(tempOut)){
|
||||||
dtostrf(tempOut, 6, 1, strFVal);
|
dtostrf(tempOut, 6, 1, strFVal);
|
||||||
@@ -400,32 +283,9 @@ void publishMin()
|
|||||||
}
|
}
|
||||||
ultoa(crun, strFVal, 10);
|
ultoa(crun, strFVal, 10);
|
||||||
mqttClient.publish("/home/kuh/millis", 1, false, strFVal);
|
mqttClient.publish("/home/kuh/millis", 1, false, strFVal);
|
||||||
// digitalWrite(BLUE, LOW);
|
digitalWrite(BLUE, LOW);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void reconnect() {
|
|
||||||
// digitalWrite(RED, HIGH);
|
|
||||||
// //Serial.print("Attempting MQTT connection...");
|
|
||||||
// // "Попытка подключиться к MQTT-брокеру... "
|
|
||||||
// // Пытаемся подключиться:
|
|
||||||
// if (client.connect("ESPKuh")) {
|
|
||||||
// //Serial.println("connected"); // "подключен"
|
|
||||||
// // подписываемся или переподписываемся на топик;
|
|
||||||
// // можно подписаться не только на один, а на несколько топиков
|
|
||||||
// client.subscribe("/home/kuh/light_sp_set");
|
|
||||||
// client.subscribe("/home/kuh/light_db_set");
|
|
||||||
// client.publish("/home/kuh/light_db_set", String(lightData.DB).c_str());
|
|
||||||
// client.publish("/home/kuh/light_sb_set", String(lightData.SP).c_str());
|
|
||||||
// } else {
|
|
||||||
// //Serial.print("failed, rc="); // "подключение не удалось"
|
|
||||||
// //Serial.print(client.state());
|
|
||||||
// //Serial.println(" try again in 5 seconds");
|
|
||||||
// }
|
|
||||||
// delay(100);
|
|
||||||
// digitalWrite(RED, LOW);
|
|
||||||
// }
|
|
||||||
|
|
||||||
void getTemp()
|
void getTemp()
|
||||||
{
|
{
|
||||||
static bool readTemp = false;
|
static bool readTemp = false;
|
||||||
@@ -436,10 +296,6 @@ void getTemp()
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
float t = sensors.getTempC(da[nSens]);//ByIndex(nSens);
|
float t = sensors.getTempC(da[nSens]);//ByIndex(nSens);
|
||||||
//float t = sensors.getTempCByIndex(nSens);
|
|
||||||
//Serial.print(nSens);
|
|
||||||
//Serial.print(" Temp readed=");
|
|
||||||
//Serial.println(t);
|
|
||||||
if ((t > -127) && (t < 85)){
|
if ((t > -127) && (t < 85)){
|
||||||
stat[nSens] = 1;
|
stat[nSens] = 1;
|
||||||
switch(nSens){
|
switch(nSens){
|
||||||
|
|||||||
Reference in New Issue
Block a user