Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit c9325a8

Browse files
authored
v1.0.0 for RP2040W with CYW43439 WiFi
### Initial Releases v1.0.0 1. Initial coding to support **RASPBERRY_PI_PICO_W with CYW43439 WiFi**, using [**arduino-pico core v2.4.0+**](https://github.com/earlephilhower/arduino-pico)
1 parent 4e7fc16 commit c9325a8

File tree

11 files changed

+804
-0
lines changed

11 files changed

+804
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/****************************************************************************************************************************
2+
AsyncCaptivePortal.ino
3+
4+
AsyncDNSServer_RP2040W is an Async DNS_Server library for the RP2040W with CYW43439 WiFi
5+
6+
Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
7+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_RP2040W
8+
*****************************************************************************************************************************/
9+
10+
#include "defines.h"
11+
12+
#include <AsyncDNSServer_RP2040W.h>
13+
#include <AsyncWebServer_RP2040W.h>
14+
15+
const byte DNS_PORT = 53;
16+
IPAddress apIP(192, 168, 100, 1);
17+
18+
AsyncDNSServer dnsServer;
19+
AsyncWebServer server(80);
20+
21+
int status = WL_IDLE_STATUS;
22+
23+
String responseHTML = ""
24+
"<!DOCTYPE html><html lang='en'><head>"
25+
"<meta name='viewport' content='width=device-width'>"
26+
"<title>RP2040W-CaptivePortal</title></head><body>"
27+
"<h1>Hello World from RP2040W!</h1><p>This is a captive portal example."
28+
" All requests will be redirected here.</p></body></html>";
29+
30+
void handleNotFound(AsyncWebServerRequest *request)
31+
{
32+
request->send(200, "text/html", responseHTML);
33+
}
34+
35+
void printWifiStatus()
36+
{
37+
// print the SSID of the network you're attached to:
38+
Serial.print("SSID: ");
39+
Serial.println(WiFi.SSID());
40+
41+
// print your board's IP address:
42+
IPAddress ip = WiFi.localIP();
43+
Serial.print("Local IP Address: ");
44+
Serial.println(ip);
45+
46+
// print the received signal strength:
47+
long rssi = WiFi.RSSI();
48+
Serial.print("signal strength (RSSI):");
49+
Serial.print(rssi);
50+
Serial.println(" dBm");
51+
}
52+
53+
void setup()
54+
{
55+
Serial.begin(115200);
56+
while (!Serial && millis() < 5000);
57+
58+
Serial.print("\nStart AsyncCaptivePortal on "); Serial.println(BOARD_NAME);
59+
Serial.println(ASYNC_DNS_SERVER_RP2040W_VERSION);
60+
61+
#if defined(ASYNC_DNS_SERVER_RP2040W_VERSION_MIN)
62+
if (ASYNC_DNS_SERVER_RP2040W_VERSION_INT < ASYNC_DNS_SERVER_RP2040W_VERSION_MIN)
63+
{
64+
Serial.print("Warning. Must use this example on Version equal or later than : ");
65+
Serial.println(ASYNC_DNS_SERVER_RP2040W_VERSION_MIN_TARGET);
66+
}
67+
#endif
68+
69+
///////////////////////////////////
70+
71+
// check for the WiFi module:
72+
if (WiFi.status() == WL_NO_MODULE)
73+
{
74+
Serial.println("Communication with WiFi module failed!");
75+
// don't continue
76+
while (true);
77+
}
78+
79+
Serial.print(F("Connecting to SSID: "));
80+
Serial.println(ssid);
81+
82+
status = WiFi.begin(ssid, pass);
83+
84+
delay(1000);
85+
86+
// attempt to connect to WiFi network
87+
while ( status != WL_CONNECTED)
88+
{
89+
delay(500);
90+
91+
// Connect to WPA/WPA2 network
92+
status = WiFi.status();
93+
}
94+
95+
printWifiStatus();
96+
97+
///////////////////////////////////
98+
99+
// modify TTL associated with the domain name (in seconds)
100+
// default is 60 seconds
101+
dnsServer.setTTL(300);
102+
// set which return code will be used for all other domains (e.g. sending
103+
// ServerFailure instead of NonExistentDomain will reduce number of queries
104+
// sent by clients)
105+
// default is AsyncDNSReplyCode::NonExistentDomain
106+
dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);
107+
108+
// if DNSServer is started with "*" for domain name, it will reply with
109+
// provided IP to all DNS request
110+
dnsServer.start(DNS_PORT, "*", apIP);
111+
112+
server.onNotFound(handleNotFound);
113+
114+
server.begin();
115+
116+
Serial.print(F("HTTP DNSServer is @ IP : "));
117+
Serial.println(apIP);
118+
}
119+
120+
void loop()
121+
{
122+
}

examples/AsyncCaptivePortal/defines.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/****************************************************************************************************************************
2+
defines.h
3+
4+
AsyncDNSServer_RP2040W is an Async DNS_Server library for the RP2040W with CYW43439 WiFi
5+
6+
Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
7+
Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_RP2040W
8+
*****************************************************************************************************************************/
9+
10+
#ifndef defines_h
11+
#define defines_h
12+
13+
#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
14+
#error For RASPBERRY_PI_PICO_W only
15+
#endif
16+
17+
#define ASYNC_DNS_RP2040W_DEBUG_PORT Serial
18+
19+
// Debug Level from 0 to 4
20+
#define _ASYNC_DNS_RP2040W_LOGLEVEL_ 4
21+
22+
#if (_ASYNC_DNS_RP2040W_LOGLEVEL_ > 3)
23+
#warning Using RASPBERRY_PI_PICO_W with CYW43439 WiFi
24+
#endif
25+
26+
char ssid[] = "your_ssid"; // your network SSID (name)
27+
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
28+
29+
#endif //defines_h

0 commit comments

Comments
 (0)