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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

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,362 +21,355 @@
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
const char * help[]= {"[ESP] (id) - display this help",
#if defined (WIFI_FEATURE)
"[ESP100](SSID) - display/set STA SSID",
"[ESP101](Password) - set STA password",
#endif //WIFI_FEATURE
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
"[ESP102](Mode) - display/set STA IP mode (DHCP/STATIC)",
"[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",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined (WIFI_FEATURE)
"[ESP105](SSID) - display/set AP SSID",
"[ESP106](Password) - set AP password",
"[ESP107](IP) - display/set AP IP",
"[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",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
"[ESP111](header)display current IP",
#endif //WIFI_FEATURE || ETH_FEATURE
const char* help[] = {
"[ESP] (id) - display this help",
#if defined(WIFI_FEATURE)
"[ESP100](SSID) - display/set STA SSID",
"[ESP101](Password) - set STA password",
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
"[ESP102](Mode) - display/set STA IP mode (DHCP/STATIC)",
"[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",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE)
"[ESP105](SSID) - display/set AP SSID",
"[ESP106](Password) - set AP password",
"[ESP107](IP) - display/set AP IP",
"[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",
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
"[ESP111](header)display current IP",
#endif // WIFI_FEATURE || ETH_FEATURE
#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",
#endif //WIFI_FEATURE || ETH_FEATURE || 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",
#endif // WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)
"[ESP120](State) - display/set HTTP state which can be ON, OFF",
"[ESP121](Port) - display/set HTTP port ",
#endif //HTTP_FEATURE
"[ESP120](State) - display/set HTTP state which can be ON, OFF",
"[ESP121](Port) - display/set HTTP port ",
#endif // HTTP_FEATURE
#if defined(TELNET_FEATURE)
"[ESP130](State) - display/set Telnet state which can be ON, OFF",
"[ESP131](Port) - display/set Telnet port",
#endif //TELNET_FEATURE
"[ESP130](State) - display/set Telnet state which can be ON, OFF",
"[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",
#endif //TIMESTAMP_FEATURE
"[ESP150](delay=time) (verbose=ON/OFF)- display/set boot delay in ms / Verbose boot",
"[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",
#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
"[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",
#endif //CAMERA_DEVICE
"[ESP170](json) (label=value) - display/set Camera commands",
"[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",
"[ESP181](ctrl=xxxx) (active=xxxx) (passive=xxxx) - display/set FTP ports",
#endif //FTP_FEATURE
"[ESP180](State) - display/set FTP state which can be ON, OFF",
"[ESP181](ctrl=xxxx) (active=xxxx) (passive=xxxx) - display/set FTP ports",
#endif // FTP_FEATURE
#if defined(WEBDAV_FEATURE)
"[ESP190](State) - display/set WebDav state which can be ON, OFF",
"[ESP191](Port) - display/set WebDav port",
#endif //WEBDAV_FEATURE
#if defined (SD_DEVICE)
"[ESP200] (json) (RELEASE) (REFRESH)- display/set SD Card Status",
#endif //SD_DEVICE
"[ESP190](State) - display/set WebDav state which can be ON, OFF",
"[ESP191](Port) - display/set WebDav port",
#endif // WEBDAV_FEATURE
#if defined(SD_DEVICE)
"[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",
#endif //DIRECT_PIN_FEATURE
#if defined (SD_DEVICE)
"[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)",
#endif //SD_DEVICE != ESP_SDIO
#endif //SD_DEVICE
"[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",
#endif //SENSOR_DEVICE
#if defined (DISPLAY_DEVICE)
"[ESP214](text) - display (text) to ESP screen status",
"[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",
#if defined(DISPLAY_TOUCH_DRIVER)
"[ESP215](CALIBRATE) - display state / start touch calibration",
#endif //DISPLAY_TOUCH_DRIVER
#endif //DISPLAY_DEVICE
"[ESP220] - Show used pins",
"[ESP215](CALIBRATE) - display state / start touch calibration",
#endif // DISPLAY_TOUCH_DRIVER
#endif // DISPLAY_DEVICE
"[ESP220] - Show used pins",
#ifdef BUZZER_DEVICE
"[ESP250]F=(frequency) D=(duration) - play sound on buzzer",
#endif //BUZZER_DEVICE
"[ESP290](delay in ms) - do a pause",
"[ESP400] - display ESP3D settings in JSON",
"[ESP401]P=(position) T=(type) V=(value) - Set specific setting",
"[ESP250]F=(frequency) D=(duration) - play sound on buzzer",
#endif // BUZZER_DEVICE
"[ESP290](delay in ms) - do a pause",
"[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",
#endif //SD_UPDATE_FEATURE
#if defined (WIFI_FEATURE)
"[ESP410]display available AP list (limited to 30) in plain/JSON",
#endif //WIFI_FEATURE
"[ESP420]display ESP3D current status in plain/JSON",
"[ESP444](Cmd) - set ESP3D state (RESET/RESTART)",
"[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",
#endif // WIFI_FEATURE
"[ESP420]display ESP3D current status in plain/JSON",
"[ESP444](Cmd) - set ESP3D state (RESET/RESTART)",
#ifdef MDNS_FEATURE
"[ESP450]display ESP3D list on network",
#endif //MDNS_FEATURE
#if defined (AUTHENTICATION_FEATURE)
"[ESP550](password) - change admin password",
"[ESP555](password) - change user password",
#endif //AUTHENTICATION_FEATURE
"[ESP450]display ESP3D list on network",
#endif // MDNS_FEATURE
#if defined(AUTHENTICATION_FEATURE)
"[ESP550](password) - change admin password",
"[ESP555](password) - change user password",
#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",
"[ESP620]URL=http://XXXXXX - send GET notification",
#endif //NOTIFICATION_FEATURE
"[ESP600](message) - send notification",
"[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)
"[ESP700](filename) - read ESP Filesystem file",
"[ESP701]action=(PAUSE/RESUME/ABORT) - query and control ESP700 stream",
#endif //GCODE_HOST_FEATURE
"[ESP700](filename) - read ESP Filesystem file",
"[ESP701]action=(PAUSE/RESUME/ABORT) - query and control ESP700 stream",
#endif // GCODE_HOST_FEATURE
#if defined(FILESYSTEM_FEATURE)
"[ESP710]FORMATFS - Format ESP Filesystem",
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
"[ESP715]FORMATSD - Format SD Filesystem",
#endif //SD_DEVICE
"[ESP710]FORMATFS - Format ESP Filesystem",
#endif // FILESYSTEM_FEATURE
#if defined(SD_DEVICE)
"[ESP715]FORMATSD - Format SD Filesystem",
#endif // SD_DEVICE
#if defined(FILESYSTEM_FEATURE)
"[ESP720](path) - List ESP Filesystem",
"[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)",
#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)",
#endif //GLOBAL_FILESYSTEM_FEATURE
"[ESP800](time=YYYY-MM-DDTHH:mm:ss)(version=3.0.0-a11)(setup=0/1) - display FW Informations /set time",
"[ESP720](path) - List ESP Filesystem",
"[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)",
#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)",
#endif // GLOBAL_FILESYSTEM_FEATURE
"[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",
#endif //COMMUNICATION_PROTOCOL != SOCKET_SERIAL
"[ESP900](ENABLE/DISABLE) - display/set serial state",
"[ESP901]<BAUD RATE> - display/set serial baud rate",
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
#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",
"[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",
#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)
"[ESP999](QUIETBOOT) [pwd=<admin/user password>] - set quiet boot mode",
#endif //ARDUINO_ARCH_ESP32
""
};
const uint cmdlist[]= {0,
#if defined (WIFI_FEATURE)
100,
101,
#endif //WIFI_FEATURE
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
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,
#endif //WIFI_FEATURE
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
110,
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined( WIFI_FEATURE) || defined (ETH_FEATURE)
111,
#endif //WIFI_FEATURE || ETH_FEATURE
"[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)
"[ESP999](QUIETBOOT) [pwd=<admin/user password>] - set quiet boot mode",
#endif // ARDUINO_ARCH_ESP32
""};
const uint cmdlist[] = {0,
#if defined(WIFI_FEATURE)
100, 101,
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
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,
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
110,
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
111,
#endif // WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
112,
114,
115,
#endif //WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
112, 114, 115,
#endif // WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)
120,
121,
#endif //HTTP_FEATURE
120, 121,
#endif // HTTP_FEATURE
#if defined(TELNET_FEATURE)
130,
131,
#endif //TELNET_FEATURE
130, 131,
#endif // TELNET_FEATURE
#if defined(TIMESTAMP_FEATURE)
140,
#endif //TIMESTAMP_FEATURE
150,
140,
#endif // TIMESTAMP_FEATURE
150,
#if defined(WS_DATA_FEATURE)
160,
161,
#endif //WS_DATA_FEATURE
160, 161,
#endif // WS_DATA_FEATURE
#if defined(CAMERA_DEVICE)
170,
171,
#endif //CAMERA_DEVICE
170, 171,
#endif // CAMERA_DEVICE
#if defined(FTP_FEATURE)
180,
181,
#endif //FTP_FEATURE
180, 181,
#endif // FTP_FEATURE
#if defined(WEBDAV_FEATURE)
190,
191,
#endif //WEBDAV_FEATURE
#if defined (SD_DEVICE)
200,
#endif //SD_DEVICE
190, 191,
#endif // WEBDAV_FEATURE
#if defined(SD_DEVICE)
200,
#endif // SD_DEVICE
#ifdef DIRECT_PIN_FEATURE
201,
#endif //DIRECT_PIN_FEATURE
#if defined (SD_DEVICE) && SD_DEVICE != ESP_SDIO
202,
#endif //SD_DEVICE
201,
#endif // DIRECT_PIN_FEATURE
#if defined(SD_DEVICE) && SD_DEVICE != ESP_SDIO
202,
#endif // SD_DEVICE
#ifdef SENSOR_DEVICE
210,
#endif //SENSOR_DEVICE
#if defined (DISPLAY_DEVICE)
214,
210,
#endif // SENSOR_DEVICE
#if defined(DISPLAY_DEVICE)
214,
#if defined(DISPLAY_TOUCH_DRIVER)
215,
#endif //DISPLAY_TOUCH_DRIVER
#endif //DISPLAY_DEVICE
220,
215,
#endif // DISPLAY_TOUCH_DRIVER
#endif // DISPLAY_DEVICE
220,
#ifdef BUZZER_DEVICE
250,
#endif //BUZZER_DEVICE
290,
400,
401,
#if defined (WIFI_FEATURE)
410,
#endif //WIFI_FEATURE
420,
444,
250,
#endif // BUZZER_DEVICE
290, 400, 401,
#if defined(WIFI_FEATURE)
410,
#endif // WIFI_FEATURE
420, 444,
#ifdef MDNS_FEATURE
450,
#endif //MDNS_FEATURE
#if defined (AUTHENTICATION_FEATURE)
550,
555,
#endif //AUTHENTICATION_FEATURE
450,
#endif // MDNS_FEATURE
#if defined(AUTHENTICATION_FEATURE)
550, 555,
#endif // AUTHENTICATION_FEATURE
#if defined(NOTIFICATION_FEATURE)
600,
610,
620,
#endif //NOTIFICATION_FEATURE
600, 610, 620,
#endif // NOTIFICATION_FEATURE
#if defined(GCODE_HOST_FEATURE)
700,
701,
#endif //GCODE_HOST_FEATURE
700, 701,
#endif // GCODE_HOST_FEATURE
#if defined(FILESYSTEM_FEATURE)
710,
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
715,
#endif //SD_DEVICE
710,
#endif // FILESYSTEM_FEATURE
#if defined(SD_DEVICE)
715,
#endif // SD_DEVICE
#if defined(FILESYSTEM_FEATURE)
720,
730,
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
740,
750,
#endif //SD_DEVICE
#if defined (GLOBAL_FILESYSTEM_FEATURE)
780,
790,
#endif //GLOBAL_FILESYSTEM_FEATURE
800,
720, 730,
#endif // FILESYSTEM_FEATURE
#if defined(SD_DEVICE)
740, 750,
#endif // SD_DEVICE
#if defined(GLOBAL_FILESYSTEM_FEATURE)
780, 790,
#endif // GLOBAL_FILESYSTEM_FEATURE
800,
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL
900,
901,
#endif //COMMUNICATION_PROTOCOL != SOCKET_SERIAL
900, 901,
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
#ifdef BUZZER_DEVICE
910,
910,
#endif //BUZZER_DEVICE
920,
#endif // BUZZER_DEVICE
920,
#if defined(ESP_SERIAL_BRIDGE_OUTPUT)
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)
999,
#endif //ARDUINO_ARCH_ESP32 && CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
0
};
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)
999,
#endif // ARDUINO_ARCH_ESP32 && CONFIG_IDF_TARGET_ESP32S3 ||
// CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
0};
//ESP3D Help
// ESP3D Help
//[ESP0] or [ESP]<command>
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*);
(void)auth_type;
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 {
output->printMSGLine("[List of ESP3D commands]");
}
for (uint i = 0; i < cmdNb -1; i++) {
if (json) {
output->print("{\"id\":\"");
output->print(String(cmdlist[i]).c_str());
output->print("\",\"help\":\"");
output->print(String(help[i]).c_str());
output->print("\"}");
if (i < cmdNb - 2) {
output->print(",");
}
} else {
output->printMSGLine(help[i]);
}
}
if (json) {
output->printLN("]}");
}
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*);
(void)auth_type;
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 {
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));
output->printLN(s.c_str());
return false;
}
for (uint i = 0; i < cmdNb-1; i++) {
if (cmdlist[i] == cmdval) {
if (json) {
output->print("{\"cmd\":\"0\",\"status\":\"ok\",\"data\":{\"id\":\"");
output->print(String(cmdval).c_str());
output->print("\",\"help\":\"");
output->print(help[i]);
output->printLN("\"}}");
} else {
output->printMSGLine(help[i]);
}
found = true;
}
}
if (!found) {
String msg = "This command is not supported: ";
msg+= parameter;
noError=false;
String response = format_response(0, json, noError, msg.c_str());
if (json) {
output->printLN (response.c_str() );
} else {
output->printERROR (response.c_str() );
}
}
output->printMSGLine("[List of ESP3D commands]");
}
return noError;
for (uint i = 0; i < cmdNb - 1; i++) {
if (json) {
output->print("{\"id\":\"");
output->print(String(cmdlist[i]).c_str());
output->print("\",\"help\":\"");
output->print(String(help[i]).c_str());
output->print("\"}");
if (i < cmdNb - 2) {
output->print(",");
}
} else {
output->printMSGLine(help[i]);
}
}
if (json) {
output->printLN("]}");
}
} else {
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));
output->printLN(s.c_str());
return false;
}
for (uint i = 0; i < cmdNb - 1; i++) {
if (cmdlist[i] == cmdval) {
if (json) {
output->print("{\"cmd\":\"0\",\"status\":\"ok\",\"data\":{\"id\":\"");
output->print(String(cmdval).c_str());
output->print("\",\"help\":\"");
output->print(help[i]);
output->printLN("\"}}");
} else {
output->printMSGLine(help[i]);
}
found = true;
}
}
if (!found) {
String msg = "This command is not supported: ";
msg += parameter;
noError = false;
String response = format_response(0, json, noError, msg.c_str());
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str());
}
}
}
return noError;
}

View File

@ -18,70 +18,75 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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)
{
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
#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) {
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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));
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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));
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (!WiFiConfig::isSSIDValid (parameter.c_str() ) ) {
response = format_response(COMMANDID, json, false, "Incorrect SSID");
noError = false;
} else {
if(!Settings_ESP3D::write_string(ESP_STA_SSID, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!WiFiConfig::isSSIDValid(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect SSID");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_string(ESP_STA_SSID, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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
#endif // WIFI_FEATURE

View File

@ -18,64 +18,71 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
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");
noError = false;
} else {
if(!Settings_ESP3D::write_string(ESP_STA_PASSWORD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
#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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
response =
format_response(COMMANDID, json, false, "Password not displayable");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
if (clearSetting) {
parameter = "";
}
if (!WiFiConfig::isPasswordValid(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "Incorrect password");
noError = false;
} else {
if (!Settings_ESP3D::write_string(ESP_STA_PASSWORD,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
return 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
#endif // WIFI_FEATURE

View File

@ -18,85 +18,90 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
#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)
#if defined(WIFI_FEATURE)
#include "../../modules/wifi/wificonfig.h"
#endif //WIFI_FEATURE
#if defined (ETH_FEATURE)
#endif // WIFI_FEATURE
#if defined(ETH_FEATURE)
#include "../../modules/ethernet/ethconfig.h"
#endif //ETH_FEATURE
#endif // ETH_FEATURE
#include "../../modules/authentication/authentication_service.h"
#define COMMANDID 102
//Change STA IP mode (DHCP/STATIC)
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
int8_t resp = Settings_ESP3D::read_byte(ESP_STA_IP_MODE);
if (resp == DHCP_MODE) {
response = format_response(COMMANDID, json, true, "DHCP");
} else if (resp == STATIC_IP_MODE) {
response = format_response(COMMANDID, json, true, "STATIC");
} else {
noError = false;
response = format_response(COMMANDID, json, true, "Unknow");
}
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
int8_t resp = Settings_ESP3D::read_byte(ESP_STA_IP_MODE);
if (resp == DHCP_MODE) {
response = format_response(COMMANDID, json, true, "DHCP");
} else if (resp == STATIC_IP_MODE) {
response = format_response(COMMANDID, json, true, "STATIC");
} else {
noError = false;
response = format_response(COMMANDID, json, true, "Unknow");
}
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "STATIC") || (parameter == "DHCP"))) {
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;
if (!Settings_ESP3D::write_byte(ESP_STA_IP_MODE, bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "STATIC") || (parameter == "DHCP"))) {
response = format_response(COMMANDID, json, false,
"only STATIC or DHCP mode supported");
noError = false;
} else {
output->printMSG (response.c_str() );
uint8_t bbuf = (parameter == "DHCP") ? DHCP_MODE : STATIC_IP_MODE;
if (!Settings_ESP3D::write_byte(ESP_STA_IP_MODE, bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 || ETH_FEATURE
#endif // WIFI_FEATURE || ETH_FEATURE

View File

@ -18,124 +18,132 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE)
#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)
#if defined(WIFI_FEATURE)
#include "../../modules/wifi/wificonfig.h"
#endif //WIFI_FEATURE
#if defined (ETH_FEATURE)
#endif // WIFI_FEATURE
#if defined(ETH_FEATURE)
#include "../../modules/ethernet/ethconfig.h"
#endif //ETH_FEATURE
#endif // ETH_FEATURE
#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)
{
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
#define COMMANDID 103
// Change STA IP/Mask/GW
//[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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
String res;
if (json) {
res += "{\"ip\":\"";
} else {
res += "IP:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_IP_VALUE);
if (json) {
res += "\",\"gw\":\"";
} else {
res += ", GW:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_GATEWAY_VALUE);
if (json) {
res += "\",\"msk\":\"";
} else {
res += ", MSK:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_MASK_VALUE);
if (json) {
res += "\",\"dns\":\"";
} else {
res += ", DNS:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_DNS_VALUE);
if (json) {
res += "\"}";
}
response = format_response(COMMANDID, json, true, res.c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
String res;
if(json) {
res+= "{\"ip\":\"";
} else {
res+= "IP:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_IP_VALUE);
if(json) {
res+= "\",\"gw\":\"";
} else {
res += ", GW:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_GATEWAY_VALUE);
if(json) {
res+= "\",\"msk\":\"";
} else {
res += ", MSK:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_MASK_VALUE);
if(json) {
res+= "\",\"dns\":\"";
} else {
res += ", DNS:";
}
res += Settings_ESP3D::read_IP_String(ESP_STA_DNS_VALUE);
if(json) {
res+= "\"}";
}
response = format_response(COMMANDID, json, true, res.c_str());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
String IP = get_param (cmd_params, "IP=");
String GW = get_param (cmd_params, "GW=");
String MSK = get_param (cmd_params, "MSK=");
String DNS = get_param (cmd_params, "DNS=");
if ( !NetConfig::isValidIP(IP.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false;
}
if ( !NetConfig::isValidIP(GW.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect gateway");
noError = false;
}
if ( !NetConfig::isValidIP(MSK.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect mask");
noError = false;
}
if ( !NetConfig::isValidIP(DNS.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect dns");
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())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
String IP = get_param(cmd_params, "IP=");
String GW = get_param(cmd_params, "GW=");
String MSK = get_param(cmd_params, "MSK=");
String DNS = get_param(cmd_params, "DNS=");
if (!NetConfig::isValidIP(IP.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
if (!NetConfig::isValidIP(GW.c_str())) {
response =
format_response(COMMANDID, json, false, "Incorrect gateway");
noError = false;
}
if (!NetConfig::isValidIP(MSK.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect mask");
noError = false;
}
if (!NetConfig::isValidIP(DNS.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect dns");
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())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}
#endif //WIFI_FEATURE || ETH_FEATURE
#endif // WIFI_FEATURE || ETH_FEATURE

View File

@ -18,111 +18,116 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
#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
#define COMMANDID 104
// 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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
int8_t wifiMode = Settings_ESP3D::read_byte(ESP_STA_FALLBACK_MODE);
if (wifiMode == ESP_NO_NETWORK) {
response = format_response(COMMANDID, json, true, "OFF");
} else if (wifiMode == ESP_BT) {
response = format_response(COMMANDID, json, true, "BT");
} else if (wifiMode == ESP_AP_SETUP) {
response = format_response(COMMANDID, json, true, "WIFI-SETUP");
} else {
response = format_response(COMMANDID, json, true, "???");
}
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
int8_t wifiMode = Settings_ESP3D::read_byte(ESP_STA_FALLBACK_MODE);
if (wifiMode == ESP_NO_NETWORK) {
response = format_response(COMMANDID, json, true, "OFF");
} else if (wifiMode == ESP_BT) {
response = format_response(COMMANDID, json, true, "BT");
} else if (wifiMode == ESP_AP_SETUP) {
response = format_response(COMMANDID, json, true, "WIFI-SETUP");
} else {
response = format_response(COMMANDID, json, true, "???");
}
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!(
#if defined( BLUETOOTH_FEATURE)
(parameter == "BT") ||
#endif //BLUETOOTH_FEATURE
#if defined( WIFI_FEATURE)
(parameter == "WIFI-SETUP") ||
#endif //WIFI_FEATURE
#if defined( ETH_FEATURE)
(parameter == "ETH-STA") || //(parameter == "ETH-SRV") ||
#endif //ETH_FEATURE
(parameter == "OFF"))) {
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!(
#if defined(BLUETOOTH_FEATURE)
(parameter == "BT") ||
#endif // BLUETOOTH_FEATURE
#if defined(WIFI_FEATURE)
(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
"BT or "
#endif // BLUETOOTH_FEATURE
#ifdef WIFI_FEATURE
"WIFI-SETUP or "
#endif //WIFI_FEATURE
"OFF mode supported!";
response = format_response(COMMANDID, json, false, res.c_str());
noError = false;
}
if (noError) {
int8_t bbuf = ESP_NO_NETWORK;
"WIFI-SETUP or "
#endif // WIFI_FEATURE
"OFF mode supported!";
response = format_response(COMMANDID, json, false, res.c_str());
noError = false;
}
if (noError) {
int8_t bbuf = ESP_NO_NETWORK;
#ifdef WIFI_FEATURE
if(parameter == "WIFI-SETUP") {
bbuf = ESP_AP_SETUP;
}
#endif //WIFI_FEATURE
if (parameter == "WIFI-SETUP") {
bbuf = ESP_AP_SETUP;
}
#endif // WIFI_FEATURE
#ifdef BLUETOOTH_FEATURE
if(parameter == "BT") {
bbuf = ESP_BT;
}
#endif //BLUETOOTH_FEATURE
if (!Settings_ESP3D::write_byte(ESP_STA_FALLBACK_MODE, bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
if (parameter == "BT") {
bbuf = ESP_BT;
}
#endif // BLUETOOTH_FEATURE
if (!Settings_ESP3D::write_byte(ESP_STA_FALLBACK_MODE, bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}
#endif //WIFI_FEATURE
#endif // WIFI_FEATURE

View File

@ -18,71 +18,75 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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 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
#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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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));
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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));
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (!WiFiConfig::isSSIDValid (parameter.c_str() ) ) {
response = format_response(COMMANDID, json, false, "Incorrect SSID");
noError = false;
} else {
if(!Settings_ESP3D::write_string(ESP_AP_SSID, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!WiFiConfig::isSSIDValid(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect SSID");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_string(ESP_AP_SSID, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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
#endif // WIFI_FEATURE

View File

@ -18,65 +18,69 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
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, "Set failed");
noError = false;
} else {
if(!Settings_ESP3D::write_string(ESP_AP_PASSWORD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
response =
format_response(COMMANDID, json, false, "Password not displayable");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
if (clearSetting) {
parameter = "";
}
if (!WiFiConfig::isPasswordValid(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
if (!Settings_ESP3D::write_string(ESP_AP_PASSWORD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
return 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
#endif // WIFI_FEATURE

View File

@ -18,70 +18,77 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
if ( !NetConfig::isValidIP(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false;
}
if ( !Settings_ESP3D::write_IP_String(ESP_AP_IP_VALUE, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!NetConfig::isValidIP(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.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 {
output->printMSG (response.c_str() );
response = format_response(COMMANDID, json, true, "ok");
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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
#endif // WIFI_FEATURE

View File

@ -18,71 +18,79 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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");
noError = false;
} else {
if (!Settings_ESP3D::write_byte (ESP_AP_CHANNEL, (int8_t)bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_byte(ESP_AP_CHANNEL, (int8_t)bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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
#endif // WIFI_FEATURE

View File

@ -18,141 +18,148 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined( WIFI_FEATURE) || defined( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
int8_t wifiMode = Settings_ESP3D::read_byte(ESP_RADIO_MODE);
if (wifiMode == ESP_NO_NETWORK) {
response = format_response(COMMANDID, json, true, "OFF");
} else if (wifiMode == ESP_BT) {
response = format_response(COMMANDID, json, true, "BT");
} else if (wifiMode == ESP_WIFI_AP) {
response = format_response(COMMANDID, json, true, "WIFI-AP");
} else if (wifiMode == ESP_WIFI_STA) {
response = format_response(COMMANDID, json, true, "WIFI-STA");
// } else if (wifiMode == ESP_ETH_SRV) {
// output->printMSG("ETH-SRV");
} else if (wifiMode == ESP_ETH_STA) {
response = format_response(COMMANDID, json, true, "ETH-STA");
} else if (wifiMode == ESP_AP_SETUP) {
response = format_response(COMMANDID, json, true, "WIFI-SETUP");
} else {
response = format_response(COMMANDID, json, true, "???");
}
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
int8_t wifiMode = Settings_ESP3D::read_byte(ESP_RADIO_MODE);
if (wifiMode == ESP_NO_NETWORK) {
response = format_response(COMMANDID, json, true, "OFF");
} else if (wifiMode == ESP_BT) {
response = format_response(COMMANDID, json, true, "BT");
} else if (wifiMode == ESP_WIFI_AP) {
response = format_response(COMMANDID, json, true, "WIFI-AP");
} else if (wifiMode == ESP_WIFI_STA) {
response = format_response(COMMANDID, json, true, "WIFI-STA");
// } else if (wifiMode == ESP_ETH_SRV) {
// output->printMSG("ETH-SRV");
} else if (wifiMode == ESP_ETH_STA) {
response = format_response(COMMANDID, json, true, "ETH-STA");
} else if (wifiMode == ESP_AP_SETUP) {
response = format_response(COMMANDID, json, true, "WIFI-SETUP");
} else {
response = format_response(COMMANDID, json, true, "???");
}
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!(
#if defined( BLUETOOTH_FEATURE)
(parameter == "BT") ||
#endif //BLUETOOTH_FEATURE
#if defined( WIFI_FEATURE)
(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"))) {
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!(
#if defined(BLUETOOTH_FEATURE)
(parameter == "BT") ||
#endif // BLUETOOTH_FEATURE
#if defined(WIFI_FEATURE)
(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
"BT or "
#endif // BLUETOOTH_FEATURE
#ifdef WIFI_FEATURE
"WIFI-STA or WIFI-AP or WIFI-SETUP or "
#endif //WIFI_FEATURE
"WIFI-STA or WIFI-AP or WIFI-SETUP or "
#endif // WIFI_FEATURE
#ifdef ETH_FEATURE
"ETH-STA or "
#endif //ETH_FEATURE
"OFF mode supported!";
response = format_response(COMMANDID, json, false, res.c_str());
noError = false;
}
if (noError) {
int8_t bbuf = ESP_NO_NETWORK;
"ETH-STA or "
#endif // ETH_FEATURE
"OFF mode supported!";
response = format_response(COMMANDID, json, false, res.c_str());
noError = false;
}
if (noError) {
int8_t bbuf = ESP_NO_NETWORK;
#ifdef WIFI_FEATURE
if(parameter == "WIFI-STA") {
bbuf = ESP_WIFI_STA;
}
if(parameter == "WIFI-AP") {
bbuf = ESP_WIFI_AP;
}
if(parameter == "WIFI-SETUP") {
bbuf = ESP_AP_SETUP;
}
#endif //WIFI_FEATURE
if (parameter == "WIFI-STA") {
bbuf = ESP_WIFI_STA;
}
if (parameter == "WIFI-AP") {
bbuf = ESP_WIFI_AP;
}
if (parameter == "WIFI-SETUP") {
bbuf = ESP_AP_SETUP;
}
#endif // WIFI_FEATURE
#ifdef ETH_FEATURE
if(parameter == "ETH-STA") {
bbuf = ESP_ETH_STA;
}
if (parameter == "ETH-STA") {
bbuf = ESP_ETH_STA;
}
// if(parameter == "ETH-SRV") {
// bbuf = ESP_ETH_SRV;
// }
#endif //ETH_FEATURE
#endif // ETH_FEATURE
#ifdef BLUETOOTH_FEATURE
if(parameter == "BT") {
bbuf = ESP_BT;
}
#endif //BLUETOOTH_FEATURE
if (!Settings_ESP3D::write_byte(ESP_RADIO_MODE, bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
if (!NetConfig::begin()) {
response = format_response(COMMANDID, json, false, "Cannot setup network");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
if (parameter == "BT") {
bbuf = ESP_BT;
}
#endif // BLUETOOTH_FEATURE
if (!Settings_ESP3D::write_byte(ESP_RADIO_MODE, bbuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
if (!NetConfig::begin()) {
response = format_response(COMMANDID, json, false,
"Cannot setup network");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}
#endif //WIFI_FEATURE
#endif // WIFI_FEATURE

View File

@ -59,7 +59,11 @@ bool Commands::ESP111(const char* cmd_params, level_authenticate_type auth_type,
}
}
} else {
output->printERROR(response.c_str(), 200);
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), 200);
}
}
return noError;
}

View File

@ -19,69 +19,75 @@
*/
#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
// 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 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
#define COMMANDID 112
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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));
} else { // set host name
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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));
} else { //set host name
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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");
noError = false;
} else {
if (!Settings_ESP3D::write_string (ESP_HOSTNAME, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!NetConfig::isHostnameValid(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "Incorrect hostname");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_string(ESP_HOSTNAME, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 || ETH_FEATURE || BT_FEATURE
#endif // WIFI_FEATURE || ETH_FEATURE || BT_FEATURE

View File

@ -19,70 +19,79 @@
*/
#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
// 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 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
#define COMMANDID 114
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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"))) {
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF mode supported");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_byte(ESP_BOOT_RADIO_STATE,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
#endif // defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)

View File

@ -19,75 +19,82 @@
*/
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
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");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
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");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if ((parameter == "ON") || (parameter == "OFF")) {
if (parameter == "ON") {
if (!NetConfig::begin()) {
response = format_response(COMMANDID, json, false,
"Cannot setup network");
noError = false;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if((parameter == "ON") || (parameter == "OFF")) {
if (parameter == "ON") {
if (!NetConfig::begin()) {
response = format_response(COMMANDID, json, false, "Cannot setup network");
noError = false;
}
} else {
NetConfig::end();
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
} else {
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 {
NetConfig::end();
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
} else {
output->printMSG (response.c_str() );
response = format_response(COMMANDID, json, false,
"Only mode ON and OFF are supported");
noError = false;
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 || ETH_FEATURE || BT_FEATURE
#endif // WIFI_FEATURE || ETH_FEATURE || BT_FEATURE

View File

@ -18,70 +18,78 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (HTTP_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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"))) {
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF mode supported!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_byte(ESP_HTTP_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //HTTP_FEATURE
#endif // HTTP_FEATURE

View File

@ -18,70 +18,77 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (HTTP_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_HTTP_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_uint32(ESP_HTTP_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //HTTP_FEATURE
#endif // HTTP_FEATURE

View File

@ -18,75 +18,84 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (TELNET_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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!");
noError = false;
} else {
if (parameter == "CLOSE") {
telnet_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte (ESP_TELNET_ON, (parameter == "ON")?1:0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (parameter == "CLOSE") {
telnet_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte(ESP_TELNET_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //TELNET_FEATURE
#endif // TELNET_FEATURE

View File

@ -18,69 +18,76 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (TELNET_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_TELNET_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_uint32(ESP_TELNET_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //TELNET_FEATURE
#endif // TELNET_FEATURE

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,33 +233,33 @@ 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 {
output->printMSG(response.c_str());
}
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
if (noError) {
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@ -18,110 +18,120 @@
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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
String s = "";
if (json) {
s += "{\"delay\":\"";
} else {
s += "delay=";
}
s += String(Settings_ESP3D::read_uint32(ESP_BOOT_DELAY));
if (json) {
s += "\",\"verbose\":\"";
} else {
s += ", verbose=";
}
s += Settings_ESP3D::isVerboseBoot(true) ? "ON" : "OFF";
if (json) {
s += "\"}";
}
response = format_response(COMMANDID, json, true, s.c_str());
} else {
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
String s ="";
if(json) {
s += "{\"delay\":\"";
} else {
s+= "delay=";
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
bool hasParameter = false;
parameter = get_param(cmd_params, "delay=");
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");
noError = false;
}
if (noError) {
if (!Settings_ESP3D::write_uint32(ESP_BOOT_DELAY, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
s+= String(Settings_ESP3D::read_uint32(ESP_BOOT_DELAY));
if(json) {
s += "\",\"verbose\":\"";
} else {
s+= ", verbose=";
}
s+= Settings_ESP3D::isVerboseBoot(true)?"ON":"OFF";
if(json) {
s += "\"}";
}
response = format_response(COMMANDID, json, true,s.c_str());
} else {
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
}
}
if (noError) {
parameter = get_param(cmd_params, "verbose=");
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");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
bool hasParameter = false;
parameter = get_param (cmd_params, "delay=");
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");
noError = false;
}
if (noError) {
if (!Settings_ESP3D::write_uint32 (ESP_BOOT_DELAY, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
if(noError) {
parameter = get_param (cmd_params, "verbose=");
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");
noError = false;
} else {
Settings_ESP3D::isVerboseBoot(true);
}
} else {
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");
noError = false;
} else if(noError) {
response = format_response(COMMANDID, json, true, "ok");
}
} else {
Settings_ESP3D::isVerboseBoot(true);
}
} else {
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");
noError = false;
} else if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}

View File

@ -18,75 +18,84 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WS_DATA_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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!");
noError = false;
} else {
if (parameter == "CLOSE") {
websocket_data_server.closeClients();
} else {
if (!Settings_ESP3D::write_byte (ESP_WEBSOCKET_ON, (parameter == "ON")?1:0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (parameter == "CLOSE") {
websocket_data_server.closeClients();
} else {
if (!Settings_ESP3D::write_byte(ESP_WEBSOCKET_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //WS_DATA_FEATURE
#endif // WS_DATA_FEATURE

View File

@ -18,69 +18,76 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WS_DATA_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_WEBSOCKET_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_uint32(ESP_WEBSOCKET_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //WS_DATA_FEATURE
#endif // WS_DATA_FEATURE

View File

@ -18,471 +18,482 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (CAMERA_DEVICE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "esp_camera.h"
#include "../settings_esp3d.h"
#if defined(CAMERA_DEVICE)
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/camera/camera.h"
#define COMMANDID 170
//Set Camera command value / list all values in JSON/plain
#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
// /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 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
// 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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if(noError) {
if (!esp3d_camera.started()) {
response = format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
sensor_t * s = esp_camera_sensor_get();
if (s == nullptr) {
response = format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
String line = "";
if (json) {
output->print ("{\"cmd\":\"170\",\"status\":\"ok\",\"data\":\"[");
}
//framesize
if (json) {
line +="{\"id\":\"framesize\",\"value\":\"";
} else {
line +="framesize:";
}
line +=s->status.framesize;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//quality
if (json) {
line +="{\"id\":\"quality\",\"value\":\"";
} else {
line +="quality:";
}
line +=s->status.quality;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//brightness
if (json) {
line +="{\"id\":\"brightness\",\"value\":\"";
} else {
line +="brightness:";
}
line +=s->status.brightness;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//contrast
if (json) {
line +="{\"id\":\"contrast\",\"value\":\"";
} else {
line +="contrast:";
}
line +=s->status.contrast;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//saturation
if (json) {
line +="{\"id\":\"saturation\",\"value\":\"";
} else {
line +="saturation:";
}
line +=s->status.saturation;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//sharpness
if (json) {
line +="{\"id\":\"sharpness\",\"value\":\"";
} else {
line +="sharpness:";
}
line +=s->status.sharpness;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//special_effect
if (json) {
line +="{\"id\":\"special_effect\",\"value\":\"";
} else {
line +="special_effect:";
}
line +=s->status.special_effect;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//wb_mode
if (json) {
line +="{\"id\":\"wb_mode\",\"value\":\"";
} else {
line +="wb_mode:";
}
line +=s->status.wb_mode;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//awb
if (json) {
line +="{\"id\":\"awb\",\"value\":\"";
} else {
line +="awb:";
}
line +=s->status.awb;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//awb_gain
if (json) {
line +="{\"id\":\"awb_gain\",\"value\":\"";
} else {
line +="awb_gain:";
}
line +=s->status.awb_gain;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//aec
if (json) {
line +="{\"id\":\"aec\",\"value\":\"";
} else {
line +="aec:";
}
line +=s->status.aec;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//aec2
if (json) {
line +="{\"id\":\"aec2\",\"value\":\"";
} else {
line +="aec2:";
}
line +=s->status.aec2;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//ae_level
if (json) {
line +="{\"id\":\"ae_level\",\"value\":\"";
} else {
line +="ae_level:";
}
line +=s->status.ae_level;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//aec_value
if (json) {
line +="{\"id\":\"aec_value\",\"value\":\"";
} else {
line +="aec_value:";
}
line +=s->status.aec_value;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//agc
if (json) {
line +="{\"id\":\"agc\",\"value\":\"";
} else {
line +="agc:";
}
line +=s->status.agc;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//agc_gain
if (json) {
line +="{\"id\":\"agc_gain\",\"value\":\"";
} else {
line +="agc_gain:";
}
line +=s->status.agc_gain;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//gainceiling
if (json) {
line +="{\"id\":\"gainceiling\",\"value\":\"";
} else {
line +="gainceiling:";
}
line +=s->status.gainceiling;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//bpc
if (json) {
line +="{\"id\":\"bpc\",\"value\":\"";
} else {
line +="bpc:";
}
line +=s->status.bpc;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//wpc
if (json) {
line +="{\"id\":\"wpc\",\"value\":\"";
} else {
line +="wpc:";
}
line +=s->status.wpc;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//raw_gma
if (json) {
line +="{\"id\":\"raw_gma\",\"value\":\"";
} else {
line +="raw_gma:";
}
line +=s->status.raw_gma;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//lenc
if (json) {
line +="{\"id\":\"lenc\",\"value\":\"";
} else {
line +="lenc:";
}
line +=s->status.lenc;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//vflip
if (json) {
line +="{\"id\":\"vflip\",\"value\":\"";
} else {
line +="vflip:";
}
line +=s->status.vflip;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//hmirror
if (json) {
line +="{\"id\":\"hmirror\",\"value\":\"";
} else {
line +="hmirror:";
}
line +=s->status.hmirror;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//dcw
if (json) {
line +="{\"id\":\"dcw\",\"value\":\"";
} else {
line +="dcw:";
}
line +=s->status.dcw;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//colorbar
if (json) {
line +="{\"id\":\"colorbar\",\"value\":\"";
} else {
line +="colorbar:";
}
line +=s->status.colorbar;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#if CAM_LED_PIN != -1
//light
if (json) {
line +="{\"id\":\"light\",\"value\":\"";
} else {
line +="light:";
}
line +=digitalRead(CAM_LED_PIN)==HIGH?1:0;
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //CAM_LED_PIN
if (json) {
output->printLN ("]}");
}
return true;
}
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
String label = get_label (parameter.c_str(), "=");
if (label.length()==0) {
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");
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");
noError = false;
} else if (r == 1) {
response = format_response(COMMANDID, json, false, "Invalid value");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!esp3d_camera.started()) {
response =
format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
sensor_t* s = esp_camera_sensor_get();
if (s == nullptr) {
response =
format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
String line = "";
if (json) {
output->print("{\"cmd\":\"170\",\"status\":\"ok\",\"data\":\"[");
}
// framesize
if (json) {
line += "{\"id\":\"framesize\",\"value\":\"";
} else {
line += "framesize:";
}
line += s->status.framesize;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// quality
if (json) {
line += "{\"id\":\"quality\",\"value\":\"";
} else {
line += "quality:";
}
line += s->status.quality;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// brightness
if (json) {
line += "{\"id\":\"brightness\",\"value\":\"";
} else {
line += "brightness:";
}
line += s->status.brightness;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// contrast
if (json) {
line += "{\"id\":\"contrast\",\"value\":\"";
} else {
line += "contrast:";
}
line += s->status.contrast;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// saturation
if (json) {
line += "{\"id\":\"saturation\",\"value\":\"";
} else {
line += "saturation:";
}
line += s->status.saturation;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// sharpness
if (json) {
line += "{\"id\":\"sharpness\",\"value\":\"";
} else {
line += "sharpness:";
}
line += s->status.sharpness;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// special_effect
if (json) {
line += "{\"id\":\"special_effect\",\"value\":\"";
} else {
line += "special_effect:";
}
line += s->status.special_effect;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// wb_mode
if (json) {
line += "{\"id\":\"wb_mode\",\"value\":\"";
} else {
line += "wb_mode:";
}
line += s->status.wb_mode;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// awb
if (json) {
line += "{\"id\":\"awb\",\"value\":\"";
} else {
line += "awb:";
}
line += s->status.awb;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// awb_gain
if (json) {
line += "{\"id\":\"awb_gain\",\"value\":\"";
} else {
line += "awb_gain:";
}
line += s->status.awb_gain;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// aec
if (json) {
line += "{\"id\":\"aec\",\"value\":\"";
} else {
line += "aec:";
}
line += s->status.aec;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// aec2
if (json) {
line += "{\"id\":\"aec2\",\"value\":\"";
} else {
line += "aec2:";
}
line += s->status.aec2;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// ae_level
if (json) {
line += "{\"id\":\"ae_level\",\"value\":\"";
} else {
line += "ae_level:";
}
line += s->status.ae_level;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// aec_value
if (json) {
line += "{\"id\":\"aec_value\",\"value\":\"";
} else {
line += "aec_value:";
}
line += s->status.aec_value;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// agc
if (json) {
line += "{\"id\":\"agc\",\"value\":\"";
} else {
line += "agc:";
}
line += s->status.agc;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// agc_gain
if (json) {
line += "{\"id\":\"agc_gain\",\"value\":\"";
} else {
line += "agc_gain:";
}
line += s->status.agc_gain;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// gainceiling
if (json) {
line += "{\"id\":\"gainceiling\",\"value\":\"";
} else {
line += "gainceiling:";
}
line += s->status.gainceiling;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// bpc
if (json) {
line += "{\"id\":\"bpc\",\"value\":\"";
} else {
line += "bpc:";
}
line += s->status.bpc;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// wpc
if (json) {
line += "{\"id\":\"wpc\",\"value\":\"";
} else {
line += "wpc:";
}
line += s->status.wpc;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// raw_gma
if (json) {
line += "{\"id\":\"raw_gma\",\"value\":\"";
} else {
line += "raw_gma:";
}
line += s->status.raw_gma;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// lenc
if (json) {
line += "{\"id\":\"lenc\",\"value\":\"";
} else {
line += "lenc:";
}
line += s->status.lenc;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// vflip
if (json) {
line += "{\"id\":\"vflip\",\"value\":\"";
} else {
line += "vflip:";
}
line += s->status.vflip;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// hmirror
if (json) {
line += "{\"id\":\"hmirror\",\"value\":\"";
} else {
line += "hmirror:";
}
line += s->status.hmirror;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// dcw
if (json) {
line += "{\"id\":\"dcw\",\"value\":\"";
} else {
line += "dcw:";
}
line += s->status.dcw;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// colorbar
if (json) {
line += "{\"id\":\"colorbar\",\"value\":\"";
} else {
line += "colorbar:";
}
line += s->status.colorbar;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#if CAM_LED_PIN != -1
// light
if (json) {
line += "{\"id\":\"light\",\"value\":\"";
} else {
line += "light:";
}
line += digitalRead(CAM_LED_PIN) == HIGH ? 1 : 0;
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // CAM_LED_PIN
if (json) {
output->printLN("]}");
}
return true;
}
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
String label = get_label(parameter.c_str(), "=");
if (label.length() == 0) {
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");
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");
noError = false;
} else if (r == 1) {
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
}
return 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 //CAMERA_DEVICE
#endif // CAMERA_DEVICE

View File

@ -18,97 +18,105 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (CAMERA_DEVICE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "esp_camera.h"
#include "../settings_esp3d.h"
#if defined(CAMERA_DEVICE)
#include <time.h>
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/camera/camera.h"
#include <time.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)
{
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
String path;
String filename;
#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) {
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
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");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if(noError) {
if (!esp3d_camera.started()) {
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="));
//get filename
if (parameter.length() != 0) {
filename = parameter;
}
//if nothing provided, use default filename / path
if (path.length()==0) {
struct tm tmstruct;
time_t now;
path = "";
time(&now);
localtime_r(&now, &tmstruct);
path = String((tmstruct.tm_year)+1900) + "-";
if (((tmstruct.tm_mon)+1) < 10) {
path +="0";
}
path += String(( tmstruct.tm_mon)+1) + "-";
if (tmstruct.tm_mday < 10) {
path +="0";
}
path += String(tmstruct.tm_mday);
}
if(filename.length()==0) {
struct tm tmstruct;
time_t now;
time(&now);
localtime_r(&now, &tmstruct);
filename = String(now) + ".jpg";
}
//now send command
if(noError) {
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");
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!esp3d_camera.started()) {
response =
format_response(COMMANDID, json, false, "No camera initialized");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
parameter = clean_param(get_param(cmd_params, "path="));
// get path
if (parameter.length() != 0) {
path = parameter;
}
parameter = clean_param(get_param(cmd_params, "filename="));
// get filename
if (parameter.length() != 0) {
filename = parameter;
}
// if nothing provided, use default filename / path
if (path.length() == 0) {
struct tm tmstruct;
time_t now;
path = "";
time(&now);
localtime_r(&now, &tmstruct);
path = String((tmstruct.tm_year) + 1900) + "-";
if (((tmstruct.tm_mon) + 1) < 10) {
path += "0";
}
path += String((tmstruct.tm_mon) + 1) + "-";
if (tmstruct.tm_mday < 10) {
path += "0";
}
path += String(tmstruct.tm_mday);
}
if (filename.length() == 0) {
struct tm tmstruct;
time_t now;
time(&now);
localtime_r(&now, &tmstruct);
filename = String(now) + ".jpg";
}
// now send command
if (noError) {
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");
}
}
}
return 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 //CAMERA_DEVICE
#endif // CAMERA_DEVICE

View File

@ -18,78 +18,86 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (FTP_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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!");
noError = false;
} else {
if (parameter == "CLOSE") {
ftp_server.closeClient();
} else {
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");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (parameter == "CLOSE") {
ftp_server.closeClient();
} else {
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");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //FTP_FEATURE
#endif // FTP_FEATURE

View File

@ -18,136 +18,156 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (FTP_FEATURE)
#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)
{
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
#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) {
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
String s = "";
if (json) {
s += "{\"ctrl\":\"";
} else {
s += "ctrl=";
}
s += String(Settings_ESP3D::read_uint32(ESP_FTP_CTRL_PORT));
if (json) {
s += "\",\"active\":\"";
} else {
s += ", active=";
}
s += String(Settings_ESP3D::read_uint32(ESP_FTP_DATA_ACTIVE_PORT));
if (json) {
s += "\",\"passive\":\"";
} else {
s += ", passive=";
}
s += String(Settings_ESP3D::read_uint32(ESP_FTP_DATA_PASSIVE_PORT));
if (json) {
s += "\"}";
}
response = format_response(COMMANDID, json, true, s.c_str());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
String s = "";
if(json) {
s += "{\"ctrl\":\"";
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param(cmd_params, "ctrl=");
uint ibuf;
bool hasParam = false;
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");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32(ESP_FTP_CTRL_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
if (noError) {
parameter = get_param(cmd_params, "active=");
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");
noError = false;
} else {
s += "ctrl=";
}
s+=String(Settings_ESP3D::read_uint32(ESP_FTP_CTRL_PORT));
if(json) {
s += "\",\"active\":\"";
} else {
s += ", active=";
}
s+=String(Settings_ESP3D::read_uint32(ESP_FTP_DATA_ACTIVE_PORT));
if(json) {
s += "\",\"passive\":\"";
} else {
s += ", passive=";
}
s+=String(Settings_ESP3D::read_uint32(ESP_FTP_DATA_PASSIVE_PORT));
if(json) {
s += "\"}";
}
response = format_response(COMMANDID, json, true,s.c_str());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
if (!Settings_ESP3D::write_uint32(ESP_FTP_DATA_ACTIVE_PORT,
ibuf)) {
response =
format_response(COMMANDID, json, false, "Set failed");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param (cmd_params, "ctrl=");
uint ibuf;
bool hasParam = false;
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");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_FTP_CTRL_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
if(noError) {
parameter = get_param (cmd_params, "active=");
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");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_FTP_DATA_ACTIVE_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
}
if(noError) {
parameter = get_param (cmd_params, "passive=");
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");
noError = false;
} 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!");
noError = false;
} else {
if(noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
if (noError) {
parameter = get_param(cmd_params, "passive=");
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");
noError = false;
} 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!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //TELNET_FEATURE
#endif // TELNET_FEATURE

View File

@ -18,78 +18,87 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WEBDAV_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
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");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
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");
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!");
noError = false;
} else {
if (parameter == "CLOSE") {
webdav_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte (ESP_WEBDAV_ON, (parameter == "ON")?1:0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (parameter == "CLOSE") {
webdav_server.closeClient();
} else {
if (!Settings_ESP3D::write_byte(ESP_WEBDAV_ON,
(parameter == "ON") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //WEBDAV_FEATURE
#endif // WEBDAV_FEATURE

View File

@ -18,69 +18,76 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WEBDAV_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_WEBDAV_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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))) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_uint32(ESP_WEBDAV_PORT, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //WEBDAV_FEATURE
#endif // WEBDAV_FEATURE

View File

@ -18,75 +18,83 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_DEVICE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (releaseSD) {
ESP_SD::releaseFS();
response = format_response(COMMANDID, json, true, " SD card released");
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (releaseSD) {
ESP_SD::releaseFS();
response = format_response(COMMANDID, json, true, " SD card released");
}
if (!ESP_SD::accessFS()) {
if (ESP_SD::getState() == ESP_SDCARD_BUSY) {
response = format_response(COMMANDID, json, true, "Busy");
} else {
response = format_response(COMMANDID, json, true, "Not available");
}
} else {
int8_t state = ESP_SD::getState(true);
if (state == ESP_SDCARD_IDLE) {
response = format_response(COMMANDID, json, true, "SD card ok");
if (refreshSD) {
ESP_SD::refreshStats(true);
}
}
ESP_SD::releaseFS();
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length()!=0 && parameter.indexOf("REFRESH")==-1 && parameter.indexOf("RELEASE")==-1) {
response = format_response(COMMANDID, json, false, "Unknown parameter");
noError = false;
}
}
}
if (noError) {
if (response.length() == 0) {
response = format_response(COMMANDID, json, true, "No SD card");
}
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
if (!ESP_SD::accessFS()) {
if (ESP_SD::getState() == ESP_SDCARD_BUSY) {
response = format_response(COMMANDID, json, true, "Busy");
} else {
response = format_response(COMMANDID, json, true, "Not available");
}
} else {
output->printERROR(response.c_str(), errorCode);
int8_t state = ESP_SD::getState(true);
if (state == ESP_SDCARD_IDLE) {
response = format_response(COMMANDID, json, true, "SD card ok");
if (refreshSD) {
ESP_SD::refreshStats(true);
}
}
ESP_SD::releaseFS();
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0 && parameter.indexOf("REFRESH") == -1 &&
parameter.indexOf("RELEASE") == -1) {
response = format_response(COMMANDID, json, false, "Unknown parameter");
noError = false;
}
}
return noError;
}
if (noError) {
if (response.length() == 0) {
response = format_response(COMMANDID, json, true, "No SD card");
}
if (json) {
output->printLN(response.c_str());
} else {
output->printMSG(response.c_str());
}
} else {
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}
#endif //SD_DEVICE
#endif // SD_DEVICE

View File

@ -18,118 +18,126 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (DIRECT_PIN_FEATURE)
#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"
#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)
{
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
#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) {
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
//check if have pin
parameter = get_param (cmd_params, "P=");
log_esp3d("Pin %s", parameter.c_str());
if (parameter .length() == 0) {
response = format_response(COMMANDID, json, false, "Missing pin");
noError = false;
} else {
int pin = parameter.toInt();
//check pin is valid and not serial used pins
if ( Hal::is_pin_usable(pin)) {
bool isdigital = true;
parameter = get_param (cmd_params, "ANALOG=");
if (parameter == "YES") {
log_esp3d ("Set as analog");
isdigital=false;
}
//check if is set or get
parameter = get_param (cmd_params, "V=");
//it is a get
if (parameter.length() == 0) {
//this is to not set pin mode
int value = 0;
if(isdigital) {
parameter = get_param (cmd_params, "RAW=");
if (parameter != "YES") {
parameter = get_param (cmd_params, "PULLUP=");
if (parameter != "YES") {
Hal::pinMode (pin, INPUT);
} else {
Hal::pinMode (pin, INPUT_PULLUP);
}
}
value = digitalRead (pin);
} else {
value = Hal::analogRead(pin);
}
response = format_response(COMMANDID, json, true, String(value).c_str());
} else {
//it is a set
int value = parameter.toInt();
Hal::pinMode (pin, OUTPUT);
if (isdigital) {
//verify it is a '0' or a '1'
if ( (value == 0) || (value == 1) ) {
digitalWrite (pin, (value == 0) ? LOW : HIGH);
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Invalid value");
noError = false;
}
} else {
int analog_range= 255;
parameter = get_param (cmd_params, "ANALOG_RANGE=");
if (parameter.length() > 0) {
analog_range = parameter.toInt();
}
if ( (value >= 0) || (value <= analog_range+1) ) {
Hal::analogRange(analog_range);
Hal::analogWriteFreq(1000);
analogWrite(pin, value);
response = format_response(COMMANDID, json, false, "Invalid value");
noError = false;
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
}
} else {
response = format_response(COMMANDID, json, false, "Invalid pin");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
// check if have pin
parameter = get_param(cmd_params, "P=");
log_esp3d("Pin %s", parameter.c_str());
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Missing pin");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
int pin = parameter.toInt();
// check pin is valid and not serial used pins
if (Hal::is_pin_usable(pin)) {
bool isdigital = true;
parameter = get_param(cmd_params, "ANALOG=");
if (parameter == "YES") {
log_esp3d("Set as analog");
isdigital = false;
}
// check if is set or get
parameter = get_param(cmd_params, "V=");
// it is a get
if (parameter.length() == 0) {
// this is to not set pin mode
int value = 0;
if (isdigital) {
parameter = get_param(cmd_params, "RAW=");
if (parameter != "YES") {
parameter = get_param(cmd_params, "PULLUP=");
if (parameter != "YES") {
Hal::pinMode(pin, INPUT);
} else {
Hal::pinMode(pin, INPUT_PULLUP);
}
}
value = digitalRead(pin);
} else {
value = Hal::analogRead(pin);
}
response =
format_response(COMMANDID, json, true, String(value).c_str());
} else {
// it is a set
int value = parameter.toInt();
Hal::pinMode(pin, OUTPUT);
if (isdigital) {
// verify it is a '0' or a '1'
if ((value == 0) || (value == 1)) {
digitalWrite(pin, (value == 0) ? LOW : HIGH);
response = format_response(COMMANDID, json, true, "ok");
} else {
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
}
} else {
int analog_range = 255;
parameter = get_param(cmd_params, "ANALOG_RANGE=");
if (parameter.length() > 0) {
analog_range = parameter.toInt();
}
if ((value >= 0) || (value <= analog_range + 1)) {
Hal::analogRange(analog_range);
Hal::analogWriteFreq(1000);
analogWrite(pin, value);
response =
format_response(COMMANDID, json, false, "Invalid value");
noError = false;
} else {
response =
format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
}
} else {
response = format_response(COMMANDID, json, false, "Invalid pin");
noError = false;
}
}
return 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 //DIRECT_PIN_FEATURE
#endif // DIRECT_PIN_FEATURE

View File

@ -18,63 +18,70 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_DEVICE) && SD_DEVICE != ESP_SDIO
#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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
parameter = get_param (cmd_params, "SPEED=");
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;
} else {
ESP_SD::setSPISpeedDivider(parameter.toInt());
response = format_response(COMMANDID, json, true, "ok");
}
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
#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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
parameter = get_param(cmd_params, "SPEED=");
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;
} else {
output->printMSG (response.c_str() );
ESP_SD::setSPISpeedDivider(parameter.toInt());
response = format_response(COMMANDID, json, true, "ok");
}
} else {
output->printERROR(response.c_str(), errorCode);
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
return 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 //SD_DEVICE
#endif // SD_DEVICE

View File

@ -18,134 +18,143 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SENSOR_DEVICE)
#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)
{
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
#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) {
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
String s;
if (json) {
s = "{\"type\":\"";
} else {
s = "type=";
}
if (esp3d_sensor.started()) {
s += esp3d_sensor.GetCurrentModelString();
} else {
s += "NONE";
}
if (json) {
s += ":\",\"interval\":";
} else {
s += ", interval=";
}
s += esp3d_sensor.interval();
if (json) {
s += ":\",\"value\":";
} else {
s += "ms, value=";
}
s += esp3d_sensor.GetData();
if (json) {
s += "\"}";
}
response = format_response(COMMANDID, json, true, s.c_str());
} else {
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
String s;
if (json) {
s="{\"type\":\"";
} else {
s="type=";
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param(cmd_params, "type=");
if (parameter.length() != 0) {
hasParam = true;
parameter.toUpperCase();
int8_t v = -1;
if (parameter == "NONE") {
v = 0;
} 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");
noError = false;
}
if (v != -1) {
if (!Settings_ESP3D::write_byte(ESP_SENSOR_TYPE, v)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
if(esp3d_sensor.started()) {
s+=esp3d_sensor.GetCurrentModelString();
} else {
s+="NONE";
}
if (json) {
s+=":\",\"interval\":";
} else {
s+=", interval=";
}
s += esp3d_sensor.interval();
if (json) {
s+=":\",\"value\":";
} else {
s+="ms, value=";
}
s += esp3d_sensor.GetData();
if (json) {
s+="\"}";
}
response = format_response(COMMANDID, json, true,s.c_str());
} else {
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
if (noError) {
if (!esp3d_sensor.begin()) {
response =
format_response(COMMANDID, json, false, "Starting failed");
noError = false;
errorCode = 401;
}
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param (cmd_params, "type=");
if (parameter.length() != 0) {
hasParam=true;
parameter.toUpperCase();
int8_t v = -1;
if (parameter == "NONE") {
v = 0;
} 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");
noError = false;
}
if (v!=-1) {
if (!Settings_ESP3D::write_byte(ESP_SENSOR_TYPE,v)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
if(noError) {
if (!esp3d_sensor.begin()) {
response = format_response(COMMANDID, json, false, "Starting failed");
noError = false;
}
}
} else {
response = format_response(COMMANDID, json, false, "Invalid type");
noError = false;
}
}
}
if (noError) {
parameter = get_param (cmd_params, "interval=");
if (parameter.length() != 0) {
hasParam = true;
if (!Settings_ESP3D::write_uint32(ESP_SENSOR_INTERVAL,parameter.toInt())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
esp3d_sensor.setInterval(parameter.toInt());
}
}
if (noError) {
if (hasParam) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "No parameter");
noError = false;
}
}
} else {
response = format_response(COMMANDID, json, false, "Invalid type");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
if (noError) {
parameter = get_param(cmd_params, "interval=");
if (parameter.length() != 0) {
hasParam = true;
if (!Settings_ESP3D::write_uint32(ESP_SENSOR_INTERVAL,
parameter.toInt())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
esp3d_sensor.setInterval(parameter.toInt());
}
}
if (noError) {
if (hasParam) {
response = format_response(COMMANDID, json, true, "ok");
} else {
output->printMSG (response.c_str() );
response = format_response(COMMANDID, json, false, "No parameter");
noError = false;
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //SENSOR_DEVICE
#endif // SENSOR_DEVICE

View File

@ -18,46 +18,49 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (DISPLAY_DEVICE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
esp3d_display.setStatus(parameter.c_str());
response = format_response(COMMANDID, json, true, "ok");
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
esp3d_display.setStatus(parameter.c_str());
response = format_response(COMMANDID, json, true, "ok");
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}
#endif //DISPLAY_DEVICE
#endif // DISPLAY_DEVICE

View File

@ -19,61 +19,68 @@
*/
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
} else { //set
parameter.toUpperCase();
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
} else { // set
parameter.toUpperCase();
if (has_tag (cmd_params, "CALIBRATE") {
if (!json) {
output->printMSG("Please follow screen instructions");
}
response = format_response(COMMANDID, json, true, ok);
esp3d_display.startCalibration();
if (!json) {
output->printMSG("Please follow screen instructions");
}
response = format_response(COMMANDID, json, true, ok);
esp3d_display.startCalibration();
} else {
if (parameter.indexOf("CALIBRATE") == -1) {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
if (parameter.indexOf("CALIBRATE") == -1) {
response =
format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
}
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}
#endif //DISPLAY_DEVICE && DISPLAY_TOUCH_DRIVER
#endif // DISPLAY_DEVICE && DISPLAY_TOUCH_DRIVER

View File

@ -18,300 +18,307 @@
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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
String line = "";
if(json) {
line = "{\"cmd\":\"220\",\"status\":\"ok\",\"data\":[";
}
bool hasPin = false;
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
String line = "";
if (json) {
line = "{\"cmd\":\"220\",\"status\":\"ok\",\"data\":[";
}
bool hasPin = false;
#ifdef SD_DEVICE
hasPin = true;
if (json) {
line += "{\"id\":\"";
}
line +="SD CS";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SD_CS_PIN==-1?SS:ESP_SD_CS_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
if (json) {
line += "{\"id\":\"";
}
line +="SD MOSI";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SD_MOSI_PIN==-1?MOSI:ESP_SD_MOSI_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
if (json) {
line += "{\"id\":\"";
}
line +="SD MISO";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SD_MISO_PIN==-1?MISO:ESP_SD_MISO_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
if (json) {
line += "{\"id\":\"";
}
line +="SD SCK";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SD_SCK_PIN==-1?SCK:ESP_SD_SCK_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
if (json) {
line += "{\"id\":\"";
}
line +="SD DETECT";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SD_DETECT_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#if ESP_SD_DETECT_PIN !=-1
if (json) {
line += "{\"id\":\"";
}
line +="SD DETECT STATE";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SD_DETECT_VALUE);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //ESP_SD_DETECT_PIN !=-1
hasPin = true;
if (json) {
line += "{\"id\":\"";
}
line += "SD CS";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SD_CS_PIN == -1 ? SS : ESP_SD_CS_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
if (json) {
line += ",{\"id\":\"";
}
line += "SD MOSI";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SD_MOSI_PIN == -1 ? MOSI : ESP_SD_MOSI_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
if (json) {
line += ",{\"id\":\"";
}
line += "SD MISO";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SD_MISO_PIN == -1 ? MISO : ESP_SD_MISO_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
if (json) {
line += ",{\"id\":\"";
}
line += "SD SCK";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SD_SCK_PIN == -1 ? SCK : ESP_SD_SCK_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
if (json) {
line += ",{\"id\":\"";
}
line += "SD DETECT";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SD_DETECT_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#if ESP_SD_DETECT_PIN != -1
if (json) {
line += ",{\"id\":\"";
}
line += "SD DETECT STATE";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SD_DETECT_VALUE);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // ESP_SD_DETECT_PIN !=-1
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD && defined(ESP_FLAG_SHARED_SD_PIN)
if (json) {
line += "{\"id\":\"";
}
line +="SD SWITCH";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_FLAG_SHARED_SD_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //SD_DEVICE_CONNECTION == ESP_SHARED_SD
#endif //SD_DEVICE
if (json) {
line += ",{\"id\":\"";
}
line += "SD SWITCH";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_FLAG_SHARED_SD_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // SD_DEVICE_CONNECTION == ESP_SHARED_SD
#endif // SD_DEVICE
#ifdef BUZZER_DEVICE
hasPin = true;
if (json) {
line += "{\"id\":\"";
}
line +="BUZZER";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP3D_BUZZER_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //BUZZER_DEVICE
#if defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && ESP3D_RESET_PIN !=-1
hasPin = true;
if (json) {
line += "{\"id\":\"";
}
line +="RESET";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP3D_RESET_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //PIN_RESET_FEATURE
hasPin = true;
if (json) {
line += ",{\"id\":\"";
}
line += "BUZZER";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP3D_BUZZER_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // BUZZER_DEVICE
#if defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && \
ESP3D_RESET_PIN != -1
hasPin = true;
if (json) {
line += ",{\"id\":\"";
}
line += "RESET";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP3D_RESET_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // PIN_RESET_FEATURE
#ifdef SENSOR_DEVICE
hasPin = true;
if (json) {
line += "{\"id\":\"";
}
line +="SENSOR";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP3D_SENSOR_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //SENSOR_DEVICE
hasPin = true;
if (json) {
line += ",{\"id\":\"";
}
line += "SENSOR";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP3D_SENSOR_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // SENSOR_DEVICE
#ifdef DISPLAY_DEVICE
#if (DISPLAY_DEVICE == OLED_I2C_SSD1306) || (DISPLAY_DEVICE == OLED_I2C_SSDSH1106)
hasPin = true;
if (json) {
line += "{\"id\":\"";
}
line +="SDA";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SDA_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
if (json) {
line += "{\"id\":\"";
}
line +="SCL";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +=String(ESP_SCL_PIN);
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //(DISPLAY_DEVICE == OLED_I2C_SSD1306) || (DISPLAY_DEVICE == OLED_I2C_SSDSH1106)
#endif //DISPLAY_DEVICE
if (!hasPin) {
if (json) {
line += "{\"id\":\"";
}
line +="NO PIN";
if (json) {
line +="\",\"value\":\"";
} else {
line +=": ";
}
line +="-";
if (json) {
line +="\"}";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
}
if (json) {
output->printLN ("]}");
}
return true;
} else {
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
noError = false;
}
}
if (noError) {
#if (DISPLAY_DEVICE == OLED_I2C_SSD1306) || \
(DISPLAY_DEVICE == OLED_I2C_SSDSH1106)
hasPin = true;
if (json) {
line += ",{\"id\":\"";
}
line += "SDA";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SDA_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
if (json) {
line += ",{\"id\":\"";
}
line += "SCL";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += String(ESP_SCL_PIN);
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif //(DISPLAY_DEVICE == OLED_I2C_SSD1306) || (DISPLAY_DEVICE ==
// OLED_I2C_SSDSH1106)
#endif // DISPLAY_DEVICE
if (!hasPin) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
line += ",{\"id\":\"";
}
line += "NO PIN";
if (json) {
line += "\",\"value\":\"";
} else {
line += ": ";
}
line += "-";
if (json) {
line += "\"}";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
}
if (json) {
output->printLN("]}");
}
return true;
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false,
"This command doesn't take parameters");
noError = false;
}
return 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,74 +18,77 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (BUZZER_DEVICE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (!esp3d_buzzer.started()) {
response = format_response(COMMANDID, json, false, "Buzzer disabled");
noError = false;
} else {
parameter = get_param (cmd_params, "");
//get
if (parameter.length() == 0) {
esp3d_buzzer.beep();
} else {
int f,d;
//frequency
parameter = get_param (cmd_params, "F=");
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "No frequency");
noError = false;
} else {
f = parameter.toInt();
parameter = get_param (cmd_params, "D=");
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "No duration");
noError = false;
} else {
d = parameter.toInt();
esp3d_buzzer.beep(f,d);
}
}
}
if(noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!esp3d_buzzer.started()) {
response = format_response(COMMANDID, json, false, "Buzzer disabled");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
parameter = get_param(cmd_params, "");
// get
if (parameter.length() == 0) {
esp3d_buzzer.beep();
} else {
int f, d;
// frequency
parameter = get_param(cmd_params, "F=");
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "No frequency");
noError = false;
} else {
f = parameter.toInt();
parameter = get_param(cmd_params, "D=");
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "No duration");
noError = false;
} else {
d = parameter.toInt();
esp3d_buzzer.beep(f, d);
}
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
return 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
#endif // BUZZER_DEVICE

View File

@ -18,51 +18,53 @@
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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param (cmd_params, "");
//get time
if (parameter.length() != 0) {
if(!json) {
output->printMSG ("Pause");
}
Hal::wait(parameter.toInt());
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
// 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 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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param(cmd_params, "");
// get time
if (parameter.length() != 0) {
if (!json) {
output->printMSG("Pause");
}
Hal::wait(parameter.toInt());
response = format_response(COMMANDID, json, true, "ok");
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
return 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\":\"");
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\"}]}");
// 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\"}]}");*/
// 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 {
output->printMSG(response.c_str());
}
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
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());
output->printERROR(response.c_str(), errorCode);
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@ -18,69 +18,78 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_UPDATE_FEATURE)
#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
// 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 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
#define COMMANDID 402
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
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");
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
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");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
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"))) {
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
response = format_response(COMMANDID, json, false,
"Only ON or OFF mode supported");
noError = false;
} else {
output->printMSG (response.c_str() );
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 {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //SD_UPDATE_FEATURE
#endif // SD_UPDATE_FEATURE

View File

@ -18,126 +18,130 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WIFI_FEATURE)
#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
// 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 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
#define COMMANDID 410
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
//Backup current mode
uint8_t currentmode = WiFi.getMode();
int n = 0;
uint8_t total = 0;
if (!json) {
output->printMSGLine ("Start Scan");
}
if(currentmode==WIFI_AP) {
WiFi.mode(WIFI_AP_STA);
}
n = WiFi.scanNetworks ();
if(currentmode==WIFI_AP) {
WiFi.mode((WiFiMode_t)currentmode);
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
// Backup current mode
uint8_t currentmode = WiFi.getMode();
int n = 0;
uint8_t total = 0;
if (!json) {
output->printMSGLine("Start Scan");
}
if (currentmode == WIFI_AP) {
WiFi.mode(WIFI_AP_STA);
}
n = WiFi.scanNetworks();
if (currentmode == WIFI_AP) {
WiFi.mode((WiFiMode_t)currentmode);
}
if (json) {
output->print("{\"cmd\":\"410\",\"status\":\"ok\",\"data\":[");
}
String line;
for (int i = 0; i < n; ++i) {
line = "";
if (WiFi.RSSI(i) >= MIN_RSSI) {
if (total > 0) {
if (json) {
output->print ("{\"cmd\":\"410\",\"status\":\"ok\",\"data\":[");
line += ",";
}
String line;
for (int i = 0; i < n; ++i) {
line = "";
if (WiFi.RSSI (i)>= MIN_RSSI) {
if (total > 0) {
if (json) {
line+=",";
}
}
total++;
if (json) {
line += "{\"SSID\":\"";
line +=ESP3DOutput::encodeString(WiFi.SSID (i).c_str());
} else {
line +=WiFi.SSID (i).c_str();
}
if (json) {
line +="\",\"SIGNAL\":\"";
} else {
line +="\t";
}
line += String(WiFiConfig::getSignal (WiFi.RSSI (i) ));
if (!json) {
line +="%";
}
if (json) {
line +="\",\"IS_PROTECTED\":\"";
}
if (WiFi.encryptionType (i) == ENC_TYPE_NONE) {
if (json) {
line +="0";
} else {
line +="\tOpen";
}
} else {
if (json) {
line +="1";
} else {
line +="\tSecure";
}
}
if (json) {
line +="\"}";
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine (line.c_str());
}
}
}
WiFi.scanDelete();
}
total++;
if (json) {
line += "{\"SSID\":\"";
line += ESP3DOutput::encodeString(WiFi.SSID(i).c_str());
} else {
line += WiFi.SSID(i).c_str();
}
if (json) {
line += "\",\"SIGNAL\":\"";
} else {
line += "\t";
}
line += String(WiFiConfig::getSignal(WiFi.RSSI(i)));
if (!json) {
line += "%";
}
if (json) {
line += "\",\"IS_PROTECTED\":\"";
}
if (WiFi.encryptionType(i) == ENC_TYPE_NONE) {
if (json) {
output->printLN ("]}");
line += "0";
} else {
output->printMSGLine ("End Scan");
line += "\tOpen";
}
return true;
} else {
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
} else {
if (json) {
line += "1";
} else {
line += "\tSecure";
}
}
if (json) {
line += "\"}";
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
}
WiFi.scanDelete();
if (json) {
output->printLN("]}");
} else {
output->printMSGLine("End Scan");
}
return true;
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false,
"This command doesn't take parameters");
noError = false;
}
return 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
#endif // WIFI_FEATURE

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 {
output->printMSG(response.c_str());
}
if (json) {
output->printLN(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
if (noError) {
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
}

View File

@ -18,63 +18,67 @@
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"
//Set ESP State
//cmd are RESTART / RESET
#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 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
#define COMMANDID 444
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (has_tag(cmd_params,"RESET")) {
if (Esp3D::reset()) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Reset failed");
noError = false;
}
}
if (noError && has_tag(cmd_params,"RESTART")) {
if (!json) {
output->printMSG ("Restart ongoing");
} else {
response = format_response(COMMANDID, json, true, "Restart ongoing");
output->printLN (response.c_str());
}
output->flush();
Hal::wait(100);
Esp3D::restart_esp();
}
if (noError && !has_tag(cmd_params,"RESTART") && !has_tag(cmd_params,"RESET")) {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (has_tag(cmd_params, "RESET")) {
if (Esp3D::reset()) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Reset failed");
noError = false;
}
}
if (noError && has_tag(cmd_params, "RESTART")) {
if (!json) {
output->printMSG("Restart ongoing");
} else {
response = format_response(COMMANDID, json, true, "Restart ongoing");
output->printLN(response.c_str());
}
output->flush();
Hal::wait(100);
Esp3D::restart_esp();
}
if (noError && !has_tag(cmd_params, "RESTART") &&
!has_tag(cmd_params, "RESET")) {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
return noError;
}

View File

@ -18,137 +18,136 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (MDNS_FEATURE)
#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
// 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 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
#define COMMANDID 450
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
uint16_t n = 0;
if (!json) {
output->printMSGLine ("Start Scan");
}
n = esp3d_mDNS.servicesCount ();
if (json) {
output->print ("{\"cmd\":\"450\",\"status\":\"ok\",\"data\":[");
}
String line;
for (uint16_t i = 0; i < n; i++) {
line = "";
if (strlen(esp3d_mDNS.answerHostname(i)) == 0) {
continue;
}
if (i > 0) {
if (json) {
line+=",";
}
}
if (json) {
line += "{\"Hostname\":\"";
line +=ESP3DOutput::encodeString(esp3d_mDNS.answerHostname(i));
} else {
line +=esp3d_mDNS.answerHostname(i);
}
if (json) {
line +="\",\"IP\":\"";
} else {
line +=" (";
}
line += esp3d_mDNS.answerIP(i);
if (!json) {
line +=":";
}
if (json) {
line +="\",\"port\":\"";
}
line += String(esp3d_mDNS.answerPort(i));
if (json) {
line +="\",\"TxT\":[";
} else {
line +=") ";
}
uint16_t nbtxt = esp3d_mDNS.answerTxtCount(i);
for (uint16_t j = 0; j < nbtxt; ++j) {
if (j>0) {
line += ",";
}
if (json) {
line += "{\"key\":\"";
}
line+=esp3d_mDNS.answerTxtKey(i, j);
if (json) {
line +="\",\"value\":\"";
} else {
line +="=";
}
line+=esp3d_mDNS.answerTxt(i, j);
if (json) {
line +="\"}";
}
}
if (json) {
line +="]}";
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine (line.c_str());
}
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
uint16_t n = 0;
if (!json) {
output->printMSGLine("Start Scan");
}
n = esp3d_mDNS.servicesCount();
if (json) {
output->print("{\"cmd\":\"450\",\"status\":\"ok\",\"data\":[");
}
String line;
for (uint16_t i = 0; i < n; i++) {
line = "";
if (strlen(esp3d_mDNS.answerHostname(i)) == 0) {
continue;
}
if (i > 0) {
if (json) {
line += ",";
}
}
if (json) {
output->printLN ("]}");
line += "{\"Hostname\":\"";
line += ESP3DOutput::encodeString(esp3d_mDNS.answerHostname(i));
} else {
output->printMSGLine ("End Scan");
line += esp3d_mDNS.answerHostname(i);
}
return true;
} else {
response = format_response(COMMANDID, json, false, "This command doesn't take parameters");
noError = false;
if (json) {
line += "\",\"IP\":\"";
} else {
line += " (";
}
line += esp3d_mDNS.answerIP(i);
if (!json) {
line += ":";
}
if (json) {
line += "\",\"port\":\"";
}
line += String(esp3d_mDNS.answerPort(i));
if (json) {
line += "\",\"TxT\":[";
} else {
line += ") ";
}
uint16_t nbtxt = esp3d_mDNS.answerTxtCount(i);
for (uint16_t j = 0; j < nbtxt; ++j) {
if (j > 0) {
line += ",";
}
if (json) {
line += "{\"key\":\"";
}
line += esp3d_mDNS.answerTxtKey(i, j);
if (json) {
line += "\",\"value\":\"";
} else {
line += "=";
}
line += esp3d_mDNS.answerTxt(i, j);
if (json) {
line += "\"}";
}
}
if (json) {
line += "]}";
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
if (json) {
output->printLN("]}");
} else {
output->printERROR(response.c_str(), errorCode);
output->printMSGLine("End Scan");
}
return noError;
return true;
} else {
response = format_response(COMMANDID, json, false,
"This command doesn't take parameters");
noError = false;
}
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 //MDNS_FEATURE
#endif // MDNS_FEATURE

View File

@ -18,54 +18,57 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (AUTHENTICATION_FEATURE)
#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
#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 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
if (auth_type == LEVEL_ADMIN) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() != 0) {
if (Settings_ESP3D::isLocalPasswordValid (parameter.c_str() ) ) {
if (!Settings_ESP3D::write_string (ESP_ADMIN_PWD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
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
if (auth_type == LEVEL_ADMIN) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) {
if (Settings_ESP3D::isLocalPasswordValid(parameter.c_str())) {
if (!Settings_ESP3D::write_string(ESP_ADMIN_PWD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
response = format_response(COMMANDID, json, true, "ok");
}
} else {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
errorCode = 401;
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
}
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
return noError;
} else {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
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 //AUTHENTICATION_FEATURE
#endif // AUTHENTICATION_FEATURE

View File

@ -18,54 +18,57 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (AUTHENTICATION_FEATURE)
#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
// 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 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
if (auth_type != LEVEL_GUEST) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() != 0) {
if (Settings_ESP3D::isLocalPasswordValid (parameter.c_str() ) ) {
if (!Settings_ESP3D::write_string (ESP_USER_PWD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
#define COMMANDID 555
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
if (auth_type != LEVEL_GUEST) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) {
if (Settings_ESP3D::isLocalPasswordValid(parameter.c_str())) {
if (!Settings_ESP3D::write_string(ESP_USER_PWD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
response = format_response(COMMANDID, json, true, "ok");
}
} else {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
errorCode = 401;
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
}
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
return noError;
} else {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
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 //AUTHENTICATION_FEATURE
#endif // AUTHENTICATION_FEATURE

View File

@ -18,57 +18,62 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (NOTIFICATION_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Message is missing");
noError = false;
} else {
parameter = get_param (cmd_params, "");
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");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Message is missing");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
parameter = get_param(cmd_params, "");
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");
noError = false;
}
}
return 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 //NOTIFICATION_FEATURE
#endif // NOTIFICATION_FEATURE

View File

@ -18,169 +18,180 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (NOTIFICATION_FEATURE)
#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)
{
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
#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) {
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
uint8_t Ntype = Settings_ESP3D::read_byte(ESP_NOTIFICATION_TYPE);
String tmp;
if (json) {
tmp = "{\"type\":\"";
} else {
tmp = "type=";
}
switch(Ntype) {
case ESP_PUSHOVER_NOTIFICATION:
tmp += "PUSHOVER";
break;
case ESP_EMAIL_NOTIFICATION:
tmp += "EMAIL";
break;
case ESP_LINE_NOTIFICATION:
tmp += "LINE";
break;
case ESP_TELEGRAM_NOTIFICATION:
tmp += "TELEGRAM";
break;
case ESP_IFTTT_NOTIFICATION:
tmp += "IFTTT";
break;
default:
tmp+= "NONE";
}
if (json) {
tmp +="\"";
}
String ts = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
if (ts.length() > 0 && ts!="NONE") {
if (json) {
tmp += ",\"TS\":\"";
} else {
tmp += ", TS=";
}
tmp+= ts;
if (json) {
tmp += "\"}";
}
}
if (json) {
tmp += "}";
}
response = format_response(COMMANDID, json, true, tmp.c_str());
} else {
//type
parameter = get_param (cmd_params, "type=");
if (parameter.length() > 0) {
hasParam = true;
uint8_t Ntype;
parameter.toUpperCase();
if (parameter == "NONE") {
Ntype = 0;
} else if (parameter == "PUSHOVER") {
Ntype = ESP_PUSHOVER_NOTIFICATION;
} else if (parameter == "EMAIL") {
Ntype = ESP_EMAIL_NOTIFICATION;
} else if (parameter == "LINE") {
Ntype = ESP_LINE_NOTIFICATION;
} else if (parameter == "TELEGRAM") {
Ntype = ESP_TELEGRAM_NOTIFICATION;
} else if (parameter == "IFTTT") {
Ntype = ESP_IFTTT_NOTIFICATION;
} else {
response = format_response(COMMANDID, json, false, "Only NONE, PUSHOVER, EMAIL, LINE, IFTTT are supported");
noError = false;
}
if (noError) {
if(!Settings_ESP3D::write_byte(ESP_NOTIFICATION_TYPE, Ntype)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
//Settings
if (noError) {
parameter = get_param (cmd_params, "TS=");
if (parameter.length() > 0) {
hasParam = true;
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set TS failed");
noError = false;
}
}
}
//Token1
if (noError) {
parameter = get_param (cmd_params, "T1=");
if (parameter.length() > 0) {
hasParam = true;
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set T1 failed");
noError = false;
}
}
}
//Token2
if (noError) {
parameter = get_param (cmd_params, "T2=");
if (parameter.length() > 0) {
hasParam = true;
if(!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set T2 failed");
noError = false;
} else {
response = true;
}
}
}
if (noError) {
if (hasParam) {
//Restart service
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");
noError = false;
}
}
}
}
if (noError) {
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
uint8_t Ntype = Settings_ESP3D::read_byte(ESP_NOTIFICATION_TYPE);
String tmp;
if (json) {
tmp = "{\"type\":\"";
} else {
tmp = "type=";
}
switch (Ntype) {
case ESP_PUSHOVER_NOTIFICATION:
tmp += "PUSHOVER";
break;
case ESP_EMAIL_NOTIFICATION:
tmp += "EMAIL";
break;
case ESP_LINE_NOTIFICATION:
tmp += "LINE";
break;
case ESP_TELEGRAM_NOTIFICATION:
tmp += "TELEGRAM";
break;
case ESP_IFTTT_NOTIFICATION:
tmp += "IFTTT";
break;
default:
tmp += "NONE";
}
if (json) {
tmp += "\"";
}
String ts = Settings_ESP3D::read_string(ESP_NOTIFICATION_SETTINGS);
if (ts.length() > 0 && ts != "NONE") {
if (json) {
output->printLN (response.c_str() );
tmp += ",\"TS\":\"";
} else {
output->printMSG (response.c_str() );
tmp += ", TS=";
}
tmp += ts;
if (json) {
tmp += "\"}";
}
}
if (json) {
tmp += "}";
}
response = format_response(COMMANDID, json, true, tmp.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
// type
parameter = get_param(cmd_params, "type=");
if (parameter.length() > 0) {
hasParam = true;
uint8_t Ntype;
parameter.toUpperCase();
if (parameter == "NONE") {
Ntype = 0;
} else if (parameter == "PUSHOVER") {
Ntype = ESP_PUSHOVER_NOTIFICATION;
} else if (parameter == "EMAIL") {
Ntype = ESP_EMAIL_NOTIFICATION;
} else if (parameter == "LINE") {
Ntype = ESP_LINE_NOTIFICATION;
} else if (parameter == "TELEGRAM") {
Ntype = ESP_TELEGRAM_NOTIFICATION;
} else if (parameter == "IFTTT") {
Ntype = ESP_IFTTT_NOTIFICATION;
} else {
response = format_response(
COMMANDID, json, false,
"Only NONE, PUSHOVER, EMAIL, LINE, IFTTT are supported");
noError = false;
}
if (noError) {
if (!Settings_ESP3D::write_byte(ESP_NOTIFICATION_TYPE, Ntype)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
}
}
// Settings
if (noError) {
parameter = get_param(cmd_params, "TS=");
if (parameter.length() > 0) {
hasParam = true;
if (!Settings_ESP3D::write_string(ESP_NOTIFICATION_SETTINGS,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set TS failed");
noError = false;
}
}
}
// Token1
if (noError) {
parameter = get_param(cmd_params, "T1=");
if (parameter.length() > 0) {
hasParam = true;
if (!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN1,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set T1 failed");
noError = false;
}
}
}
// Token2
if (noError) {
parameter = get_param(cmd_params, "T2=");
if (parameter.length() > 0) {
hasParam = true;
if (!Settings_ESP3D::write_string(ESP_NOTIFICATION_TOKEN2,
parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set T2 failed");
noError = false;
} else {
response = true;
}
}
}
if (noError) {
if (hasParam) {
// Restart service
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");
noError = false;
}
}
}
return 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 //NOTIFICATION_FEATURE
#endif // NOTIFICATION_FEATURE

View File

@ -18,57 +18,61 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (NOTIFICATION_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param (cmd_params, "");
//get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Message is missing");
noError = false;
} else {
parameter = get_param (cmd_params, "URL=");
if (notificationsservice.GET(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Send notification failed");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param(cmd_params, "");
// get
if (parameter.length() == 0) {
response = format_response(COMMANDID, json, false, "Message is missing");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
parameter = get_param(cmd_params, "URL=");
if (notificationsservice.GET(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response =
format_response(COMMANDID, json, false, "Send notification failed");
noError = false;
}
}
return 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 //NOTIFICATION_FEATURE
#endif // NOTIFICATION_FEATURE

View File

@ -18,64 +18,72 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined(GCODE_HOST_FEATURE)
#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
//read local file
#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
// read local file
//[ESP700]<filename>
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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Error processing file");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Streaming already in progress");
noError = false;
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
response =
format_response(COMMANDID, json, false, "Error processing file");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false,
"Streaming already in progress");
noError = false;
}
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
return 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 //GCODE_HOST_FEATURE
#endif // GCODE_HOST_FEATURE

View File

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

View File

@ -18,53 +18,56 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (FILESYSTEM_FEATURE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (has_tag (cmd_params, "FORMATFS")) {
if (!json) {
output->printMSGLine("Start Formating");
}
ESP_FileSystem::format();
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSGLine (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (has_tag(cmd_params, "FORMATFS")) {
if (!json) {
output->printMSGLine("Start Formating");
}
ESP_FileSystem::format();
response = format_response(COMMANDID, json, true, "ok");
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
return 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 //FILESYSTEM_FEATURE
#endif // FILESYSTEM_FEATURE

View File

@ -18,64 +18,67 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_DEVICE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (has_tag (cmd_params, "FORMATSD")) {
if (!ESP_SD::accessFS()) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
ESP_SD::setState(ESP_SDCARD_BUSY);
if (!json) {
output->printMSGLine("Start Formating");
}
if (ESP_SD::format(output)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Format failed");
noError = false;
}
ESP_SD::releaseFS();
}
} else {
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (has_tag(cmd_params, "FORMATSD")) {
if (!ESP_SD::accessFS()) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
ESP_SD::setState(ESP_SDCARD_BUSY);
if (!json) {
output->printMSGLine("Start Formating");
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
if (ESP_SD::format(output)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
output->printMSGLine (response.c_str() );
response = format_response(COMMANDID, json, false, "Format failed");
noError = false;
}
ESP_SD::releaseFS();
}
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Invalid parameter");
noError = false;
}
return 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 //SD_DEVICE
#endif // SD_DEVICE

View File

@ -18,183 +18,187 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (FILESYSTEM_FEATURE)
#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"
#endif //FILESYSTEM_TIMESTAMP_FEATURE
#define COMMANDID 720
//List ESP Filesystem
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
parameter = "/";
}
if (ESP_FileSystem::exists(parameter.c_str())) {
String line = "";
ESP_File f ;
f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
uint countf = 0;
uint countd = 0;
if (f) {
if(json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" + parameter + "\",\"files\":[";
output->print (line.c_str());
} else {
line = "Directory on FS : " + parameter;
output->printMSGLine(line.c_str());
}
//Check directories
ESP_File sub;
sub = f.openNextFile();
while (sub) {
if (sub.isDirectory()) {
line="";
countd++;
if (json) {
line="";
if (countd > 1) {
line += ",";
}
line += "{\"name\":\"" ;
line+=sub.name() ;
line+= "\",\"size\":\"-1\"}";
} else {
line = "[DIR] \t";
line+= sub.name();
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
//Check files
sub = f.openNextFile();
while (sub) {
if (!sub.isDirectory()) {
countf++;
String time = "";
line="";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeserver.current_time(sub.getLastWrite());
#endif //FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
line="";
if (countd > 0 || countf>1) {
line += ",";
}
line+= "{\"name\":\"";
line+=sub.name() ;
line+="\",\"size\":\"";
line+=ESP_FileSystem::formatBytes(sub.size());
if (time.length() > 0) {
line += "\",\"time\":\"";
line += time;
}
line+="\"}";
} else {
line+=" \t ";
line+=sub.name();
line+=" \t";
line+=ESP_FileSystem::formatBytes(sub.size());
line+=" \t";
line+=time;
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
if (json) {
line = "], \"total\":\"";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::totalBytes());
line += "\",\"used\":\"";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::usedBytes());
line+="\",\"occupation\":\"";
uint64_t total =ESP_FileSystem::totalBytes();
if (total==0) {
total=1;
}
float occupation = 100.0*ESP_FileSystem::usedBytes()/total;
if ((occupation < 1) && (ESP_FileSystem::usedBytes()>0)) {
occupation=1;
}
line+= String((int)round(occupation));
line+="\"}}";
output->printLN (line.c_str());
} else {
line =String(countf) + " file";
if (countf > 1) {
line += "s";
}
line += " , " + String(countd) + " dir";
if (countd > 1) {
line += "s";
}
output->printMSGLine(line.c_str());
line = "Total ";
line+=ESP_FileSystem::formatBytes(ESP_FileSystem::totalBytes());
line+=", Used ";
line+=ESP_FileSystem::formatBytes(ESP_FileSystem::usedBytes());
line+=", Available: ";
line+=ESP_FileSystem::formatBytes(ESP_FileSystem::freeBytes());
output->printMSGLine(line.c_str());
}
return true;
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
parameter = "/";
}
if (noError) {
if (ESP_FileSystem::exists(parameter.c_str())) {
String line = "";
ESP_File f;
f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
uint countf = 0;
uint countd = 0;
if (f) {
if (json) {
output->printLN (response.c_str() );
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" +
parameter + "\",\"files\":[";
output->print(line.c_str());
} else {
output->printMSG (response.c_str() );
line = "Directory on FS : " + parameter;
output->printMSGLine(line.c_str());
}
// Check directories
ESP_File sub;
sub = f.openNextFile();
while (sub) {
if (sub.isDirectory()) {
line = "";
countd++;
if (json) {
line = "";
if (countd > 1) {
line += ",";
}
line += "{\"name\":\"";
line += sub.name();
line += "\",\"size\":\"-1\"}";
} else {
line = "[DIR] \t";
line += sub.name();
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_READ);
// Check files
sub = f.openNextFile();
while (sub) {
if (!sub.isDirectory()) {
countf++;
String time = "";
line = "";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
line = "";
if (countd > 0 || countf > 1) {
line += ",";
}
line += "{\"name\":\"";
line += sub.name();
line += "\",\"size\":\"";
line += ESP_FileSystem::formatBytes(sub.size());
if (time.length() > 0) {
line += "\",\"time\":\"";
line += time;
}
line += "\"}";
} else {
line += " \t ";
line += sub.name();
line += " \t";
line += ESP_FileSystem::formatBytes(sub.size());
line += " \t";
line += time;
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
if (json) {
line = "], \"total\":\"";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::totalBytes());
line += "\",\"used\":\"";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::usedBytes());
line += "\",\"occupation\":\"";
uint64_t total = ESP_FileSystem::totalBytes();
if (total == 0) {
total = 1;
}
float occupation = 100.0 * ESP_FileSystem::usedBytes() / total;
if ((occupation < 1) && (ESP_FileSystem::usedBytes() > 0)) {
occupation = 1;
}
line += String((int)round(occupation));
line += "\"}}";
output->printLN(line.c_str());
} else {
line = String(countf) + " file";
if (countf > 1) {
line += "s";
}
line += " , " + String(countd) + " dir";
if (countd > 1) {
line += "s";
}
output->printMSGLine(line.c_str());
line = "Total ";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::totalBytes());
line += ", Used ";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::usedBytes());
line += ", Available: ";
line += ESP_FileSystem::formatBytes(ESP_FileSystem::freeBytes());
output->printMSGLine(line.c_str());
}
return true;
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
return 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 //FILESYSTEM_FEATURE
#endif // FILESYSTEM_FEATURE

View File

@ -18,105 +18,107 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (FILESYSTEM_FEATURE)
#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 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;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param (cmd_params, "mkdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_FileSystem::mkdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "rmdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_FileSystem::rmdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "remove=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_FileSystem::remove(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "exists=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_FileSystem::exists(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "yes");
} else {
response = format_response(COMMANDID, json, false, "no");
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "create=");
if (parameter.length() != 0) {
hasParam = true;
ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_WRITE);
if (!f.isOpen()) {
response = format_response(COMMANDID, json, false, "create failed");
noError = false;
} else {
f.close();
}
}
}
if (hasParam && noError && response.length() == 0) {
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
#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 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;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = get_param(cmd_params, "mkdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_FileSystem::mkdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
if (noError && !hasParam) {
parameter = get_param(cmd_params, "rmdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_FileSystem::rmdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "remove=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_FileSystem::remove(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "exists=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_FileSystem::exists(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "yes");
} else {
output->printMSG (response.c_str() );
response = format_response(COMMANDID, json, false, "no");
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return noError;
if (noError && !hasParam) {
parameter = get_param(cmd_params, "create=");
if (parameter.length() != 0) {
hasParam = true;
ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_FILE_WRITE);
if (!f.isOpen()) {
response = format_response(COMMANDID, json, false, "create failed");
noError = false;
} else {
f.close();
}
}
}
if (hasParam && noError && response.length() == 0) {
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
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 //FILESYSTEM_FEATURE
#endif // FILESYSTEM_FEATURE

View File

@ -18,190 +18,197 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_DEVICE)
#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"
#endif //SD_TIMESTAMP_FEATURE
#define COMMANDID 740
//List SD Filesystem
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
parameter = "/";
}
if (!ESP_SD::accessFS()) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
response = format_response(COMMANDID, json, false, "No SD card");
noError = false;
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
parameter = "/";
}
if (!ESP_SD::accessFS()) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
response = format_response(COMMANDID, json, false, "No SD card");
noError = false;
} else {
ESP_SD::setState(ESP_SDCARD_BUSY);
if (ESP_SD::exists(parameter.c_str())) {
String line = "";
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_FILE_READ);
uint countf = 0;
uint countd = 0;
if (f) {
if (json) {
line =
"{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" +
parameter + "\",\"files\":[";
output->print(line.c_str());
} else {
ESP_SD::setState(ESP_SDCARD_BUSY );
if (ESP_SD::exists(parameter.c_str())) {
String line = "";
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_FILE_READ);
uint countf = 0;
uint countd = 0;
if (f) {
if(json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" + parameter + "\",\"files\":[";
output->print (line.c_str());
} else {
line = "Directory on SD : " + parameter;
output->printMSGLine(line.c_str());
}
//Check directories
ESP_SDFile sub = f.openNextFile();
while (sub) {
if (sub.isDirectory()) {
line="";
countd++;
if (json) {
line="";
if (countd > 1) {
line += ",";
}
line += "{\"name\":\"" ;
line+=sub.name() ;
line+= "\",\"size\":\"-1\"}";
} else {
line = "[DIR] \t";
line+= sub.name();
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
f = ESP_SD::open(parameter.c_str(), ESP_FILE_READ);
//Check files
sub = f.openNextFile();
while (sub) {
if (!sub.isDirectory()) {
String time = "";
line="";
countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeserver.current_time(sub.getLastWrite());
#endif //FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
if (countd > 0 || countf>1) {
line += ",";
}
line+= "{\"name\":\"";
line+=sub.name() ;
line+="\",\"size\":\"";
line+=ESP_SD::formatBytes(sub.size());
if (time.length() > 0) {
line += "\",\"time\":\"";
line += time;
}
line+="\"}";
} else {
line+=" \t ";
line+=sub.name();
line+=" \t";
line+=ESP_SD::formatBytes(sub.size());
line+=" \t";
line+=time;
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
if (json) {
line = "], \"total\":\"";
line += ESP_SD::formatBytes(ESP_SD::totalBytes());
line += "\",\"used\":\"";
line += ESP_SD::formatBytes(ESP_SD::usedBytes());
line+="\",\"occupation\":\"";
uint64_t total =ESP_SD::totalBytes();
if (total==0) {
total=1;
}
float occupation = 100.0*ESP_SD::usedBytes()/total;
if ((occupation < 1) && (ESP_SD::usedBytes()>0)) {
occupation=1;
}
line+= String((int)round(occupation));
line+="\"}}";
output->printLN (line.c_str());
} else {
line =String(countf) + " file";
if (countf > 1) {
line += "s";
}
line += " , " + String(countd) + " dir";
if (countd > 1) {
line += "s";
}
output->printMSGLine(line.c_str());
line = "Total ";
line+=ESP_SD::formatBytes(ESP_SD::totalBytes());
line+=", Used ";
line+=ESP_SD::formatBytes(ESP_SD::usedBytes());
line+=", Available: ";
line+=ESP_SD::formatBytes(ESP_SD::freeBytes());
output->printMSGLine(line.c_str());
}
ESP_SD::releaseFS();
return true;
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
line = "Directory on SD : " + parameter;
output->printMSGLine(line.c_str());
}
// Check directories
ESP_SDFile sub = f.openNextFile();
while (sub) {
if (sub.isDirectory()) {
line = "";
countd++;
if (json) {
line = "";
if (countd > 1) {
line += ",";
}
line += "{\"name\":\"";
line += sub.name();
line += "\",\"size\":\"-1\"}";
} else {
response = format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
line = "[DIR] \t";
line += sub.name();
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
f = ESP_SD::open(parameter.c_str(), ESP_FILE_READ);
// Check files
sub = f.openNextFile();
while (sub) {
if (!sub.isDirectory()) {
String time = "";
line = "";
countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
if (countd > 0 || countf > 1) {
line += ",";
}
line += "{\"name\":\"";
line += sub.name();
line += "\",\"size\":\"";
line += ESP_SD::formatBytes(sub.size());
if (time.length() > 0) {
line += "\",\"time\":\"";
line += time;
}
line += "\"}";
} else {
line += " \t ";
line += sub.name();
line += " \t";
line += ESP_SD::formatBytes(sub.size());
line += " \t";
line += time;
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
if (json) {
line = "], \"total\":\"";
line += ESP_SD::formatBytes(ESP_SD::totalBytes());
line += "\",\"used\":\"";
line += ESP_SD::formatBytes(ESP_SD::usedBytes());
line += "\",\"occupation\":\"";
uint64_t total = ESP_SD::totalBytes();
if (total == 0) {
total = 1;
}
float occupation = 100.0 * ESP_SD::usedBytes() / total;
if ((occupation < 1) && (ESP_SD::usedBytes() > 0)) {
occupation = 1;
}
line += String((int)round(occupation));
line += "\"}}";
output->printLN(line.c_str());
} else {
line = String(countf) + " file";
if (countf > 1) {
line += "s";
}
line += " , " + String(countd) + " dir";
if (countd > 1) {
line += "s";
}
output->printMSGLine(line.c_str());
line = "Total ";
line += ESP_SD::formatBytes(ESP_SD::totalBytes());
line += ", Used ";
line += ESP_SD::formatBytes(ESP_SD::usedBytes());
line += ", Available: ";
line += ESP_SD::formatBytes(ESP_SD::freeBytes());
output->printMSGLine(line.c_str());
}
ESP_SD::releaseFS();
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
return true;
} else {
response =
format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
} else {
output->printMSG (response.c_str() );
response =
format_response(COMMANDID, json, false, "Invalid directory");
noError = false;
}
} else {
output->printERROR(response.c_str(), errorCode);
}
ESP_SD::releaseFS();
}
return 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 //SD_DEVICE
#endif // SD_DEVICE

View File

@ -18,116 +18,123 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_DEVICE)
#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
#define COMMANDID 750
// Action on SD Filesystem
//rmdir / remove / mkdir / exists /create
// 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 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;
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;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
if (!ESP_SD::accessFS()) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
response = format_response(COMMANDID, json, false, "No SD card");
noError = false;
} else {
ESP_SD::setState(ESP_SDCARD_BUSY );
parameter = get_param (cmd_params, "mkdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_SD::mkdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "rmdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_SD::rmdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "remove=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_SD::remove(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "exists=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_SD::exists(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "yes");
} else {
response = format_response(COMMANDID, json, false, "no");
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "create=");
if (parameter.length() != 0) {
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");
noError = false;
} else {
f.close();
}
}
}
if (hasParam && noError && response.length() == 0) {
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
ESP_SD::releaseFS();
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
if (!ESP_SD::accessFS()) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
if (ESP_SD::getState(true) == ESP_SDCARD_NOT_PRESENT) {
response = format_response(COMMANDID, json, false, "No SD card");
noError = false;
} else {
ESP_SD::setState(ESP_SDCARD_BUSY);
parameter = get_param(cmd_params, "mkdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_SD::mkdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "rmdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_SD::rmdir(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "remove=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_SD::remove(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "exists=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_SD::exists(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "yes");
} else {
response = format_response(COMMANDID, json, false, "no");
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "create=");
if (parameter.length() != 0) {
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");
noError = false;
} else {
f.close();
}
}
}
if (hasParam && noError && response.length() == 0) {
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response =
format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
}
ESP_SD::releaseFS();
}
return 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 //SD_DEVICE
#endif // SD_DEVICE

View File

@ -18,189 +18,193 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (GLOBAL_FILESYSTEM_FEATURE)
#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"
#endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
#define COMMANDID 780
//List Global Filesystem
#if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
if (parameter.length() == 0) {
parameter = "/";
}
uint8_t fsType = ESP_GBFS::getFSType(parameter.c_str());
if (fsType==FS_UNKNOWN) {
response = format_response(COMMANDID, json, false, "Invalid path");
noError = false;
} else {
if (!ESP_GBFS::accessFS(fsType)) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
String line = "";
ESP_GBFile f;
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_READ);
uint countf = 0;
uint countd = 0;
if (f) {
if(json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" + parameter + "\",\"files\":[";
output->print (line.c_str());
} else {
line = "Directory on Global FS : " + parameter;
output->printMSGLine(line.c_str());
}
//Check directories
ESP_GBFile sub;
sub = f.openNextFile();
while (sub) {
if (sub.isDirectory()) {
line="";
countd++;
if (json) {
line="";
if (countd > 1) {
line += ",";
}
line += "{\"name\":\"" ;
line+=sub.name() ;
line+= "\",\"size\":\"-1\"}";
} else {
line = "[DIR] \t";
line+= sub.name();
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_READ);
//Check files
sub = f.openNextFile();
while (sub) {
if (!sub.isDirectory()) {
String time = "";
line="";
countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeserver.current_time(sub.getLastWrite());
#endif //FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
if (countd > 0 || countf>1) {
line += ",";
}
line+= "{\"name\":\"";
line+=sub.name() ;
line+="\",\"size\":\"";
line+=ESP_GBFS::formatBytes(sub.size());
if (time.length() > 0) {
line += "\",\"time\":\"";
line += time;
}
line+="\"}";
} else {
line+=" \t ";
line+=sub.name();
line+=" \t";
line+=ESP_GBFS::formatBytes(sub.size());
line+=" \t";
line+=time;
}
if (json) {
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
if (json) {
line = "], \"total\":\"";
line += ESP_GBFS::formatBytes(ESP_GBFS::totalBytes());
line += "\",\"used\":\"";
line += ESP_GBFS::formatBytes(ESP_GBFS::usedBytes());
line+="\",\"occupation\":\"";
uint64_t total =ESP_GBFS::totalBytes();
if (total==0) {
total=1;
}
float occupation = 100.0*ESP_GBFS::usedBytes()/total;
if ((occupation < 1) && (ESP_GBFS::usedBytes()>0)) {
occupation=1;
}
line+= String((int)round(occupation));
line+="\"}}";
output->printLN (line.c_str());
} else {
line =String(countf) + " file";
if (countf > 1) {
line += "s";
}
line += " , " + String(countd) + " dir";
if (countd > 1) {
line += "s";
}
output->printMSGLine(line.c_str());
line = "Total ";
line+=ESP_GBFS::formatBytes(ESP_GBFS::totalBytes(fsType));
line+=", Used ";
line+=ESP_GBFS::formatBytes(ESP_GBFS::usedBytes(fsType));
line+=", Available: ";
line+=ESP_GBFS::formatBytes(ESP_GBFS::freeBytes(fsType));
if (fsType!=FS_ROOT) {
output->printMSGLine(line.c_str());
}
}
ESP_GBFS::releaseFS(fsType);
return true;
} else {
response = format_response(COMMANDID, json, false, "Invalid path");
noError = false;
}
ESP_GBFS::releaseFS(fsType);
}
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() == 0) {
parameter = "/";
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
uint8_t fsType = ESP_GBFS::getFSType(parameter.c_str());
if (fsType == FS_UNKNOWN) {
response = format_response(COMMANDID, json, false, "Invalid path");
noError = false;
} else {
output->printERROR(response.c_str(), errorCode);
if (!ESP_GBFS::accessFS(fsType)) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
String line = "";
ESP_GBFile f;
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_READ);
uint countf = 0;
uint countd = 0;
if (f) {
if (json) {
line = "{\"cmd\":\"720\",\"status\":\"ok\",\"data\":{\"path\":\"" +
parameter + "\",\"files\":[";
output->print(line.c_str());
} else {
line = "Directory on Global FS : " + parameter;
output->printMSGLine(line.c_str());
}
// Check directories
ESP_GBFile sub;
sub = f.openNextFile();
while (sub) {
if (sub.isDirectory()) {
line = "";
countd++;
if (json) {
line = "";
if (countd > 1) {
line += ",";
}
line += "{\"name\":\"";
line += sub.name();
line += "\",\"size\":\"-1\"}";
} else {
line = "[DIR] \t";
line += sub.name();
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_READ);
// Check files
sub = f.openNextFile();
while (sub) {
if (!sub.isDirectory()) {
String time = "";
line = "";
countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE
if (json) {
if (countd > 0 || countf > 1) {
line += ",";
}
line += "{\"name\":\"";
line += sub.name();
line += "\",\"size\":\"";
line += ESP_GBFS::formatBytes(sub.size());
if (time.length() > 0) {
line += "\",\"time\":\"";
line += time;
}
line += "\"}";
} else {
line += " \t ";
line += sub.name();
line += " \t";
line += ESP_GBFS::formatBytes(sub.size());
line += " \t";
line += time;
}
if (json) {
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
}
sub.close();
sub = f.openNextFile();
}
f.close();
if (json) {
line = "], \"total\":\"";
line += ESP_GBFS::formatBytes(ESP_GBFS::totalBytes());
line += "\",\"used\":\"";
line += ESP_GBFS::formatBytes(ESP_GBFS::usedBytes());
line += "\",\"occupation\":\"";
uint64_t total = ESP_GBFS::totalBytes();
if (total == 0) {
total = 1;
}
float occupation = 100.0 * ESP_GBFS::usedBytes() / total;
if ((occupation < 1) && (ESP_GBFS::usedBytes() > 0)) {
occupation = 1;
}
line += String((int)round(occupation));
line += "\"}}";
output->printLN(line.c_str());
} else {
line = String(countf) + " file";
if (countf > 1) {
line += "s";
}
line += " , " + String(countd) + " dir";
if (countd > 1) {
line += "s";
}
output->printMSGLine(line.c_str());
line = "Total ";
line += ESP_GBFS::formatBytes(ESP_GBFS::totalBytes(fsType));
line += ", Used ";
line += ESP_GBFS::formatBytes(ESP_GBFS::usedBytes(fsType));
line += ", Available: ";
line += ESP_GBFS::formatBytes(ESP_GBFS::freeBytes(fsType));
if (fsType != FS_ROOT) {
output->printMSGLine(line.c_str());
}
}
ESP_GBFS::releaseFS(fsType);
return true;
} else {
response = format_response(COMMANDID, json, false, "Invalid path");
noError = false;
}
ESP_GBFS::releaseFS(fsType);
}
}
return 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 //GLOBAL_FILESYSTEM_FEATURE
#endif // GLOBAL_FILESYSTEM_FEATURE

View File

@ -18,125 +18,132 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (GLOBAL_FILESYSTEM_FEATURE)
#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 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;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
parameter.replace("mkdir=", "path=");
parameter.replace("rmdir=", "path=");
parameter.replace("exists=", "path=");
parameter.replace("create=", "path=");
parameter.replace("remove=", "path=");
String path = get_param (parameter.c_str(), "path=");
if (path.length()!=0) {
uint8_t fsType = ESP_GBFS::getFSType(path.c_str());
if (!ESP_GBFS::accessFS(fsType)) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
parameter = get_param (cmd_params, "mkdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_GBFS::mkdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "rmdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_GBFS::rmdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "remove=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_GBFS::remove(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "exists=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_GBFS::exists(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "yes");
} else {
response = format_response(COMMANDID, json, false, "no");
}
}
}
if (noError && !hasParam) {
parameter = get_param (cmd_params, "create=");
if (parameter.length() != 0) {
hasParam = true;
ESP_GBFile f;
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_WRITE);
if (!f.isOpen()) {
response = format_response(COMMANDID, json, false, "create failed");
noError = false;
} else {
f.close();
}
}
}
if (hasParam && noError && response.length() == 0) {
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
ESP_GBFS::releaseFS(fsType);
}
} else {
response = format_response(COMMANDID, json, false, "Missing parameter");
#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 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;
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response =
format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
parameter.replace("mkdir=", "path=");
parameter.replace("rmdir=", "path=");
parameter.replace("exists=", "path=");
parameter.replace("create=", "path=");
parameter.replace("remove=", "path=");
String path = get_param(parameter.c_str(), "path=");
if (path.length() != 0) {
uint8_t fsType = ESP_GBFS::getFSType(path.c_str());
if (!ESP_GBFS::accessFS(fsType)) {
response = format_response(COMMANDID, json, false, "Not available");
noError = false;
} else {
parameter = get_param(cmd_params, "mkdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_GBFS::mkdir(parameter.c_str())) {
response = format_response(COMMANDID, json, false, "mkdir failed");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
if (noError && !hasParam) {
parameter = get_param(cmd_params, "rmdir=");
if (parameter.length() != 0) {
hasParam = true;
if (!ESP_GBFS::rmdir(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "rmdir failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "remove=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_GBFS::remove(parameter.c_str())) {
response =
format_response(COMMANDID, json, false, "remove failed");
noError = false;
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "exists=");
if (parameter.length() != 0) {
hasParam = true;
if (ESP_GBFS::exists(parameter.c_str())) {
response = format_response(COMMANDID, json, true, "yes");
} else {
response = format_response(COMMANDID, json, false, "no");
}
}
}
if (noError && !hasParam) {
parameter = get_param(cmd_params, "create=");
if (parameter.length() != 0) {
hasParam = true;
ESP_GBFile f;
f = ESP_GBFS::open(parameter.c_str(), ESP_FILE_WRITE);
if (!f.isOpen()) {
response =
format_response(COMMANDID, json, false, "create failed");
noError = false;
} else {
f.close();
}
}
}
if (hasParam && noError && response.length() == 0) {
response = format_response(COMMANDID, json, true, "ok");
}
if (!hasParam) {
response =
format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
ESP_GBFS::releaseFS(fsType);
}
} else {
output->printERROR(response.c_str(), errorCode);
response = format_response(COMMANDID, json, false, "Missing parameter");
noError = false;
}
return 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 //GLOBAL_FILESYSTEM_FEATURE
#endif // GLOBAL_FILESYSTEM_FEATURE

View File

@ -18,409 +18,431 @@
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
#if defined (WIFI_FEATURE) || defined(ETH_FEATURE) ||defined(BLUETOOTH_FEATURE)
#endif // FILESYSTEM_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BLUETOOTH_FEATURE)
#include "../../modules/network/netconfig.h"
#if defined (WIFI_FEATURE)
#if defined(WIFI_FEATURE)
#include "../../modules/wifi/wificonfig.h"
#endif //WIFI_FEATURE
#endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
#endif // WIFI_FEATURE
#endif // WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
#ifdef HTTP_FEATURE
#include "../../modules/http/http_server.h"
#include "../../modules/websocket/websocket_server.h"
#endif //HTTP_FEATURE
#endif // HTTP_FEATURE
#ifdef TIMESTAMP_FEATURE
#include "../../modules/time/time_server.h"
#endif //TIMESTAMP_FEATURE
#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
//eventually set time with pc time
//output is JSON or plain text according parameter
#endif // CAMERA_DEVICE
#define COMMANDID 800
// 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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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");
noError = false;
errorCode = 401;
}
}
}
if (noError) {
#ifdef TIMESTAMP_FEATURE
String newtime = get_param(cmd_params, "time=");
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 {
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
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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");
noError = false;
}
}
String tparm = "none";
#endif // TIMESTAMP_FEATURE
String line = "";
if (json) {
line = "{\"cmd\":\"800\",\"status\":\"ok\",\"data\":{";
}
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";
}
} else {
if (!timeserver.is_internet_time() && (newtime.length() == 0)) {
tparm="Not set";
}
}
#endif //TIMESTAMP_FEATURE
// FW version
if (json) {
line += "\"FWVersion\":\"";
} else {
line += "FW version:";
}
#if defined(SHORT_BUILD_VERSION)
line += SHORT_BUILD_VERSION;
line += "-";
#endif // SHORT_BUILD_VERSION
line += FW_VERSION;
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// FW target
if (json) {
line += ",\"FWTarget\":\"";
} else {
line += "FW target:";
}
line += Settings_ESP3D::GetFirmwareTargetShortName();
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// FW ID
if (json) {
line += ",\"FWTargetID\":\"";
} else {
line += "FW ID:";
}
line += Settings_ESP3D::GetFirmwareTarget();
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// Setup done
if (json) {
line += ",\"Setup\":\"";
} else {
line += "Setup:";
}
line += Settings_ESP3D::read_byte(ESP_SETUP) == 0 ? F("Enabled")
: F("Disabled");
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
String line = "";
if(json) {
line = "{\"cmd\":\"800\",\"status\":\"ok\",\"data\":{";
}
//FW version
if (json) {
line+="\"FWVersion\":\"";
} else {
line+="FW version:";
}
#if defined (SHORT_BUILD_VERSION)
line+=SHORT_BUILD_VERSION;
line+="-";
#endif //SHORT_BUILD_VERSION
line+=FW_VERSION;
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//FW target
if (json) {
line+=",\"FWTarget\":\"";
} else {
line+="FW target:";
}
line+=Settings_ESP3D::GetFirmwareTargetShortName();
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//FW ID
if (json) {
line+=",\"FWTargetID\":\"";
} else {
line+="FW ID:";
}
line+=Settings_ESP3D::GetFirmwareTarget();
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//Setup done
if (json) {
line+=",\"Setup\":\"";
} else {
line+= "Setup:";
}
line+=Settings_ESP3D::read_byte (ESP_SETUP) == 0?F("Enabled"):F("Disabled");
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
// SD connection
if (json) {
line += ",\"SDConnection\":\"";
} else {
line += "SD connection:";
}
if (Settings_ESP3D::GetSDDevice() == ESP_DIRECT_SD) {
line += "direct";
} else if (Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD) {
line += "shared";
} else {
line += "none";
}
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// Serial protocol
if (json) {
line += ",\"SerialProtocol\":\"";
} else {
line += "Serial protocol:";
}
//SD connection
if (json) {
line+=",\"SDConnection\":\"";
} else {
line+= "SD connection:";
}
if (Settings_ESP3D::GetSDDevice() == ESP_DIRECT_SD) {
line+="direct";
} else if (Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD) {
line+="shared";
} else {
line+="none";
}
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//Serial protocol
if (json) {
line+=",\"SerialProtocol\":\"";
} else {
line+= "Serial protocol:";
}
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
line+="MKS";
#endif //COMMUNICATION_PROTOCOL == MKS_SERIAL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL
line+="Raw";
#endif //COMMUNICATION_PROTOCOL == RAW_SERIAL
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
line+="Socket";
#endif //COMMUNICATION_PROTOCOL == SOCKET_SERIAL
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//Authentication
if (json) {
line+=",\"Authentication\":\"";
} else {
line+= "Authentication:";
}
#if COMMUNICATION_PROTOCOL == MKS_SERIAL
line += "MKS";
#endif // COMMUNICATION_PROTOCOL == MKS_SERIAL
#if COMMUNICATION_PROTOCOL == RAW_SERIAL
line += "Raw";
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL
#if COMMUNICATION_PROTOCOL == SOCKET_SERIAL
line += "Socket";
#endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// Authentication
if (json) {
line += ",\"Authentication\":\"";
} else {
line += "Authentication:";
}
#ifdef AUTHENTICATION_FEATURE
line+="Enabled";
line += "Enabled";
#else
line+="Disabled";
#endif //AUTHENTICATION_FEATURE
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#if (defined(WIFI_FEATURE) || defined(ETH_FEATURE)) && defined(HTTP_FEATURE)
//Web Communication
if (json) {
line+=",\"WebCommunication\":\"";
} else {
line+= "Web Communication:";
}
#if defined (ASYNCWEBSERVER_FEATURE)
line+="Asynchronous";
#else
line+="Synchronous";
#endif //ASYNCWEBSERVER_FEATURE
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//WebSocket IP
if (json) {
line+=",\"WebSocketIP\":\"";
} else {
line+= "Web Socket IP:";
}
line+=NetConfig::localIP().c_str();
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//WebSocket Port
if (json) {
line+=",\"WebSocketPort\":\"";
} else {
line+= "Web Socket Port:";
}
#if defined (ASYNCWEBSERVER_FEATURE)
line+=HTTP_Server::port();
#else
line+=websocket_terminal_server.getPort();
#endif
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif // (WIFI_FEATURE) || ETH_FEATURE) && HTTP_FEATURE)
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
//Hostname
if (json) {
line+=",\"Hostname\":\"";
} else {
line+= "Hostname:";
}
line+=NetConfig::hostname();
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //WIFI_FEATURE|| ETH_FEATURE || BT_FEATURE
#if defined(WIFI_FEATURE)
if (WiFiConfig::started()) {
//WiFi mode
if (json) {
line+=",\"WiFiMode\":\"";
} else {
line+= "WiFi mode:";
}
line+=(WiFi.getMode() == WIFI_AP)?"AP":"STA";
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
}
#endif //WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
//Update
if (json) {
line+=",\"WebUpdate\":\"";
} else {
line+= "Web update:";
}
#ifdef WEB_UPDATE_FEATURE
if (ESP_FileSystem::max_update_size()!=0) {
line+="Enabled";
} else {
line+="Disabled";
}
#else
line+="Disabled";
#endif //WEB_UPDATE_FEATURE
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //WIFI_FEATURE|| ETH_FEATURE
//FS
if (json) {
line+=",\"FlashFileSystem\":\"";
} else {
line+= "Flash File System:";
}
#if defined(FILESYSTEM_FEATURE)
line+=ESP_FileSystem::FilesystemName();
#else
line+="none";
#endif //FILESYSTEM_FEATURE
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
// Host path
if (json) {
line+=",\"HostPath\":\"";
} else {
line+= "Host Path:";
}
line+= ESP3D_HOST_PATH;
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//time server
if (json) {
line+=",\"Time\":\"";
} else {
line+= "Time:";
}
#ifdef TIMESTAMP_FEATURE
line+=tparm;
#else
line+="none";
#endif //TIMESTAMP_FEATURE
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#ifdef CAMERA_DEVICE
//camera ID
if (json) {
line+=",\"CameraID\":\"";
} else {
line+= "Camera ID:";
}
line+=esp3d_camera.GetModel();
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
//camera Name
if (json) {
line+=",\"CameraName\":\"";
} else {
line+= "Camera name:";
}
line+=esp3d_camera.GetModelString();
if (json) {
line +="\"";
output->print (line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line="";
#endif //CAMERA_DEVICE
if(json) {
output->printLN("}}");
}
return true;
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
line += "Disabled";
#endif // AUTHENTICATION_FEATURE
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printMSGLine(line.c_str());
}
return noError;
}
line = "";
#if (defined(WIFI_FEATURE) || defined(ETH_FEATURE)) && defined(HTTP_FEATURE)
// Web Communication
if (json) {
line += ",\"WebCommunication\":\"";
} else {
line += "Web Communication:";
}
#if defined(ASYNCWEBSERVER_FEATURE)
line += "Asynchronous";
#else
line += "Synchronous";
#endif // ASYNCWEBSERVER_FEATURE
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// WebSocket IP
if (json) {
line += ",\"WebSocketIP\":\"";
} else {
line += "Web Socket IP:";
}
line += NetConfig::localIP().c_str();
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// WebSocket Port
if (json) {
line += ",\"WebSocketPort\":\"";
} else {
line += "Web Socket Port:";
}
#if defined(ASYNCWEBSERVER_FEATURE)
line += HTTP_Server::port();
#else
line += websocket_terminal_server.getPort();
#endif
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // (WIFI_FEATURE) || ETH_FEATURE) && HTTP_FEATURE)
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
// Hostname
if (json) {
line += ",\"Hostname\":\"";
} else {
line += "Hostname:";
}
line += NetConfig::hostname();
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // WIFI_FEATURE|| ETH_FEATURE || BT_FEATURE
#if defined(WIFI_FEATURE)
if (WiFiConfig::started()) {
// WiFi mode
if (json) {
line += ",\"WiFiMode\":\"";
} else {
line += "WiFi mode:";
}
line += (WiFi.getMode() == WIFI_AP) ? "AP" : "STA";
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
}
#endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
// Update
if (json) {
line += ",\"WebUpdate\":\"";
} else {
line += "Web update:";
}
#ifdef WEB_UPDATE_FEATURE
if (ESP_FileSystem::max_update_size() != 0) {
line += "Enabled";
} else {
line += "Disabled";
}
#else
line += "Disabled";
#endif // WEB_UPDATE_FEATURE
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // WIFI_FEATURE|| ETH_FEATURE
// FS
if (json) {
line += ",\"FlashFileSystem\":\"";
} else {
line += "Flash File System:";
}
#if defined(FILESYSTEM_FEATURE)
line += ESP_FileSystem::FilesystemName();
#else
line += "none";
#endif // FILESYSTEM_FEATURE
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// Host path
if (json) {
line += ",\"HostPath\":\"";
} else {
line += "Host Path:";
}
line += ESP3D_HOST_PATH;
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// time server
if (json) {
line += ",\"Time\":\"";
} else {
line += "Time:";
}
#ifdef TIMESTAMP_FEATURE
line += tparm;
#else
line += "none";
#endif // TIMESTAMP_FEATURE
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#ifdef CAMERA_DEVICE
// camera ID
if (json) {
line += ",\"CameraID\":\"";
} else {
line += "Camera ID:";
}
line += esp3d_camera.GetModel();
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
// camera Name
if (json) {
line += ",\"CameraName\":\"";
} else {
line += "Camera name:";
}
line += esp3d_camera.GetModelString();
if (json) {
line += "\"";
output->print(line.c_str());
} else {
output->printMSGLine(line.c_str());
}
line = "";
#endif // CAMERA_DEVICE
if (json) {
output->printLN("}}");
}
return true;
}
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,68 +19,72 @@
*/
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
String r;
if (parameter.length() == 0) {
if (serial_service.started()) {
r="ENABLED";
} else {
r="DISABLED";
}
r+=" - Serial" + String(serial_service.serialIndex());
response = format_response(COMMANDID, json, true, r.c_str());
} else { //set
if (parameter == "ENABLE" ) {
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");
noError = false;
}
} else if (parameter == "DISABLE" ) {
response = format_response(COMMANDID, json, true, "ok");
serial_service.end();
} else {
response = format_response(COMMANDID, json, false, "Incorrect command");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
String r;
if (parameter.length() == 0) {
if (serial_service.started()) {
r = "ENABLED";
} else {
r = "DISABLED";
}
r += " - Serial" + String(serial_service.serialIndex());
response = format_response(COMMANDID, json, true, r.c_str());
} else { // set
if (parameter == "ENABLE") {
if (serial_service.begin(ESP_SERIAL_OUTPUT)) {
response = format_response(COMMANDID, json, true, "ok");
} else {
output->printMSG (response.c_str() );
response = format_response(COMMANDID, json, false,
"Cannot enable serial communication");
noError = false;
}
} else {
output->printERROR(response.c_str(), errorCode);
} else if (parameter == "DISABLE") {
response = format_response(COMMANDID, json, true, "ok");
serial_service.end();
} else {
response = format_response(COMMANDID, json, false, "Incorrect command");
noError = false;
}
}
return 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,69 +19,75 @@
*/
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if (serial_service.is_valid_baudrate(ibuf)) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_BAUD_RATE, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if (serial_service.is_valid_baudrate(ibuf)) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_uint32(ESP_BAUD_RATE, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //COMMUNICATION_PROTOCOL != SOCKET_SERIAL
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL

View File

@ -18,73 +18,78 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (BUZZER_DEVICE)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
if (esp3d_buzzer.started()) {
response = format_response(COMMANDID, json, true, "ENABLED");
} else {
response = format_response(COMMANDID, json, true, "DISABLED");
}
} else { //set
if (parameter == "ENABLE" || parameter == "DISABLE" ) {
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");
noError = false;
}
} else if (parameter == "DISABLE" ) {
esp3d_buzzer.end();
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect command");
noError = false;
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
if (esp3d_buzzer.started()) {
response = format_response(COMMANDID, json, true, "ENABLED");
} else {
response = format_response(COMMANDID, json, true, "DISABLED");
}
} else { // set
if (parameter == "ENABLE" || parameter == "DISABLE") {
if (!Settings_ESP3D::write_byte(ESP_BUZZER,
(parameter == "ENABLE") ? 1 : 0)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
output->printMSG (response.c_str() );
if (parameter == "ENABLE") {
if (!esp3d_buzzer.begin()) {
response = format_response(COMMANDID, json, false,
"Starting service failed");
noError = false;
}
} else if (parameter == "DISABLE") {
esp3d_buzzer.end();
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
} else {
response = format_response(COMMANDID, json, false, "Incorrect command");
noError = false;
}
}
return 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
#endif // BUZZER_DEVICE

View File

@ -18,331 +18,365 @@
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)
{
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
String s = "";
if (json) {
s += "{";
}
bool hasData=false;
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
hasData=true;
if (json) {
s += "\"";
}
s += "SERIAL";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_SERIAL_CLIENT)?"ON":"OFF";
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)))
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "REMOTE_SCREEN";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_REMOTE_SCREEN_CLIENT)?"ON":"OFF";
if (json) {
s += "\"";
}
#endif //!defined(ESP3DLIB_ENV) || (defined (ESP3DLIB_ENV) && HAS_DISPLAY)
#ifdef DISPLAY_DEVICE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "REMOTE_SCREEN";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_SCREEN_CLIENT)?"ON":"OFF";
if (json) {
s += "\"";
}
#endif //DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "WEBSOCKET";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_WEBSOCKET_CLIENT)?"ON":"OFF";
if (json) {
s += "\"";
}
#endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "BT";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_BT_CLIENT)?"ON":"OFF";
if (json) {
s += "\"";
}
#endif //BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "TELNET";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_TELNET_CLIENT)?"ON":"OFF";
if (json) {
s += "\"";
}
#endif //TELNET_FEATURE
if (json) {
s += "}";
}
response = format_response(COMMANDID, json, true, s.c_str());
} else { //set
#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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
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)))
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
}
#endif //!defined(ESP3DLIB_ENV) || (defined (ESP3DLIB_ENV) && HAS_DISPLAY)
if (noError && !hasParam) {
parameter = get_param (cmd_params, "ALL=");
if (parameter.length() != 0) {
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
#ifdef DISPLAY_DEVICE
!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)||
#endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
!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)||
#endif //TELNET_FEATURE
!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");
noError = false;
}
}
}
#ifdef DISPLAY_DEVICE
if (noError && !hasParam) {
parameter = get_param (cmd_params, "SCREEN=");
if (parameter.length() != 0) {
hasParam=true;
if ((parameter == "ON")|| (parameter == "OFF")) {
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");
noError = false;
}
}
}
#endif //DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
if (noError && !hasParam) {
parameter = get_param (cmd_params, "WEBSOCKET=");
if (parameter.length() != 0) {
hasParam=true;
if ((parameter == "ON")|| (parameter == "OFF")) {
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");
noError = false;
}
}
}
#endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
if (noError && !hasParam) {
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
}
#endif //BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
if (noError && !hasParam) {
parameter = get_param (cmd_params, "TELNET=");
if (parameter.length() != 0) {
hasParam=true;
if ((parameter == "ON")|| (parameter == "OFF")) {
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");
noError = false;
}
}
}
#endif //TELNET_FEATURE
//all ok we do the hot change
if(noError) {
if ( hasParam) {
ESP3DOutput::isOutput(ESP_ALL_CLIENTS,true);
response = format_response(COMMANDID, json, true, "ok");
} else {
response = format_response(COMMANDID, json, false, "Incorrect parameter");
noError = false;
}
}
}
}
if (noError) {
#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) {
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
String s = "";
if (json) {
s += "{";
}
bool hasData = false;
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
COMMUNICATION_PROTOCOL == MKS_SERIAL || \
COMMUNICATION_PROTOCOL == SOCKET_SERIAL
hasData = true;
if (json) {
s += "\"";
}
s += "SERIAL";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_SERIAL_CLIENT) ? "ON" : "OFF";
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)))
if (hasData) {
if (json) {
output->printLN (response.c_str() );
s += ",";
} else {
output->printMSG (response.c_str() );
s += ", ";
}
} else {
output->printERROR(response.c_str(), errorCode);
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "REMOTE_SCREEN";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_REMOTE_SCREEN_CLIENT) ? "ON" : "OFF";
if (json) {
s += "\"";
}
#endif //! defined(ESP3DLIB_ENV) || (defined (ESP3DLIB_ENV) && HAS_DISPLAY)
#ifdef DISPLAY_DEVICE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "REMOTE_SCREEN";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_SCREEN_CLIENT) ? "ON" : "OFF";
if (json) {
s += "\"";
}
#endif // DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "WEBSOCKET";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_WEBSOCKET_CLIENT) ? "ON" : "OFF";
if (json) {
s += "\"";
}
#endif // WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "BT";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_BT_CLIENT) ? "ON" : "OFF";
if (json) {
s += "\"";
}
#endif // BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
if (hasData) {
if (json) {
s += ",";
} else {
s += ", ";
}
} else {
hasData = true;
}
if (json) {
s += "\"";
}
s += "TELNET";
if (json) {
s += "\":\"";
} else {
s += ":";
}
s += ESP3DOutput::isOutput(ESP_TELNET_CLIENT) ? "ON" : "OFF";
if (json) {
s += "\"";
}
#endif // TELNET_FEATURE
if (json) {
s += "}";
}
response = format_response(COMMANDID, json, true, s.c_str());
} else { // set
#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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response = format_response(COMMANDID, json, false, "Incorrect value");
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)))
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
}
#endif //! defined(ESP3DLIB_ENV) || (defined (ESP3DLIB_ENV) && HAS_DISPLAY)
if (noError && !hasParam) {
parameter = get_param(cmd_params, "ALL=");
if (parameter.length() != 0) {
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
#ifdef DISPLAY_DEVICE
!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) ||
#endif // WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
!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) ||
#endif // TELNET_FEATURE
!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");
noError = false;
}
}
}
#ifdef DISPLAY_DEVICE
if (noError && !hasParam) {
parameter = get_param(cmd_params, "SCREEN=");
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
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");
noError = false;
}
}
}
#endif // DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
if (noError && !hasParam) {
parameter = get_param(cmd_params, "WEBSOCKET=");
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
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");
noError = false;
}
}
}
#endif // WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
if (noError && !hasParam) {
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)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
}
} else {
response =
format_response(COMMANDID, json, false, "Incorrect value");
noError = false;
}
}
}
#endif // BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
if (noError && !hasParam) {
parameter = get_param(cmd_params, "TELNET=");
if (parameter.length() != 0) {
hasParam = true;
if ((parameter == "ON") || (parameter == "OFF")) {
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");
noError = false;
}
}
}
#endif // TELNET_FEATURE
// all ok we do the hot change
if (noError) {
if (hasParam) {
ESP3DOutput::isOutput(ESP_ALL_CLIENTS, true);
response = format_response(COMMANDID, json, true, "ok");
} else {
response =
format_response(COMMANDID, json, false, "Incorrect parameter");
noError = false;
}
}
}
return 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,80 +18,89 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (ESP_SERIAL_BRIDGE_OUTPUT)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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";
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");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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";
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");
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!");
noError = false;
} else {
if (parameter == "CLOSE") {
serial_bridge_service.end();
} else {
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()) {
serial_bridge_service.begin(ESP_SERIAL_BRIDGE_OUTPUT);
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#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!");
noError = false;
} else {
output->printMSG (response.c_str() );
if (parameter == "CLOSE") {
serial_bridge_service.end();
} else {
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()) {
serial_bridge_service.begin(ESP_SERIAL_BRIDGE_OUTPUT);
}
}
if (noError) {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //TELNET_FEATURE
#endif // TELNET_FEATURE

View File

@ -18,70 +18,76 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (ESP_SERIAL_BRIDGE_OUTPUT)
#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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
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());
} else { // set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false,
"Wrong authentication level");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
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());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = format_response(COMMANDID, json, false, "Wrong authentication level");
noError = false;
errorCode = 401;
}
#endif //AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if (serial_bridge_service.is_valid_baudrate(ibuf)) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
if (!Settings_ESP3D::write_uint32 (ESP_SERIAL_BRIDGE_BAUD, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
}
}
if (noError) {
if (json) {
output->printLN (response.c_str() );
}
#endif // AUTHENTICATION_FEATURE
if (noError) {
uint ibuf = parameter.toInt();
if (serial_bridge_service.is_valid_baudrate(ibuf)) {
response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false;
} else {
output->printMSG (response.c_str() );
if (!Settings_ESP3D::write_uint32(ESP_SERIAL_BRIDGE_BAUD, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
} else {
output->printERROR(response.c_str(), errorCode);
}
}
return 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 //TELNET_FEATURE
#endif // TELNET_FEATURE

View File

@ -18,57 +18,65 @@
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
#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 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
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
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false, "Guest user can't use this command");
noError = false;
errorCode = 401;
}
if (auth_type == LEVEL_GUEST) {
response = format_response(COMMANDID, json, false,
"Guest user can't use this command");
noError = false;
errorCode = 401;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param (cmd_params, ""));
//get
if (parameter.length() == 0) {
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?)");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
(void)auth_type;
#endif // AUTHENTICATION_FEATURE
if (noError) {
parameter = clean_param(get_param(cmd_params, ""));
// get
if (parameter.length() == 0) {
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?)");
noError = false;
} else {
response = format_response(COMMANDID, json, true, "ok");
}
}
}
if (json) {
output->printLN(response.c_str());
} else {
if (noError) {
if (json) {
output->printLN (response.c_str() );
} else {
output->printMSG (response.c_str() );
}
output->printMSG(response.c_str());
} else {
output->printERROR(response.c_str(), errorCode);
output->printERROR(response.c_str(), errorCode);
}
return noError;
}
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

@ -20,41 +20,52 @@
#ifndef _ESP3D_HAL_H
#define _ESP3D_HAL_H
//be sure correct IDE and settings are used for ESP8266 or ESP32
#if !(defined( ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32))
// be sure correct IDE and settings are used for ESP8266 or ESP32
#if !(defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32))
#error Oops! Make sure you have 'ESP8266 or ESP32' compatible board selected from the 'Tools -> Boards' menu.
#endif // ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32
#endif // ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#endif //ARDUINO_ARCH_ESP8266
#endif // ARDUINO_ARCH_ESP8266
#if defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <esp_task_wdt.h>
#endif //ARDUINO_ARCH_ESP32
#endif // ARDUINO_ARCH_ESP32
#include <Arduino.h>
class Hal
{
public:
static bool begin();
static void end();
static void wait (uint32_t milliseconds);
static uint16_t getChipID();
static bool has_temperature_sensor();
static float temperature();
static bool is_pin_usable(uint pin);
static void clearAnalogChannels();
static void pinMode(uint8_t pin, uint8_t mode);
static int analogRead(uint8_t pin);
static bool analogWrite(uint8_t pin, uint value);
static void analogWriteFreq(uint32_t freq);
static void analogRange(uint32_t range);
class Hal {
public:
static bool begin();
static void end();
static void wait(uint32_t milliseconds);
static uint16_t getChipID();
static bool has_temperature_sensor();
static float temperature();
static bool is_pin_usable(uint pin);
static void clearAnalogChannels();
static void pinMode(uint8_t pin, uint8_t mode);
static int analogRead(uint8_t pin);
static bool analogWrite(uint8_t pin, uint value);
static void analogWriteFreq(uint32_t freq);
static void analogRange(uint32_t range);
#if defined(ARDUINO_ARCH_ESP32)
static TaskHandle_t xHandle;
#endif //ARDUINO_ARCH_ESP32
private:
static void wdtFeed();
static uint32_t _analogRange;
static uint32_t _analogWriteFreq;
static TaskHandle_t xHandle;
#endif // ARDUINO_ARCH_ESP32
private:
static void wdtFeed();
static uint32_t _analogRange;
static uint32_t _analogWriteFreq;
};
#endif //_ESP3D_HAL_H
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