anemoststt norm + spiffs

master
SmartUbuntu 2021-08-31 14:56:12 +03:00
parent c6348a6706
commit 8c3ac9e31e
4 changed files with 69 additions and 50 deletions

View File

@ -1,7 +1,7 @@
{ {
// See http://go.microsoft.com/fwlink/?LinkId=827846 // See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format // for the documentation about the extensions.json format
"recommendations": [ "recommendations": [
"platformio.platformio-ide" "platformio.platformio-ide"
] ]
} }

View File

@ -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,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x1E0000
5 app1 app ota_1 0x1F0000 0x1E0000
6 spiffs data spiffs 0x3D0000 0x30000

View File

@ -12,4 +12,5 @@
platform = espressif32 platform = espressif32
board = m5stack-atom board = m5stack-atom
framework = arduino framework = arduino
lib_extra_dirs = C:\Users\38093\Documents\Arduino\libraries lib_extra_dirs = /home/smart/Arduino/libraries
board_build.partitions = min_spiffs.csv

View File

@ -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 <WiFiManager.h> // https://github.com/tzapu/WiFiManager #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Preferences.h> //Сохранение настроек хеша прошивки #include <Preferences.h> //Сохранение настроек хеша прошивки
#include <HTTPClient.h> #include <HTTPClient.h>
@ -16,11 +30,11 @@
#define Resist 33 #define Resist 33
#define TRIGGER_PIN 39 #define TRIGGER_PIN 39
unsigned int VersionSW = 4; unsigned int VersionSW = 7;
//3 - Первый код для анемостата //3 - Первый код для анемостата
// 5 - перед установкой
//7 - выполнение команд последовательно
WiFiManager wm; // обьект менеджера WiFiManager wm; // обьект менеджера
Preferences OTApreferences; //Обьект хранения настроек хеша прошивки Preferences OTApreferences; //Обьект хранения настроек хеша прошивки
@ -45,7 +59,7 @@ String setTopic = "aastudio/act/" + macc + "/set/0";
String willTopicTemp = "aastudio/act/" + macc + "/status"; String willTopicTemp = "aastudio/act/" + macc + "/status";
const PROGMEM char *mqttLogin = "AA_Lab", *mqttPass = "automation.art$"; const PROGMEM char *mqttLogin = "AA_Lab", *mqttPass = "automation.art$";
byte setPercent = 0, setSpeedAnemo = 0; byte setPercent = 0, prevPercent=100, setSpeedAnemo = 0;
int stateResistor = 0; int stateResistor = 0;
const char *mqttIPHost; //тут хранится IP хоста по хостнейму const char *mqttIPHost; //тут хранится IP хоста по хостнейму
@ -57,19 +71,17 @@ int reqCounter = 0;
long rssi = 0, minRes=1480, maxRes=2600; long rssi = 0, minRes=1480, maxRes=2600;
char bufTopic[140], bufWillTopic[150], bufSetTopic[150]; char bufTopic[140], bufWillTopic[150], bufSetTopic[150];
int moveAnemo(byte percent);
int moveAnemo(byte speed, byte percent);
int setMotor(bool Finput, int Binput); int setMotor(bool Finput, int Binput);
void callback(char *topic, byte *payload, unsigned int length); void callback(char *topic, byte *payload, unsigned int length);
int disconnectMQTT(); int disconnectMQTT();
int SendMqttReq(bool sendVal, bool sendStatus, byte statusConn); int SendMqttReq(bool sendVal, bool sendStatus, byte statusConn);
void ledset(byte color = 0) void ledset(byte color = 0)
{ {
M5.dis.setBrightness(60); //Половина яркости M5.dis.setBrightness(60); //Половина яркости
switch (color) switch (color)
{ {
case 2: case 2:
M5.dis.drawpix(0, 0xf00000); //Зеленый M5.dis.drawpix(0, 0xf00000); //Зеленый
break; break;
@ -183,7 +195,7 @@ int reqNtpTime()
{ {
uint32_t timeEpoch = timeClient.getEpochTime(); uint32_t timeEpoch = timeClient.getEpochTime();
if (timeEpoch < 1600000000) if (timeEpoch < 1600000000)
{ {
Serial.println("Error reqNtpTime() Time"); Serial.println("Error reqNtpTime() Time");
return 1; return 1;
} }
@ -195,15 +207,13 @@ int reqNtpTime()
return 0; return 0;
} }
//{"percent":50,"speed":20} //{"amount":50}
void callback(char *topic, byte *payload, unsigned int length) void callback(char *topic, byte *payload, unsigned int length)
{ {
Serial.print("Message arrived ["); Serial.print("Message arrived [");
Serial.print(topic); Serial.print(topic);
Serial.print("] "); Serial.print("] ");
char jsonResult[250]; char jsonResult[250];
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
Serial.print((char)payload[i]); Serial.print((char)payload[i]);
@ -211,73 +221,74 @@ void callback(char *topic, byte *payload, unsigned int length)
} }
DeserializationError error = deserializeJson(docResult, jsonResult); DeserializationError error = deserializeJson(docResult, jsonResult);
if (error) if(error)
{ {
Serial.print(F("deserializeJson() failed: ")); Serial.print(F("deserializeJson() failed: "));
return; return;
} }
setPercent = (byte)docResult["percent"]; //0-100 setPercent = (byte)docResult["amount"]; //0-100
setSpeedAnemo = (byte)docResult["speed"]; //speed //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) int nowPercent(int analogStatus)
{ {
Serial.print("Percent NOW: "); Serial.print("Percent NOW: ");
int percentNow = map(analogStatus, minRes, maxRes, 0, 100); int percentNow = map(analogStatus, minRes, maxRes, 0, 100);
Serial.print(percentNow); Serial.print(percentNow);
Serial.println(" %"); Serial.println(" %");
return percentNow; return percentNow;
} }
int nowResist() int nowResist()
{ {
Serial.print("NOW: "); Serial.print("NOW: ");
int analogStatus = analogRead(Resist); int analogStatus = analogRead(Resist);
Serial.print(analogStatus); Serial.println(analogStatus);
return analogStatus; return analogStatus;
} }
int moveAnemo(byte speed, byte percent) int moveAnemo(byte percent)
{ {
Serial.print("Set: "); Serial.print("Set: ");
Serial.print(speed);
Serial.print(" ");
Serial.println(percent); Serial.println(percent);
int setResist = map(percent, 0, 100, minRes, maxRes); int setResist = map(percent, 0, 100, minRes, maxRes);
Serial.println(" -------------------- "); Serial.println(" -------------------- ");
if (setResist <= stateResistor) if (setResist <= stateResistor)
{ {
setMotor(false, true); setMotor(false, true);
while (setResist <= stateResistor) while (setResist <= stateResistor)
{ {
stateResistor = analogRead(Resist); stateResistor = analogRead(Resist);
Serial.print("Now: "); Serial.print("Now: ");
Serial.print(map(stateResistor, minRes, maxRes, 0, 100)); Serial.print(map(stateResistor, minRes, maxRes, 0, 100));
Serial.println(" %"); Serial.println(" %");
delay(200); MqttClient.loop();
delay(100);
} }
} }
else else
{ {
setMotor(true, false); setMotor(true, false);
while (setResist >= stateResistor) while (setResist >= stateResistor)
{ {
stateResistor = analogRead(Resist); stateResistor = analogRead(Resist);
Serial.print("Now: "); Serial.print("Now: ");
Serial.print(map(stateResistor, minRes, maxRes, 0, 100)); Serial.print(map(stateResistor, minRes, maxRes, 0, 100));
Serial.println(" %"); Serial.println(" %");
delay(200); MqttClient.loop();
delay(100);
} }
} }
@ -326,9 +337,8 @@ void OTAUpdate()
OTApreferences.begin("ota-config"); OTApreferences.begin("ota-config");
if (WiFi.status() == WL_CONNECTED) if (WiFi.status() == WL_CONNECTED)
{ {
HTTPClient http; 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()); http.begin(serverPath.c_str());
int httpResponseCode = http.GET(); int httpResponseCode = http.GET();
@ -378,8 +388,8 @@ void OTAUpdate()
{ {
flagOTA = false; flagOTA = false;
//Serial.println("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 ничего не происходит, такая вот особенность. //После update ничего не происходит, такая вот особенность.
//Если все прошло хорошо, перезагрузка на новую прошивку //Если все прошло хорошо, перезагрузка на новую прошивку
@ -437,15 +447,17 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
unsigned long timeNow = now(); unsigned long timeNow = now();
doc["analog"] = nowResist(); doc["analog"] = nowResist();
doc["percent"] = nowPercent(nowResist()); doc["amount"] = setPercent;
doc["calc"] = nowPercent(nowResist());
doc["ts"] = timeNow; doc["ts"] = timeNow;
serializeJson(doc, JsonData); serializeJson(doc, JsonData);
doc.remove("ts"); doc.remove("ts");
doc.remove("analog"); doc.remove("analog");
doc.remove("percent"); doc.remove("amount");
doc.clear(); doc.remove("calc");
doc.clear();
doc.garbageCollect(); doc.garbageCollect();
Serial.println(JsonData); //Вывод JSON строки в консоль Serial.println(JsonData); //Вывод JSON строки в консоль