@@ -675,36 +675,36 @@ void printMacAddress(byte mac[]) {
675675 by Tom Igoe
676676 modified 23 March 2023
677677 by Karl Söderby
678+ modified 18 September 2025
679+ by Michele Zaffalon
678680 */
679681
680- #include <SPI.h>
681682#include <WiFi.h>
682683
683- #include "arduino_secrets.h"
684+ #include "arduino_secrets.h"
684685///////please enter your sensitive data in the Secret tab/arduino_secrets.h
685- char ssid[] = SECRET_SSID; // your network SSID (name)
686- char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
686+ char ssid[] = SECRET_SSID; // your network SSID (name)
687+ char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
687688
688- int keyIndex = 0; // your network key index number (needed only for WEP)
689+ int keyIndex = 0; // your network key index number (needed only for WEP)
689690
690691int status = WL_IDLE_STATUS;
691692
692693WiFiServer server(23);
693694
694- boolean alreadyConnected = false; // whether or not the client was connected previously
695-
696695void setup() {
697696 //Initialize serial and wait for port to open:
698697 Serial.begin(9600);
699698 while (!Serial) {
700- ; // wait for serial port to connect. Needed for native USB port only
699+ ; // wait for serial port to connect. Needed for native USB port only
701700 }
702701
703702 // check for the WiFi module:
704703 if (WiFi.status() == WL_NO_MODULE) {
705704 Serial.println("Communication with WiFi module failed!");
706705 // don't continue
707- while (true);
706+ while (true)
707+ ;
708708 }
709709
710710
@@ -728,27 +728,27 @@ void setup() {
728728
729729void loop() {
730730 // wait for a new client:
731- WiFiClient client = server.available();
732-
731+ WiFiClient client = server.accept();
733732
734733 // when the client sends the first byte, say hello:
735734 if (client) {
736- if (!alreadyConnected) {
737- // clear out the input buffer:
738- client.flush();
739- Serial.println("We have a new client");
740- client.println("Hello, client!");
741- alreadyConnected = true;
742- }
735+ Serial.println("We have a new client.");
736+ client.println("Hello, client!");
743737
744- if (client.available() > 0) {
745- // read the bytes incoming from the client:
746- char thisChar = client.read();
747- // echo the bytes back to the client:
748- server.write(thisChar);
749- // echo the bytes to the server as well:
750- Serial.write(thisChar);
738+ while (client.connected()) {
739+ if (client.available() > 0) {
740+ // read the bytes incoming from the client:
741+ char thisChar = client.read();
742+ // echo the bytes back to the client:
743+ client.println(thisChar);
744+ // echo the bytes to the server as well:
745+ Serial.write(thisChar);
746+ }
751747 }
748+
749+ // close the connection:
750+ client.stop();
751+ Serial.println("client disconnected");
752752 }
753753}
754754
@@ -768,6 +768,11 @@ void printWifiStatus() {
768768 Serial.print("signal strength (RSSI):");
769769 Serial.print(rssi);
770770 Serial.println(" dBm");
771+
772+ // print the command to use with the telnet client:
773+ Serial.print("To see this program in action, open a telnet client and type \"open ");
774+ Serial.print(ip);
775+ Serial.println("\"");
771776}
772777```
773778
@@ -1660,4 +1665,4 @@ void onMqttMessage(int messageSize) {
16601665 Serial.println();
16611666 Serial.println();
16621667}
1663- ```
1668+ ```
0 commit comments