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