mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 19:09:03 +08:00
Fix travis-ci using latest git
This commit is contained in:
parent
2714904c52
commit
9f6a7c0b91
@ -36,7 +36,6 @@ before_script:
|
|||||||
- cd ..
|
- cd ..
|
||||||
- echo 'build.flash_freq=40m' >> platform.txt
|
- echo 'build.flash_freq=40m' >> platform.txt
|
||||||
- mv $TRAVIS_BUILD_DIR/libraries/WebServer $HOME/arduino_ide/hardware/esp32/esp32/libraries/
|
- mv $TRAVIS_BUILD_DIR/libraries/WebServer $HOME/arduino_ide/hardware/esp32/esp32/libraries/
|
||||||
- mv $TRAVIS_BUILD_DIR/libraries/DNSServer $HOME/arduino_ide/hardware/esp32/esp32/libraries/
|
|
||||||
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
32
libraries/DNSServer/.gitignore
vendored
32
libraries/DNSServer/.gitignore
vendored
@ -1,32 +0,0 @@
|
|||||||
# Prerequisites
|
|
||||||
*.d
|
|
||||||
|
|
||||||
# Compiled Object files
|
|
||||||
*.slo
|
|
||||||
*.lo
|
|
||||||
*.o
|
|
||||||
*.obj
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Compiled Dynamic libraries
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
*.dll
|
|
||||||
|
|
||||||
# Fortran module files
|
|
||||||
*.mod
|
|
||||||
*.smod
|
|
||||||
|
|
||||||
# Compiled Static libraries
|
|
||||||
*.lai
|
|
||||||
*.la
|
|
||||||
*.a
|
|
||||||
*.lib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
@ -1,83 +0,0 @@
|
|||||||
sudo: false
|
|
||||||
|
|
||||||
language: python
|
|
||||||
python:
|
|
||||||
- "2.7"
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
|
|
||||||
env:
|
|
||||||
- TESTCASE="1.8.3|esp8266|stable|esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M"
|
|
||||||
- TESTCASE="1.8.3|esp8266|devel|esp8266com:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M"
|
|
||||||
- TESTCASE="1.8.3|esp32|devel|espressif:esp32:esp32:FlashFreq=40"
|
|
||||||
|
|
||||||
script:
|
|
||||||
- echo -e "travis_fold:start:sketch_test_env_prepare"
|
|
||||||
- pip install pyserial
|
|
||||||
- IFS='|' read -r -a array <<< "${TESTCASE}"
|
|
||||||
- |
|
|
||||||
for index in "${!array[@]}"
|
|
||||||
do
|
|
||||||
case $index in
|
|
||||||
0) IDEVER="${array[index]}" ;;
|
|
||||||
1) PLATFORM="${array[index]}" ;;
|
|
||||||
2) RELEASE="${array[index]}" ;;
|
|
||||||
3) BOARD="${array[index]}" ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
- cd $HOME
|
|
||||||
- wget -O arduino.tar.xz https://downloads.arduino.cc/arduino-${IDEVER}-linux64.tar.xz
|
|
||||||
- tar xf arduino.tar.xz
|
|
||||||
- mv arduino-${IDEVER} $HOME/arduino_ide
|
|
||||||
- mkdir -p $HOME/Arduino/libraries
|
|
||||||
- IDEDIR="${HOME}/arduino_ide"
|
|
||||||
- export PATH="$IDEDIR:$PATH"
|
|
||||||
- cd ${IDEDIR}
|
|
||||||
- which arduino
|
|
||||||
- |
|
|
||||||
if [[ $PLATFORM == "esp8266" ]] && [[ $RELEASE == "stable" ]]
|
|
||||||
then
|
|
||||||
arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
|
|
||||||
arduino --install-boards "esp8266:esp8266"
|
|
||||||
fi
|
|
||||||
- |
|
|
||||||
if [[ $PLATFORM == "esp8266" ]] && [[ $RELEASE == "devel" ]]
|
|
||||||
then
|
|
||||||
mkdir -p hardware/esp8266com
|
|
||||||
cd hardware/esp8266com
|
|
||||||
git clone https://github.com/esp8266/Arduino.git esp8266
|
|
||||||
cd esp8266/tools
|
|
||||||
python get.py
|
|
||||||
fi
|
|
||||||
- |
|
|
||||||
if [[ $PLATFORM == "esp32" ]] && [[ $RELEASE == "devel" ]]
|
|
||||||
then
|
|
||||||
mkdir -p hardware/espressif
|
|
||||||
cd hardware/espressif
|
|
||||||
git clone https://github.com/espressif/arduino-esp32.git esp32
|
|
||||||
cd esp32/tools/
|
|
||||||
python get.py
|
|
||||||
fi
|
|
||||||
- arduino --pref "compiler.warning_level=all" --save-prefs
|
|
||||||
- echo -e "travis_fold:end:sketch_test_env_prepare"
|
|
||||||
- echo -e "travis_fold:start:install_library"
|
|
||||||
- cd $HOME/Arduino/libraries
|
|
||||||
- git clone https://github.com/bbx10/WebServer_tng ${HOME}/Arduino/libraries/WebServer
|
|
||||||
- git clone https://github.com/bbx10/DNSServer_tng ${HOME}/Arduino/libraries/DNSServer
|
|
||||||
- echo -e "travis_fold:end:install_library"
|
|
||||||
- echo -e "travis_fold:start:CaptivePortalAdvanced"
|
|
||||||
- cd DNSServer/examples
|
|
||||||
- arduino --verbose-build --verify --board $BOARD CaptivePortalAdvanced/CaptivePortalAdvanced.ino
|
|
||||||
- echo -e "travis_fold:end:CaptivePortalAdvanced"
|
|
||||||
- echo -e "travis_fold:start:CaptivePortal"
|
|
||||||
- arduino --verbose-build --verify --board $BOARD CaptivePortal/CaptivePortal.ino
|
|
||||||
- echo -e "travis_fold:end:CaptivePortal"
|
|
||||||
- echo -e "travis_fold:start:DNSServer"
|
|
||||||
- arduino --verbose-build --verify --board $BOARD DNSServer/DNSServer.ino
|
|
||||||
- echo -e "travis_fold:end:DNSServer"
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
email:
|
|
||||||
on_success: change
|
|
||||||
on_failure: change
|
|
@ -1,7 +0,0 @@
|
|||||||
# DNSServer
|
|
||||||
ESP8266/ESP32 DNSServer library
|
|
||||||
|
|
||||||
This is an experimental port of the DNSServer library that should work on
|
|
||||||
ESP8266 and ESP32. This is NOT an official repo supported by Espressif. Do not
|
|
||||||
depend on this code for anything important or expect it to be updated. Once the
|
|
||||||
official repo is created, this repo will be deleted.
|
|
@ -1,41 +0,0 @@
|
|||||||
#ifdef ESP8266
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
ESP8266WebServer webServer(80);
|
|
||||||
#else
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <WebServer.h>
|
|
||||||
WebServer webServer(80);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const byte DNS_PORT = 53;
|
|
||||||
IPAddress apIP(192, 168, 1, 1);
|
|
||||||
DNSServer dnsServer;
|
|
||||||
|
|
||||||
String responseHTML = ""
|
|
||||||
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
|
|
||||||
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
|
|
||||||
"be redirected here.</p></body></html>";
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
WiFi.mode(WIFI_AP);
|
|
||||||
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
|
||||||
WiFi.softAP("DNSServer CaptivePortal example");
|
|
||||||
|
|
||||||
// if DNSServer is started with "*" for domain name, it will reply with
|
|
||||||
// provided IP to all DNS request
|
|
||||||
dnsServer.start(DNS_PORT, "*", apIP);
|
|
||||||
|
|
||||||
// replay to all requests with same HTML
|
|
||||||
webServer.onNotFound([]() {
|
|
||||||
webServer.send(200, "text/html", responseHTML);
|
|
||||||
});
|
|
||||||
webServer.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
dnsServer.processNextRequest();
|
|
||||||
webServer.handleClient();
|
|
||||||
}
|
|
@ -1,157 +0,0 @@
|
|||||||
#ifdef ESP8266
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <WiFiClient.h>
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
#include <EEPROM.h>
|
|
||||||
// Web server
|
|
||||||
ESP8266WebServer server(80);
|
|
||||||
#else
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <WiFiClient.h>
|
|
||||||
#include <WebServer.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <ESPmDNS.h>
|
|
||||||
#include <Preferences.h>
|
|
||||||
// Web server
|
|
||||||
WebServer server(80);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This example serves a "hello world" on a WLAN and a SoftAP at the same time.
|
|
||||||
* The SoftAP allow you to configure WLAN parameters at run time. They are not setup in the sketch but saved on EEPROM.
|
|
||||||
*
|
|
||||||
* Connect your computer or cell phone to wifi network ESP_ap with password 12345678. A popup may appear and it allow you to go to WLAN config. If it does not then navigate to http://192.168.4.1/wifi and config it there.
|
|
||||||
* Then wait for the module to connect to your wifi and take note of the WLAN IP it got. Then you can disconnect from ESP_ap and return to your regular WLAN.
|
|
||||||
*
|
|
||||||
* Now the ESP8266/ESP32 is in your network. You can reach it through http://192.168.x.x/ (the IP you took note of) or maybe at http://esp8266.local too.
|
|
||||||
*
|
|
||||||
* This is a captive portal because through the softAP it will redirect any http request to http://192.168.4.1/
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Set these to your desired softAP credentials. They are not configurable at runtime */
|
|
||||||
const char *softAP_ssid = "ESP_ap";
|
|
||||||
const char *softAP_password = "12345678";
|
|
||||||
|
|
||||||
/* hostname for mDNS. Should work at least on windows. Try http://esp8266.local */
|
|
||||||
#ifdef ESP8266
|
|
||||||
const char *myHostname = "esp8266";
|
|
||||||
#else
|
|
||||||
const char *myHostname = "esp32mambo";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Don't set this wifi credentials. They are configurated at runtime and stored on EEPROM */
|
|
||||||
char ssid[32] = "";
|
|
||||||
char password[32] = "";
|
|
||||||
|
|
||||||
// DNS server
|
|
||||||
const byte DNS_PORT = 53;
|
|
||||||
DNSServer dnsServer;
|
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
/* Storage for SSID and password */
|
|
||||||
Preferences preferences;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Soft AP network parameters */
|
|
||||||
IPAddress apIP(192, 168, 4, 1);
|
|
||||||
IPAddress netMsk(255, 255, 255, 0);
|
|
||||||
|
|
||||||
|
|
||||||
/** Should I connect to WLAN asap? */
|
|
||||||
boolean connect;
|
|
||||||
|
|
||||||
/** Last time I tried to connect to WLAN */
|
|
||||||
long lastConnectTry = 0;
|
|
||||||
|
|
||||||
/** Current WLAN status */
|
|
||||||
int status = WL_IDLE_STATUS;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
delay(1000);
|
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.println();
|
|
||||||
#ifdef ESP32
|
|
||||||
preferences.begin("CapPortAdv", false);
|
|
||||||
#endif
|
|
||||||
Serial.print("Configuring access point...");
|
|
||||||
/* You can remove the password parameter if you want the AP to be open. */
|
|
||||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
|
||||||
WiFi.softAP(softAP_ssid, softAP_password);
|
|
||||||
delay(500); // Without delay I've seen the IP address blank
|
|
||||||
Serial.print("AP IP address: ");
|
|
||||||
Serial.println(WiFi.softAPIP());
|
|
||||||
|
|
||||||
/* Setup the DNS server redirecting all the domains to the apIP */
|
|
||||||
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
|
||||||
dnsServer.start(DNS_PORT, "*", apIP);
|
|
||||||
|
|
||||||
/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
|
|
||||||
server.on("/", handleRoot);
|
|
||||||
server.on("/wifi", handleWifi);
|
|
||||||
server.on("/wifisave", handleWifiSave);
|
|
||||||
server.on("/generate_204", handleRoot); //Android captive portal. Maybe not needed. Might be handled by notFound handler.
|
|
||||||
server.on("/fwlink", handleRoot); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
|
||||||
server.onNotFound ( handleNotFound );
|
|
||||||
server.begin(); // Web server start
|
|
||||||
Serial.println("HTTP server started");
|
|
||||||
loadCredentials(); // Load WLAN credentials from network
|
|
||||||
connect = strlen(ssid) > 0; // Request WLAN connect if there is a SSID
|
|
||||||
}
|
|
||||||
|
|
||||||
void connectWifi() {
|
|
||||||
Serial.println("Connecting as wifi client...");
|
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.begin ( ssid, password );
|
|
||||||
int connRes = WiFi.waitForConnectResult();
|
|
||||||
Serial.print ( "connRes: " );
|
|
||||||
Serial.println ( connRes );
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (connect) {
|
|
||||||
Serial.println ( "Connect requested" );
|
|
||||||
connect = false;
|
|
||||||
connectWifi();
|
|
||||||
lastConnectTry = millis();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
int s = WiFi.status();
|
|
||||||
if (s == 0 && millis() > (lastConnectTry + 60000) ) {
|
|
||||||
/* If WLAN disconnected and idle try to connect */
|
|
||||||
/* Don't set retry time too low as retry interfere the softAP operation */
|
|
||||||
connect = true;
|
|
||||||
}
|
|
||||||
if (status != s) { // WLAN status change
|
|
||||||
Serial.print ( "Status: " );
|
|
||||||
Serial.println ( s );
|
|
||||||
status = s;
|
|
||||||
if (s == WL_CONNECTED) {
|
|
||||||
/* Just connected to WLAN */
|
|
||||||
Serial.println ( "" );
|
|
||||||
Serial.print ( "Connected to " );
|
|
||||||
Serial.println ( ssid );
|
|
||||||
Serial.print ( "IP address: " );
|
|
||||||
Serial.println ( WiFi.localIP() );
|
|
||||||
|
|
||||||
// Setup MDNS responder
|
|
||||||
if (!MDNS.begin(myHostname)) {
|
|
||||||
Serial.println("Error setting up MDNS responder!");
|
|
||||||
} else {
|
|
||||||
Serial.println("mDNS responder started");
|
|
||||||
// Add service to MDNS-SD
|
|
||||||
MDNS.addService("http", "tcp", 80);
|
|
||||||
}
|
|
||||||
} else if (s == WL_NO_SSID_AVAIL) {
|
|
||||||
WiFi.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Do work:
|
|
||||||
//DNS
|
|
||||||
dnsServer.processNextRequest();
|
|
||||||
//HTTP
|
|
||||||
server.handleClient();
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
|||||||
#ifdef ESP8266
|
|
||||||
/** Load WLAN credentials from EEPROM */
|
|
||||||
void loadCredentials() {
|
|
||||||
EEPROM.begin(512);
|
|
||||||
EEPROM.get(0, ssid);
|
|
||||||
EEPROM.get(0+sizeof(ssid), password);
|
|
||||||
char ok[2+1];
|
|
||||||
EEPROM.get(0+sizeof(ssid)+sizeof(password), ok);
|
|
||||||
EEPROM.end();
|
|
||||||
if (String(ok) != String("OK")) {
|
|
||||||
ssid[0] = 0;
|
|
||||||
password[0] = 0;
|
|
||||||
}
|
|
||||||
Serial.println("Recovered credentials:");
|
|
||||||
Serial.println(ssid);
|
|
||||||
Serial.println(strlen(password)>0?"********":"<no password>");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Store WLAN credentials to EEPROM */
|
|
||||||
void saveCredentials() {
|
|
||||||
EEPROM.begin(512);
|
|
||||||
EEPROM.put(0, ssid);
|
|
||||||
EEPROM.put(0+sizeof(ssid), password);
|
|
||||||
char ok[2+1] = "OK";
|
|
||||||
EEPROM.put(0+sizeof(ssid)+sizeof(password), ok);
|
|
||||||
EEPROM.commit();
|
|
||||||
EEPROM.end();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/** Load WLAN credentials from Preferences */
|
|
||||||
void loadCredentials() {
|
|
||||||
preferences.getString("ssid", ssid, sizeof(ssid));
|
|
||||||
preferences.getString("password", password, sizeof(password));
|
|
||||||
Serial.println("Recovered credentials:");
|
|
||||||
Serial.println(ssid);
|
|
||||||
Serial.println(strlen(password)>0?"********":"<no password>");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Store WLAN credentials to Preference */
|
|
||||||
void saveCredentials() {
|
|
||||||
preferences.putString("ssid", ssid);
|
|
||||||
preferences.putString("password", password);
|
|
||||||
Serial.println("Saved credentials:");
|
|
||||||
Serial.println(ssid);
|
|
||||||
Serial.println(strlen(password)>0?"********":"<no password>");
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,137 +0,0 @@
|
|||||||
/** Handle root or redirect to captive portal */
|
|
||||||
void handleRoot() {
|
|
||||||
if (captivePortal()) { // If caprive portal redirect instead of displaying the page.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
||||||
server.sendHeader("Pragma", "no-cache");
|
|
||||||
server.sendHeader("Expires", "-1");
|
|
||||||
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
|
||||||
server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
|
||||||
server.sendContent(
|
|
||||||
"<html><head></head><body>"
|
|
||||||
"<h1>HELLO WORLD!!</h1>"
|
|
||||||
);
|
|
||||||
if (server.client().localIP() == apIP) {
|
|
||||||
server.sendContent(String("<p>You are connected through the soft AP: ") + softAP_ssid + "</p>");
|
|
||||||
} else {
|
|
||||||
server.sendContent(String("<p>You are connected through the wifi network: ") + ssid + "</p>");
|
|
||||||
}
|
|
||||||
server.sendContent(
|
|
||||||
"<p>You may want to <a href='/wifi'>config the wifi connection</a>.</p>"
|
|
||||||
"</body></html>"
|
|
||||||
);
|
|
||||||
server.sendContent("");
|
|
||||||
server.client().stop(); // Stop is needed because we sent no content length
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
|
|
||||||
boolean captivePortal() {
|
|
||||||
if (!isIp(server.hostHeader()) && server.hostHeader() != (String(myHostname)+".local")) {
|
|
||||||
Serial.print("Request redirected to captive portal");
|
|
||||||
server.sendHeader("Location", String("http://") + toStringIp(server.client().localIP()), true);
|
|
||||||
server.send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
|
||||||
server.client().stop(); // Stop is needed because we sent no content length
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Wifi config page handler */
|
|
||||||
void handleWifi() {
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
||||||
server.sendHeader("Pragma", "no-cache");
|
|
||||||
server.sendHeader("Expires", "-1");
|
|
||||||
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
|
||||||
server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
|
||||||
server.sendContent(
|
|
||||||
"<html><head></head><body>"
|
|
||||||
"<h1>Wifi config</h1>"
|
|
||||||
);
|
|
||||||
if (server.client().localIP() == apIP) {
|
|
||||||
server.sendContent(String("<p>You are connected through the soft AP: ") + softAP_ssid + "</p>");
|
|
||||||
} else {
|
|
||||||
server.sendContent(String("<p>You are connected through the wifi network: ") + ssid + "</p>");
|
|
||||||
}
|
|
||||||
server.sendContent(
|
|
||||||
"\r\n<br />"
|
|
||||||
"<table><tr><th align='left'>SoftAP config</th></tr>"
|
|
||||||
);
|
|
||||||
server.sendContent(String() + "<tr><td>SSID " + String(softAP_ssid) + "</td></tr>");
|
|
||||||
server.sendContent(String() + "<tr><td>IP " + toStringIp(WiFi.softAPIP()) + "</td></tr>");
|
|
||||||
server.sendContent(
|
|
||||||
"</table>"
|
|
||||||
"\r\n<br />"
|
|
||||||
"<table><tr><th align='left'>WLAN config</th></tr>"
|
|
||||||
);
|
|
||||||
server.sendContent(String() + "<tr><td>SSID " + String(ssid) + "</td></tr>");
|
|
||||||
server.sendContent(String() + "<tr><td>IP " + toStringIp(WiFi.localIP()) + "</td></tr>");
|
|
||||||
server.sendContent(
|
|
||||||
"</table>"
|
|
||||||
"\r\n<br />"
|
|
||||||
"<table><tr><th align='left'>WLAN list (refresh if any missing)</th></tr>"
|
|
||||||
);
|
|
||||||
Serial.println("scan start");
|
|
||||||
int n = WiFi.scanNetworks();
|
|
||||||
Serial.println("scan done");
|
|
||||||
if (n > 0) {
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
#ifdef ESP8266
|
|
||||||
server.sendContent(String() + "\r\n<tr><td>SSID " + WiFi.SSID(i) + String((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":" *") + " (" + WiFi.RSSI(i) + ")</td></tr>");
|
|
||||||
#else
|
|
||||||
server.sendContent(String() + "\r\n<tr><td>SSID " + WiFi.SSID(i) + String((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":" *") + " (" + WiFi.RSSI(i) + ")</td></tr>");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
server.sendContent(String() + "<tr><td>No WLAN found</td></tr>");
|
|
||||||
}
|
|
||||||
server.sendContent(
|
|
||||||
"</table>"
|
|
||||||
"\r\n<br /><form method='POST' action='wifisave'><h4>Connect to network:</h4>"
|
|
||||||
"<input type='text' placeholder='network' name='n'/>"
|
|
||||||
"<br /><input type='password' placeholder='password' name='p'/>"
|
|
||||||
"<br /><input type='submit' value='Connect/Disconnect'/></form>"
|
|
||||||
"<p>You may want to <a href='/'>return to the home page</a>.</p>"
|
|
||||||
"</body></html>"
|
|
||||||
);
|
|
||||||
server.sendContent("");
|
|
||||||
server.client().stop(); // Stop is needed because we sent no content length
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handle the WLAN save form and redirect to WLAN config page again */
|
|
||||||
void handleWifiSave() {
|
|
||||||
Serial.println("wifi save");
|
|
||||||
server.arg("n").toCharArray(ssid, sizeof(ssid) - 1);
|
|
||||||
server.arg("p").toCharArray(password, sizeof(password) - 1);
|
|
||||||
server.sendHeader("Location", "wifi", true);
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
||||||
server.sendHeader("Pragma", "no-cache");
|
|
||||||
server.sendHeader("Expires", "-1");
|
|
||||||
server.send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
|
||||||
server.client().stop(); // Stop is needed because we sent no content length
|
|
||||||
saveCredentials();
|
|
||||||
connect = strlen(ssid) > 0; // Request WLAN connect with new credentials if there is a SSID
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleNotFound() {
|
|
||||||
if (captivePortal()) { // If caprive portal redirect instead of displaying the error page.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String message = "File Not Found\n\n";
|
|
||||||
message += "URI: ";
|
|
||||||
message += server.uri();
|
|
||||||
message += "\nMethod: ";
|
|
||||||
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
|
|
||||||
message += "\nArguments: ";
|
|
||||||
message += server.args();
|
|
||||||
message += "\n";
|
|
||||||
|
|
||||||
for ( uint8_t i = 0; i < server.args(); i++ ) {
|
|
||||||
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
|
|
||||||
}
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
||||||
server.sendHeader("Pragma", "no-cache");
|
|
||||||
server.sendHeader("Expires", "-1");
|
|
||||||
server.send ( 404, "text/plain", message );
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
/** Is this an IP? */
|
|
||||||
boolean isIp(String str) {
|
|
||||||
for (int i = 0; i < str.length(); i++) {
|
|
||||||
int c = str.charAt(i);
|
|
||||||
if (c != '.' && (c < '0' || c > '9')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** IP to String? */
|
|
||||||
String toStringIp(IPAddress ip) {
|
|
||||||
String res = "";
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
res += String((ip >> (8 * i)) & 0xFF) + ".";
|
|
||||||
}
|
|
||||||
res += String(((ip >> 8 * 3)) & 0xFF);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
#ifdef ESP8266
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
ESP8266WebServer webServer(80);
|
|
||||||
#else
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <WebServer.h>
|
|
||||||
WebServer webServer(80);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const byte DNS_PORT = 53;
|
|
||||||
IPAddress apIP(192, 168, 1, 1);
|
|
||||||
DNSServer dnsServer;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
WiFi.mode(WIFI_AP);
|
|
||||||
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
|
||||||
WiFi.softAP("DNSServer example");
|
|
||||||
|
|
||||||
// modify TTL associated with the domain name (in seconds)
|
|
||||||
// default is 60 seconds
|
|
||||||
dnsServer.setTTL(300);
|
|
||||||
// set which return code will be used for all other domains (e.g. sending
|
|
||||||
// ServerFailure instead of NonExistentDomain will reduce number of queries
|
|
||||||
// sent by clients)
|
|
||||||
// default is DNSReplyCode::NonExistentDomain
|
|
||||||
dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure);
|
|
||||||
|
|
||||||
// start DNS server for a specific domain name
|
|
||||||
dnsServer.start(DNS_PORT, "www.example.com", apIP);
|
|
||||||
|
|
||||||
// simple HTTP server to see that DNS server is working
|
|
||||||
webServer.onNotFound([]() {
|
|
||||||
String message = "Hello World!\n\n";
|
|
||||||
message += "URI: ";
|
|
||||||
message += webServer.uri();
|
|
||||||
|
|
||||||
webServer.send(200, "text/plain", message);
|
|
||||||
});
|
|
||||||
webServer.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
dnsServer.processNextRequest();
|
|
||||||
webServer.handleClient();
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
name=DNSServer
|
|
||||||
version=1.1.0
|
|
||||||
author=Kristijan Novoselić
|
|
||||||
maintainer=Kristijan Novoselić, <kristijan.novoselic@gmail.com>
|
|
||||||
sentence=A simple DNS server for ESP8266.
|
|
||||||
paragraph=This library implements a simple DNS server.
|
|
||||||
category=Communication
|
|
||||||
url=
|
|
||||||
architectures=esp8266,esp32
|
|
@ -1,171 +0,0 @@
|
|||||||
#include "DNSServer.h"
|
|
||||||
#include <lwip/def.h>
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
|
|
||||||
DNSServer::DNSServer()
|
|
||||||
{
|
|
||||||
_ttl = htonl(60);
|
|
||||||
_errorReplyCode = DNSReplyCode::NonExistentDomain;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DNSServer::start(const uint16_t &port, const String &domainName,
|
|
||||||
const IPAddress &resolvedIP)
|
|
||||||
{
|
|
||||||
_port = port;
|
|
||||||
_buffer = NULL;
|
|
||||||
_domainName = domainName;
|
|
||||||
_resolvedIP[0] = resolvedIP[0];
|
|
||||||
_resolvedIP[1] = resolvedIP[1];
|
|
||||||
_resolvedIP[2] = resolvedIP[2];
|
|
||||||
_resolvedIP[3] = resolvedIP[3];
|
|
||||||
downcaseAndRemoveWwwPrefix(_domainName);
|
|
||||||
return _udp.begin(_port) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::setErrorReplyCode(const DNSReplyCode &replyCode)
|
|
||||||
{
|
|
||||||
_errorReplyCode = replyCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::setTTL(const uint32_t &ttl)
|
|
||||||
{
|
|
||||||
_ttl = htonl(ttl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::stop()
|
|
||||||
{
|
|
||||||
_udp.stop();
|
|
||||||
free(_buffer);
|
|
||||||
_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::downcaseAndRemoveWwwPrefix(String &domainName)
|
|
||||||
{
|
|
||||||
domainName.toLowerCase();
|
|
||||||
domainName.replace("www.", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::processNextRequest()
|
|
||||||
{
|
|
||||||
_currentPacketSize = _udp.parsePacket();
|
|
||||||
if (_currentPacketSize)
|
|
||||||
{
|
|
||||||
if (_buffer != NULL) free(_buffer);
|
|
||||||
_buffer = (unsigned char*)malloc(_currentPacketSize * sizeof(char));
|
|
||||||
if (_buffer == NULL) return;
|
|
||||||
_udp.read(_buffer, _currentPacketSize);
|
|
||||||
_dnsHeader = (DNSHeader*) _buffer;
|
|
||||||
|
|
||||||
if (_dnsHeader->QR == DNS_QR_QUERY &&
|
|
||||||
_dnsHeader->OPCode == DNS_OPCODE_QUERY &&
|
|
||||||
requestIncludesOnlyOneQuestion() &&
|
|
||||||
(_domainName == "*" || getDomainNameWithoutWwwPrefix() == _domainName)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
replyWithIP();
|
|
||||||
}
|
|
||||||
else if (_dnsHeader->QR == DNS_QR_QUERY)
|
|
||||||
{
|
|
||||||
replyWithCustomCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
free(_buffer);
|
|
||||||
_buffer = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DNSServer::requestIncludesOnlyOneQuestion()
|
|
||||||
{
|
|
||||||
return ntohs(_dnsHeader->QDCount) == 1 &&
|
|
||||||
_dnsHeader->ANCount == 0 &&
|
|
||||||
_dnsHeader->NSCount == 0 &&
|
|
||||||
_dnsHeader->ARCount == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
String DNSServer::getDomainNameWithoutWwwPrefix()
|
|
||||||
{
|
|
||||||
String parsedDomainName = "";
|
|
||||||
if (_buffer == NULL) return parsedDomainName;
|
|
||||||
unsigned char *start = _buffer + 12;
|
|
||||||
if (*start == 0)
|
|
||||||
{
|
|
||||||
return parsedDomainName;
|
|
||||||
}
|
|
||||||
int pos = 0;
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
unsigned char labelLength = *(start + pos);
|
|
||||||
for(int i = 0; i < labelLength; i++)
|
|
||||||
{
|
|
||||||
pos++;
|
|
||||||
parsedDomainName += (char)*(start + pos);
|
|
||||||
}
|
|
||||||
pos++;
|
|
||||||
if (*(start + pos) == 0)
|
|
||||||
{
|
|
||||||
downcaseAndRemoveWwwPrefix(parsedDomainName);
|
|
||||||
return parsedDomainName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parsedDomainName += ".";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::replyWithIP()
|
|
||||||
{
|
|
||||||
if (_buffer == NULL) return;
|
|
||||||
_dnsHeader->QR = DNS_QR_RESPONSE;
|
|
||||||
_dnsHeader->ANCount = _dnsHeader->QDCount;
|
|
||||||
_dnsHeader->QDCount = _dnsHeader->QDCount;
|
|
||||||
//_dnsHeader->RA = 1;
|
|
||||||
|
|
||||||
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
|
|
||||||
_udp.write(_buffer, _currentPacketSize);
|
|
||||||
|
|
||||||
_udp.write((uint8_t)192); // answer name is a pointer
|
|
||||||
_udp.write((uint8_t)12); // pointer to offset at 0x00c
|
|
||||||
|
|
||||||
_udp.write((uint8_t)0); // 0x0001 answer is type A query (host address)
|
|
||||||
_udp.write((uint8_t)1);
|
|
||||||
|
|
||||||
_udp.write((uint8_t)0); //0x0001 answer is class IN (internet address)
|
|
||||||
_udp.write((uint8_t)1);
|
|
||||||
|
|
||||||
_udp.write((unsigned char*)&_ttl, 4);
|
|
||||||
|
|
||||||
// Length of RData is 4 bytes (because, in this case, RData is IPv4)
|
|
||||||
_udp.write((uint8_t)0);
|
|
||||||
_udp.write((uint8_t)4);
|
|
||||||
_udp.write(_resolvedIP, sizeof(_resolvedIP));
|
|
||||||
_udp.endPacket();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
DEBUG_OUTPUT.print("DNS responds: ");
|
|
||||||
DEBUG_OUTPUT.print(_resolvedIP[0]);
|
|
||||||
DEBUG_OUTPUT.print(".");
|
|
||||||
DEBUG_OUTPUT.print(_resolvedIP[1]);
|
|
||||||
DEBUG_OUTPUT.print(".");
|
|
||||||
DEBUG_OUTPUT.print(_resolvedIP[2]);
|
|
||||||
DEBUG_OUTPUT.print(".");
|
|
||||||
DEBUG_OUTPUT.print(_resolvedIP[3]);
|
|
||||||
DEBUG_OUTPUT.print(" for ");
|
|
||||||
DEBUG_OUTPUT.println(getDomainNameWithoutWwwPrefix());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void DNSServer::replyWithCustomCode()
|
|
||||||
{
|
|
||||||
if (_buffer == NULL) return;
|
|
||||||
_dnsHeader->QR = DNS_QR_RESPONSE;
|
|
||||||
_dnsHeader->RCode = (unsigned char)_errorReplyCode;
|
|
||||||
_dnsHeader->QDCount = 0;
|
|
||||||
|
|
||||||
_udp.beginPacket(_udp.remoteIP(), _udp.remotePort());
|
|
||||||
_udp.write(_buffer, sizeof(DNSHeader));
|
|
||||||
_udp.endPacket();
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
#ifndef DNSServer_h
|
|
||||||
#define DNSServer_h
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
|
|
||||||
#define DNS_QR_QUERY 0
|
|
||||||
#define DNS_QR_RESPONSE 1
|
|
||||||
#define DNS_OPCODE_QUERY 0
|
|
||||||
|
|
||||||
enum class DNSReplyCode
|
|
||||||
{
|
|
||||||
NoError = 0,
|
|
||||||
FormError = 1,
|
|
||||||
ServerFailure = 2,
|
|
||||||
NonExistentDomain = 3,
|
|
||||||
NotImplemented = 4,
|
|
||||||
Refused = 5,
|
|
||||||
YXDomain = 6,
|
|
||||||
YXRRSet = 7,
|
|
||||||
NXRRSet = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DNSHeader
|
|
||||||
{
|
|
||||||
uint16_t ID; // identification number
|
|
||||||
unsigned char RD : 1; // recursion desired
|
|
||||||
unsigned char TC : 1; // truncated message
|
|
||||||
unsigned char AA : 1; // authoritive answer
|
|
||||||
unsigned char OPCode : 4; // message_type
|
|
||||||
unsigned char QR : 1; // query/response flag
|
|
||||||
unsigned char RCode : 4; // response code
|
|
||||||
unsigned char Z : 3; // its z! reserved
|
|
||||||
unsigned char RA : 1; // recursion available
|
|
||||||
uint16_t QDCount; // number of question entries
|
|
||||||
uint16_t ANCount; // number of answer entries
|
|
||||||
uint16_t NSCount; // number of authority entries
|
|
||||||
uint16_t ARCount; // number of resource entries
|
|
||||||
};
|
|
||||||
|
|
||||||
class DNSServer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DNSServer();
|
|
||||||
void processNextRequest();
|
|
||||||
void setErrorReplyCode(const DNSReplyCode &replyCode);
|
|
||||||
void setTTL(const uint32_t &ttl);
|
|
||||||
|
|
||||||
// Returns true if successful, false if there are no sockets available
|
|
||||||
bool start(const uint16_t &port,
|
|
||||||
const String &domainName,
|
|
||||||
const IPAddress &resolvedIP);
|
|
||||||
// stops the DNS server
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
private:
|
|
||||||
WiFiUDP _udp;
|
|
||||||
uint16_t _port;
|
|
||||||
String _domainName;
|
|
||||||
unsigned char _resolvedIP[4];
|
|
||||||
int _currentPacketSize;
|
|
||||||
unsigned char* _buffer;
|
|
||||||
DNSHeader* _dnsHeader;
|
|
||||||
uint32_t _ttl;
|
|
||||||
DNSReplyCode _errorReplyCode;
|
|
||||||
|
|
||||||
void downcaseAndRemoveWwwPrefix(String &domainName);
|
|
||||||
String getDomainNameWithoutWwwPrefix();
|
|
||||||
bool requestIncludesOnlyOneQuestion();
|
|
||||||
void replyWithIP();
|
|
||||||
void replyWithCustomCode();
|
|
||||||
};
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user