How to stop notification loop/ or set a duration when only to notify

So I have this code where I get data from ESP32 and it has to notify when the value is Y. Now the issue is that it doesn't stop and persist until the value is no longer Y. I would like that it only notifies every 20 or so seconds. I tried a count variable but it isn't considered when I made the if statement. Sort of like making the millis method in Arduino compared to using delay() functions. Timer is at 250 ms that's why you'll see x4 to get 20 seconds from the timer.

How can this be approached?

You can see I made variable Temp1Counter but it looks like it's not reflected inside the .GotText of ESP32. Sort of at wit's end as well because of the nonstop notifications. I can give the .aia if necessary

Clock1.SystemTime is good for this, with two global variables:

  • constant NotificationInterval = 20000 (milliseconds, per taste)
  • variable LastNotifiedMS init 0

When you want to Notify

  • if Clock1.SystemTime > LastNotifiedMS + NotificationInterval then
    • set LastNotifiedMS to Clock1.SystemTime
    • Notify
  • else
    • do nothing

Hi @roamingal,
you know that in AI2 a delay function is not possible (like a delay in Arduino), due to the single thread architecture. Anyway, there are some posts on the delay matter in the forum, from which you can get some hints.

.In addition to this, what is the intention of these blocks ?
image

as soon as the Temp1counter variable gets the value NotificationCount*4 it is reset to 0, therefore the block:
image
will never return "true", I guess... :thinking:
(I made variable Temp1Counter but it looks like it's not reflected inside the .GotText)

Hi ABG,

Tried it using the current clock I have but seems to not work. Can you check what I could be missing?

Question I have are:

  1. Do I have to add another clock? Only AutoRefresh clock is what I have attached running at 250 ms.

You don't need another Clock just to tell you the SystemTime.

Log your incoming responses to a global list and feed that into a List Picker's Elements for debugging.

Hello Uskiara,

This is a way to get a count similar to the millis() function in Arduino though I think making a counter is not the right approach.

What I would like to have is when I get a value of "Y", I get a notification but only every 20 seconds until I no longer get a "Y" value.

Example, I am getting a "Y" value. While I'm getting a "Y" value, send notification every 20 seconds.

If I get another value, don't send notification. Then repeat.

Any possible way I can do this?

Sorry, I seem to be getting lost.

The response I'm getting is a string like so: "1|Y|Y|Y" and then I split them in "|" then save them in a list called "ListItems". I call each item in the list through ZoneIndex.

Now for the notification part, what I would like to do is when the 2nd list item or the Y in 1|Y|Y|Y is "Y" then change color of the label and get a notification but only every 20 seconds until I no longer get a "Y" value.

My questions are:

  1. Why and where do we use the list picker here?
  2. Any way I can use Clock.SytemTime like the way I intended to?

Export and post your current aia here, so I can get to it tomorrow.

Here is a general purpose notification limitter.

It is built into an app for people driving their kids somewhere.
(The kids are instructed to gripe through the app.)

sample run



notification_limitter.aia (3.6 KB)


Dear @roamingal,
sorry but I was out on business trip.
What I meant is that you cannot wait, for example with a while..do block, for an external event to happen (unless you use the extension Itoo from @Kumaraswamy ), but this is another story.
If I have correctly understood, what you need is a clock that every one second (for example) checks if a "Y" has arrived from ESP32. As soon as the "Y" has arrived, this clock (let's call it clock1) enables a second clock (clock2), that fires every 20 seconds, which sends a notification. This clock2 continues to fire every 20 seconds (and consequently sends the notification) until clock1 that fires every one second, doesn't receive anymore the "Y" or, better, it receives a "N". Therefore when clock one ceases to receive the "Y", or it receives an "N", it disables clock 2 so the notification is not sent any longer. My suggestion is not to rely on the lack of "Y" from the ESP but to wait a "N" to synchronize the stop of clock 2.

Most probably other, and more clever, solutions can be adopted, but this one is the first that has jumped to my mind.
Cheers.

Hi ABG,

This is interesting. I will check and test your app later.

After reading this, it seems to be how I would want it to work.

But say, I have a lot of options that need notifications but same interval, would I need like to put/add 20 different clocks for 20 notifications?

If you have 20 different sources of notification, each source can raise its own flag (i.e. an element within a list of boolean). The clock that raises the notification parses the list and when it encounter the element with the true value, then selects the relevant message to notify.
In other words: you have a list of 20 messages and a list of 20 booleans.
When the 10th (i.e. the 'n'th) source sets the 10th element of the booleans' list to true , the clock will parse this list, and when it finds the 'true' element (the 10th in this example) will pick up the 10th element in the messages list and will shiow it in the notification box.
Again, this is just a suggestion :grin:
Cheers