Skip to content

Instantly share code, notes, and snippets.

Last active Jun 28, 2021
What would you like to do?
#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#ifdef ESP32
#include <WiFi.h>
class GuineapigWiFiConfig
GuineapigWiFiConfig() = default;
bool connectWiFi();
typedef void (*LogCallback)(String);
LogCallback logCallback;
void clearWiFiConfig();
void printLog(String msg);
void printlnLog(String msg) { printLog(msg + "\n"); }
void printlnLog() { printlnLog(""); }
bool tryConnect();
void initConfigWeb();
extern GuineapigWiFiConfig WiFiConfig;
const char guineapig_wifi_config_html[] PROGMEM = R"====(
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="utf-8" />
.content { width: 240px; margin: 0 auto; font-size: 16pt; font-family: '微軟正黑體' }
form > * { width: 95%; margin: 6px auto; }
#dvStatus { font-size: 14pt; color: dodgerblue; }
<div class=content>
<div style='text-align:center'>無線網路設定<div>
<form action="/" method="POST" target='submitRes'>
<input name="ssid" placeholder="SSID" />
<input type="password" name="passwd" placeholder="請輸入密碼" />
<input type="submit" name="action" value="儲存設定" id=btnSave />
<input type="submit" name="action" value="重新啟動" disabled id=btnReboot />
<iframe name='submitRes' style='display:none'></iframe>
<div id=dvStatus></div>
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function() {
var res = JSON.parse(this.responseText);
document.getElementById('dvStatus').innerHTML = res.m;
if (res.p == "CONNECTED") {
document.getElementById('btnSave').disabled = true;
document.getElementById('btnReboot').disabled = false;
else if (res.p == "REBOOT") {
var hnd = setInterval(function() {"GET", "http://" + + "/status");
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment