Skip to content

Commit cf1aeea

Browse files
committed
Merge remote-tracking branch 'origin/wifi_leven_dev' into HEAD
2 parents 4e631a0 + 6a1ca4b commit cf1aeea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4483
-1
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
WiFi Web Server LED Blink
3+
4+
A simple web server that lets you blink an LED via the web.
5+
This sketch will create a new access point (with no password).
6+
It will then launch a new server and print out the IP address
7+
to the Serial Monitor. From there, you can open that address in a web browser
8+
to turn on and off the LED on pin 13.
9+
10+
If the IP address of your board is yourAddress:
11+
http://yourAddress/H turns the LED on
12+
http://yourAddress/L turns it off
13+
14+
created 25 Nov 2012
15+
by Tom Igoe
16+
adapted to WiFi AP by Adafruit
17+
*/
18+
19+
#include "WiFiS3.h"
20+
21+
#include "arduino_secrets.h"
22+
23+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
24+
char ssid[] = SECRET_SSID; // your network SSID (name)
25+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
26+
int keyIndex = 0; // your network key index number (needed only for WEP)
27+
28+
int led = LED_BUILTIN;
29+
int status = WL_IDLE_STATUS;
30+
WiFiServer server(80);
31+
32+
void setup() {
33+
//Initialize serial and wait for port to open:
34+
Serial.begin(9600);
35+
while (!Serial) {
36+
; // wait for serial port to connect. Needed for native USB port only
37+
}
38+
Serial.println("Access Point Web Server");
39+
40+
pinMode(led, OUTPUT); // set the LED pin mode
41+
42+
// check for the WiFi module:
43+
if (WiFi.status() == WL_NO_MODULE) {
44+
Serial.println("Communication with WiFi module failed!");
45+
// don't continue
46+
while (true);
47+
}
48+
49+
String fv = WiFi.firmwareVersion();
50+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
51+
Serial.println("Please upgrade the firmware");
52+
}
53+
54+
// by default the local IP address will be 192.168.4.1
55+
// you can override it with the following:
56+
WiFi.config(IPAddress(192,48,56,2));
57+
58+
// print the network name (SSID);
59+
Serial.print("Creating access point named: ");
60+
Serial.println(ssid);
61+
62+
// Create open network. Change this line if you want to create an WEP network:
63+
status = WiFi.beginAP(ssid, pass);
64+
if (status != WL_AP_LISTENING) {
65+
Serial.println("Creating access point failed");
66+
// don't continue
67+
while (true);
68+
}
69+
70+
// wait 10 seconds for connection:
71+
delay(10000);
72+
73+
// start the web server on port 80
74+
server.begin();
75+
76+
// you're connected now, so print out the status
77+
printWiFiStatus();
78+
}
79+
80+
81+
void loop() {
82+
83+
// compare the previous status to the current status
84+
if (status != WiFi.status()) {
85+
// it has changed update the variable
86+
status = WiFi.status();
87+
88+
if (status == WL_AP_CONNECTED) {
89+
// a device has connected to the AP
90+
Serial.println("Device connected to AP");
91+
} else {
92+
// a device has disconnected from the AP, and we are back in listening mode
93+
Serial.println("Device disconnected from AP");
94+
}
95+
}
96+
97+
WiFiClient client = server.available(); // listen for incoming clients
98+
99+
if (client) { // if you get a client,
100+
Serial.println("new client"); // print a message out the serial port
101+
String currentLine = ""; // make a String to hold incoming data from the client
102+
while (client.connected()) { // loop while the client's connected
103+
delayMicroseconds(10); // This is required for the Arduino Nano RP2040 Connect - otherwise it will loop so fast that SPI will never be served.
104+
if (client.available()) { // if there's bytes to read from the client,
105+
char c = client.read(); // read a byte, then
106+
Serial.write(c); // print it out to the serial monitor
107+
if (c == '\n') { // if the byte is a newline character
108+
109+
// if the current line is blank, you got two newline characters in a row.
110+
// that's the end of the client HTTP request, so send a response:
111+
if (currentLine.length() == 0) {
112+
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
113+
// and a content-type so the client knows what's coming, then a blank line:
114+
client.println("HTTP/1.1 200 OK");
115+
client.println("Content-type:text/html");
116+
client.println();
117+
118+
// the content of the HTTP response follows the header:
119+
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/H\">here</a> turn the LED on<br></p>");
120+
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/L\">here</a> turn the LED off<br></p>");
121+
122+
// The HTTP response ends with another blank line:
123+
client.println();
124+
// break out of the while loop:
125+
break;
126+
}
127+
else { // if you got a newline, then clear currentLine:
128+
currentLine = "";
129+
}
130+
}
131+
else if (c != '\r') { // if you got anything else but a carriage return character,
132+
currentLine += c; // add it to the end of the currentLine
133+
}
134+
135+
// Check to see if the client request was "GET /H" or "GET /L":
136+
if (currentLine.endsWith("GET /H")) {
137+
digitalWrite(led, HIGH); // GET /H turns the LED on
138+
}
139+
if (currentLine.endsWith("GET /L")) {
140+
digitalWrite(led, LOW); // GET /L turns the LED off
141+
}
142+
}
143+
}
144+
// close the connection:
145+
client.stop();
146+
Serial.println("client disconnected");
147+
}
148+
}
149+
150+
void printWiFiStatus() {
151+
// print the SSID of the network you're attached to:
152+
Serial.print("SSID: ");
153+
Serial.println(WiFi.SSID());
154+
155+
// print your WiFi shield's IP address:
156+
IPAddress ip = WiFi.localIP();
157+
Serial.print("IP Address: ");
158+
Serial.println(ip);
159+
160+
// print where to go in a browser:
161+
Serial.print("To see this page in action, open a browser to http://");
162+
Serial.println(ip);
163+
164+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Both SSID and password must be 8 characters or longer
2+
#define SECRET_SSID "testAP"
3+
#define SECRET_PASS "123456789"
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
SerialPassthroughESP32-C3 - Use esptool to flash the ES32-C3 module on Santiago and Portenta H33
3+
4+
Copyright (c) 2022 Arduino SA. All rights reserved.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
unsigned long baud = 9600;
22+
23+
int rts = -1;
24+
int dtr = -1;
25+
26+
27+
#ifdef ARDUINO_PORTENTA_H33
28+
29+
#warning Compiling for Portenta H33
30+
#ifndef SerialNina
31+
#define SerialNina Serial5
32+
#endif
33+
34+
#ifndef NINA_GPIO0
35+
#define NINA_GPIO0 (100)
36+
#endif
37+
38+
#ifndef NINA_RESETN
39+
#define NINA_RESETN (101)
40+
#endif
41+
42+
#else
43+
44+
#warning Compiling for Santiago
45+
46+
#ifndef SerialNina
47+
#define SerialNina Serial2
48+
#endif
49+
50+
#ifndef NINA_GPIO0
51+
#define NINA_GPIO0 (28)
52+
#endif
53+
54+
#ifndef NINA_RESETN
55+
#define NINA_RESETN (29)
56+
#endif
57+
58+
#endif
59+
60+
void setup() {
61+
Serial.begin(baud, SERIAL_8N1);
62+
SerialNina.begin(baud);
63+
while (!Serial);
64+
65+
pinMode(NINA_GPIO0, OUTPUT);
66+
pinMode(NINA_RESETN, OUTPUT);
67+
68+
digitalWrite(NINA_GPIO0, HIGH);
69+
delay(100);
70+
digitalWrite(NINA_RESETN, HIGH);
71+
digitalWrite(NINA_RESETN, LOW);
72+
digitalWrite(NINA_RESETN, HIGH);
73+
74+
rts = Serial.rts();
75+
dtr = Serial.dtr();
76+
}
77+
78+
void loop() {
79+
80+
auto _rts = Serial.rts();
81+
auto _dtr = Serial.dtr();
82+
83+
if ((rts != _rts) || (dtr != _dtr)) {
84+
digitalWrite(NINA_RESETN, _rts ? LOW : HIGH);
85+
rts = _rts;
86+
digitalWrite(NINA_GPIO0, _dtr ? LOW : HIGH);
87+
dtr = _dtr;
88+
}
89+
90+
int len = 0;
91+
uint8_t auc_buffer[488];
92+
while (Serial.available() && len < sizeof(auc_buffer)) {
93+
auc_buffer[len++] = Serial.read();
94+
}
95+
if (len) {
96+
SerialNina.write(auc_buffer, len);
97+
}
98+
99+
len = 0;
100+
while (SerialNina.available() && len < sizeof(auc_buffer)) {
101+
auc_buffer[len++] = SerialNina.read();
102+
}
103+
if (len) {
104+
Serial.write(auc_buffer, len);
105+
}
106+
107+
// check if the USB virtual serial wants a new baud rate
108+
if (Serial.baud() != baud) {
109+
//rts = -1;
110+
//dtr = -1;
111+
112+
baud = Serial.baud();
113+
SerialNina.end();
114+
SerialNina.begin(baud);
115+
}
116+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
This example connects to an unencrypted WiFi network.
3+
Then it prints the MAC address of the WiFi module,
4+
the IP address obtained, and other network details.
5+
6+
created 13 July 2010
7+
by dlf (Metodo2 srl)
8+
modified 31 May 2012
9+
by Tom Igoe
10+
*/
11+
#include <WiFi.h>
12+
13+
#include "arduino_secrets.h"
14+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
15+
char ssid[] = SECRET_SSID; // your network SSID (name)
16+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
17+
int status = WL_IDLE_STATUS; // the WiFi radio's status
18+
19+
void setup() {
20+
//Initialize serial and wait for port to open:
21+
Serial.begin(9600);
22+
while (!Serial) {
23+
; // wait for serial port to connect. Needed for native USB port only
24+
}
25+
26+
// check for the WiFi module:
27+
if (WiFi.status() == WL_NO_MODULE) {
28+
Serial.println("Communication with WiFi module failed!");
29+
// don't continue
30+
while (true);
31+
}
32+
33+
String fv = WiFi.firmwareVersion();
34+
if (fv < WiFi_FIRMWARE_LATEST_VERSION) {
35+
Serial.println("Please upgrade the firmware");
36+
}
37+
38+
// attempt to connect to WiFi network:
39+
while (status != WL_CONNECTED) {
40+
Serial.print("Attempting to connect to WPA SSID: ");
41+
Serial.println(ssid);
42+
// Connect to WPA/WPA2 network:
43+
status = WiFi.begin(ssid, pass);
44+
45+
// wait 10 seconds for connection:
46+
delay(10000);
47+
}
48+
49+
// you're connected now, so print out the data:
50+
Serial.print("You're connected to the network");
51+
printCurrentNet();
52+
printWifiData();
53+
54+
}
55+
56+
void loop() {
57+
// check the network connection once every 10 seconds:
58+
delay(10000);
59+
printCurrentNet();
60+
}
61+
62+
void printWifiData() {
63+
// print your board's IP address:
64+
IPAddress ip = WiFi.localIP();
65+
Serial.print("IP Address: ");
66+
Serial.println(ip);
67+
Serial.println(ip);
68+
69+
// print your MAC address:
70+
byte mac[6];
71+
WiFi.macAddress(mac);
72+
Serial.print("MAC address: ");
73+
printMacAddress(mac);
74+
}
75+
76+
void printCurrentNet() {
77+
// print the SSID of the network you're attached to:
78+
Serial.print("SSID: ");
79+
Serial.println(WiFi.SSID());
80+
81+
// print the MAC address of the router you're attached to:
82+
byte bssid[6];
83+
WiFi.BSSID(bssid);
84+
Serial.print("BSSID: ");
85+
printMacAddress(bssid);
86+
87+
// print the received signal strength:
88+
long rssi = WiFi.RSSI();
89+
Serial.print("signal strength (RSSI):");
90+
Serial.println(rssi);
91+
92+
// print the encryption type:
93+
byte encryption = WiFi.encryptionType();
94+
Serial.print("Encryption Type:");
95+
Serial.println(encryption, HEX);
96+
Serial.println();
97+
}
98+
99+
void printMacAddress(byte mac[]) {
100+
for (int i = 5; i >= 0; i--) {
101+
if (mac[i] < 16) {
102+
Serial.print("0");
103+
}
104+
Serial.print(mac[i], HEX);
105+
if (i > 0) {
106+
Serial.print(":");
107+
}
108+
}
109+
Serial.println();
110+
}

0 commit comments

Comments
 (0)