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();
}
Pozdrawiam.
