Wait() in setup question.
-
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!
-
@skywatch
loop()
will not be run until aftersetup()
is finished (unless maybe if you have setMY_TRANSPORT_WAIT_READY_MS
but perhaps even not then), but I thinkreceive()
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.
-
@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!
-
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 )
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
LAN8720A - will mysensors work with this module
Development • 13 Nov 2024, 17:06 • Marcin 15 Nov 2024, 10:59 -
Home Assistant/MySensors quirks
Development • 12 days ago • OldSurferDude 12 days ago -
Gateway without a radio
Development • 12 Jan 2025, 23:19 • OldSurferDude 14 Jan 2025, 22:07 -
Sending offset to node
Development • 31 Jan 2025, 00:59 • bsl88k 4 Feb 2025, 12:14 -
MQTT-Help me understand about the MQTT Gateway.
Development • 27 days ago • dpcons 16 days ago