Ok, powiadomienia z urządzenia zaimplementowane i połączone ze skryptem wykrywającym za duży wypływ wody na wodomierzu, przetestowane. Działa pięknie.
Pobieranie czasu z serwera Supli i wyciągnięcie info o specyficznych dla aktualnego dnia godzinach wschodu i zachodu słońca, zrobione, działa.
Teraz zostało mi to zainstalować i dopisać szkic odpowiedzialny za sterowanie paskami led na podjeździe. Zrobimy;).
Szkic:
Code: Select all
///////////////////////////////////// 192.168.4.1/update //////////////////////////////
#include <SuplaDevice.h>
#include <supla/sensor/DS18B20.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
#include <supla/sensor/binary.h>
#include <supla/network/esp_wifi.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/events.h>
#include <supla/storage/eeprom.h>
#include <ESP8266HTTPUpdateServer.h> //OTA
#include <Timers.h>
#include <supla/clock/clock.h> //int suplaClock.getYear(); getMonth(); getDay(); getDayOfWeek();1 - Sunday, 2 - Monday getHour(); getMin(); getSec();
#include <supla/sensor/impulse_counter.h>
#include <supla/device/notifications.h>
Supla::Clock suplaClock;
Supla::Eeprom eeprom;
Supla::ESPWifi wifi;
ESP8266HTTPUpdateServer httpUpdater;
#include <Ephemeris.h>
#define kran_wjazd 5 //D1
#define bramaWjazdRelay 4 //D2
#define lampaOgrodRelay 2 //D4
int chLicznikWody;
int progWody = 30;
void printRiseAndSet(FLOAT latitude, FLOAT longitude, int UTCOffset, int day, int month, int year)
{
Ephemeris::setLocationOnEarth(latitude,longitude);
SolarSystemObject sun = Ephemeris::solarSystemObjectAtDateAndTime(Sun,day,month,year,0,0,0);
if( sun.riseAndSetState == RiseAndSetOk )
{
int hoursR,minutesR,hoursS, minutesS;
FLOAT seconds;
Ephemeris::floatingHoursToHoursMinutesSeconds(Ephemeris::floatingHoursWithUTCOffset(sun.rise,UTCOffset), &hoursR, &minutesR, &seconds);
Serial.print(" Wschod: ");
Serial.print(hoursR);
Serial.print("h");
Serial.print(minutesR);
Serial.print("m");
Ephemeris::floatingHoursToHoursMinutesSeconds(Ephemeris::floatingHoursWithUTCOffset(sun.set,UTCOffset), &hoursS, &minutesS, &seconds);
Serial.print(" Zachod: ");
Serial.print(hoursS);
Serial.print("h");
Serial.print(minutesS);
Serial.print("m");
}
Serial.println();
}
Timer sekund10;
Timer minut1;
#define BUTTON_CFG_RELAY_GPIO 12 //D6
Supla::LittleFsConfig configSupla;
Supla::EspWebServer suplaServer;
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Sensor::ImpulseCounter *licznikWody = nullptr;
Supla::Control::Relay *bramaWjazd = nullptr;
Supla::Control::Relay *lampaOgrod = nullptr;
Supla::Sensor::Binary *kranWjazd = nullptr;
void setup()
{
Serial.begin(9600);
httpUpdater.setup(suplaServer.getServerPtr(), "/update");
auto buttonCfgRelay =
new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);
Supla::Notification::RegisterNotification(-1);
licznikWody = new Supla::Sensor::ImpulseCounter(14, true, false, 100);///D5
lampaOgrod = new Supla::Control::Relay(lampaOgrodRelay, false);
bramaWjazd = new Supla::Control::Relay(bramaWjazdRelay, false);
kranWjazd = new Supla::Sensor::Binary(kran_wjazd, false);// false = pullUp
buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
SuplaDevice.begin();
sekund10.begin(9985);
minut1.begin(59998);
}
void loop() {
SuplaDevice.iterate();
pobierzCzas();
kontrolaWody();
}
void pobierzCzas(){
if(sekund10.available()){
printRiseAndSet(00.0000, 00.0000, +1, suplaClock.getDay(),suplaClock.getMonth(),suplaClock.getYear());
sekund10.restart();
}
}
void kontrolaWody(){
if(minut1.available()){
if(licznikWody->getCounter() > (chLicznikWody + progWody)){
Supla::Notification::Send(-1, "WODOMIERZ", "Przekroczono limit wylanej wody w 1 minutę");
}
chLicznikWody = licznikWody->getCounter();
minut1.restart();
}
}
Logi:
Code: Select all
Clock: new local time: 2024-1-31 20:21:13
Wschod: 7h20m Zachod: 16h36m
Wschod: 7h20m Zachod: 16h36m
Co to znaczy:
Code: Select all
Clock: time diff (system-new): -2 s