Pierwszy projekt supla device

Rino
Posts: 2
Joined: Sat Mar 28, 2026 2:43 pm

Post

Cześć,
próbuje zrobić swój pierwszy projekt na ESP z wykorzystaniem SuplaDevice w Arduino IDE.

Są to tylko dwa przyciski sterujące dwoma przekaźnikami plus trzeci przycisk jako CONFIG.
Bazuję na przykładach z biblioteki dostępnych z poziomu Arduino IDE, lecz niestety nie działa mi to w pełni.

Program wgrywa się bez problemu, ESP startuje i łączy się z cloudem Supli. Kanały z przekaźnikami są widoczne i mogę nimi sterować, lecz nie działają mi przyciski, które powinny sterować przekaźnikami. W logach w serial monitorze widzę, że podczas klikania wykrywane są eventy button pressed i released, ale nie powoduje to zmiany stanu przekaźnika czy też wysłania jakiejkolwiek informacji do clouda w postaci action triggera.

Dodam, że wgrywając przykładowy program ConfigModeInputs który posiada jeden przekaźnik i jeden przycisk, to wszystko działa poprawnie.

Poniżej zamieszczam mój kod:

Code: Select all

#define RELAY_1_GPIO 4
#define RELAY_2_GPIO 5

#define BUTTON_RELAY_1_GPIO 12
#define BUTTON_RELAY_2_GPIO 14
#define BUTTON_CONFIG_MODE_GPIO 13

#define STATUS_LED_GPIO 0 //TX

#include <SuplaDevice.h>
#include <supla/network/esp_wifi.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>

// Includes for HTML elements
#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/events.h>

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

// This class provides Wi-Fi network connectivity for your device
Supla::ESPWifi wifi;

// This class provides web server to handle config mode
Supla::EspWebServer suplaServer;

// This class provides configuration storage (like SSID, password, all
// user defined parameters, etc. We use LittleFS.
Supla::LittleFsConfig configSupla;

Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state

void setup() {

  Serial.begin(115200);

  // Channels configuration
  // CH 1 - Relay
  auto r1 = new Supla::Control::Relay(RELAY_1_GPIO);
  // CH 2 - Relay
  auto r2 = new Supla::Control::Relay(RELAY_2_GPIO);

  // CH 1 - Action trigger
  auto at1 = new Supla::Control::ActionTrigger();
  // CH 2 - Action trigger
  auto at2 = new Supla::Control::ActionTrigger();

  // Buttons configuration
  auto buttonRelay1 = new Supla::Control::Button(BUTTON_RELAY_1_GPIO, true, true);
  auto buttonRelay2 = new Supla::Control::Button(BUTTON_RELAY_2_GPIO, true, true);
  auto buttonConfigMode = new Supla::Control::Button(BUTTON_CONFIG_MODE_GPIO , false, true);

  buttonConfigMode->configureAsConfigButton(&SuplaDevice);

  buttonRelay1->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1);
  buttonRelay2->addAction(Supla::TOGGLE, r2, Supla::ON_CLICK_1);

  // Action trigger configuration
  at1->setRelatedChannel(r1);
  at1->attach(buttonRelay1);

  at2->setRelatedChannel(r2);
  at2->attach(buttonRelay2);

  // HTML www component
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;
  new Supla::Html::StatusLedParameters;

  SuplaDevice.setInitialMode(Supla::InitialMode::StartInCfgMode);
  SuplaDevice.begin();
}

void loop() {
  SuplaDevice.iterate();
}
Byłbym bardzo wdzięczny na naprowadzenie mnie w czym tutaj jest problem.

Pozdrawiam.
User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

Jak masz przyciski podłączone? Sterujesz plusem, czy masą? Według tego co masz ustawione to masz programowy Pullup i odwróconą logikę (jedynka jest gdy podasz masę). Usuń też do testów linie

Code: Select all

/ CH 1 - Action trigger
  auto at1 = new Supla::Control::ActionTrigger();
  // CH 2 - Action trigger
  auto at2 = new Supla::Control::ActionTrigger();
Oraz

Code: Select all

/ Action trigger configuration
  at1->setRelatedChannel(r1);
  at1->attach(buttonRelay1);

  at2->setRelatedChannel(r2);
  at2->attach(buttonRelay2);
Całą logikę masz ustawioną w addaction.
Możesz zamiast ON_CLICK_1 dać ON_PRESS

Jak zadziała trzeba pokombinować z AT
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005
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

Używasz eventu on click 1x, który działa gdy skonfiguruje się wielokliki, których nie ustawiłeś.
Także tutaj on press pomoże.
Lub trzeba ustawić na button setMuticlickTime (albo coś podobnego).

Na relay była też chyba metoda attach, która automatycznie skonfiguruje przycisk
Najlepsze suple dla Twojego domu :mrgreen:
Rino
Posts: 2
Joined: Sat Mar 28, 2026 2:43 pm

Post

veeroos wrote: Sat Mar 28, 2026 4:10 pm Jak masz przyciski podłączone? Sterujesz plusem, czy masą? Według tego co masz ustawione to masz programowy Pullup i odwróconą logikę (jedynka jest gdy podasz masę).
Taka konfiguracja była zamierzona. Steruję masą.
Możesz zamiast ON_CLICK_1 dać ON_PRESS
ON_PRESS działa :). Dzięki!
klew wrote: Sat Mar 28, 2026 4:22 pm Używasz eventu on click 1x, który działa gdy skonfiguruje się wielokliki, których nie ustawiłeś.
Także tutaj on press pomoże.
Lub trzeba ustawić na button setMuticlickTime (albo coś podobnego).
Bazowałem na przykładzie z biblioteki i tam było na ON_CLICK_1 i działało, a nie widziałem żeby były gdzieś konfigurowane wielokliki.
Dopiero teraz przyjrzałem się funkcji configureAsConfigButton() i to ona to ustawia: setMulticlickTime(300, isBistable());.

Także jakby ktoś potrzebował taki podstawowy program do ESP8266, to poniżej zamieszczam poprawiony kod:

Code: Select all

#define RELAY_1_GPIO 4
#define RELAY_2_GPIO 5

#define BUTTON_RELAY_1_GPIO 12
#define BUTTON_RELAY_2_GPIO 14
#define BUTTON_CONFIG_MODE_GPIO 13

#define STATUS_LED_GPIO 3

#include <SuplaDevice.h>
#include <supla/network/esp_wifi.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/control/virtual_relay.h>

// Includes for HTML elements
#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/events.h>

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

// This class provides Wi-Fi network connectivity for your device
Supla::ESPWifi wifi;

// This class provides web server to handle config mode
Supla::EspWebServer suplaServer;

// This class provides configuration storage (like SSID, password, all
// user defined parameters, etc. We use LittleFS.
Supla::LittleFsConfig configSupla;

Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state

void setup() {

  Serial.begin(115200);

  // Channels configuration
  // CH 1 - Relay
  auto r1 = new Supla::Control::Relay(RELAY_1_GPIO);
  r1->setDefaultFunction(SUPLA_CHANNELFNC_LIGHTSWITCH);
  r1->setDefaultStateOff();
  // CH 2 - Relay
  auto r2 = new Supla::Control::Relay(RELAY_2_GPIO);
  r2->setDefaultFunction(SUPLA_CHANNELFNC_LIGHTSWITCH);
  r2->setDefaultStateOff();

  // Action trigger configuration
  // AT 1 - Action trigger
  auto at1 = new Supla::Control::ActionTrigger();
  // AT 2 - Action trigger
  auto at2 = new Supla::Control::ActionTrigger();

  // Buttons configuration
  auto buttonRelay1 = new Supla::Control::Button(BUTTON_RELAY_1_GPIO, true, true);
  auto buttonRelay2 = new Supla::Control::Button(BUTTON_RELAY_2_GPIO, true, true);
  auto buttonConfigMode = new Supla::Control::Button(BUTTON_CONFIG_MODE_GPIO , true, true);

  buttonConfigMode->configureAsConfigButton(&SuplaDevice);
  buttonRelay1->addAction(Supla::TOGGLE, r1, Supla::ON_PRESS);
  buttonRelay2->addAction(Supla::TOGGLE, r2, Supla::ON_PRESS);

  // Action trigger configuration
  at1->setRelatedChannel(r1);
  at1->attach(buttonRelay1);

  at2->setRelatedChannel(r2);
  at2->attach(buttonRelay2);

  // HTML www component
  new Supla::Html::DeviceInfo(&SuplaDevice);
  new Supla::Html::WifiParameters;
  new Supla::Html::ProtocolParameters;
  new Supla::Html::StatusLedParameters;

  // Set custom device name
  SuplaDevice.setName("SUPLA-EXAMPLE");
  
  SuplaDevice.setInitialMode(Supla::InitialMode::StartInCfgMode);
  SuplaDevice.begin();
}

void loop() {
  SuplaDevice.iterate();
}

User avatar
veeroos
Posts: 1081
Joined: Sun Mar 20, 2022 9:30 am
Location: Głogów
Has thanked: 1 time
Been thanked: 9 times

Post

Krzysztofowi bardziej chodziło o ustawienie tych parametrów

Code: Select all

  
buttonRelay1->setHoldTime(1000);
buttonRelay1->setMulticlickTime(300);
buttonRelay2->setHoldTime(1000);
buttonRelay2->setMulticlickTime(300);
Ale ON_PRESS też będzie działał dobrze
Zamel Mew-01, Zamel PEW-01, Zamel SBW-01, Zamel THW-01, Zamel SRW-01, Zamel mSLW-02, Auraton BOX + Indor Sensor, Airly Gate By Veeroos, Zigbee to Supla Gateway + sensors, Zamel SGW-01 and more

https://github.com/v33r005

Return to “Pomoc”