hello!
how can i change the statut of the relay on supla when i use push button?
controle realy using supla app and button
-
caps_t
- Posts: 5
- Joined: Fri Dec 09, 2022 6:49 pm
Card esp8266
software arduino
this is my code every thing is working except when i use the push button there is no update on supla app ( imean when i on the relay using the push button it geos on but on supla app it still have the off icone)
software arduino
this is my code every thing is working except when i use the push button there is no update on supla app ( imean when i on the relay using the push button it geos on but on supla app it still have the off icone)
Code: Select all
#include <WiFiManager.h>
#include <SuplaDevice.h>
#include <supla/sensor/DHT.h>
#include <supla/control/relay.h>
#include <supla/condition.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] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Supla::EthernetShield ethernet(mac);
// 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("", "");
#endif
#define DHT1PIN 5
#define DHT1TYPE DHT11
/*#define DHT2PIN 25
#define DHT2TYPE DHT22*/
void setup() {
pinMode(14,OUTPUT); // led pin as output
pinMode(4,INPUT_PULLUP); // d2 as input with internai pullup enabled
Serial.begin(115200);
WiFiManager wm;
wm.resetSettings();
bool res;
res = wm.autoConnect("ESP8266","xxxx");
if(!res) {
Serial.println("Failed to connect :(");
}
else {
Serial.println("connected... :)");
}
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] ={xxxx};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxxx};
// CHANNEL0 - DHT22 Sensor
new Supla::Sensor::DHT(DHT1PIN, DHT1TYPE);
new Supla::Control::Relay(14,0);
new Supla::Control::Relay(12,0);
SuplaDevice.begin(GUID, // Global Unique Identifier
"xxxx.supla.org", // SUPLA server address
"[email protected]", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
int buttonstate1, relaysatate1, buttonstate2, relaysatate2;
void loop() {
SuplaDevice.iterate();
buttonstate1 = digitalRead(4);
relaysatate1 = digitalRead(14);
buttonstate2 = digitalRead(0);
relaysatate2 = digitalRead(12);
if(buttonstate1 == LOW) // if pressed
{
delay(500);
if (relaysatate1 == LOW)
digitalWrite(14,HIGH);
else
digitalWrite(14,LOW);
}
if(buttonstate2 == LOW) // if pressed
{
delay(500);
if (relaysatate2 == LOW)
digitalWrite(12,HIGH);
else
digitalWrite(12,LOW);
}
}-
klew
- Posts: 13908
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
- Has thanked: 134 times
- Been thanked: 137 times
The easiest way is to use components provided by SuplaDevice library. Beside of Relay, SuplaDevice also have Button class. You can also manage Wi-Fi and Supla server settings via web interface that is available.caps_t wrote: Mon Dec 12, 2022 7:26 pm Card esp8266
software arduino
this is my code every thing is working except when i use the push button there is no update on supla app ( imean when i on the relay using the push button it geos on but on supla app it still have the off icone)
Please take a look at WebInterface example. It also contain some RollerShutter related config, but it should be ease to remove them.
https://github.com/SUPLA/supla-device/b ... erface.ino
Najlepsze suple dla Twojego domu 
-
caps_t
- Posts: 5
- Joined: Fri Dec 09, 2022 6:49 pm
thank you for your reply i tried to change your code and it didnt work
actually i want to do like this project
https://www.youtube.com/watch?v=4ywi2-nQy2o
actually i want to do like this project
https://www.youtube.com/watch?v=4ywi2-nQy2o
-
klew
- Posts: 13908
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
- Has thanked: 134 times
- Been thanked: 137 times
What is not working?caps_t wrote: Tue Dec 13, 2022 12:03 am thank you for your reply i tried to change your code and it didnt work
actually i want to do like this project
https://www.youtube.com/watch?v=4ywi2-nQy2o
BTW. if you'll reply to my message with a quote, then I'll be notified and I'll reply quicker
Najlepsze suple dla Twojego domu 
-
caps_t
- Posts: 5
- Joined: Fri Dec 09, 2022 6:49 pm
klew wrote: Tue Dec 13, 2022 12:31 amWhat is not working?caps_t wrote: Tue Dec 13, 2022 12:03 am thank you for your reply i tried to change your code and it didnt work
actually i want to do like this project
https://www.youtube.com/watch?v=4ywi2-nQy2o
BTW. if you'll reply to my message with a quote, then I'll be notified and I'll reply quicker![]()
i tried to modify your code but the relay goes on and off quicly.. and there areno change on supla app.
-
klew
- Posts: 13908
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
- Has thanked: 134 times
- Been thanked: 137 times
Please share your modified code herecaps_t wrote: Tue Dec 13, 2022 2:44 am
i tried to modify your code but the relay goes on and off quicly.. and there areno change on supla app.
Najlepsze suple dla Twojego domu 
-
caps_t
- Posts: 5
- Joined: Fri Dec 09, 2022 6:49 pm
this is my first code it work perfectly but there no change on the icone on supla app when i push botton (for exemple when i turn on the relay using the button the relay goes on but on supla app the icone show that relay is off)
Code: Select all
#include <WiFiManager.h>
#include <SuplaDevice.h>
#include <supla/sensor/DHT.h>
#include <supla/control/relay.h>
#include <supla/condition.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] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Supla::EthernetShield ethernet(mac);
// 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("", "");
#endif
#define DHT1PIN 5
#define DHT1TYPE DHT11
/*#define DHT2PIN 25
#define DHT2TYPE DHT22*/
void setup() {
pinMode(14,OUTPUT); // led pin as output
pinMode(4,INPUT_PULLUP); // d2 as input with internai pullup enabled
Serial.begin(115200);
WiFiManager wm;
wm.resetSettings();
bool res;
res = wm.autoConnect("ESP8266","xxxx");
if(!res) {
Serial.println("Failed to connect :(");
}
else {
Serial.println("connected... :)");
}
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] ={deleted };
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {deleted };
// CHANNEL0 - DHT22 Sensor
new Supla::Sensor::DHT(DHT1PIN, DHT1TYPE);
new Supla::Control::Relay(14,0);
new Supla::Control::Relay(12,0);
SuplaDevice.begin(GUID, // Global Unique Identifier
"xxxxx.supla.org", // SUPLA server address
"[email protected]", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
int buttonstate1, relaysatate1, buttonstate2, relaysatate2;
void loop() {
SuplaDevice.iterate();
buttonstate1 = digitalRead(4);
relaysatate1 = digitalRead(14);
if(buttonstate1 == LOW) // if pressed
{
if (relaysatate1 == LOW)
digitalWrite(14,HIGH);
else
digitalWrite(14,LOW);
}
buttonstate2 = digitalRead(0);
relaysatate2 = digitalRead(12);
if(buttonstate2 == LOW) // if pressed
{
if (relaysatate2 == LOW)
digitalWrite(12,HIGH);
else
digitalWrite(12,LOW);
}
}Code: Select all
#include <WiFiManager.h>
#include <SuplaDevice.h>
#include <supla/sensor/DHT.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/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/device/supla_ca_cert.h>
#include <supla/events.h>
#include <supla/condition.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] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
Supla::EthernetShield ethernet(mac);
// 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("", "");
#endif
#define DHT1PIN 5
#define DHT1TYPE DHT11
/*#define DHT2PIN 25
#define DHT2TYPE DHT22*/
Supla::Device::StatusLed statusLed(14, true); // inverted state
Supla::EspWebServer suplaServer;
// HTML www component (they appear in sections according to creation
// sequence)
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Html::StatusLedParameters htmlStatusLed;
void setup() {
pinMode(14, OUTPUT); // led pin as output
pinMode(4, INPUT_PULLUP); // d2 as input with internai pullup enabled
Serial.begin(115200);
WiFiManager wm;
wm.resetSettings();
bool res;
res = wm.autoConnect("ESP8266", "xxxx");
if (!res) {
Serial.println("Failed to connect :(");
} else {
Serial.println("connected... :)");
}
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = { deleted };
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = { deleted };
// CHANNEL0 - DHT22 Sensor
new Supla::Sensor::DHT(DHT1PIN, DHT1TYPE);
new Supla::Control::Relay(14, 0);
new Supla::Control::Relay(12, 0);
SuplaDevice.begin(GUID, // Global Unique Identifier
"xxxx.supla.org", // SUPLA server address
"[email protected]", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
// CH 0 - Roller shutter
auto rs1 = new Supla::Control::RollerShutter(14, 14, true);
// CH 0 - Roller shutter
auto rs2 = new Supla::Control::RollerShutter(12, 12, true);
// CH 1 - Relay
auto r1 = new Supla::Control::Relay(14);
// CH 2 - Relay
auto r2 = new Supla::Control::Relay(12);
// CH 3 - Action trigger
auto at1 = new Supla::Control::ActionTrigger();
// CH 4 - Action trigger
auto at2 = new Supla::Control::ActionTrigger();
// CH 5 - Action trigger
auto at3 = new Supla::Control::ActionTrigger();
// CH 6 - Action trigger
auto at4 = new Supla::Control::ActionTrigger();
// CH 7 - Action trigger
auto at5 = new Supla::Control::ActionTrigger();
// CH 8 - Action trigger
auto at6 = new Supla::Control::ActionTrigger();
// Buttons configuration
auto button1Open = new Supla::Control::Button(4, true, true);
auto button1Close = new Supla::Control::Button(4, true, true);
auto button2Open = new Supla::Control::Button(0, true, true);
auto button2Close = new Supla::Control::Button(0, true, true);
auto buttonCfgRelay1 = new Supla::Control::Button(14, true, true);
auto buttonCfgRelay2 = new Supla::Control::Button(12, true, true);
button1Open->addAction(Supla::OPEN_OR_STOP, *rs1, Supla::ON_PRESS);
button1Open->setHoldTime(100);
button1Open->setMulticlickTime(300);
button1Close->addAction(Supla::CLOSE_OR_STOP, *rs1, Supla::ON_PRESS);
button1Close->setHoldTime(100);
button1Close->setMulticlickTime(300);
button2Open->addAction(Supla::OPEN_OR_STOP, *rs2, Supla::ON_PRESS);
button2Open->setHoldTime(100);
button2Open->setMulticlickTime(300);
button2Close->addAction(Supla::CLOSE_OR_STOP, *rs2, Supla::ON_PRESS);
button2Close->setHoldTime(100);
button2Close->setMulticlickTime(300);
buttonCfgRelay1->configureAsConfigButton(&SuplaDevice);
buttonCfgRelay1->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1);
buttonCfgRelay2->configureAsConfigButton(&SuplaDevice);
buttonCfgRelay2->addAction(Supla::TOGGLE, r2, Supla::ON_CLICK_1);
// Action trigger configuration
at1->setRelatedChannel(rs1);
at1->attach(button1Open);
at2->setRelatedChannel(rs1);
at2->attach(button1Close);
at3->setRelatedChannel(r1);
at3->attach(buttonCfgRelay1);
at4->setRelatedChannel(rs2);
at4->attach(button2Open);
at5->setRelatedChannel(rs2);
at5->attach(button2Close);
at6->setRelatedChannel(r2);
at6->attach(buttonCfgRelay2);
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
SuplaDevice.begin();
}
int buttonstate1, relaysatate1, buttonstate2, relaysatate2;
void loop() {
SuplaDevice.iterate();
}
-
klew
- Posts: 13908
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
- Has thanked: 134 times
- Been thanked: 137 times
Don't add anything from your previous code.caps_t wrote: Tue Dec 13, 2022 1:40 pm i tried to add your code and this is the result ( i'm new on iot)
Just start with this example and remove items you don't need (like roller shutter).
Handling of WiFi SSID setting, Supla server setting is already part of this example.
Also handling of input/button is also already included.
Najlepsze suple dla Twojego domu 
