Update the Current state of GPIO to Supla Amazon Skill

durobhash
Posts: 11
Joined: Tue Feb 22, 2022 11:50 pm

Post

Thanks a lot. A handful of information. Would try all these over next few days and keep you updated.
durobhash
Posts: 11
Joined: Tue Feb 22, 2022 11:50 pm

Post

Hi.

So far here is my observations:
auto vrelay = new Supla::Control::VirtualRelay();
Throughs the error "expected type-specifier". Tried passing arguments as you suggested,
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.
but no luck so far.

Code: Select all

if (gpio1_value == HIGH) {
  relay1->turnOn();
 } else {
  relay1->turnOff();
 }
This may be usefull if another part of your program will configure GPIO in earlier stage before calling to SuplaDevice.begin().
This works for setup(), but doenn't help in loop(), which i was looking ahead.

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;
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
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.
but I think itwont take me to the root of the query…
User avatar
klew
Posts: 11230
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Post

durobhash wrote: Sat Mar 05, 2022 7:43 pm
auto vrelay = new Supla::Control::VirtualRelay();
Throughs the error "expected type-specifier".
Do you have include added? #include <supla/control/virtual_relay.h>
durobhash wrote: Sat Mar 05, 2022 7:43 pm

Code: Select all

if (gpio1_value == HIGH) {
  relay1->turnOn();
 } else {
  relay1->turnOff();
 }
This may be usefull if another part of your program will configure GPIO in earlier stage before calling to SuplaDevice.begin().

This works for setup(), but doenn't help in loop(), which i was looking ahead.
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(...);
...
And then those variables will be accessible in loop() as well.
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:
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.
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).
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…
I don't understand.
durobhash
Posts: 11
Joined: Tue Feb 22, 2022 11:50 pm

Post

Hi,

I have an update and good news too.
Do you have include added? #include <supla/control/virtual_relay.h>
My miss, i forgot. But didn't have to use vRelay for this purpose.
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 did exactly same way, thanks for confirming i was on right path.

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;
}
And ran it through loop to detect change of GPIO State by other parallel app (like Blynk) or manual switch.

Code: Select all

void loop() {
  SuplaDevice.iterate();
  suplaFeedback();  
}
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 :

Code: Select all

auto vRelay = new Supla::Control::VirtualRelay();

Code: Select all

	if (vRelay (isOn)) {
		Relay->turnOn();
	}
	else {
		Relay->turnOff();
	}
Something like this possible?
elmaya
Posts: 1484
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

Post

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();
  }

Return to “General discussion”