Supports ESP32

pull/11/head
Hieromon Ikasamo 6 years ago
parent 51cd72375f
commit 0a9c49bd71
  1. 28
      README.md
  2. 50
      examples/FSBrowser/FSBrowser.ino
  3. 9
      examples/HandlePortalEX/HandlePortalEX.ino
  4. 4
      mkdocs/index.md
  5. 34
      src/AutoConnect.cpp
  6. 9
      src/AutoConnectPage.cpp

@ -1,17 +1,17 @@
# AutoConnect for ESP8266
# AutoConnect for ESP8266/ESP32
An Arduino library for ESP8266 WLAN configuration at run time with web interface. [![Build Status](https://travis-ci.org/Hieromon/AutoConnect.svg?branch=master)](https://travis-ci.org/Hieromon/AutoConnect)
An Arduino library for ESP8266/ESP32 WLAN configuration at run time with web interface. [![Build Status](https://travis-ci.org/Hieromon/AutoConnect.svg?branch=master)](https://travis-ci.org/Hieromon/AutoConnect)
## Overview
To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with *ESP8266WebServer* class.
Easily implementing the Web interface constituting the WLAN for ESP8266 WiFi connection. With this library to make a sketch easily which connects from ESP8266 to the access point at runtime by the web interface without hard-coded SSID and password.
To the dynamic configuration for joining to WLAN with SSID and PSK accordingly. It an Arduino library united with *ESP8266WebServer* class of ESP8266 or *WebServer* class of ESP32.
Easily implementing the Web interface constituting the WLAN for ESP8266/ESP32 WiFi connection. With this library to make a sketch easily which connects from ESP8266/ESP32 to the access point at runtime by the web interface without hard-coded SSID and password.
<div align="center"><img alt="Overview" width="460" src="docs/images/ov.png" />&emsp;&emsp;&emsp;<img alt="Captiveportal" width="182" src="docs/images/ov.gif" /></div>
### No need pre-coded SSID &amp; password
It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.
It is no needed hard-coding in advance the SSID and Password into the sketch to connect between ESP8266/ESP32 and WLAN. You can input SSID &amp; Password from a smartphone via the web interface at runtime.
### Simple usage
@ -19,7 +19,7 @@ AutoConnect control screen will be displayed automatically for establishing new
### Store the established connection
The connection authentication data as credentials are saved automatically in EEPROM of ESP8266 and You can select the past SSID from the [AutoConnect menu](https://hieromon.github.io/AutoConnect/menu/index.html).
The connection authentication data as credentials are saved automatically in EEPROM of ESP8266/ESP32 and You can select the past SSID from the [AutoConnect menu](https://hieromon.github.io/AutoConnect/menu/index.html).
### Easy to embed in
@ -27,7 +27,7 @@ AutoConnect can be embedded easily into your sketch, just "**begin**" and "**han
### Lives with the your sketches
The sketches which provide the web page using ESP8266WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object, or itself can assign it.
The sketches which provide the web page using ESP8266WebServer/WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object(ESP8266) or WebServer object(ESP32), or itself can assign it.
## Supported hardware
@ -42,6 +42,16 @@ Apply the [Arduino core](https://github.com/esp8266/Arduino) of the ESP8266 Comm
- SparkFun Thing
- SweetPea ESP-210
Alter the platform applying the [arduino-esp32](https://github.com/espressif/arduino-esp32) for the ESP32 modules.
- ESP32Dev Board
- SparkFun ESP32 Thing
- WEMOS LOLIN D32
- Ai-Thinker NodeMCU-32S
- Heltec WiFi Kit 32
- M5Stack
- And other ESP32 modules supported by the Additional Board Manager URLs of the Arduino-IDE.
## Simple usage
### The AutoConnect menu
@ -68,6 +78,10 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some
## Change log
### [0.9.5] Aug. 27, 2018
- Supports the espressif arduino-esp32 core.
- Fixed that crash may occur if the number of stored credentials in the EEPROM is smaller than the number of found WiFi networks.
### [0.9.4] May 5, 2018.
- Automatically focus passphrase after selecting SSID with Configure New AP.
- Supports AutoConnectConfig::autoReconnect option, it will scan the WLAN when it can not connect to the default SSID, apply the applicable credentials if it is saved, and try reconnecting.

@ -22,11 +22,19 @@
access the sample web page at http://esp8266fs.local
edit the page by going to http://esp8266fs.local/edit
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#endif
//Add a below line for AutoConnect.
#include <AutoConnect.h>
@ -34,9 +42,15 @@
const char* ssid = "wifi-ssid";
const char* password = "wifi-password";
#if defined(ARDUINO_ARCH_ESP8266)
const char* host = "esp8266fs";
ESP8266WebServer server(80);
#elif defined(ARDUINO_ARCH_ESP32)
const char* host = "esp32fs";
WebServer server(80);
#endif
//Add a below line for AutoConnect.
AutoConnect portal(server);
//holds the current upload
@ -144,10 +158,15 @@ void handleFileList() {
String path = server.arg("dir");
DBG_OUTPUT_PORT.println("handleFileList: " + path);
#if defined(ARDUINO_ARCH_ESP8266)
Dir dir = SPIFFS.openDir(path);
#elif defined(ARDUINO_ARCH_ESP32)
File root = SPIFFS.open(path);
#endif
path = String();
String output = "[";
#if defined(ARDUINO_ARCH_ESP8266)
while(dir.next()){
File entry = dir.openFile("r");
if (output != "[") output += ',';
@ -159,6 +178,22 @@ void handleFileList() {
output += "\"}";
entry.close();
}
#elif defined(ARDUINO_ARCH_ESP32)
if(root.isDirectory()){
File file = root.openNextFile();
while(file){
if (output != "[") {
output += ',';
}
output += "{\"type\":\"";
output += (file.isDirectory()) ? "dir" : "file";
output += "\",\"name\":\"";
output += String(file.name()).substring(1);
output += "\"}";
file = root.openNextFile();
}
}
#endif
output += "]";
server.send(200, "text/json", output);
@ -170,12 +205,23 @@ void setup(void){
DBG_OUTPUT_PORT.setDebugOutput(true);
SPIFFS.begin();
{
#if defined(ARDUINO_ARCH_ESP8266)
Dir dir = SPIFFS.openDir("/");
while (dir.next()) {
String fileName = dir.fileName();
size_t fileSize = dir.fileSize();
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
}
#elif defined(ARDUINO_ARCH_ESP32)
File root = SPIFFS.open("/");
File file = root.openNextFile();
while(file){
String fileName = file.name();
size_t fileSize = file.size();
DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
file = root.openNextFile();
}
#endif
DBG_OUTPUT_PORT.printf("\n");
}
@ -222,7 +268,11 @@ void setup(void){
String json = "{";
json += "\"heap\":"+String(ESP.getFreeHeap());
json += ", \"analog\":"+String(analogRead(A0));
#if defined(ARDUINO_ARCH_ESP8266)
json += ", \"gpio\":"+String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
#elif defined(ARDUINO_ARCH_ESP32)
json += ", \"gpio\":" + String((uint32_t)(0));
#endif
json += "}";
server.send(200, "text/json", json);
json = String();

@ -15,12 +15,21 @@
It will help you understand AutoConnect usage.
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <PageBuilder.h>
#include <AutoConnect.h>
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer server;
#elif defined(ARDUINO_ARCH_ESP32)
WebServer server;
#endif
AutoConnect portal(server);
static const char PROGMEM mold_page[] = R"*lit(

@ -1,6 +1,6 @@
# AutoConnect <small>for ESP8266</small>
# AutoConnect <small>for ESP8266/ESP32</small>
An Arduino library for ESP8266 WLAN configuration at run time with web interface.
An Arduino library for ESP8266/ESP32 WLAN configuration at run time with web interface.
## Overview

@ -321,16 +321,20 @@ void AutoConnect::handleRequest() {
AC_DBG("Request for %s\n", (const char*)_credential.ssid);
WiFi.begin((const char*)_credential.ssid, (const char*)_credential.password);
if (_waitForConnect(_portalTimeout) == WL_CONNECTED) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
_currentHostIP = WiFi.localIP();
_redirectURI = String(AUTOCONNECT_URI_SUCCESS);
// Save current credential
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset);
credit.save(&_credential);
AC_DBG("%s credential saved\n", _credential.ssid);
if (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
_currentHostIP = WiFi.localIP();
_redirectURI = String(AUTOCONNECT_URI_SUCCESS);
// Save current credential
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset);
credit.save(&_credential);
AC_DBG("%s credential saved\n", _credential.ssid);
}
}
else
AC_DBG("%s has no BSSID, saving is unavailable\n", _credential.ssid);
}
else {
_currentHostIP = WiFi.softAPIP();
@ -342,7 +346,7 @@ void AutoConnect::handleRequest() {
if (_rfReset) {
// Reset or disconnect by portal operation result
_stopPortal();
AC_DBG("Reset");
AC_DBG("Reset\n");
delay(1000);
SOFT_RESET();
delay(1000);
@ -352,7 +356,7 @@ void AutoConnect::handleRequest() {
// Disconnect from the current AP.
_stopPortal();
_disconnectWiFi(true);
AC_DBG("Disconnected");
AC_DBG("Disconnected\n");
// Reset disconnection request, restore the menu title.
_rfDisconnect = false;
_menuTitle = String(AUTOCONNECT_MENU_TITLE);
@ -391,11 +395,12 @@ bool AutoConnect::_loadAvailCredential() {
if (credential.entries() >= 0) {
// Scan the vicinity only when the saved credentials are existing.
int8_t nn = WiFi.scanNetworks(false, true);
AC_DBG("%d network(s) found\n", (int)nn);
if (nn > 0) {
// Determine valid credentials by BSSID.
for (uint8_t i = 0; i < credential.entries(); i++) {
credential.load(i, &_credential);
for (uint8_t n = 0; n <= nn; n++) {
for (uint8_t n = 0; n < nn; n++) {
if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config::bssid)))
return true;
}
@ -419,6 +424,7 @@ void AutoConnect::_stopPortal() {
}
WiFi.softAPdisconnect(false);
AC_DBG("SoftAP stopped\n");
}
/**
@ -585,9 +591,9 @@ bool AutoConnect::_isIP(String ipStr) {
* @retval MAC address string in XX:XX:XX:XX:XX:XX format.
*/
String AutoConnect::_toMACAddressString(const uint8_t mac[]) {
String macAddr = "";
String macAddr = "";
for (uint8_t i = 0; i < 6; i++) {
char buf[3];
char buf[3];
sprintf(buf, "%02X", mac[i]);
macAddr += buf;
if (i < 5)

@ -967,17 +967,16 @@ String AutoConnect::_token_OPEN_SSID(PageArgument& args) {
struct station_config entry;
String ssidList = "";
uint8_t* bssid = WiFi.BSSID();
for (uint8_t i = 0; i < credit.entries(); i++) {
credit.load(i, &entry);
AC_DBG("A credential #%d loaded\n", (int)i);
ssidList += String(F("<input id=\"sb\" type=\"submit\" name=\"" AUTOCONNECT_PARAMID_CRED "\" value=\"")) + String((char*)entry.ssid) + String(F("\">"));
ssidList += String(F("<label>"));
if (memcmp(WiFi.BSSID(), entry.bssid, sizeof(station_config::bssid)) == 0) {
if (bssid != NULL && memcmp(bssid, entry.bssid, sizeof(station_config::bssid)) == 0)
ssidList += String(AutoConnect::_toWiFiQuality(WiFi.RSSI())) + String("%");
}
else {
else
ssidList += String("N/A");
}
ssidList += String(F("</label><br>"));
}

Loading…
Cancel
Save