Update the Current state of GPIO to Supla Amazon Skill
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
Thanks a lot. A handful of information. Would try all these over next few days and keep you updated.
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
Hi.
So far here is my observations:
Tried with additional variable in place of virtualRelay to store the state with this small code, and run with loop(), but the relay turned on and off in few micro seconds.
Tried additional function in loop, but didn't help:
Presuming i couldn't get till supla core... how do i read rather update current status of GPIO status in Supla App?
i am yet to try
So far here is my observations:
Throughs the error "expected type-specifier". Tried passing arguments as you suggested,auto vrelay = new Supla::Control::VirtualRelay();
but no luck so far.Here (https://github.com/SUPLA/supla-arduino/ ... elay.h#L49) is a list of all options that configure relay initial state. Those methods will work on Relay and all derived classes like VirtualRelay.
This works for setup(), but doenn't help in loop(), which i was looking ahead.This may be usefull if another part of your program will configure GPIO in earlier stage before calling to SuplaDevice.begin().Code: Select all
if (gpio1_value == HIGH) { relay1->turnOn(); } else { relay1->turnOff(); }
Tried with additional variable in place of virtualRelay to store the state with this small code, and run with loop(), but the relay turned on and off in few micro seconds.
Tried additional function in loop, but didn't help:
Code: Select all
void suplaFeedback()
{
if (PIN_SWITCH == HIGH)
{
Relay->turnOn();
//vrelay->turnOn()
}
else if (PIN_SWITCH == LOW)
{
//vrelay->turnOff()
Relay->turnOff();
}
else return;
i am yet to try
but I think itwont take me to the root of the query…If you want to use GPIO as an input, then check Supla::Sensor::Binary class ( https://github.com/SUPLA/supla-arduino/ ... r/binary.h ).
It will read GPIO and show it as sensor on Supla with ON/OFF state.
-
- Posts: 11230
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
Do you have include added? #include <supla/control/virtual_relay.h>durobhash wrote: Sat Mar 05, 2022 7:43 pmThroughs the error "expected type-specifier".auto vrelay = new Supla::Control::VirtualRelay();
Those methods will work only after "SuplaDevice.begin()". I'm not sure what you mean by saying that it doesn't work in loop. Do you mean that program is not compiling? If yes, then if you define variable in setup() method, then this variable name can be used only in scope of that method. The simplest workaround is to define variables outside of setup method, i.e. as:durobhash wrote: Sat Mar 05, 2022 7:43 pmThis may be usefull if another part of your program will configure GPIO in earlier stage before calling to SuplaDevice.begin().Code: Select all
if (gpio1_value == HIGH) { relay1->turnOn(); } else { relay1->turnOff(); }
This works for setup(), but doenn't help in loop(), which i was looking ahead.
Code: Select all
Supla::Control::Relay *relay1 = nullptr;
Supla::Control::Relay *relay2 = nullptr;
...
// in setup:
relay1 = new Supla::Control::Relay(...);
...
If it is switching very quickly, then most probably you are mixing what is "ON" and "HIGH" state on GPIO. If "HIGH" means "ON", then this code will be fine, but it also require proper setup of Relay class instance.Tried with additional variable in place of virtualRelay to store the state with this small code, and run with loop(), but the relay turned on and off in few micro seconds.
Tried additional function in loop, but didn't help:
Please share your full code - it will be simpler to help (you can send it on priv if you don't want to put it on forum).
I don't understand.Presuming i couldn't get till supla core... how do i read rather update current status of GPIO status in Supla App?
of the query…
-
- Posts: 11
- Joined: Tue Feb 22, 2022 11:50 pm
Hi,
I have an update and good news too.
I was trying to create code and functions to update status on App regularly. After many stuffs, I tried a simple digitalRead() function to read GPIO and it worked wonder. Sometime simple things helps best.
Here is what i did: Created a feedback function and run it through loop.
And ran it through loop to detect change of GPIO State by other parallel app (like Blynk) or manual switch.
And that's it.
Many thanks to you for your support and suggestions.
However, i still have a query. If i need to read VirtualRelay() status (On/Off), and take call based on the vRelay() status, how do I do that?
Query Example :
Something like this possible?
I have an update and good news too.
My miss, i forgot. But didn't have to use vRelay for this purpose.Do you have include added? #include <supla/control/virtual_relay.h>
I did exactly same way, thanks for confirming i was on right path.Those methods will work only after "SuplaDevice.begin()". I'm not sure what you mean by saying that it doesn't work in loop. Do you mean that program is not compiling? If yes, then if you define variable in setup() method, then this variable name can be used only in scope of that method. The simplest workaround is to define variables outside of setup method, i.e. as:Code: Select all
Supla::Control::Relay *relay1 = nullptr; Supla::Control::Relay *relay2 = nullptr; ... // in setup: relay1 = new Supla::Control::Relay(...); ...
I was trying to create code and functions to update status on App regularly. After many stuffs, I tried a simple digitalRead() function to read GPIO and it worked wonder. Sometime simple things helps best.
Here is what i did: Created a feedback function and run it through loop.
Code: Select all
void suplaFeedback()
{
if (digitalRead(GPIO) == HIGH)
{
Relay->turnOn();
}
else if (digitalRead(GPIO) == LOW)
{
Relay->turnOff();
}
else return;
}
Code: Select all
void loop() {
SuplaDevice.iterate();
suplaFeedback();
}
Many thanks to you for your support and suggestions.
However, i still have a query. If i need to read VirtualRelay() status (On/Off), and take call based on the vRelay() status, how do I do that?
Query Example :
Code: Select all
auto vRelay = new Supla::Control::VirtualRelay();
Code: Select all
if (vRelay (isOn)) {
Relay->turnOn();
}
else {
Relay->turnOff();
}
-
- Posts: 1484
- Joined: Wed Jun 27, 2018 5:48 pm
- Location: El Saucejo - Sevilla
Code: Select all
Supla::Control::VirtualRelay *vRelay = nullptr;
......
// in setup:
vRelay = new Supla::Control::VirtualRelay();
......
// in loop:
if (vRelay->isOn()) {
Relay->turnOn();
}
else {
Relay->turnOff();
}