Mam problem z przyciskami przy ustawieniu kanału na automat schodowy, przełączniki z aplikacji działają prawidłowo załączając na ustawiony czas, a przyciski fizyczne załączają na stałe (bez względu na ustawiony czas automatu schodowego).
Jak zrobić by przycisk fizyczny też działał jako automat schodowy?
Przekaźnik r4 jak przeniosę do setup to w pętli nie mogę nim sterować ( r4->turnOff(); ) arduino wywala r4 nie zdeklarowany, prawidłowo?
Poniżej mój kod, a właściwie zlepek innych kodów.
SuplaDevice 2.4.2
Kod: Zaznacz cały
/*
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.
*/
#include <SuplaDevice.h>
#include <supla/device/status_led.h>
/*
* This example requires Dallas Temperature Control library installed.
* https://github.com/milesburton/Arduino-Temperature-Control-Library
*/
// Add include to DS sensor
#include <supla/sensor/DS18B20.h>
#include <supla/control/relay.h>
#include <supla/control/button.h>
//histereza
int roznica = 4; //roznica załączenia
int roznica2 = 2; //roznica wyłączenia
float T1;
float T2;
int licz; // ?flaga
unsigned long aktualnyCzas = 0;
unsigned long zapamietanyCzas = 0;
unsigned long roznicaCzasu = 0;
//channel 0
auto r4 = new Supla::Control::Relay(15); // przekaźnik r4 na pin15
// 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);
// 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("xxxxxxxxxxxxxx", "xxxxxxxxxxxxx");
#endif
Supla::Device::StatusLed statusLed(13, true); // inverted state
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] = {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx};
/*
* Having your device already registered at cloud.supla.org,
* you want to change CHANNEL sequence or remove any of them,
* then you must also remove the device itself from cloud.supla.org.
* Otherwise you will get "Channel conflict!" error.
*/
auto r1 = new Supla::Control::Relay(12);
auto r2 = new Supla::Control::Relay(5);
auto r3 = new Supla::Control::Relay(4);
auto b1 = new Supla::Control::Button(0, true, true); // przycisk na pin0, z input pullup i odwróconą logiką (zwieranie do gnd)
b1->addAction(Supla::TOGGLE, r1, Supla::ON_PRESS);
auto b2 = new Supla::Control::Button(9, true, true); // przycisk na pin9, z input pullup i odwróconą logiką (zwieranie do gnd)
b2->addAction(Supla::TOGGLE, r2, Supla::ON_PRESS);
auto b3 = new Supla::Control::Button(10, true, true); // przycisk na pin10, z input pullup i odwróconą logiką (zwieranie do gnd)
b3->addAction(Supla::TOGGLE, r3, Supla::ON_PRESS);
auto b4 = new Supla::Control::Button(14, true, true); // przycisk na pin14, z input pullup i odwróconą logiką (zwieranie do gnd)
b4->addAction(Supla::TOGGLE, r4, Supla::ON_PRESS);
// CHANNEL 4-5 - Thermometer DS18B20
new Supla::Sensor::DS18B20(3);//rx
new Supla::Sensor::DS18B20(2);//sda solar
/*
* SuplaDevice Initialization.
* Server address, LocationID and LocationPassword are available at https://cloud.supla.org
* If you do not have an account, you can create it at https://cloud.supla.org/account/create
* SUPLA and SUPLA CLOUD are free of charge
*
*/
SuplaDevice.begin(GUID, // Global Unique Identifier
"svr1.supla.org", // SUPLA server address
"xxxxx@xxxxx.pl", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
void loop() {
SuplaDevice.iterate();
/////////////////////////////////////////////////////////////////////////////////////////////////czas+odzcyt temp
//Pobierz liczbe milisekund od startu
aktualnyCzas = millis();
roznicaCzasu = aktualnyCzas - zapamietanyCzas;
//Jeśli różnica wynosi ponad 5 sekund
if (roznicaCzasu >= 5000UL) {
//Zapamietaj aktualny czas
zapamietanyCzas = aktualnyCzas;
//Wyslij do PC
//serial.println(aktualnyCzas);
for (auto element = Supla::Element::begin(); element != nullptr; element = element->next()) { // iterujemy po wszystkich elementach dodanych do programu
if (element->getChannel()) { // sprawdzamy, czy do elementu jest przypisany kanał. Niektóre elementy (np. button) nie posiadają kanału.
auto channel = element->getChannel();
if (channel->getChannelNumber() == 4) {
double lastTemperature = channel->getValueDouble();
T1 = lastTemperature;
// do something with lastTemperature
}
if (channel->getChannelNumber() == 5) {
double lastTemperature = channel->getValueDouble();
T2 = lastTemperature;
}
}
}
//serial.print(T1) ;
//serial.println("C T1");
//serial.print(T2) ;
//serial.println("C T2");
//////////termostat///////////////////////////////////////////////////////////////////////////
if((roznica)<=T1-T2)
{
licz =0;
}
else if(T1-T2<=(roznica2))
{
licz =1;
}
if( T1<-25)
{
licz =0;
}
if(licz>0)
{
r4->turnOff();
//serial.print(" pompa OFF ");
}
else
{
r4->turnOn(); // włącza przekaźnik.
//serial.print(" pompa ON ");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
}