The documentation for Spark.sleep() says:
Spark.sleep(int seconds) does NOT stop the execution of
user code (non-blocking call). User code will continue running while the Wi-Fi module is in standby mode. During sleep, WiFi.status() will return WIFI_OFF. Once sleep time has expired and the Wi-FI module attempts reconnection, WiFi.status() will return value WIFI_CONNECTING and WIFI_ON.
This implied to me that the code in the neverending loop part of the firmware would do just that, loop forever. However, it appears that the code also runs the setup section of the code every time it wakes up after sleep. Thus the code ran from initial conditions after every sleep and my variables kept being reset to initial values. I have had to modify my code so that manual intervention soon after startup sets the intial conditions, not the setup part of the code. At least it works now and things are not mysteriously reset without my permission (so to speak). I think the docs should be changed to indicate that code runs from the beginning and doesn’t stay within the “forever” loop when sleep is involved. I am not using deep sleep by the way.