I have two projects having problems when it comes to reflash the core. One is my 8x8x8 cube, running code to display 3D patterns. The main loop takes several seconds to display all patterns.
When I try to flash new code, the core stops somewhere, the LED is blinking cyan, and 2 seconds later the software continuous. At the end of the void(loop) procedure I call SPARK_WLAN_Loop() during 20ms.
I understand that the code inside void(loop) is just part of a bigger system. But what is the right strategy to keep the core responsive to the cloud and reflash?
But the common practice is to ensure that Spark.process() or SPARK_WLAN_Loop() or delay() is called at least once every 10sec, to keep the cloud connection alive and the Core responsive for cloud actions - more often would be better and more responsive the Core will be.
@ScruffR is correct. Perhaps you would consider adding a button or a 5ish second delay in the setup which would call SPARK_WLAN_Loop() so you would have some time to flash the core?
@digixx, you could also call SPARK_WAN_Loop() at various points in your loop(), or like @harrisonhjones eluded to, add a simple jumper (to GND) on a pin and in setup(), set the pin as an INPUT, read it and if it is LOW, go into an timed or infinite SPARK_WAN_Loop() loop to allow for OTA programming. I think someone had some code for that in another topic.
I thought that the breathing LED means good connection to the WiFi / Cloud. So I changed the code and put a 10 second wait in setup() and run SPARK_WLAN_Loop() between every pattern. Now its no problem to reflash.
The other project is a bit different because the core is battery powered and it goes immediately to sleep when it has send the weather data to the webservice. If the response of the webservice is ‘$’, the core stays awake and run SPARK_WLAN_Loop() for the next 5 minutes. Unfortunately it does not recognize the ‘$’ anymore. The project stays in my backyard and I have to screw off the electronics for investigation. I have to say that the core now runs for more than 3 month without power off.
This is the project I am talking about. You can find the code here
Look at weather_station.ino. At line 97 starts function updateDATA() which concatenates all sensor data to a string and send it with a GET to the webservice. By default, the webservice does not send any data back. I enable it manualy in the code of the webservice. If it sends a $ back, the core does not execute the sleep function and stays awake. At the moment this seams not to work. When I send sensor data from a browser, the $ is send back. Tomorrow, I will get the electronic on the bench and connect the serial debugger.
The 4 cell NiCd Battery is powered by solar cells. A power up/down converter from Pololu then produces 3.3V voltage for the core and the sensors.
Since several days without direct sunlight, the voltage from the battery has dropped from 5.6V to 5.0V. Also with very poor daylight, the solar cells produces still some milliamps. The voltage drop is about 0.08V per day. If the voltage get lower than 4.3V, sleeping interval is extended to 20min.
I can flash the core now. I am not shure what the problem was.
The weather station now sends the brightness level into the cloud via spark.publish(). My MessageTorch receives the event and switches the lamp on/off if the brightness cross a certain level.