Let’s see if it can ping www.google.com at port 80. This code will print out some other diagnostics too. It is curious why some things show up with information and other items report 0.0.0.0. I do call Particle.process().
// Use primary serial over USB interface for logging output
SerialLogHandler logHandler;
TCPClient client;
IPAddress ip;
int reading_content = 0;
int connected = 0;
String msg = "";
void setup() {
// The WiFi module saves credentials!
//WiFi.clearCredentials();
delay(10000);
waitUntil(WiFi.ready);
byte mac[6];
Particle.process();
Log.info("System version: %s", System.version().c_str());
Log.info("Wifi SSID: %s", WiFi.SSID());
WiFi.BSSID(mac);
Log.info("Mac address SSID: %02x:%02x:%02x:%02x:%02x:%02x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
WiFi.macAddress(mac);
Log.info("Mac address: %02x:%02x:%02x:%02x:%02x:%02x", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
ip = WiFi.dhcpServerIP();
Log.info("DHCP Server IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
ip = WiFi.localIP();
Log.info("Assigned IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
ip = WiFi.subnetMask();
Log.info("Subnet Mask: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
ip = WiFi.gatewayIP();
Log.info("Gateway IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
ip = WiFi.dnsServerIP();
Log.info("DNS Server IP: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
// Do a simple port 80 test to www.google.com to test for a firewall
// Port 80 is generally open
ip = WiFi.resolve("www.google.com");
Log.info("Resolved IP for www.google.com: %u.%u.%u.%u", ip[0],ip[1],ip[2],ip[3]);
if (client.connect(ip, 80))
{
Log.info("Connected...");
client.println("GET /search?q=unicorn HTTP/1.0");
client.println("Host: www.google.com");
client.println("Content-Length: 0");
client.println();
connected = 1;
}
else
{
Log.info("Connection failed.");
}
}
void loop()
{
if (client.available()) {
if (reading_content == 0) {
Log.info("Reading content...");
}
reading_content++;
char c = client.read();
if (c > 0) {
if (c == 10 || c == 13) {
if (msg != "") {
Log.info("Web>%s", (const char *) msg);
}
msg = "";
} else {
msg.concat(c);
}
}
}
if (connected && !client.connected())
{
if (msg != "") {
Log.info("Web>%s", (const char *) msg);
}
Log.info("Disconnecting.");
client.stop();
connected = 0;
}
}
Running this bit of code should log something similar. I put a delay in setup() so there is a better chance of capturing it in the log. Notice, you will see the header response right away. The body will not show up until Google drops the connection. I pulled the example from the docs.
$ particle serial monitor
Opening serial monitor for com port: "/dev/cu.usbmodem1421"
Serial monitor opened successfully:
0000007066 [system] INFO: CLR_WLAN_WD 1, DHCP success
0000007067 [system] INFO: Cloud: connecting
0000007067 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000007079 [system] INFO: Resolved host device.spark.io to 54.175.227.173
0000007189 [system] INFO: connected to cloud 54.175.227.173:5683
0000007190 [system] INFO: Cloud socket connected
0000007190 [system] INFO: Starting handshake: presense_announce=1
0000007190 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000007299 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000007346 [comm.sparkprotocol.handshake] INFO: Sending encrypted nonce
0000007347 [comm.sparkprotocol.handshake] INFO: Receive key
0000007470 [comm.sparkprotocol.handshake] INFO: Setting key
0000007659 [comm.sparkprotocol.handshake] INFO: Sending HELLO message
0000007659 [comm.sparkprotocol.handshake] INFO: Receiving HELLO response
0000007767 [comm.sparkprotocol.handshake] INFO: Completed
0000007768 [system] INFO: Send spark/hardware/max_binary event
0000007768 [system] INFO: spark/hardware/ota_chunk_size event
0000007768 [system] INFO: Send spark/device/last_reset event
0000007769 [system] INFO: Send subscriptions
0000007769 [comm.sparkprotocol] INFO: Sending TIME request
0000007771 [system] INFO: Cloud connected
0000009773 [comm.sparkprotocol] INFO: Received TIME response: 1497039148
0000010773 [comm.sparkprotocol] INFO: Sending A describe message
0000011788 [comm.sparkprotocol] INFO: Sending S describe message
0000017773 [app] INFO: System version: 0.6.2
0000017773 [app] INFO: Wifi SSID: romswrf
0000017773 [app] INFO: Mac address SSID: e4:ce:8f:69:28:d1
0000017773 [app] INFO: Mac address: 6c:0b:84:59:72:95
0000017774 [app] INFO: DHCP Server IP: 0.0.0.0
0000017774 [app] INFO: Assigned IP: 10.0.1.8
0000017774 [app] INFO: Subnet Mask: 255.255.255.0
0000017774 [app] INFO: Gateway IP: 10.0.1.1
0000017775 [app] INFO: DNS Server IP: 0.0.0.0
0000017779 [app] INFO: Resolved IP for www.google.com: 216.58.194.164
0000017845 [app] INFO: Connected...
0000018056 [app] INFO: Reading content...
0000018071 [app] INFO: Web>HTTP/1.0 200 OK
0000018108 [app] INFO: Web>Date: Fri, 09 Jun 2017 20:12:39 GMT
0000018121 [app] INFO: Web>Expires: -1
0000018156 [app] INFO: Web>Cache-Control: private, max-age=0
0000018201 [app] INFO: Web>Content-Type: text/html; charset=ISO-8859-1
0000018317 [app] INFO: Web>P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
0000018330 [app] INFO: Web>Server: gws
0000018363 [app] INFO: Web>X-XSS-Protection: 1; mode=block
0000018392 [app] INFO: Web>X-Frame-Options: SAMEORIGIN
0000018637 [app] INFO: Web>Set-Cookie: NID=105=bJ_yDctGKuWmxU2GOCiuaavFg7SKhb7ra_Je_TPoPjXXDN0B7EFraChE7ZEa4TIRc2qXc6gV2JsAxUo0P6HlWkW1SUEZplicUj0T1aL7_Iseoq26y8yU9sSp1Ybyr-NAx65OKQ~
0000018659 [app] INFO: Web>Accept-Ranges: none
0000018682 [app] INFO: Web>Vary: Accept-Encoding
0000076760 [app] INFO: Web><!doctype html><html itemscope="" itemtype="http://schema.org/SearchResultsPage" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Cont~
0000078978 [app] INFO: Web>beast with a single large, pointed, spiraling horn projecting from its forehead.</span><br><div class="osl"><a href="/url?q=https://en.wikipedia.org/wiki/~
0000079064 [app] INFO: Web>impossible. Impossible is nothing. Under no circumstances, never ever, not ever, <br>
0000083314 [app] INFO: Web>at no ...</span><br></div></div><div class="g"><h3 class="r"><a href="/search?q=unicorn&ie=UTF-8&prmd=ivns&tbm=isch&tbo=u&source=~
0000084869 [app] INFO: Web>Cute <b>unicorn</b> and <b>Unicorn</b> drawing.</span><br></div></div><div class="g"><div><h3 class="r"><a href="/search?q=unicorn&ie=UTF-8&prmd=i~
0000087146 [app] INFO: Web>and <b>unicorn</b> mimosas to Starbucks's <b>Unicorn</b> Frappucino, ...</span></div></div><div style="margin-top:4px"><a href="/url?q=http://www~
0000088280 [app] INFO: Web>unicorne, and their source, Latin ūnicornis, from unus (“one”) + cornu (“horn”).</span><br></div></div><div class="g"><h3 cla~
0000089346 [app] INFO: Web>of information systems and information and communication technologies.</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=http://fortune.c~
0000090790 [app] INFO: Web>billion-dollar technology startup was once the stuff of myth.</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=https://www.cbinsights.co~
0000092050 [app] INFO: Web>more.</span><br></div></div><div class="g"><h3 class="r"><a href="/url?q=https://www.wired.com/2015/02/fantastically-wrong-unicorn/&sa=U&ved=0ahUK~
0000103112 [app] INFO: Web>to capture one alive. It has the body of a horse, the head of a ...</span><br></div></div></ol></div></div></div><div style="clear:both;margin-bottom~
0000103113 [app] INFO: Disconnecting.