From d09655d4780dbd444c737cbdb015c7eee268300d Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 12 Mar 2012 13:57:42 -0400 Subject: [PATCH 1/2] Updated WifiChatServer to clear out garbage characters --- .../WifiChatServer/WifiChatServer.ino | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/WiFi/examples/WifiChatServer/WifiChatServer.ino b/WiFi/examples/WifiChatServer/WifiChatServer.ino index 441491f13..22b9e546a 100644 --- a/WiFi/examples/WifiChatServer/WifiChatServer.ino +++ b/WiFi/examples/WifiChatServer/WifiChatServer.ino @@ -14,24 +14,24 @@ created 18 Dec 2009 by David A. Mellis - modified 4 Mar 2012 + modified 12 Mar 2012 by Tom Igoe */ - #include #include char ssid[] = "YourNetwork"; // your network SSID (name) char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) + int keyIndex = 0; // your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; WiFiServer server(23); -boolean gotAMessage = false; // whether or not you got a message from the client yet +boolean alreadyConnected = false; // whether or not the client was connected previously void setup() { // initialize serial: @@ -55,20 +55,25 @@ void loop() { // wait for a new client: WiFiClient client = server.available(); + // when the client sends the first byte, say hello: if (client) { - if (!gotAMessage) { + if (!alreadyConnected) { + // clead out the input buffer: + client.flush(); Serial.println("We have a new client"); client.println("Hello, client!"); - gotAMessage = true; - } + alreadyConnected = true; + } - // read the bytes incoming from the client: - char thisChar = client.read(); - // echo the bytes back to the client: - server.write(thisChar); - // echo the bytes to the server as well: - Serial.print(thisChar); + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } } } From 71ee20314fbdc15da75dda68f1e993881e90f61a Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 12 Mar 2012 14:35:02 -0400 Subject: [PATCH 2/2] Re-formatted ScanNetworks output --- WiFi/examples/ScanNetworks/ScanNetworks.ino | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/WiFi/examples/ScanNetworks/ScanNetworks.ino b/WiFi/examples/ScanNetworks/ScanNetworks.ino index c1267e672..ecae9b300 100644 --- a/WiFi/examples/ScanNetworks/ScanNetworks.ino +++ b/WiFi/examples/ScanNetworks/ScanNetworks.ino @@ -10,7 +10,7 @@ created 13 July 2010 by dlf (Metodo2 srl) - modified 9 Mar 2012 + modified 12 Mar 2012 by Tom Igoe */ @@ -26,7 +26,6 @@ void setup() { Serial.println("Initializing Wifi..."); printMacAddress(); - // scan for existing networks: Serial.println("Scanning available networks..."); listNetworks(); @@ -72,13 +71,12 @@ void listNetworks() { for (int thisNet = 0; thisNet