system variable after boot

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
obod0002c
Normal user
Posts: 119
Joined: 10 Aug 2019, 20:31

system variable after boot

#1 Post by obod0002c » 28 Nov 2021, 20:43

Hi,
beg this has been answered somewhere .. but I don't find it and I also don't get it solved ..

When (re)booting my device, system variables as e.g. %ip% or the fourth octet of Devices -> System Info -> IP does not seem to be loaded.
Looks like that takes some time?

How can I have my ESP wait for a state where all variables are loaded and available correctly?

I'm running ESP_Easy_mega_20211105_normal_WROOM02_2M256 on this device.

Thanks for your help

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

Re: system variable after boot

#2 Post by Ath » 28 Nov 2021, 21:37

After event "Wifi#Connected" the network interface, including IP address, will be initialized properly, so after that you can use those values.

All System events can be found on this documentation page: https://espeasy.readthedocs.io/en/lates ... Rules.html
/Ton (PayPal.me)

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

Re: system variable after boot

#3 Post by TD-er » 29 Nov 2021, 00:54

To be slightly more specific with the link to the events: https://espeasy.readthedocs.io/en/lates ... ore-events

But Ton's link may provide more examples.
Better read both :)

obod0002c
Normal user
Posts: 119
Joined: 10 Aug 2019, 20:31

Re: system variable after boot

#4 Post by obod0002c » 29 Nov 2021, 09:49

Thanks for your posts.

Meanwhile I believe it's due to the standard 60sec in the Device's-tab for this item - although I thought it might set the values first and THEN run down the counter to update them 60seconds later 8-)
Attachments
delayDevices.png
delayDevices.png (22.12 KiB) Viewed 5745 times

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

Re: system variable after boot

#5 Post by TD-er » 29 Nov 2021, 11:27

Not sure if your conclusion is correct, or not all is clear to me ;)

The sysinfo task may report wrong info on its first call, as that's done before WiFi is initialized.
So you may want to call taskrun on that task as soon as you see the WiFi#Connected event.

obod0002c
Normal user
Posts: 119
Joined: 10 Aug 2019, 20:31

Re: system variable after boot

#6 Post by obod0002c » 29 Nov 2021, 16:34

hmm, getting lost even more ..

What I'm trying to do: setting up three devices (two differing, two identical ones) using the same rules for all three. I'd like to differentiate the devices by their fixed ip addresses.

Code: Select all

on System#Boot do
 TaskValueSet 6,2,  74 // identical setting regardless of device
endon

on WiFi#Connected do
 taskrun,12 // initialize 4th ip octet

 if %ip% = 192.168.178.52
  // do [1]
 endif

 if %ip% = 192.168.178.61
  // do [2]
 endif

 if %ip% = 192.168.178.46
 // do [3]
 endif
endon
But it reaches the wrong section ..

Tools -> System variables is showing the correct ip address

Code: Select all

%ip% 	192.168.178.52
it hence should perform statements in [1] but it executes the [3] part that's meant for a differing ip address.

The commands in the if statements are pretty plain ones, e.g.

Code: Select all

gpio, 4,0
What am I doing wrong?

P.S.: taskrun is working fine, but maybe not the solution to my problem

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

Re: system variable after boot

#7 Post by TD-er » 29 Nov 2021, 16:47

This is not going to work:

Code: Select all

if %ip% = 192.168.178.52
The IP-address may be parsed into a floating point value 192.168
Not sure if it will evaluate to true, but if it does, then it does it probably for all your nodes.

Just assuming you have a "class C" network (subnet = 255.255.255.0) then you could compare the last part of the IP:

Code: Select all

on System#Boot do
 TaskValueSet 6,2,  74 // identical setting regardless of device
endon

on WiFi#Connected do
 taskrun,12 // initialize 4th ip octet

 if %ip4% = 52
  // do [1]
 endif

 if %ip4% = 61
  // do [2]
 endif

 if %ip4% = 46
 // do [3]
 endif
endon
The sysinfo task is not responsible for the system variables to be initialized.

obod0002c
Normal user
Posts: 119
Joined: 10 Aug 2019, 20:31

Re: system variable after boot

#8 Post by obod0002c » 29 Nov 2021, 18:27

This is not going to work:
if %ip% = 192.168.178.52
in the afterglow this makes sense.

Pity, I had chosen a test before that worked .. for the last !! of the three devices (can I call this 'worked', hmm ;) )

Thanks so much. Cheers

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests