diff --git a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi/giga-wifi.md b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi/giga-wifi.md index aa4f73115c..48c5e1116c 100644 --- a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi/giga-wifi.md +++ b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi/giga-wifi.md @@ -675,36 +675,36 @@ void printMacAddress(byte mac[]) { by Tom Igoe modified 23 March 2023 by Karl Söderby + modified 18 September 2025 + by Michele Zaffalon */ -#include #include -#include "arduino_secrets.h" +#include "arduino_secrets.h" ///////please enter your sensitive data in the Secret tab/arduino_secrets.h -char ssid[] = SECRET_SSID; // your network SSID (name) -char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // 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; WiFiServer server(23); -boolean alreadyConnected = false; // whether or not the client was connected previously - void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only + ; // wait for serial port to connect. Needed for native USB port only } // check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue - while (true); + while (true) + ; } @@ -728,27 +728,27 @@ void setup() { void loop() { // wait for a new client: - WiFiClient client = server.available(); - + WiFiClient client = server.accept(); // when the client sends the first byte, say hello: if (client) { - if (!alreadyConnected) { - // clear out the input buffer: - client.flush(); - Serial.println("We have a new client"); - client.println("Hello, client!"); - alreadyConnected = true; - } + Serial.println("We have a new client."); + client.println("Hello, client!"); - 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); + while (client.connected()) { + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + client.println(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } } + + // close the connection: + client.stop(); + Serial.println("client disconnected"); } } @@ -768,6 +768,11 @@ void printWifiStatus() { Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); + + // print the command to use with the telnet client: + Serial.print("To see this program in action, open a telnet client and type \"open "); + Serial.print(ip); + Serial.println("\""); } ``` @@ -1660,4 +1665,4 @@ void onMqttMessage(int messageSize) { Serial.println(); Serial.println(); } -``` \ No newline at end of file +```