LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need to send an email once a target is reached

Solved!
Go to solution

Hey folks, I'm having some issues trying to accomplish a personal goal here. I'm fairly new to Labview, so if this is fairly obvious, try to cut me a bit of slack Smiley Tongue I'm trying to send an email to myself, once a value from some input on the front panel reaches or exceeds a target value. I check said values once every milli-second as part of a loop. If the input is greater or equal to my target value, then I send an email using the code from the Gmail VI that's been passed around here. I've tested that the email code itself works fine, and I've successfully sent emails repeatedly. The only issue I'm stuck with is that since I check my inputs every millisecond, if the input exceeds my target goal, then an email is sent every second that said case is true. Obviously, that's overkill because no one wants a million emails per day.

 

What I'd like is for only one email to be sent each time that case is true. So if that case is true maybe three times in one day, then that user only recieves three emails, rather than continuous emails in the period that the case is true. I'm assuming that the best way to do this is some kind of timed loop, but unfortunately, that's where my knowledge ends. If anyone has any ideas for solutions, I'd very much appreciate it.

0 Kudos
Message 1 of 9
(3,275 Views)

The obvious answer is to use flag to indicate you've sent the email out, so you don't send it out again while the value is at or above your target. If the value drops below, then you reset the flag. The flag can be a simple Boolean that you set/reset via a shift register or Feedback node. Plenty of examples that use this premise have been posted before.

 

Of course, given the fact that you're checking your value that frequently, there's the possibility you will need some hysteresis if the value is "noisy" and can drop below your target, and then briefly go above for just a tiny amount of time, but still be heading down.

Message 2 of 9
(3,270 Views)

This makes sense, but I'm going to write out how I forsee doing this, in case someone has some better ideas.

 

As it stands, the email sending code is all within a while loop, with the exit condition being that the value I check is less than the target value (Because if it's greater, we want to initiate the email notification). That loop in and of itself is within a larger timed loop, where I check input values every millisecond(Or whatever I set it to).

 

Using what you said, I would implement a boolean flag, which was dependant on a shift register. If an email is sent originally, the shift register notes it, passes it around for the next iteration, where it is then passed to my boolean flag. The flag is raised, preventing another sent email. Every iteration from that point on checks the boolean flag, if the flag is raised, do nothing, otherwise, send an email. This continues until the exit condition in my while loop is achieved. Does that make sense?

0 Kudos
Message 3 of 9
(3,250 Views)

What doesn't make sense is why you would have another while loop inside your timed loop. I fail to see the need for this.

 

Perhaps it would be best if you posted your code.

0 Kudos
Message 4 of 9
(3,241 Views)

While I can't upload the exact code due to personal reasons, I can upload a very messy (But 100% accurate to what I am using) older version. The only difference is that I'm not using a timed loop to get my values here, just using a simple numeric control for testing purposes.

 

Watch running the uploaded code, it will email you infinitely as it stands.

 

 

0 Kudos
Message 5 of 9
(3,234 Views)

And the VI you uploaded is supposed to show us what, exactly? It's a loop that runs if a control is greater than some value and sends out an email in each iteration, with nothing being looked at in terms of comparing a value to anything. Of course it's going to send out an email each and every iteration - you have nothing to prevent it from doing so.

0 Kudos
Message 6 of 9
(3,221 Views)

@smercurio_fc wrote:

 It's a loop that runs if a control is greater than some value and sends out an email in each iteration, with nothing being looked at in terms of comparing a value to anything.


That is my comparision. I understand that since it's a control, I will have to manually change it while running my VI if I ever want to stop the loop, that's fine, whatever, it's not like that in the final version. In my real code, instead of a panel control, it will be a value, gathered from a fieldpoint sensor, being compared to a specific constant (in the provided VI, I arbirtarily chose 45). If the value is higher or equal to that constant, great, send an email. If not, do nothing until it is. Other than the fact that I get the value differently, this is how I have things set up.

 

The point of my being able to control that value was to make my testing easier. If I set it to start at say, 46, then one email will be sent. As it stands, yes, it will do that infinitely. However, I would like for it to only do it once, until I (manually) change that value back to lower than 45. From that point, it should NOT send another email until I (again) manually raise it to above 45.  In the real code, the only difference is that this initial value is not ever set manually, instead, it's gathered from the prior mentioned fieldpoint sensor to be compared to a very specific constant.

 

I realize this is a tad confusing with the code as it stands, but that's the best I can explain it. Hopefully that makes things at least a little more clear.

0 Kudos
Message 7 of 9
(3,214 Views)
Solution
Accepted by topic author linkmaster94

What the heck...

I haven't been on the forum in a long time or with this username.

 

linkmaster94.png

 

When I say these subVIs in the comment I am speaking of the boolean trigger and your VI to send email.

 

James

 

It's free advice, you don't have to accept it or even like it.  Smiley Wink

Tech Advisor - Automation
LabVIEW 5.0 - 2020
Message 8 of 9
(3,213 Views)

Thank you for this. Though I modified it slightly, the code you've posted got me thinking along the right lines. Very much appreciated.

0 Kudos
Message 9 of 9
(3,185 Views)