Code: Select all
#include <SuplaDevice.h>
// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
// Arduino Mega with EthernetShield W5100:
#include <supla/network/ethernet_shield.h>
// Ethernet MAC address
uint8_t mac[6] = {0xEA, 0x9F, 0x6D, 0x92, 0x88, 0xC0};
Supla::EthernetShield ethernet(mac);
// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
// ESP8266 and ESP32 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("ssid", "haslo");
#endif
int przycisk1 = 2; // Przelacznik1
int stan_przekaznika1 = LOW;
int stan_przycisku1;
int ostatni_stan_przycisku1 = HIGH;
long lastDebounceTime1 = 0;
long czas_drgania1 = 10;
void setup()
{
Serial.begin(115200);
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {kod mam};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {kod mam};
pinMode(przycisk1, INPUT_PULLUP);
pinMode(2, OUTPUT);
SuplaDevice.begin(GUID, "dane", "dane", AUTHKEY);
}
void loop()
{
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 = 2; // Need enter the relay channel number
value1.DurationMS = 0; //turn on time
int odczyt1 = digitalRead(przycisk1);
if (odczyt1 != ostatni_stan_przycisku1)
{
lastDebounceTime1 = millis();
}
if ((millis() - lastDebounceTime1) > czas_drgania1)
{
if (odczyt1 != stan_przycisku1)
{
stan_przycisku1 = odczyt1;
if (stan_przycisku1 == LOW)
{
//stan_przekaznika = !stan_przekaznika;
value1.value[0] = !value1.value[0];
SuplaDevice.channelSetValue(&value1);
}
}
}
//digitalWrite(5, stan_przekaznika);
ostatni_stan_przycisku1 = odczyt1;
}