Arduino + Supla + Sterowanie Przyciskiem (jak wyświetlić aktualny stan Pinu)
-
alankedzior
- Posts: 114
- Joined: Mon Jun 18, 2018 5:38 pm
Nie zmieni to funkcjonowania pozostałych przycisków?
-
pzygmunt
- Posts: 20302
- Joined: Tue Jan 19, 2016 9:26 am
- Location: Paczków
- Been thanked: 59 times
Zmieni. Aby nie zmieniło musiałbyś kod zmodyfikować w następujący sposób
Code: Select all
#define BTN_COUNT 1
typedef struct {
int pin;
int relay_pin;
int channel;
int ms;
char
char last_val;
unsigned long last_time;
} _btn_t;
_btn_t btn[BTN_COUNT];
void supla_timer() {
char v;
unsigned long now = millis();
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
v = digitalRead(btn[a].pin);
if (v != btn[a].last_val && now - btn[a].last_time ) {
btn[a].last_val = v;
btn[a].last_time = now;
if (v==0)
{
if ( btn[a].ms > 0 ) {
SuplaDevice.relayOn(btn[a].channel, btn[a].ms);
} else {
if ( digitalRead(btn[a].relay_pin) > 0 ) {
SuplaDevice.relayOff(btn[a].channel);
} else {
SuplaDevice.relayOn(btn[a].channel, 0);
}
}
}
}
}
}
}void setup() { memset(btn, 0, sizeof( ... _timer); }
SUPLA.... Nareszcie w domu.
-
alankedzior
- Posts: 114
- Joined: Mon Jun 18, 2018 5:38 pm
Nie działa, próbuje już chyba na każdy sposób
#define BTN_COUNT 20
typedef struct {
int pin;
int relay_pin;
int channel;
int ms;
char ;
char last_val;
unsigned long last_time;
} _btn_t;
_btn_t btn[BTN_COUNT];
void supla_timer() {
char v;
unsigned long now = millis();
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
v = digitalRead(btn[a].pin);
if (v != btn[a].last_val && now - btn[a].last_time ) {
btn[a].last_val = v;
btn[a].last_time = now;
if (v==0)
{
if ( btn[a].ms > 0 ) {
SuplaDevice.relayOn(btn[a].channel, btn[a].ms);
} else {
if ( digitalRead(btn[a].relay_pin) > 0 ) {
SuplaDevice.relayOff(btn[a].channel);
} else {
SuplaDevice.relayOn(btn[a].channel, 0);
}
}
}
}
}
}
void supla_btn_init()
{
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
pinMode(btn[a].pin, INPUT_PULLUP);
btn[a].last_val = digitalRead(btn[a].pin);
btn[a].last_time = millis();
}
}
....
btn[18].pin = 45; // przycisk furtki
btn[18].relay_pin = 39; // przekaznik furtka
btn[18].channel = 19; // numer kanału
btn[18].ms = 2000; // czas otwierania furtki
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);
}
void loop() {
SuplaDevice.iterate();
}
-
koksinek80
- Posts: 1
- Joined: Fri Dec 27, 2019 7:01 pm
Posiadam arduino mega + ethernet shield w5100 , chciałbym sterować poprzez suple oświetleniem w domu + aplikacja z telefonu
jako że supla jest dla mnie nowościa mam problem z wysterowaniem przekaźnika , brak reakcji na przycisk.
Czy mogę prosic o pomoc?
Z gory dziękuje
jako że supla jest dla mnie nowościa mam problem z wysterowaniem przekaźnika , brak reakcji na przycisk.
Czy mogę prosic o pomoc?
Z gory dziękuje
Code: Select all
#include <SPI.h>
#include <Ethernet.h>
#include <SuplaDevice.h>
#define BTN_COUNT 1
typedef struct {
int pin;
int relay_pin;
int channel;
char last_val;
unsigned long last_time;
} _btn_t;
_btn_t btn[BTN_COUNT];
void supla_timer() {
char v;
unsigned long now = millis();
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
v = digitalRead(btn[a].pin);
if (v != btn[a].last_val && now - btn[a].last_time ) {
btn[a].last_val = v;
btn[a].last_time = now;
if (v==0)
{
if ( digitalRead(btn[a].relay_pin) > 0 ) {
SuplaDevice.relayOff(btn[a].channel);
} else {
SuplaDevice.relayOn(btn[a].channel, 0);
}
}
}
}
}
void supla_btn_init() {
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
pinMode(btn[a].pin, INPUT_PULLUP);
btn[a].last_val = digitalRead(btn[a].pin);
btn[a].last_time = millis();
}
}
void setup() {
memset(btn, 0, sizeof(btn));
btn[0].pin = 53;
btn[0].relay_pin = 37;
btn[0].channel = 0;
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);
Serial.begin(9600);
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {xxxxxxxxxxxxxxxxxxxxxxx};
// with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
// Ethernet MAC address
uint8_t mac[6] = {xxxxxxxxxxxxxxxxxxxxx};
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"svr28.supla.org", // SUPLA server address
xxxx, // Location ID
"xxx"); // Location Password
}
void loop() {
SuplaDevice.iterate();
}-
Krisvan
- Posts: 6
- Joined: Wed Jan 08, 2020 6:01 pm
Zacząłem dopiero z "Supla Arduino" na ESP8266. Wszystkie stany wyjściowe są dla mnie jasne, ale z dodaniem przycisku mam problem. Zanim tu trafiłem zauważyłem, ze standardowa obsługa wejścia nie daje informacji w serwerze. Mam tu przykład z roletami. Z aplikacji steruję przekaźnikami bezproblemowo, ale przycisku dodać nie mogę. Jeżeli mógłbym, to proszę o wskazanie, gdzie mam błąd:
Jeżeli to jest PULLUP, to powinienem na pinie D0 mieć 3,3V, a mam 0V. Nie ma znaczenia czy wpiszę btn[0].pin = 16; czy tez btn[0].pin = D0; to i tak po załadowaniu programu, mam na pinie D0 0V. Nie wiem, gdzie jest błąd
Code: Select all
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#define BTN_COUNT 1
OneWire oneWire(2); //termometr powinien byc podlaczony pod pin nr 2
DallasTemperature sensors(&oneWire); // to jeżeli chciałbym uzyć ds18b20
WiFiClient client;
const char* ssid = "TP-LINK_F3EA6C"; //nazwa sieci WiFi
const char* password = "xxx"; //hasło do sieci
typedef struct {
int pin;
int relay_pin;
int channel;
char last_val;
unsigned long last_time;
} _btn_t;
_btn_t btn[BTN_COUNT];
void supla_timer() {
char v;
unsigned long now = millis();
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
v = digitalRead(btn[a].pin);
if (v != btn[a].last_val && now - btn[a].last_time ) {
btn[a].last_val = v;
btn[a].last_time = now;
if (v==0)
{
if ( digitalRead(btn[a].relay_pin) > 0 ) {
SuplaDevice.relayOff(btn[a].channel);
} else {
SuplaDevice.relayOn(btn[a].channel, 0);
}
}
}
}
}
void supla_btn_init() {
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
pinMode(btn[a].pin, INPUT_PULLUP);
btn[a].last_val = digitalRead(btn[a].pin);
btn[a].last_time = millis();
}
}
void setup() {
Serial.begin(9600); //ustawiamy predkość na 9600
sensors.begin(); //uruchamiamy odczyt temperatury
char GUID[SUPLA_GUID_SIZE] = {xxx}; //pobieramy ze strony https://www.supla.org/arduino/get-guid
byte mac[6] = {0x01, 0x22, 0x33, 0x40, 0x50, 0x07}; //ustawiamy indywidualny adres mac
// CHANNEL2,3 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(D7,D8, true);
memset(btn, 0, sizeof(btn));
btn[0].pin = 16;
btn[0].relay_pin = 13;
btn[0].channel = 0;
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);
SuplaDevice.begin(xxx); //logony, hasła
}
void loop() {
if (WiFi.status() != WL_CONNECTED) // Jeżeli sieć WiFi nie jest podłączona, wywołaj procedurę łączenia
{
WiFi_up(); //połączenia z wifi
}
SuplaDevice.iterate(); //CO TO ZA FUNKCJA I CO OAN ROBI?????????????????????????????????
}
// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
_supla_int_t size = client.available();
if ( size > 0 ) {
if ( size > count ) size = count;
return client.read((uint8_t *)buf, size);
};
return -1;
};
int supla_arduino_tcp_write(void *buf, int count) {
return client.write((const uint8_t *)buf, count);
};
bool supla_arduino_svr_connect(const char *server, int port) {
return client.connect(server, 2015);
}
bool supla_arduino_svr_connected(void) {
return client.connected();
}
void supla_arduino_svr_disconnect(void) {
client.stop();
}
void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {
WiFi_up();
}
SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
SuplaDeviceCallbacks cb;
cb.tcp_read = &supla_arduino_tcp_read;
cb.tcp_write = &supla_arduino_tcp_write;
cb.eth_setup = &supla_arduino_eth_setup;
cb.svr_connected = &supla_arduino_svr_connected;
cb.svr_connect = &supla_arduino_svr_connect;
cb.svr_disconnect = &supla_arduino_svr_disconnect;
cb.get_temperature = NULL;
cb.get_temperature_and_humidity = NULL;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
return cb;
}
void WiFi_up() // Procedura podłączenia do sieci WiFi
{
Serial.print("Proba podlaczenia do sieci ");
Serial.println(ssid);
WiFi.begin(ssid, password); // Próba podłączenia do sieci
for (int x = 60; x > 0; x--) // Powtarzaj pętlę maksymanie maksymalnie 30 sekund (ponieważ przy każdym elsie jest 0,5 sekundy zwłoki)
{
if (WiFi.status() == WL_CONNECTED) // Jezeli WiFi jest podłączone
{
break; // to zatrzymaj pętlę
}
else // w przeciwnym wypadku
{
Serial.print("."); // wystaw na serial .
delay(500); // i czekaj 0,5 sekundy
}
}
if (WiFi.status() == WL_CONNECTED) // Jeżeli połączenie z siecią zostało nawiązane, wyślij na serial jego parametry
{
Serial.println("");
Serial.println("Polaczenie nawiazane");
Serial.println("Adres IP: ");
Serial.print(WiFi.localIP());
Serial.print(" / ");
Serial.println(WiFi.subnetMask());
Serial.print("Brama: ");
Serial.println(WiFi.gatewayIP());
long rssi = WiFi.RSSI();
Serial.print("Sila sygnalu (RSSI): ");
Serial.print(rssi);
Serial.println(" dBm");
}
else // w przeciwnym wypadku poinformuj przez serial o nieudanej próbie
{
Serial.println("");
Serial.println("Polaczenia nie udalo sie nawiazac");
}
}
-
elmaya
- Posts: 1485
- Joined: Wed Jun 27, 2018 5:48 pm
- Location: El Saucejo - Sevilla
A little guide of Gpio.
Gpio 16 has no internal pullup and interup
//#define D0 16 //no internal pullup resistor
//#define D1 5
//#define D2 4
//#define D3 0 //must not be pulled low during power on/reset, toggles value during boot
//#define D4 2 //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15 //must not be pulled high during power on/reset
Gpio 16 has no internal pullup and interup
//#define D0 16 //no internal pullup resistor
//#define D1 5
//#define D2 4
//#define D3 0 //must not be pulled low during power on/reset, toggles value during boot
//#define D4 2 //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15 //must not be pulled high during power on/reset
-
Krisvan
- Posts: 6
- Joined: Wed Jan 08, 2020 6:01 pm
Ok, dziekuję. Teraz zrobiłem w ten sposób:
i na D1 mam 3,3V. Na serial monitorze, za każdym razem jak pin D1 złączę z GND to mam wyświetlane Value changed, czyli jest reakcja "przycisk", ale przekaźnik podpięty pod D7, nie zmienia swojego stanu. Czy na pewno w tym przypadku kanał dwa będzie tym odpowiedzialnym za wyjście D7. Czy numer kanału jest przypisywany zawsze w tej kolejności w jakiej definiuję urzadzenie w SETUP-ie?
Code: Select all
void setup() {
Serial.begin(9600); //ustawiamy predkość na 9600
sensors.begin(); //uruchamiamy odczyt temperatury
char GUID[SUPLA_GUID_SIZE] = {xxx}; //pobieramy ze strony https://www.supla.org/arduino/get-guid
byte mac[6] = {0x01, 0x22, 0x33, 0x40, 0x50, 0x07}; //ustawiamy indywidualny adres mac
// CHANNEL0 - RELAY
SuplaDevice.addRelay(D5, true); //definiujemy co chcemy widzieć pod danym kanałem. Tu mamy przekaźnik. true oznacza, ze
// CHANNEL1 - RELAY
SuplaDevice.addRelay(D6, true);
// CHANNEL2,3 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(D7,D8, true);
memset(btn, 0, sizeof(btn));
btn[0].pin = 5;
btn[0].relay_pin = 13;
btn[0].channel = 2;
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);
SuplaDevice.begin(xxx"); //loginy, hasła
}
}
-
elmaya
- Posts: 1485
- Joined: Wed Jun 27, 2018 5:48 pm
- Location: El Saucejo - Sevilla
in case of being a Roller Shutter channel the buttons are added like this
Code: Select all
SuplaDevice.setRollerShutterButtons(0, // 0 - Channel Number
20, // 20 - Pin where the 1st button is connected
21); // 21 - Pin where the 2nd button is connected-
Krisvan
- Posts: 6
- Joined: Wed Jan 08, 2020 6:01 pm
Thank You, it works fine. This is my code:
But could You explain me, where are those chanel numbers taken from? Are they devided into input chanels (like buttons) and output chanels (like Relays)? As you can see, above my roller shutter relays declaration I have a comment that those relays are assigned to chanel number 2 and 3.
My byttons chanel numbers are 1 and 2.
When I started to complete the roller shutter chanel number I didn't know what number should I put there. I wrote number 2 and everything works really fine, once again thank You for help, but please explain me what are the chanel numbers rules.
Code: Select all
void setup() {
Serial.begin(9600); //ustawiamy predkość na 9600
sensors.begin(); //uruchamiamy odczyt temperatury
char GUID[SUPLA_GUID_SIZE] = {xxx}; //pobieramy ze strony https://www.supla.org/arduino/get-guid
byte mac[6] = {0x01, 0x22, 0x33, 0x40, 0x50, 0x07}; //ustawiamy indywidualny adres mac
// CHANNEL0 - RELAY
SuplaDevice.addRelay(D5, true); //definiujemy co chcemy widzieć pod danym kanałem. Tu mamy przekaźnik. true oznacza, ze
// CHANNEL1 - RELAY
SuplaDevice.addRelay(D6, true);
// CHANNEL2,3 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(D7,D8, true);
memset(btn, 0, sizeof(btn));
btn[0].pin = 5;
btn[0].relay_pin = 13;
btn[0].channel = 1;
btn[1].pin = 4;
btn[1].relay_pin = 15;
btn[1].channel = 2;
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);
SuplaDevice.setRollerShutterButtons(2, // 0 - Channel Number
5, // 5 - Pin where the 1st button is connected
4); // 4 - Pin where the 2nd button is connected
SuplaDevice.begin(xxx"); //loginy, hasła
}
My byttons chanel numbers are 1 and 2.
When I started to complete the roller shutter chanel number I didn't know what number should I put there. I wrote number 2 and everything works really fine, once again thank You for help, but please explain me what are the chanel numbers rules.
-
elmaya
- Posts: 1485
- Joined: Wed Jun 27, 2018 5:48 pm
- Location: El Saucejo - Sevilla
Channel number is assigned in the same order as described in the code starting with 0.
channel of blinds is 1 channel with two relays, in this case it is channel 2
you don't need this
channel of blinds is 1 channel with two relays, in this case it is channel 2
Code: Select all
void setup() {
Serial.begin(9600); //ustawiamy predkość na 9600
sensors.begin(); //uruchamiamy odczyt temperatury
char GUID[SUPLA_GUID_SIZE] = {xxx}; //pobieramy ze strony https://www.supla.org/arduino/get-guid
byte mac[6] = {0x01, 0x22, 0x33, 0x40, 0x50, 0x07}; //ustawiamy indywidualny adres mac
// CHANNEL0 - RELAY
SuplaDevice.addRelay(14, true); //channel 0 D5
// CHANNEL1 - RELAY
SuplaDevice.addRelay(12, true); //channel 1 D6
// CHANNEL2 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(13,15, true); //channel 2 D7,D8
/* memset(btn, 0, sizeof(btn)); //this is only necessary for relay channel
btn[0].pin = 5;
btn[0].relay_pin = 13;
btn[0].channel = 1;
btn[1].pin = 4;
btn[1].relay_pin = 15;
btn[1].channel = 2;
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);*/
SuplaDevice.setRollerShutterButtons(2, // Channel 2
5, // 5 - Pin where the 1st button is connected D1
4); // 4 - Pin where the 2nd button is connected D2
SuplaDevice.begin(xxx"); //loginy, hasła
}Code: Select all
memset(btn, 0, sizeof(btn));
btn[0].pin = 5;
btn[0].relay_pin = 13;
btn[0].channel = 1;
btn[1].pin = 4;
btn[1].relay_pin = 15;
btn[1].channel = 2;
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);