Крайний код 35 версия

master
SmartUaWIn 2021-03-26 16:14:14 +02:00
parent cb0938fa50
commit 46a1131229
5 changed files with 94 additions and 70 deletions

BIN
31.bin Normal file

Binary file not shown.

BIN
32.bin Normal file

Binary file not shown.

BIN
33.bin Normal file

Binary file not shown.

View File

@ -17,6 +17,14 @@
24A160474D14
24A160542B80
Белая 2B80
Шумная 38CC
У вас 23AC
Офис 5450
Кухня 4D41
***************************************************************************/
#include "esp_sleep.h"
@ -47,7 +55,7 @@
#define CCS811_ADDR 0x5B //Default I2C Address
//#define CCS811_ADDR 0x5A //Alternate I2C Address
unsigned int VersionSW = 30; //65536 Версия прошивки
unsigned int VersionSW = 35; //65536 Версия прошивки
//15 - добавлено то, се, забыл вообще дописать что добавленоSerial
//19 - вывод в консоль всех действий, ошибки с обновлнеием - починил, прияногое мигание светодиодом, тест для поиска metrics.
@ -59,8 +67,13 @@ unsigned int VersionSW = 30; //65536 Версия прошивки
//26 - тест обновления сука - работает
//27 - таймаут станции без wifi 40 сек
//28 - калибровка вернулась
//29 - baseline выведен и отключен
//30 - новое освещение оранжевый цвет
//29 - baseline выведен и отключен
//30 - новое освещение оранжевый цвет
//31 - фиксим время
//32 - рестарт без wifi
//33 - бейслайн и куча изменений по переподключению mqtt
//34 - правка с опросом, бесконечный цикл
//35 - закоменчен вывод ошибок available
gpio_num_t pinWak = GPIO_NUM_23;
@ -78,11 +91,10 @@ PubSubClient MqttClient(espClient);
IPAddress IpMqtt;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "0.ua.pool.ntp.org", 7200, 60000); //Собственно сервер времени смещение и частоат запроса, но он вручную
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 60000); //Собственно сервер времени смещение и частоат запроса, но он вручную
const PROGMEM char *willmess = "{\"conn\":\"err\"}";
const char *mqttHostName = "metrics"; //Хостнейм брокера metrics.local cctv.automation.art //192.168.89.210
unsigned int mqttPort = 1883; //Порт брокера 1883 8889
unsigned int mqttPort = 1883; //Порт брокера 1883 8889
String getMacAddress();
String macc = getMacAddress();
@ -102,7 +114,7 @@ int PROGMEM nextReqSensor = 10000; //опрос датчиков раз в 10 с
int PROGMEM nextMqttSend = 60000; //Отправка
float TempAv, HumAv, Eco2Av, TvocAv;
unsigned int BaselineTvoc=0;
unsigned int BaselineTvoc = 0;
byte errorID = 0;
long rssi = 0;
byte idxT = 0, idxH = 0, idxECO = 0, idxTVOC = 0;
@ -117,16 +129,16 @@ void ledset(byte color = 0, bool blink = false)
switch (color)
{
case 2:
M5.dis.drawpix(0, 0xf00000); //Зеленый
M5.dis.drawpix(0, 0xf00000); //Зеленый
break;
case 1:
M5.dis.drawpix(0, 0x00ff00); //Красный
M5.dis.drawpix(0, 0x00ff00); //Красный
break;
case 3:
M5.dis.drawpix(0, 0x0000ff); //Синий
M5.dis.drawpix(0, 0x0000ff); //Синий
break;
case 4:
M5.dis.drawpix(0, 0x707070); //Белый
M5.dis.drawpix(0, 0x707070); //Белый
break;
default:
M5.dis.clear();
@ -139,7 +151,7 @@ void setup()
{
Serial.begin(115200);
// Serial.setDebugOutput(true);
Serial.setDebugOutput(true);
btStop();
// esp_bt_controller_disable();
@ -161,8 +173,8 @@ void setup()
ledset(1, true);
}
//ccs.setTempOffset(8.6);
// ccs.setBaseline(21634);
//ccs.setTempOffset(8.6);
ccs.setBaseline(25725);
//Установка коеффициентов каллибровки по MAC адресу
// SetCallibrationCoeff();
@ -247,16 +259,16 @@ int reqNtpTime()
if (timeClient.update())
{
uint32_t timeEpoch = timeClient.getEpochTime();
setTime(timeEpoch);
Serial.print(timeEpoch);
Serial.print(" <=ntp== ==device=> ");
Serial.println(now());
if (timeEpoch < 100000)
if (timeEpoch < 1000000)
{
Serial.println("Error Time");
}
setTime(timeEpoch);
// Serial.print(timeEpoch);
// Serial.print(" <=ntp== ==device=> ");
// Serial.println(now());
}
return 0;
@ -287,7 +299,7 @@ int checkButton()
void OTAUpdate()
{
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!OTAUpdate() START!!!!!!!!!!!!!!!!!!!!!!!!!!");
Serial.println("!!!OTAUpdate() START!!!!");
bool flagOTA = false;
String keyOTA;
String payload;
@ -351,7 +363,6 @@ void OTAUpdate()
if (flagOTA == true)
{
// flagOTA = false;
disconnectMQTT();
ESPhttpUpdate.rebootOnUpdate(true);
@ -460,34 +471,39 @@ void reqSensorData()
TempAv = atof(outstr);
dtostrf(hdc1080Hum, 5, 2, outstr);
HumAv = atof(outstr);
for (int g = 0; g <= 5; g++)
for (int g = 0; g <= 7; g++)
{
delay(1000);
if (ccs.available())
while (!ccs.available())
{
if (!ccs.readData())
{
ccs.setEnvironmentalData(hdc1080Hum-55,hdc1080Temp-25);
eco2 = ccs.geteCO2();
tvoc = ccs.getTVOC();
BaselineTvoc=ccs.getBaseline();
Serial.println(eco2);
Serial.println(tvoc);
}
else
{
Serial.println("==========ECO TVOC NONE READ");
}
// Serial.println("ccs.NONE available()");
}
if (!ccs.readData())
{
ccs.setEnvironmentalData(hdc1080Hum - 55, hdc1080Temp - 25);
eco2 = ccs.geteCO2();
tvoc = ccs.getTVOC();
BaselineTvoc = ccs.getBaseline();
Serial.print(eco2);
Serial.print(" ");
Serial.print(tvoc);
Serial.print(" ");
Serial.println(BaselineTvoc);
}
else
{
eco2 = 0;
tvoc = 0;
Serial.println("==========ECO TVOC NONE AVAILABLE");
errorID = 5;
Serial.println("==========ECO TVOC NONE READ");
}
// else
// {
// eco2 = 0;
// tvoc = 0;
// Serial.println("==========ECO TVOC NONE AVAILABLE");
// errorID = 5;
// delay(1000);
// }
}
Eco2Av = eco2;
@ -500,6 +516,8 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
{
if (mqttSendFlag == true)
{
ledset(2, true);
char resultString[200];
String JsonData = "";
rssi = WiFi.RSSI();
@ -511,20 +529,20 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
doc["h"] = HumAv;
doc["eco"] = (int)Eco2Av;
doc["tvoc"] = (int)TvocAv;
doc["blt"]= BaselineTvoc;
doc["blt"] = BaselineTvoc;
if (macc == "24A1605423AC")
{
{
doc["ligh"] = (int)map(analogRead(33), 0, 4095, 0, 100);
}
doc["ts"] = timeNow;
serializeJson(doc, JsonData);
doc.remove("t");
doc.remove("t");
doc.remove("h");
doc.remove("eco");
doc.remove("tvoc");
doc.remove("blt");
doc.remove("blt");
if (macc == "24A1605423AC")
{
@ -557,6 +575,10 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
conn = "slp";
break;
case 4:
conn = "upd";
break;
default:
break;
}
@ -589,7 +611,7 @@ void reconnectMqtt()
Serial.print("MQTT reconnect...");
circle++;
if (circle == 2)
if (circle == 7)
{
break;
}
@ -607,9 +629,9 @@ void reconnectMqtt()
}
else
{
////Serial.print("MqttClient.state() = ");
////Serial.println(MqttClient.state());
/*
Serial.print("MqttClient.state() = ");
Serial.println(MqttClient.state());
/*
-4 : MQTT_CONNECTION_TIMEOUT - the server didn't respond within the keepalive time
-3 : MQTT_CONNECTION_LOST - the network connection was broken
-2 : MQTT_CONNECT_FAILED - the network connection failed
@ -622,7 +644,7 @@ void reconnectMqtt()
5 : MQTT_CONNECT_UNAUTHORIZED - the client was not authorized to connect
*/
mqttSendFlag = false;
delay(1000);
delay(500);
}
}
}
@ -635,50 +657,52 @@ void loop()
if (!MqttClient.connected())
{
reconnectMqtt();
ledset(1, true);
}
if (countOta >= 10)
{
// reqNtpTime();
OTAUpdate();
countOta = 0;
}
countOta++;
MqttClient.loop();
reqSensorData();
SetCallibrationCoeff(macc);
SendMqttReq(true, true, 3);
MqttClient.loop();
disconnectMQTT();
delay(500);
if (M5.Btn.pressedFor(1000))
{
ledset(4, true);
checkButton();
}
if (countOta >= 10)
{
// reqNtpTime();
countOta = 0;
SendMqttReq(false, true, 4);
OTAUpdate();
SendMqttReq(false, true, 1);
}
countOta++;
goToSleep();
}
int disconnectMQTT()
{
MqttClient.disconnect();
MqttClient.disconnect();
return 0;
}
int goToSleep()
{
ledset(3, true);
disconnectMQTT();
delay(500);
WiFi.disconnect(true);
delay(50);
WiFi.mode(WIFI_OFF);
delay(50);
esp_wifi_stop();
delay(100);
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
delay(100);
esp_deep_sleep_start();
}

Binary file not shown.