Przekaźnik + przycisk nowa biblioteka arduino ide

emerce23
Posts: 36
Joined: Sat Dec 16, 2017 10:46 pm

Post

Witam serdecznie, bardzo długo mnie nie było na forum i zauważyłem zmianę biblioteki z supla-arduino na supla-device, potrzebuje zrobic przycisk i przekaźnik, poniżej kod (połączyłem stara i nowa biblioteke, niewiem co się zmieniło w nowej i nie moge ogarnać, pomoze ktos ?

Code: Select all

#include <SuplaDevice.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] = {0xEA, 0x9F, 0x6D, 0x92, 0x88, 0xC0};
Supla::EthernetShield ethernet(mac);

// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// 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("ssid", "haslo");
#endif

int przycisk1 = 2; // Przelacznik1

int stan_przekaznika1 = LOW;
int stan_przycisku1;             
int ostatni_stan_przycisku1 = HIGH; 
long lastDebounceTime1 = 0; 
long czas_drgania1 = 10;  

void setup() 
{
    Serial.begin(115200);
  
    // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
    char GUID[SUPLA_GUID_SIZE] = {kod mam};
    // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
    char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {kod mam};
  
    pinMode(przycisk1, INPUT_PULLUP);
    pinMode(2, OUTPUT);
  
    SuplaDevice.begin(GUID, "dane", "dane", AUTHKEY);     
}

void loop() 
{
    SuplaDevice.iterate();
    TSD_SuplaChannelNewValue value1; //Set value name
    value1.SenderID = 0; // Notify other users that your smartphone opens a blind. In case of actuators is to be 0
    value1.ChannelNumber = 2; // Need enter the relay channel number
    value1.DurationMS = 0; //turn on time
            
    int odczyt1 = digitalRead(przycisk1); 
      
    if (odczyt1 != ostatni_stan_przycisku1) 
    {
        lastDebounceTime1 = millis();
    }
          
    if ((millis() - lastDebounceTime1) > czas_drgania1) 
    {
        if (odczyt1 != stan_przycisku1) 
        {
            stan_przycisku1 = odczyt1;
            
            if (stan_przycisku1 == LOW) 
            { 
               //stan_przekaznika = !stan_przekaznika; 
               value1.value[0] = !value1.value[0]; 
               SuplaDevice.channelSetValue(&value1);
            }
        }
    }
      
    //digitalWrite(5, stan_przekaznika); 
    ostatni_stan_przycisku1 = odczyt1;        
}
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Przyciski są normalnie dostępne z poziomu SuplaDevice.
Może spróbuj zacząć od tego przykładu: https://github.com/SUPLA/supla-device/b ... erface.ino
Najlepsze suple dla Twojego domu :mrgreen:
emerce23
Posts: 36
Joined: Sat Dec 16, 2017 10:46 pm

Post

Zrobiłem coś takiego ale naprawdę nie umiem ogarnąć tej biblioteki, wydaje mi się ze tamta wcześniejsza była prostsza, pomoże ktoś ?

Code: Select all

#define RELAY 1
#define BUTTON 2

#include <SuplaDevice.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
  
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("", "");

void setup() 
{
    Serial.begin(115200);
  
    // Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
    char GUID[SUPLA_GUID_SIZE] = {};
    
    // Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
    char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {};

    Supla::Control::Relay(RELAY);
    Supla::Control::Button(BUTTON, true, true);
  
    SuplaDevice.begin(GUID, "", "", AUTHKEY);   
}

void loop() 
{
    SuplaDevice.iterate();      
}
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Musisz jeszcze powiązać zdarzenia generowane przez przycisk z akcjami wywoływanymi na przekaźniku. Zerknij na wywołania który addAction w podanym wcześniej przykładzie
Najlepsze suple dla Twojego domu :mrgreen:
emerce23
Posts: 36
Joined: Sat Dec 16, 2017 10:46 pm

Post

ok, a co dodać żebym miał tryb konfiguracyjny i zeby supla widziała urzadzenie ? Mozna jakis prosty kod ?
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Ten przykład WebInterface to prosty przykład na tryb konfiguracyjny z jednym przekaźnikiem i jedną roletą.

Jedyne co to można tam usunąć weryfikację certyfikatów serwera, bo to nie zadziała jeszcze z większością serwerów bez dodatkowych ustawień
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Tak by to mniej więcej wyglądało dla samego przekaźnika i przycisku (nie kompilowałem tego kodu)

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#define RELAY_GPIO 12
#define BUTTON_CFG_RELAY_GPIO 0

#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/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/events.h>

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

Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;

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;

void setup() {
  Serial.begin(115200);

  // Channels configuration
  // CH 0 - Relay
  auto r1 = new Supla::Control::Relay(RELAY_GPIO);
  // CH 1 - Action trigger
  auto at1 = new Supla::Control::ActionTrigger();

  // Buttons configuration
  auto buttonCfgRelay =
    new Supla::Control::Button(BUTTON_CFG_RELAY_GPIO, true, true);

  buttonCfgRelay->setHoldTime(1000);
  buttonCfgRelay->setMulticlickTime(300);
  buttonCfgRelay->addAction(Supla::TOGGLE, r1, Supla::ON_CLICK_1);
  buttonCfgRelay->addAction(Supla::TOGGLE_CONFIG_MODE, SuplaDevice, Supla::ON_HOLD);

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

  SuplaDevice.begin();
}

void loop() {
  SuplaDevice.iterate();
}
Najlepsze suple dla Twojego domu :mrgreen:
emerce23
Posts: 36
Joined: Sat Dec 16, 2017 10:46 pm

Post

dobrze pojąłem o co chodzi w tej bibliotece, a pytanie, nie ma jakiś listy z tymi stałymi żeby zrozumieć to tak dosłownie, która funkcja za co odpowiada ? I pytanie drugie, dało by rady polaczyć tą biblioteke " CapacitiveSensor.h ", poprostu chciałbym zeby po dotknięciu tak naprawde pinu poszedł impuls i załączyło mi przekaźnik (mam przycisk dotykowy naścienny z wylutowanym układem TTP), tak ze musze jakos samemu zrobić włącznik dotykowy, pomyslałem o takim rozwiazaniu chyba ze jakies inne pomysły ?

Return to “Pomoc”