Wait() in setup question.
skywatch last edited by
So I can't figure this out -
If I use a wait() in setup(), will this delay running loop() and all other functions (like Receive() ) until after the wait() has timed out?
Will receive() still function even if a wait() is running in setup()?
Having a bad brain day it seems!
loop()will not be run until after
setup()is finished (unless maybe if you have set
MY_TRANSPORT_WAIT_READY_MSbut perhaps even not then), but I think
receive()will work because the transport has been initialized.
https://www.mysensors.org/download/sensor_api_20#node-boot-sequence might be useful to better understand the flow.
skywatch last edited by skywatch
@mfalkvidd Thank you for confirming that is how it works - so my next question is that if receive() is being called and functioning, but loop() is not - what happens to the messages with state change for a node child?
Clearly nothing within the loop() is updated (as it is not running) so messages received will be ignored until such time as loop() is able to process incoming messages? Or the state changes get lost?
To elaborate on my use, the issues is 'synching' LED lights with the controller after an unexpected power cut.
I have the nodes remember in eeprom their last state, but can't send that when the power comes back on as it takes a while for the controller and pi to boot and be running. If the nodes send it straight away the controller won't be available.
So a wait() in setup seems a way to do this, but with receive() running and loop() not then I am wondering what problems might occur if someone changes the lights state during this wait() period......
The nodes have IR senders for light control and IR receivers so that even if the manufacturers remote for the lights is used, then this is sensed by the node and the controller gets updated. This means that any method of changing the lights can be used and the controller always knows the status.
I suppose I could put the delay in loop() and only have it for the first run of loop() or I could add a before().... I have to give this some more thought!
JeeLet last edited by
maybe this can be useful : https://forum.mysensors.org/topic/6948/synchronising-light-switch
I use it with version 1requestState or 2 requestTime() on some sketches
(I modified the structure, moved some parts to functions to make it more readable )