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

Requests for new functions or software apps
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
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,
Using the portal will it send the alert immediately or does it delay it some period of time (ex. 5 minutes or 1 hour)? I did not receive the immediate SMS text as I expected. I manually tested sending an SMS text using the email address that I specified in the portal and received the text within a few seconds.
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 »

Its set to only page once every 15 minutes. You can change it with .SetDelay(int)

I wonder if the empty key is causing an issue. Can you try appending that output to http://forum.reefangel.com and see if you get a page? Try without the &key=
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,
Using the portal will it send the alert immediately or does it delay it some period of time (ex. 5 minutes or 1 hour)? I did not receive the immediate SMS text as I expected. I manually tested sending an SMS text using the email address that I specified in the portal and received the text within a few seconds.
Yeah this is the part that didn't work for me either. The serial output looks good though except for the empty key.

I need to look at the original code again and make sure I didn't miss anything.
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:Its set to only page once every 15 minutes. You can change it with .SetDelay(int)

I wonder if the empty key is causing an issue. Can you try appending that output to http://forum.reefangel.com and see if you get a page? Try without the &key=
Lee,
I did not see your message in time. I added a portal key to see if that might be the issue. It will take me a few minutes to put it back to its original state. But i did just try your suggestion...

http://forum.reefangel.com/status/wifia ... with%20key

...with a portal key and the portal did send me a SMS text message.
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 »

Alright, i know the page works and i know the code is working to some degree...we'll get this going tonight... :)
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 also tried sending this command after removing the portal key.

wifialert.aspx?id=mudcat1&msg=Test%20without%20key (URL trimmed to prevent spam)

It successfully sent the SMS text too.
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 tested also with a blank key and it was fine...so our syntax is good...
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 »

Roberto... I think this time it's your fault ;)

If I go to the IP that is set on the wifi module and try the URL I'm generating, I get a 404 that the resource is not found...

URL removed to prevent spamming!

If I use forum.reefangel.com which is a different IP it works. So it looks like we just need to copy the aspx file over... hopefully simple :)
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 »

I think you are right :oops:
I'll fix it shortly....
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. I think that should take care of the issue :) Btw, I also added a force option just do object.Send("Msg",true); and it will bypass the time check. Make sure you put some type of flag that this was done once. I am using it for my power outage check. So it's nice to know when power is restored. I'm sure others will find good use for it.

Also, some notices, I needed a lot less time (30 seconds...during WC mode...) between notifications or wanted a lot more time (like once per hour), so the SetDelay should be nice feature for all of those. The default in the class is currently 15 minutes.
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've made the required changes.
Can you try again?
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 »

Working!
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 don't think it is working for me. Where do I change the time interval with .SetDelay(int)? I can't find this anywhere.

Lee,
Did you have to change any of the original code to get it working?
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 »

Its part of the object..so if you declared atoAlarm then atoAlarm.SetDelay(30);

I didn't change any of the code. The code was good :) i need to upload my version with the force option tomorrow and see if that part is working. That might make debug easier..
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,
The problem that I am encountering now seems to be that it will not send the portal key with the request.

I have the portal key specified in the INO.

ReefAngel.Portal( "mudcat1","xxxxxxxxxx" );

When the float switch is triggered. This gets sent...

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

The portal key is missing "&key=" How did you get past that issue?

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 »

I didn't get that far...i don't use a key. Your using the copy/paste code above? I'll check in a little while if i missed something.

For the record, long term the second arg will be for force not for key...that will get stored in library when you do SendPortal
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 just re-read your post. If your doing copy / paste the. You will need to do

atoAlarm.Send("msg","key");

Edit: forgot the function :) syntax updated.
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, this is starting to seriously call for a class to manage all the dosing pumps and a class for each dosing pump with its characteristics (calibration volume, rate factor, timers, messages, etc.)

Anyway, here's my first run at a calibraton routine. The way it works is that I have a virtual outlet that I turn on to calibrate. This could just as easily be a menu mode... When that outlet is on, the calibration starts. For each pump defined it waits for the maskon to happen. when you turn it on it assumes you are filling a measuring cup to whatever amount you want. At that point it records the time. When the mask off happens it compares the times and gets the total running time. It then pages you with the result. If you need to turn the pump back on for a little more, it will track the running time. When your happy with the result, the last page you get will be the total time.

You can then put that time into a memory variable and that is used by my previous dosing pump routine to calculate the dosage. Since you've also stored the amount of liquid you are measuring we can properly calculate this. Also, the units can be whatever.. it could just as easily be 5 gallons in 200 seconds or 100ml in an hour.

What is now important is that you can now enter the number of ml or gallons or whatever you want and over how ever many doses you want per day and it's all calculated... :) Let's see how it tests out.

I'm also going to add logging that we started working on for kirkwood. What I would like a separate function that is logging the relay and storing the total time it is on and send me the total each hour.

Anyway, without further-ado. This code is compiled but not yet tested. It will be uploaded after this post :)

Code: Select all

// Run calibration routine,
void CalibrateDPumps() {
  const byte numPumps=2;
  byte pump[numPumps] = { DPump1, DPump2 };
  static time_t pumpTimer[numPumps];
  static WiFiAlert calibrateMsg;
  char msg[16];
  
  if (ReefAngel.Relay.Status(VO_Calibrate)) { 
    for (int i=0;i < numPumps;i++) {
      if (ReefAngel.Relay.isMaskOn(pump[i])) {
        pumpTimer[i]=now()-pumpTimer[i];
        ReefAngel.Relay.Override(pump[i],2); 
        ReefAngel.Relay.On(pump[i]);
      } 
      
      if (ReefAngel.Relay.isMaskOff(pump[i]) && pumpTimer[i]>0) {
        ReefAngel.Relay.Override(pump[i],2);
        ReefAngel.Relay.Off(pump[i]);
        pumpTimer[i]=now()-pumpTimer[i];
        sprintf(msg,"Pump%d+:+%d",i+1,pumpTimer[i]); 
        calibrateMsg.Send(msg,true);
      }
    }
  } else {
    for (int i=0;i< numPumps;i++) {
      pumpTimer[i]=0;
    }
  }    
}
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:Oh just re-read your post. If your doing copy / paste the. You will need to do

atoAlarm.Send("msg","key");

Edit: forgot the function :) syntax updated.
Lee,
That fixed it. I can now send SMS texts from the Reef Angel. :D

Thanks for all of your help and patience.

John
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,
One more question. What interval does the 30 specify in this statement?
atoAlarm.SetDelay(30);

Is it 30 minutes, 30 seconds or 30 milliseconds? And does this delay the interval between when it will send the alert? I just tested the Sump too hot code and it SPAMMED me with several messages. I need to tune something.

Thanks,
John
Post Reply