I can't find the WifiSendAlert() function in the libraries.

Requests for new functions or software apps
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon May 27, 2013 7:08 pm
Ok, the previous function was using a byte to hold 8 bit flags on when an alert was sent or not. It also had a delay(900) which should be avoided if possible. I created a new class called WiFiAlert that stores when it was last sent and waits a set delay. Each class you instantiate will maintain its status. So you will need to declare one for each type of alert you want to send.

Usage looks like this:
Code: Select all
// This line in globals or declared as a static
WiFiAlert atoAlarm;

// This part inside loop()
if (ReefAngel.LowATO.IsActive()) {
  atoAlarm.Send("Sump_WaterLevel_is_low");
}


You can also pass a portal key as a second argument to Send(). Also since this gets translated to a web request you can not have spaces. You will need to use %20 or + if you want a space. You should also be able to use strcat to build a custom message to the alert. Like if you want to add your params or debug info. Is streams in the arduino libraries yet?? :)

Here's the code. I have not tested it yet... :)

Code: Select all
class WiFiAlert
{
public:
  WiFiAlert();
  void Send(char *message, char *key);
  inline void Send(char *message) { Send(message,""); }
  inline void SetDelay(int delay) { AlertDelay=delay; }
private:
  int AlertDelay;
  time_t LastAlert;
  boolean IsAlert();
  void WiFiSendAlert(char *message, char *key); 
};

WiFiAlert::WiFiAlert()
{
  AlertDelay=900;
  LastAlert=0;
}

boolean WiFiAlert::IsAlert()
{
  if (now()-LastAlert >= AlertDelay)
  {
    return true;
  }
  return false;
}

void WiFiAlert::Send(char *message, char *key)
{
  if (IsAlert())
  {
    LastAlert=now();
    WiFiSendAlert(message, key);
  }
}

void WiFiAlert::WiFiSendAlert(char *message, char *key)
{
  Serial.print("GET /status/wifialert.aspx?id=");
  Serial.print(ReefAngel.portalusername);
  Serial.print("&key=");
  Serial.print(key);
  Serial.print("&msg=");
  Serial.println(message);
  Serial.println("\n\n");
}

Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm
PostPosted: Mon May 27, 2013 7:48 pm
Thanks Lee. I attempted to modify the original code using your previous suggestions but I could not get it working correctly. I also only have a Reef Angel basic so I kept getting the sketch too large error. I will try your new code and let you know how it works out.

Thanks again for your assistance,
John
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon May 27, 2013 7:52 pm
My code may not be basic version friendly..especially if your already close to memory limits.

Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm
PostPosted: Mon May 27, 2013 9:35 pm
Lee,
This code goes beyond my current level of knowledge. I have not used the class statement in any of my previous sketches so I am not sure exactly where to place it in my sketch. I copied the code section that begins with class at the end of my sketch. When I compile it, I receive the error "'atoAlarm' was not declared in scope".

Here is where I placed the other code within my loop.
   if (!ReefAngel.LowATO.IsActive() && ( hour() >= 7 && hour() < 22)) {
      ReefAngel.PWM.SetDaylight( buzzer );
      atoAlarm.Send("ATO_container_is_empty");
 } else {
      ReefAngel.PWM.SetDaylight(0);
      if (!ReefAngel.HighATO.IsActive()) {
        ReefAngel.PWM.SetDaylight( buzzer );
        atoAlarm.Send("Sump_WaterLevel_is_to_high");
    } else {
        ReefAngel.PWM.SetDaylight(0);
      }
   }    

User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon May 27, 2013 10:44 pm
You shouldnt have to escape the quotes. You should be getting an error where you declare atoAlarm. Try pasting it above the setup function. It may need to be moved to its own files. Like i said, havent tried yet.

I updated my ino to use it, ill try compiling it up tomorrow..
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue May 28, 2013 6:06 am
Ok, I had one typo needed a ; after the class statement. Anyway a class is not much different from a struct except that it has functions (methods) tied to it and not just variables.

In any event, I tested just pasting this to the top of my code and it compiles nicely. Just put it after your includes.

Edit: Was also missing the declaration for the constructor (the WiFiAlert() function)
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue May 28, 2013 8:03 am
mudcat1 wrote:Lee,
This code goes beyond my current level of knowledge. I have not used the class statement in any of my previous sketches so I am not sure exactly where to place it in my sketch. I copied the code section that begins with class at the end of my sketch. When I compile it, I receive the error "'atoAlarm' was not declared in scope".

Here is where I placed the other code within my loop.
if (!ReefAngel.LowATO.IsActive() && ( hour() >= 7 && hour() < 22)) {
ReefAngel.PWM.SetDaylight( buzzer );
atoAlarm.Send("ATO_container_is_empty");
} else {
ReefAngel.PWM.SetDaylight(0);
if (!ReefAngel.HighATO.IsActive()) {
ReefAngel.PWM.SetDaylight( buzzer );
atoAlarm.Send("Sump_WaterLevel_is_to_high");
} else {
ReefAngel.PWM.SetDaylight(0);
}
}



One thing to note is you are using the same instance "atoAlarm" for two conditions. If they both happen at same time you will only be alerted for the first. But that isn't the cause of your errors. I believe it's where you are declaring the atoAlarm object.
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue May 28, 2013 11:15 am
Ok, I have this compiling properly now as a seperate entity. You can either download the attached file and just #include it, you can copy the code above and paste it in the top of your INO, or you can checkout the wifialert branch from my github repo http://github.com/lnevo/Libraries.

The one added to the Repo also adds a portalkey variabe to the ReefAngel class and so I took out the functions that Send using a key. This way you set your portal key once when you do a SendPortal and the function uses it if it's there.

I'll be uploading this code later today. I've converted all the alerts that I was using CustomVars for to use this method now. I've also add a few alerts to some of my interactive functions like RefillATO and AutoWaterChange. We'll se force if these stay.

The only thing that I've yet to do is add support for sending an all clear. If it happens within the delay then it won't send an alert so not very useful, yet I'd like to know when it's all set. I could instantiate another alert type but at the same time, we don't want an all good status to keep sending either... so I may add a ForceSend, or a boolean to Send to tell it not check LastAlert. You'll want to be careful with using any type of force though so I like the idea of the seperate function for it...

Anyway, feedback, comments, etc are welcome.
Attachments
WiFiAlert.h
(1.01 KiB) Downloaded 113 times
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue May 28, 2013 11:40 am
Well, my first alert test didn't work. Will need to check the serial output to see whats going on...

Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm
PostPosted: Tue May 28, 2013 12:57 pm
Lee,
I copied the code to the top of my INO file after the #include statements. I tested the sump overflow first without attaching the wifi attachment so that I could see the serial monitor output as you suggested. This was logged...

GET /status/wifialert.aspx?id=mudcat1&key=&msg=Sump_WaterLevel_is_to_high

Which is what I would have expected. Unfortunately when I attempted to try it a second time nothing else appeared in the serial monitor log. Is it designed to send only one alert and then it needs to be reset? I also tried the ATO container empty but it did not send an alarm either.

I powered off the Reef Angel and performed a subsequent test of the ATO container empty test and it also worked correctly the first time sending GET /status/wifialert.aspx?id=mudcat1&key=&msg=ATO_container_is_empty.

But again if I tested perform another test immediately it did not send a second alert. I will hook up the wifi attachment and perform the test to see if I receive the SMS page.

Thanks,
John
PreviousNext

Return to Requests

Who is online

Users browsing this forum: No registered users and 1 guest