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

Requests for new functions or software apps
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by rimai »

Actually, sleeping over the issue, I know what needs to be done.
I can create another page that takes portal username/key instead of email address.
This way, a malicious bot can only spam itself... :twisted: lol
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

Cool. Can we get that WiFiSendAlert() added to the libs then to make it easy :)
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by rimai »

Ok, I created a new webpage wifialert.aspx
It will use the same email address set on your portal notifications.

Parameters:
id - your forum username
key - your portal key (optional)
msg= your custom message

Just be careful not to spam your own mailbox.
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

Very cool!!! Tested this and it works. Now I can add this to my INO, get rid of my Custom Memory variables for flags and no more internal memory flags either with virtual relays... this will be my 5.x version :) Muahahah
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

So Roberto,

I can work on a pull request if you want for the WifiSendAlert.. but I'm thinking we should put the portal user and keys in a variable in the ReefAngel class... I guess I'll wrap it in an ifdef to save memory... the function can take a char * as an arg and it will be pretty nice for people I think...

Sound good?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by rimai »

It's already there :)
char *portalusername;
Key is not though, but you can use the same thing I did for portalusername
Roberto.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by rimai »

The only thing is we need the logic to lock it from being used over and over again and only send once/hour reminders or something, just like in the original code.
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

Oh cool. Would you want that on your end or in the RA side? I would think on the RA side you'd only want to send if the status changes otherwise you could be calling that URL multiple times per second which would get ugly pretty fast. That part opens up a little can of worms... hmmm
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

I'm thinking we could create an alert class. This way it could maintain it's state of what the status of the alert is. If the status changes it could trigger the alert and it could have a timer built in...

This way in code safely call the alert function every loop without fear and it would only call the URL when the status changes or the timeout is exceeded.

I'm thinking something along the lines of this.

if (condition is good) then alert(status_good) else alert (status_bad)

Need to think a bit more on this.
enigma32
Posts: 74
Joined: Fri Apr 26, 2013 11:48 am
Location: Los Angeles and NYC

Re: I can't find the WifiSendAlert() function in the librari

Post by enigma32 »

Probably best to do it on both sides...that way even if there's a bug one one side or the other there's never a situation where a dozen people get 10,000 alerts...
Current setup:
60g 24" custom cube (fish and softies right now)
AI Sol Blue, Ecotech MP-10wES
Coralife skimmer
100% customer controller, transitioning to ReefAngel
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

Roberto or Lee,
Did you ever finish the coding for WifiSendAlert that will allow me to add a few custom SMS alert messages? If so, will it be released in the next library version? Or is it available for download on github?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

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

Post by lnevo »

Havent had time to touch it yet, but you should be able to modify the url being called to hit the new page and then send whatever custom message you like :)
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

lnevo wrote:Havent had time to touch it yet, but you should be able to modify the url being called to hit the new page and then send whatever custom message you like :)
Sorry Lee, I don't understand what you mean. Do you want me to copy these statements somewhere after my condition that determines when to send the SMS alert?

Serial.print("GET /status/alert.asp?e=314123456@vtext.com&id=");
Serial.println(alert_status,DEC);
Serial.println("\n\n");

I need a little more to go on.
Thanks,
John
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

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

Post by lnevo »

rimai wrote:Ok, I created a new webpage wifialert.aspx
It will use the same email address set on your portal notifications.

Parameters:
id - your forum username
key - your portal key (optional)
msg= your custom message

Just be careful not to spam your own mailbox.

You have to use this new wifialert.aspx

Change the line you have that calls alert.aspx to the new syntax above.

Maybe I'll have some time next week to play with this...
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

lnevo wrote:
rimai wrote:Ok, I created a new webpage wifialert.aspx
It will use the same email address set on your portal notifications.

Parameters:
id - your forum username
key - your portal key (optional)
msg= your custom message

Just be careful not to spam your own mailbox.

You have to use this new wifialert.aspx

Change the line you have that calls alert.aspx to the new syntax above.

Maybe I'll have some time next week to play with this...
Lee,
Thanks for the clarification.
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

I still can't figure out how to use wifialert.aspx. When I compile it says it has not been declared. Can someone please provide an example of how the wifialert.aspx is used in the sketch.

thanks,
John
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

Did you not have it working with the other page before?
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

lnevo wrote:Did you not have it working with the other page before?
Yes, the WifiSendAlert() function was working, but I am not sure how to pass the parameters that you and Roberto suggested in this section of the code.

Serial.print("GET /status/alert.asp?e=314123456@vtext.com&id=");
Serial.println(alert_status,DEC);
Serial.println("\n\n");

I am assuming that you wanted me to replace "alert.asp?" with "wifialert.aspx", but I am not sure how to specify the ID, Key and Message parameters.

I was hoping that you or Roberto could supply some sample code that I could modify.

Thanks,
John
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

Try this:

Code: Select all

Serial.print("GET /status/wifialert.aspx?id=mudcat1&msg=ato_alert");
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

You can comment the second line as well. I'm going to work on this soon where you can pass the alert string to the function.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

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");
}
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

My code may not be basic version friendly..especially if your already close to memory limits.
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

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 546 times
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: I can't find the WifiSendAlert() function in the librari

Post by lnevo »

Well, my first alert test didn't work. Will need to check the serial output to see whats going on...
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: I can't find the WifiSendAlert() function in the librari

Post by mudcat1 »

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
Post Reply