Dear everybody,
My programm become complexe and I need to start more services such as 2 threads, a watchdog, a wifi client and a MQTT client, sd card, lcd and I/O and I wonder if there is right order in calling these functions in setup()? for exemple for memory management in order to prevent board effect(i.e. variable corruption) ? any idea, some tips?
Thanks a lot for your advise
There should be no variable corruption whatsoever if you have enough memory for all the services.
The order in which you start them has to be "logical", ie start the services in the order of dependencies.
- setup the board's pin as the first thing.
- if you want to print debug info about the services you are starting, call
Serial.begin()first - if you want MQTT to work, connect to the WiFi or Ethernet before doing the MQTT stuff
- ...
1 Like
Variable corruption happens when you run out of memory (clash of heap and stack) or if your code touches memory that it's not supposed to touch (e.g. writing outside the bounds of an array).
Neither of those will be prevented with a certain sequence of starting of 'services'.