Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServerSecure.h>
- #include "certs.h"
- const char* ssid = "YOUR_WIFI_SSID";
- const char* password = "YOUR_WIFI_PASSWORD";
- const char* authUser = "admin";
- const char* authPass = "yourpassword";
- BearSSL::ESP8266WebServerSecure server(10000);
- void setup() {
- Serial.begin(115200);
- delay(100);
- // Connect to Wi-Fi
- WiFi.begin(ssid, password);
- Serial.print("Connecting to WiFi...");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("\nWiFi connected. IP address: ");
- Serial.println(WiFi.localIP());
- // Load certificate and private key
- server.getServer().setRSACert(
- (const uint8_t*)cert, strlen(cert),
- (const uint8_t*)key, strlen(key)
- );
- // Add basic authentication to the root route
- server.on("/", []() {
- if (!server.authenticate(authUser, authPass)) {
- return server.requestAuthentication(); // send 401
- }
- server.send(200, "text/html", "<h1>Hello, secure world!</h1><p>You are authenticated.</p>");
- });
- server.begin();
- Serial.println("Secure HTTPS server started on port 10000.");
- }
- void loop() {
- server.handleClient();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement