1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-19 09:42:11 +03:00

Merge branch 'master' of github.com:arduino/wifishield

This commit is contained in:
Mimmo La Fauci
2012-03-13 12:22:27 +01:00
2 changed files with 22 additions and 19 deletions

View File

@ -10,7 +10,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 9 Mar 2012 modified 12 Mar 2012
by Tom Igoe by Tom Igoe
*/ */
@ -26,7 +26,6 @@ void setup() {
Serial.println("Initializing Wifi..."); Serial.println("Initializing Wifi...");
printMacAddress(); printMacAddress();
// scan for existing networks: // scan for existing networks:
Serial.println("Scanning available networks..."); Serial.println("Scanning available networks...");
listNetworks(); listNetworks();
@ -72,13 +71,12 @@ void listNetworks() {
for (int thisNet = 0; thisNet<numSsid; thisNet++) { for (int thisNet = 0; thisNet<numSsid; thisNet++) {
Serial.print(thisNet); Serial.print(thisNet);
Serial.print(") "); Serial.print(") ");
Serial.println(WiFi.SSID(thisNet)); Serial.print(WiFi.SSID(thisNet));
Serial.print("Signal Strength: "); Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet)); Serial.print(WiFi.RSSI(thisNet));
Serial.println("dBm"); Serial.print(" dBm");
Serial.print("Encryption Type: "); Serial.print("\tEncryption: ");
Serial.println(WiFi.encryptionType(thisNet)); Serial.println(WiFi.encryptionType(thisNet));
Serial.println();
} }
} }

View File

@ -14,24 +14,24 @@
created 18 Dec 2009 created 18 Dec 2009
by David A. Mellis by David A. Mellis
modified 4 Mar 2012 modified 12 Mar 2012
by Tom Igoe by Tom Igoe
*/ */
#include <SPI.h> #include <SPI.h>
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "YourNetwork"; // your network SSID (name) char ssid[] = "YourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) 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 keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS; int status = WL_IDLE_STATUS;
WiFiServer server(23); 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() { void setup() {
// initialize serial: // initialize serial:
@ -55,20 +55,25 @@ void loop() {
// wait for a new client: // wait for a new client:
WiFiClient client = server.available(); WiFiClient client = server.available();
// when the client sends the first byte, say hello: // when the client sends the first byte, say hello:
if (client) { if (client) {
if (!gotAMessage) { if (!alreadyConnected) {
// clead out the input buffer:
client.flush();
Serial.println("We have a new client"); Serial.println("We have a new client");
client.println("Hello, client!"); client.println("Hello, client!");
gotAMessage = true; alreadyConnected = true;
} }
// read the bytes incoming from the client: if (client.available() > 0) {
char thisChar = client.read(); // read the bytes incoming from the client:
// echo the bytes back to the client: char thisChar = client.read();
server.write(thisChar); // echo the bytes back to the client:
// echo the bytes to the server as well: server.write(thisChar);
Serial.print(thisChar); // echo the bytes to the server as well:
Serial.write(thisChar);
}
} }
} }