Skip to content

Commit 566c076

Browse files
committed
Add NoAuth Example
1 parent 25e1622 commit 566c076

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
default_example: [examples/HelloHttp/HelloHttp.cpp]
12-
no_flash_no_auth_example: [examples/HelloHttp/HelloHttp.cpp]
12+
no_flash_no_auth_example: [examples/HelloHttpNoFlashNoAuth/HelloNoFlashNoAuthHttp.cpp]
1313

1414
steps:
1515
- uses: actions/checkout@v2
@@ -37,7 +37,7 @@ jobs:
3737
- name: Run PlatformIO - No Auth, No Flash Example
3838
run: pio ci --lib="." --project-conf="platformio.ini"
3939
env:
40-
PLATFORMIO_CI_SRC: ${{ matrix.example }}
40+
PLATFORMIO_CI_SRC: ${{ matrix.no_flash_no_auth_example }}
4141
PLATFORMIO_BUILD_FLAGS: -D ARDUINO_HTTP_SERVER_NO_FLASH -D ARDUINO_HTTP_SERVER_NO_BASIC_AUTH
4242

4343

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ArduinoHttpServer
22

3-
![GitHub Actions](https://github.com/github/QuickSander/ArduinoHttpServer/workflows/main.yml/badge.svg)
3+
![GitHub Actions](https://github.com/QuickSander/ArduinoHttpServer/actions/workflows/main.yml/badge.svg)
44
[![Code Climate](https://codeclimate.com/github/QuickSander/ArduinoHttpServer/badges/gpa.svg)](https://codeclimate.com/github/QuickSander/ArduinoHttpServer)
55
[![Test Coverage](https://codeclimate.com/github/QuickSander/ArduinoHttpServer/badges/coverage.svg)](https://codeclimate.com/github/QuickSander/ArduinoHttpServer/coverage)
66

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <ArduinoHttpServer.h>
2+
3+
#include <Arduino.h>
4+
5+
6+
#ifdef ESP8266 // This example is compatible with both, ATMega and ESP8266
7+
#include <ESP8266WiFi.h>
8+
#else
9+
#include <SPI.h> //! \todo Temporary see fix: https://github.com/platformio/platformio/issues/48
10+
#include <WiFi.h>
11+
#endif
12+
13+
const char* ssid = "";
14+
const char* password = "";
15+
16+
WiFiServer wifiServer(80);
17+
18+
void setup()
19+
{
20+
Serial.begin(115200);
21+
Serial.println("Starting Wifi Connection...");
22+
23+
WiFi.begin(const_cast<char*>(ssid), password);
24+
while (WiFi.status() != WL_CONNECTED)
25+
{
26+
delay(500);
27+
}
28+
29+
wifiServer.begin();
30+
}
31+
32+
void loop()
33+
{
34+
WiFiClient client( wifiServer.available() );
35+
if (client.connected())
36+
{
37+
// Connected to client. Allocate and initialize StreamHttpRequest object.
38+
ArduinoHttpServer::StreamHttpRequest<1024> httpRequest(client);
39+
40+
if (httpRequest.readRequest())
41+
{
42+
43+
// Retrieve HTTP resource / URL requested
44+
Serial.println( httpRequest.getResource().toString() );
45+
46+
// Retrieve 1st part of HTTP resource.
47+
// E.g.: "api" from "/api/sensors/on"
48+
Serial.println(httpRequest.getResource()[0]);
49+
50+
}
51+
else
52+
{
53+
// HTTP parsing failed. Client did not provide correct HTTP data or
54+
// client requested an unsupported feature.
55+
ArduinoHttpServer::StreamHttpErrorReply httpReply(client, httpRequest.getContentType());
56+
57+
const char *pErrorStr( httpRequest.getError().cStr() );
58+
String errorStr(pErrorStr); //! \todo Make HttpReply FixString compatible.
59+
60+
httpReply.send( errorStr );
61+
}
62+
client.stop();
63+
}
64+
65+
}

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ lib_dir = ../
1717
platform = espressif8266
1818
framework = arduino
1919
board = esp01
20-
#lib_deps = agdl/Base64@^1.0.0
20+
lib_deps = agdl/Base64@^1.0.0
2121
build_flags =
2222
;-DARDUINO_HTTP_SERVER_DEBUG
2323
;-DARDUINO_HTTP_SERVER_NO_FLASH

0 commit comments

Comments
 (0)