Web dav rewrite/Time refactoring (#960)

* Time refactoring 
* Webdav rewrite 
Base on work done on ESP3D-TFT
This commit is contained in:
Luc
2023-11-05 21:27:28 +08:00
committed by GitHub
parent 3ffb7c3b4c
commit 963147a541
128 changed files with 11654 additions and 9744 deletions

View File

@@ -7,7 +7,7 @@ shopt -s globstar
cd $HOME/arduino_ide/hardware
mkdir esp8266com
cd esp8266com
git clone -b 3.0.2 https://github.com/esp8266/Arduino.git esp8266
git clone -b 3.1.1 https://github.com/esp8266/Arduino.git esp8266
cd esp8266
git submodule update --init
cd tools

View File

@@ -74,7 +74,7 @@ The json format is
`[ESP131]<port> json=<no> pwd=<admin password>`
* Sync / Set / Get current time
`[ESP140]<SYNC> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <zone=xxx> <dst=YES/NO> <time=YYYY-MM-DDTHH:mm:ss> <NOW> json=<no> pwd=<admin password>`
`[ESP140]<SYNC> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <tzone=+HH:SS> <time=YYYY-MM-DDTHH:mm:ss> <ntp=yes/no> <NOW> json=<no> pwd=<admin password>`
* Get/Set display/set boot delay in ms / Verbose boot
`[ESP150]<delay=time in milliseconds><verbose=ON/OFF>pwd=<admin password>`
@@ -183,7 +183,7 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
ESP_NOTIFICATION_TOKEN2 396 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
ESP_SENSOR_TYPE 460 //1 bytes = flag
ESP_TARGET_FW 461 //1 bytes = flag
ESP_TIMEZONE 462 //1 bytes = flag
ESP_FREE 462 //1 bytes = flag
ESP_TIME_IS_DST 463 //1 bytes = flag
ESP_TIME_SERVER1 464 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
ESP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
@@ -216,6 +216,7 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
ESP_SERIAL_BRIDGE_ON 1036 //1 byte = flag
ESP_SERIAL_BRIDGE_FLAG 1037 //1 byte = flag
ESP_SERIAL_BRIDGE_BAUD 1038 //4 bytes= int
ESP_TIME_ZONE 1042 //7 bytes= string
```
* Get/Set Check update at boot state which can be ON, OFF
@@ -287,7 +288,7 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
`[ESP790]<Action>=<path> json=<no> pwd=<admin password>`
* FW Informations
`[ESP800]json=<no> pwd=<admin password> <time=YYYY-MM-DDTHH:mm:ss> <version=3.0.0-a11> <setup=0/1>`
`[ESP800]json=<no> pwd=<admin password> <time=YYYY-MM-DDTHH:mm:ss> <tz=+HH:SS> <version=3.0.0-a11> <setup=0/1>`
* Get state / Set Enable / Disable Serial Communication
`[ESP900]<ENABLE/DISABLE> json=<no> pwd=<admin/user password>`

View File

@@ -119,8 +119,8 @@ Time_server1 = 1.pool.ntp.org
Time_server2 = 2.pool.ntp.org
Time_server3 = 3.pool.ntp.org
#time zone -12~12
Time_zone = 2
#time zone -12~14
Time_zone = +00:00
#is DST Yes/No
Time_DST = No

1683
docs/espXXX.md Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@@ -250,7 +250,7 @@
/* Enable date/time on files
* Set date/time on files using SNTP or last webui connection
*/
// #define FILESYSTEM_TIMESTAMP_FEATURE
#define FILESYSTEM_TIMESTAMP_FEATURE
/************************************
*

View File

@@ -0,0 +1,150 @@
/*
esp3d_string.cpp - esp3d strings helpers
Copyright (c) 2023 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
*/
#include "esp3d_string.h"
#include <Arduino.h>
#include "../include/esp3d_config.h"
#if defined(TIMESTAMP_FEATURE)
#include "../modules/time/time_service.h"
#endif // TIMESTAMP_FEATURE
const char* esp3d_string::getTimeString(time_t time, bool isGMT) {
static char buffer[40];
memset(buffer, 0, sizeof(buffer));
struct tm* tm_info;
struct tm tmstruct;
if (isGMT) {
// convert to GMT time
tm_info = gmtime_r(&time, &tmstruct);
strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S GMT", tm_info);
} else {
// convert to local time
tm_info = localtime_r(&time, &tmstruct);
strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", tm_info);
}
if (!isGMT) {
#if defined(TIMESTAMP_FEATURE)
// if time zone is set add it
strcat(buffer, timeService.getTimeZone());
#else
// add Z to indicate UTC time because no time zone is set
strcat(buffer, "Z");
#endif // TIMESTAMP_FEATURE
}
return buffer;
}
// Update hash function used by generateUUID
void update_hash(uint8_t* data, size_t len, uint8_t* hash_buffer,
uint8_t hash_size) {
static bool reverse = false;
reverse = !reverse;
int start_index = reverse ? hash_size : 0;
for (int i = 0; i < hash_size; i++) {
int idx =
reverse ? (start_index - i) % hash_size : (start_index + i) % hash_size;
if (i >= len) {
hash_buffer[idx] ^= random(1, 254);
} else {
hash_buffer[idx] ^= data[i];
}
}
}
const char* esp3d_string::generateUUID(const char* seed) {
static String token;
String tmp;
uint8_t hash_buffer[16];
memset(hash_buffer, 0, 16);
if (!seed) {
tmp = "ESP3D ecosystem";
} else {
tmp = seed;
}
// init random seed
randomSeed(time(NULL));
// Use seed
update_hash((uint8_t*)tmp.c_str(), tmp.length(), hash_buffer, 16);
// use epoch time
uint64_t millisec = millis();
update_hash((uint8_t*)&millisec, sizeof(millisec), hash_buffer, 16);
// use current time
time_t now;
time(&now);
update_hash((uint8_t*)&now, sizeof(now), hash_buffer, 16);
tmp = "";
// now hash all the buffer
for (int i = 0; i < 16; i++) {
char hex[3];
sprintf(hex, "%02x", hash_buffer[i]);
tmp += hex;
}
// format the uuid on 36 chars
token = tmp.substring(0, 7) + "-";
token += tmp.substring(8, 8 + 3) + "-";
token += tmp.substring(12, 12 + 3) + "-";
token += tmp.substring(16, 16 + 3) + "-";
token += &tmp[20];
return token.c_str();
}
const char* esp3d_string::getContentType(const char* filename) {
String file_name = filename;
file_name.toLowerCase();
if (file_name.endsWith(".htm")) {
return "text/html";
} else if (file_name.endsWith(".html")) {
return "text/html";
} else if (file_name.endsWith(".css")) {
return "text/css";
} else if (file_name.endsWith(".js")) {
return "application/javascript";
} else if (file_name.endsWith(".png")) {
return "image/png";
} else if (file_name.endsWith(".gif")) {
return "image/gif";
} else if (file_name.endsWith(".jpeg")) {
return "image/jpeg";
} else if (file_name.endsWith(".jpg")) {
return "image/jpeg";
} else if (file_name.endsWith(".ico")) {
return "image/x-icon";
} else if (file_name.endsWith(".xml")) {
return "text/xml";
} else if (file_name.endsWith(".pdf")) {
return "application/x-pdf";
} else if (file_name.endsWith(".zip")) {
return "application/x-zip";
} else if (file_name.endsWith(".gz")) {
return "application/x-gzip";
} else if (file_name.endsWith(".txt") || file_name.endsWith(".gcode") ||
file_name.endsWith(".gco") || file_name.endsWith(".g")) {
return "text/plain";
}
return "application/octet-stream";
}

View File

@@ -1,7 +1,7 @@
/*
time_server.h - time server functions class
esp3d_string.h - esp3d strings helpers
Copyright (c) 2014 Luc Lebosse. All rights reserved.
Copyright (c) 2023 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
@@ -18,31 +18,13 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _TIME_SERVER_H
#define _TIME_SERVER_H
#ifndef _ESP3D_STRING_H
#define _ESP3D_STRING_H
#include <time.h>
namespace esp3d_string {
const char* getTimeString(time_t time, bool isGMT);
const char* generateUUID(const char* seed);
const char* getContentType(const char* filename);
} // namespace esp3d_string
class TimeServer
{
public:
TimeServer();
~TimeServer();
bool begin();
void end();
void handle();
const char * current_time(time_t t = 0);
bool setTime(const char* stime);
bool started();
bool is_internet_time(bool readfromsettings = false);
private:
bool _started;
bool _is_internet_time;
};
extern TimeServer timeserver;
#endif //_TIME_SERVER_H
#endif //_ESP3D_STRING_H

View File

@@ -70,6 +70,7 @@ uint8_t ESP3DOutput::_BToutputflags = DEFAULT_BT_FLAG;
uint8_t ESP3DOutput::_serialBridgeoutputflags = DEFAULT_SERIAL_BRIDGE_FLAG;
#endif // ESP_SERIAL_BRIDGE_OUTPUT
#if defined(HTTP_FEATURE)
#include "../modules/http/http_server.h"
#if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif // ARDUINO_ARCH_ESP32
@@ -453,6 +454,7 @@ size_t ESP3DOutput::printMSGLine(const char *s) {
_webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
_webserver->sendHeader("Content-Type", "text/html");
_webserver->sendHeader("Cache-Control", "no-cache");
HTTP_Server::set_http_headers();
_webserver->send(_code);
_headerSent = true;
}
@@ -529,6 +531,7 @@ size_t ESP3DOutput::printMSG(const char *s, bool withNL) {
if (_webserver) {
if (!_headerSent && !_footerSent) {
_webserver->sendHeader("Cache-Control", "no-cache");
HTTP_Server::set_http_headers();
#ifdef ESP_ACCESS_CONTROL_ALLOW_ORIGIN
_webserver->sendHeader("Access-Control-Allow-Origin", "*");
#endif // ESP_ACCESS_CONTROL_ALLOw_ORIGIN
@@ -606,6 +609,7 @@ size_t ESP3DOutput::printERROR(const char *s, int code_error) {
if (_webserver) {
if (!_headerSent && !_footerSent) {
_webserver->sendHeader("Cache-Control", "no-cache");
HTTP_Server::set_http_headers();
if (s[0] != '{') {
display = "error: ";
} else {
@@ -750,6 +754,7 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size) {
_webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
_webserver->sendHeader("Content-Type", "text/html");
_webserver->sendHeader("Cache-Control", "no-cache");
HTTP_Server::set_http_headers();
_webserver->send(_code);
_headerSent = true;
}

View File

@@ -21,7 +21,8 @@
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
const char * help[]= {"[ESP] (id) - display this help",
const char* help[] = {
"[ESP] (id) - display this help",
#if defined(WIFI_FEATURE)
"[ESP100](SSID) - display/set STA SSID",
"[ESP101](Password) - set STA password",
@@ -31,7 +32,8 @@ const char * help[]= {"[ESP] (id) - display this help",
"[ESP103](IP=xxxx MSK=xxxx GW=xxxx) - display/set STA IP/Mask/GW",
#endif // WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
"[ESP104](State) - display/set sta fallback mode which can be BT, SETUP, OFF",
"[ESP104](State) - display/set sta fallback mode which can be BT, SETUP, "
"OFF",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE)
"[ESP105](SSID) - display/set AP SSID",
@@ -40,7 +42,8 @@ const char * help[]= {"[ESP] (id) - display this help",
"[ESP108](Chanel) - display/set AP chanel",
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
"[ESP110](State) - display/set radio state which can be BT, WIFI-STA, WIFI-AP, WIFI-SETUP, ETH-STA, OFF",
"[ESP110](State) - display/set radio state which can be BT, WIFI-STA, "
"WIFI-AP, WIFI-SETUP, ETH-STA, OFF",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
"[ESP111](header)display current IP",
@@ -48,7 +51,8 @@ const char * help[]= {"[ESP] (id) - display this help",
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
"[ESP112](Hostname) - display/set Hostname",
"[ESP114](State) - display/set boot Network state which can be ON, OFF",
"[ESP115](State) - display/set immediate Network state which can be ON, OFF",
"[ESP115](State) - display/set immediate Network state which can be ON, "
"OFF",
#endif // WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)
"[ESP120](State) - display/set HTTP state which can be ON, OFF",
@@ -59,16 +63,20 @@ const char * help[]= {"[ESP] (id) - display this help",
"[ESP131](Port) - display/set Telnet port",
#endif // TELNET_FEATURE
#if defined(TIMESTAMP_FEATURE)
"[ESP140](SYNC) (srv1=xxxx) (srv2=xxxx) (srv3=xxxx) (zone=xxx) (dst=YES/NO) (time=YYYY-MM-DDTHH:mm:ss) (SYNC) (NOW)- sync/display/set current time/time servers",
"[ESP140](SYNC) (srv1=xxxx) (srv2=xxxx) (srv3=xxxx) (tzone=xxx) "
"(time=YYYY-MM-DDTHH:mm:ss)(ntp=YES/NO) (SYNC) (NOW)- sync/display/set "
"current time/time servers",
#endif // TIMESTAMP_FEATURE
"[ESP150](delay=time) (verbose=ON/OFF)- display/set boot delay in ms / Verbose boot",
"[ESP150](delay=time) (verbose=ON/OFF)- display/set boot delay in ms / "
"Verbose boot",
#if defined(WS_DATA_FEATURE)
"[ESP160](State) - display/set WebSocket state which can be ON, OFF, CLOSE",
"[ESP161](Port) - display/set WebSocket port",
#endif // WS_DATA_FEATURE
#if defined(CAMERA_DEVICE)
"[ESP170](json) (label=value) - display/set Camera commands",
"[ESP171] (path=<target path>) (filename=<target filename>) Save frame to target path and filename",
"[ESP171] (path=<target path>) (filename=<target filename>) Save frame to "
"target path and filename",
#endif // CAMERA_DEVICE
#if defined(FTP_FEATURE)
"[ESP180](State) - display/set FTP state which can be ON, OFF",
@@ -82,15 +90,18 @@ const char * help[]= {"[ESP] (id) - display this help",
"[ESP200] (json) (RELEASE) (REFRESH)- display/set SD Card Status",
#endif // SD_DEVICE
#ifdef DIRECT_PIN_FEATURE
"[ESP201](P=xxx) (V=xxx) (PULLUP=YES RAW=YES ANALOG=NO ANALOG_RANGE=255) - read / set pin value",
"[ESP201](P=xxx) (V=xxx) (PULLUP=YES RAW=YES ANALOG=NO ANALOG_RANGE=255) - "
"read / set pin value",
#endif // DIRECT_PIN_FEATURE
#if defined(SD_DEVICE)
#if SD_DEVICE != ESP_SDIO
"[ESP202] SPEED=(factor) - display / set SD Card SD card Speed factor (1 2 4 6 8 16 32)",
"[ESP202] SPEED=(factor) - display / set SD Card SD card Speed factor (1 "
"2 4 6 8 16 32)",
#endif // SD_DEVICE != ESP_SDIO
#endif // SD_DEVICE
#ifdef SENSOR_DEVICE
"[ESP210](type=NONE/xxx) (interval=xxxx) - display and read/set SENSOR info",
"[ESP210](type=NONE/xxx) (interval=xxxx) - display and read/set SENSOR "
"info",
#endif // SENSOR_DEVICE
#if defined(DISPLAY_DEVICE)
"[ESP214](text) - display (text) to ESP screen status",
@@ -106,7 +117,8 @@ const char * help[]= {"[ESP] (id) - display this help",
"[ESP400] - display ESP3D settings in JSON",
"[ESP401]P=(position) T=(type) V=(value) - Set specific setting",
#ifdef SD_UPDATE_FEATURE
"[ESP402](State) - display/set check update at boot from SD which can be ON, OFF",
"[ESP402](State) - display/set check update at boot from SD which can be "
"ON, OFF",
#endif // SD_UPDATE_FEATURE
#if defined(WIFI_FEATURE)
"[ESP410]display available AP list (limited to 30) in plain/JSON",
@@ -122,7 +134,8 @@ const char * help[]= {"[ESP] (id) - display this help",
#endif // AUTHENTICATION_FEATURE
#if defined(NOTIFICATION_FEATURE)
"[ESP600](message) - send notification",
"[ESP610]type=(NONE/PUSHOVER/EMAIL/LINE/TELEGRAM/IFTTT) (T1=xxx) (T2=xxx) (TS=xxx) - display/set Notification settings",
"[ESP610]type=(NONE/PUSHOVER/EMAIL/LINE/TELEGRAM/IFTTT) (T1=xxx) (T2=xxx) "
"(TS=xxx) - display/set Notification settings",
"[ESP620]URL=http://XXXXXX - send GET notification",
#endif // NOTIFICATION_FEATURE
#if defined(GCODE_HOST_FEATURE)
@@ -137,17 +150,21 @@ const char * help[]= {"[ESP] (id) - display this help",
#endif // SD_DEVICE
#if defined(FILESYSTEM_FEATURE)
"[ESP720](path) - List ESP Filesystem",
"[ESP730](Action)=(path) - rmdir / remove / mkdir / exists / create on ESP FileSystem (path)",
"[ESP730](Action)=(path) - rmdir / remove / mkdir / exists / create on ESP "
"FileSystem (path)",
#endif // FILESYSTEM_FEATURE
#if defined(SD_DEVICE)
"[ESP740](path) - List SD Filesystem",
"[ESP750](Action)=(path) - rmdir / remove / mkdir / exists / create on SD (path)",
"[ESP750](Action)=(path) - rmdir / remove / mkdir / exists / create on SD "
"(path)",
#endif // SD_DEVICE
#if defined(GLOBAL_FILESYSTEM_FEATURE)
"[ESP780](path) - List Global Filesystem",
"[ESP790](Action)=(path) - rmdir / remove / mkdir / exists / create on Global Filesystem (path)",
"[ESP790](Action)=(path) - rmdir / remove / mkdir / exists / create on "
"Global Filesystem (path)",
#endif // GLOBAL_FILESYSTEM_FEATURE
"[ESP800](time=YYYY-MM-DDTHH:mm:ss)(version=3.0.0-a11)(setup=0/1) - display FW Informations /set time",
"[ESP800](time=YYYY-MM-DDTHH:mm:ss)(version=3.0.0-a11)(setup=0/1) - "
"display FW Informations /set time",
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL
"[ESP900](ENABLE/DISABLE) - display/set serial state",
"[ESP901]<BAUD RATE> - display/set serial baud rate",
@@ -155,33 +172,30 @@ const char * help[]= {"[ESP] (id) - display this help",
#ifdef BUZZER_DEVICE
"[ESP910](ENABLE/DISABLE) - display/set buzzer state",
#endif // BUZZER_DEVICE
"[ESP920](client)=(ON/OFF) - display/set SERIAL / SCREEN / REMOTE_SCREEN / WEBSOCKET / TELNET /BT / ALL client state if available",
"[ESP920](client)=(ON/OFF) - display/set SERIAL / SCREEN / REMOTE_SCREEN / "
"WEBSOCKET / TELNET /BT / ALL client state if available",
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
"[ESP930](ON/OFF/CLOSE) - display/set serial bridge state",
"[ESP931]<BAUD RATE> - display/set serial bridge baud rate",
#endif // defined(ESP_SERIAL_BRIDGE_OUTPUT)
#if defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
#if defined(ARDUINO_ARCH_ESP32) && \
(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || \
CONFIG_IDF_TARGET_ESP32C3)
"[ESP999](QUIETBOOT) [pwd=<admin/user password>] - set quiet boot mode",
#endif // ARDUINO_ARCH_ESP32
""
};
""};
const uint cmdlist[] = {0,
#if defined(WIFI_FEATURE)
100,
101,
100, 101,
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
102,
103,
102, 103,
#endif // WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
104,
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE)
105,
106,
107,
108,
105, 106, 107, 108,
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
110,
@@ -190,37 +204,29 @@ const uint cmdlist[]= {0,
111,
#endif // WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
112,
114,
115,
112, 114, 115,
#endif // WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)
120,
121,
120, 121,
#endif // HTTP_FEATURE
#if defined(TELNET_FEATURE)
130,
131,
130, 131,
#endif // TELNET_FEATURE
#if defined(TIMESTAMP_FEATURE)
140,
#endif // TIMESTAMP_FEATURE
150,
#if defined(WS_DATA_FEATURE)
160,
161,
160, 161,
#endif // WS_DATA_FEATURE
#if defined(CAMERA_DEVICE)
170,
171,
170, 171,
#endif // CAMERA_DEVICE
#if defined(FTP_FEATURE)
180,
181,
180, 181,
#endif // FTP_FEATURE
#if defined(WEBDAV_FEATURE)
190,
191,
190, 191,
#endif // WEBDAV_FEATURE
#if defined(SD_DEVICE)
200,
@@ -244,29 +250,22 @@ const uint cmdlist[]= {0,
#ifdef BUZZER_DEVICE
250,
#endif // BUZZER_DEVICE
290,
400,
401,
290, 400, 401,
#if defined(WIFI_FEATURE)
410,
#endif // WIFI_FEATURE
420,
444,
420, 444,
#ifdef MDNS_FEATURE
450,
#endif // MDNS_FEATURE
#if defined(AUTHENTICATION_FEATURE)
550,
555,
550, 555,
#endif // AUTHENTICATION_FEATURE
#if defined(NOTIFICATION_FEATURE)
600,
610,
620,
600, 610, 620,
#endif // NOTIFICATION_FEATURE
#if defined(GCODE_HOST_FEATURE)
700,
701,
700, 701,
#endif // GCODE_HOST_FEATURE
#if defined(FILESYSTEM_FEATURE)
710,
@@ -275,21 +274,17 @@ const uint cmdlist[]= {0,
715,
#endif // SD_DEVICE
#if defined(FILESYSTEM_FEATURE)
720,
730,
720, 730,
#endif // FILESYSTEM_FEATURE
#if defined(SD_DEVICE)
740,
750,
740, 750,
#endif // SD_DEVICE
#if defined(GLOBAL_FILESYSTEM_FEATURE)
780,
790,
780, 790,
#endif // GLOBAL_FILESYSTEM_FEATURE
800,
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL
900,
901,
900, 901,
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
#ifdef BUZZER_DEVICE
910,
@@ -297,20 +292,20 @@ const uint cmdlist[]= {0,
#endif // BUZZER_DEVICE
920,
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
930,
935,
930, 935,
#endif // defined(ESP_SERIAL_BRIDGE_OUTPUT)
#if defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
#if defined(ARDUINO_ARCH_ESP32) && \
(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || \
CONFIG_IDF_TARGET_ESP32C3)
999,
#endif //ARDUINO_ARCH_ESP32 && CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
0
};
#endif // ARDUINO_ARCH_ESP32 && CONFIG_IDF_TARGET_ESP32S3 ||
// CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
0};
// ESP3D Help
//[ESP0] or [ESP]<command>
bool Commands::ESP0(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP0(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
String parameter;
const uint cmdNb = sizeof(help) / sizeof(char*);
@@ -318,7 +313,6 @@ bool Commands::ESP0(const char* cmd_params, level_authenticate_type auth_type, E
bool json = has_tag(cmd_params, "json");
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
if (json) {
output->print("{\"cmd\":\"0\",\"status\":\"ok\",\"data\":[");
} else {
@@ -337,9 +331,7 @@ bool Commands::ESP0(const char* cmd_params, level_authenticate_type auth_type, E
}
} else {
output->printMSGLine(help[i]);
}
}
if (json) {
output->printLN("]}");
@@ -348,7 +340,8 @@ bool Commands::ESP0(const char* cmd_params, level_authenticate_type auth_type, E
bool found = false;
uint cmdval = parameter.toInt();
if (sizeof(help) / sizeof(char*) != sizeof(cmdlist) / sizeof(uint)) {
String s = "Error in code:" + String(sizeof(help)/sizeof(char*)) + "entries vs " + String(sizeof(cmdlist)/sizeof(uint));
String s = "Error in code:" + String(sizeof(help) / sizeof(char*)) +
"entries vs " + String(sizeof(cmdlist) / sizeof(uint));
output->printLN(s.c_str());
return false;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 100
// STA SSID
//[ESP100]<SSID>[json=no] [pwd=<admin password>
bool Commands::ESP100(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP100]<SSID>[json=no] [pwd=<admin password>]
bool Commands::ESP100(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,11 +51,13 @@ bool Commands::ESP100(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, Settings_ESP3D::read_string(ESP_STA_SSID));
response = format_response(COMMANDID, json, true,
Settings_ESP3D::read_string(ESP_STA_SSID));
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -72,15 +77,15 @@ bool Commands::ESP100(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 101
// STA Password
//[ESP101]<Password> [json=no] [pwd=<admin password>]
bool Commands::ESP101(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP101(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
bool clearSetting = has_tag(cmd_params, "NOPASSWORD");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -47,17 +50,20 @@ bool Commands::ESP101(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Password not displayable");
response =
format_response(COMMANDID, json, false, "Password not displayable");
noError = false;
} else {
if (clearSetting) {
parameter = "";
}
if (!WiFiConfig::isPasswordValid(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect password");
response =
format_response(COMMANDID, json, false, "Incorrect password");
noError = false;
} else {
if(!Settings_ESP3D::write_string(ESP_STA_PASSWORD, parameter.c_str())) {
if (!Settings_ESP3D::write_string(ESP_STA_PASSWORD,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
@@ -67,15 +73,16 @@ bool Commands::ESP101(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}
#endif // WIFI_FEATURE

View File

@@ -19,10 +19,11 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#if defined(WIFI_FEATURE)
#include "../../modules/wifi/wificonfig.h"
#endif // WIFI_FEATURE
@@ -33,16 +34,18 @@
#define COMMANDID 102
// Change STA IP mode (DHCP/STATIC)
//[ESP102]<mode>[json=no] [pwd=<admin password>]
bool Commands::ESP102(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP102(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -65,7 +68,8 @@ bool Commands::ESP102(const char* cmd_params, level_authenticate_type auth_type,
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -73,7 +77,8 @@ bool Commands::ESP102(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter.toUpperCase();
if (!((parameter == "STATIC") || (parameter == "DHCP"))) {
response = format_response(COMMANDID, json, false, "only STATIC or DHCP mode supported");
response = format_response(COMMANDID, json, false,
"only STATIC or DHCP mode supported");
noError = false;
} else {
uint8_t bbuf = (parameter == "DHCP") ? DHCP_MODE : STATIC_IP_MODE;
@@ -87,15 +92,15 @@ bool Commands::ESP102(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,10 +19,11 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#if defined(WIFI_FEATURE)
#include "../../modules/wifi/wificonfig.h"
#endif // WIFI_FEATURE
@@ -32,17 +33,19 @@
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 103
// Change STA IP/Mask/GW
//[ESP103]IP=<IP> MSK=<IP> GW=<IP> [json=no] [pwd=<admin password>
bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP103]IP=<IP> MSK=<IP> GW=<IP> DNS=<IP> [json=no] [pwd=<admin password>
bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -85,7 +88,8 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -100,7 +104,8 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
if (!NetConfig::isValidIP(GW.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect gateway");
response =
format_response(COMMANDID, json, false, "Incorrect gateway");
noError = false;
}
if (!NetConfig::isValidIP(MSK.c_str())) {
@@ -112,11 +117,13 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
if (noError) {
if (!Settings_ESP3D::write_IP_String(ESP_STA_IP_VALUE, IP.c_str()) ||
!Settings_ESP3D::write_IP_String(ESP_STA_GATEWAY_VALUE, GW.c_str()) ||
!Settings_ESP3D::write_IP_String(ESP_STA_DNS_VALUE, DNS.c_str()) ||
!Settings_ESP3D::write_IP_String(ESP_STA_MASK_VALUE, MSK.c_str())) {
!Settings_ESP3D::write_IP_String(ESP_STA_GATEWAY_VALUE,
GW.c_str()) ||
!Settings_ESP3D::write_IP_String(ESP_STA_DNS_VALUE,
DNS.c_str()) ||
!Settings_ESP3D::write_IP_String(ESP_STA_MASK_VALUE,
MSK.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
@@ -126,15 +133,16 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 104
//Set STA fallback mode state at boot which can be BT, WIFI-AP, OFF
// Set STA fallback mode state at boot which can be BT, WIFI-SETUP, OFF
//[ESP104]<state> json=<no> pwd=<admin password>
bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -60,7 +63,8 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -79,7 +83,8 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
#endif // ETH_FEATURE
(parameter == "OFF"))) {
String res = "Only "
String res =
"Only "
#ifdef BLUETOOTH_FEATURE
"BT or "
#endif // BLUETOOTH_FEATURE
@@ -113,15 +118,15 @@ bool Commands::ESP104(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 105
// AP SSID
//[ESP105]<SSID> [json=no] [pwd=<admin password>]
bool Commands::ESP105(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP105(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -49,11 +51,13 @@ bool Commands::ESP105(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, Settings_ESP3D::read_string(ESP_AP_SSID));
response = format_response(COMMANDID, json, true,
Settings_ESP3D::read_string(ESP_AP_SSID));
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -73,15 +77,15 @@ bool Commands::ESP105(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 106
// AP Password
//[ESP106]<Password> [json=no] [pwd=<admin password>]
bool Commands::ESP106(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP106(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
bool clearSetting = has_tag(cmd_params, "NOPASSWORD");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -48,7 +51,8 @@ bool Commands::ESP106(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Password not displayable");
response =
format_response(COMMANDID, json, false, "Password not displayable");
noError = false;
} else {
if (clearSetting) {
@@ -67,15 +71,15 @@ bool Commands::ESP106(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 107
// Change AP IP
//[ESP107]<IP> [json=no] pwd=<admin password>
bool Commands::ESP107(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP107(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -49,11 +52,14 @@ bool Commands::ESP107(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, Settings_ESP3D::read_IP_String(ESP_AP_IP_VALUE).c_str());
response = format_response(
COMMANDID, json, true,
Settings_ESP3D::read_IP_String(ESP_AP_IP_VALUE).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -63,7 +69,8 @@ bool Commands::ESP107(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false;
}
if ( !Settings_ESP3D::write_IP_String(ESP_AP_IP_VALUE, parameter.c_str())) {
if (!Settings_ESP3D::write_IP_String(ESP_AP_IP_VALUE,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
@@ -72,15 +79,15 @@ bool Commands::ESP107(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 108
// Change AP channel
//[ESP108]<channel> [json=no] [pwd=<admin password>]
bool Commands::ESP108(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP108(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,19 +51,24 @@ bool Commands::ESP108(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, String(Settings_ESP3D::read_byte (ESP_AP_CHANNEL)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_byte(ESP_AP_CHANNEL)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
int bbuf = parameter.toInt();
if ((bbuf > Settings_ESP3D::get_max_byte (ESP_AP_CHANNEL)) || (bbuf < Settings_ESP3D::get_min_byte (ESP_AP_CHANNEL))) {
response = format_response(COMMANDID, json, false, "Incorrect channel");
if ((bbuf > Settings_ESP3D::get_max_byte(ESP_AP_CHANNEL)) ||
(bbuf < Settings_ESP3D::get_min_byte(ESP_AP_CHANNEL))) {
response =
format_response(COMMANDID, json, false, "Incorrect channel");
noError = false;
} else {
if (!Settings_ESP3D::write_byte(ESP_AP_CHANNEL, (int8_t)bbuf)) {
@@ -73,15 +81,15 @@ bool Commands::ESP108(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 110
// Set radio state at boot which can be BT, WIFI-STA, WIFI-AP, ETH-STA, OFF
//[ESP110]<state> json=<no> pwd=<admin password>
bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -69,7 +72,8 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -81,14 +85,16 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
(parameter == "BT") ||
#endif // BLUETOOTH_FEATURE
#if defined(WIFI_FEATURE)
(parameter == "WIFI-STA") || (parameter == "WIFI-AP") || (parameter == "WIFI-SETUP") ||
(parameter == "WIFI-STA") || (parameter == "WIFI-AP") ||
(parameter == "WIFI-SETUP") ||
#endif // WIFI_FEATURE
#if defined(ETH_FEATURE)
(parameter == "ETH-STA") || //(parameter == "ETH-SRV") ||
#endif // ETH_FEATURE
(parameter == "OFF"))) {
String res ="Only "
String res =
"Only "
#ifdef BLUETOOTH_FEATURE
"BT or "
#endif // BLUETOOTH_FEATURE
@@ -133,7 +139,8 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
} else {
if (!NetConfig::begin()) {
response = format_response(COMMANDID, json, false, "Cannot setup network");
response = format_response(COMMANDID, json, false,
"Cannot setup network");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
@@ -143,15 +150,15 @@ bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -58,9 +58,13 @@ bool Commands::ESP111(const char* cmd_params, level_authenticate_type auth_type,
printerOutput.printMSG(NetConfig::localIP().c_str());
}
}
} else {
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), 200);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/authentication/authentication_service.h"
// Get/Set hostname
//[ESP112]<Hostname> [json=no] pwd=<admin password>
#define COMMANDID 112
bool Commands::ESP112(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP112(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,18 +51,21 @@ bool Commands::ESP112(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// Get hostname
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, Settings_ESP3D::read_string(ESP_HOSTNAME));
response = format_response(COMMANDID, json, true,
Settings_ESP3D::read_string(ESP_HOSTNAME));
} else { // set host name
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!NetConfig::isHostnameValid(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect hostname");
response =
format_response(COMMANDID, json, false, "Incorrect hostname");
noError = false;
} else {
if (!Settings_ESP3D::write_string(ESP_HOSTNAME, parameter.c_str())) {
@@ -72,15 +78,15 @@ bool Commands::ESP112(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
// Get/Set Boot radio state which can be ON, OFF
//[ESP114]<state> json=<no> pwd=<user/admin password>
#define COMMANDID 114
bool Commands::ESP114(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP114(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,11 +51,15 @@ bool Commands::ESP114(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response =format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_BOOT_RADIO_STATE) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_BOOT_RADIO_STATE) == 0) ? "OFF"
: "ON");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -60,10 +67,12 @@ bool Commands::ESP114(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF mode supported");
response = format_response(COMMANDID, json, false,
"Only ON or OFF mode supported");
noError = false;
} else {
if (!Settings_ESP3D::write_byte (ESP_BOOT_RADIO_STATE, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_BOOT_RADIO_STATE,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
@@ -73,15 +82,15 @@ bool Commands::ESP114(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 115
// Get/Set immediate Network (WiFi/BT/Ethernet) state which can be ON, OFF
//[ESP115]<state> json=<no> pwd=<admin password>
bool Commands::ESP115(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP115(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,11 +51,13 @@ bool Commands::ESP115(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response =format_response(COMMANDID, json, true, (NetConfig::started())?"ON":"OFF");
response = format_response(COMMANDID, json, true,
(NetConfig::started()) ? "ON" : "OFF");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -62,7 +67,8 @@ bool Commands::ESP115(const char* cmd_params, level_authenticate_type auth_type,
if ((parameter == "ON") || (parameter == "OFF")) {
if (parameter == "ON") {
if (!NetConfig::begin()) {
response = format_response(COMMANDID, json, false, "Cannot setup network");
response = format_response(COMMANDID, json, false,
"Cannot setup network");
noError = false;
}
} else {
@@ -72,21 +78,22 @@ bool Commands::ESP115(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, true, "ok");
}
} else {
response = format_response(COMMANDID, json, false, "Only mode ON and OFF are supported");
response = format_response(COMMANDID, json, false,
"Only mode ON and OFF are supported");
noError = false;
}
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,23 +19,26 @@
*/
#include "../../include/esp3d_config.h"
#if defined(HTTP_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 120
// Set HTTP state which can be ON, OFF
//[ESP120]<state> json=<no> pwd=<admin password>
bool Commands::ESP120(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP120(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,11 +50,14 @@ bool Commands::ESP120(const char* cmd_params, level_authenticate_type auth_type,
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_HTTP_ON) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_HTTP_ON) == 0) ? "OFF" : "ON");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -59,10 +65,12 @@ bool Commands::ESP120(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF mode supported!");
response = format_response(COMMANDID, json, false,
"Only ON or OFF mode supported!");
noError = false;
} else {
if (!Settings_ESP3D::write_byte (ESP_HTTP_ON, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_HTTP_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
@@ -72,15 +80,15 @@ bool Commands::ESP120(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(HTTP_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 121
// Set HTTP port
//[ESP121]<port> json=<no> pwd=<admin password>
bool Commands::ESP121(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP121(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,18 +50,22 @@ bool Commands::ESP121(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true,String(Settings_ESP3D::read_uint32(ESP_HTTP_PORT)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_uint32(ESP_HTTP_PORT)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_HTTP_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_HTTP_PORT))) {
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_HTTP_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_HTTP_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
@@ -72,15 +79,15 @@ bool Commands::ESP121(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(TELNET_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/telnet/telnet_server.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/telnet/telnet_server.h"
#define COMMANDID 130
// Set TELNET state which can be ON, OFF, CLOSE
//[ESP130]<state> json=<no> pwd=<admin password>
bool Commands::ESP130(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP130(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,25 +50,31 @@ bool Commands::ESP130(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_HTTP_ON) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_HTTP_ON) == 0) ? "OFF" : "ON");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF") || (parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF or CLOSE mode supported!");
if (!((parameter == "ON") || (parameter == "OFF") ||
(parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF or CLOSE mode supported!");
noError = false;
} else {
if (parameter == "CLOSE") {
telnet_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte (ESP_TELNET_ON, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_TELNET_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
@@ -77,15 +86,15 @@ bool Commands::ESP130(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,23 +19,26 @@
*/
#include "../../include/esp3d_config.h"
#if defined(TELNET_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 131
// Set TELNET port
//[ESP131]<port> json=<no> pwd=<admin password>
bool Commands::ESP131(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP131(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -46,18 +49,22 @@ bool Commands::ESP131(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true,String(Settings_ESP3D::read_uint32(ESP_TELNET_PORT)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_uint32(ESP_TELNET_PORT)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_TELNET_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_TELNET_PORT))) {
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_TELNET_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_TELNET_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
@@ -71,15 +78,15 @@ bool Commands::ESP131(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -20,15 +20,15 @@
#include "../../include/esp3d_config.h"
#if defined(TIMESTAMP_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#define COMMANDID 140
// Sync / Set / Get current time
//[ESP140]<SYNC> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <zone=xxx> <dst=YES/NO>
//<time=YYYY-MM-DDTHH:mm:ss> NOW json=<no> pwd=<admin password>
//[ESP140]<SYNC> <srv1=XXXXX> <srv2=XXXXX> <srv3=XXXXX> <tzone=+HH:SS>
//<ntp=YES/NO> <time=YYYY-MM-DDTHH:mm:ss> NOW json=<no> pwd=<admin password>
bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
@@ -106,22 +106,48 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
}
}
if (noError) {
parameter = get_param(cmd_params, "zone=");
parameter = get_param(cmd_params, "tzone=");
if (parameter.length() > 0) {
hasParam = true;
if ((parameter.toInt() <=
(int8_t)Settings_ESP3D::get_max_byte(ESP_TIMEZONE)) &&
(parameter.toInt() >=
(int8_t)Settings_ESP3D::get_min_byte(ESP_TIMEZONE))) {
if (!Settings_ESP3D::write_byte(ESP_TIMEZONE, parameter.toInt())) {
bool isvalid = false;
for (uint8_t i = 0; i < SupportedTimeZonesSize; i++) {
if (parameter == SupportedTimeZones[i]) {
isvalid = true;
break;
}
}
if (isvalid) {
if (!Settings_ESP3D::write_string(ESP_TIME_ZONE,
parameter.c_str())) {
response = format_response(COMMANDID, json, false,
"Set time zone failed");
noError = false;
}
} else {
response =
format_response(COMMANDID, json, false, "Invalid time zone");
noError = false;
}
}
}
if (noError) {
parameter = get_param(cmd_params, "ntp=");
parameter.toUpperCase();
if (parameter.length() > 0) {
hasParam = true;
parameter.toUpperCase();
if (parameter.length() > 0) {
if (!Settings_ESP3D::write_byte(ESP_INTERNET_TIME,
(parameter == "NO") ? 0 : 1)) {
response = format_response(COMMANDID, json, false,
"Set internet time failed");
noError = false;
}
}
}
}
if (noError) {
/*if (noError) {
parameter = get_param(cmd_params, "dst=");
if (parameter.length() > 0) {
hasParam = true;
@@ -135,13 +161,13 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
}
}*/
if (noError) {
parameter = get_param(cmd_params, "time=");
parameter.toUpperCase();
if (parameter.length() > 0) {
hasParam = true;
if (!timeserver.setTime(parameter.c_str())) {
if (!timeService.setTime(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "Set time failed");
noError = false;
@@ -149,12 +175,13 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
}
}
parameter = clean_param(get_param(cmd_params, ""));
parameter.toUpperCase();
if (noError) {
if (has_tag(parameter.c_str(), "SYNC")) {
log_esp3d("Sync time");
hasParam = true;
if (timeserver.is_internet_time()) {
if (!timeserver.begin()) {
if (timeService.is_internet_time()) {
if (!timeService.begin()) {
response =
format_response(COMMANDID, json, false, "Init time failed");
noError = false;
@@ -167,16 +194,19 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
log_esp3d("Get time");
response = format_response(COMMANDID, json, true,
timeserver.current_time());
timeService.getCurrentTime());
}
}
}
if (noError) {
if (has_tag(parameter.c_str(), "NOW")) {
String tmp = timeService.getCurrentTime();
tmp += " (";
tmp += timeService.getTimeZone();
tmp += ")";
hasParam = true;
log_esp3d("Get time");
response =
format_response(COMMANDID, json, true, timeserver.current_time());
response = format_response(COMMANDID, json, true, tmp.c_str());
}
}
if (noError && !hasParam) {
@@ -203,34 +233,34 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
} else {
tmp += ", srv3=";
}
tmp += Settings_ESP3D::read_string(ESP_TIME_SERVER3);
tmp += Settings_ESP3D::read_string(ESP_TIME_ZONE);
if (json) {
tmp += "\",\"zone\":\"";
tmp += "\",\"tzone\":\"";
} else {
tmp += ", zone=";
tmp += ", tzone=";
}
tmp += Settings_ESP3D::read_byte(ESP_TIMEZONE);
tmp += Settings_ESP3D::read_byte(ESP_INTERNET_TIME);
if (json) {
tmp += "\",\"dst\":\"";
tmp += "\",\"ntp\":\"";
} else {
tmp += ", dst=";
tmp += ", ntp=";
}
tmp += Settings_ESP3D::read_byte(ESP_TIME_IS_DST) ? "YES" : "NO";
tmp += Settings_ESP3D::read_byte(ESP_INTERNET_TIME) ? "YES" : "NO";
if (json) {
tmp += "\"}";
}
response = format_response(COMMANDID, json, true, tmp.c_str());
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -18,24 +18,27 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 150
// Get/Set display/set boot delay in ms / Verbose boot
//[ESP150]<delay=time in milliseconds><verbose=ON/OFF>[pwd=<admin password>]
bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -66,7 +69,8 @@ bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type,
} else {
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -77,8 +81,10 @@ bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParameter = true;
uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY))) {
response = format_response(COMMANDID, json, false, "Incorrect delay");
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY))) {
response =
format_response(COMMANDID, json, false, "Incorrect delay");
noError = false;
}
if (noError) {
@@ -93,20 +99,24 @@ bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParameter = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_VERBOSE_BOOT, (parameter == "ON")?1:0)) {
response = format_response(COMMANDID, json, false, "Set failed");
if (!Settings_ESP3D::write_byte(ESP_VERBOSE_BOOT,
(parameter == "ON") ? 1 : 0)) {
response =
format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
Settings_ESP3D::isVerboseBoot(true);
}
} else {
response = format_response(COMMANDID, json, false, "Only verbose +ON/OFF is allowed");
response = format_response(COMMANDID, json, false,
"Only verbose +ON/OFF is allowed");
noError = false;
}
}
}
if (noError && !hasParameter) {
response = format_response(COMMANDID, json, false, "Incorrect command");
response =
format_response(COMMANDID, json, false, "Incorrect command");
noError = false;
} else if (noError) {
response = format_response(COMMANDID, json, true, "ok");
@@ -114,14 +124,14 @@ bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WS_DATA_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/websocket/websocket_server.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/websocket/websocket_server.h"
#define COMMANDID 160
// Set WebSocket state which can be ON, OFF, CLOSE
//[ESP160]<state> json=<no> pwd=<admin password>
bool Commands::ESP160(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP160(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,25 +50,31 @@ bool Commands::ESP160(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_WEBSOCKET_ON) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_WEBSOCKET_ON) == 0) ? "OFF" : "ON");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF") || (parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF or CLOSE mode supported!");
if (!((parameter == "ON") || (parameter == "OFF") ||
(parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF or CLOSE mode supported!");
noError = false;
} else {
if (parameter == "CLOSE") {
websocket_data_server.closeClients();
} else {
if (!Settings_ESP3D::write_byte (ESP_WEBSOCKET_ON, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_WEBSOCKET_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
@@ -77,15 +86,15 @@ bool Commands::ESP160(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,23 +19,26 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WS_DATA_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 161
// Set Websocket port
//[ESP161]<port> json=<no> pwd=<admin password>
bool Commands::ESP161(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP161(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -46,18 +49,22 @@ bool Commands::ESP161(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true,String(Settings_ESP3D::read_uint32(ESP_WEBSOCKET_PORT)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_uint32(ESP_WEBSOCKET_PORT)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBSOCKET_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBSOCKET_PORT))) {
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBSOCKET_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBSOCKET_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
@@ -71,15 +78,15 @@ bool Commands::ESP161(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,29 +19,33 @@
*/
#include "../../include/esp3d_config.h"
#if defined(CAMERA_DEVICE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "esp_camera.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/camera/camera.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "esp_camera.h"
#define COMMANDID 170
// Set Camera command value / list all values in JSON/plain
//[ESP170]<plain><label=value> pwd=<admin password>
//label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling/colorbar
// label can be:
// light/framesize/quality/contrast/brightness/saturation/gainceiling/colorbar
// /awb/agc/aec/hmirror/vflip/awb_gain/agc_gain/aec_value/aec2/cw/bpc/wpc
// /raw_gma/lenc/special_effect/wb_mode/ae_level
bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -50,7 +54,8 @@ bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!esp3d_camera.started()) {
response = format_response(COMMANDID, json, false, "No camera initialized");
response =
format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
parameter = clean_param(get_param(cmd_params, ""));
@@ -58,7 +63,8 @@ bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() == 0) {
sensor_t* s = esp_camera_sensor_get();
if (s == nullptr) {
response = format_response(COMMANDID, json, false, "No camera initialized");
response =
format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
String line = "";
@@ -439,7 +445,8 @@ bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type,
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -447,22 +454,26 @@ bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
String label = get_label(parameter.c_str(), "=");
if (label.length() == 0) {
response = format_response(COMMANDID, json, false, "Missing command");
response =
format_response(COMMANDID, json, false, "Missing command");
noError = false;
} else {
String labels = label + "=";
String value = get_param(cmd_params, labels.c_str());
if (value.length() == 0) {
response = format_response(COMMANDID, json, false, "Invalid value");
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
}
if (noError) {
int r = esp3d_camera.command(label.c_str(), value.c_str());
if (r == -1) {
response = format_response(COMMANDID, json, false, "Unknow command");
response =
format_response(COMMANDID, json, false, "Unknow command");
noError = false;
} else if (r == 1) {
response = format_response(COMMANDID, json, false, "Invalid value");
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
@@ -473,15 +484,15 @@ bool Commands::ESP170(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,28 +19,34 @@
*/
#include "../../include/esp3d_config.h"
#if defined(CAMERA_DEVICE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "esp_camera.h"
#include "../settings_esp3d.h"
#include <time.h>
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/camera/camera.h"
#include <time.h>
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "esp_camera.h"
#define COMMANDID 171
//Save frame to target path and filename (default target = today date, default name=timestamp.jpg)
//[ESP171]path=<target path> filename=<target filename> pwd=<admin/user password>
bool Commands::ESP171(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
// Save frame to target path and filename (default target = today date, default
// name=timestamp.jpg)
//[ESP171]path=<target path> filename=<target filename> pwd=<admin/user
//password>
bool Commands::ESP171(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
String path;
String filename;
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -49,13 +55,13 @@ bool Commands::ESP171(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!esp3d_camera.started()) {
response = format_response(COMMANDID, json, false, "No camera initialized");
response =
format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
parameter = clean_param(get_param(cmd_params, "path="));
// get path
if (parameter.length() != 0) {
path = parameter;
}
parameter = clean_param(get_param(cmd_params, "filename="));
@@ -90,24 +96,26 @@ bool Commands::ESP171(const char* cmd_params, level_authenticate_type auth_type,
// now send command
if (noError) {
noError = esp3d_camera.handle_snap(nullptr,path.c_str(), filename.c_str());
noError =
esp3d_camera.handle_snap(nullptr, path.c_str(), filename.c_str());
if (noError) {
response = format_response(COMMANDID, json, true, "Snapshot taken");
} else {
response = format_response(COMMANDID, json, false, "Error taking snapshot");
response =
format_response(COMMANDID, json, false, "Error taking snapshot");
}
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(FTP_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/ftp/FtpServer.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/ftp/FtpServer.h"
#define COMMANDID 180
// Set ftp state which can be ON, OFF, CLOSE
//[ESP180]<state> json=<no> pwd=<admin password>
bool Commands::ESP180(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP180(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,30 +51,35 @@ bool Commands::ESP180(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_FTP_ON) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_FTP_ON) == 0) ? "OFF" : "ON");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF") || (parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF or CLOSE mode supported!");
if (!((parameter == "ON") || (parameter == "OFF") ||
(parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF or CLOSE mode supported!");
noError = false;
} else {
if (parameter == "CLOSE") {
ftp_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte (ESP_FTP_ON, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_FTP_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
@@ -80,15 +88,15 @@ bool Commands::ESP180(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,28 @@
*/
#include "../../include/esp3d_config.h"
#if defined(FTP_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 181
// Set/Get Ftp ports
//[ESP181]ctrl=<port> active=<port> passive=<port> json=<no> pwd=<admin password>
bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP181]ctrl=<port> active=<port> passive=<port> json=<no> pwd=<admin
//password>
bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -73,7 +77,8 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -85,8 +90,10 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() > 0) {
hasParam = true;
ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_FTP_CTRL_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_FTP_CTRL_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect ctrl port");
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_FTP_CTRL_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_FTP_CTRL_PORT))) {
response =
format_response(COMMANDID, json, false, "Incorrect ctrl port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32(ESP_FTP_CTRL_PORT, ibuf)) {
@@ -100,12 +107,18 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() > 0) {
ibuf = parameter.toInt();
hasParam = true;
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_FTP_DATA_ACTIVE_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_FTP_DATA_ACTIVE_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect active port");
if ((ibuf > Settings_ESP3D::get_max_int32_value(
ESP_FTP_DATA_ACTIVE_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(
ESP_FTP_DATA_ACTIVE_PORT))) {
response = format_response(COMMANDID, json, false,
"Incorrect active port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_FTP_DATA_ACTIVE_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
if (!Settings_ESP3D::write_uint32(ESP_FTP_DATA_ACTIVE_PORT,
ibuf)) {
response =
format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
@@ -116,37 +129,44 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() > 0) {
hasParam = true;
ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_FTP_DATA_PASSIVE_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_FTP_DATA_PASSIVE_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect passive port");
if ((ibuf > Settings_ESP3D::get_max_int32_value(
ESP_FTP_DATA_PASSIVE_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(
ESP_FTP_DATA_PASSIVE_PORT))) {
response = format_response(COMMANDID, json, false,
"Incorrect passive port");
noError = false;
} else {}
if (!Settings_ESP3D::write_uint32 (ESP_FTP_DATA_PASSIVE_PORT, ibuf)) {
} else {
}
if (!Settings_ESP3D::write_uint32(ESP_FTP_DATA_PASSIVE_PORT,
ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
if (noError && !hasParam) {
response = format_response(COMMANDID, json, false, "Only ctrl, active and passive settings are supported!");
response = format_response(
COMMANDID, json, false,
"Only ctrl, active and passive settings are supported!");
noError = false;
} else {
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WEBDAV_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/webdav/webdav_server.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/webdav/webdav_server.h"
#define COMMANDID 190
// Set WebDav state which can be ON, OFF, CLOSE
//[ESP190]<state> json=<no> pwd=<admin password>
bool Commands::ESP190(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP190(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,27 +51,33 @@ bool Commands::ESP190(const char* cmd_params, level_authenticate_type auth_type,
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_WEBDAV_ON) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_WEBDAV_ON) == 0) ? "OFF" : "ON");
// webdav_server.dir();
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF") || (parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF or CLOSE mode supported!");
if (!((parameter == "ON") || (parameter == "OFF") ||
(parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF or CLOSE mode supported!");
noError = false;
} else {
if (parameter == "CLOSE") {
webdav_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte (ESP_WEBDAV_ON, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_WEBDAV_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
@@ -80,15 +89,15 @@ bool Commands::ESP190(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,23 +19,26 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WEBDAV_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 191
// Set webdav port
//[ESP191]<port> json=<no> pwd=<admin password>
bool Commands::ESP191(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP191(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -46,18 +49,22 @@ bool Commands::ESP191(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true,String(Settings_ESP3D::read_uint32(ESP_WEBDAV_PORT)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_uint32(ESP_WEBDAV_PORT)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBDAV_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBDAV_PORT))) {
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBDAV_PORT)) ||
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBDAV_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
@@ -71,15 +78,15 @@ bool Commands::ESP191(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,27 +19,30 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SD_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 200
// Get SD Card Status
//[ESP200] json=<YES/NO> <RELEASESD> <REFRESH> pwd=<user/admin password>
bool Commands::ESP200(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP200(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
bool releaseSD = has_tag(cmd_params, "RELEASE");
bool refreshSD = has_tag(cmd_params, "REFRESH");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -68,7 +71,8 @@ bool Commands::ESP200(const char* cmd_params, level_authenticate_type auth_type,
}
ESP_SD::releaseFS();
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length()!=0 && parameter.indexOf("REFRESH")==-1 && parameter.indexOf("RELEASE")==-1) {
if (parameter.length() != 0 && parameter.indexOf("REFRESH") == -1 &&
parameter.indexOf("RELEASE") == -1) {
response = format_response(COMMANDID, json, false, "Unknown parameter");
noError = false;
}
@@ -83,9 +87,13 @@ bool Commands::ESP200(const char* cmd_params, level_authenticate_type auth_type,
} else {
output->printMSG(response.c_str());
}
} else {
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,30 @@
*/
#include "../../include/esp3d_config.h"
#if defined(DIRECT_PIN_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../hal.h"
#include "../../modules/authentication/authentication_service.h"
#include "../settings_esp3d.h"
#define COMMANDID 201
// Get/Set pin value
//[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES ANALOG=NO ANALOG_RANGE=255]pwd=<admin password>
//Range can be 255 / 1024 / 2047 / 4095 / 8191
bool Commands::ESP201(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES ANALOG=NO
// ANALOG_RANGE=255]pwd=<admin password> Range can be 255 / 1024 / 2047 / 4095 /
// 8191
bool Commands::ESP201(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -82,7 +86,8 @@ bool Commands::ESP201(const char* cmd_params, level_authenticate_type auth_type,
} else {
value = Hal::analogRead(pin);
}
response = format_response(COMMANDID, json, true, String(value).c_str());
response =
format_response(COMMANDID, json, true, String(value).c_str());
} else {
// it is a set
int value = parameter.toInt();
@@ -93,7 +98,8 @@ bool Commands::ESP201(const char* cmd_params, level_authenticate_type auth_type,
digitalWrite(pin, (value == 0) ? LOW : HIGH);
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Invalid value");
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
}
} else {
@@ -106,10 +112,12 @@ bool Commands::ESP201(const char* cmd_params, level_authenticate_type auth_type,
Hal::analogRange(analog_range);
Hal::analogWriteFreq(1000);
analogWrite(pin, value);
response = format_response(COMMANDID, json, false, "Invalid value");
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
response =
format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
@@ -120,15 +128,15 @@ bool Commands::ESP201(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SD_DEVICE) && SD_DEVICE != ESP_SDIO
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 202
// Get/Set SD card Speed factor 1 2 4 6 8 16 32
//[ESP202]SPEED=<value> json=<no> pwd=<user/admin password>
bool Commands::ESP202(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP202(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,10 +50,14 @@ bool Commands::ESP202(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, String(Settings_ESP3D::read_byte (ESP_SD_SPEED_DIV)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV)).c_str());
} else { // set
parameter = get_param(cmd_params, "SPEED=");
if ((parameter == "1") || (parameter == "2") || (parameter == "4")|| (parameter == "6")|| (parameter == "8")|| (parameter == "16")|| (parameter == "32")) {
if ((parameter == "1") || (parameter == "2") || (parameter == "4") ||
(parameter == "6") || (parameter == "8") || (parameter == "16") ||
(parameter == "32")) {
if (!Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV, parameter.toInt())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
@@ -65,15 +72,15 @@ bool Commands::ESP202(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,25 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SENSOR_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/sensor/sensor.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/sensor/sensor.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 210
// Get Sensor Value / type/Set Sensor type
//[ESP210]<type=NONE/xxx> <interval=XXX in millisec> json=<no> pwd=<admin password>
bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP210]<type=NONE/xxx> <interval=XXX in millisec> json=<no> pwd=<admin
//password>
bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -78,7 +82,8 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
} else {
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -91,10 +96,12 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
int8_t v = -1;
if (parameter == "NONE") {
v = 0;
} else if(esp3d_sensor.isModelValid(esp3d_sensor.getIDFromString(parameter.c_str()))) {
} else if (esp3d_sensor.isModelValid(
esp3d_sensor.getIDFromString(parameter.c_str()))) {
v = esp3d_sensor.getIDFromString(parameter.c_str());
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
response =
format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
if (v != -1) {
@@ -104,7 +111,8 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
}
if (noError) {
if (!esp3d_sensor.begin()) {
response = format_response(COMMANDID, json, false, "Starting failed");
response =
format_response(COMMANDID, json, false, "Starting failed");
noError = false;
}
}
@@ -119,7 +127,8 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "interval=");
if (parameter.length() != 0) {
hasParam = true;
if (!Settings_ESP3D::write_uint32(ESP_SENSOR_INTERVAL,parameter.toInt())) {
if (!Settings_ESP3D::write_uint32(ESP_SENSOR_INTERVAL,
parameter.toInt())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
@@ -136,15 +145,15 @@ bool Commands::ESP210(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(DISPLAY_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/display/display.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/display/display.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 214
// Output to esp screen status
//[ESP214]<Text>json=<no> pwd=<user/admin password>
bool Commands::ESP214(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP214(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,15 +51,15 @@ bool Commands::ESP214(const char* cmd_params, level_authenticate_type auth_type,
esp3d_display.setStatus(parameter.c_str());
response = format_response(COMMANDID, json, true, "ok");
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(DISPLAY_DEVICE) && defined(DISPLAY_TOUCH_DRIVER)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/display/display.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/display/display.h"
#define COMMANDID 215
// Touch Calibration
//[ESP215]<CALIBRATE> json=<no> [pwd=<user password>]
bool Commands::ESP215(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP215(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,7 +50,10 @@ bool Commands::ESP215(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_CALIBRATION)==1)?"Done":"Not done");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_CALIBRATION) == 1) ? "Done"
: "Not done");
} else { // set
parameter.toUpperCase();
if (has_tag (cmd_params, "CALIBRATE") {
@@ -58,21 +64,22 @@ bool Commands::ESP215(const char* cmd_params, level_authenticate_type auth_type,
esp3d_display.startCalibration();
} else {
if (parameter.indexOf("CALIBRATE") == -1) {
response = format_response(COMMANDID, json, false, "Invalid parameter");
response =
format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -18,25 +18,28 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 220
// Get ESP pins definition
// output is JSON or plain text according parameter
//[ESP220]json=<no>
bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -71,7 +74,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
line = "";
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SD MOSI";
if (json) {
@@ -88,7 +91,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
line = "";
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SD MISO";
if (json) {
@@ -105,7 +108,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
line = "";
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SD SCK";
if (json) {
@@ -122,7 +125,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
line = "";
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SD DETECT";
if (json) {
@@ -140,7 +143,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
line = "";
#if ESP_SD_DETECT_PIN != -1
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SD DETECT STATE";
if (json) {
@@ -159,7 +162,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
#endif // ESP_SD_DETECT_PIN !=-1
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD && defined(ESP_FLAG_SHARED_SD_PIN)
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SD SWITCH";
if (json) {
@@ -180,7 +183,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
#ifdef BUZZER_DEVICE
hasPin = true;
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "BUZZER";
if (json) {
@@ -197,10 +200,11 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
line = "";
#endif // BUZZER_DEVICE
#if defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && ESP3D_RESET_PIN !=-1
#if defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && \
ESP3D_RESET_PIN != -1
hasPin = true;
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "RESET";
if (json) {
@@ -220,7 +224,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
#ifdef SENSOR_DEVICE
hasPin = true;
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SENSOR";
if (json) {
@@ -238,10 +242,11 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
line = "";
#endif // SENSOR_DEVICE
#ifdef DISPLAY_DEVICE
#if (DISPLAY_DEVICE == OLED_I2C_SSD1306) || (DISPLAY_DEVICE == OLED_I2C_SSDSH1106)
#if (DISPLAY_DEVICE == OLED_I2C_SSD1306) || \
(DISPLAY_DEVICE == OLED_I2C_SSDSH1106)
hasPin = true;
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SDA";
if (json) {
@@ -258,7 +263,7 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
line = "";
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "SCL";
if (json) {
@@ -274,11 +279,12 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
output->printMSGLine(line.c_str());
}
line = "";
#endif //(DISPLAY_DEVICE == OLED_I2C_SSD1306) || (DISPLAY_DEVICE == OLED_I2C_SSDSH1106)
#endif //(DISPLAY_DEVICE == OLED_I2C_SSD1306) || (DISPLAY_DEVICE ==
// OLED_I2C_SSDSH1106)
#endif // DISPLAY_DEVICE
if (!hasPin) {
if (json) {
line += "{\"id\":\"";
line += ",{\"id\":\"";
}
line += "NO PIN";
if (json) {
@@ -300,18 +306,19 @@ bool Commands::ESP220(const char* cmd_params, level_authenticate_type auth_type,
}
return true;
} else {
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
response = format_response(COMMANDID, json, false,
"This command doesn't take parameters");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(BUZZER_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/buzzer/buzzer.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/buzzer/buzzer.h"
#define COMMANDID 250
// Play sound
//[ESP250]F=<frequency> D=<duration> json=<no> [pwd=<user password>]
bool Commands::ESP250(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP250(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -76,15 +79,15 @@ bool Commands::ESP250(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -18,22 +18,25 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../commands.h"
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
// Delay command
//[ESP290]<delay in ms> json=<no> [pwd=<user password>]
#define COMMANDID 290
bool Commands::ESP290(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP290(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -53,16 +56,15 @@ bool Commands::ESP290(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -28,6 +28,9 @@
#if defined(SENSOR_DEVICE)
#include "../../modules/sensor/sensor.h"
#endif // SENSOR_DEVICE
#ifdef TIMESTAMP_FEATURE
#include "../../modules/time/time_service.h"
#endif // TIMESTAMP_FEATURE
#define COMMANDID 400
// Get full ESP3D settings
//[ESP400]<pwd=admin>
@@ -427,26 +430,25 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
// Time zone
output->print(",{\"F\":\"service/time\",\"P\":\"");
output->print(ESP_TIMEZONE);
output->print("\",\"T\":\"B\",\"R\":\"1\",\"V\":\"");
output->print(
String((int8_t)Settings_ESP3D::read_byte(ESP_TIMEZONE)).c_str());
output->print(ESP_TIME_ZONE);
output->print("\",\"T\":\"S\",\"R\":\"1\",\"V\":\"");
output->print(Settings_ESP3D::read_string(ESP_TIME_ZONE));
output->print("\",\"H\":\"tzone\",\"O\":[");
for (int8_t i = Settings_ESP3D::get_min_byte(ESP_TIMEZONE);
i <= Settings_ESP3D::get_max_byte(ESP_TIMEZONE); i++) {
if (i > Settings_ESP3D::get_min_byte(ESP_TIMEZONE)) {
for (int8_t i = 0; i < SupportedTimeZonesSize; i++) {
if (i > 0) {
output->print(",");
}
output->printf("{\"%d\":\"%d\"}", i, i);
output->printf("{\"%s\":\"%s\"}", SupportedTimeZones[i],
SupportedTimeZones[i]);
}
output->print("]}");
// DST
output->print(",{\"F\":\"service/time\",\"P\":\"");
// DST which is currently not supported automaticatly
/* output->print(",{\"F\":\"service/time\",\"P\":\"");
output->print(ESP_TIME_IS_DST);
output->print("\",\"T\":\"B\",\"R\":\"1\",\"V\":\"");
output->print(Settings_ESP3D::read_byte(ESP_TIME_IS_DST));
output->print("\",\"H\":\"dst\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
output->print("\",\"H\":\"dst\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");*/
// Time Server1
output->print(",{\"F\":\"service/time\",\"P\":\"");
@@ -735,14 +737,14 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -34,7 +34,7 @@
#include "../../modules/buzzer/buzzer.h"
#endif // BUZZER_DEVICE
#ifdef TIMESTAMP_FEATURE
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#endif // TIMESTAMP_FEATURE
#ifdef NOTIFICATION_FEATURE
#include "../../modules/notifications/notifications_service.h"
@@ -133,7 +133,7 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
#endif // SD_DEVICE
#ifdef TIMESTAMP_FEATURE
case ESP_INTERNET_TIME:
timeserver.begin();
timeService.begin();
break;
#endif // TIMESTAMP_FEATURE
#ifdef NOTIFICATION_FEATURE
@@ -248,7 +248,11 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
response += spos.length() > 0 ? " for P=" + spos : "";
}
response = format_response(COMMANDID, json, false, response.c_str());
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SD_UPDATE_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
// Set SD Check at boot state which can be ON, OFF
//[ESP402]<state> json=<no> pwd=<admin password>
#define COMMANDID 402
bool Commands::ESP402(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP402(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -46,11 +49,15 @@ bool Commands::ESP402(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true, (Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT) == 0)?"OFF":"ON");
response = format_response(
COMMANDID, json, true,
(Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT) == 0) ? "OFF"
: "ON");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -58,10 +65,12 @@ bool Commands::ESP402(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF mode supported");
response = format_response(COMMANDID, json, false,
"Only ON or OFF mode supported");
noError = false;
} else {
if (!Settings_ESP3D::write_byte (ESP_SD_CHECK_UPDATE_AT_BOOT, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_SD_CHECK_UPDATE_AT_BOOT,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
@@ -71,15 +80,15 @@ bool Commands::ESP402(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(WIFI_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/wifi/wificonfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/wifi/wificonfig.h"
#include "../../modules/authentication/authentication_service.h"
// Get available AP list (limited to 30)
// output is JSON or plain text according parameter
//[ESP410]json=<no>
#define COMMANDID 410
bool Commands::ESP410(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP410(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -124,19 +127,20 @@ bool Commands::ESP410(const char* cmd_params, level_authenticate_type auth_type,
}
return true;
} else {
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
response = format_response(COMMANDID, json, false,
"This command doesn't take parameters");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -57,7 +57,7 @@
#include "../../modules/webdav/webdav_server.h"
#endif // WEBDAV_FEATURE
#if defined(TIMESTAMP_FEATURE)
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#endif // TIMESTAMP_FEATURE
#if defined(SENSOR_DEVICE)
#include "../../modules/sensor/sensor.h"
@@ -1317,7 +1317,7 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
} else {
line += ": ";
}
line += timeserver.started() ? "ON" : "OFF";
line += timeService.started() ? "ON" : "OFF";
if (json) {
line += "\"}";
output->print(line.c_str());
@@ -1660,14 +1660,14 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -18,24 +18,27 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../esp3d.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3d.h"
#include "../esp3doutput.h"
// Set ESP State
// cmd are RESTART / RESET
//[ESP444]<cmd> json=<no> <pwd=admin>
#define COMMANDID 444
bool Commands::ESP444(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP444(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -62,19 +65,20 @@ bool Commands::ESP444(const char* cmd_params, level_authenticate_type auth_type,
Hal::wait(100);
Esp3D::restart_esp();
}
if (noError && !has_tag(cmd_params,"RESTART") && !has_tag(cmd_params,"RESET")) {
if (noError && !has_tag(cmd_params, "RESTART") &&
!has_tag(cmd_params, "RESET")) {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(MDNS_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/mDNS/mDNS.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/mDNS/mDNS.h"
#include "../../modules/authentication/authentication_service.h"
// Get available ESP3D list
// output is JSON or plain text according parameter
//[ESP4\50]json=<no>
#define COMMANDID 450
bool Commands::ESP450(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP450(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -48,7 +51,6 @@ bool Commands::ESP450(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
uint16_t n = 0;
if (!json) {
output->printMSGLine("Start Scan");
@@ -112,7 +114,6 @@ bool Commands::ESP450(const char* cmd_params, level_authenticate_type auth_type,
if (json) {
line += "\"}";
}
}
if (json) {
line += "]}";
@@ -123,9 +124,6 @@ bool Commands::ESP450(const char* cmd_params, level_authenticate_type auth_type,
output->printMSGLine(line.c_str());
}
}
}
if (json) {
@@ -135,19 +133,20 @@ bool Commands::ESP450(const char* cmd_params, level_authenticate_type auth_type,
}
return true;
} else {
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
response = format_response(COMMANDID, json, false,
"This command doesn't take parameters");
noError = false;
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,20 +19,22 @@
*/
#include "../../include/esp3d_config.h"
#if defined(AUTHENTICATION_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 550
// Change admin password
//[ESP550]<password> json=<no> pwd=<admin password>
bool Commands::ESP550(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP550(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
if (auth_type == LEVEL_ADMIN) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) {
@@ -52,19 +54,20 @@ bool Commands::ESP550(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,20 +19,22 @@
*/
#include "../../include/esp3d_config.h"
#if defined(AUTHENTICATION_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
// Change user password
//[ESP555]<password> json=<no> pwd=<admin/user password>
#define COMMANDID 555
bool Commands::ESP555(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP555(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
if (auth_type != LEVEL_GUEST) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) {
@@ -52,19 +54,20 @@ bool Commands::ESP555(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(NOTIFICATION_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h"
#define COMMANDID 600
// Send Notification
//[ESP600]msg json=<no> [pwd=<admin/user password>]
bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -51,23 +54,25 @@ bool Commands::ESP600(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
} else {
parameter = get_param(cmd_params, "");
if (notificationsservice.sendMSG(ESP_NOTIFICATION_TITLE, parameter.c_str())) {
if (notificationsservice.sendMSG(ESP_NOTIFICATION_TITLE,
parameter.c_str())) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Send notification failed");
response =
format_response(COMMANDID, json, false, "Send notification failed");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,30 @@
*/
#include "../../include/esp3d_config.h"
#if defined(NOTIFICATION_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h"
#define COMMANDID 610
// Set/Get Notification settings
//[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE/IFTTT> T1=<token1> T2=<token2> TS=<Settings> json=<no> [pwd=<admin password>]
//Get will give type and settings only not the protected T1/T2
bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP610]type=<NONE/PUSHOVER/EMAIL/LINE/IFTTT> T1=<token1> T2=<token2>
//TS=<Settings> json=<no> [pwd=<admin password>] Get will give type and settings
// only not the protected T1/T2
bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -114,7 +118,9 @@ bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type,
} else if (parameter == "IFTTT") {
Ntype = ESP_IFTTT_NOTIFICATION;
} else {
response = format_response(COMMANDID, json, false, "Only NONE, PUSHOVER, EMAIL, LINE, IFTTT are supported");
response = format_response(
COMMANDID, json, false,
"Only NONE, PUSHOVER, EMAIL, LINE, IFTTT are supported");
noError = false;
}
if (noError) {
@@ -129,7 +135,8 @@ bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "TS=");
if (parameter.length() > 0) {
hasParam = true;
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS, parameter.c_str())) {
if (!Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set TS failed");
noError = false;
}
@@ -140,7 +147,8 @@ bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "T1=");
if (parameter.length() > 0) {
hasParam = true;
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1, parameter.c_str())) {
if (!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set T1 failed");
noError = false;
}
@@ -151,7 +159,8 @@ bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "T2=");
if (parameter.length() > 0) {
hasParam = true;
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2, parameter.c_str())) {
if (!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set T2 failed");
noError = false;
} else {
@@ -165,21 +174,23 @@ bool Commands::ESP610(const char* cmd_params, level_authenticate_type auth_type,
notificationsservice.begin();
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Only type, T1, T2 and TS not empty are supported");
response = format_response(
COMMANDID, json, false,
"Only type, T1, T2 and TS not empty are supported");
noError = false;
}
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(NOTIFICATION_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/notifications/notifications_service.h"
#define COMMANDID 620
// Send Notification using URL
//[ESP620]URL=<encoded url> json=<no>[pwd=<admin/user password>]
bool Commands::ESP620(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP620(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -54,20 +57,21 @@ bool Commands::ESP620(const char* cmd_params, level_authenticate_type auth_type,
if (notificationsservice.GET(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Send notification failed");
response =
format_response(COMMANDID, json, false, "Send notification failed");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,28 +19,33 @@
*/
#include "../../include/esp3d_config.h"
#if defined(GCODE_HOST_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/gcode_host/gcode_host.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/gcode_host/gcode_host.h"
#define COMMANDID 700
// TODO :
// - on ESP3DLib or GRBL_ESP32 the file/line must be processed like a SD gcode file
// - on ESP3D the file/line must be processed and/or streamed like a SD gcode file
// - on ESP3DLib or GRBL_ESP32 the file/line must be processed like a SD gcode
// file
// - on ESP3D the file/line must be processed and/or streamed like a SD gcode
// file
// read local file
//[ESP700]<filename>
bool Commands::ESP700(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP700(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -51,14 +56,17 @@ bool Commands::ESP700(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) {
if (esp3d_gcode_host.getStatus() == HOST_NO_STREAM) {
if (esp3d_gcode_host.processFile(parameter.c_str(), auth_type, output)) {
if (esp3d_gcode_host.processFile(parameter.c_str(), auth_type,
output)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Error processing file");
response =
format_response(COMMANDID, json, false, "Error processing file");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Streaming already in progress");
response = format_response(COMMANDID, json, false,
"Streaming already in progress");
noError = false;
}
} else {
@@ -66,15 +74,15 @@ bool Commands::ESP700(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -140,15 +140,15 @@ bool Commands::ESP701(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(FILESYSTEM_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h"
#define COMMANDID 710
// Format ESP Filesystem
//[ESP710]FORMATFS json=<no> pwd=<admin password>
bool Commands::ESP710(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP710(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -55,15 +58,15 @@ bool Commands::ESP710(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
output->printMSGLine (response.c_str() );
}
if (noError) {
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SD_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#define COMMANDID 715
// Format SD Filesystem
//[ESP715]FORMATSD json=<no> pwd=<admin password>
bool Commands::ESP715(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP715(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -66,15 +69,15 @@ bool Commands::ESP715(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
output->printMSGLine (response.c_str() );
}
if (noError) {
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,27 +19,30 @@
*/
#include "../../include/esp3d_config.h"
#if defined(FILESYSTEM_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#endif // FILESYSTEM_TIMESTAMP_FEATURE
#define COMMANDID 720
// List ESP Filesystem
//[ESP720]<Root> json=<no> pwd=<admin password>
bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -60,7 +63,8 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type,
uint countd = 0;
if (f) {
if (json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" + parameter + "\",\"files\":[";
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" +
parameter + "\",\"files\":[";
output->print(line.c_str());
} else {
line = "Directory on FS : " + parameter;
@@ -104,7 +108,7 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type,
String time = "";
line = "";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeserver.current_time(sub.getLastWrite());
time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
line = "";
@@ -185,15 +189,15 @@ bool Commands::ESP720(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(FILESYSTEM_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_filesystem.h"
#define COMMANDID 730
// Action on ESP Filesystem
// rmdir / remove / mkdir / exists / create
//[ESP730]<Action>=<path> json=<no> pwd=<admin password>
bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead;
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -53,7 +56,6 @@ bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "rmdir=");
@@ -107,15 +109,15 @@ bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,27 +19,30 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SD_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#ifdef SD_TIMESTAMP_FEATURE
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#endif // SD_TIMESTAMP_FEATURE
#define COMMANDID 740
// List SD Filesystem
//[ESP740]<Root> json=<no> pwd=<admin password>
bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -67,7 +70,9 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
uint countd = 0;
if (f) {
if (json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" + parameter + "\",\"files\":[";
line =
"{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" +
parameter + "\",\"files\":[";
output->print(line.c_str());
} else {
line = "Directory on SD : " + parameter;
@@ -110,7 +115,7 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
line = "";
countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeserver.current_time(sub.getLastWrite());
time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
if (countd > 0 || countf > 1) {
@@ -181,26 +186,28 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
ESP_SD::releaseFS();
return true;
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
response =
format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
response =
format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
}
ESP_SD::releaseFS();
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(SD_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_sd.h"
#define COMMANDID 750
// Action on SD Filesystem
// rmdir / remove / mkdir / exists /create
//[ESP750]<Action>=<path> json=<no> pwd=<admin password>
bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead;
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -68,7 +71,8 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_SD::rmdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "rmdir failed");
response =
format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
@@ -78,7 +82,8 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if (ESP_SD::remove(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "remove failed");
response =
format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
@@ -100,7 +105,8 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
hasParam = true;
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_FILE_WRITE);
if (!f.isOpen()) {
response = format_response(COMMANDID, json, false, "create failed");
response =
format_response(COMMANDID, json, false, "create failed");
noError = false;
} else {
f.close();
@@ -111,22 +117,23 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response = format_response(COMMANDID, json, false, "Missing parameter");
response =
format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
ESP_SD::releaseFS();
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,27 +19,30 @@
*/
#include "../../include/esp3d_config.h"
#if defined(GLOBAL_FILESYSTEM_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_globalFS.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_globalFS.h"
#if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#endif // SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
#define COMMANDID 780
// List Global Filesystem
//[ESP780]<Root> json=<no> pwd=<admin password>
bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -67,7 +70,8 @@ bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type,
uint countd = 0;
if (f) {
if (json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" + parameter + "\",\"files\":[";
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" +
parameter + "\",\"files\":[";
output->print(line.c_str());
} else {
line = "Directory on Global FS : " + parameter;
@@ -111,7 +115,7 @@ bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type,
line = "";
countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeserver.current_time(sub.getLastWrite());
time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
if (countd > 0 || countf > 1) {
@@ -191,15 +195,15 @@ bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,26 +19,29 @@
*/
#include "../../include/esp3d_config.h"
#if defined(GLOBAL_FILESYSTEM_FEATURE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_globalFS.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/filesystem/esp_globalFS.h"
#define COMMANDID 790
// Action on Global Filesystem
// rmdir / remove / mkdir / exists /create
//[ESP790]<Action>=<path> json=<no> pwd=<admin password>
bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead;
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -72,7 +75,8 @@ bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_GBFS::rmdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "rmdir failed");
response =
format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
@@ -82,7 +86,8 @@ bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if (ESP_GBFS::remove(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "remove failed");
response =
format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
@@ -105,7 +110,8 @@ bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
ESP_GBFile f;
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_WRITE);
if (!f.isOpen()) {
response = format_response(COMMANDID, json, false, "create failed");
response =
format_response(COMMANDID, json, false, "create failed");
noError = false;
} else {
f.close();
@@ -116,7 +122,8 @@ bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response = format_response(COMMANDID, json, false, "Missing parameter");
response =
format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
@@ -127,15 +134,15 @@ bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -18,11 +18,12 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/network/netconfig.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/network/netconfig.h"
#include "../../modules/authentication/authentication_service.h"
#ifdef FILESYSTEM_FEATURE
#include "../../modules/filesystem/esp_filesystem.h"
#endif // FILESYSTEM_FEATURE
@@ -37,26 +38,28 @@
#include "../../modules/websocket/websocket_server.h"
#endif // HTTP_FEATURE
#ifdef TIMESTAMP_FEATURE
#include "../../modules/time/time_server.h"
#include "../../modules/time/time_service.h"
#endif // TIMESTAMP_FEATURE
#ifdef CAMERA_DEVICE
#include "../../modules/camera/camera.h"
#endif // CAMERA_DEVICE
#define COMMANDID 800
//get fw version firmare target and fw version
// get fw capabilities
// eventually set time with pc time
// output is JSON or plain text according parameter
//[ESP800]json=<no><time=YYYY-MM-DDTHH:mm:ss> <version=3.0.0-a11> <setup=0/1>
bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -67,7 +70,8 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "setup=");
if (parameter.length() > 0) {
if (!Settings_ESP3D::write_byte(ESP_SETUP, parameter == "0" ? 0 : 1)) {
response = format_response(COMMANDID, json, false, "Save setup flag failed");
response =
format_response(COMMANDID, json, false, "Save setup flag failed");
noError = false;
}
}
@@ -75,16 +79,34 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
if (noError) {
#ifdef TIMESTAMP_FEATURE
String newtime = get_param(cmd_params, "time=");
String tparm = (timeserver.is_internet_time())?"Auto":"Manual";
if (!timeserver.is_internet_time() && (newtime.length() > 0)) {
if (!timeserver.setTime(newtime.c_str())) {
tparm="Failed to set";
String timezone = get_param(cmd_params, "tz=");
String tparm = (timeService.is_internet_time()) ? "Auto" : "Manual";
if (!timeService.is_internet_time()) {
if (newtime.length() > 0) {
if (!timeService.setTime(newtime.c_str())) {
tparm = "Failed to set time";
log_esp3d_e("Failed to set time");
} else {
tparm = "Manual";
}
} else {
if (!timeserver.is_internet_time() && (newtime.length() == 0)) {
tparm = "Not set";
}
if (timezone.length() > 0) {
if (!timeService.setTimeZone(timezone.c_str())) {
tparm = "Failed to set timezone";
log_esp3d_e("Failed to set timezone");
}
}
} else {
if (timeService.started()) {
tparm = "Auto";
} else {
tparm = "Not set";
}
}
#else
String tparm = "none";
#endif // TIMESTAMP_FEATURE
String line = "";
@@ -143,7 +165,8 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
} else {
line += "Setup:";
}
line+=Settings_ESP3D::read_byte (ESP_SETUP) == 0?F("Enabled"):F("Disabled");
line += Settings_ESP3D::read_byte(ESP_SETUP) == 0 ? F("Enabled")
: F("Disabled");
if (json) {
line += "\"";
output->print(line.c_str());
@@ -412,15 +435,14 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
}
return true;
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#define COMMANDID 900
// Get state / Set Enable / Disable Serial Communication
//[ESP900]<ENABLE/DISABLE> json=<no> [pwd=<admin password>]
bool Commands::ESP900(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP900(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -60,7 +63,8 @@ bool Commands::ESP900(const char* cmd_params, level_authenticate_type auth_type,
if (serial_service.begin(ESP_SERIAL_OUTPUT)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Cannot enable serial communication");
response = format_response(COMMANDID, json, false,
"Cannot enable serial communication");
noError = false;
}
} else if (parameter == "DISABLE") {
@@ -72,15 +76,15 @@ bool Commands::ESP900(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}
#endif

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#define COMMANDID 901
// Set Serial baudrate
//[ESP901]<baude rate> json=<no> pwd=<admin password>
bool Commands::ESP901(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP901(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,11 +50,14 @@ bool Commands::ESP901(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true,String(Settings_ESP3D::read_uint32(ESP_BAUD_RATE)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_uint32(ESP_BAUD_RATE)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -72,15 +78,15 @@ bool Commands::ESP901(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(BUZZER_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/buzzer/buzzer.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/buzzer/buzzer.h"
#define COMMANDID 910
// Get state / Set Enable / Disable buzzer
//[ESP910]<ENABLE/DISABLE>[pwd=<admin password>]
bool Commands::ESP910(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP910(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -54,13 +57,15 @@ bool Commands::ESP910(const char* cmd_params, level_authenticate_type auth_type,
}
} else { // set
if (parameter == "ENABLE" || parameter == "DISABLE") {
if (!Settings_ESP3D::write_byte (ESP_BUZZER, (parameter == "ENABLE")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_BUZZER,
(parameter == "ENABLE") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
if (parameter == "ENABLE") {
if (!esp3d_buzzer.begin()) {
response = format_response(COMMANDID, json, false, "Starting service failed");
response = format_response(COMMANDID, json, false,
"Starting service failed");
noError = false;
}
} else if (parameter == "DISABLE") {
@@ -76,15 +81,15 @@ bool Commands::ESP910(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}
#endif // BUZZER_DEVICE

View File

@@ -18,24 +18,28 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 920
// Get state / Set state of output message clients
//[ESP920]<SERIAL / SCREEN / REMOTE_SCREEN/ WEBSOCKET / TELNET /BT / ALL>=<ON/OFF> json=<no> [pwd=<admin password>]
bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
//[ESP920]<SERIAL / SCREEN / REMOTE_SCREEN/ WEBSOCKET / TELNET /BT /
//ALL>=<ON/OFF> json=<no> [pwd=<admin password>]
bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -51,7 +55,9 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
s += "{";
}
bool hasData = false;
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
hasData = true;
if (json) {
s += "\"";
@@ -66,8 +72,10 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
if (json) {
s += "\"";
}
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if !defined(ESP3DLIB_ENV) || (defined (ESP3DLIB_ENV) && (HAS_DISPLAY || defined (HAS_SERIAL_DISPLAY)))
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
// MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if !defined(ESP3DLIB_ENV) || \
(defined(ESP3DLIB_ENV) && (HAS_DISPLAY || defined(HAS_SERIAL_DISPLAY)))
if (hasData) {
if (json) {
s += ",";
@@ -193,12 +201,15 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, true, s.c_str());
} else { // set
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
parameter = get_param(cmd_params, "SERIAL=");
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_SERIAL_FLAG, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_SERIAL_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
@@ -207,19 +218,23 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
noError = false;
}
}
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if !defined(ESP3DLIB_ENV) || (defined (ESP3DLIB_ENV) && (HAS_DISPLAY || defined (HAS_SERIAL_DISPLAY)))
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
// MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if !defined(ESP3DLIB_ENV) || \
(defined(ESP3DLIB_ENV) && (HAS_DISPLAY || defined(HAS_SERIAL_DISPLAY)))
if (noError && !hasParam) {
parameter = get_param(cmd_params, "REMOTE_SCREEN=");
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_REMOTE_SCREEN_FLAG, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_REMOTE_SCREEN_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
@@ -231,27 +246,37 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
!Settings_ESP3D::write_byte (ESP_SERIAL_FLAG, (parameter == "ON")?1:0)||
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
!Settings_ESP3D::write_byte(ESP_SERIAL_FLAG,
(parameter == "ON") ? 1 : 0) ||
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
// MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#ifdef DISPLAY_DEVICE
!Settings_ESP3D::write_byte (ESP_SCREEN_FLAG, (parameter == "ON")?1:0)||
!Settings_ESP3D::write_byte(ESP_SCREEN_FLAG,
(parameter == "ON") ? 1 : 0) ||
#endif // DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
!Settings_ESP3D::write_byte (ESP_WEBSOCKET_FLAG, (parameter == "ON")?1:0)||
!Settings_ESP3D::write_byte(ESP_WEBSOCKET_FLAG,
(parameter == "ON") ? 1 : 0) ||
#endif // WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
!Settings_ESP3D::write_byte (ESP_BT_FLAG, (parameter == "ON")?1:0)||
!Settings_ESP3D::write_byte(ESP_BT_FLAG,
(parameter == "ON") ? 1 : 0) ||
#endif // BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
!Settings_ESP3D::write_byte (ESP_TELNET_FLAG, (parameter == "ON")?1:0)||
!Settings_ESP3D::write_byte(ESP_TELNET_FLAG,
(parameter == "ON") ? 1 : 0) ||
#endif // TELNET_FEATURE
!Settings_ESP3D::write_byte (ESP_REMOTE_SCREEN_FLAG, (parameter == "ON")?1:0)) {
!Settings_ESP3D::write_byte(ESP_REMOTE_SCREEN_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
@@ -262,12 +287,14 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_SCREEN_FLAG, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_SCREEN_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
@@ -279,12 +306,14 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_WEBSOCKET_FLAG, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_WEBSOCKET_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
@@ -295,12 +324,14 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "BT=");
if (parameter.length() != 0) {
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_BT_FLAG, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_BT_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
@@ -312,12 +343,14 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_TELNET_FLAG, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_TELNET_FLAG,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
@@ -329,20 +362,21 @@ bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput::isOutput(ESP_ALL_CLIENTS, true);
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Incorrect parameter");
response =
format_response(COMMANDID, json, false, "Incorrect parameter");
noError = false;
}
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#define COMMANDID 930
// Set Bridge Serial state which can be ON, OFF, CLOSE
//[ESP930]<state> json=<no> pwd=<admin password>
bool Commands::ESP930(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP930(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,31 +50,37 @@ bool Commands::ESP930(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
String r = (Settings_ESP3D::read_byte(ESP_SERIAL_BRIDGE_ON) == 0)?"OFF":"ON";
String r =
(Settings_ESP3D::read_byte(ESP_SERIAL_BRIDGE_ON) == 0) ? "OFF" : "ON";
r += " - Serial" + String(serial_bridge_service.serialIndex());
response = format_response(COMMANDID, json, true, r.c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF") || (parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false, "Only ON or OFF or CLOSE mode supported!");
if (!((parameter == "ON") || (parameter == "OFF") ||
(parameter == "CLOSE"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF or CLOSE mode supported!");
noError = false;
} else {
if (parameter == "CLOSE") {
serial_bridge_service.end();
} else {
if (!Settings_ESP3D::write_byte (ESP_SERIAL_BRIDGE_ON, (parameter == "ON")?1:0)) {
if (!Settings_ESP3D::write_byte(ESP_SERIAL_BRIDGE_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
if(noError && parameter == "ON" && !serial_bridge_service.started()) {
if (noError && parameter == "ON" &&
!serial_bridge_service.started()) {
serial_bridge_service.begin(ESP_SERIAL_BRIDGE_OUTPUT);
}
}
@@ -82,15 +91,15 @@ bool Commands::ESP930(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -19,24 +19,27 @@
*/
#include "../../include/esp3d_config.h"
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/serial/serial_service.h"
#define COMMANDID 931
// Set Serial bridge baudrate
//[ESP931]<baude rate> json=<no> pwd=<admin password>
bool Commands::ESP931(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP931(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -47,11 +50,14 @@ bool Commands::ESP931(const char* cmd_params, level_authenticate_type auth_type,
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, true,String(Settings_ESP3D::read_uint32(ESP_SERIAL_BRIDGE_BAUD)).c_str());
response = format_response(
COMMANDID, json, true,
String(Settings_ESP3D::read_uint32(ESP_SERIAL_BRIDGE_BAUD)).c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
@@ -72,15 +78,15 @@ bool Commands::ESP931(const char* cmd_params, level_authenticate_type auth_type,
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@@ -18,26 +18,31 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../../modules/authentication/authentication_service.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#if defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
#if defined(ARDUINO_ARCH_ESP32) && \
(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || \
CONFIG_IDF_TARGET_ESP32C3)
#include <esp_efuse.h>
#define COMMANDID 999
// Set quiet boot if strapping pin is High
//[ESP999]QUIETBOOT [pwd=<admin/user password>]
bool Commands::ESP999(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool Commands::ESP999(const char* cmd_params, level_authenticate_type auth_type,
ESP3DOutput* output) {
bool noError = true;
bool json = has_tag(cmd_params, "json");
String response;
String parameter;
bool hasParam = false;
int errorCode = 200; //unless it is a server error use 200 as default and set error in json instead
int errorCode = 200; // unless it is a server error use 200 as default and
// set error in json instead
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
@@ -51,24 +56,27 @@ bool Commands::ESP999(const char* cmd_params, level_authenticate_type auth_type,
response = format_response(COMMANDID, json, false, "Incorrect parameter");
noError = false;
} else { // set
if (esp_efuse_set_rom_log_scheme(ESP_EFUSE_ROM_LOG_ON_GPIO_HIGH)!=ESP_OK) {
response = format_response(COMMANDID, json, false, "Set failed(May be already set?)");
if (esp_efuse_set_rom_log_scheme(ESP_EFUSE_ROM_LOG_ON_GPIO_HIGH) !=
ESP_OK) {
response = format_response(COMMANDID, json, false,
"Set failed(May be already set?)");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
if (noError) {
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}
#endif //defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)
#endif // defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 ||
// CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3)

View File

@@ -33,8 +33,7 @@
#endif // ARDUINO_ARCH_ESP32
#include <Arduino.h>
class Hal
{
class Hal {
public:
static bool begin();
static void end();
@@ -57,4 +56,16 @@ private:
static uint32_t _analogRange;
static uint32_t _analogWriteFreq;
};
class Esp3dTimout {
public:
Esp3dTimout(uint64_t timeout) { _start = millis(); };
void reset() { _start = millis(); };
bool isTimeout() { return (millis() - _start > _timeout); };
uint64_t getTimeout() { return _timeout; };
private:
uint64_t _start;
uint64_t _timeout;
};
#endif //_ESP3D_HAL_H

View File

@@ -57,6 +57,7 @@
#define MAX_NOTIFICATION_TOKEN_LENGTH 63
#define MAX_NOTIFICATION_SETTINGS_LENGTH 128
#define MAX_SERVER_ADDRESS_LENGTH 128
#define MAX_TIME_ZONE_LENGTH 7
#define MIN_SERVER_ADDRESS_LENGTH 0
// default byte values
@@ -104,7 +105,7 @@
#ifndef DEFAULT_FW
#define DEFAULT_FW UNKNOWN_FW
#endif // DEFAULT_FW
#define DEFAULT_TIME_ZONE 0
#define DEFAULT_TIME_ZONE "+00:00"
#define DEFAULT_TIME_DST 0
#define DEFAULT_SD_MOUNT ESP_SD_ROOT
#define DEFAULT_SD_CHECK_UPDATE_AT_BOOT 1
@@ -363,9 +364,6 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos) {
res = DEFAULT_FW;
break;
#ifdef TIMESTAMP_FEATURE
case ESP_TIMEZONE:
res = DEFAULT_TIME_ZONE;
break;
case ESP_TIME_IS_DST:
res = DEFAULT_TIME_DST;
break;
@@ -566,11 +564,6 @@ uint8_t Settings_ESP3D::get_max_byte(int pos) {
res = MAX_CHANNEL;
break;
#endif // WIFI_FEATURE
#ifdef TIMESTAMP_FEATURE
case ESP_TIMEZONE:
res = 12;
break;
#endif // TIMESTAMP_FEATURE
default:
res = 255;
}
@@ -585,11 +578,6 @@ int8_t Settings_ESP3D::get_min_byte(int pos) {
res = MIN_CHANNEL;
break;
#endif // WIFI_FEATURE
#ifdef TIMESTAMP_FEATURE
case ESP_TIMEZONE:
res = -12;
break;
#endif // TIMESTAMP_FEATURE
default:
res = 0;
}
@@ -611,6 +599,9 @@ const String &Settings_ESP3D::get_default_string_value(int pos) {
break;
#endif // WIFI_FEATURE || ETH_FEATURE || defined (ETH_FEATURE)
#ifdef TIMESTAMP_FEATURE
case ESP_TIME_ZONE:
res = DEFAULT_TIME_ZONE;
break;
case ESP_TIME_SERVER1:
res = DEFAULT_TIME_SERVER1;
break;
@@ -673,6 +664,9 @@ uint8_t Settings_ESP3D::get_max_string_size(int pos) {
break;
#endif // WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
#ifdef TIMESTAMP_FEATURE
case ESP_TIME_ZONE:
res = MAX_TIME_ZONE_LENGTH;
break;
case ESP_TIME_SERVER1:
case ESP_TIME_SERVER2:
case ESP_TIME_SERVER3:
@@ -1321,8 +1315,9 @@ bool Settings_ESP3D::reset(bool networkonly) {
ESP_INTERNET_TIME,
Settings_ESP3D::get_default_byte_value(ESP_INTERNET_TIME));
// Time Zone
Settings_ESP3D::write_byte(
ESP_TIMEZONE, Settings_ESP3D::get_default_byte_value(ESP_TIMEZONE));
Settings_ESP3D::write_string(
ESP_TIME_ZONE,
Settings_ESP3D::get_default_string_value(ESP_TIME_ZONE).c_str());
// Is DST Time Zone
Settings_ESP3D::write_byte(
ESP_TIME_IS_DST, Settings_ESP3D::get_default_byte_value(ESP_TIME_IS_DST));

View File

@@ -99,7 +99,7 @@
// chinese
#define ESP_SENSOR_TYPE 460 // 1 bytes = flag
#define ESP_TARGET_FW 461 // 1 bytes = flag
#define ESP_TIMEZONE 462 // 1 bytes = flag
#define ESP_FREE 462 // 1 bytes = flag
#define ESP_TIME_IS_DST 463 // 1 bytes = flag
#define ESP_TIME_SERVER1 \
464 // 129 bytes 128+1 = string ; warning does not support multibyte char
@@ -142,6 +142,7 @@
#define ESP_SERIAL_BRIDGE_ON 1036 // 1 byte = flag
#define ESP_SERIAL_BRIDGE_FLAG 1037 // 1 byte = flag
#define ESP_SERIAL_BRIDGE_BAUD 1038 // 4 bytes= int
#define ESP_TIME_ZONE 1042 // 7 bytes 6+1 = string
// Hidden password
#define HIDDEN_PASSWORD "********"

View File

@@ -78,6 +78,7 @@ bool Camera::handle_snap(WebServer *webserver, const char *path,
webserver->sendHeader(String(F("Content-Disposition")),
String(F("inline; filename=capture.jpg")), true);
webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
HTTP_Server::set_http_headers();
webserver->send(200);
}
log_esp3d("Camera capture ongoing");

View File

@@ -574,6 +574,15 @@ time_t ESP_GBFile::getLastWrite() {
return _sdFile.getLastWrite();
}
#endif // SD_DEVICE
#if defined(TIMESTAMP_FEATURE)
static time_t t = 0;
if (t == 0) {
time(&t);
t = t - (millis() / 1000);
}
return t;
#endif // TIMESTAMP_FEATURE
return 0;
}

View File

@@ -142,6 +142,7 @@ uint8_t ESP_SD::getFSType(const char* path) {
bool ESP_SD::accessFS(uint8_t FS) {
(void)FS;
bool res = true;
// if card is busy do not let another task access SD and so prevent a release
if (_state == ESP_SDCARD_BUSY) {
log_esp3d("SD Busy");
@@ -149,16 +150,31 @@ bool ESP_SD::accessFS(uint8_t FS) {
}
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
if (ESP_SD::enableSharedSD()) {
log_esp3d("Access SD ok");
return true;
log_esp3d("Access shared SD ok");
res = true;
} else {
log_esp3d_e("Enable shared SD failed");
return false;
res = false;
}
#else
log_esp3d("Access SD");
return true;
log_esp3d("Accessing Direct SD");
res = true;
#endif // SD_DEVICE_CONNECTION == ESP_SHARED_SD
if (res) {
log_esp3d("Checking SD state");
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
log_esp3d_e("SD not present");
res = false;
// Sd is not available so release it
ESP_SD::releaseFS(FS);
} else {
log_esp3d("SD present");
res = true;
log_esp3d("Accessing SD is ok");
ESP_SD::setState(ESP_SDCARD_BUSY);
}
}
return res;
}
void ESP_SD::releaseFS(uint8_t FS) {
(void)FS;

View File

@@ -202,10 +202,9 @@ bool ESP_SD::exists(const char *path) {
}
res = SD.exists(p);
if (!res) {
ESP_SDFile root = ESP_SD::open(p.c_str(), ESP_FILE_READ);
if (root) {
res = root.isDirectory();
}
// check if it is a directory
p += '/';
res = SD.exists(p);
}
return res;
}

View File

@@ -35,6 +35,8 @@
void HTTP_Server::handleSDFileList() {
level_authenticate_type auth_level =
AuthenticationService::authenticated_level();
HTTP_Server::set_http_headers();
if (auth_level == LEVEL_GUEST) {
_upload_status = UPLOAD_STATUS_NONE;
_webserver->send(401, "text/plain", "Wrong authentication!");

View File

@@ -0,0 +1,106 @@
/*
handle-command.cpp - ESP3D http handle
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
*/
#include "../../../include/esp3d_config.h"
#if defined(HTTP_FEATURE)
#include "../http_server.h"
#if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif // ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif // ARDUINO_ARCH_ESP8266
#include "../../../core/commands.h"
#include "../../../core/esp3doutput.h"
#include "../../../core/settings_esp3d.h"
#include "../../authentication/authentication_service.h"
const unsigned char realTimeCommands[] = {
'!', '~', '?', 0x18, 0x84, 0x85, 0x90, 0x92, 0x93, 0x94, 0x95,
0x96, 0x97, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0xA0, 0xA1};
bool isRealTimeCommand(unsigned char c) {
for (unsigned int i = 0; i < sizeof(realTimeCommands); i++) {
if (c == realTimeCommands[i]) {
return true;
}
}
return false;
}
// Handle web command query and send answer//////////////////////////////
void HTTP_Server::handle_web_command() {
level_authenticate_type auth_level =
AuthenticationService::authenticated_level();
if (auth_level == LEVEL_GUEST) {
_webserver->send(401, "text/plain", "Wrong authentication!");
return;
}
// log_esp3d("Authentication = %d", auth_level);
String cmd = "";
if (_webserver->hasArg("cmd")) {
cmd = _webserver->arg("cmd");
ESP3DOutput output(_webserver);
if (!cmd.endsWith("\n")) {
if (Settings_ESP3D::GetFirmwareTarget() == GRBL) {
uint len = cmd.length();
if (!((len == 1 && isRealTimeCommand(cmd[0])) ||
(len == 2 && isRealTimeCommand(cmd[1])))) {
cmd += "\n";
} else { // no need \n for realtime command
// remove the 0XC2 that should not be there
if (len == 2 && isRealTimeCommand(cmd[1]) && cmd[1] == 0xC2) {
cmd[0] = cmd[1];
cmd[1] = 0x0;
}
}
} else {
cmd += "\n"; // need to validate command
}
}
log_esp3d("Web Command: %s", cmd.c_str());
if (esp3d_commands.is_esp_command((uint8_t *)cmd.c_str(), cmd.length())) {
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(), &output,
auth_level);
} else {
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
ESP3DOutput outputOnly(ESP_SOCKET_SERIAL_CLIENT);
#endif // COMMUNICATION_PROTOCOL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
ESP3DOutput outputOnly(ESP_SERIAL_CLIENT);
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
_webserver->sendHeader("Cache-Control", "no-cache");
HTTP_Server::set_http_headers();
#ifdef ESP_ACCESS_CONTROL_ALLOW_ORIGIN
_webserver->sendHeader("Access-Control-Allow-Origin", "*");
#endif // ESP_ACCESS_CONTROL_ALLOw_ORIGIN
// the command is not ESP3D so it will be forwarded to the serial port
// no need to wait to answer then
_webserver->send(200, "text/plain", "ESP3D says: command forwarded");
esp3d_commands.process((uint8_t *)cmd.c_str(), cmd.length(), &output,
auth_level, &outputOnly);
}
} else if (_webserver->hasArg("ping")) {
_webserver->send(200);
} else {
_webserver->send(400, "text/plain", "Invalid command");
}
return;
}
#endif // HTTP_FEATURE

View File

@@ -26,6 +26,7 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif // ARDUINO_ARCH_ESP8266
#include "../../../core/esp3d_string.h"
#include "../../authentication/authentication_service.h"
#include "../../filesystem/esp_filesystem.h"
@@ -40,12 +41,14 @@
// Handle not registred path on FS neither SD ///////////////////////
void HTTP_Server::handle_not_found() {
HTTP_Server::set_http_headers();
if (AuthenticationService::authenticated_level() == LEVEL_GUEST) {
_webserver->send(401, "text/plain", "Wrong authentication!");
return;
}
String path = _webserver->urlDecode(_webserver->uri());
String contentType = getContentType(path.c_str());
String contentType = esp3d_string::getContentType(path.c_str());
String pathWithGz = path + ".gz";
log_esp3d("URI: %s", path.c_str());
#if defined(FILESYSTEM_FEATURE)
@@ -104,7 +107,7 @@ void HTTP_Server::handle_not_found() {
#ifdef FILESYSTEM_FEATURE
// check local page
path = "/404.htm";
contentType = getContentType(path.c_str());
contentType = esp3d_string::getContentType(path.c_str());
pathWithGz = path + ".gz";
if (ESP_FileSystem::exists(pathWithGz.c_str()) ||
ESP_FileSystem::exists(path.c_str())) {

View File

@@ -0,0 +1,226 @@
/*
handle-files.cpp - ESP3D http handle
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
*/
#include "../../../include/esp3d_config.h"
#if defined(HTTP_FEATURE) && defined(FILESYSTEM_FEATURE)
#include "../http_server.h"
#if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif // ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif // ARDUINO_ARCH_ESP8266
#include "../../authentication/authentication_service.h"
#include "../../filesystem/esp_filesystem.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include "../../time/time_service.h"
#endif // FILESYSTEM_TIMESTAMP_FEATURE
// Filesystem
// Filesystem files list and file commands
void HTTP_Server::handleFSFileList() {
HTTP_Server::set_http_headers();
level_authenticate_type auth_level =
AuthenticationService::authenticated_level();
if (auth_level == LEVEL_GUEST) {
_upload_status = UPLOAD_STATUS_NONE;
_webserver->send(401, "text/plain", "Wrong authentication!");
return;
}
String path;
String status = "ok";
if ((_upload_status == UPLOAD_STATUS_FAILED) ||
(_upload_status == UPLOAD_STATUS_CANCELLED)) {
status = "Upload failed";
_upload_status = UPLOAD_STATUS_NONE;
}
if (_webserver->hasArg("quiet")) {
if (_webserver->arg("quiet") == "yes") {
status = "{\"status\":\"" + status + "\"}";
_webserver->send(200, "text/plain", status.c_str());
return;
}
}
// get current path
if (_webserver->hasArg("path")) {
path += _webserver->arg("path");
}
// to have a clean path
path.trim();
path.replace("//", "/");
if (path[path.length() - 1] != '/') {
path += "/";
}
// check if query need some action
if (_webserver->hasArg("action")) {
// delete a file
if (_webserver->arg("action") == "delete" &&
_webserver->hasArg("filename")) {
String filename;
String shortname = _webserver->arg("filename");
shortname.replace("/", "");
filename = path + _webserver->arg("filename");
filename.replace("//", "/");
if (!ESP_FileSystem::exists(filename.c_str())) {
status = shortname + " does not exists!";
} else {
if (ESP_FileSystem::remove(filename.c_str())) {
status = shortname + " deleted";
// what happen if no "/." and no other subfiles for SPIFFS like?
String ptmp = path;
if ((path != "/") && (path[path.length() - 1] = '/')) {
ptmp = path.substring(0, path.length() - 1);
}
if (!ESP_FileSystem::exists(ptmp.c_str())) {
ESP_FileSystem::mkdir(ptmp.c_str());
}
} else {
status = "Cannot deleted ";
status += shortname;
}
}
}
// delete a directory
if (_webserver->arg("action") == "deletedir" &&
_webserver->hasArg("filename")) {
String filename;
String shortname = _webserver->arg("filename");
shortname.replace("/", "");
filename = path + _webserver->arg("filename");
filename += "/";
filename.replace("//", "/");
if (filename != "/") {
if (ESP_FileSystem::rmdir(filename.c_str())) {
log_esp3d("Deleting %s", filename.c_str());
status = shortname;
status += " deleted";
} else {
status = "Cannot deleted ";
status += shortname;
}
}
}
// create a directory
if (_webserver->arg("action") == "createdir" &&
_webserver->hasArg("filename")) {
String filename;
filename = path + _webserver->arg("filename");
String shortname = _webserver->arg("filename");
shortname.replace("/", "");
filename.replace("//", "/");
if (ESP_FileSystem::exists(filename.c_str())) {
status = shortname + " already exists!";
} else {
if (!ESP_FileSystem::mkdir(filename.c_str())) {
status = "Cannot create ";
status += shortname;
} else {
status = shortname + " created";
}
}
}
}
String buffer2send;
buffer2send.reserve(1200);
buffer2send = "{\"files\":[";
String ptmp = path;
if ((path != "/") && (path[path.length() - 1] = '/')) {
ptmp = path.substring(0, path.length() - 1);
}
_webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
_webserver->sendHeader("Content-Type", "application/json");
_webserver->sendHeader("Cache-Control", "no-cache");
_webserver->send(200);
if (ESP_FileSystem::exists(ptmp.c_str())) {
ESP_File f = ESP_FileSystem::open(ptmp.c_str(), ESP_FILE_READ);
// Parse files
ESP_File sub = f.openNextFile();
if (f) {
bool needseparator = false;
while (sub) {
if (needseparator) {
buffer2send += ",";
} else {
// for next entry
needseparator = true;
}
buffer2send += "{\"name\":\"";
buffer2send += sub.name();
buffer2send += "\",\"size\":\"";
if (sub.isDirectory()) {
buffer2send += "-1";
} else {
buffer2send += ESP_FileSystem::formatBytes(sub.size());
}
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
buffer2send += "\",\"time\":\"";
if (!sub.isDirectory()) {
buffer2send += timeService.getDateTime((time_t)sub.getLastWrite());
}
#endif // FILESYSTEM_TIMESTAMP_FEATURE
buffer2send += "\"}";
if (buffer2send.length() > 1100) {
_webserver->sendContent_P(buffer2send.c_str(), buffer2send.length());
buffer2send = "";
}
sub.close();
sub = f.openNextFile();
}
f.close();
} else {
if (status == "ok") {
status = "cannot open" + ptmp;
} else {
status += ", cannot open" + ptmp;
}
}
} else {
if (status == "ok") {
status = ptmp + " does not exists!";
} else {
status += ", " + ptmp + " does not exists!";
}
}
buffer2send += "],\"path\":\"" + path + "\",";
if (ESP_FileSystem::totalBytes() > 0) {
buffer2send += "\"occupation\":\"" +
String(100 * ESP_FileSystem::usedBytes() /
ESP_FileSystem::totalBytes()) +
"\",";
} else {
status = "FileSystem Error";
buffer2send += "\"occupation\":\"0\",";
}
buffer2send += "\"status\":\"" + status + "\",";
buffer2send += "\"total\":\"" +
ESP_FileSystem::formatBytes(ESP_FileSystem::totalBytes()) +
"\",";
buffer2send += "\"used\":\"" +
ESP_FileSystem::formatBytes(ESP_FileSystem::usedBytes()) +
"\"}";
path = "";
_webserver->sendContent_P(buffer2send.c_str(), buffer2send.length());
_webserver->sendContent("");
_upload_status = UPLOAD_STATUS_NONE;
}
#endif // HTTP_FEATURE && FILESYSTEM_FEATURE

View File

@@ -0,0 +1,137 @@
/*
handle-login.cpp - ESP3D http handle
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
*/
#include "../../../include/esp3d_config.h"
#if defined(HTTP_FEATURE)
#include "../http_server.h"
#if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif // ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif // ARDUINO_ARCH_ESP8266
#include "../../../core/esp3doutput.h"
#include "../../../core/settings_esp3d.h"
#include "../../authentication/authentication_service.h"
// login status check
void HTTP_Server::handle_login() {
HTTP_Server::set_http_headers();
#ifdef AUTHENTICATION_FEATURE
int code = 401;
String status = "Wrong authentication!";
// Disconnect can be done anytime no need to check credential
if (_webserver->hasArg("DISCONNECT") &&
_webserver->arg("DISCONNECT") == "YES") {
AuthenticationService::ClearCurrentSession();
_webserver->sendHeader("Set-Cookie", "ESPSESSIONID=0");
_webserver->sendHeader("Cache-Control", "no-cache");
_webserver->send(
401, "application/json",
"{\"status\":\"disconnected\",\"authentication_lvl\":\"guest\"}");
return;
}
level_authenticate_type auth_level =
AuthenticationService::authenticated_level();
// check is it is a submission or a query
if (_webserver->hasArg("SUBMIT")) {
// is there a correct list of query?
if (_webserver->hasArg("PASSWORD") && _webserver->hasArg("USER")) {
// User
String sUser = _webserver->arg("USER");
// Password
String sPassword = _webserver->arg("PASSWORD");
if ((((sUser == DEFAULT_ADMIN_LOGIN) &&
(AuthenticationService::isadmin(sPassword.c_str()))) ||
((sUser == DEFAULT_USER_LOGIN) &&
(AuthenticationService::isuser(sPassword.c_str()))))) {
// check if it is to change password or login
if (_webserver->hasArg("NEWPASSWORD")) {
String newpassword = _webserver->arg("NEWPASSWORD");
// check new password
if (Settings_ESP3D::isLocalPasswordValid(newpassword.c_str())) {
if (!Settings_ESP3D::write_string(ESP_ADMIN_PWD,
newpassword.c_str())) {
code = 500;
status = "Set failed!";
} else {
code = 200;
status = "ok";
}
} else {
code = 500;
status = "Incorrect password!";
}
} else { // do authentication
// allow to change session timeout when login
if (_webserver->hasArg("TIMEOUT")) {
String timeout = _webserver->arg("TIMEOUT");
AuthenticationService::setSessionTimeout(timeout.toInt());
}
// it is a change or same level
if (((auth_level == LEVEL_USER) && (sUser == DEFAULT_USER_LOGIN)) ||
((auth_level == LEVEL_ADMIN) && (sUser == DEFAULT_ADMIN_LOGIN))) {
code = 200;
status = "ok";
} else { // new authentication
String session = AuthenticationService::create_session_ID();
if (AuthenticationService::CreateSession(
(sUser == DEFAULT_ADMIN_LOGIN) ? LEVEL_ADMIN : LEVEL_USER,
sUser.c_str(), session.c_str())) {
AuthenticationService::ClearCurrentSession();
code = 200;
status = "ok";
String tmps = "ESPSESSIONID=";
tmps += session;
_webserver->sendHeader("Set-Cookie", tmps);
}
}
}
}
}
} else {
if (auth_level == LEVEL_USER || auth_level == LEVEL_ADMIN) {
status = "Identified";
code = 200;
}
}
_webserver->sendHeader("Cache-Control", "no-cache");
String smsg = "{\"status\":\"";
smsg += status;
smsg += "\",\"authentication_lvl\":\"";
if (auth_level == LEVEL_USER) {
smsg += "user";
} else if (auth_level == LEVEL_ADMIN) {
smsg += "admin";
} else {
smsg += "guest";
}
smsg += "\"}";
_webserver->send(code, "application/json", smsg);
return;
#else // No AUTHENTICATION_FEATURE
_webserver->sendHeader("Cache-Control", "no-cache");
_webserver->send(200, "application/json",
"{\"status\":\"ok\",\"authentication_lvl\":\"admin\"}");
#endif // AUTHENTICATION_FEATURE
}
#endif // HTTP_FEATURE

View File

@@ -28,9 +28,12 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif // ARDUINO_ARCH_ESP8266
#include "../../../core/esp3d_string.h"
#include "../../filesystem/esp_filesystem.h"
// Root of Webserver/////////////////////////////////////////////////////
void HTTP_Server::handle_root() {
HTTP_Server::set_http_headers();
String path = ESP3D_HOST_PATH;
// Some sanity check
if (path[0] != '/') {
@@ -40,7 +43,7 @@ void HTTP_Server::handle_root() {
path = path + "/";
}
path += "index.html";
String contentType = getContentType(path.c_str());
String contentType = esp3d_string::getContentType(path.c_str());
String pathWithGz = path + ".gz";
// if have a index.html or gzip version this is default root page
if ((ESP_FileSystem::exists(pathWithGz.c_str()) ||

View File

@@ -0,0 +1,69 @@
/*
handle-updatefw.cpp - ESP3D http handle
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
*/
#include "../../../include/esp3d_config.h"
#if defined(HTTP_FEATURE) && defined(WEB_UPDATE_FEATURE)
#include "../http_server.h"
#if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif // ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif // ARDUINO_ARCH_ESP8266
#include "../../../core/esp3d.h"
#include "../../authentication/authentication_service.h"
// Web Update handler
void HTTP_Server::handleUpdate() {
level_authenticate_type auth_level =
AuthenticationService::authenticated_level();
HTTP_Server::set_http_headers();
if (auth_level != LEVEL_ADMIN) {
_upload_status = UPLOAD_STATUS_NONE;
_webserver->send(401, "text/plain", "Wrong authentication!");
return;
}
String jsonfile = "{\"status\":\"";
switch (_upload_status) {
case UPLOAD_STATUS_NONE:
jsonfile += "no file";
break;
case UPLOAD_STATUS_CANCELLED:
jsonfile += "canceled";
break;
case UPLOAD_STATUS_SUCCESSFUL:
jsonfile += "ok";
break;
default:
jsonfile += "error";
break;
}
jsonfile += "\"}";
_webserver->sendHeader("Cache-Control", "no-cache");
_webserver->send(200, "application/json", jsonfile);
// if success restart
if (_upload_status == UPLOAD_STATUS_SUCCESSFUL) {
Hal::wait(1000);
Esp3D::restart_esp();
} else {
_upload_status = UPLOAD_STATUS_NONE;
}
}
#endif // HTTP_FEATURE && WEB_UPDATE_FEATURE

View File

@@ -1,100 +0,0 @@
/*
handle-command.cpp - ESP3D http handle
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
*/
#include "../../../include/esp3d_config.h"
#if defined (HTTP_FEATURE)
#include "../http_server.h"
#if defined (ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif //ARDUINO_ARCH_ESP32
#if defined (ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif //ARDUINO_ARCH_ESP8266
#include "../../authentication/authentication_service.h"
#include "../../../core/commands.h"
#include "../../../core/esp3doutput.h"
#include "../../../core/settings_esp3d.h"
const unsigned char realTimeCommands[]= {'!','~','?',0x18,0x84,0x85,0x90,0x92,0x93,0x94,0x95,0x96,0x97,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0xA0,0xA1};
bool isRealTimeCommand(unsigned char c)
{
for(unsigned int i=0; i<sizeof(realTimeCommands); i++) {
if(c==realTimeCommands[i]) {
return true;
}
}
return false;
}
//Handle web command query and send answer//////////////////////////////
void HTTP_Server::handle_web_command ()
{
level_authenticate_type auth_level = AuthenticationService::authenticated_level();
if (auth_level == LEVEL_GUEST) {
_webserver->send (401, "text/plain", "Wrong authentication!");
return;
}
//log_esp3d("Authentication = %d", auth_level);
String cmd = "";
if (_webserver->hasArg ("cmd")) {
cmd = _webserver->arg ("cmd");
ESP3DOutput output(_webserver);
if(!cmd.endsWith("\n")) {
if (Settings_ESP3D::GetFirmwareTarget() == GRBL) {
uint len = cmd.length();
if (!((len ==1 && isRealTimeCommand(cmd[0]))||(len ==2 && isRealTimeCommand(cmd[1])))) {
cmd += "\n";
} else {//no need \n for realtime command
//remove the 0XC2 that should not be there
if (len==2 && isRealTimeCommand(cmd[1])&& cmd[1]==0xC2) {
cmd[0] = cmd[1];
cmd[1] = 0x0;
}
}
} else {
cmd += "\n";//need to validate command
}
}
log_esp3d("Web Command: %s",cmd.c_str());
if (esp3d_commands.is_esp_command((uint8_t *)cmd.c_str(), cmd.length())) {
esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level);
} else {
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
ESP3DOutput outputOnly(ESP_SOCKET_SERIAL_CLIENT);
#endif//COMMUNICATION_PROTOCOL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL
ESP3DOutput outputOnly(ESP_SERIAL_CLIENT);
#endif //COMMUNICATION_PROTOCOL == SOCKET_SERIAL
_webserver->sendHeader("Cache-Control","no-cache");
#ifdef ESP_ACCESS_CONTROL_ALLOW_ORIGIN
_webserver->sendHeader("Access-Control-Allow-Origin", "*");
#endif //ESP_ACCESS_CONTROL_ALLOw_ORIGIN
//the command is not ESP3D so it will be forwarded to the serial port
//no need to wait to answer then
_webserver->send (200, "text/plain", "ESP3D says: command forwarded");
esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level,&outputOnly);
}
} else if (_webserver->hasArg ("ping")) {
_webserver->send (200);
} else {
_webserver->send (400, "text/plain", "Invalid command");
}
return;
}
#endif //HTTP_FEATURE

View File

@@ -1,212 +0,0 @@
/*
handle-files.cpp - ESP3D http handle
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
*/
#include "../../../include/esp3d_config.h"
#if defined (HTTP_FEATURE) && defined(FILESYSTEM_FEATURE)
#include "../http_server.h"
#if defined (ARDUINO_ARCH_ESP32)
#include <WebServer.h>
#endif //ARDUINO_ARCH_ESP32
#if defined (ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h>
#endif //ARDUINO_ARCH_ESP8266
#include "../../filesystem/esp_filesystem.h"
#include "../../authentication/authentication_service.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include "../../time/time_server.h"
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//Filesystem
//Filesystem files list and file commands
void HTTP_Server::handleFSFileList ()
{
level_authenticate_type auth_level = AuthenticationService::authenticated_level();
if (auth_level == LEVEL_GUEST) {
_upload_status = UPLOAD_STATUS_NONE;
_webserver->send (401, "text/plain", "Wrong authentication!");
return;
}
String path ;
String status = "ok";
if ( (_upload_status == UPLOAD_STATUS_FAILED) || (_upload_status == UPLOAD_STATUS_CANCELLED) ) {
status = "Upload failed";
_upload_status = UPLOAD_STATUS_NONE;
}
if (_webserver->hasArg ("quiet")) {
if(_webserver->arg ("quiet") == "yes") {
status = "{\"status\":\"" + status + "\"}";
_webserver->send (200, "text/plain", status.c_str());
return;
}
}
//get current path
if (_webserver->hasArg ("path") ) {
path += _webserver->arg ("path") ;
}
//to have a clean path
path.trim();
path.replace ("//", "/");
if (path[path.length() - 1] != '/') {
path += "/";
}
//check if query need some action
if (_webserver->hasArg ("action") ) {
//delete a file
if (_webserver->arg ("action") == "delete" && _webserver->hasArg ("filename") ) {
String filename;
String shortname = _webserver->arg ("filename");
shortname.replace ("/", "");
filename = path + _webserver->arg ("filename");
filename.replace ("//", "/");
if (!ESP_FileSystem::exists (filename.c_str()) ) {
status = shortname + " does not exists!";
} else {
if (ESP_FileSystem::remove (filename.c_str()) ) {
status = shortname + " deleted";
//what happen if no "/." and no other subfiles for SPIFFS like?
String ptmp = path;
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
ptmp = path.substring (0, path.length() - 1);
}
if (!ESP_FileSystem::exists (ptmp.c_str())) {
ESP_FileSystem::mkdir(ptmp.c_str());
}
} else {
status = "Cannot deleted " ;
status += shortname ;
}
}
}
//delete a directory
if (_webserver->arg ("action") == "deletedir" && _webserver->hasArg ("filename") ) {
String filename;
String shortname = _webserver->arg ("filename");
shortname.replace ("/", "");
filename = path + _webserver->arg ("filename");
filename += "/";
filename.replace ("//", "/");
if (filename != "/") {
if (ESP_FileSystem::rmdir(filename.c_str())) {
log_esp3d("Deleting %s",filename.c_str());
status = shortname ;
status += " deleted";
} else {
status = "Cannot deleted " ;
status += shortname ;
}
}
}
//create a directory
if (_webserver->arg ("action") == "createdir" && _webserver->hasArg ("filename") ) {
String filename;
filename = path + _webserver->arg ("filename");
String shortname = _webserver->arg ("filename");
shortname.replace ("/", "");
filename.replace ("//", "/");
if (ESP_FileSystem::exists (filename.c_str()) ) {
status = shortname + " already exists!";
} else {
if (!ESP_FileSystem::mkdir(filename.c_str())) {
status = "Cannot create ";
status += shortname ;
} else {
status = shortname + " created";
}
}
}
}
String buffer2send ;
buffer2send.reserve(1200);
buffer2send = "{\"files\":[";
String ptmp = path;
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
ptmp = path.substring (0, path.length() - 1);
}
_webserver->setContentLength(CONTENT_LENGTH_UNKNOWN);
_webserver->sendHeader("Content-Type","application/json");
_webserver->sendHeader("Cache-Control","no-cache");
_webserver->send(200);
if (ESP_FileSystem::exists(ptmp.c_str())) {
ESP_File f = ESP_FileSystem::open(ptmp.c_str(), ESP_FILE_READ);
//Parse files
ESP_File sub = f.openNextFile();
if (f) {
bool needseparator = false;
while (sub) {
if (needseparator) {
buffer2send+=",";
} else {
//for next entry
needseparator=true;
}
buffer2send+="{\"name\":\"";
buffer2send+=sub.name();
buffer2send+="\",\"size\":\"";
if (sub.isDirectory()) {
buffer2send+="-1";
} else {
buffer2send+=ESP_FileSystem::formatBytes(sub.size());
}
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
buffer2send+="\",\"time\":\"";
if (!sub.isDirectory()) {
buffer2send+=timeserver.current_time(sub.getLastWrite());
}
#endif //FILESYSTEM_TIMESTAMP_FEATURE
buffer2send+="\"}";
if (buffer2send.length() > 1100) {
_webserver->sendContent_P(buffer2send.c_str(),buffer2send.length());
buffer2send = "";
}
sub.close();
sub = f.openNextFile();
}
f.close();
} else {
if (status == "ok") {
status = "cannot open" + ptmp;
} else {
status += ", cannot open" + ptmp;
}
}
} else {
if (status == "ok") {
status = ptmp + " does not exists!";
} else {
status += ", " + ptmp + " does not exists!";
}
}
buffer2send += "],\"path\":\"" + path + "\",";
if (ESP_FileSystem::totalBytes()>0) {
buffer2send += "\"occupation\":\"" + String(100*ESP_FileSystem::usedBytes()/ESP_FileSystem::totalBytes()) + "\",";
} else {
status = "FileSystem Error";
buffer2send += "\"occupation\":\"0\",";
}
buffer2send += "\"status\":\"" + status + "\",";
buffer2send += "\"total\":\"" + ESP_FileSystem::formatBytes (ESP_FileSystem::totalBytes()) + "\",";
buffer2send += "\"used\":\"" + ESP_FileSystem::formatBytes (ESP_FileSystem::usedBytes()) + "\"}";
path = "";
_webserver->sendContent_P(buffer2send.c_str(),buffer2send.length());
_webserver->sendContent("");
_upload_status = UPLOAD_STATUS_NONE;
}
#endif //HTTP_FEATURE && FILESYSTEM_FEATURE

Some files were not shown because too many files have changed in this diff Show More