Skip to content

Commit 2ba1f44

Browse files
authored
Merge pull request #133 from JAndrassy/wifis3_example_pagerserver
WiFiS3 example WiFiPagerServer
2 parents 7061327 + 5c47583 commit 2ba1f44

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
WiFi Pager Server
3+
4+
The example is a simple server that echoes any incoming
5+
messages to all connected clients. Connect two or more
6+
telnet sessions to see how server.available() and
7+
server.print() work.
8+
9+
You may need to update the firwmare on your WiFi module.
10+
Download the files and follow the instructions from
11+
https://github.com/arduino/uno-r4-wifi-usb-bridge/releases/tag/0.3.0 .
12+
13+
Run a nmap scan or check the output of this sketch to obtain
14+
the IP given to your DHCP server to this sketch, i.e.
15+
16+
Nmap scan report for esp32s3-C4E524 (192.168.8.161)
17+
Host is up (0.012s latency).
18+
Not shown: 999 closed ports
19+
PORT STATE SERVICE
20+
23/tcp open telnet
21+
22+
Connect via telnet (at least twice):
23+
telnet 192.168.8.161
24+
*/
25+
26+
#include <WiFiS3.h>
27+
28+
#include "arduino_secrets.h"
29+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
30+
char ssid[] = SECRET_SSID; // your network SSID (name)
31+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
32+
33+
int status = WL_IDLE_STATUS;
34+
35+
WiFiServer server(23);
36+
37+
void setup() {
38+
39+
//Initialize serial and wait for port to open:
40+
Serial.begin(9600);
41+
while (!Serial) {
42+
; // wait for serial port to connect. Needed for native USB port only
43+
}
44+
45+
// check for the WiFi module:
46+
if (WiFi.status() == WL_NO_MODULE) {
47+
Serial.println("Communication with WiFi module failed!");
48+
// don't continue
49+
while (true);
50+
}
51+
52+
String fv = WiFi.firmwareVersion();
53+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
54+
Serial.println("Please upgrade the firmware");
55+
}
56+
57+
// attempt to connect to WiFi network:
58+
while (status != WL_CONNECTED) {
59+
Serial.print("Attempting to connect to SSID: ");
60+
Serial.println(ssid);
61+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
62+
status = WiFi.begin(ssid, pass);
63+
64+
// wait 10 seconds for connection:
65+
delay(10000);
66+
}
67+
68+
server.begin();
69+
70+
IPAddress ip = WiFi.localIP();
71+
Serial.println();
72+
Serial.println("Connected to WiFi network.");
73+
Serial.print("To access the server, connect with Telnet client to ");
74+
Serial.print(ip);
75+
Serial.println(" 23");
76+
}
77+
78+
void loop() {
79+
80+
WiFiClient client = server.available(); // returns first client which has data to read or a 'false' client
81+
if (client) { // client is true only if it is connected and has data to read
82+
String s = client.readStringUntil('\n'); // read the message incoming from one of the clients
83+
s.trim(); // trim eventual \r
84+
Serial.println(s); // print the message to Serial Monitor
85+
client.print("echo: "); // this is only for the sending client
86+
server.println(s); // send the message to all connected clients
87+
server.flush(); // flush the buffers
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID ""
2+
#define SECRET_PASS ""

0 commit comments

Comments
 (0)