кухня посчледние изменения

master
SmartUaWIn 2021-03-19 23:13:43 +02:00
parent f18723883c
commit 5387d531e0
1 changed files with 44 additions and 44 deletions

View File

@ -1,7 +1,7 @@
/*
Отправка данных на MQTT про обновление
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Preferences.h> //Сохранение настроек хеша прошивки
@ -32,7 +32,7 @@ byte errorID = 0; //Сбор и вывод ошибок
//5
WiFiManager wm; // обьект менеджера
WiFiManagerParameter custom_field;
//WiFiManagerParameter custom_field;
Preferences OTApreferences; //Обьект хранения настроек хеша прошивки
StaticJsonDocument<200> doc;
@ -43,6 +43,7 @@ IPAddress IpMqtt;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "0.ua.pool.ntp.org", 7200, 60000); //Собственно сервер времени смещение и частоат запроса, но он вручную
const char *wmhostname="KitchenWater";
const PROGMEM char *willmess = "{\"conn\":\"err\"}";
const PROGMEM char *mqttHostName = "cctv.automation.art"; //Хостнейм брокера 192.168.89.210 cctv.automation.art:8889
@ -99,8 +100,6 @@ void setup()
// FALLING прерывание будет запущено, если значение на контакте изменится с «HIGH» на «LOW»
// RISING прерывание будет запущено, если значение на контакте изменится с «LOW» на «HIGH»
WiFi.mode(WIFI_STA);
Serial.setDebugOutput(true);
String topicTemp = "aastudio/" + macc + "/data/0";
@ -126,10 +125,10 @@ void setup()
// test custom html input type(checkbox)
// new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\" type=\"checkbox\""); // custom html type
// test custom html(radio)
const char *custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three";
new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input
wm.addParameter(&custom_field);
wm.setSaveParamsCallback(saveParamCallback);
//const char *custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three";
//new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input
//wm.addParameter(&custom_field);
//wm.setSaveParamsCallback(saveParamCallback);
// custom menu via array or vector
// menu tokens, "wifi","wifinoscan","info","param","close","sep","erase","restart","exit" (sep is seperator) (if param is in menu, params will not show up in wifi page!)
// const char* menu[] = {"wifi","info","param","sep","restart","exit"};
@ -137,36 +136,38 @@ void setup()
std::vector<const char *> menu = {"wifi", "info", "param", "sep", "restart", "exit"};
wm.setMenu(menu);
// set dark theme
wm.setClass("invert");
wm.setClass("invert");
//set static ip
// wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn
// wm.setShowStaticFields(true); // force show static ip fields
// wm.setShowDnsFields(true); // force show dns field always
// wm.setConnectTimeout(20); // how long to try to connect for before continuing
wm.setConfigPortalTimeout(60); // auto close configportal after n seconds
// wm.setConfigPortalTimeout(60); // auto close configportal after n seconds
// wm.setCaptivePortalEnable(false); // disable captive portal redirection
// wm.setAPClientCheck(true); // avoid timeout if client connected to softap
// wifi scan settings
// wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true)
wm.setMinimumSignalQuality(10); // set min RSSI (percentage) to show in scans, null = 8%
// wm.setShowInfoErase(false); // do not show erase button on info page
// wm.setScanDispPerc(true); // show RSSI as percentage not graph icons
wm.setScanDispPerc(true); // show RSSI as percentage not graph icons
// wm.setBreakAfterConfig(true); // always exit configportal even if wifi save fails
wm.setWiFiAutoReconnect(true); // if true, enable autoreconnecting
// wm.setWiFiAutoReconnect(true); // if true, enable autoreconnecting
// wm.setConfigPortalBlocking(false);
wm.setHostname(wmhostname);
wm.setConfigPortalBlocking(false);
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("KitchenM5Portal", "12345678"); // Подключение к анонимной точке доступа
if (!res)
{
Serial.println("Failed to connect or hit timeout");
//ESP.restart();
}
else
{
Serial.println("connected - OK");
}
// res = wm.autoConnect("KitchenM5Portal", "12345678");
// if (!res)
// {
// Serial.println("Failed to connect or hit timeout");
// //ESP.restart();
// }
// else
// {
// Serial.println("connected - OK");
// }
//Запрос IP сервера MQTT и установка сервера
setMqttServer();
@ -241,7 +242,11 @@ void checkButton()
disconnectMQTT();
wm.resetSettings();
ESP.restart();
//
wm.startConfigPortal();
// ESP.restart();
}
String getParam(String name)
@ -254,12 +259,6 @@ String getParam(String name)
return value;
}
void saveParamCallback()
{
//Serial.\println("[CALLBACK] saveParamCallback fired");
//Serial.\println("PARAM customfieldid = " + getParam("customfieldid"));
getParam("customfieldid");
}
//Обновление прошивки, происходит проверка и загрузка
//Делается Get запрос на хостинг проверяется хеш, если хеш
@ -410,7 +409,7 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
if (sendStatus == true)
{
char *conn;
const char *conn;
switch (statusConn)
{
@ -556,8 +555,8 @@ void loop()
}
// 40 секунд и происходит сброс настроек WIFI
if (M5.Btn.wasReleasefor(40000))
{
if (M5.Btn.wasReleasefor(10000))
{
checkButton();
}
@ -577,8 +576,9 @@ void loop()
}
//Таймер отправки данных в брокер
MqttClient.loop();
wm.process();
}
int disconnectMQTT()
@ -607,15 +607,15 @@ int buzAlarm(bool buzFlag)
Serial.println(buzFlag);
if (buzFlag == true)
{
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);
delay(100);
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
delay(200);
{
// digitalWrite(buzzerPin, HIGH);
// delay(100);
// digitalWrite(buzzerPin, LOW);
// delay(100);
// digitalWrite(buzzerPin, HIGH);
// delay(200);
// digitalWrite(buzzerPin, LOW);
// delay(200);
}
else
{