I’ve ported over the webduino webserver to the spark and have been stumped for hours why I’m not getting the correct response from a simple example, yet some of the built in web pages (like favicon.ico) do work.
I’ve reduced the problem down to how the message is printed. Here are two functions that handle page output - they only differ in the how they print the response body. The first case prints using 3 separate prints:
void cmd1(WebServer &server, WebServer::ConnectionType type, char * data, bool)
{
server.printP("HTTP/1.0 200 OK" CRLF);
server.printP("Content-Type: text/html" CRLF CRLF);
server.printP("Hello world");
}
This doesn’t work. Connecting with telnet and typing GET /1 HTTP/1.0' <CRLF> <CRLF>
I get a “connection closed by remote host” after the 2nd line has been printed, before Hello world
is printed. 100% reproducable.
Here’s the code that works:
void cmd2(WebServer &server, WebServer::ConnectionType type, char * data, bool)
{
server.printP("HTTP/1.0 200 OK" CRLF);
server.printP("Content-Type: text/html" CRLF CRLF "Hello world");
server.printP("It's 42");
}
This works, I now see “Hello world” in the browser, but not “It’s 42”. Again, I get a disconnect before the third print.
Trying to make sense of the code:
server.printP()
calls `TCPClient.write(string, strlen(string));’, which is implemented as
status() ? send(...) : -1
To be sure it wasn’t a problem with status() dropping calls to send, I just made the send unconditional. No change.
send()
calls simple_link_send(sd, buf, len, flags, NULL, 0, HCI_CMND_SEND);
so then it’s down to the CC3000.
This is strange behaviour, but good that it is 100% reproducable, so there is a chance of tracking down the bug. But I’m out of my depth debugging the CC3000 - I hope someone can help.