7 segment LED display and time rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mackowiakp
Normal user
Posts: 531
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

7 segment LED display and time rules

#1 Post by mackowiakp » 17 Apr 2023, 02:40

I have a device with several sensors and a 7 segment 4 digit LED display. Custom build based on mega-20230306.
I found that the time-based command rules probably don't work:

Code: Select all

on Rules#Timer
if %uptime%
To check it and eliminate possible errors in quite extensive rules, I made a test device containing only a temp/hygro sensor and a 7 segment display.
Below are all the rules of this test device.

Code: Select all

on Si7021#Temperature do
 7dt,[Si7021#Temperature]
done

On Clock#Time=All,01:51 do 
 TimerSet,3,57
Endon

on Rules#Timer=3 do
 if %isntp% = 1
  reboot
 endif
endon

if %uptime% > 10
 reboot
Endif
The time is synchronized with the NTP server correctly.
The task of these rules is to reboot the device every night or if their working time will be greater than 24h (in the absence of NTP).
Here, I set a test time of 10 minutes (not 24h).
I have several other devices with FW based on custom mega-20230306 but without 7 segment LED.
All work fine including those with 4x20 and 2x16 LDC display.
Any potential bug or my error?

UPDATE
Rules based on syntax:

Code: Select all

On Clock#Time=All,**:** Do
works properly

User avatar
Ath
Normal user
Posts: 3506
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 7 segment LED display and time rules

#2 Post by Ath » 17 Apr 2023, 08:21

That numerical parsing issue has been solved in the 20230409 release, so upgrading to the latest mega sources should get you going again.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8747
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 7 segment LED display and time rules

#3 Post by TD-er » 17 Apr 2023, 09:07

Syntax error in your rules:

Code: Select all

...
on Rules#Timer=3 do
 if %isntp% = 1
  reboot
 endif
endon

if %uptime% > 10
 reboot
Endif
The last if check will never be "executed" as you need to act on an event. (a block within On ... Do ... endon)
So something like this will probably work:

Code: Select all

On Clock#Time=All,**:** Do
  if %uptime% > 10
    reboot
  Endif
Endon

mackowiakp
Normal user
Posts: 531
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: 7 segment LED display and time rules

#4 Post by mackowiakp » 17 Apr 2023, 10:04

That numerical parsing issue has been solved in the 20230409 release, so upgrading to the latest mega sources should get you going again.
I just compiled FW based on 20230409 release, but rule below still does not work.

Code: Select all

On Clock#Time=All,09:56 do 
 TimerSet,3,57
Endon

on Rules#Timer=3 do
 if %isntp% = 1
  reboot
 endif
endon
If I set manually from "Tools" menu:

Code: Select all

TimerSet,3,57
reboot is done properly.

Once more. The problem occurs only if FW contain 7-segment driver.

TD-er
Core team member
Posts: 8747
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 7 segment LED display and time rules

#5 Post by TD-er » 17 Apr 2023, 10:06

Do you have multiple "Clock#Time" blocks in your rules?

Edit:
Once more. The problem occurs only if FW contain 7-segment driver.
Hmm can you look at the timing stats, to see if there's something blocking execution so this clock event may not be matched?

mackowiakp
Normal user
Posts: 531
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: 7 segment LED display and time rules

#6 Post by mackowiakp » 17 Apr 2023, 10:37

Do you have multiple "Clock#Time" blocks in your rules?
Yes, I have. Both in FW containing 7-segment display driver and without one.
In this particular case (not test device but really working) another statements looks like this:

Code: Select all

On Clock#Time=All,**:** Do
....
....
On Clock#Time=All,03:35 Do
....
....
On Clock#Time=All,3:05 do
....
First one works OK.

But on the test device I have only one "Clock#Time" statement. So no other can block execution.

TD-er
Core team member
Posts: 8747
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 7 segment LED display and time rules

#7 Post by TD-er » 17 Apr 2023, 11:30

The most generic one should be at the bottom as the rules parsing stops when a matching rules block is found.

Thus place this one at the bottom:

Code: Select all

On Clock#Time=All,**:** Do
Also not sure if this will work, maybe you need a leading 0 in the hour value:

Code: Select all

On Clock#Time=All,3:05 do

mackowiakp
Normal user
Posts: 531
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: 7 segment LED display and time rules

#8 Post by mackowiakp » 17 Apr 2023, 12:09

Ok I see. So the most general rule should be placed last.
As I understand this also applies to the rule number.
That is, the line containing "On Clock#Time=All,3:05 do" must be in set #1 and the line containing "On Clock#Time=All,**:** Do" in set #3 for example.
Am I thinking right?
In the meantime, I'll try and let you know.

TD-er
Core team member
Posts: 8747
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 7 segment LED display and time rules

#9 Post by TD-er » 17 Apr 2023, 12:18

The most specific matching event should be first.


Thus:
* "Clock#Time=All,10:00" should be before "Clock#Time=All,10:**"
* "Clock#Time=All,10:**" should be before "Clock#Time=All,**:**"
* "Clock#Time=Mon,**:**" should be before "Clock#Time=All,**:**"

etc.

But also on task value events like these:
"On switch#state=1 do" is more specific than "On switch#state do"

mackowiakp
Normal user
Posts: 531
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: 7 segment LED display and time rules

#10 Post by mackowiakp » 17 Apr 2023, 14:05

* * "Clock#Time=All,10:**"
* "Clock#Time=All,**:**"
OK, but do i understand correctly. In this case above, if the first rule is executed then the second rule will fail because the first matching rule will interrupt the execution of the following ones?

TD-er
Core team member
Posts: 8747
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 7 segment LED display and time rules

#11 Post by TD-er » 17 Apr 2023, 16:12

That's correct.

So if you have common stuff to do, you can place those in a separate event block and generate an event to execute that block.

Code: Select all

On Clock#Time=All,10:** Do
  asyncevent,CommonClockEvent
  logEntry,"10:** time"
Endon

On Clock#Time=All,**:** Do
  asyncevent,CommonClockEvent
  logEntry,"**:** time"
Endon

on CommonClockEvent do
  logEntry,"Handling CommonClockEvent"
endon

mackowiakp
Normal user
Posts: 531
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: 7 segment LED display and time rules

#12 Post by mackowiakp » 18 Apr 2023, 03:58

Again, thank you very much for all your help.
The problems have been solved and everything works fine

TD-er
Core team member
Posts: 8747
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 7 segment LED display and time rules

#13 Post by TD-er » 18 Apr 2023, 09:45

You're welcome :)
Glad it is all working again.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 52 guests