Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 6961aa7

Browse files
committed
CI Update
1 parent 11a6439 commit 6961aa7

File tree

4 files changed

+119
-60
lines changed

4 files changed

+119
-60
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ jobs:
2424
eeprom: true
2525
softwareserial: false
2626
index_url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
27+
- core: esp8266:esp8266
28+
board: esp8266:esp8266:huzzah
29+
eeprom: true
30+
softwareserial: true
31+
index_url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
2732

2833
steps:
2934
- name: Checkout
@@ -46,6 +51,9 @@ jobs:
4651
- name: Install AsyncTCP-esphome
4752
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-AsyncTCP#v2.1.1
4853

54+
- name: Install ESPAsyncTCP-esphome
55+
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-urlhttps://github.com/mathieucarbou/ESPAsyncTCP-esphome#v2.0.0
56+
4957
- name: Build CaptivePortal
5058
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/CaptivePortal/CaptivePortal.ino"
5159

@@ -63,6 +71,10 @@ jobs:
6371
board: esp32dev
6472
eeprom: true
6573
softwareserial: false
74+
- platform: espressif8266
75+
board: huzzah
76+
eeprom: true
77+
softwareserial: false
6678

6779
steps:
6880
- name: Checkout
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
1-
#include "ESPAsyncWebServer.h"
2-
#include <AsyncTCP.h>
31
#include <DNSServer.h>
2+
#ifdef ESP32
43
#include <WiFi.h>
4+
#include <AsyncTCP.h>
5+
#elif defined(ESP8266)
6+
#include <ESP8266WiFi.h>
7+
#include <ESPAsyncTCP.h>
8+
#endif
9+
#include "ESPAsyncWebServer.h"
510

611
DNSServer dnsServer;
712
AsyncWebServer server(80);
813

914
class CaptiveRequestHandler : public AsyncWebHandler {
10-
public:
11-
CaptiveRequestHandler() {}
12-
virtual ~CaptiveRequestHandler() {}
15+
public:
16+
CaptiveRequestHandler() {}
17+
virtual ~CaptiveRequestHandler() {}
1318

14-
bool canHandle(AsyncWebServerRequest* request) {
15-
// request->addInterestingHeader("ANY");
16-
return true;
17-
}
19+
bool canHandle(AsyncWebServerRequest *request){
20+
//request->addInterestingHeader("ANY");
21+
return true;
22+
}
1823

19-
void handleRequest(AsyncWebServerRequest* request) {
20-
AsyncResponseStream* response = request->beginResponseStream("text/html");
21-
response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
22-
response->print("<p>This is out captive portal front page.</p>");
23-
response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
24-
response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
25-
response->print("</body></html>");
26-
request->send(response);
27-
}
24+
void handleRequest(AsyncWebServerRequest *request) {
25+
AsyncResponseStream *response = request->beginResponseStream("text/html");
26+
response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
27+
response->print("<p>This is out captive portal front page.</p>");
28+
response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
29+
response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
30+
response->print("</body></html>");
31+
request->send(response);
32+
}
2833
};
2934

30-
void setup() {
31-
// your other setup stuff...
35+
36+
void setup(){
37+
//your other setup stuff...
3238
WiFi.softAP("esp-captive");
3339
dnsServer.start(53, "*", WiFi.softAPIP());
34-
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP
35-
// more handlers...
40+
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP
41+
//more handlers...
3642
server.begin();
3743
}
3844

39-
void loop() {
45+
void loop(){
4046
dnsServer.processNextRequest();
41-
}
47+
}
Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,74 @@
1-
#include "ESPAsyncWebServer.h"
2-
#include <AsyncTCP.h>
3-
#include <DNSServer.h>
1+
//
2+
// A simple server implementation showing how to:
3+
// * serve static messages
4+
// * read GET and POST parameters
5+
// * handle missing pages / 404s
6+
//
7+
8+
#include <Arduino.h>
9+
#ifdef ESP32
410
#include <WiFi.h>
11+
#include <AsyncTCP.h>
12+
#elif defined(ESP8266)
13+
#include <ESP8266WiFi.h>
14+
#include <ESPAsyncTCP.h>
15+
#endif
16+
#include <ESPAsyncWebServer.h>
517

6-
DNSServer dnsServer;
718
AsyncWebServer server(80);
819

9-
class CaptiveRequestHandler : public AsyncWebHandler {
10-
public:
11-
CaptiveRequestHandler() {}
12-
virtual ~CaptiveRequestHandler() {}
20+
const char* ssid = "YOUR_SSID";
21+
const char* password = "YOUR_PASSWORD";
1322

14-
bool canHandle(AsyncWebServerRequest* request) {
15-
// request->addInterestingHeader("ANY");
16-
return true;
17-
}
23+
const char* PARAM_MESSAGE = "message";
1824

19-
void handleRequest(AsyncWebServerRequest* request) {
20-
AsyncResponseStream* response = request->beginResponseStream("text/html");
21-
response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
22-
response->print("<p>This is out captive portal front page.</p>");
23-
response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
24-
response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
25-
response->print("</body></html>");
26-
request->send(response);
27-
}
28-
};
25+
void notFound(AsyncWebServerRequest *request) {
26+
request->send(404, "text/plain", "Not found");
27+
}
2928

3029
void setup() {
31-
// your other setup stuff...
32-
WiFi.softAP("esp-captive");
33-
dnsServer.start(53, "*", WiFi.softAPIP());
34-
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP
35-
// more handlers...
36-
server.begin();
30+
31+
Serial.begin(115200);
32+
WiFi.mode(WIFI_STA);
33+
WiFi.begin(ssid, password);
34+
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
35+
Serial.printf("WiFi Failed!\n");
36+
return;
37+
}
38+
39+
Serial.print("IP Address: ");
40+
Serial.println(WiFi.localIP());
41+
42+
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
43+
request->send(200, "text/plain", "Hello, world");
44+
});
45+
46+
// Send a GET request to <IP>/get?message=<message>
47+
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
48+
String message;
49+
if (request->hasParam(PARAM_MESSAGE)) {
50+
message = request->getParam(PARAM_MESSAGE)->value();
51+
} else {
52+
message = "No message sent";
53+
}
54+
request->send(200, "text/plain", "Hello, GET: " + message);
55+
});
56+
57+
// Send a POST request to <IP>/post with a form field message set to <message>
58+
server.on("/post", HTTP_POST, [](AsyncWebServerRequest *request){
59+
String message;
60+
if (request->hasParam(PARAM_MESSAGE, true)) {
61+
message = request->getParam(PARAM_MESSAGE, true)->value();
62+
} else {
63+
message = "No message sent";
64+
}
65+
request->send(200, "text/plain", "Hello, POST: " + message);
66+
});
67+
68+
server.onNotFound(notFound);
69+
70+
server.begin();
3771
}
3872

3973
void loop() {
40-
dnsServer.processNextRequest();
4174
}

platformio.ini

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[env]
2-
lib_deps =
3-
bblanchon/ArduinoJson @ 7.0.2
4-
esphome/AsyncTCP-esphome @ 2.1.1
2+
framework = arduino
53

64
build_flags = -Wall -Wextra
75

@@ -13,11 +11,21 @@ monitor_speed = 115200
1311
monitor_filters = esp32_exception_decoder, log2file
1412

1513
[platformio]
14+
default_envs = esp8266
1615
lib_dir = .
17-
src_dir = examples/CaptivePortal
18-
; src_dir = examples/SimpleServer
16+
; src_dir = examples/CaptivePortal
17+
src_dir = examples/SimpleServer
1918

2019
[env:esp32]
21-
platform = espressif32@6.5.0
20+
platform = espressif32
2221
board = esp32dev
23-
framework = arduino
22+
lib_deps =
23+
bblanchon/ArduinoJson @ 7.0.2
24+
esphome/AsyncTCP-esphome @ 2.1.1
25+
26+
[env:esp8266]
27+
platform = espressif8266
28+
board = huzzah
29+
lib_deps =
30+
bblanchon/ArduinoJson @ 7.0.2
31+
esphome/ESPAsyncTCP-esphome @ 2.0.0

0 commit comments

Comments
 (0)