SD WebInterface - wybór LAN/WLAN

User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

radzik_r wrote: Sun Nov 12, 2023 2:10 pm
lukfud wrote: Sun Nov 12, 2023 1:19 pm
https://github.com/RobTillaart/PCA9685_RT
Tak, też.
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

Code: Select all

#ifdef ARDUINO_ARCH_ESP32
#include <HTTPUpdateServer.h>
HTTPUpdateServer httpUpdater;
#else
#include <ESP8266HTTPUpdateServer.h>
ESP8266HTTPUpdateServer httpUpdater;
#endif

#include <supla/network/esp_web_server.h>
Supla::EspWebServer suplaServer;

void setup() {
  httpUpdater.setup(suplaServer.getServerPtr(), "/update");
}
Nie jest to ładne rozwiązanie, ale jest i działa ;)
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

lukfud wrote: Wed Nov 15, 2023 8:08 am

Code: Select all

#ifdef ARDUINO_ARCH_ESP32
#include <HTTPUpdateServer.h>
HTTPUpdateServer httpUpdater;
#else
#include <ESP8266HTTPUpdateServer.h>
ESP8266HTTPUpdateServer httpUpdater;
#endif

#include <supla/network/esp_web_server.h>
Supla::EspWebServer suplaServer;

void setup() {
  httpUpdater.setup(suplaServer.getServerPtr(), "/update");
}
Nie jest to ładne rozwiązanie, ale jest i działa ;)
Tak niewiele potrzeba? :) Piękne w swojej prostocie :)
Najlepsze suple dla Twojego domu :mrgreen:
jaku2k
Posts: 920
Joined: Sun May 24, 2020 8:40 pm
Has thanked: 1 time

Post

Witam,
próbuję uruchomić całość na testowym module, ale otrzymuję błąd. Poniżej przesyłam jego treść.

W przypadku wyłączenia CA, sprzęt również nie nie chce się połączyć z Cloudem.
SD v23.11; boardy v2.0.11

Code: Select all

Establishing encrypted connection with: [adres.serwera] (port: 2016)
SSL error: -8576, X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected
Connection fail (0). Server: [adres.serwera]
Deinitializing SRPC

Przy okazji, czy dla trybu konfiguracyjnego da się ustawić "przycisk CONFIG"?
Pozdrawiam
Jakub
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

jaku2k wrote: Sun Dec 03, 2023 1:28 am Witam,
próbuję uruchomić całość na testowym module, ale otrzymuję błąd. Poniżej przesyłam jego treść.

W przypadku wyłączenia CA, sprzęt również nie nie chce się połączyć z Cloudem.
SD v23.11; boardy v2.0.11

Code: Select all

Establishing encrypted connection with: [adres.serwera] (port: 2016)
SSL error: -8576, X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected
Connection fail (0). Server: [adres.serwera]
Deinitializing SRPC
Jeżeli łączysz do swojej instancji to wyłącz SSL,

Code: Select all

wifi->setSSLEnabled(false);
lub
eth->setSSLEnabled(false);
albo poproś Przemka o wygenerowanie certyfikatu dla niej.
jaku2k wrote: Sun Dec 03, 2023 1:28 am Przy okazji, czy dla trybu konfiguracyjnego da się ustawić "przycisk CONFIG"?
Co chcesz osiągnąć?
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
jaku2k
Posts: 920
Joined: Sun May 24, 2020 8:40 pm
Has thanked: 1 time

Post

lukfud wrote: Sun Dec 03, 2023 7:54 am
jaku2k wrote: Sun Dec 03, 2023 1:28 am Witam,
próbuję uruchomić całość na testowym module, ale otrzymuję błąd. Poniżej przesyłam jego treść.

W przypadku wyłączenia CA, sprzęt również nie nie chce się połączyć z Cloudem.
SD v23.11; boardy v2.0.11

Code: Select all

Establishing encrypted connection with: [adres.serwera] (port: 2016)
SSL error: -8576, X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected
Connection fail (0). Server: [adres.serwera]
Deinitializing SRPC
Jeżeli łączysz do swojej instancji to wyłącz SSL,

Code: Select all

wifi->setSSLEnabled(false);
lub
eth->setSSLEnabled(false);
albo poproś Przemka o wygenerowanie certyfikatu dla niej.
jaku2k wrote: Sun Dec 03, 2023 1:28 am Przy okazji, czy dla trybu konfiguracyjnego da się ustawić "przycisk CONFIG"?
Co chcesz osiągnąć?
Dziękuję, spróbuję w ten sposób.

Chodziło mi o przycisk, który pozwoliłby przełączyć moduł w tryb programowania w przypadku, gdy np. zostały wpisane źle dane serwera. Obecnie, gdy walczyłem z wyżej opisanym problemem, musiałem na nowo flashować ESP.

Czy mógłbyś przybliżyć, o co chodzi z tym certyfikatem? Cloud, z którego korzystam ma aktywny certyfikat SSL.
Pozdrawiam
Jakub
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

jaku2k wrote: Mon Dec 04, 2023 2:25 pm Dziękuję, spróbuję w ten sposób.

Chodziło mi o przycisk, który pozwoliłby przełączyć moduł w tryb programowania w przypadku, gdy np. zostały wpisane źle dane serwera. Obecnie, gdy walczyłem z wyżej opisanym problemem, musiałem na nowo flashować ESP.
Czy mógłbyś przybliżyć, o co chodzi z tym certyfikatem? Cloud, z którego korzystam ma aktywny certyfikat SSL.
Przełączenie do konfiguracji dodane jest w szkicu jako 3-klik na drugim przycisku.

Code: Select all

button_2->addAction(Supla::ENTER_CONFIG_MODE_OR_RESET_TO_FACTORY, SuplaDevice, Supla::ON_CLICK_3, true);
jaku2k wrote: Mon Dec 04, 2023 2:25 pm Czy mógłbyś przybliżyć, o co chodzi z tym certyfikatem? Cloud, z którego korzystam ma aktywny certyfikat SSL.
Certyfikat dla supla-cloud nie ma nic do tego.
Musisz mieć poprawny certyfikat dla supla-server, a z tym tylko Przemek może Ci pomóc.
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
nebraska
Posts: 204
Joined: Thu Dec 08, 2022 3:00 pm
Been thanked: 1 time

Post

Mam to samo wcześniejsze programy działają, a dzisiaj chciałem wgrać i teraz lipa. :twisted:
Dlaczego takie utrudnienia?
Też chciałbym się dowiedzieć o co chodzi z tymi certyfikatami jakieś celowe działania?
jaku2k ja w trybie konfiguracji zaznaczyłem skip certificate veryfication i poszło.
Pytanie do specjalistów czy tak może być zgodnie ze sztuką, jakie mogą być konsekwencje?
User avatar
klew
Posts: 13907
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

nebraska wrote: Mon Dec 04, 2023 8:10 pm Mam to samo wcześniejsze programy działają, a dzisiaj chciałem wgrać i teraz lipa. :twisted:
Dlaczego takie utrudnienia?
Też chciałbym się dowiedzieć o co chodzi z tymi certyfikatami jakieś celowe działania?
Wejdź w tryb cfg i wyłącz weryfikację certyfikatów serwera.

Weryfikacja certyfikatów pozwala się upewnić urządzeniu, że nawiązało połączenie z serwerem, z którym chciało je nawiązać. To jest zabezpieczenie przed atakiem, w stylu, że ktoś podstawia swoją maszynę i Twoje urządzenia łączą się z innym serwerem.

Wszystkie publiczne serwery dla połączeń szyfrowanych na porcie 2016 mają certyfikaty podpisane przez Suplowe CA. Dla serwerów prywatnych też jest przewidziana taka funkcja, która pozwala na podpisanie certfikatu przez Suplę, ale jak wiele rzeczy, to też czeka na swoją kolejkę.

Aktualnie macie dwie (trzy?) opcje jeśli używacie prywatnych instancji:
1. W trybie cfg wyłączyć weryfikację certyfikatów
2. Wygenerować sobie certyfikat CA, podpisać certyfikat serwera Supli tym CA, a następnie publiczny klucz CA wstawić na urządzenie (opcja Custom CA i w polu tekstowym dać certyfikat)
3. Poprosić pzygmunt'a a podpisanie certyfikatu. Szczegóły może lukfud opisze, bo on tą procedurę przeszedł, a ja nie mam pojęcia jakie kroki trzeba tutaj wykonać.
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

Finalna wersja szkicu dla max. 16 ściemniaczy z obsługą MCP, PCA i LAN'u ;)

Code: Select all

#define DEFAULT_DIMMERS_QTY 2
#define WLAN 0
#define LAN 1
#define STATUS_LED_GPIO 2
#define BUTTON_CFG_GPIO 12

#define DEFAULT_HOLD_TIME 400
#define DEFAULT_REPEAT_ON_HOLD 35
#define DEFAULT_MULTICLICK_TIME 350
#define DEFAULT_BUTTON_STEP 5
#define DEFAULT_FADE_EFFECT 500
#define DEFAULT_ITERATION_DELAY 750
#define DEFAULT_MIN_VALUE 0
#define DEFAULT_MAX_VALUE 100

#include <SuplaDevice.h>
#include <supla/clock/clock.h>

#include <supla/network/client.h>
#include <supla/network/esp_wifi.h>
Supla::ESPWifi *wifi = nullptr;
#ifdef ARDUINO_ARCH_ESP32
#include <supla/network/wt32_eth01.h>
Supla::WT32_ETH01 *eth = nullptr;
#include <HTTPUpdateServer.h>
HTTPUpdateServer httpUpdater;
#else
#include <ESP8266HTTPUpdateServer.h>
ESP8266HTTPUpdateServer httpUpdater;
#endif
#include <supla/network/esp_web_server.h>
Supla::EspWebServer suplaServer;

#include <supla/control/button.h>
Supla::Control::Button *button_[16] = {};
#include <supla/control/dimmer_leds.h>
Supla::Control::DimmerLeds *dimmer_[16] = {};
#include <supla/control/action_trigger.h>
Supla::Control::ActionTrigger *at_[16] = {};
#include <supla/control/virtual_relay.h>
Supla::Control::VirtualRelay *webSrvVRelay = nullptr;
Supla::Control::VirtualRelay *vrelay_[16] = {};
#include <supla/control/EXT_PCA9685.h>
Supla::Control::ExtPCA9685 *extpca = nullptr;
#include <supla/control/EXT_MCP23017.h>
Supla::Control::ExtMCP23017 *extmcp = nullptr;

#include <supla/device/status_led.h>
#ifdef ARDUINO_ARCH_ESP8266
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true);
#else
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO);
#endif
#include <supla/device/supla_ca_cert.h>

#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom;
#include <supla/storage/littlefs_config.h>
Supla::LittleFsConfig configSupla(2048);

#include <supla/network/html/div.h>
#include <supla/network/html/h3_tag.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#ifdef ARDUINO_ARCH_ESP8266
#include <supla/network/html/wifi_parameters.h>
#else
#include <supla/network/html/connection_settings.h>
#endif
#include <supla/network/html/custom_parameter.h>
#include <supla/network/html/custom_text_parameter.h>
#include <supla/network/html/select_input_parameter.h>

int8_t selectConnection = 0;
const char DEV_NAME[] = "dev_name";
char devName[30] = {};
const char HT_VALUE[] = "hold_time_value";
int32_t holdTimeValue = DEFAULT_HOLD_TIME;
const char ROH_VALUE[] = "repeat_on_hold_value";
int32_t repeatOnHoldValue = DEFAULT_REPEAT_ON_HOLD;
const char MCT_VALUE[] = "multiclick_time_value";
int32_t multiclickTimeValue = DEFAULT_MULTICLICK_TIME;
const char PWM_FREQ[] = "pwm_frequency";
int32_t pwmFrequency = 223;
const char BUTTON_STEP[] = "button_step";
int32_t btnStep = DEFAULT_BUTTON_STEP;
const char FADE_EFFECT[] = "fade_effect";
int32_t fadeEffect_ = DEFAULT_FADE_EFFECT;
const char ITERATION_DELAY[] = "iteration_delay";
int32_t iterationDelay = DEFAULT_ITERATION_DELAY;
int32_t minValue[16] = {};
int32_t maxValue[16] = {};
const char DIM_QTY[] = "dimmers_quantity";
int32_t dimmersQuantity = DEFAULT_DIMMERS_QTY;

enum default_actions {
  START_WEB_SERVER,
  STOP_WEB_SERVER,
  ENABLE_BUTTON_0,
  ENABLE_BUTTON_1,
  ENABLE_BUTTON_2,
  ENABLE_BUTTON_3,
  ENABLE_BUTTON_4,
  ENABLE_BUTTON_5,
  ENABLE_BUTTON_6,
  ENABLE_BUTTON_7,
  DISABLE_BUTTON_0,
  DISABLE_BUTTON_1,
  DISABLE_BUTTON_2,
  DISABLE_BUTTON_3,
  DISABLE_BUTTON_4,
  DISABLE_BUTTON_5,
  DISABLE_BUTTON_6,
  DISABLE_BUTTON_7
};

class addedActionsClass : public Supla::ActionHandler, public Supla::Element {
 public: addedActionsClass() {}
  void handleAction(int event, int action) {
    if (action == START_WEB_SERVER) {
      SuplaDevice.handleAction(0, Supla::START_LOCAL_WEB_SERVER);
    }
    if (action == STOP_WEB_SERVER) {
      SuplaDevice.handleAction(0, Supla::STOP_LOCAL_WEB_SERVER);
    }
    for (int i = 0; i < dimmersQuantity; i++) {
      if (action == ENABLE_BUTTON_0+i) {
        button_[i]->enableAction(-1, dimmer_[i], -1);
        SUPLA_LOG_INFO("# button[%d] enabled", i);
      }
      if (action == DISABLE_BUTTON_0+i) {
        button_[i]->disableAction(-1, dimmer_[i], -1);
        SUPLA_LOG_INFO("# button[%d] disabled", i);
      }
    }  
  }
};
addedActionsClass *custAct = new addedActionsClass;

void setup() {
  Serial.begin(115200);
  new Supla::Clock;

  Supla::Storage::Init();

#ifdef ARDUINO_ARCH_ESP32
  if (Supla::Storage::ConfigInstance()->getInt8(
                      Supla::Html::ConnectionSettingsTag, &selectConnection)) {
    SUPLA_LOG_DEBUG("# Param[%s]: %d", Supla::Html::ConnectionSettingsTag,
                                                             selectConnection);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s]: is not set",
                                           Supla::Html::ConnectionSettingsTag);
  }
#endif

  if (Supla::Storage::ConfigInstance()->getString(DEV_NAME, devName, 30)) {
    SUPLA_LOG_DEBUG("# Param[%s]: %s", DEV_NAME, devName);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", DEV_NAME);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(DIM_QTY, &dimmersQuantity)) {
    if (dimmersQuantity < 1 || dimmersQuantity > 16) {
      dimmersQuantity = DEFAULT_DIMMERS_QTY;
      Supla::Storage::ConfigInstance()->setInt32(DIM_QTY, dimmersQuantity);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", DIM_QTY, dimmersQuantity);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s]: is not set", DIM_QTY);
  }
  
  if (Supla::Storage::ConfigInstance()->getInt32(HT_VALUE, &holdTimeValue)) {
    if (holdTimeValue <= 0 || holdTimeValue > 1000) {
      holdTimeValue = DEFAULT_HOLD_TIME;
      Supla::Storage::ConfigInstance()->setInt32(HT_VALUE, holdTimeValue);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", HT_VALUE, holdTimeValue);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", HT_VALUE);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(ROH_VALUE,
                                                         &repeatOnHoldValue)) {
    if (repeatOnHoldValue <= 0 || repeatOnHoldValue > 150) {
      repeatOnHoldValue = DEFAULT_REPEAT_ON_HOLD;
      Supla::Storage::ConfigInstance()->setInt32(ROH_VALUE, repeatOnHoldValue);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", ROH_VALUE, repeatOnHoldValue);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", ROH_VALUE);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MCT_VALUE,
                                                       &multiclickTimeValue)) {
    if (multiclickTimeValue <= 0 || multiclickTimeValue > 1500) {
      multiclickTimeValue = DEFAULT_MULTICLICK_TIME;
      Supla::Storage::ConfigInstance()->setInt32(MCT_VALUE,
                                                          multiclickTimeValue);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", MCT_VALUE, multiclickTimeValue);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", MCT_VALUE);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(BUTTON_STEP, &btnStep)) {
    if (btnStep <= 0 || btnStep > 20) {
      btnStep = DEFAULT_BUTTON_STEP;
      Supla::Storage::ConfigInstance()->setInt32(BUTTON_STEP, btnStep);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", BUTTON_STEP, btnStep);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", BUTTON_STEP);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(FADE_EFFECT, &fadeEffect_)) {
    if (fadeEffect_ <= 0 || fadeEffect_ > 1000) {
      fadeEffect_ = DEFAULT_FADE_EFFECT;
      Supla::Storage::ConfigInstance()->setInt32(FADE_EFFECT, fadeEffect_);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", FADE_EFFECT, fadeEffect_);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", FADE_EFFECT);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(ITERATION_DELAY,
                                                            &iterationDelay)) {
    if (iterationDelay <= 0 || iterationDelay > 5000) {
      iterationDelay = DEFAULT_ITERATION_DELAY;
      Supla::Storage::ConfigInstance()->setInt32(ITERATION_DELAY,
                                                               iterationDelay);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", ITERATION_DELAY, iterationDelay);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", ITERATION_DELAY);
  }

  for (int i = 0; i < dimmersQuantity; i++) {
    char minBuffer[10], maxBuffer[10];
    snprintf(minBuffer, sizeof(minBuffer), "min_%d", i);
    snprintf(maxBuffer, sizeof(maxBuffer), "max_%d", i);
    if (Supla::Storage::ConfigInstance()->getInt32(minBuffer, &minValue[i])) {
      if (minValue[i] < 0 || minValue[i] >= 50) {
        minValue[i] = DEFAULT_MIN_VALUE;
        Supla::Storage::ConfigInstance()->setInt32(minBuffer, minValue[i]);
      } 
      SUPLA_LOG_DEBUG("# Param[%s]: %d", minBuffer, minValue[i]);
    } else {
      SUPLA_LOG_DEBUG("# Param[%s] is not set, setting default value: %d",
                                                 minBuffer, DEFAULT_MIN_VALUE);
      minValue[i] = DEFAULT_MIN_VALUE;
      Supla::Storage::ConfigInstance()->setInt32(minBuffer, minValue[i]);
    }
    if (Supla::Storage::ConfigInstance()->getInt32(maxBuffer, &maxValue[i])) {
      if (maxValue[i] <= 50 || maxValue[i] > 100) {
        maxValue[i] = DEFAULT_MAX_VALUE;
        Supla::Storage::ConfigInstance()->setInt32(maxBuffer, maxValue[i]);
      }
      SUPLA_LOG_DEBUG("# Param[%s]: %d", maxBuffer, maxValue[i]);
    } else {
      SUPLA_LOG_DEBUG("# Param[%s] is not set, setting default value: %d",
                                                 maxBuffer, DEFAULT_MAX_VALUE);
      maxValue[i] = DEFAULT_MAX_VALUE;
      Supla::Storage::ConfigInstance()->setInt32(maxBuffer, maxValue[i]);
    }
  }

  if (Supla::Storage::ConfigInstance()->getInt32(PWM_FREQ, &pwmFrequency)) {
    if (pwmFrequency <= 24 || pwmFrequency > 1526) {
      pwmFrequency = 223;
      Supla::Storage::ConfigInstance()->setInt32(PWM_FREQ, pwmFrequency);
    }
    SUPLA_LOG_DEBUG("# Param[%s]: %d", PWM_FREQ, pwmFrequency);
  } else {
    SUPLA_LOG_DEBUG("# Param[%s] is not set", PWM_FREQ);
  }

  if (selectConnection == WLAN) {
    wifi = new Supla::ESPWifi;
  } else {
#ifdef ARDUINO_ARCH_ESP32
    eth = new Supla::WT32_ETH01(1);
#endif
  }
  extmcp = new Supla::Control::ExtMCP23017(0x20);
  extpca = new Supla::Control::ExtPCA9685();
  extpca->setPWMFrequency(pwmFrequency);

  int pcaChannel[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
  int mcpChannel[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

  for (int i = 0; i < dimmersQuantity; i++) {
    dimmer_[i] = new Supla::Control::DimmerLeds(extpca, pcaChannel[i]);
    dimmer_[i]->setStep(btnStep);
    dimmer_[i]->setFadeEffectTime(fadeEffect_);
    dimmer_[i]->setMinMaxIterationDelay(iterationDelay);
    at_[i] = new Supla::Control::ActionTrigger();
    button_[i] = new Supla::Control::Button(extmcp, mcpChannel[i], true, true);
    button_[i]->setSwNoiseFilterDelay(100);
    button_[i]->setHoldTime(holdTimeValue);
    button_[i]->repeatOnHoldEvery(repeatOnHoldValue);
    button_[i]->setMulticlickTime(multiclickTimeValue);
    button_[i]->addAction(Supla::ITERATE_DIM_W, dimmer_[i], Supla::ON_HOLD);
    button_[i]->addAction(Supla::TOGGLE, dimmer_[i], Supla::ON_CLICK_1);
    at_[i]->setRelatedChannel(dimmer_[i]);
    at_[i]->attach(button_[i]);
    minValue[i] = map(minValue[i], 0, 100, 0, 1023);
    maxValue[i] = map(maxValue[i], 0, 100, 0, 1023);
    dimmer_[i]->setBrightnessLimits(minValue[i], maxValue[i]);
  }
  button_[0]->addAction(Supla::ENTER_CONFIG_MODE_OR_RESET_TO_FACTORY,
                                         SuplaDevice, Supla::ON_CLICK_3, true);
  webSrvVRelay = new Supla::Control::VirtualRelay(32);
  webSrvVRelay->setDefaultStateOff();
  webSrvVRelay->getChannel()->setDefault(SUPLA_CHANNELFNC_POWERSWITCH);
  webSrvVRelay->addAction(START_WEB_SERVER, custAct, Supla::ON_TURN_ON);
  webSrvVRelay->addAction(STOP_WEB_SERVER, custAct, Supla::ON_TURN_OFF);
  for (int i = 0; i < dimmersQuantity; i++) {
    vrelay_[i] = new Supla::Control::VirtualRelay(32);
    vrelay_[i]->setDefaultStateRestore();
    vrelay_[i]->getChannel()->setDefault(SUPLA_CHANNELFNC_POWERSWITCH);
    vrelay_[i]->addAction(DISABLE_BUTTON_0+i, custAct, Supla::ON_TURN_ON);
    vrelay_[i]->addAction(ENABLE_BUTTON_0+i, custAct, Supla::ON_TURN_OFF);
  }
  auto buttonCfg = new Supla::Control::Button(BUTTON_CFG_GPIO, true, true);
  buttonCfg->configureAsConfigButton(&SuplaDevice);

  new Supla::Html::DeviceInfo(&SuplaDevice);
#ifdef ARDUINO_ARCH_ESP8266
  new Supla::Html::WifiParameters;
#else
  new Supla::Html::ConnectionSettings;
#endif
  new Supla::Html::ProtocolParameters;
  new Supla::Html::CustomTextParameter(DEV_NAME, "Device name", 30);
  new Supla::Html::CustomParameter(DIM_QTY, "Dimmers quantity",
                                                          DEFAULT_DIMMERS_QTY);
  new Supla::Html::StatusLedParameters;
  new Supla::Html::DivEnd();
  new Supla::Html::DivBegin("box");
  new Supla::Html::H3Tag("Parameters Adjustment");
  new Supla::Html::CustomParameter(HT_VALUE, "Hold time (ms)",
                                                            DEFAULT_HOLD_TIME);
  new Supla::Html::CustomParameter(ROH_VALUE, "Repeat on hold (ms)",
                                                       DEFAULT_REPEAT_ON_HOLD);
  new Supla::Html::CustomParameter(MCT_VALUE, "Multiclick time (ms)",
                                                      DEFAULT_MULTICLICK_TIME);
  new Supla::Html::CustomParameter(BUTTON_STEP, "Button step (ms)",
                                                          DEFAULT_BUTTON_STEP);
  new Supla::Html::CustomParameter(FADE_EFFECT, "Fade effect (ms)",
                                                          DEFAULT_FADE_EFFECT);
  new Supla::Html::CustomParameter(ITERATION_DELAY, "Iteration delay (ms)",
                                                      DEFAULT_ITERATION_DELAY);
  for (int i = 0; i < dimmersQuantity; i++) {
    char minBuffer[10], maxBuffer[10], labelBuff1[25], labelBuff2[25];
    snprintf(minBuffer, sizeof(minBuffer), "min_%d", i);
    snprintf(maxBuffer, sizeof(maxBuffer), "max_%d", i);
    snprintf(labelBuff1, sizeof(labelBuff1), "Min.%d brightness (%%)", i+1);
    snprintf(labelBuff2, sizeof(labelBuff2), "Max.%d brightness (%%)", i+1);
    new Supla::Html::CustomParameter(minBuffer, labelBuff1);
    new Supla::Html::CustomParameter(maxBuffer, labelBuff2, 100);
  }
  new Supla::Html::CustomParameter(PWM_FREQ, "PWM frequency (Hz)", 223);

  httpUpdater.setup(suplaServer.getServerPtr(), "/update");
  SuplaDevice.setName(devName);
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
  SuplaDevice.begin();
  SuplaDevice.getSrpcLayer()->client->setDebugLogs(false);
};

void loop() {
  SuplaDevice.iterate();
};
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl

Return to “Projekty użytkowników”