Работает, кроме автополива

This commit is contained in:
skysamara 2021-07-02 17:05:35 +03:00
parent 6bbc20548e
commit 24a4776ea1
5 changed files with 63 additions and 38 deletions

View File

@ -14,8 +14,8 @@
#define led_pin 2 // D4
boolean led_status = 0;
//float Temperature;
//float Humidity;
const int timeSleep = 60*1000*1000; // одна минута
DHT dht(DHTPin, DHTTYPE); // Инициализация датчика DHT
BlynkTimer timer;

View File

@ -3,7 +3,7 @@ class Pump
unsigned long lastTime;
int duration = 10; // Время полива **************************
int maxDuration; // Максимальное время полива
int maxDuration = 600; // Максимальное время полива 10 минут
int currentDuration; // Текущее время полива для отображения в приложении
public:
@ -15,33 +15,32 @@ class Pump
}
void Update() {
// if ((millis() - lastTime) > duration * 1000) // Пора выключать
// {
// lastTime = millis();
// Serial.println("Update-stop");
// _m -> setmotor(_STOP);
// }
if (((millis() - lastTime) > duration * 1000) // истекло установленное время
|| ((millis() - lastTime) > maxDuration * 1000))// или превышено максимальное
{
lastTime = millis();
Serial.println("class Pump. void Stop()");
_m -> setmotor(_STOP);
}
}
void Start() {
// if (!IsON())
// {
Serial.print("Start! ");
Serial.print("class Pump. void Start() ");
Serial.println(duration);
lastTime = millis();
_m -> setmotor(_CCW, 100);
// Update();
// }
}
void Stop() {
// if (IsON())
// {
Serial.print("Stop! ");
Serial.print("class Pump. void Stop() ");
Serial.println(duration);
lastTime = millis();
_m -> setmotor(_STOP);
// Update();
// Update();
// }
}
@ -58,7 +57,7 @@ class Pump
void SetDuration(int d) {
duration = d;
Serial.print("SetDuration ");
Serial.print("void SetDuration(int d): ");
Serial.println(duration);
}

View File

@ -1,3 +1,8 @@
void sleep(){
delay (200);
ESP.deepSleep(timeSleep);
}
void timerEvent()
{
read_DHT22();
@ -6,34 +11,35 @@ void timerEvent()
void refreshApp()
{
while (Blynk.connect() == false){}; // Ждём подключения
Blynk.virtualWrite(V5, pump1.GetCurrentDuration());
// Blynk.virtualWrite(V4, pump1.IsON());
}
void read_DHT22()
{
while (Blynk.connect() == false){}; // Ждём подключения
float Temperature = dht.readTemperature();
float Humidity = dht.readHumidity();
// Serial.print("Температура: ");
// Serial.println(Temperature, 2);
// Serial.print("Влажность: ");
// Serial.println(Humidity, 2);
// Serial.print("Температура: ");
// Serial.println(Temperature, 2);
// Serial.print("Влажность: ");
// Serial.println(Humidity, 2);
Blynk.virtualWrite(V3, Temperature);
Blynk.virtualWrite(V2, Humidity);
}
void setPumpDuration(int v0){
void setPumpDuration(int v0) {
int d = v0;
// pump1.SetDuration(d);
Serial.print("Длительность: ");
pump1.SetDuration(d);
Serial.print("setPumpDuration(int v0): ");
Serial.println(d);
}
void blynk_connected(){
void blynk_connected() {
Blynk.syncAll();
}
@ -42,14 +48,14 @@ void blynk_connected(){
//}
void readSettings() {
// int f = 0;
// EEPROM.get(0, f);
// pump1.setDuration(f);
// Serial.print("EEPROM.get(0, f): ");
// Serial.println(f, 2);
//
// EEPROM.write(0, 15);
// EEPROM.get(0, f);
// Serial.print("EEPROM.write(0, f): ");
// Serial.println(f, 2);
// int f = 0;
// EEPROM.get(0, f);
// pump1.setDuration(f);
// Serial.print("EEPROM.get(0, f): ");
// Serial.println(f, 2);
//
// EEPROM.write(0, 15);
// EEPROM.get(0, f);
// Serial.print("EEPROM.write(0, f): ");
// Serial.println(f, 2);
}

View File

@ -12,10 +12,17 @@ BLYNK_WRITE(V1) // Установка времени старта полива
// until you remove widget or stop project or
// clean stop/start fields of widget
Serial.print("Таймер: ");
Serial.print("BLYNK_WRITE(V1) // Установка времени старта полива: ");
Serial.println(param.asStr());
// Serial.println(pump1.GetCurrentDuration());
// pump1.Start();
if (param.asInt() == 1){
pump1.Start();
}
else{
pump1.Stop();
}
}
BLYNK_WRITE(V4) // Кнопка помпы 1

View File

@ -7,4 +7,17 @@ char auth[] = "Fdj2ndHfZmRirtgrgdrfh81fzPpfB0-";
char ssid[] = "WIFI";
char pass[] = "132password";
https://www.youtube.com/watch?v=gX71MupZQF4
Для погружения в сон соединить D0 и Reset!
https://habr.com/ru/post/257141/
И убрать светодиод
https://itnan.ru/post.php?c=2&p=130421
Про датчик влажности грунта и сон.
512 байт RTC памяти, которая прекрасно сохраняет данные в то время,
пока чип находится в режиме Deep sleep
https://habr.com/ru/post/411537/
Про железо почитать
*/