Firmware TCPServer Dropped Connections

I am running this program on my Spark Core; basically, just copied over from here,

   TCPServer webServer = TCPServer(80);
    TCPClient webClient;
    void setup() {
    void loop() {
        if (webClient.connected() && webClient.available()) {
        else {
            webClient = webServer.available();
    void serveWebpage() {
        //TODO: read in the request to see what page they want:
        //TODO: retrieve larger content from flash?
        webClient.println("<html>I'm serving a webpage!</html>\n\n");

Spark core is powered by a 10,000 mAh Anker battery. the input of a Charger Doctor is connected to the battery and the output connected to the Spark Core USB port. The battery indicates 3/4 capacity. The current and voltage readings from the battery tend to fluctuate from around 5.0 to 5.2V and 110 to 160mA. If I move the Core to a PC USB port, the readings remain virtually constant at 5.06V and 150mA. Spark Core is connected as indicated by breathing cyan.

The problem is that the Core periodically drops the connection when powered from either USB or by battery. The following patterns are observed on the status LED. Pattern 1 is observed rarely.

Pattern 1

blinking cyan
LED goes off several seconds (maybe more)
blinking green
a couple of blinks red
LED comes back blinking cyan
LED starts breathing cyan

Pattern 2

blinking cyan
steady cyan for several seconds or more
LED starts breathing cyan

Pattern 3

blinking cyan
LED goes off several seconds
Steady cyan for several seconds or more
led starts breathing cyan

So my question is: what could be causing this behaviour? It could be my router, but I don’t think so. I have an ASUS RT-N56U router and it is pretty rock solid for all of my other clients; VoIp ATA, Netduino Plus 2, PCs, tablets, etc. Also, power doesn’t seem to be a problem. I suspect something is wrong with the program (or, maybe the firmware).

I’m seeing similar behavior in my webserver project that uses the Webserver library, which is also based on TCPServer. I learned that power is not the issue. The usage of the WiFi component by either the Spark firmware or my own code does have significant influence. The WiFi driver is often blocking for small durations and less often for longer durations. When the core is not connected to the cloud, the core behaves more stable. In my project the core will reset within ten minutes or so when connected to the cloud. Without the connection it may survive for more than an hour, but it will still reset in some point in time.

My conclusion is that the WiFi driver is still far from stable and I can only hope for better times…