Code: Select all
#include <SuplaDevice.h>
#include <Arduino.h>
#include <supla/sensor/DS18B20.h>
#include <supla/sensor/Thermometer.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/roller_shutter.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
#include <supla/control/action_trigger.h>
#include <supla/device/status_led.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/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/network/html/security_certificate.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/events.h>
int pinsw = 4; // Przelacznik
int stan_przekaznika = LOW;
int stan_przycisku;
int ostatni_stan_przycisku = HIGH;
long lastDebounceTime = 0;
long czas_drgania = 10;
byte ile = 1;
Supla::ESPWifi wifi("xxx", "xxx");
void setup()
{
Serial.begin(115200);
pinMode(pinsw, INPUT_PULLUP);
pinMode(5, OUTPUT);
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {xxxxx};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxxxx};
// Przekazniki i przyciski
auto r1 = new Supla::Control::Relay(5);
//auto r2 = new Supla::Control::Relay(13);
auto button1 = new Supla::Control::Button(4, true, true);
//auto button2 = new Supla::Control::Button(12, true, true);
button1->addAction(Supla::TOGGLE, *r1, Supla::ON_PRESS);
//button2->addAction(Supla::TOGGLE, *r2, Supla::ON_PRESS);
auto at1 = new Supla::Control::ActionTrigger();
at1->setRelatedChannel(r1);
//at1->setRelatedChannel(r2);
SuplaDevice.begin(GUID, "svrXXX.supla.org", "xxxxxxx", AUTHKEY);
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
SuplaDevice.iterate();
TSD_SuplaChannelNewValue value1; //Set value name
value1.SenderID = 0; // Notify other users that your smartphone opens a blind. In case of actuators is to be 0
value1.ChannelNumber = 0; // Need enter the relay channel number
value1.DurationMS = 0; //turn on time
int odczyt = digitalRead(pinsw);
if (odczyt != ostatni_stan_przycisku)
{
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > czas_drgania)
{
if (odczyt != stan_przycisku)
{
stan_przycisku = odczyt;
if (stan_przycisku == LOW)
{
//stan_przekaznika = !stan_przekaznika;
value1.value[0] = !value1.value[0];
SuplaDevice.channelSetValue(&value1);
}
}
}
//digitalWrite(5, stan_przekaznika);
ostatni_stan_przycisku = odczyt;
}
else
{
int odczyt = digitalRead(pinsw);
if (odczyt != ostatni_stan_przycisku)
{
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > czas_drgania)
{
if (odczyt != stan_przycisku)
{
stan_przycisku = odczyt;
if (stan_przycisku == LOW)
{
stan_przekaznika = !stan_przekaznika;
}
}
}
digitalWrite(5, stan_przekaznika);
ostatni_stan_przycisku = odczyt;
}
}