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

Wklejam, może ktoś wykorzysta ;)

Jeszcze nie dokończony szkic dla kilku ściemniaczy (na razie dwa) wykorzytujący tylko zasoby supla-device z drobnymi modyfikacjami (dodałem do klasy parametrów wifi wybór interfejsu i uruchamianie AP w trybie konfiguracji w klasie ESPETH)

Code: Select all

#define WLAN 0
#define LAN 1
#define STATUS_LED_GPIO 2
#define DIMMER1_GPIO 12
#define DIMMER2_GPIO 14
#define BUTTON_CFG_DIM1_GPIO 4
#define BUTTON_CFG_DIM2_GPIO 5

#define DEFAULT_HOLD_TIME 400
#define DEFAULT_REPEAT_ON_HOLD 35
#define DEFAULT_MULTICLICK_TIME 350
#define DEFAULT_BUTTON_STEP 10
#define DEFAULT_FADE_EFFECT 500
#define DEFAULT_ITERATION_DELAY 750

#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/esp32eth.h>
Supla::ESPETH *eth = nullptr;
#endif
#include <supla/network/esp_web_server.h>
Supla::EspWebServer suplaServer;

#include <supla/control/button.h>
Supla::Control::Button *button_1 = nullptr;
Supla::Control::Button *button_2 = nullptr;
#include <supla/control/dimmer_leds.h>
Supla::Control::DimmerLeds *dimmer_1 = nullptr;
Supla::Control::DimmerLeds *dimmer_2 = nullptr;
#include <supla/control/action_trigger.h>
#include <supla/control/virtual_relay.h>
Supla::Control::VirtualRelay *vrelay_1 = nullptr;
Supla::Control::VirtualRelay *vrelay_2 = nullptr;

#include <supla/device/status_led.h>
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO); 
#include <supla/device/supla_ca_cert.h>

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

#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>

enum default_actions {
  START_WEB_SERVER,
  STOP_WEB_SERVER,
  ENABLE_BUTTONS,
  DISABLE_BUTTONS
};

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);
    }
    if (action == ENABLE_BUTTONS) {
      button_1->enableAction(-1, dimmer_1, -1);
      button_2->enableAction(-1, dimmer_2, -1);
      SUPLA_LOG_INFO("# buttons enabled");
    }
    if (action == DISABLE_BUTTONS) {
      button_1->disableAction(-1, dimmer_1, -1);
      button_2->disableAction(-1, dimmer_2, -1);
      SUPLA_LOG_INFO("# buttons disabled");
    }
  }
};
addedActionsClass *custAct = new addedActionsClass;

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 MINIMUM_1[] = "minimum_1";
int32_t min1Value = 0;
const char MAXIMUM_1[] = "maximum_1";
int32_t max1Value = 100;
const char MINIMUM_2[] = "minimum_2";
int32_t min2Value = 0;
const char MAXIMUM_2[] = "maximum_2";
int32_t max2Value = 100;
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;

void setup() {

  Serial.begin(115200);
  new Supla::Clock;
  
  Supla::Storage::Init();
  
#ifdef ARDUINO_ARCH_ESP32
  Supla::Storage::ConfigInstance()->getInt8(
                        Supla::Html::ConnectionSettingsTag, &selectConnection);
#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(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);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MINIMUM_1, &min1Value)) {
    if (min1Value < 0 || min1Value >= 50) {
      min1Value = 0;
      Supla::Storage::ConfigInstance()->setInt32(MINIMUM_1, min1Value);
    } 
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MINIMUM_1, min1Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MINIMUM_1);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MAXIMUM_1, &max1Value)) {
    if (max1Value <= 50 || max1Value > 100) {
      max1Value = 100;
      Supla::Storage::ConfigInstance()->setInt32(MAXIMUM_1, max1Value);
    }
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MAXIMUM_1, max1Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MAXIMUM_1);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MINIMUM_2, &min2Value)) {
    if (min2Value < 0 || min2Value >= 50) {
      min2Value = 0;
      Supla::Storage::ConfigInstance()->setInt32(MINIMUM_2, min2Value);
    }
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MINIMUM_2, min2Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MINIMUM_2);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MAXIMUM_2, &max2Value)) {
    if (max2Value <= 50 || max2Value > 100) {
      max2Value = 100;
      Supla::Storage::ConfigInstance()->setInt32(MAXIMUM_2, max2Value);
    }
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MAXIMUM_2, max2Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MAXIMUM_2);
  }
  
  if (selectConnection == WLAN) {
    wifi = new Supla::ESPWifi;
  } else {
#ifdef ARDUINO_ARCH_ESP32
    eth = new Supla::ESPETH(1);
#endif
  }
  
  min1Value = map(min1Value, 0, 100, 0, 1023);
  max1Value = map(max1Value, 0, 100, 0, 1023);
  dimmer_1 = new Supla::Control::DimmerLeds(DIMMER1_GPIO);
  dimmer_1->setStep(btnStep);
  dimmer_1->setFadeEffectTime(fadeEffect_);
  dimmer_1->setMinMaxIterationDelay(iterationDelay);
  dimmer_1->setBrightnessLimits(min1Value, max1Value);
  
  min2Value = map(min2Value, 0, 100, 0, 1023);
  max2Value = map(max2Value, 0, 100, 0, 1023);
  dimmer_2 = new Supla::Control::DimmerLeds(DIMMER2_GPIO);
  dimmer_2->setStep(btnStep);
  dimmer_2->setFadeEffectTime(fadeEffect_);
  dimmer_2->setMinMaxIterationDelay(iterationDelay);
  dimmer_2->setBrightnessLimits(min2Value, max2Value);

  auto at_1 = new Supla::Control::ActionTrigger();
  auto at_2 = new Supla::Control::ActionTrigger();

  button_1 = new Supla::Control::Button(BUTTON_CFG_DIM1_GPIO, true, true);
  button_1->setSwNoiseFilterDelay(100);
  button_1->setHoldTime(holdTimeValue);
  button_1->repeatOnHoldEvery(repeatOnHoldValue);
  button_1->setMulticlickTime(multiclickTimeValue);
  button_1->addAction(Supla::ITERATE_DIM_W, dimmer_1, Supla::ON_HOLD);
  button_1->addAction(Supla::TOGGLE, dimmer_1, Supla::ON_CLICK_1);
  
  at_1->setRelatedChannel(dimmer_1);
  at_1->attach(button_1);

  button_2 = new Supla::Control::Button(BUTTON_CFG_DIM2_GPIO, true, true);
  button_2->setSwNoiseFilterDelay(100);
  button_2->setHoldTime(holdTimeValue);
  button_2->repeatOnHoldEvery(repeatOnHoldValue);
  button_2->setMulticlickTime(multiclickTimeValue);
  button_2->addAction(Supla::ITERATE_DIM_W, dimmer_2, Supla::ON_HOLD);
  button_2->addAction(Supla::TOGGLE, dimmer_2, Supla::ON_CLICK_1);
  button_2->addAction(Supla::ENTER_CONFIG_MODE_OR_RESET_TO_FACTORY,
                                         SuplaDevice, Supla::ON_CLICK_3, true);
  at_2->setRelatedChannel(dimmer_2);
  at_2->attach(button_2);

  vrelay_1 = new Supla::Control::VirtualRelay(32);
  vrelay_1->setDefaultStateOff();
  vrelay_1->getChannel()->setDefault(SUPLA_CHANNELFNC_POWERSWITCH);
  vrelay_1->addAction(START_WEB_SERVER, custAct, Supla::ON_TURN_ON);
  vrelay_1->addAction(STOP_WEB_SERVER, custAct, Supla::ON_TURN_OFF);

  vrelay_2 = new Supla::Control::VirtualRelay(32);
  vrelay_2->setDefaultStateRestore();
  vrelay_2->getChannel()->setDefault(SUPLA_CHANNELFNC_POWERSWITCH);
  vrelay_2->addAction(DISABLE_BUTTONS, custAct, Supla::ON_TURN_ON);
  vrelay_2->addAction(ENABLE_BUTTONS, custAct, Supla::ON_TURN_OFF);
  
  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::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);
  new Supla::Html::CustomParameter(MINIMUM_1, "Min.1 brightness (%)");
  new Supla::Html::CustomParameter(MAXIMUM_1, "Max.1 brightness (%)", 100);
  new Supla::Html::CustomParameter(MINIMUM_2, "Min.2 brightness (%)");
  new Supla::Html::CustomParameter(MAXIMUM_2, "Max.2 brightness (%)", 100);
  
  SuplaDevice.setName(devName);
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.begin();
  SuplaDevice.getSrpcLayer()->client->setDebugLogs(false);
};

void loop() {
  SuplaDevice.iterate();
};
NIestety brakuje w supla-device możliwości aktualizacji softu poprzez www, ale może wkrótce (czas nieokreślony ;)) zostanie dodana.
.
You do not have the required permissions to view the files attached to this post.
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
User avatar
Duch__
Posts: 2199
Joined: Wed Aug 24, 2016 7:26 pm
Location: Opole
Been thanked: 6 times

Post

Na jaki procesor to pisałeś?
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

Duch__ wrote: Sat Nov 04, 2023 7:45 pm Na jaki procesor to pisałeś?
Szkic działa na ESP8266 i ESP32.
Ifdef'ami usuwam wszystko co związane z LAN-em przy kompilacji dla ESP8266
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
LukaszH
Posts: 710
Joined: Sat Dec 14, 2019 11:49 pm

Post

Fajnie to wygląda :)
Dopytam tylko czy to zadziała z LAN8720 ? Dla przykładu takie coś: LAN8720
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

LukaszH wrote: Sun Nov 05, 2023 7:34 pm Fajnie to wygląda :)
Dopytam tylko czy to zadziała z LAN8720 ?
Tak, dokładnie ten moduł mam teraz podpięty do ESP32.
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: Sat Nov 04, 2023 6:34 pm Wklejam, może ktoś wykorzysta ;)

Jeszcze nie dokończony szkic dla kilku ściemniaczy (na razie dwa) wykorzytujący tylko zasoby supla-device z drobnymi modyfikacjami (dodałem do klasy parametrów wifi wybór interfejsu i uruchamianie AP w trybie konfiguracji w klasie ESPETH)

Code: Select all

#define WLAN 0
#define LAN 1
#define STATUS_LED_GPIO 2
#define DIMMER1_GPIO 12
#define DIMMER2_GPIO 14
#define BUTTON_CFG_DIM1_GPIO 4
#define BUTTON_CFG_DIM2_GPIO 5

#define DEFAULT_HOLD_TIME 400
#define DEFAULT_REPEAT_ON_HOLD 35
#define DEFAULT_MULTICLICK_TIME 350
#define DEFAULT_BUTTON_STEP 10
#define DEFAULT_FADE_EFFECT 500
#define DEFAULT_ITERATION_DELAY 750

#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/esp32eth.h>
Supla::ESPETH *eth = nullptr;
#endif
#include <supla/network/esp_web_server.h>
Supla::EspWebServer suplaServer;

#include <supla/control/button.h>
Supla::Control::Button *button_1 = nullptr;
Supla::Control::Button *button_2 = nullptr;
#include <supla/control/dimmer_leds.h>
Supla::Control::DimmerLeds *dimmer_1 = nullptr;
Supla::Control::DimmerLeds *dimmer_2 = nullptr;
#include <supla/control/action_trigger.h>
#include <supla/control/virtual_relay.h>
Supla::Control::VirtualRelay *vrelay_1 = nullptr;
Supla::Control::VirtualRelay *vrelay_2 = nullptr;

#include <supla/device/status_led.h>
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO); 
#include <supla/device/supla_ca_cert.h>

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

#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>

enum default_actions {
  START_WEB_SERVER,
  STOP_WEB_SERVER,
  ENABLE_BUTTONS,
  DISABLE_BUTTONS
};

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);
    }
    if (action == ENABLE_BUTTONS) {
      button_1->enableAction(-1, dimmer_1, -1);
      button_2->enableAction(-1, dimmer_2, -1);
      SUPLA_LOG_INFO("# buttons enabled");
    }
    if (action == DISABLE_BUTTONS) {
      button_1->disableAction(-1, dimmer_1, -1);
      button_2->disableAction(-1, dimmer_2, -1);
      SUPLA_LOG_INFO("# buttons disabled");
    }
  }
};
addedActionsClass *custAct = new addedActionsClass;

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 MINIMUM_1[] = "minimum_1";
int32_t min1Value = 0;
const char MAXIMUM_1[] = "maximum_1";
int32_t max1Value = 100;
const char MINIMUM_2[] = "minimum_2";
int32_t min2Value = 0;
const char MAXIMUM_2[] = "maximum_2";
int32_t max2Value = 100;
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;

void setup() {

  Serial.begin(115200);
  new Supla::Clock;
  
  Supla::Storage::Init();
  
#ifdef ARDUINO_ARCH_ESP32
  Supla::Storage::ConfigInstance()->getInt8(
                        Supla::Html::ConnectionSettingsTag, &selectConnection);
#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(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);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MINIMUM_1, &min1Value)) {
    if (min1Value < 0 || min1Value >= 50) {
      min1Value = 0;
      Supla::Storage::ConfigInstance()->setInt32(MINIMUM_1, min1Value);
    } 
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MINIMUM_1, min1Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MINIMUM_1);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MAXIMUM_1, &max1Value)) {
    if (max1Value <= 50 || max1Value > 100) {
      max1Value = 100;
      Supla::Storage::ConfigInstance()->setInt32(MAXIMUM_1, max1Value);
    }
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MAXIMUM_1, max1Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MAXIMUM_1);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MINIMUM_2, &min2Value)) {
    if (min2Value < 0 || min2Value >= 50) {
      min2Value = 0;
      Supla::Storage::ConfigInstance()->setInt32(MINIMUM_2, min2Value);
    }
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MINIMUM_2, min2Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MINIMUM_2);
  }

  if (Supla::Storage::ConfigInstance()->getInt32(MAXIMUM_2, &max2Value)) {
    if (max2Value <= 50 || max2Value > 100) {
      max2Value = 100;
      Supla::Storage::ConfigInstance()->setInt32(MAXIMUM_2, max2Value);
    }
    SUPLA_LOG_DEBUG(" **** Param[%s]: %d", MAXIMUM_2, max2Value);
  } else {
    SUPLA_LOG_DEBUG(" **** Param[%s] is not set", MAXIMUM_2);
  }
  
  if (selectConnection == WLAN) {
    wifi = new Supla::ESPWifi;
  } else {
#ifdef ARDUINO_ARCH_ESP32
    eth = new Supla::ESPETH(1);
#endif
  }
  
  min1Value = map(min1Value, 0, 100, 0, 1023);
  max1Value = map(max1Value, 0, 100, 0, 1023);
  dimmer_1 = new Supla::Control::DimmerLeds(DIMMER1_GPIO);
  dimmer_1->setStep(btnStep);
  dimmer_1->setFadeEffectTime(fadeEffect_);
  dimmer_1->setMinMaxIterationDelay(iterationDelay);
  dimmer_1->setBrightnessLimits(min1Value, max1Value);
  
  min2Value = map(min2Value, 0, 100, 0, 1023);
  max2Value = map(max2Value, 0, 100, 0, 1023);
  dimmer_2 = new Supla::Control::DimmerLeds(DIMMER2_GPIO);
  dimmer_2->setStep(btnStep);
  dimmer_2->setFadeEffectTime(fadeEffect_);
  dimmer_2->setMinMaxIterationDelay(iterationDelay);
  dimmer_2->setBrightnessLimits(min2Value, max2Value);

  auto at_1 = new Supla::Control::ActionTrigger();
  auto at_2 = new Supla::Control::ActionTrigger();

  button_1 = new Supla::Control::Button(BUTTON_CFG_DIM1_GPIO, true, true);
  button_1->setSwNoiseFilterDelay(100);
  button_1->setHoldTime(holdTimeValue);
  button_1->repeatOnHoldEvery(repeatOnHoldValue);
  button_1->setMulticlickTime(multiclickTimeValue);
  button_1->addAction(Supla::ITERATE_DIM_W, dimmer_1, Supla::ON_HOLD);
  button_1->addAction(Supla::TOGGLE, dimmer_1, Supla::ON_CLICK_1);
  
  at_1->setRelatedChannel(dimmer_1);
  at_1->attach(button_1);

  button_2 = new Supla::Control::Button(BUTTON_CFG_DIM2_GPIO, true, true);
  button_2->setSwNoiseFilterDelay(100);
  button_2->setHoldTime(holdTimeValue);
  button_2->repeatOnHoldEvery(repeatOnHoldValue);
  button_2->setMulticlickTime(multiclickTimeValue);
  button_2->addAction(Supla::ITERATE_DIM_W, dimmer_2, Supla::ON_HOLD);
  button_2->addAction(Supla::TOGGLE, dimmer_2, Supla::ON_CLICK_1);
  button_2->addAction(Supla::ENTER_CONFIG_MODE_OR_RESET_TO_FACTORY,
                                         SuplaDevice, Supla::ON_CLICK_3, true);
  at_2->setRelatedChannel(dimmer_2);
  at_2->attach(button_2);

  vrelay_1 = new Supla::Control::VirtualRelay(32);
  vrelay_1->setDefaultStateOff();
  vrelay_1->getChannel()->setDefault(SUPLA_CHANNELFNC_POWERSWITCH);
  vrelay_1->addAction(START_WEB_SERVER, custAct, Supla::ON_TURN_ON);
  vrelay_1->addAction(STOP_WEB_SERVER, custAct, Supla::ON_TURN_OFF);

  vrelay_2 = new Supla::Control::VirtualRelay(32);
  vrelay_2->setDefaultStateRestore();
  vrelay_2->getChannel()->setDefault(SUPLA_CHANNELFNC_POWERSWITCH);
  vrelay_2->addAction(DISABLE_BUTTONS, custAct, Supla::ON_TURN_ON);
  vrelay_2->addAction(ENABLE_BUTTONS, custAct, Supla::ON_TURN_OFF);
  
  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::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);
  new Supla::Html::CustomParameter(MINIMUM_1, "Min.1 brightness (%)");
  new Supla::Html::CustomParameter(MAXIMUM_1, "Max.1 brightness (%)", 100);
  new Supla::Html::CustomParameter(MINIMUM_2, "Min.2 brightness (%)");
  new Supla::Html::CustomParameter(MAXIMUM_2, "Max.2 brightness (%)", 100);
  
  SuplaDevice.setName(devName);
  SuplaDevice.setSuplaCACert(suplaCACert);
  SuplaDevice.begin();
  SuplaDevice.getSrpcLayer()->client->setDebugLogs(false);
};

void loop() {
  SuplaDevice.iterate();
};
NIestety brakuje w supla-device możliwości aktualizacji softu poprzez www, ale może wkrótce (czas nieokreślony ;)) zostanie dodana.
.
Dzień dobry,
u mnie w zaktualizowanej bibliotece nie ma pliku connection_settings.h. Czy mógłbyś go podesłać?
You do not have the required permissions to view the files attached to this post.
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: Wed Nov 08, 2023 12:23 am Dzień dobry,
u mnie w zaktualizowanej bibliotece nie ma pliku connection_settings.h. Czy mógłbyś go podesłać?
Oficjalnie go nie ma w bibliotece.
Pliki są w załączniku pierwszego posta
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: Wed Nov 08, 2023 5:45 am
jaku2k wrote: Wed Nov 08, 2023 12:23 am Dzień dobry,
u mnie w zaktualizowanej bibliotece nie ma pliku connection_settings.h. Czy mógłbyś go podesłać?
Oficjalnie go nie ma w bibliotece.
Pliki są w załączniku pierwszego posta
Dziękuję, nie zauważyłem.
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

Mała aktualizacja szkicu ;)
Dorzuciłem ekspander PCA9685. Wymagało to kosmetycznej modyfikacji klasy DimmerLeds.

Code: Select all

#define DIMMER1_PCA_CHANNEL 0
#define DIMMER2_PCA_CHANNEL 15

#include <supla/control/EXT_PCA9685.h>
Supla::Control::ExtPCA9685 *extpca = nullptr;

setup() {
  Wire.begin(4, 5);
  extpca = new Supla::Control::ExtPCA9685();
  dimmer_1 = new Supla::Control::DimmerLeds(extpca, DIMMER1_PCA_CHANNEL);
  dimmer_2 = new Supla::Control::DimmerLeds(extpca, DIMMER2_PCA_CHANNEL);
}
You do not have the required permissions to view the files attached to this post.
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
radzik_r
Posts: 468
Joined: Sun Aug 11, 2019 5:32 pm
Has thanked: 1 time
Been thanked: 2 times

Post

lukfud wrote: Sun Nov 12, 2023 1:19 pm
https://github.com/RobTillaart/PCA9685_RT

Return to “Projekty użytkowników”