UPDATE:
I’ve now run the test on a live host. Works much better, but still problems. Haven’t noticed any long outages but approximately 10% of the connects still fail. However it usually picks it up at the next 5 second interval. Another 5% of the time I get a connect okay, but the rest of the communication doesn’t go through. Again it usually picks it up the next time around. So, I guess it’s mandatory to monitor the return message to make sure it completed ok.
Another problem of greater concern is that the Spark will randomly reset itself (I guess that’s what it’s doing). This occurs at random intervals of between 5 minutes, and 12 minutes. When it occurs all communication stops and I see (as best I can tell) 8 red flashes, pause, 1 red flash, pause, 9 red flashes, pause, followed by 1 red flash. This is followed by some rapid green flashes, rapid blue flashes, and normal breathing pattern. NOTE: To save you some reading, I patched over this problem by adding delays after each client.println(). Doesn’t give me a warm fuzzy feeling but it seems to clear the problem up.
Here is the original post, which I will leave as is because it might be a useful data point for anyone trying to do local development (BTW, the reason for local development is that real web hosts will block your IP if you make too many bad requests on their server):
Hi,
The Spark Core appears to be randomly bombing out while sending web requests to a local (non cloud) server. The program will run fine for long periods of time, then will fail. Sometimes the device will reset itself, and try to recover, yet will not send out packets. Then after some time it will correctly connect and communicate with the server for several minutes before failing again. Any thoughts will be appreciated.
Setup: Spark Core (at 192.168.1.108) with builtin Antenna, Linksys (Cisco) E2000 router (20’ away), destination server XAMPP (Apache & PHP) running on XP box connected via Ethernet to router.
Problem:
- Keep getting Connect Fail (ie client.connect() returns 0).
- Wireshark running on the XP server shows packets coming in from 192.168.1.108 when device is running normally.
- Wireshark shows absolutely no packets coming from 192.168.1.108 while I’m getting the Connect Fail messages (Spark is still breathing and sending out serial messages).
- Occasionally it will connect but won’t allow further communication (println()s).
- Resetting, and/or removing and reapplying power doesn’t help. Measured power with DVM: VIn = 4.78V, V3.3 = 3.28V. Power viewed with scope looks ok.
- Can be reprogrammed via Cloud IDE 80% of the time while the fail to connect situation has gone on for many minutes previously, so WiFi is working.
- Sometimes during all of this, without any intervention, instead of “breathing” it blinks red, then eventually goes back to breathing, outputting to Serial1, but not connecting.
Note: it can run well for 30 minutes or more, and then fail, giving repeated Connect Fail messages for 30 minutes or more before recovering by itself. Totally unrelated to any other network traffic from what I can tell.
#Code:
TCPClient client;
byte serverAddress[] = { 192, 168, 1, 141 };
unsigned long lasttime = 0L;
void setup()
{
Serial1.begin(9600);
delay(2000);
Serial1.flush();
Serial1.println(Network.SSID());
Serial1.println(Network.gatewayIP());
Serial1.println(Network.subnetMask());
Serial1.println(Network.localIP());
}
void loop()
{
unsigned long time;
time = millis();
if ((time - lasttime) >= 5000L)
{
lasttime += 5000L;
if (client.connect(serverAddress, 80))
{
Serial1.write("(V33 Connect Success)\r\n");
client.println("GET /farCI3F4/get_test.php?what=cheese&who=mickeymouse HTTP/1.1");
client.println("Host: 192.168.1.141");
client.println("Content-Length: 0");
client.println("Connection: Keep-Alive");
client.println();
while ((millis() - lasttime) < 1000)
{
char c = client.read();
if (c >= 0)
{
Serial1.print(c);
}
}
Serial1.println();
client.stop();
}
else
{
Serial1.write("(V33 Connect Fail) ");
client.stop();
}
}
}
#get_test.php
on root directory of web server
<?php
$data_array = array(
'what' => $_GET["what"] ,
'who' => $_GET["who"]);
echo "Ok ";
?>
#Results through Serial Port 1:
ELLDA
192.168.1.1
255.255.255.0
192.168.1.108
(V33 Connect Success)
HTTP/1.1 200 OK
Date: Fri, 27 Jun 2014 00:21:45 GMT
Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
X-Powered-By: PHP/5.4.7
Content-Length: 3
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Ok
(V33 Connect Success)
(V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33
Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Con
nect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect
Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fai
l) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (
V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33
Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Conn
ect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect
Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail
) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V
33 Connect Fail) (V33 Connect Success)
(V33 Connect Success)
(V33 Connect Success)
(V33 Connect Success) <<== NOTE: It connects, but won't communicate
(V33 Connect Success)
(V33 Connect Success)
(V33 Connect Success)
(V33 Connect Success)
(V33 Connect Success)
(V33 Connect Success)
HTTP/1.1 200 OK
Date: Fri, 27 Jun 2014 00:25:30 GMT
Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
X-Powered-By: PHP/5.4.7
Content-Length: 3
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Ok
(V33 Connect Success)
HTTP/1.1 200 OK
Date: Fri, 27 Jun 2014 01:02:43 GMT
Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
X-Powered-By: PHP/5.4.7
Content-Length: 3
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Ok
(V33 Connect Success)
.......
ELLDA
192.168.1.1
255.255.255.0
192.168.1.108
(V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33
Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Con
nect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect
Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fai
l) (V33 Connect Fail) (V33 Connect Fail) (V33 Connect Fail)