소스 검색

examples und libraries eingecheckt

FloKra 6 년 전
부모
커밋
ba2826da2a

+ 82 - 0
examples/ESPmanager-example/ESPmanager-example.ino

@@ -0,0 +1,82 @@
+/*-------------------------------------------------------------------------------------------------------
+
+
+							Example ESP Manager software..
+
+BeerWare Licence, just give due credits
+
+Upload files to the ESP using this command (on mac and linux anyway, can upload using serial via SPIFFS data upload too)
+for file in `ls -A1`; do curl -F "file=@$PWD/$file" X.X.X.X/espman/upload; done
+ * Thanks to me-no-dev
+
+--------------------------------------------------------------------------------------------------------*/
+#include <FS.h> //  Settings saved to SPIFFS
+#include <ESP8266WiFi.h>
+#include <ESP8266HTTPClient.h>
+#include <ESP8266httpUpdate.h>
+#include <ESPAsyncTCP.h>
+#include <ESPAsyncWebServer.h>
+#include <AsyncJson.h>
+
+#include <ArduinoOTA.h>
+#include <ArduinoJson.h> // required for settings file to make it readable
+
+#include <Hash.h>
+#include <ESP8266mDNS.h>
+
+#include <ESPmanager.h>
+
+AsyncWebServer HTTP(80);
+
+ESPmanager settings(HTTP, SPIFFS);
+
+
+//  You can specify a default hard coded set of credentials
+/*
+const char * defaultSSID = "";
+const char * defaultPSK = "";
+ESPmanager settings(HTTP, SPIFFS, "ESPManager", defaultSSID , defaultPSK);
+*/
+
+void setup()
+{
+
+	Serial.begin(115200);
+	SPIFFS.begin();
+
+	Serial.println("");
+	Serial.println(F("Example ESPconfig - using ESPAsyncWebServer"));
+
+	Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
+	Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
+
+	settings.begin();
+
+
+
+	//  This rewrite is active when the captive portal is working, and redirects the root / to the setup wizard. 
+	//  This has to go in the main sketch to allow your project to control the root when using ESPManager. 
+	HTTP.rewrite("/", "/espman/setup.htm").setFilter( [](AsyncWebServerRequest * request) {
+		return settings.portal();
+	});
+
+
+	//  then use this rewrite and serve static to serve your index file(s)
+	HTTP.rewrite("/", "/index.htm");
+	HTTP.serveStatic("/index.htm", SPIFFS, "/index.htm");
+
+
+
+	HTTP.begin();
+
+	Serial.print(F("Free Heap: "));
+	Serial.println(ESP.getFreeHeap());
+
+
+}
+
+
+void loop()
+{
+	settings.handle();
+}

BIN
examples/ESPmanager-example/data/espman/ajax-loader.gif


BIN
examples/ESPmanager-example/data/espman/index.htm.gz


BIN
examples/ESPmanager-example/data/espman/setup.htm.gz


+ 62 - 0
examples/PersWiFiManager-test/spiffs_rest_api_nonblocking/data/conf.htm

@@ -0,0 +1,62 @@
+<h3>Configuration</h3>
+MQTT Server:
+<span id="mqtthost"></span>
+<br/> MQTT Port:
+<span id="mqttport"></span>
+<br/> MQTT User:
+<span id="mqttuser"></span>
+<br/> MQTT Password:
+<span id="mqttpass"></span>
+
+<h6>Last updated
+	<span id="ut"></span> seconds ago.
+	<span id="status"></span>
+</h6>
+
+<h3>Update Data</h3>
+<form id="xform" onsubmit="return transmit(this)">
+	x:
+	<input type="number" name="x" />
+	<input type="submit" />
+</form>
+<form id="yform" onsubmit="return transmit(this)">
+	y:
+	<input type="text" name="y" />
+	<input type="submit" />
+</form>
+<form id="zform" onsubmit="return transmit(this)">
+	z:
+	<input type="text" name="z" />
+	<input type="submit" />
+</form>
+
+<a href="wifi.htm">WiFi settings</a>
+
+<script>
+	function g(i) { return document.getElementById(i) };
+	var xhttp, updateTime;
+
+	function transmit(f) {
+		if (!xhttp) { //prevent simultaneous requests
+			g("status").innerHTML = "updating...";
+			xhttp = new XMLHttpRequest();
+			xhttp.open("POST", "/api");
+			xhttp.send(f ? (new FormData(f)) : "");
+			xhttp.onreadystatechange = function () {
+				if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
+					var data = JSON.parse(xhttp.responseText);
+					g("x").innerHTML = data.x;
+					g("y").innerHTML = data.y;
+					g("z").innerHTML = data.z;
+					xhttp = null;
+					g("status").innerHTML = "";
+					updateTime = 0;
+				}
+			}
+		}
+		return false; //prevent form redirect
+	}
+	transmit();
+	setInterval(function () { g("ut").innerHTML = ++updateTime; }, 1000);
+	setInterval(transmit, 5000); //autoupdate display every 5s
+</script>

+ 64 - 0
examples/PersWiFiManager-test/spiffs_rest_api_nonblocking/data/index.htm

@@ -0,0 +1,64 @@
+<h3>Current Data</h3>
+x:
+<span id="x"></span>
+<br/> y:
+<span id="y"></span>
+<br/> z:
+<span id="z"></span>
+<br/> current WiFi SSID:
+<span id="ssid"></span>
+
+<h6>Last updated
+	<span id="ut"></span> seconds ago.
+	<span id="status"></span>
+</h6>
+
+<h3>Update Data</h3>
+<form id="xform" onsubmit="return transmit(this)">
+	x:
+	<input type="number" name="x" />
+	<input type="submit" />
+</form>
+<form id="yform" onsubmit="return transmit(this)">
+	y:
+	<input type="text" name="y" />
+	<input type="submit" />
+</form>
+<form id="zform" onsubmit="return transmit(this)">
+	z:
+	<input type="text" name="z" />
+	<input type="submit" />
+</form>
+
+<a href="wifi.htm">WiFi settings</a><br/>
+<a href="/update">Firmware Update</a>
+
+<script>
+	function g(i) { return document.getElementById(i) };
+	var xhttp, updateTime;
+
+	function transmit(f) {
+		if (!xhttp) { //prevent simultaneous requests
+			g("status").innerHTML = "updating...";
+			xhttp = new XMLHttpRequest();
+			xhttp.open("POST", "/api");
+			xhttp.send(f ? (new FormData(f)) : "");
+			xhttp.onreadystatechange = function () {
+				if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
+					var data = JSON.parse(xhttp.responseText);
+					g("x").innerHTML = data.x;
+					g("y").innerHTML = data.y;
+					g("z").innerHTML = data.z;
+					g("ssid").innerHTML = data.ssid;
+					xhttp = null;
+					g("status").innerHTML = "";
+					updateTime = 0;
+				}
+			}
+		}
+		return false; //prevent form redirect
+	}
+	transmit();
+	setInterval(function () { g("ut").innerHTML = ++updateTime; }, 1000);
+	setInterval(transmit, 5000); //autoupdate display every 5s
+</script>

+ 108 - 0
examples/PersWiFiManager-test/spiffs_rest_api_nonblocking/data/wifi.htm

@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
+	<title>ESP WiFi</title>
+	<script>
+		function g(i){return document.getElementById(i);};
+		function p(t,l){if(confirm(t)) window.location=l;};
+		function E(s){return document.createElement(s)};
+		var S="setAttribute",A="appendChild",H="innerHTML",X,wl;
+		function scan(){
+			if(X) return;
+			X=new XMLHttpRequest(),wl=document.getElementById('wl');
+			wl[H]="Scanning...";
+			X.onreadystatechange=function(){
+				if (this.readyState==4&&this.status==200) {
+					X=0;
+					wl[H]="";
+					this.responseText.split("\n").forEach(function (e) {
+						let t=e.split(","), s=t.slice(2).join(',');
+						var d=E('div'),i=E('a'),c=E('a');
+						i[S]('class','s'); c[S]('class','q');
+						i.onclick=function(){g('s').value=s;g('p').focus();};
+						i[A](document.createTextNode(s));
+						c[H]=t[0]+"%"+(parseInt(t[1])?"\uD83D\uDD12":"\u26A0");
+						wl[A](i); wl[A](c);
+						wl[A](document.createElement('br'));
+					});
+				}
+			};
+			X.open("GET","wifi/list",true);
+			X.send();
+		};
+	</script>
+	<style>
+		input {
+			padding:5px;
+			font-size:1em;
+			width:95%;
+			filter:invert(100%);
+		}
+
+		body {
+			text-align:center;
+			font-family:verdana;
+			background-color:black;
+			color:white;
+		}
+
+		a {
+			color:#1fa3ec;
+		}
+
+		button {
+			border:0;
+			border-radius:0.3em;
+			background-color:#1fa3ec;
+			color:#fff;
+			line-height:2.4em;
+			font-size:1.2em;
+			width:100%;
+			display:block;
+		}
+
+		.q {
+			float:right;
+		}
+
+		.s {
+			display:inline-block;
+			width:14em;
+			overflow:hidden;
+			text-overflow:ellipsis;
+			white-space:nowrap;
+		}
+		#wl{
+			line-height:1.5em;
+		}
+	</style>
+</head>
+
+<body>
+	<div style='text-align:left;display:inline-block;width:320px;padding:5px'>
+		<button onclick="scan()">&#x21bb; Scan</button>
+		<p id='wl'></p>
+		<form method='post' action='/wifi/connect'>
+			<input id='s' name='n' length=32 placeholder='SSID'>
+			<br>
+			<input id='p' name='p' length=64 type='password' placeholder='password'>
+			<br>
+			<br>
+			<button type='submit'>Connect</button>
+		</form>
+		<br>
+		<br>
+		<button onclick="p('Start WPS?','/wifi/wps')">WPS Setup</button>
+		<br>
+		<button onclick="p('Start AP mode?','/wifi/ap')">AP Mode</button>
+		<br>
+		<button onclick="p('Reboot device?','/wifi/rst')">Reboot</button>
+		<br>
+		<a href="javascript:history.back()">Back</a> | 
+		<a href="/">Home</a>
+	</div>
+</body>
+
+</html>

+ 134 - 0
examples/PersWiFiManager-test/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino

@@ -0,0 +1,134 @@
+/*
+SPIFFS-served REST API example for PersWiFiManager v3.0
+*/
+
+#define DEBUG_SERIAL //uncomment for Serial debugging statements
+
+#ifdef DEBUG_SERIAL
+#define DEBUG_BEGIN Serial.begin(115200)
+#define DEBUG_PRINT(x) Serial.println(x)
+#else
+#define DEBUG_PRINT(x)
+#define DEBUG_BEGIN
+#endif
+
+//includes
+#include <PersWiFiManager.h>
+#include <ArduinoJson.h>
+#include <ESP8266WiFi.h>
+#include <WiFiClient.h>
+//#include <ESP8266WebServer.h>
+#include <ESP8266mDNS.h>
+#include <ESP8266HTTPUpdateServer.h>
+//#include <PubSubClient.h>
+
+
+//#include <EasySSDP.h> // http://ryandowning.net/EasySSDP/
+
+//extension of ESP8266WebServer with SPIFFS handlers built in
+#include <SPIFFSReadServer.h> // http://ryandowning.net/SPIFFSReadServer/
+// upload data folder to chip with Arduino ESP8266 filesystem uploader
+// https://github.com/esp8266/arduino-esp8266fs-plugin
+
+#include <DNSServer.h>
+#include <FS.h>
+
+#define DEVICE_NAME "ESP8266 DEVICE"
+
+
+//server objects
+SPIFFSReadServer server(80);
+DNSServer dnsServer;
+PersWiFiManager persWM(server, dnsServer);
+
+ESP8266HTTPUpdateServer httpUpdater;
+
+
+////// Sample program data
+int x;
+String y;
+float z;
+
+void setup() {
+  DEBUG_BEGIN; //for terminal debugging
+  DEBUG_PRINT();
+  
+  //optional code handlers to run everytime wifi is connected...
+  persWM.onConnect([]() {
+    DEBUG_PRINT("wifi connected");
+    DEBUG_PRINT(WiFi.SSID());
+    DEBUG_PRINT(WiFi.localIP());
+    //EasySSDP::begin(server);
+  });
+  //...or AP mode is started
+  persWM.onAp([](){
+    DEBUG_PRINT("AP MODE");
+    DEBUG_PRINT(persWM.getApSsid());
+  });
+
+  //allows serving of files from SPIFFS
+  SPIFFS.begin();
+  //sets network name for AP mode
+  persWM.setApCredentials(DEVICE_NAME);
+  //persWM.setApCredentials(DEVICE_NAME, "password"); optional password
+
+  //make connecting/disconnecting non-blocking
+  persWM.setConnectNonBlock(true);
+
+  //in non-blocking mode, program will continue past this point without waiting
+  persWM.begin();
+
+  //handles commands from webpage, sends live data in JSON format
+  server.on("/api", []() {
+    DEBUG_PRINT("server.on /api");
+    if (server.hasArg("x")) {
+      x = server.arg("x").toInt();
+      DEBUG_PRINT(String("x: ") + x);
+    } //if
+    if (server.hasArg("y")) {
+      y = server.arg("y");
+      DEBUG_PRINT("y: " + y);
+    } //if
+    if (server.hasArg("z")) {
+      z = server.arg("z").toFloat();;
+      //DEBUG_PRINT("z: " + z);
+    } //if
+
+    //build json object of program data
+    StaticJsonBuffer<200> jsonBuffer;
+    JsonObject &json = jsonBuffer.createObject();
+    json["x"] = x;
+    json["y"] = y;
+    json["z"] = z;
+    json["ssid"] = WiFi.SSID();
+
+    char jsonchar[200];
+    json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece
+    server.send(200, "application/json", jsonchar);
+
+  }); //server.on api
+
+
+  // HTTP Updater at /update
+  httpUpdater.setup(&server);
+
+  
+  server.begin();
+  
+  DEBUG_PRINT("setup complete.");
+  DEBUG_PRINT("Hodensack!");
+} //void setup
+
+void loop() {
+  //in non-blocking mode, handleWiFi must be called in the main loop
+  persWM.handleWiFi();
+
+  dnsServer.processNextRequest();
+  server.handleClient();
+
+  //DEBUG_PRINT(millis());
+
+  // do stuff with x and y
+
+} //void loop
+

BIN
examples/PersWiFiManager-test/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino.d1_mini.bin


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
examples/PersWiFiManager-test/wifi.min.htm


BIN
examples/PersWiFiManager-test/wifi.min.htm.gz


BIN
libraries/ESPAsyncTCP.zip


BIN
libraries/ESPAsyncWebServer.zip


BIN
libraries/ESPmanager-1.2.0.zip


BIN
libraries/ESPmanager.zip


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.