From 8c3ac9e31e98008e84b3881fe1cf15b6611df9ee Mon Sep 17 00:00:00 2001 From: SmartUbuntu Date: Tue, 31 Aug 2021 14:56:12 +0300 Subject: [PATCH] anemoststt norm + spiffs --- anemostat/anemostat/.vscode/extensions.json | 14 +-- anemostat/anemostat/min_spiffs.csv | 6 ++ anemostat/anemostat/platformio.ini | 3 +- anemostat/anemostat/src/main.cpp | 96 ++++++++++++--------- 4 files changed, 69 insertions(+), 50 deletions(-) create mode 100644 anemostat/anemostat/min_spiffs.csv diff --git a/anemostat/anemostat/.vscode/extensions.json b/anemostat/anemostat/.vscode/extensions.json index e80666b..0f0d740 100644 --- a/anemostat/anemostat/.vscode/extensions.json +++ b/anemostat/anemostat/.vscode/extensions.json @@ -1,7 +1,7 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/anemostat/anemostat/min_spiffs.csv b/anemostat/anemostat/min_spiffs.csv new file mode 100644 index 0000000..0b6a9ff --- /dev/null +++ b/anemostat/anemostat/min_spiffs.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x1E0000, +app1, app, ota_1, 0x1F0000,0x1E0000, +spiffs, data, spiffs, 0x3D0000,0x30000, diff --git a/anemostat/anemostat/platformio.ini b/anemostat/anemostat/platformio.ini index acf0330..830a64b 100644 --- a/anemostat/anemostat/platformio.ini +++ b/anemostat/anemostat/platformio.ini @@ -12,4 +12,5 @@ platform = espressif32 board = m5stack-atom framework = arduino -lib_extra_dirs = C:\Users\38093\Documents\Arduino\libraries +lib_extra_dirs = /home/smart/Arduino/libraries +board_build.partitions = min_spiffs.csv \ No newline at end of file diff --git a/anemostat/anemostat/src/main.cpp b/anemostat/anemostat/src/main.cpp index e05f038..0127ea6 100644 --- a/anemostat/anemostat/src/main.cpp +++ b/anemostat/anemostat/src/main.cpp @@ -1,3 +1,17 @@ +//{"amount":40} +//1 офис +//aastudio/act/94B97EACF00C/set/0 + +//2белая +// 14:06:40.942 -> aastudio/act/24A160461D08/set/0 +// 14:06:40.942 -> aastudio/act/24A160461D08/data/0 +// 14:06:40.975 -> aastudio/act/24A160461D08/status + +//3 кухня +// 19:38:23.635 -> aastudio/act/94B97E929DE0/set/0 +// 19:38:23.669 -> aastudio/act/94B97E929DE0/data/0 +// 19:38:23.669 -> aastudio/act/94B97E929DE0/status + #include // https://github.com/tzapu/WiFiManager #include //Сохранение настроек хеша прошивки #include @@ -16,11 +30,11 @@ #define Resist 33 #define TRIGGER_PIN 39 -unsigned int VersionSW = 4; - - +unsigned int VersionSW = 7; //3 - Первый код для анемостата +// 5 - перед установкой +//7 - выполнение команд последовательно WiFiManager wm; // обьект менеджера Preferences OTApreferences; //Обьект хранения настроек хеша прошивки @@ -45,7 +59,7 @@ String setTopic = "aastudio/act/" + macc + "/set/0"; String willTopicTemp = "aastudio/act/" + macc + "/status"; const PROGMEM char *mqttLogin = "AA_Lab", *mqttPass = "automation.art$"; -byte setPercent = 0, setSpeedAnemo = 0; +byte setPercent = 0, prevPercent=100, setSpeedAnemo = 0; int stateResistor = 0; const char *mqttIPHost; //тут хранится IP хоста по хостнейму @@ -57,19 +71,17 @@ int reqCounter = 0; long rssi = 0, minRes=1480, maxRes=2600; char bufTopic[140], bufWillTopic[150], bufSetTopic[150]; - -int moveAnemo(byte speed, byte percent); +int moveAnemo(byte percent); int setMotor(bool Finput, int Binput); void callback(char *topic, byte *payload, unsigned int length); -int disconnectMQTT(); +int disconnectMQTT(); int SendMqttReq(bool sendVal, bool sendStatus, byte statusConn); - void ledset(byte color = 0) { M5.dis.setBrightness(60); //Половина яркости switch (color) - { + { case 2: M5.dis.drawpix(0, 0xf00000); //Зеленый break; @@ -183,7 +195,7 @@ int reqNtpTime() { uint32_t timeEpoch = timeClient.getEpochTime(); if (timeEpoch < 1600000000) - { + { Serial.println("Error reqNtpTime() Time"); return 1; } @@ -195,15 +207,13 @@ int reqNtpTime() return 0; } -//{"percent":50,"speed":20} +//{"amount":50} void callback(char *topic, byte *payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); - char jsonResult[250]; - for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); @@ -211,73 +221,74 @@ void callback(char *topic, byte *payload, unsigned int length) } DeserializationError error = deserializeJson(docResult, jsonResult); - if (error) + if(error) { Serial.print(F("deserializeJson() failed: ")); return; } - setPercent = (byte)docResult["percent"]; //0-100 - setSpeedAnemo = (byte)docResult["speed"]; //speed + setPercent = (byte)docResult["amount"]; //0-100 + //setSpeedAnemo = (byte)docResult["speed"]; //speed - moveAnemo(setSpeedAnemo, setPercent); -} + if(setPercent!=prevPercent) { + setMotor(false,false); + delay(1000); + if(setPercent<=100 && setPercent>=0 && abs(prevPercent-setPercent)>=10) { + moveAnemo(setPercent); + prevPercent=setPercent; + } + } +} int nowPercent(int analogStatus) { - Serial.print("Percent NOW: "); int percentNow = map(analogStatus, minRes, maxRes, 0, 100); Serial.print(percentNow); Serial.println(" %"); - return percentNow; } int nowResist() { - Serial.print("NOW: "); int analogStatus = analogRead(Resist); - Serial.print(analogStatus); - + Serial.println(analogStatus); return analogStatus; } -int moveAnemo(byte speed, byte percent) +int moveAnemo(byte percent) { - Serial.print("Set: "); - Serial.print(speed); - Serial.print(" "); Serial.println(percent); - int setResist = map(percent, 0, 100, minRes, maxRes); - + Serial.println(" -------------------- "); if (setResist <= stateResistor) { setMotor(false, true); while (setResist <= stateResistor) - { + { stateResistor = analogRead(Resist); Serial.print("Now: "); Serial.print(map(stateResistor, minRes, maxRes, 0, 100)); - Serial.println(" %"); - delay(200); + Serial.println(" %"); + MqttClient.loop(); + delay(100); } } else - { + { setMotor(true, false); while (setResist >= stateResistor) - { + { stateResistor = analogRead(Resist); Serial.print("Now: "); Serial.print(map(stateResistor, minRes, maxRes, 0, 100)); Serial.println(" %"); - delay(200); + MqttClient.loop(); + delay(100); } } @@ -326,9 +337,8 @@ void OTAUpdate() OTApreferences.begin("ota-config"); if (WiFi.status() == WL_CONNECTED) { - HTTPClient http; - String serverPath = "http://meteosence.s-host.net/airqa/airquality.php?meteopas=sfddsg38r327kjsdgf8932r&mac = " + macc + " &meteodata = gethash"; + String serverPath = "http://meteosence.s-host.net/airqa/airquality.php?meteopas=sfdd2retert45645yre932r&mac = " + macc + " &meteodata = gethash"; http.begin(serverPath.c_str()); int httpResponseCode = http.GET(); @@ -378,8 +388,8 @@ void OTAUpdate() { flagOTA = false; //Serial.println("flagOTA = false;"); - - t_httpUpdate_return ret = ESPhttpUpdate.update("http://meteosence.s-host.net/airqa/co2/co2.bin"); + + t_httpUpdate_return ret = ESPhttpUpdate.update("http://meteosence.s-host.net/airqa/anemo/anemoatoms.bin"); //После update ничего не происходит, такая вот особенность. //Если все прошло хорошо, перезагрузка на новую прошивку @@ -437,15 +447,17 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1 unsigned long timeNow = now(); doc["analog"] = nowResist(); - doc["percent"] = nowPercent(nowResist()); + doc["amount"] = setPercent; + doc["calc"] = nowPercent(nowResist()); doc["ts"] = timeNow; serializeJson(doc, JsonData); doc.remove("ts"); doc.remove("analog"); - doc.remove("percent"); - doc.clear(); + doc.remove("amount"); + doc.remove("calc"); + doc.clear(); doc.garbageCollect(); Serial.println(JsonData); //Вывод JSON строки в консоль