mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-03 15:40:39 +08:00
Add embedded favicon.ico scripts and support
Add WebSocket Subprotocol support per @terjeio suggestion Change ESP800 report to use FlashFileSystem instead of FileSystem per @terjeio suggestion for consistency Add Host Path support for files hosted in subdirectory (WIP) Add createPath flag for upload to create full path if does not exists Update embedded page to support new ESP800 flags Update WebSocket library to avoid warning Update Features.md Bump platformIO to 5.1.0 Bumb version to 204
This commit is contained in:
parent
d0317e6d99
commit
da4190ec8b
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -2,7 +2,8 @@
|
||||
"git.ignoreLimitWarning": true,
|
||||
"files.associations": {
|
||||
"*.tcc": "cpp",
|
||||
"fstream": "cpp"
|
||||
"fstream": "cpp",
|
||||
"string": "cpp"
|
||||
},
|
||||
"cmake.configureOnOpen": false
|
||||
}
|
16
Features.md
16
Features.md
@ -14,7 +14,7 @@
|
||||
* FTP support (limited to 1 connection at once)
|
||||
* WebDav support
|
||||
* Local FS support:
|
||||
* Little FS (prefered)
|
||||
* Little FS (recommended)
|
||||
* Fat (ESP32 only)
|
||||
* SPIFFS (deprecated)
|
||||
* SD support
|
||||
@ -29,13 +29,15 @@
|
||||
* Sharing connection using hardware switch
|
||||
* e.g.: Panucatt Wifi Backpack / Azteeg X5 WiFi
|
||||
* MKS fast upload by serial
|
||||
* NOT SUPPORTED
|
||||
* NOT SUPPORTED ANYMORE
|
||||
* M28/M29 File transfer protocol
|
||||
* Serial file transfer using custom protocol (planned)
|
||||
* USB support
|
||||
* planned
|
||||
* Global FS under FTP / Webdav : SD + Local FS in same directory
|
||||
* Buzzer support
|
||||
* Recovery pin support
|
||||
* Pins control by commands
|
||||
* ESP32 Camera support (only with PSRAM)
|
||||
* Basic oled screen support
|
||||
* I2C SSD1306 128x64
|
||||
@ -44,7 +46,7 @@
|
||||
* SPI ST7789 135x240
|
||||
* SPI ST7789 240x240
|
||||
* Time synchronization support (manual / internet server)
|
||||
* Lua interpreter support
|
||||
* Lua interpreter support (Work in progress)
|
||||
* Notifications support
|
||||
* WebUI
|
||||
* TFT/OLED
|
||||
@ -58,11 +60,13 @@
|
||||
* Analog
|
||||
* BMX280
|
||||
* Auto script support at start
|
||||
* Basic Host GCODE stream for macros hosted on local FS
|
||||
* Basic Host GCODE stream for macros hosted on local FS (Work in Progress to improve it)
|
||||
* Update
|
||||
* ESP3D configuration using ini file on SD
|
||||
* ESP3D update using binary file on SD
|
||||
|
||||
*
|
||||
* OTA support
|
||||
* Update by WebUI
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@ I did a project board to put all majors tasks/issues in one places : [ESP3D Proj
|
||||
|
||||
- [Finish web UI Major features (3D printing and GRBL)](https://github.com/luc-github/ESP3D-WEBUI/issues/94#issuecomment-660600551)
|
||||
- Do user documentation: Readme / features list description / wiki/ Features videos etc...
|
||||
- Complete all planned features
|
||||
- Test current features heavily
|
||||
- Collect some feedback
|
||||
|
||||
|
BIN
embedded/assets/favicon.ico
Normal file
BIN
embedded/assets/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
1
embedded/assets/footer.txt
Normal file
1
embedded/assets/footer.txt
Normal file
@ -0,0 +1 @@
|
||||
#endif //__favicon_h
|
22
embedded/assets/header.txt
Normal file
22
embedded/assets/header.txt
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
favicon.h - ESP3D data file
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __favicon_h
|
||||
#define __favicon_h
|
95
embedded/config/buildassets.js
Normal file
95
embedded/config/buildassets.js
Normal file
@ -0,0 +1,95 @@
|
||||
let path = require("path");
|
||||
const fs = require("fs");
|
||||
const { createReadStream, createWriteStream } = require("fs");
|
||||
const { createGzip } = require("zlib");
|
||||
const chalk = require("chalk");
|
||||
|
||||
let distPath = path.normalize(__dirname + "/../dist/");
|
||||
let srcPath = path.normalize(__dirname + "/../assets/");
|
||||
let headerPath = path.normalize(
|
||||
__dirname + "/../../esp3d/src/modules/http/favicon.h"
|
||||
);
|
||||
|
||||
|
||||
|
||||
const convertToC = (filepath) => {
|
||||
console.log(chalk.yellow("Converting bin to text file"));
|
||||
//Cleaning files
|
||||
if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp");
|
||||
if (fs.existsSync(distPath + "favicon.h")) fs.rmSync(distPath + "favicon.h");
|
||||
|
||||
const data = new Uint8Array(
|
||||
fs.readFileSync(filepath, { flag: "r" })
|
||||
);
|
||||
console.log("data size is ", data.length);
|
||||
let out = "#define favicon_size " + data.length + "\n";
|
||||
out += "const unsigned char favicon[" + data.length + "] PROGMEM = {\n ";
|
||||
let nb = 0;
|
||||
data.forEach((byte, index) => {
|
||||
out += " 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16);
|
||||
if (index < data.length - 1) out += ",";
|
||||
if (nb == 15) {
|
||||
out += "\n ";
|
||||
nb = 0;
|
||||
} else {
|
||||
nb++;
|
||||
}
|
||||
});
|
||||
|
||||
out += "\n};\n";
|
||||
fs.writeFileSync(distPath + "out.tmp", out);
|
||||
|
||||
//Check conversion
|
||||
if (fs.existsSync(distPath + "out.tmp")) {
|
||||
console.log(chalk.green("[ok]"));
|
||||
} else {
|
||||
console.log(chalk.red("[error]Conversion failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Format header file
|
||||
console.log(chalk.yellow("Building header"));
|
||||
fs.writeFileSync(
|
||||
distPath + "favicon.h",
|
||||
fs.readFileSync(srcPath + "header.txt")
|
||||
);
|
||||
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString();
|
||||
fs.appendFileSync(distPath + "favicon.h", bin2cfile);
|
||||
fs.appendFileSync(
|
||||
distPath + "favicon.h",
|
||||
fs.readFileSync(srcPath + "footer.txt")
|
||||
);
|
||||
|
||||
//Check format result
|
||||
if (fs.existsSync(distPath + "favicon.h")) {
|
||||
console.log(chalk.green("[ok]"));
|
||||
} else {
|
||||
console.log(chalk.red("[error]Conversion failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Move file to src
|
||||
console.log(chalk.yellow("Overwriting header in sources"));
|
||||
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "favicon.h"));
|
||||
if (fs.existsSync(headerPath)) {
|
||||
console.log(chalk.green("[ok]"));
|
||||
} else {
|
||||
console.log(chalk.red("[error]Overwriting failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create a gzip function for reusable purpose
|
||||
const compressFile = (filePath, targetPath) => {
|
||||
const stream = createReadStream(filePath);
|
||||
stream
|
||||
.pipe(createGzip(targetPath))
|
||||
.pipe(createWriteStream(targetPath))
|
||||
.on("finish", () =>{console.log(`Successfully compressed at ${targetPath}`);
|
||||
convertToC (targetPath)}
|
||||
);
|
||||
};
|
||||
|
||||
compressFile(srcPath + "favicon.ico", distPath + "favicon.ico.gz");
|
15
embedded/config/pack_favicon.js
Normal file
15
embedded/config/pack_favicon.js
Normal file
@ -0,0 +1,15 @@
|
||||
const path = require("path");
|
||||
const { createReadStream, createWriteStream } = require("fs");
|
||||
const { createGzip } = require("zlib");
|
||||
const faviconPath = path.normalize(__dirname + "/../assets/favicon.ico");
|
||||
|
||||
// Create a gzip function for reusable purpose
|
||||
const compressFile = (filePath) => {
|
||||
const stream = createReadStream(filePath);
|
||||
stream
|
||||
.pipe(createGzip())
|
||||
.pipe(createWriteStream(`${filePath}.gz`))
|
||||
.on("finish", () =>console.log(`Successfully compressed the file at ${filePath}`)
|
||||
);
|
||||
};
|
||||
compressFile(faviconPath);
|
@ -15,9 +15,12 @@ let currentID = 0;
|
||||
const app = express();
|
||||
const fileUpload = require("express-fileupload");
|
||||
let serverpath = path.normalize(__dirname + "/../server/public/");
|
||||
let sdpath = path.normalize(__dirname + "/../server/sd/");
|
||||
|
||||
let WebSocketServer = require("ws").Server,
|
||||
wss = new WebSocketServer({ port: 81 });
|
||||
wss = new WebSocketServer({ port: 81,handleProtocols:function(protocol) {console.log( "protocol received from client " + protocol );
|
||||
return "webui-v3";
|
||||
return null;}});
|
||||
app.use(fileUpload({ preserveExtension: true, debug: false }));
|
||||
app.listen(port, () =>
|
||||
console.log(expresscolor(`[express] Listening on port ${port}!`))
|
||||
@ -85,22 +88,30 @@ app.get("/command", function (req, res) {
|
||||
console.log(commandcolor(`[server]/command params: ${req.query.cmd}`));
|
||||
let url = req.query.cmd;
|
||||
if (url.startsWith("[ESP800]json")) {
|
||||
res.json({
|
||||
FWVersion: "3.0.0.a28",
|
||||
FWTarget: 40,
|
||||
SDConnection: "none",
|
||||
Authentication: "Disabled",
|
||||
WebCommunication: "Synchronous",
|
||||
WebSocketIP: "localhost",
|
||||
WebSocketPort: "81",
|
||||
Hostname: "esp3d",
|
||||
WiFiMode: "STA",
|
||||
WebUpdate: "Enabled",
|
||||
Filesystem: "SPIFFS",
|
||||
Time: "none",
|
||||
Cam_ID: "4",
|
||||
Cam_name: "ESP32 Cam",
|
||||
});
|
||||
res.json(
|
||||
{
|
||||
cmd: "800",
|
||||
status: "ok",
|
||||
data:{
|
||||
FWVersion: "3.0.0.a28",
|
||||
FWTarget: 40,
|
||||
SDConnection: "none",
|
||||
Authentication: "Disabled",
|
||||
WebCommunication: "Synchronous",
|
||||
WebSocketIP: "localhost",
|
||||
WebSocketPort: "81",
|
||||
WebSocketSubProtocol: "webui-v3",
|
||||
Hostname: "esp3d",
|
||||
WiFiMode: "STA",
|
||||
WebUpdate: "Enabled",
|
||||
FlashFileSystem: "LittleFs",
|
||||
HostPath: "/",
|
||||
Time: "none",
|
||||
Cam_ID: "4",
|
||||
Cam_name: "ESP32 Cam",
|
||||
}
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (url.indexOf("ESP111") != -1) {
|
||||
@ -465,12 +476,12 @@ function fileSizeString(size) {
|
||||
return "X B";
|
||||
}
|
||||
|
||||
function filesList(mypath) {
|
||||
function filesList(mypath,mainpath) {
|
||||
let res = '{"files":[';
|
||||
let nb = 0;
|
||||
let total = 1.31 * 1024 * 1024;
|
||||
let totalused = getTotalSize(serverpath);
|
||||
let currentpath = path.normalize(serverpath + mypath);
|
||||
let total = sdpath==mainpath? (4096 * 1024 * 1024):(1.2 * 1024 * 1024);
|
||||
let totalused = getTotalSize(mainpath);
|
||||
let currentpath = path.normalize(mainpath + mypath);
|
||||
console.log("[path]" + currentpath);
|
||||
fs.readdirSync(currentpath).forEach((fileelement) => {
|
||||
let fullpath = path.normalize(currentpath + "/" + fileelement);
|
||||
@ -548,6 +559,55 @@ app.all("/updatefw", function (req, res) {
|
||||
res.send("ok");
|
||||
});
|
||||
|
||||
app.all("/sdfiles", function (req, res) {
|
||||
let mypath = req.query.path;
|
||||
let url = req.originalUrl;
|
||||
let filepath = path.normalize(sdpath + mypath + "/" + req.query.filename);
|
||||
if (url.indexOf("action=deletedir") != -1) {
|
||||
console.log("[server]delete directory " + filepath);
|
||||
deleteFolderRecursive(filepath);
|
||||
fs.readdirSync(mypath);
|
||||
} else if (url.indexOf("action=delete") != -1) {
|
||||
fs.unlinkSync(filepath);
|
||||
console.log("[server]delete file " + filepath);
|
||||
}
|
||||
if (url.indexOf("action=createdir") != -1) {
|
||||
fs.mkdirSync(filepath);
|
||||
console.log("[server]new directory " + filepath);
|
||||
}
|
||||
if (typeof mypath == "undefined") {
|
||||
if (typeof req.body.path == "undefined") {
|
||||
console.log("[server]path is not defined");
|
||||
mypath = "/";
|
||||
} else {
|
||||
mypath = (req.body.path == "/" ? "" : req.body.path) + "/";
|
||||
}
|
||||
}
|
||||
console.log("[server]path is " + mypath);
|
||||
if (!req.files || Object.keys(req.files).length === 0) {
|
||||
return res.send(filesList(mypath,sdpath));
|
||||
}
|
||||
let myFile = req.files.myfiles;
|
||||
if (typeof myFile.length == "undefined") {
|
||||
let fullpath = path.normalize(sdpath + mypath + myFile.name);
|
||||
console.log("[server]one file:" + fullpath);
|
||||
myFile.mv(fullpath, function (err) {
|
||||
if (err) return res.status(500).send(err);
|
||||
res.send(filesList(mypath,sdpath));
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
console.log(myFile.length + " files");
|
||||
for (let i = 0; i < myFile.length; i++) {
|
||||
let fullpath = path.normalize(sdpath + mypath + myFile[i].name);
|
||||
console.log(fullpath);
|
||||
myFile[i].mv(fullpath).then(() => {
|
||||
if (i == myFile.length - 1) res.send(filesList(mypath,sdpath));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.all("/files", function (req, res) {
|
||||
let mypath = req.query.path;
|
||||
let url = req.originalUrl;
|
||||
@ -574,7 +634,7 @@ app.all("/files", function (req, res) {
|
||||
}
|
||||
console.log("[server]path is " + mypath);
|
||||
if (!req.files || Object.keys(req.files).length === 0) {
|
||||
return res.send(filesList(mypath));
|
||||
return res.send(filesList(mypath,serverpath));
|
||||
}
|
||||
let myFile = req.files.myfiles;
|
||||
if (typeof myFile.length == "undefined") {
|
||||
@ -582,7 +642,7 @@ app.all("/files", function (req, res) {
|
||||
console.log("[server]one file:" + fullpath);
|
||||
myFile.mv(fullpath, function (err) {
|
||||
if (err) return res.status(500).send(err);
|
||||
res.send(filesList(mypath));
|
||||
res.send(filesList(mypath, serverpath));
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
@ -591,7 +651,7 @@ app.all("/files", function (req, res) {
|
||||
let fullpath = path.normalize(serverpath + mypath + myFile[i].name);
|
||||
console.log(fullpath);
|
||||
myFile[i].mv(fullpath).then(() => {
|
||||
if (i == myFile.length - 1) res.send(filesList(mypath));
|
||||
if (i == myFile.length - 1) res.send(filesList(mypath, serverpath));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
1846
embedded/package-lock.json
generated
1846
embedded/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -7,10 +7,11 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"front": "webpack serve --config config/webpack.dev.js ",
|
||||
"pack": "webpack --config config/webpack.prod.js",
|
||||
"convert": "node ./config/buildheader.js",
|
||||
"convert-assets": "node ./config/buildassets.js",
|
||||
"convert-page": "node ./config/buildheader.js",
|
||||
"server": "nodemon config/server.js",
|
||||
"dev": "concurrently \"npm run server\" \"npm run front\"",
|
||||
"build": "npm run pack && npm run convert"
|
||||
"build": "npm run pack && npm run convert-page && npm run convert-assets"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
@ -30,7 +30,7 @@ let wsMsg = "";
|
||||
let logOff = false;
|
||||
let pageId = "";
|
||||
let currentPath = "/";
|
||||
const version = "3.0.0.a4";
|
||||
const version = "3.0.0.a5";
|
||||
let xmlhttpupload;
|
||||
let prgfiletext;
|
||||
let prgfile;
|
||||
@ -40,6 +40,8 @@ let loginLink;
|
||||
let loginModal;
|
||||
let loginUser = "";
|
||||
let loginMsg;
|
||||
let fspath="/files";
|
||||
let hostpath="/";
|
||||
|
||||
window.onload = function () {
|
||||
consolePanel = document.getElementById("consolePanel");
|
||||
@ -332,9 +334,15 @@ function processFWJson(text) {
|
||||
window.open(url);
|
||||
});
|
||||
consolePanel.classList.remove("hide");
|
||||
if (json.FileSystem && json.FileSystem != "none")
|
||||
fileSystem.classList.remove("hide");
|
||||
if ((json.FlashFileSystem && json.FlashFileSystem != "none")||(json.SDConnection && json.SDConnection != "none")){
|
||||
fileSystem.classList.remove("hide");
|
||||
if (json.FlashFileSystem && json.FlashFileSystem == "none"){
|
||||
fspath="/sdfiles";
|
||||
}
|
||||
}
|
||||
|
||||
if (json.WebUpdate == "Enabled") firmware.classList.remove("hide");
|
||||
hostpath = json.HostPath;
|
||||
if (json.WiFiMode && json.WebSocketIP) {
|
||||
if (isLimitedEnvironment(json.WiFiMode)) {
|
||||
let address =
|
||||
@ -349,18 +357,18 @@ function processFWJson(text) {
|
||||
}
|
||||
}
|
||||
if (json.Hostname) document.title = json.Hostname;
|
||||
startSocket(json.WebSocketIP, json.WebSocketPort, json.WebCommunication);
|
||||
startSocket(json.WebSocketIP, json.WebSocketPort, json.WebCommunication, json.WebSocketSubProtocol);
|
||||
SendFileCommand("list", "all");
|
||||
}
|
||||
|
||||
function startSocket(ip, port, sync) {
|
||||
function startSocket(ip, port, sync, protocol) {
|
||||
if (websocketStarted) {
|
||||
wsSource.close();
|
||||
}
|
||||
|
||||
wsSource = new WebSocket(
|
||||
"ws://" + ip + ":" + port + (sync == "Asynchronous" ? "/ws" : ""),
|
||||
["arduino"]
|
||||
[protocol]
|
||||
);
|
||||
wsSource.binaryType = "arraybuffer";
|
||||
wsSource.onopen = function (e) {
|
||||
@ -372,10 +380,13 @@ function startSocket(ip, port, sync) {
|
||||
//if it is not a log off
|
||||
if (!logOff)
|
||||
setTimeout(() => {
|
||||
startSocket(ip, port, sync);
|
||||
startSocket(ip, port, sync, protocol);
|
||||
}, 3000);
|
||||
};
|
||||
wsSource.onerror = function (e) {};
|
||||
wsSource.onerror = function (e) {
|
||||
ErrorMSG("Error: websocket error!<br/>" );
|
||||
console.log("Error: websocket error!");
|
||||
};
|
||||
wsSource.onmessage = function (e) {
|
||||
let msg = "";
|
||||
//bin
|
||||
@ -466,12 +477,12 @@ function InfoMSG(msg) {
|
||||
|
||||
function getFWData() {
|
||||
let url = new URL("http://" + window.location.host + "/command");
|
||||
url.searchParams.append("cmd", "[ESP800]json=YES time=" + getPCTime());
|
||||
url.searchParams.append("cmd", "[ESP800]json=YES version="+version+" time=" + getPCTime());
|
||||
httpGet(url, processFWJson);
|
||||
}
|
||||
|
||||
function SendFileCommand(action, filename) {
|
||||
let url = new URL("http://" + window.location.host + "/files");
|
||||
let url = new URL("http://" + window.location.host + fspath);
|
||||
url.searchParams.append("action", action);
|
||||
url.searchParams.append("filename", filename);
|
||||
url.searchParams.append("path", currentPath);
|
||||
@ -578,7 +589,7 @@ function dispatchFileStatus(jsonresponse) {
|
||||
for (let i1 = 0; i1 < json.files.length; i1++) {
|
||||
if (String(json.files[i1].size) != "-1") {
|
||||
if (
|
||||
currentPath == "/" &&
|
||||
currentPath == hostpath &&
|
||||
(json.files[i1].name == "index.html.gz" ||
|
||||
json.files[i1].name == "index.html")
|
||||
) {
|
||||
@ -737,7 +748,7 @@ function uploadFiles() {
|
||||
formData.append("myfiles", file, currentpath + file.name);
|
||||
}
|
||||
xmlhttpupload = new XMLHttpRequest();
|
||||
xmlhttpupload.open("POST", "/files", true);
|
||||
xmlhttpupload.open("POST", fspath, true);
|
||||
//progress upload event
|
||||
xmlhttpupload.upload.addEventListener("progress", updateProgress, false);
|
||||
//progress function
|
||||
|
@ -48,6 +48,6 @@ Telnet_Server telnet_debug;
|
||||
|
||||
//Websocket
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
WebSocket_Server websocket_debug;
|
||||
WebSocket_Server websocket_debug("debug");
|
||||
#endif // ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
|
@ -34,6 +34,7 @@
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
|
||||
#ifdef HTTP_FEATURE
|
||||
#include "../../modules/http/http_server.h"
|
||||
#include "../../modules/websocket/websocket_server.h"
|
||||
#endif //HTTP_FEATURE
|
||||
#ifdef TIMESTAMP_FEATURE
|
||||
#include "../../modules/time/time_server.h"
|
||||
@ -246,6 +247,20 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printMSGLine(line.c_str());
|
||||
}
|
||||
line="";
|
||||
//WebSocket subprotocol
|
||||
if (json) {
|
||||
line+=",\"WebSocketSubProtocol\":\"";
|
||||
} else {
|
||||
line+= "Web Socket SubProtocol:";
|
||||
}
|
||||
line+= websocket_terminal_server.getProtocol();
|
||||
if (json) {
|
||||
line +="\"";
|
||||
output->print (line.c_str());
|
||||
} else {
|
||||
output->printMSGLine(line.c_str());
|
||||
}
|
||||
line="";
|
||||
//WebSocket Port
|
||||
if (json) {
|
||||
line+=",\"WebSocketPort\":\"";
|
||||
@ -255,7 +270,7 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
|
||||
#if defined (ASYNCWEBSERVER_FEATURE)
|
||||
line+=HTTP_Server::port();
|
||||
#else
|
||||
line+=(HTTP_Server::port() +1);
|
||||
line+=websocket_terminal_server.getPort();
|
||||
#endif
|
||||
if (json) {
|
||||
line +="\"";
|
||||
@ -324,12 +339,11 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
line="";
|
||||
#endif //WIFI_FEATURE|| ETH_FEATURE
|
||||
|
||||
//FS
|
||||
if (json) {
|
||||
line+=",\"FileSystem\":\"";
|
||||
line+=",\"FlashFileSystem\":\"";
|
||||
} else {
|
||||
line+= "File system:";
|
||||
line+= "Flash File System:";
|
||||
}
|
||||
#if defined(FILESYSTEM_FEATURE)
|
||||
line+=ESP_FileSystem::FilesystemName();
|
||||
@ -343,6 +357,21 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printMSGLine(line.c_str());
|
||||
}
|
||||
line="";
|
||||
// Host path
|
||||
if (json) {
|
||||
line+=",\"HostPath\":\"";
|
||||
} else {
|
||||
line+= "Host Path:";
|
||||
}
|
||||
|
||||
line+= ESP3D_HOST_PATH;
|
||||
if (json) {
|
||||
line +="\"";
|
||||
output->print (line.c_str());
|
||||
} else {
|
||||
output->printMSGLine(line.c_str());
|
||||
}
|
||||
line="";
|
||||
//time server
|
||||
if (json) {
|
||||
line+=",\"Time\":\"";
|
||||
|
@ -267,4 +267,7 @@
|
||||
#define FS_UNKNOWN 254
|
||||
#define MAX_FS 3
|
||||
|
||||
//Host path
|
||||
#define ESP3D_HOST_PATH "/"
|
||||
|
||||
#endif //_DEFINES_ESP3D_H
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a203"
|
||||
#define FW_VERSION "3.0.0.a204"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
File diff suppressed because it is too large
Load Diff
48
esp3d/src/modules/http/favicon.h
Normal file
48
esp3d/src/modules/http/favicon.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
favicon.h - ESP3D data file
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __favicon_h
|
||||
#define __favicon_h
|
||||
#define favicon_size 345
|
||||
const unsigned char favicon[345] PROGMEM = {
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xb5, 0x94, 0x31, 0x4b, 0xc3, 0x50,
|
||||
0x14, 0x85, 0x4f, 0x63, 0xc1, 0x5a, 0x0b, 0x06, 0x91, 0x4e, 0x52, 0x3a, 0x44, 0x10, 0x27, 0x31,
|
||||
0x45, 0xdc, 0x74, 0xea, 0xef, 0x90, 0x4c, 0x22, 0x0e, 0x22, 0xba, 0x0b, 0x4e, 0xc5, 0xb9, 0x3f,
|
||||
0xc0, 0x5f, 0xd0, 0x31, 0xab, 0x8e, 0x0e, 0x4e, 0x52, 0xba, 0x0a, 0x0e, 0xe2, 0x26, 0x48, 0x87,
|
||||
0x52, 0xa5, 0x9e, 0x4b, 0x4f, 0xf0, 0x52, 0x13, 0xa8, 0x82, 0xaf, 0x7c, 0xcd, 0xcb, 0xb9, 0xe7,
|
||||
0xde, 0x77, 0xfb, 0x5e, 0x52, 0xa0, 0xc4, 0x4f, 0x18, 0x82, 0xdf, 0x4d, 0x1c, 0x95, 0x81, 0x3a,
|
||||
0x80, 0x4d, 0x42, 0x89, 0xca, 0x54, 0xff, 0xaf, 0xf1, 0x7e, 0xb1, 0x3c, 0x31, 0xf2, 0xe6, 0xf3,
|
||||
0xfa, 0x6c, 0x78, 0x5f, 0x76, 0x8d, 0xe3, 0xf8, 0xc0, 0xc8, 0x8b, 0xf9, 0x3a, 0x45, 0x75, 0x55,
|
||||
0x63, 0x4c, 0x56, 0xf3, 0x7a, 0xf3, 0xda, 0x6c, 0xcf, 0xca, 0xbd, 0x91, 0x16, 0xfc, 0x66, 0x7d,
|
||||
0xe6, 0x3d, 0x3b, 0x3d, 0xe0, 0x7d, 0x52, 0xd4, 0xe7, 0xec, 0xa0, 0x77, 0x97, 0x8c, 0x88, 0xd5,
|
||||
0x79, 0x15, 0x13, 0x69, 0x7b, 0x45, 0xe7, 0xc0, 0x58, 0x44, 0xba, 0xa4, 0x41, 0x5a, 0x24, 0x25,
|
||||
0x43, 0x91, 0x4a, 0x6b, 0xc8, 0x13, 0xe5, 0xe4, 0x27, 0x6e, 0xcd, 0x43, 0x4a, 0x15, 0x17, 0xae,
|
||||
0x98, 0xe6, 0x7a, 0x49, 0x5c, 0x5e, 0x95, 0xb4, 0x39, 0x2d, 0xf3, 0xda, 0x21, 0x9f, 0xf2, 0xd8,
|
||||
0xba, 0x0f, 0x62, 0x28, 0xcd, 0x62, 0x1d, 0x79, 0xdb, 0xca, 0x3d, 0x57, 0xac, 0x47, 0x42, 0xb2,
|
||||
0x63, 0xfb, 0xee, 0xd6, 0xca, 0x7a, 0x32, 0x6d, 0x5b, 0x9e, 0x9e, 0x74, 0xcb, 0x5d, 0x27, 0x7d,
|
||||
0xdd, 0xbf, 0x90, 0x53, 0xb2, 0xa6, 0xde, 0x6a, 0x86, 0xe6, 0x75, 0x72, 0xe6, 0xea, 0x3e, 0x5a,
|
||||
0xae, 0xf3, 0x75, 0xf5, 0xac, 0x64, 0x7d, 0xf6, 0xb5, 0x6f, 0xa9, 0xe6, 0xd9, 0xef, 0x1a, 0xcb,
|
||||
0x5b, 0x2b, 0x38, 0x83, 0x6b, 0x32, 0x70, 0xfe, 0xac, 0xde, 0x40, 0xb1, 0x1f, 0x7b, 0x5f, 0x70,
|
||||
0x9e, 0xb6, 0x37, 0x4d, 0x51, 0x9d, 0x27, 0xe7, 0x2f, 0xc3, 0xde, 0xbc, 0x8d, 0x7b, 0xa0, 0x75,
|
||||
0x0c, 0x44, 0x5c, 0xe5, 0x64, 0x8b, 0xff, 0x19, 0x4b, 0xc0, 0xdb, 0x0a, 0x70, 0xbb, 0x00, 0xdc,
|
||||
0x5d, 0x7d, 0x7b, 0x03, 0xbe, 0x89, 0x97, 0x25, 0xe0, 0x69, 0x11, 0xf8, 0xd8, 0x9f, 0xe6, 0x7e,
|
||||
0x01, 0xbf, 0xe1, 0x18, 0x97, 0x7e, 0x04, 0x00, 0x00
|
||||
};
|
||||
#endif //__favicon_h
|
@ -31,6 +31,7 @@
|
||||
#if defined(SD_DEVICE)
|
||||
#include "../../filesystem/esp_sd.h"
|
||||
#endif //SD_DEVICE
|
||||
#include "../favicon.h"
|
||||
|
||||
#if defined(ESP3DLIB_ENV) && COMMUNICATION_PROTOCOL == SOCKET_SERIAL
|
||||
#include "../../serial2socket/serial2socket.h"
|
||||
@ -60,6 +61,11 @@ void HTTP_Server:: handle_not_found()
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (path=="favicon.ico" || path=="/favicon.ico") {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
_webserver->send_P(200,"image/x-icon",(const char *)favicon,favicon_size);
|
||||
return;
|
||||
}
|
||||
#endif //#if defined (FILESYSTEM_FEATURE)
|
||||
|
||||
#if defined (SD_DEVICE)
|
||||
|
@ -32,7 +32,15 @@
|
||||
//Root of Webserver/////////////////////////////////////////////////////
|
||||
void HTTP_Server::handle_root()
|
||||
{
|
||||
String path = "/index.html";
|
||||
String path = ESP3D_HOST_PATH;
|
||||
//Some sanity check
|
||||
if (path[0]!='/') {
|
||||
path ="/" + path;
|
||||
}
|
||||
if (path[path.length()-1]!='/') {
|
||||
path = path + "/";
|
||||
}
|
||||
path += "index.html";
|
||||
String contentType = getContentType(path.c_str());
|
||||
String pathWithGz = path + ".gz";
|
||||
//if have a index.html or gzip version this is default root page
|
||||
|
@ -99,6 +99,35 @@ void HTTP_Server::SDFileupload ()
|
||||
if (ESP_SD::exists (filename.c_str()) ) {
|
||||
ESP_SD::remove (filename.c_str());
|
||||
}
|
||||
String path = _webserver->arg ("path");
|
||||
if (path[0] != '/') {
|
||||
path = "/" + path;
|
||||
}
|
||||
if (path[path.length()-1] != '/') {
|
||||
path = path + "/";
|
||||
}
|
||||
if (_webserver->hasArg("createPath") && path.length() > 1) {
|
||||
if (_webserver->arg("createPath")== "true") {
|
||||
int pos = path.indexOf('/',1);
|
||||
while (pos != -1) {
|
||||
String currentPath = path.substring(0, pos);
|
||||
if (!ESP_SD::exists (currentPath.c_str()) ) {
|
||||
if ( !ESP_SD::mkdir (currentPath.c_str()) ) {
|
||||
pushError(ESP_ERROR_FILE_CREATION, "Failed to create path", 500);
|
||||
_upload_status=UPLOAD_STATUS_FAILED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pos+1 >= path.length()-1) {
|
||||
pos=-1;
|
||||
break;
|
||||
} else {
|
||||
pos = path.indexOf('/',pos+1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fsUploadFile.isOpen() ) {
|
||||
fsUploadFile.close();
|
||||
}
|
||||
|
@ -85,6 +85,35 @@ void HTTP_Server::FSFileupload ()
|
||||
if (ESP_FileSystem::exists (filename.c_str()) ) {
|
||||
ESP_FileSystem::remove (filename.c_str());
|
||||
}
|
||||
String path = _webserver->arg ("path");
|
||||
if (path[0] != '/') {
|
||||
path = "/" + path;
|
||||
}
|
||||
if (path[path.length()-1] != '/') {
|
||||
path = path + "/";
|
||||
}
|
||||
if (_webserver->hasArg("createPath") && path.length() > 1) {
|
||||
if (_webserver->arg("createPath")== "true") {
|
||||
int pos = path.indexOf('/',1);
|
||||
while (pos != -1) {
|
||||
String currentPath = path.substring(0, pos);
|
||||
if (!ESP_FileSystem::exists (currentPath.c_str()) ) {
|
||||
if ( !ESP_FileSystem::mkdir (currentPath.c_str()) ) {
|
||||
pushError(ESP_ERROR_FILE_CREATION, "Failed to create path", 500);
|
||||
_upload_status=UPLOAD_STATUS_FAILED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pos+1 >= path.length()-1) {
|
||||
pos=-1;
|
||||
break;
|
||||
} else {
|
||||
pos = path.indexOf('/',pos+1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fsUploadFile.isOpen() ) {
|
||||
fsUploadFile.close();
|
||||
}
|
||||
|
@ -30,10 +30,9 @@
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/commands.h"
|
||||
#include "../authentication/authentication_service.h"
|
||||
|
||||
WebSocket_Server websocket_terminal_server;
|
||||
WebSocket_Server websocket_terminal_server("webui-v3");
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
WebSocket_Server websocket_data_server;
|
||||
WebSocket_Server websocket_data_server();
|
||||
#endif //WS_DATA_FEATURE
|
||||
void WebSocket_Server::pushMSG (const char * data)
|
||||
{
|
||||
@ -79,7 +78,7 @@ void handle_Websocket_Server_Event(uint8_t num, uint8_t type, uint8_t * payload,
|
||||
log_esp3d("[%u] Disconnected! port %d", num,websocket_data_server.port());
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
log_esp3d("[%u] Connected! port %d", num,websocket_data_server.port());
|
||||
log_esp3d("[%u] Connected! port %d, %s", num,websocket_data_server.port(), payload);
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
@ -108,6 +107,7 @@ void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payloa
|
||||
log_esp3d("[%u] Socket Disconnected port %d!", num,websocket_terminal_server.port());
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
log_esp3d("[%u] Connected! port %d, %s", num,websocket_terminal_server.port(), (const char *)payload);
|
||||
msg = "currentID:" + String(num);
|
||||
// send message to client
|
||||
websocket_terminal_server.set_currentID(num);
|
||||
@ -152,22 +152,22 @@ int WebSocket_Server::availableForWrite()
|
||||
{
|
||||
return TXBUFFERSIZE -_TXbufferSize;
|
||||
}
|
||||
WebSocket_Server::WebSocket_Server()
|
||||
WebSocket_Server::WebSocket_Server(const char * protocol )
|
||||
{
|
||||
_websocket_server = nullptr;
|
||||
_started = false;
|
||||
_port = 0;
|
||||
_current_id = 0;
|
||||
_isdebug = false;
|
||||
_RXbuffer = nullptr;
|
||||
_RXbufferSize = 0;
|
||||
_protocol = protocol;
|
||||
|
||||
}
|
||||
WebSocket_Server::~WebSocket_Server()
|
||||
{
|
||||
end();
|
||||
}
|
||||
bool WebSocket_Server::begin(uint16_t port, bool debug)
|
||||
bool WebSocket_Server::begin(uint16_t port)
|
||||
{
|
||||
end();
|
||||
if(port == 0) {
|
||||
@ -178,8 +178,7 @@ bool WebSocket_Server::begin(uint16_t port, bool debug)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_isdebug = debug;
|
||||
_websocket_server = new WebSocketsServer(_port);
|
||||
_websocket_server = new WebSocketsServer(_port,"",_protocol.c_str());
|
||||
if (_websocket_server) {
|
||||
_websocket_server->begin();
|
||||
#if defined (HTTP_FEATURE) //terminal websocket for HTTP
|
||||
@ -188,7 +187,7 @@ bool WebSocket_Server::begin(uint16_t port, bool debug)
|
||||
}
|
||||
#endif //HTTP_FEATURE
|
||||
#if defined (WS_DATA_FEATURE) //terminal websocket for HTTP
|
||||
if((port != 0) && !_isdebug) {
|
||||
if((port != 0) && _protocol!="debug") {
|
||||
_websocket_server->onEvent(handle_Websocket_Server_Event);
|
||||
_RXbuffer= (uint8_t *)malloc(RXBUFFERSIZE +1);
|
||||
if (!_RXbuffer) {
|
||||
@ -207,7 +206,6 @@ void WebSocket_Server::end()
|
||||
{
|
||||
_current_id = 0;
|
||||
_TXbufferSize = 0;
|
||||
_isdebug = false;
|
||||
if(_RXbuffer) {
|
||||
free(_RXbuffer);
|
||||
_RXbuffer = nullptr;
|
||||
@ -263,9 +261,6 @@ size_t WebSocket_Server::write(const uint8_t *buffer, size_t size)
|
||||
_TXbuffer[_TXbufferSize] = buffer[i];
|
||||
_TXbufferSize++;
|
||||
}
|
||||
//if(!_isdebug) {
|
||||
// log_esp3d("[SOCKET]buffer size %d",_TXbufferSize);
|
||||
//}
|
||||
return size;
|
||||
}
|
||||
return 0;
|
||||
@ -352,9 +347,7 @@ void WebSocket_Server::flushTXbuffer(void)
|
||||
{
|
||||
if (_started) {
|
||||
if ((_TXbufferSize > 0) && (_websocket_server->connectedClients() > 0 )) {
|
||||
//if(!_isdebug) {
|
||||
// log_esp3d("[SOCKET]flush data, buffer size %d",_TXbufferSize);
|
||||
//}
|
||||
|
||||
if (_websocket_server) {
|
||||
_websocket_server->broadcastBIN(_TXbuffer,_TXbufferSize);
|
||||
log_esp3d("WS Broadcast bin port %d: %d bytes", port(), _TXbufferSize);
|
||||
|
@ -30,7 +30,7 @@ class WebSocketsServer;
|
||||
class WebSocket_Server: public Print
|
||||
{
|
||||
public:
|
||||
WebSocket_Server();
|
||||
WebSocket_Server(const char* protocol="arduino");
|
||||
~WebSocket_Server();
|
||||
size_t write(uint8_t c);
|
||||
size_t write(const uint8_t *buffer, size_t size);
|
||||
@ -55,7 +55,7 @@ public:
|
||||
{
|
||||
return write((uint8_t) n);
|
||||
}
|
||||
bool begin(uint16_t port=0, bool debug=false);
|
||||
bool begin(uint16_t port=0);
|
||||
uint16_t port()
|
||||
{
|
||||
return _port;
|
||||
@ -77,14 +77,21 @@ public:
|
||||
return _started;
|
||||
}
|
||||
void push2RXbuffer(uint8_t * sbuf, size_t len);
|
||||
const char * getProtocol()
|
||||
{
|
||||
return _protocol.c_str();
|
||||
}
|
||||
uint16_t getPort()
|
||||
{
|
||||
return _port;
|
||||
}
|
||||
private:
|
||||
bool _started;
|
||||
uint16_t _port;
|
||||
bool _isdebug;
|
||||
bool _isdata;
|
||||
uint32_t _lastTXflush;
|
||||
uint32_t _lastRXflush;
|
||||
WebSocketsServer * _websocket_server;
|
||||
String _protocol;
|
||||
uint8_t _TXbuffer[TXBUFFERSIZE];
|
||||
uint16_t _TXbufferSize;
|
||||
uint8_t _current_id;
|
||||
|
@ -42,7 +42,7 @@ extern "C" {
|
||||
#include <esp_system.h>
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include <esp32/sha.h>
|
||||
#include <sha/sha_parallel_engine.h>
|
||||
#else
|
||||
#include <hwcrypto/sha.h>
|
||||
#endif
|
||||
@ -62,7 +62,8 @@ extern "C" {
|
||||
* @param reason ptr to the disconnect reason message
|
||||
* @param reasonLen length of the disconnect reason message
|
||||
*/
|
||||
void WebSockets::clientDisconnect(WSclient_t * client, uint16_t code, char * reason, size_t reasonLen) {
|
||||
void WebSockets::clientDisconnect(WSclient_t * client, uint16_t code, char * reason, size_t reasonLen)
|
||||
{
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] clientDisconnect code: %u\n", client->num, code);
|
||||
if(client->status == WSC_CONNECTED && code) {
|
||||
if(reason) {
|
||||
@ -86,7 +87,8 @@ void WebSockets::clientDisconnect(WSclient_t * client, uint16_t code, char * rea
|
||||
* @param maskkey uint8_t[4] key used for payload
|
||||
* @param fin bool can be used to send data in more then one frame (set fin on the last frame)
|
||||
*/
|
||||
uint8_t WebSockets::createHeader(uint8_t * headerPtr, WSopcode_t opcode, size_t length, bool mask, uint8_t maskKey[4], bool fin) {
|
||||
uint8_t WebSockets::createHeader(uint8_t * headerPtr, WSopcode_t opcode, size_t length, bool mask, uint8_t maskKey[4], bool fin)
|
||||
{
|
||||
uint8_t headerSize;
|
||||
// calculate header Size
|
||||
if(length < 126) {
|
||||
@ -170,7 +172,8 @@ uint8_t WebSockets::createHeader(uint8_t * headerPtr, WSopcode_t opcode, size_t
|
||||
* @param fin bool can be used to send data in more then one frame (set fin on the last frame)
|
||||
* @return true if ok
|
||||
*/
|
||||
bool WebSockets::sendFrameHeader(WSclient_t * client, WSopcode_t opcode, size_t length, bool fin) {
|
||||
bool WebSockets::sendFrameHeader(WSclient_t * client, WSopcode_t opcode, size_t length, bool fin)
|
||||
{
|
||||
uint8_t maskKey[4] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t buffer[WEBSOCKETS_MAX_HEADER_SIZE] = { 0 };
|
||||
|
||||
@ -193,7 +196,8 @@ bool WebSockets::sendFrameHeader(WSclient_t * client, WSopcode_t opcode, size_t
|
||||
* @param headerToPayload bool set true if the payload has reserved 14 Byte at the beginning to dynamically add the Header (payload neet to be in RAM!)
|
||||
* @return true if ok
|
||||
*/
|
||||
bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin, bool headerToPayload) {
|
||||
bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin, bool headerToPayload)
|
||||
{
|
||||
if(client->tcp && !client->tcp->connected()) {
|
||||
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] not Connected!?\n", client->num);
|
||||
return false;
|
||||
@ -320,7 +324,8 @@ bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * pay
|
||||
* callen when HTTP header is done
|
||||
* @param client WSclient_t * ptr to the client struct
|
||||
*/
|
||||
void WebSockets::headerDone(WSclient_t * client) {
|
||||
void WebSockets::headerDone(WSclient_t * client)
|
||||
{
|
||||
client->status = WSC_CONNECTED;
|
||||
client->cWsRXsize = 0;
|
||||
DEBUG_WEBSOCKETS("[WS][%d][headerDone] Header Handling Done.\n", client->num);
|
||||
@ -334,7 +339,8 @@ void WebSockets::headerDone(WSclient_t * client) {
|
||||
* handle the WebSocket stream
|
||||
* @param client WSclient_t * ptr to the client struct
|
||||
*/
|
||||
void WebSockets::handleWebsocket(WSclient_t * client) {
|
||||
void WebSockets::handleWebsocket(WSclient_t * client)
|
||||
{
|
||||
if(client->cWsRXsize == 0) {
|
||||
handleWebsocketCb(client);
|
||||
}
|
||||
@ -345,7 +351,8 @@ void WebSockets::handleWebsocket(WSclient_t * client) {
|
||||
* @param client
|
||||
* @param size
|
||||
*/
|
||||
bool WebSockets::handleWebsocketWaitFor(WSclient_t * client, size_t size) {
|
||||
bool WebSockets::handleWebsocketWaitFor(WSclient_t * client, size_t size)
|
||||
{
|
||||
if(!client->tcp || !client->tcp->connected()) {
|
||||
return false;
|
||||
}
|
||||
@ -372,11 +379,12 @@ bool WebSockets::handleWebsocketWaitFor(WSclient_t * client, size_t size) {
|
||||
server->clientDisconnect(client, 1002);
|
||||
}
|
||||
},
|
||||
this, size, std::placeholders::_1, std::placeholders::_2));
|
||||
this, size, std::placeholders::_1, std::placeholders::_2));
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebSockets::handleWebsocketCb(WSclient_t * client) {
|
||||
void WebSockets::handleWebsocketCb(WSclient_t * client)
|
||||
{
|
||||
if(!client->tcp || !client->tcp->connected()) {
|
||||
return;
|
||||
}
|
||||
@ -461,7 +469,8 @@ void WebSockets::handleWebsocketCb(WSclient_t * client) {
|
||||
}
|
||||
}
|
||||
|
||||
void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t * payload) {
|
||||
void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t * payload)
|
||||
{
|
||||
WSMessageHeader_t * header = &client->cWsHeaderDecode;
|
||||
if(ok) {
|
||||
if(header->payloadLen > 0) {
|
||||
@ -476,43 +485,44 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
|
||||
}
|
||||
|
||||
switch(header->opCode) {
|
||||
case WSop_text:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] text: %s\n", client->num, payload);
|
||||
// no break here!
|
||||
case WSop_binary:
|
||||
case WSop_continuation:
|
||||
messageReceived(client, header->opCode, payload, header->payloadLen, header->fin);
|
||||
break;
|
||||
case WSop_ping:
|
||||
// send pong back
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] ping received (%s)\n", client->num, payload ? (const char *)payload : "");
|
||||
sendFrame(client, WSop_pong, payload, header->payloadLen);
|
||||
messageReceived(client, header->opCode, payload, header->payloadLen, header->fin);
|
||||
break;
|
||||
case WSop_pong:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get pong (%s)\n", client->num, payload ? (const char *)payload : "");
|
||||
client->pongReceived = true;
|
||||
messageReceived(client, header->opCode, payload, header->payloadLen, header->fin);
|
||||
break;
|
||||
case WSop_close: {
|
||||
case WSop_text:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] text: %s\n", client->num, payload);
|
||||
// no break here!
|
||||
case WSop_binary:
|
||||
case WSop_continuation:
|
||||
messageReceived(client, header->opCode, payload, header->payloadLen, header->fin);
|
||||
break;
|
||||
case WSop_ping:
|
||||
// send pong back
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] ping received (%s)\n", client->num, payload ? (const char *)payload : "");
|
||||
sendFrame(client, WSop_pong, payload, header->payloadLen);
|
||||
messageReceived(client, header->opCode, payload, header->payloadLen, header->fin);
|
||||
break;
|
||||
case WSop_pong:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get pong (%s)\n", client->num, payload ? (const char *)payload : "");
|
||||
client->pongReceived = true;
|
||||
messageReceived(client, header->opCode, payload, header->payloadLen, header->fin);
|
||||
break;
|
||||
case WSop_close: {
|
||||
#ifndef NODEBUG_WEBSOCKETS
|
||||
uint16_t reasonCode = 1000;
|
||||
if(header->payloadLen >= 2) {
|
||||
reasonCode = payload[0] << 8 | payload[1];
|
||||
}
|
||||
uint16_t reasonCode = 1000;
|
||||
if(header->payloadLen >= 2) {
|
||||
reasonCode = payload[0] << 8 | payload[1];
|
||||
}
|
||||
#endif
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d\n", client->num, reasonCode);
|
||||
if(header->payloadLen > 2) {
|
||||
DEBUG_WEBSOCKETS(" (%s)\n", (payload + 2));
|
||||
} else {
|
||||
DEBUG_WEBSOCKETS("\n");
|
||||
}
|
||||
clientDisconnect(client, 1000);
|
||||
} break;
|
||||
default:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] got unknown opcode: %d\n", client->num, header->opCode);
|
||||
clientDisconnect(client, 1002);
|
||||
break;
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d\n", client->num, reasonCode);
|
||||
if(header->payloadLen > 2) {
|
||||
DEBUG_WEBSOCKETS(" (%s)\n", (payload + 2));
|
||||
} else {
|
||||
DEBUG_WEBSOCKETS("\n");
|
||||
}
|
||||
clientDisconnect(client, 1000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] got unknown opcode: %d\n", client->num, header->opCode);
|
||||
clientDisconnect(client, 1002);
|
||||
break;
|
||||
}
|
||||
|
||||
if(payload) {
|
||||
@ -538,7 +548,8 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
|
||||
* @param clientKey String
|
||||
* @return String Accept Key
|
||||
*/
|
||||
String WebSockets::acceptKey(String & clientKey) {
|
||||
String WebSockets::acceptKey(String & clientKey)
|
||||
{
|
||||
uint8_t sha1HashBin[20] = { 0 };
|
||||
#ifdef ESP8266
|
||||
sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]);
|
||||
@ -565,7 +576,8 @@ String WebSockets::acceptKey(String & clientKey) {
|
||||
* @param length size_t
|
||||
* @return base64 encoded String
|
||||
*/
|
||||
String WebSockets::base64_encode(uint8_t * data, size_t length) {
|
||||
String WebSockets::base64_encode(uint8_t * data, size_t length)
|
||||
{
|
||||
size_t size = ((length * 1.6f) + 1);
|
||||
char * buffer = (char *)malloc(size);
|
||||
if(buffer) {
|
||||
@ -588,7 +600,8 @@ String WebSockets::base64_encode(uint8_t * data, size_t length) {
|
||||
* @param n size_t byte count
|
||||
* @return true if ok
|
||||
*/
|
||||
bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWaitCb cb) {
|
||||
bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWaitCb cb)
|
||||
{
|
||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||
if(!client->tcp || !client->tcp->connected()) {
|
||||
return false;
|
||||
@ -599,7 +612,7 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait
|
||||
cb(client, ok);
|
||||
}
|
||||
},
|
||||
client, std::placeholders::_1, cb));
|
||||
client, std::placeholders::_1, cb));
|
||||
|
||||
#else
|
||||
unsigned long t = millis();
|
||||
@ -663,11 +676,14 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait
|
||||
* @param n size_t byte count
|
||||
* @return bytes send
|
||||
*/
|
||||
size_t WebSockets::write(WSclient_t * client, uint8_t * out, size_t n) {
|
||||
if(out == NULL)
|
||||
size_t WebSockets::write(WSclient_t * client, uint8_t * out, size_t n)
|
||||
{
|
||||
if(out == NULL) {
|
||||
return 0;
|
||||
if(client == NULL)
|
||||
}
|
||||
if(client == NULL) {
|
||||
return 0;
|
||||
}
|
||||
unsigned long t = millis();
|
||||
size_t len = 0;
|
||||
size_t total = 0;
|
||||
@ -706,11 +722,14 @@ size_t WebSockets::write(WSclient_t * client, uint8_t * out, size_t n) {
|
||||
return total;
|
||||
}
|
||||
|
||||
size_t WebSockets::write(WSclient_t * client, const char * out) {
|
||||
if(client == NULL)
|
||||
size_t WebSockets::write(WSclient_t * client, const char * out)
|
||||
{
|
||||
if(client == NULL) {
|
||||
return 0;
|
||||
if(out == NULL)
|
||||
}
|
||||
if(out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return write(client, (uint8_t *)out, strlen(out));
|
||||
}
|
||||
|
||||
@ -721,9 +740,11 @@ size_t WebSockets::write(WSclient_t * client, const char * out) {
|
||||
* @param pongTimeout uint32_t millis after which pong should timout if not received
|
||||
* @param disconnectTimeoutCount uint8_t how many timeouts before disconnect, 0=> do not disconnect
|
||||
*/
|
||||
void WebSockets::enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount) {
|
||||
if(client == NULL)
|
||||
void WebSockets::enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount)
|
||||
{
|
||||
if(client == NULL) {
|
||||
return;
|
||||
}
|
||||
client->pingInterval = pingInterval;
|
||||
client->pongTimeout = pongTimeout;
|
||||
client->disconnectTimeoutCount = disconnectTimeoutCount;
|
||||
@ -734,7 +755,8 @@ void WebSockets::enableHeartbeat(WSclient_t * client, uint32_t pingInterval, uin
|
||||
* handle ping/pong heartbeat timeout process
|
||||
* @param client WSclient_t *
|
||||
*/
|
||||
void WebSockets::handleHBTimeout(WSclient_t * client) {
|
||||
void WebSockets::handleHBTimeout(WSclient_t * client)
|
||||
{
|
||||
if(client->pingInterval) { // if heartbeat is enabled
|
||||
uint32_t pi = millis() - client->lastPing;
|
||||
|
||||
|
@ -17,7 +17,7 @@ data_dir = esp3d/data
|
||||
default_envs = esp32dev
|
||||
|
||||
[env:esp32dev]
|
||||
platform = espressif32@5.0.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
@ -38,7 +38,7 @@ upload_speed = 460800
|
||||
extra_scripts = pre:platformIO/extra_script.py
|
||||
|
||||
[env:esp32cam]
|
||||
platform = espressif32@4.4.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
@ -62,7 +62,7 @@ extra_scripts = pre:platformIO/extra_script.py
|
||||
|
||||
;TTGO_T_Display with ST7789
|
||||
[env:esp32-TTGO_T_Display]
|
||||
platform = espressif32@4.4.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
@ -109,7 +109,7 @@ extra_scripts = pre:platformIO/extra_script.py
|
||||
|
||||
;TTGO_T_Display with ST7789
|
||||
[env:esp32-ST7789]
|
||||
platform = espressif32@4.4.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
@ -155,7 +155,7 @@ upload_speed = 460800
|
||||
extra_scripts = pre:platformIO/extra_script.py
|
||||
|
||||
[env:esp32-s2]
|
||||
platform = espressif32@4.4.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32-s2-saola-1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
@ -179,7 +179,7 @@ lib_ignore =
|
||||
;https://github.com/Bodmer/TFT_eSPI/issues/1246
|
||||
|
||||
[env:esp32-s3]
|
||||
platform = espressif32@4.4.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32-s3-devkitc-1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
@ -200,7 +200,7 @@ board_build.partitions = min_spiffs.csv
|
||||
upload_speed = 460800
|
||||
|
||||
[env:esp32-c3]
|
||||
platform = espressif32@4.4.0
|
||||
platform = espressif32@5.1.0
|
||||
board = esp32-c3-devkitm-1
|
||||
board_build.mcu = esp32c3
|
||||
board_build.variant = esp32c3
|
||||
|
Loading…
x
Reference in New Issue
Block a user