Page 1 of 1

Get count when relay is on or off

Posted: Tue Jan 30, 2018 2:08 pm
by Armetas
Hello,

I'm wondering if there are some ways to count how many times relay is turned on or off in the arduino? For example: when we use temp probes in order to switch on/off heater: if temp less than 25 turn on heater and if more than 26 turn off heater. And if during the day temp drops 3 times and heater is turned on 3 times - so is it possible to calculate such thing and use somewhere else in the code?

Re: Get count when relay is on or off

Posted: Tue Jan 30, 2018 2:46 pm
by rimai
You can count for a day and store the data in a custom variable.
It would show up as custom variable.

Re: Get count when relay is on or off

Posted: Tue Jan 30, 2018 2:51 pm
by Armetas
rimai wrote:You can count for a day and store the data in a custom variable.
It would show up as custom variable.
But how to write such code in order to have such count? If I put code in the loop section when temp is less 25 then add 1 to the count - the count grows each milisecond

Re: Get count when relay is on or off

Posted: Tue Jan 30, 2018 7:17 pm
by rimai
You need a variable to control that.

Code: Select all

static boolean control=false;
if (ReefAngel.Relay.IsOn(Port1) && control==false) 
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.IsOff(Port1) && control==true) 
{
  control=false;
}

Re: Get count when relay is on or off

Posted: Wed Jan 31, 2018 12:10 am
by Armetas
Thanks!

By the way is there any possibility to have more custom variables that could be seen in the app? Or at least have some of them as text (not as number)?

Re: Get count when relay is on or off

Posted: Wed Jan 31, 2018 5:23 am
by binder
custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk

Re: Get count when relay is on or off

Posted: Wed Jan 31, 2018 5:24 am
by Armetas
rimai wrote:You need a variable to control that.

Code: Select all

static boolean control=false;
if (ReefAngel.Relay.IsOn(Port1) && control==false) 
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.IsOff(Port1) && control==true) 
{
  control=false;
}
I'm getting compile error :(

error: 'class RelayClass' has no member named 'IsOn'
error: 'class RelayClass' has no member named 'IsOff'

Re: Get count when relay is on or off

Posted: Wed Jan 31, 2018 5:43 am
by Armetas
binder wrote:custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk
Only 7 are available and all of them are number which cannot exceed ~300
I would like to have more variables shown on android app or have them as text (as I'm trying to display some information for reporting failures in my reef)

Re: Get count when relay is on or off

Posted: Wed Jan 31, 2018 6:53 pm
by rimai
Sorry. Try this:

Code: Select all

static boolean control=false;
if (ReefAngel.Relay.Status(Port1)==true && control==false) 
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.Status(Port1)==false && control==true) 
{
  control=false;
}

Re: Get count when relay is on or off

Posted: Wed Jan 31, 2018 9:00 pm
by binder
Armetas wrote:
binder wrote:custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk
Only 7 are available and all of them are number which cannot exceed ~300
I would like to have more variables shown on android app or have them as text (as I'm trying to display some information for reporting failures in my reef)
Ahhhh... gotcha. the libraries would have to be modified to allow for larger values or to display text instead.
most likely it would have to be additional custom variables added instead of the same ones...or maybe not (at least for getting larger values). the text would require separate variables.

Sent from my XT1585 using Tapatalk

Re: Get count when relay is on or off

Posted: Thu Feb 01, 2018 5:57 am
by Armetas
rimai wrote:Sorry. Try this:

Code: Select all

static boolean control=false;
if (ReefAngel.Relay.Status(Port1)==true && control==false) 
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.Status(Port1)==false && control==true) 
{
  control=false;
}
Thank you. It works perfectly ;)

Re: Get count when relay is on or off

Posted: Thu Feb 01, 2018 5:58 am
by Armetas
binder wrote:
Armetas wrote:
binder wrote:custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk
Only 7 are available and all of them are number which cannot exceed ~300
I would like to have more variables shown on android app or have them as text (as I'm trying to display some information for reporting failures in my reef)
Ahhhh... gotcha. the libraries would have to be modified to allow for larger values or to display text instead.
most likely it would have to be additional custom variables added instead of the same ones...or maybe not (at least for getting larger values). the text would require separate variables.

Sent from my XT1585 using Tapatalk
Is there a way who could change the libraries for such purpose. And how about android app? Will it handle longer variables? Or even text?

Get count when relay is on or off

Posted: Thu Feb 01, 2018 12:34 pm
by binder
Armetas wrote:
Is there a way who could change the libraries for such purpose. And how about android app? Will it handle longer variables? Or even text?
yes, it is possible to change the libraries around to do this. what i would suggest is creating a separate discussion topic/thread that we can discuss it in more detail of what you are wanting to accomplish. then we can create a testing branch for the libraries to test out functionality. if all goes well, then the changes could get merged into the main branch of the libraries.
then i could find some time to create a special build of my android app to help test and display the variables.
so that’s how i would suggest handling this so there’s a clear, open discussion on what is desired and we can move forward from there.


Sent from my iPad using Tapatalk

Re: Get count when relay is on or off

Posted: Thu Feb 01, 2018 12:36 pm
by rimai
Why don't you just use alert emails for that?
You can type anything on email alerts.

Re: Get count when relay is on or off

Posted: Thu Feb 01, 2018 12:38 pm
by binder
and yes, roberto’s idea would be the simplest and easiest to do.

one issue with sending text is the size. the more text on the controller, the bigger the code and harder it is to maintain. you are also limited with the options and changing them is harder. the email alerts are changed much easier without modifying the libraries.


Sent from my iPad using Tapatalk

Re: Get count when relay is on or off

Posted: Thu Feb 01, 2018 12:47 pm
by Armetas
rimai wrote:Why don't you just use alert emails for that?
You can type anything on email alerts.
But email alerts are outside the controller. Im writing code in the arduino ir order to track some things to catch when there is a problem and even now my all custom variables are fully occupied, im even saving like 31, 32, 120 values which represent for example: 32 - water in issue when changing water on 3rd time. I hope that you get what im trying to achieve