Settings validation refactoring (#964)

* Rewrite the setting API to use same API as ESP3D-TFT or at least close enough to be improved - WIP

* Add isValidXXX setting API

* Factorize dispatch_setting for ESP400

* ESP400 refactoring
This commit is contained in:
Luc 2023-11-09 10:29:13 +08:00 committed by GitHub
parent 265e0e60a2
commit cda276e2e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 2388 additions and 2209 deletions

View File

@ -1552,132 +1552,180 @@ the admin password if authentication is enabled
+++ +++
archetype = "section" archetype = "section"
title = "[ESP800]" title = "[ESP400]"
weight = 800 weight = 800
+++ +++
Get FW capabilities Get full ESP3D settings
## Input ## Input
`[ESP400] json=<no> pwd=<admin password>`
`[ESP800]<time=YYYY-MM-DDTHH:mm:ss> <tzone=+HH:ss> <version=3.0.0-a11> <setup=0/1> json=<no> pwd=<admin/user password>`
* json=no * json=no
the output format the output format
can be in JSON or plain text can be in JSON or plain text
* time=
to set ESP3D time using ISO 8601 format : `YYYY`-`MM`-`DD`T`HH`:`minutes`:`seconds`
* tzone=
to set ESP3D time zone using ISO 8601 format : `+`/`-` `HH`:`minutes`
* pwd=<admin password> * pwd=<admin password>
the admin password if authentication is enabled the admin password if authentication is enabled
* version
version of webUI
* setup flag
Enable / Disable the setup flag
## Output ## Output
- In json format Passwords are not displayed and replaced by `********`
* if json
```json ```json
{ {"cmd":"400","status":"ok","data":[
"cmd":"800", {"F":"network/network","P":"130","T":"S","R":"1","V":"esp3d","H":"hostname" ,"S":"32", "M":"1"},
"status":"ok", {"F":"network/network","P":"0","T":"B","R":"1","V":"1","H":"radio mode","O":[{"none":"0"},
"data":{ {"sta":"1"},
"FWVersion":"bugfix-2.0.x-3.0.0.a200", {"ap":"2"},
"FWTarget":"marlin", {"setup":"5"}]},
"FWTargetID":"30", {"F":"network/network","P":"1034","T":"B","R":"1","V":"1","H":"radio_boot","O":[{"no":"0"},
"Setup":"Enabled", {"yes":"1"}]},
"SDConnection":"shared", {"F":"network/sta","P":"1","T":"S","V":"Luc-Lab","S":"32","H":"SSID","M":"1"},
"SerialProtocol":"Socket", {"F":"network/sta","P":"34","T":"S","N":"1","MS":"0","R":"1","V":"********","S":"64","H":"pwd","M":"8"},
"Authentication":"Disabled", {"F":"network/sta","P":"99","T":"B","R":"1","V":"1","H":"ip mode","O":[{"dhcp":"1"},
"WebCommunication":"Synchronous", {"static":"0"}]},
"WebSocketIP":"192.168.2.117", {"F":"network/sta","P":"100","T":"A","R":"1","V":"192.168.0.1","H":"ip"},
"WebSocketPort":"81", {"F":"network/sta","P":"108","T":"A","R":"1","V":"192.168.0.1","H":"gw"},
"Hostname":"esp3d", {"F":"network/sta","P":"104","T":"A","R":"1","V":"255.255.255.0","H":"msk"},
"WiFiMode":"STA", {"F":"network/sta","P":"1029","T":"A","R":"1","V":"192.168.0.1","H":"DNS"},
"WebUpdate":"Enabled", {"F":"network/sta","P":"1035","T":"B","R":"0","V":"5","H":"sta fallback mode","O":[{"none":"0"},
"FlashFileSystem":"LittleFS", {"setup":"5"}]},
"HostPath":"www", {"F":"network/ap","P":"218","T":"S","R":"1","V":"ESP3D","S":"32","H":"SSID","M":"1"},
"Time":"none" {"F":"network/ap","P":"251","T":"S","N":"1","MS":"0","R":"1","V":"********","S":"64","H":"pwd","M":"8"},
} {"F":"network/ap","P":"316","T":"A","R":"1","V":"192.168.0.1","H":"ip"},
} {"F":"network/ap","P":"118","T":"B","R":"1","V":"11","H":"channel","O":[{"1":"1"},
{"2":"2"},
{"3":"3"},
{"4":"4"},
{"5":"5"},
{"6":"6"},
{"7":"7"},
{"8":"8"},
{"9":"9"},
{"10":"10"},
{"11":"11"},
{"12":"12"},
{"13":"13"},
{"14":"14"}]},
{"F":"service/http","P":"328","T":"B","R":"1","V":"1","H":"enable","O":[{"no":"0"},{"yes":"1"}]},
{"F":"service/http","P":"121","T":"I","R":"1","V":"8181","H":"port","S":"65001","M":"1"},
{"F":"service/telnetp","P":"329","T":"B","R":"1","V":"1","H":"enable","O":[{"no":"0"},{"yes":"1"}]},
{"F":"service/telnetp","P":"125","T":"I","R":"1","V":"23","H":"port","S":"65001","M":"1"},
{"F":"service/webdavp","P":"1024","T":"B","R":"1","V":"1","H":"enable","O":[{"no":"0"},{"yes":"1"}]},
{"F":"service/webdavp","P":"1025","T":"I","R":"1","V":"80","H":"port","S":"65001","M":"1"},
{"F":"service/time","P":"120","T":"B","V":"1","H":"i-time","O":[{"no":"0"},{"yes":"1"}]},
{"F":"service/time","P":"1042","T":"S","R":"1","V":"+08:00","H":"tzone","O":[{"-12:00":"-12:00"},
{"-11:00":"-11:00"},
{"-10:00":"-10:00"},
{"-09:00":"-09:00"},
{"-08:00":"-08:00"},
{"-07:00":"-07:00"},
{"-06:00":"-06:00"},
{"-05:00":"-05:00"},
{"-04:00":"-04:00"},
{"-03:30":"-03:30"},
{"-03:00":"-03:00"},
{"-02:00":"-02:00"},
{"-01:00":"-01:00"},
{"+00:00":"+00:00"},
{"+01:00":"+01:00"},
{"+02:00":"+02:00"},
{"+03:00":"+03:00"},
{"+03:30":"+03:30"},
{"+04:00":"+04:00"},
{"+04:30":"+04:30"},
{"+05:00":"+05:00"},
{"+05:30":"+05:30"},
{"+05:45":"+05:45"},
{"+06:00":"+06:00"},
{"+06:30":"+06:30"},
{"+07:00":"+07:00"},
{"+08:00":"+08:00"},
{"+08:45":"+08:45"},
{"+09:00":"+09:00"},
{"+09:30":"+09:30"},
{"+10:00":"+10:00"},
{"+10:30":"+10:30"},
{"+11:00":"+11:00"},
{"+12:00":"+12:00"},
{"+12:45":"+12:45"},
{"+13:00":"+13:00"},
{"+14:00":"+14:00"}]},
{"F":"service/time","P":"464","T":"S","R":"1","V":"time.windows.com","S":"128","H":"t-server","M":"0"},
{"F":"service/time","P":"593","T":"S","R":"1","V":"time.google.com","S":"128","H":"t-server","M":"0"},
{"F":"service/time","P":"722","T":"S","R":"1","V":"0.pool.ntp.org","S":"128","H":"t-server","M":"0"},
{"F":"service/notification","P":"1022","T":"B","R":"1","V":"1","H":"auto notif","O":[{"no":"0"},{"yes":"1"}]},
{"F":"service/notification","P":"116","T":"B","R":"1","V":"0","H":"notification","O":[{"none":"0"},
{"pushover":"1"},
{"email":"2"},
{"line":"3"},
{"telegram":"4"},
{"IFTTT":"5"}]},
{"F":"service/notification","P":"332","T":"S","R":"1","V":"********","S":"63","H":"t1","M":"0"},
{"F":"service/notification","P":"396","T":"S","R":"1","V":"********","S":"63","H":"t2","M":"0"},
{"F":"service/notification","P":"856","T":"S","R":"1","V":" ","S":"128","H":"ts","M":"0"},
{"F":"system/system","P":"461","T":"B","V":"0","H":"targetfw","O":[{"repetier":"50"},
{"marlin":"20"},
{"smoothieware":"40"},
{"grbl":"10"},
{"unknown":"0"}]},
{"F":"system/system","P":"112","T":"I","V":"115200","H":"baud","O":[{"9600":"9600"},
{"19200":"19200"},
{"38400":"38400"},
{"57600":"57600"},
{"74880":"74880"},
{"115200":"115200"},
{"230400":"230400"},
{"250000":"250000"},
{"500000":"500000"},
{"921600":"921600"},
{"1958400":"1958400"}]},
{"F":"system/boot","P":"320","T":"I","V":"100","H":"bootdelay","S":"40000","M":"0"},
{"F":"system/boot","P":"1023","T":"B","V":"0","H":"verbose","O":[{"no":"0"},{"yes":"1"}]},
{"F":"system/outputmsg","P":"129","T":"B","V":"1","H":"serial","O":[{"no":"0"},{"yes":"1"}]},
{"F":"system/outputmsg","P":"851","T":"B","V":"1","H":"M117","O":[{"no":"0"},{"yes":"1"}]},
{"F":"system/outputmsg","P":"1006","T":"B","V":"1","H":"telnet","O":[{"no":"0"},{"yes":"1"}]
}]}
``` ```
* `cmd` 1 - key : `Settings`
Id of requested command, should be `800` 2 - value: array of data formated like this
{"F":"network/network","P":"130","T":"S","V":"esp3d","H":"hostname","S":"32","M":"1"}
or
{"F":"service/notification","P":"1004","T":"B","V":"1","H":"auto notif","O":[{"no":"0"},{"yes":"1"}]}
* `status` - F: is filter formated as section/sub-section, if section is same as sub-section, it means no sub-section
status of command, should be `ok` - P: is id (also position reference so it is unique)
- T: is type of data which can be:
- S: for string
- I: for integer
- B: for Byte
- A: for IP address / Mask
- F: for float (only grblHAL)
- M: for bits mask (only grblHAL)
- X: for exclusive bitsfield (only grblHAL)
- V: is current value, if type is string and value is `********`, (8 stars) then it is a password
- E: is integer for exactess / precision of float/double value (only grblHAL)
- U: is text unit of value (only grblHAL)
- H: is text label of value
- S: is max size if type is string, and max possible value if value is number (byte, integer)
- M: is min size if type is string, and min possible value if value is number (byte, integer)
- MS: is additionnal min size if type is string (e.g for password can be 0 or 8, so need additional min size), M should be the more minimal value
so MS value must be between M and S
- O: is an array of {label:value} used for possible values in selection or bits labels list
- R: need restart to be applied
* `data` Note: if Type `M` and `X` use `O` entry to define the label / position, if `O` is `[]` then axis label are used according need `X`, `Y`, `Z`, `A`, `B`, `C`
content of response: Note2 : the 2.1 Flag type is no more used, several entries are used instead grouped by sub-section
* `FWVersion`
Version of ESP3D firmware or targeted FW (Marlin with ESP3DLib / grblHal) If no json the list is limited to a list of `<help>: <value>`
* `FWTarget`
name of targeted Firmware ```text
* `FWTargetID`
numerical ID of targeted FW as same name can have several Ids Settings:
* `Setup` network/network/hostname: esp3d
Should be `Enabled` or `Disabled` according flag in EEPROM/Preferences, this allows to WedUI to start wizard automaticaly (or not) network/network/mdns: 1
```
* `SDConnection`
This is SD capability, SD can be
* `shared`
ESP does share access to SD card reader with main board or Firmware (Marlin with ESP3Dlib, ESP3D with hardware SD share solution)
* `direct`
ESP does have direct access to SD card reader (e.g: ESP3D, grblHal)
* `none`
ESP does not have direct access to SD card reader, (e.g: ESP3D with only serial connection)
* `SerialProtocol`
It define how ESP3D FW communicate with main FW
* `Socket`
ESP and main FW use same FW (e.g: Marlin with ESP3DLib, grblHal)
* `Raw`
Classic serial connection
* `MKS`
Serial connection using MKS protocol
* `Authentication`
Can be `Enabled` or `Disabled`
* `WebCommunication`
currently only `Synchronous`, because `Asychronous` has been put in hold
* `WebSocketIP`
Ip address for the websocket terminal `192.168.2.117`
* `WebSocketPort`
Port for the web socket terminal `81`
* `Hostname`
Hostname of ESP3D or main Baord `esp3d`
* `WiFiMode`
Current wiFi mode in use can be `AP` or `STA`
* `WebUpdate`
Inform webUI the feature is available or not, can be `Enabled` or `Disabled`
* `FlashFileSystem` (currently `FileSystem`, to be updated soon )
The file system used by ESP board can be `LittleFS`, `SPIFFS`, `Fat`, `none`
* `HostPath`
Path where the preferences.json and index.html.gz are stored and can be updated (e.g: `www`)
* `Time`
Type of time support
* `none`
Time is not supported
* `Auto`
Board use internet to sync time and it is successful
* `Failed to set`
Board use internet to sync time and it is failed
* `Manual`
Board use time of ESP800 to set the time and it is successful
* `Not set`
Board use time of ESP800 to set the time and command did not sent it (time may have been set by previous command)
* `CameraID`
if ESP has camera it contain the camera ID
* `CameraName`
if ESP has camera it contain the camera name
* `Axisletters`
Currently only used for grbHAL
can be :
- XYZABC
- XYZUVZ (supported soon)
- XYZABCUVZ (supported soon)

41
docs/pagespliter.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python3
import os
input_file = "espXXX.md"
output_file_head = "esp"
output_ext = ".md"
f = open(input_file, "r")
lines = f.readlines()
#parse each lines
head = ""
have_command = False
fo=0
count = 0
for line in lines:
if not have_command:
count=0
head+=line
if line.startswith("title ="):
have_command = True
num = line.split("ESP")[1].split("]")[0]
fo = open(output_file_head+num+output_ext, "w")
fo.write(head)
have_command = True
else:
if line.startswith("+++"):
count+=1
if count==2:
fo.close()
have_command = False
head = line
print("close file "+output_file_head+num+output_ext)
else:
fo.write(line)
else:
fo.write(line)
f.close()

View File

@ -809,3 +809,161 @@ bool Commands::execute_internal_command(int cmd, const char *cmd_params,
} }
return response; return response;
} }
bool Commands::_dispatchSetting(
bool json, const char *filter, ESP3DSettingIndex index, const char *help,
const char **optionValues, const char **optionLabels, uint32_t maxsize,
uint32_t minsize, uint32_t minsize2, uint8_t precision, const char *unit,
bool needRestart, ESP3DOutput *output, bool isFirst) {
String tmpstr;
String value;
char out_str[255];
tmpstr.reserve(
350); // to save time and avoid several memories allocation delay
const ESP3DSettingDescription *elementSetting =
Settings_ESP3D::getSettingPtr(index);
if (!elementSetting) {
return false;
}
switch (elementSetting->type) {
case ESP3DSettingType::byte_t:
value = String(Settings_ESP3D::read_byte(index));
break;
case ESP3DSettingType::integer_t:
value = String(Settings_ESP3D::read_uint32(index));
break;
case ESP3DSettingType::ip_t:
value = Settings_ESP3D::read_IP_String(index);
break;
case ESP3DSettingType::float_t:
// TODO Add float support ?
value = "Not supported";
log_esp3d_e("Float not supported");
return false;
break;
case ESP3DSettingType::mask:
// TODO Add Mask support ?
value = "Not supported";
log_esp3d_e("Mask not supported");
return false;
break;
case ESP3DSettingType::bitsfield:
// TODO Add bitfield support ?
value = "Not supported";
log_esp3d_e("Bitsfield not supported");
return false;
break;
case ESP3DSettingType::string_t:
// String
if (index == ESP_AP_PASSWORD || index == ESP_STA_PASSWORD ||
#ifdef NOTIFICATION_FEATURE
index == ESP_NOTIFICATION_TOKEN1 ||
index == ESP_NOTIFICATION_TOKEN2 ||
#endif // NOTIFICATION_FEATURE
index == ESP_USER_PWD || index == ESP_ADMIN_PWD) { // hide passwords
// using ********
value = HIDDEN_PASSWORD;
} else {
value = Settings_ESP3D::read_string(index);
}
break;
default:
value = "Not supported";
log_esp3d_e("Type not supported");
return false;
break;
}
if (json) {
if (!isFirst) {
tmpstr += ",";
}
tmpstr += "{\"F\":\"";
tmpstr += filter;
tmpstr += "\",\"P\":\"";
tmpstr += String(static_cast<uint16_t>(index));
tmpstr += "\",\"T\":\"";
// Limited support already done for above so even not supported we can
// define it once will be enabled
switch (elementSetting->type) {
case ESP3DSettingType::byte_t:
tmpstr += "B";
break;
case ESP3DSettingType::integer_t:
tmpstr += "I";
break;
case ESP3DSettingType::ip_t:
tmpstr += "A";
break;
case ESP3DSettingType::float_t:
tmpstr += "F";
break;
case ESP3DSettingType::mask:
tmpstr += "M";
break;
case ESP3DSettingType::bitsfield:
tmpstr += "X";
break;
default:
tmpstr += "S";
}
tmpstr += "\",\"V\":\"";
tmpstr += value;
tmpstr += "\",\"H\":\"";
tmpstr += help;
tmpstr += "\"";
if (needRestart) {
tmpstr += ",\"R\":\"1\"";
}
if (optionValues && optionLabels) {
tmpstr += ",\"O\":[";
for (uint8_t i = 0; i < maxsize; i++) {
if (i > 0) {
tmpstr += ",";
}
tmpstr += "{\"";
// be sure we have same size for both array to avoid overflow
tmpstr += optionLabels[i];
tmpstr += "\":\"";
tmpstr += optionValues[i];
tmpstr += "\"}";
}
tmpstr += "]";
}
if (unit) {
tmpstr += ",\"R\":\"";
tmpstr += unit;
tmpstr += "\"";
}
if (precision != ((uint8_t)-1)) {
tmpstr += ",\"E\":\"";
tmpstr += String(precision);
tmpstr += "\"";
}
if (maxsize != (uint32_t)-1 && !optionValues) {
tmpstr += ",\"S\":\"";
tmpstr += String(maxsize);
tmpstr += "\"";
}
if (minsize != (uint32_t)-1) {
tmpstr += ",\"M\":\"";
tmpstr += String(minsize);
tmpstr += "\"";
}
if (minsize2 != (uint32_t)-1) {
tmpstr += ",\"MS\":\"";
tmpstr += String(minsize2);
tmpstr += "\"";
}
tmpstr += "}";
} else {
tmpstr = filter;
tmpstr += "/";
tmpstr += help;
tmpstr += ": ";
tmpstr += value;
tmpstr += "\n";
}
output->print(tmpstr.c_str());
return true;
}

View File

@ -21,157 +21,242 @@
#ifndef COMMANDS_H #ifndef COMMANDS_H
#define COMMANDS_H #define COMMANDS_H
#include <Arduino.h> #include <Arduino.h>
#include "../modules/authentication/authentication_service.h" #include "../modules/authentication/authentication_service.h"
class ESP3DOutput; class ESP3DOutput;
class Commands class Commands {
{
public: public:
Commands(); Commands();
~Commands(); ~Commands();
void process(uint8_t * sbuf, size_t len, ESP3DOutput * output, level_authenticate_type auth = LEVEL_GUEST, ESP3DOutput * outputonly = nullptr, uint8_t outputignore = 0); void process(uint8_t* sbuf, size_t len, ESP3DOutput* output,
level_authenticate_type auth = LEVEL_GUEST,
ESP3DOutput* outputonly = nullptr, uint8_t outputignore = 0);
bool is_esp_command(uint8_t* sbuf, size_t len); bool is_esp_command(uint8_t* sbuf, size_t len);
bool execute_internal_command(int cmd, const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool execute_internal_command(int cmd, const char* cmd_params,
level_authenticate_type auth_level,
ESP3DOutput* output);
int get_space_pos(const char* string, uint from = 0); int get_space_pos(const char* string, uint from = 0);
const char* get_param(const char* cmd_params, const char* label); const char* get_param(const char* cmd_params, const char* label);
const char* get_label (const char * cmd_params, const char * labelseparator, uint8_t startindex = 0); const char* get_label(const char* cmd_params, const char* labelseparator,
uint8_t startindex = 0);
const char* clean_param(const char* cmd_params); const char* clean_param(const char* cmd_params);
const char * format_response(uint cmdID, bool isjson = false, bool isok=true, const char * message=""); const char* format_response(uint cmdID, bool isjson = false, bool isok = true,
const char* message = "");
bool has_tag(const char* cmd_params, const char* tag); bool has_tag(const char* cmd_params, const char* tag);
bool ESP0(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP0(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if defined(WIFI_FEATURE) #if defined(WIFI_FEATURE)
bool ESP100(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP100(const char* cmd_params, level_authenticate_type auth_level,
bool ESP101(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP101(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE #endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) #if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
bool ESP102(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP102(const char* cmd_params, level_authenticate_type auth_level,
bool ESP103(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP103(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE ||ETH_FEATURE #endif // WIFI_FEATURE ||ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE) #if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
bool ESP104(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP104(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE #endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) #if defined(WIFI_FEATURE)
bool ESP105(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP105(const char* cmd_params, level_authenticate_type auth_level,
bool ESP106(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP107(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP106(const char* cmd_params, level_authenticate_type auth_level,
bool ESP108(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP107(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
bool ESP108(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE #endif // WIFI_FEATURE
#if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE) #if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE)
bool ESP110(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP110(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE #endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) #if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
bool ESP111(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP111(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE || ETH_FEATURE #endif // WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE) #if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
bool ESP112(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP112(const char* cmd_params, level_authenticate_type auth_level,
bool ESP114(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP115(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP114(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
bool ESP115(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE #endif // WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(HTTP_FEATURE) #if defined(HTTP_FEATURE)
bool ESP120(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP120(const char* cmd_params, level_authenticate_type auth_level,
bool ESP121(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP121(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // HTTP_FEATURE #endif // HTTP_FEATURE
#if defined(TELNET_FEATURE) #if defined(TELNET_FEATURE)
bool ESP130(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP130(const char* cmd_params, level_authenticate_type auth_level,
bool ESP131(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP131(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // TELNET_FEATURE #endif // TELNET_FEATURE
#if defined(TIMESTAMP_FEATURE) #if defined(TIMESTAMP_FEATURE)
bool ESP140(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP140(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // TIMESTAMP_FEATURE #endif // TIMESTAMP_FEATURE
bool ESP150(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP150(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if defined(WS_DATA_FEATURE) #if defined(WS_DATA_FEATURE)
bool ESP160(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP160(const char* cmd_params, level_authenticate_type auth_level,
bool ESP161(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP161(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WS_DATA_FEATURE #endif // WS_DATA_FEATURE
#if defined(CAMERA_DEVICE) #if defined(CAMERA_DEVICE)
bool ESP170(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP170(const char* cmd_params, level_authenticate_type auth_level,
bool ESP171(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP171(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // CAMERA_DEVICE #endif // CAMERA_DEVICE
#if defined(FTP_FEATURE) #if defined(FTP_FEATURE)
bool ESP180(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP180(const char* cmd_params, level_authenticate_type auth_level,
bool ESP181(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP181(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // FTP_FEATURE #endif // FTP_FEATURE
#if defined(WEBDAV_FEATURE) #if defined(WEBDAV_FEATURE)
bool ESP190(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP190(const char* cmd_params, level_authenticate_type auth_level,
bool ESP191(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP191(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WEBDAV_FEATURE #endif // WEBDAV_FEATURE
#if defined(SD_DEVICE) #if defined(SD_DEVICE)
bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP200(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if SD_DEVICE != ESP_SDIO #if SD_DEVICE != ESP_SDIO
bool ESP202(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP202(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // SD_DEVICE != ESP_SDIO #endif // SD_DEVICE != ESP_SDIO
#ifdef SD_UPDATE_FEATURE #ifdef SD_UPDATE_FEATURE
bool ESP402(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP402(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // SD_UPDATE_FEATURE #endif // SD_UPDATE_FEATURE
#endif // SD_DEVICE #endif // SD_DEVICE
#ifdef DIRECT_PIN_FEATURE #ifdef DIRECT_PIN_FEATURE
bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP201(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // DIRECT_PIN_FEATURE #endif // DIRECT_PIN_FEATURE
#if defined(DISPLAY_DEVICE) #if defined(DISPLAY_DEVICE)
bool ESP214(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP214(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if defined(DISPLAY_TOUCH_DRIVER) #if defined(DISPLAY_TOUCH_DRIVER)
bool ESP215(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP215(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // DISPLAY_TOUCH_DRIVER #endif // DISPLAY_TOUCH_DRIVER
#endif // DISPLAY_DEVICE #endif // DISPLAY_DEVICE
#ifdef SENSOR_DEVICE #ifdef SENSOR_DEVICE
bool ESP210(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP210(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // SENSOR_DEVICE #endif // SENSOR_DEVICE
bool ESP220(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP220(const char* cmd_params, level_authenticate_type auth_level,
bool ESP290(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP400(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP290(const char* cmd_params, level_authenticate_type auth_level,
bool ESP401(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP400(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
bool ESP401(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if defined(WIFI_FEATURE) #if defined(WIFI_FEATURE)
bool ESP410(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP410(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // WIFI_FEATURE #endif // WIFI_FEATURE
bool ESP420(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP420(const char* cmd_params, level_authenticate_type auth_level,
bool ESP444(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP444(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#ifdef MDNS_FEATURE #ifdef MDNS_FEATURE
bool ESP450(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP450(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // MDNS_FEATURE #endif // MDNS_FEATURE
#if defined(AUTHENTICATION_FEATURE) #if defined(AUTHENTICATION_FEATURE)
bool ESP550(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP550(const char* cmd_params, level_authenticate_type auth_level,
bool ESP555(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP555(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
#if defined(NOTIFICATION_FEATURE) #if defined(NOTIFICATION_FEATURE)
bool ESP600(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP600(const char* cmd_params, level_authenticate_type auth_level,
bool ESP610(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP620(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP610(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
bool ESP620(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // NOTIFICATION_FEATURE #endif // NOTIFICATION_FEATURE
#if defined(GCODE_HOST_FEATURE) #if defined(GCODE_HOST_FEATURE)
bool ESP700(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP700(const char* cmd_params, level_authenticate_type auth_level,
bool ESP701(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP701(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // GCODE_HOST_FEATURE #endif // GCODE_HOST_FEATURE
#if defined(FILESYSTEM_FEATURE) #if defined(FILESYSTEM_FEATURE)
bool ESP710(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP710(const char* cmd_params, level_authenticate_type auth_level,
bool ESP720(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP730(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP720(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
bool ESP730(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // FILESYSTEM_FEATURE #endif // FILESYSTEM_FEATURE
#if defined(SD_DEVICE) #if defined(SD_DEVICE)
bool ESP715(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP715(const char* cmd_params, level_authenticate_type auth_level,
bool ESP750(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP740(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP750(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
bool ESP740(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // SD_DEVICE #endif // SD_DEVICE
#if defined(GLOBAL_FILESYSTEM_FEATURE) #if defined(GLOBAL_FILESYSTEM_FEATURE)
bool ESP780(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP780(const char* cmd_params, level_authenticate_type auth_level,
bool ESP790(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP790(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // GLOBAL_FILESYSTEM_FEATURE #endif // GLOBAL_FILESYSTEM_FEATURE
bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP800(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if COMMUNICATION_PROTOCOL != SOCKET_SERIAL #if COMMUNICATION_PROTOCOL != SOCKET_SERIAL
bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP900(const char* cmd_params, level_authenticate_type auth_level,
bool ESP901(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP901(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL #endif // COMMUNICATION_PROTOCOL != SOCKET_SERIAL
bool ESP920(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP920(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#if defined(ESP_SERIAL_BRIDGE_OUTPUT) #if defined(ESP_SERIAL_BRIDGE_OUTPUT)
bool ESP930(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP930(const char* cmd_params, level_authenticate_type auth_level,
bool ESP931(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP931(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // defined (ESP_SERIAL_BRIDGE_OUTPUT) #endif // defined (ESP_SERIAL_BRIDGE_OUTPUT)
#ifdef BUZZER_DEVICE #ifdef BUZZER_DEVICE
bool ESP910(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP910(const char* cmd_params, level_authenticate_type auth_level,
bool ESP250(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); ESP3DOutput* output);
bool ESP250(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // BUZZER_DEVICE #endif // BUZZER_DEVICE
#if defined(ARDUINO_ARCH_ESP32) && (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3) #if defined(ARDUINO_ARCH_ESP32) && \
bool ESP999(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || \
CONFIG_IDF_TARGET_ESP32C3)
bool ESP999(const char* cmd_params, level_authenticate_type auth_level,
ESP3DOutput* output);
#endif // ARDUINO_ARCH_ESP32 #endif // ARDUINO_ARCH_ESP32
private:
bool _dispatchSetting(bool json, const char* filter, ESP3DSettingIndex index,
const char* help, const char** optionValues,
const char** optionLabels, uint32_t maxsize,
uint32_t minsize, uint32_t minsize2, uint8_t precision,
const char* unit, bool needRestart, ESP3DOutput* output,
bool isFirst = false);
}; };
extern Commands esp3d_commands; extern Commands esp3d_commands;

View File

@ -48,17 +48,17 @@
#if COMMUNICATION_PROTOCOL == RAW_SERIAL || \ #if COMMUNICATION_PROTOCOL == RAW_SERIAL || \
COMMUNICATION_PROTOCOL == MKS_SERIAL || \ COMMUNICATION_PROTOCOL == MKS_SERIAL || \
COMMUNICATION_PROTOCOL == SOCKET_SERIAL COMMUNICATION_PROTOCOL == SOCKET_SERIAL
uint8_t ESP3DOutput::_serialoutputflags = DEFAULT_SERIAL_OUTPUT_FLAG; uint8_t ESP3DOutput::_serialoutputflags = 0;
#endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL == #endif // COMMUNICATION_PROTOCOL == RAW_SERIAL || COMMUNICATION_PROTOCOL ==
// MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL // MKS_SERIAL || COMMUNICATION_PROTOCOL == SOCKET_SERIAL
#if defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY) #if defined(HAS_DISPLAY) || defined(HAS_SERIAL_DISPLAY)
uint8_t ESP3DOutput::_remotescreenoutputflags = DEFAULT_REMOTE_SCREEN_FLAG; uint8_t ESP3DOutput::_remotescreenoutputflags = 0;
#endif // HAS_DISPLAY || HAS_SERIAL_DISPLAY #endif // HAS_DISPLAY || HAS_SERIAL_DISPLAY
#if defined(WS_DATA_FEATURE) #if defined(WS_DATA_FEATURE)
uint8_t ESP3DOutput::_websocketoutputflags = DEFAULT_WEBSOCKET_FLAG; uint8_t ESP3DOutput::_websocketoutputflags = DEFAULT_WEBSOCKET_FLAG;
#endif // WS_DATA_FEATURE #endif // WS_DATA_FEATURE
#if defined(TELNET_FEATURE) #if defined(TELNET_FEATURE)
uint8_t ESP3DOutput::_telnetoutputflags = DEFAULT_TELNET_FLAG; uint8_t ESP3DOutput::_telnetoutputflags = 0;
#endif // TELNET_FEATURE #endif // TELNET_FEATURE
#if defined(DISPLAY_DEVICE) #if defined(DISPLAY_DEVICE)
uint8_t ESP3DOutput::_screenoutputflags = DEFAULT_SCREEN_FLAG; uint8_t ESP3DOutput::_screenoutputflags = DEFAULT_SCREEN_FLAG;

View File

@ -63,7 +63,8 @@ bool Commands::ESP100(const char* cmd_params, level_authenticate_type auth_type,
} }
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
if (!WiFiConfig::isSSIDValid(parameter.c_str())) { if (!Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_STA_SSID)) {
response = format_response(COMMANDID, json, false, "Incorrect SSID"); response = format_response(COMMANDID, json, false, "Incorrect SSID");
noError = false; noError = false;
} else { } else {

View File

@ -57,7 +57,8 @@ bool Commands::ESP101(const char* cmd_params, level_authenticate_type auth_type,
if (clearSetting) { if (clearSetting) {
parameter = ""; parameter = "";
} }
if (!WiFiConfig::isPasswordValid(parameter.c_str())) { if (!Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_STA_PASSWORD)) {
response = response =
format_response(COMMANDID, json, false, "Incorrect password"); format_response(COMMANDID, json, false, "Incorrect password");
noError = false; noError = false;

View File

@ -99,20 +99,25 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type,
String GW = get_param(cmd_params, "GW="); String GW = get_param(cmd_params, "GW=");
String MSK = get_param(cmd_params, "MSK="); String MSK = get_param(cmd_params, "MSK=");
String DNS = get_param(cmd_params, "DNS="); String DNS = get_param(cmd_params, "DNS=");
if (!NetConfig::isValidIP(IP.c_str())) {
if (!Settings_ESP3D::isValidIPStringSetting(IP.c_str(),
ESP_STA_IP_VALUE)) {
response = format_response(COMMANDID, json, false, "Incorrect IP"); response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false; noError = false;
} }
if (!NetConfig::isValidIP(GW.c_str())) { if (!Settings_ESP3D::isValidIPStringSetting(GW.c_str(),
ESP_STA_GATEWAY_VALUE)) {
response = response =
format_response(COMMANDID, json, false, "Incorrect gateway"); format_response(COMMANDID, json, false, "Incorrect gateway");
noError = false; noError = false;
} }
if (!NetConfig::isValidIP(MSK.c_str())) { if (!Settings_ESP3D::isValidIPStringSetting(MSK.c_str(),
ESP_STA_MASK_VALUE)) {
response = format_response(COMMANDID, json, false, "Incorrect mask"); response = format_response(COMMANDID, json, false, "Incorrect mask");
noError = false; noError = false;
} }
if (!NetConfig::isValidIP(DNS.c_str())) { if (!Settings_ESP3D::isValidIPStringSetting(DNS.c_str(),
ESP_STA_DNS_VALUE)) {
response = format_response(COMMANDID, json, false, "Incorrect dns"); response = format_response(COMMANDID, json, false, "Incorrect dns");
noError = false; noError = false;
} }

View File

@ -63,7 +63,8 @@ bool Commands::ESP105(const char* cmd_params, level_authenticate_type auth_type,
} }
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
if (!WiFiConfig::isSSIDValid(parameter.c_str())) { if (!Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_AP_SSID)) {
response = format_response(COMMANDID, json, false, "Incorrect SSID"); response = format_response(COMMANDID, json, false, "Incorrect SSID");
noError = false; noError = false;
} else { } else {

View File

@ -58,7 +58,8 @@ bool Commands::ESP106(const char* cmd_params, level_authenticate_type auth_type,
if (clearSetting) { if (clearSetting) {
parameter = ""; parameter = "";
} }
if (!WiFiConfig::isPasswordValid(parameter.c_str())) { if (!Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_AP_PASSWORD)) {
response = format_response(COMMANDID, json, false, "Set failed"); response = format_response(COMMANDID, json, false, "Set failed");
noError = false; noError = false;
} else { } else {

View File

@ -65,7 +65,8 @@ bool Commands::ESP107(const char* cmd_params, level_authenticate_type auth_type,
} }
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
if (!NetConfig::isValidIP(parameter.c_str())) { if (!Settings_ESP3D::isValidIPStringSetting(parameter.c_str(),
ESP_AP_IP_VALUE)) {
response = format_response(COMMANDID, json, false, "Incorrect IP"); response = format_response(COMMANDID, json, false, "Incorrect IP");
noError = false; noError = false;
} }

View File

@ -65,8 +65,7 @@ bool Commands::ESP108(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
int bbuf = parameter.toInt(); int bbuf = parameter.toInt();
if ((bbuf > Settings_ESP3D::get_max_byte(ESP_AP_CHANNEL)) || if (!Settings_ESP3D::isValidByteSetting(bbuf, ESP_AP_CHANNEL)) {
(bbuf < Settings_ESP3D::get_min_byte(ESP_AP_CHANNEL))) {
response = response =
format_response(COMMANDID, json, false, "Incorrect channel"); format_response(COMMANDID, json, false, "Incorrect channel");
noError = false; noError = false;

View File

@ -63,7 +63,8 @@ bool Commands::ESP112(const char* cmd_params, level_authenticate_type auth_type,
} }
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
if (!NetConfig::isHostnameValid(parameter.c_str())) { if (!Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_HOSTNAME)) {
response = response =
format_response(COMMANDID, json, false, "Incorrect hostname"); format_response(COMMANDID, json, false, "Incorrect hostname");
noError = false; noError = false;

View File

@ -64,8 +64,7 @@ bool Commands::ESP121(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_HTTP_PORT)) || if (!Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_HTTP_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_HTTP_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port"); response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false; noError = false;
} else { } else {

View File

@ -63,8 +63,7 @@ bool Commands::ESP131(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_TELNET_PORT)) || if (!Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_TELNET_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_TELNET_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port"); response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false; noError = false;
} else { } else {

View File

@ -64,8 +64,8 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "srv1="); parameter = get_param(cmd_params, "srv1=");
if (parameter.length() > 0) { if (parameter.length() > 0) {
hasParam = true; hasParam = true;
if (parameter.length() < if (Settings_ESP3D::isValidIPStringSetting(parameter.c_str(),
Settings_ESP3D::get_max_string_size(ESP_TIME_SERVER1)) { ESP_TIME_SERVER1)) {
if (!Settings_ESP3D::write_string(ESP_TIME_SERVER1, if (!Settings_ESP3D::write_string(ESP_TIME_SERVER1,
parameter.c_str())) { parameter.c_str())) {
response = format_response(COMMANDID, json, false, response = format_response(COMMANDID, json, false,
@ -79,8 +79,8 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "srv2="); parameter = get_param(cmd_params, "srv2=");
if (parameter.length() > 0) { if (parameter.length() > 0) {
hasParam = true; hasParam = true;
if (parameter.length() < if (!Settings_ESP3D::isValidIPStringSetting(parameter.c_str(),
Settings_ESP3D::get_max_string_size(ESP_TIME_SERVER2)) { ESP_TIME_SERVER2)) {
if (!Settings_ESP3D::write_string(ESP_TIME_SERVER2, if (!Settings_ESP3D::write_string(ESP_TIME_SERVER2,
parameter.c_str())) { parameter.c_str())) {
response = format_response(COMMANDID, json, false, response = format_response(COMMANDID, json, false,
@ -94,8 +94,8 @@ bool Commands::ESP140(const char* cmd_params, level_authenticate_type auth_type,
parameter = get_param(cmd_params, "srv3="); parameter = get_param(cmd_params, "srv3=");
if (parameter.length() > 0) { if (parameter.length() > 0) {
hasParam = true; hasParam = true;
if (parameter.length() < if (!Settings_ESP3D::isValidIPStringSetting(parameter.c_str(),
Settings_ESP3D::get_max_string_size(ESP_TIME_SERVER3)) { ESP_TIME_SERVER3)) {
if (!Settings_ESP3D::write_string(ESP_TIME_SERVER3, if (!Settings_ESP3D::write_string(ESP_TIME_SERVER3,
parameter.c_str())) { parameter.c_str())) {
response = format_response(COMMANDID, json, false, response = format_response(COMMANDID, json, false,

View File

@ -81,8 +81,7 @@ bool Commands::ESP150(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() != 0) { if (parameter.length() != 0) {
hasParameter = true; hasParameter = true;
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) || if (!Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_BOOT_DELAY)) {
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY))) {
response = response =
format_response(COMMANDID, json, false, "Incorrect delay"); format_response(COMMANDID, json, false, "Incorrect delay");
noError = false; noError = false;

View File

@ -63,8 +63,7 @@ bool Commands::ESP161(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBSOCKET_PORT)) || if !(Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_WEBSOCKET_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBSOCKET_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port"); response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false; noError = false;
} else { } else {

View File

@ -90,8 +90,7 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() > 0) { if (parameter.length() > 0) {
hasParam = true; hasParam = true;
ibuf = parameter.toInt(); ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_FTP_CTRL_PORT)) || if (!Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_FTP_CTRL_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_FTP_CTRL_PORT))) {
response = response =
format_response(COMMANDID, json, false, "Incorrect ctrl port"); format_response(COMMANDID, json, false, "Incorrect ctrl port");
noError = false; noError = false;
@ -107,10 +106,8 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() > 0) { if (parameter.length() > 0) {
ibuf = parameter.toInt(); ibuf = parameter.toInt();
hasParam = true; hasParam = true;
if ((ibuf > Settings_ESP3D::get_max_int32_value( if (!Settings_ESP3D::isValidIntegerSetting(ibuf,
ESP_FTP_DATA_ACTIVE_PORT)) || ESP_FTP_DATA_ACTIVE_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(
ESP_FTP_DATA_ACTIVE_PORT))) {
response = format_response(COMMANDID, json, false, response = format_response(COMMANDID, json, false,
"Incorrect active port"); "Incorrect active port");
noError = false; noError = false;
@ -129,10 +126,8 @@ bool Commands::ESP181(const char* cmd_params, level_authenticate_type auth_type,
if (parameter.length() > 0) { if (parameter.length() > 0) {
hasParam = true; hasParam = true;
ibuf = parameter.toInt(); ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value( if (!Settings_ESP3D::isValidIntegerSetting(
ESP_FTP_DATA_PASSIVE_PORT)) || ibuf, ESP_FTP_DATA_PASSIVE_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(
ESP_FTP_DATA_PASSIVE_PORT))) {
response = format_response(COMMANDID, json, false, response = format_response(COMMANDID, json, false,
"Incorrect passive port"); "Incorrect passive port");
noError = false; noError = false;

View File

@ -63,8 +63,7 @@ bool Commands::ESP191(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBDAV_PORT)) || if (!Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_WEBDAV_PORT)) {
(ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBDAV_PORT))) {
response = format_response(COMMANDID, json, false, "Incorrect port"); response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false; noError = false;
} else { } else {

View File

@ -55,9 +55,8 @@ bool Commands::ESP202(const char* cmd_params, level_authenticate_type auth_type,
String(Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV)).c_str()); String(Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV)).c_str());
} else { // set } else { // set
parameter = get_param(cmd_params, "SPEED="); parameter = get_param(cmd_params, "SPEED=");
if ((parameter == "1") || (parameter == "2") || (parameter == "4") || if (Settings_ESP3D::isValidByteSetting(parameter.toInt(),
(parameter == "6") || (parameter == "8") || (parameter == "16") || ESP_SD_SPEED_DIV)) {
(parameter == "32")) {
if (!Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV, parameter.toInt())) { if (!Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV, parameter.toInt())) {
response = format_response(COMMANDID, json, false, "Set failed"); response = format_response(COMMANDID, json, false, "Set failed");
noError = false; noError = false;

File diff suppressed because it is too large Load Diff

View File

@ -86,9 +86,12 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
if (response) { if (response) {
// Byte value // Byte value
if (styp == "B") { if (styp == "B") {
if (Settings_ESP3D::isValidByteSetting((uint8_t)sval.toInt(),
spos.toInt())) {
if (!Settings_ESP3D::write_byte(spos.toInt(), if (!Settings_ESP3D::write_byte(spos.toInt(),
(uint8_t)sval.toInt())) { (uint8_t)sval.toInt())) {
response = false; response = false;
log_esp3d_e("Set failed");
} else { } else {
// dynamique refresh is better than restart the boards // dynamique refresh is better than restart the boards
switch (spos.toInt()) { switch (spos.toInt()) {
@ -160,12 +163,18 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
break; break;
} }
} }
} else {
response = "Invalid value for V";
noError = false;
}
} }
// Integer value // Integer value
if (styp == "I") { if (styp == "I") {
if (Settings_ESP3D::isValidByteSetting(sval.toInt(), spos.toInt())) {
if (!Settings_ESP3D::write_uint32(spos.toInt(), sval.toInt())) { if (!Settings_ESP3D::write_uint32(spos.toInt(), sval.toInt())) {
response = "Set failed"; response = "Set failed";
noError = false; noError = false;
log_esp3d_e("Set failed");
} else { } else {
// dynamique refresh is better than restart the board // dynamique refresh is better than restart the board
switch (spos.toInt()) { switch (spos.toInt()) {
@ -189,12 +198,19 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
break; break;
} }
} }
} else {
response = "Invalid value for V";
noError = false;
}
} }
// String value // String value
if (styp == "S") { if (styp == "S") {
if (Settings_ESP3D::isValidStringSetting(sval.c_str(),
spos.toInt())) {
if (!Settings_ESP3D::write_string(spos.toInt(), sval.c_str())) { if (!Settings_ESP3D::write_string(spos.toInt(), sval.c_str())) {
response = "Set failed"; response = "Set failed";
noError = false; noError = false;
log_esp3d_e("Set failed");
} else { } else {
// dynamique refresh is better than restart the board // dynamique refresh is better than restart the board
switch (spos.toInt()) { switch (spos.toInt()) {
@ -208,10 +224,16 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
break; break;
} }
} }
} else {
response = "Invalid value for V";
noError = false;
}
} }
#if defined(WIFI_FEATURE) #if defined(WIFI_FEATURE)
// IP address // IP address
if (styp == "A") { if (styp == "A") {
if (Settings_ESP3D::isValidIPStringSetting(sval.c_str(),
spos.toInt())) {
if (!Settings_ESP3D::write_IP_String(spos.toInt(), sval.c_str())) { if (!Settings_ESP3D::write_IP_String(spos.toInt(), sval.c_str())) {
response = "Set failed"; response = "Set failed";
noError = false; noError = false;
@ -219,6 +241,10 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
// dynamique refresh is better than restart the board // dynamique refresh is better than restart the board
// TBD // TBD
} }
} else {
response = "Invalid value for V";
noError = false;
}
} }
#endif // WIFI_FEATURE #endif // WIFI_FEATURE
} }

View File

@ -38,7 +38,8 @@ bool Commands::ESP550(const char* cmd_params, level_authenticate_type auth_type,
if (auth_type == LEVEL_ADMIN) { if (auth_type == LEVEL_ADMIN) {
parameter = clean_param(get_param(cmd_params, "")); parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) { if (parameter.length() != 0) {
if (Settings_ESP3D::isLocalPasswordValid(parameter.c_str())) { if (Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_ADMIN_PWD)) {
if (!Settings_ESP3D::write_string(ESP_ADMIN_PWD, parameter.c_str())) { if (!Settings_ESP3D::write_string(ESP_ADMIN_PWD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed"); response = format_response(COMMANDID, json, false, "Set failed");
noError = false; noError = false;

View File

@ -38,7 +38,8 @@ bool Commands::ESP555(const char* cmd_params, level_authenticate_type auth_type,
if (auth_type != LEVEL_GUEST) { if (auth_type != LEVEL_GUEST) {
parameter = clean_param(get_param(cmd_params, "")); parameter = clean_param(get_param(cmd_params, ""));
if (parameter.length() != 0) { if (parameter.length() != 0) {
if (Settings_ESP3D::isLocalPasswordValid(parameter.c_str())) { if (Settings_ESP3D::isValidStringSetting(parameter.c_str(),
ESP_USER_PWD)) {
if (!Settings_ESP3D::write_string(ESP_USER_PWD, parameter.c_str())) { if (!Settings_ESP3D::write_string(ESP_USER_PWD, parameter.c_str())) {
response = format_response(COMMANDID, json, false, "Set failed"); response = format_response(COMMANDID, json, false, "Set failed");
noError = false; noError = false;

View File

@ -114,9 +114,9 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
String time = ""; String time = "";
line = ""; line = "";
countf++; countf++;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE #ifdef SD_TIMESTAMP_FEATURE
time = timeService.getDateTime((time_t)sub.getLastWrite()); time = timeService.getDateTime((time_t)sub.getLastWrite());
#endif // FILESYSTEM_TIMESTAMP_FEATURE #endif // SD_TIMESTAMP_FEATURE
if (json) { if (json) {
if (countd > 0 || countf > 1) { if (countd > 0 || countf > 1) {
line += ","; line += ",";

View File

@ -64,7 +64,7 @@ bool Commands::ESP901(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if (serial_service.is_valid_baudrate(ibuf)) { if (Settings_ESP3D::isValidIntegerSetting(ibuf, ESP_BAUD_RATE)) {
response = format_response(COMMANDID, json, false, "Incorrect port"); response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false; noError = false;
} else { } else {

View File

@ -64,10 +64,11 @@ bool Commands::ESP931(const char* cmd_params, level_authenticate_type auth_type,
#endif // AUTHENTICATION_FEATURE #endif // AUTHENTICATION_FEATURE
if (noError) { if (noError) {
uint ibuf = parameter.toInt(); uint ibuf = parameter.toInt();
if (serial_bridge_service.is_valid_baudrate(ibuf)) { if (Settings_ESP3D.isValidIntegerSetting(ibuf, ESP_SERIAL_BRIDGE_BAUD)) {
response = format_response(COMMANDID, json, false, "Incorrect port"); response = format_response(COMMANDID, json, false, "Incorrect port");
noError = false; noError = false;
} else { }
else {
if (!Settings_ESP3D::write_uint32(ESP_SERIAL_BRIDGE_BAUD, ibuf)) { if (!Settings_ESP3D::write_uint32(ESP_SERIAL_BRIDGE_BAUD, ibuf)) {
response = format_response(COMMANDID, json, false, "Set failed"); response = format_response(COMMANDID, json, false, "Set failed");
noError = false; noError = false;

File diff suppressed because it is too large Load Diff

View File

@ -19,27 +19,47 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef _SETTINGS_ESP3D_H #ifndef _SETTINGS_ESP3D_H
#define _SETTINGS_ESP3D_H #define _SETTINGS_ESP3D_H
#include <Arduino.h> #include <Arduino.h>
class Settings_ESP3D #include "../include/esp3d_config.h"
{
enum class ESP3DState : uint8_t {
off = 0,
on = 1,
};
enum class ESP3DSettingType : uint8_t {
byte_t, // byte
integer_t, // 4 bytes
string_t, // string
ip_t, // 4 bytes
float_t, // 4 bytes
mask, // x bytes
bitsfield, // x bytes
unknown_t
};
struct ESP3DSettingDescription {
ESP3DSettingIndex index;
ESP3DSettingType type;
uint16_t size;
const char *default_val;
};
#ifdef SD_DEVICE
extern const uint8_t SupportedSPIDivider[];
extern const uint8_t SupportedSPIDividerSize;
#endif // SD_DEVICE
#if defined(WIFI_FEATURE)
extern const uint8_t SupportedApChannels[];
extern const uint8_t SupportedApChannelsSize;
#endif // WIFI_FEATURE
class Settings_ESP3D {
public: public:
static bool begin(); static bool begin();
static uint8_t get_default_byte_value(int pos);
static uint32_t get_default_int32_value(int pos);
static uint32_t get_default_IP_value(int pos);
static const String & get_default_string_value(int pos);
static uint8_t get_max_string_size(int pos);
static uint8_t get_min_string_size(int pos);
static uint32_t get_max_int32_value(int pos);
static uint32_t get_min_int32_value(int pos);
static uint8_t get_max_byte(int pos);
static int8_t get_min_byte(int pos);
static uint8_t read_byte(int pos, bool *haserror = NULL); static uint8_t read_byte(int pos, bool *haserror = NULL);
static uint32_t read_uint32(int pos, bool *haserror = NULL); static uint32_t read_uint32(int pos, bool *haserror = NULL);
static uint32_t read_IP(int pos, bool *haserror = NULL); static uint32_t read_IP(int pos, bool *haserror = NULL);
@ -56,16 +76,29 @@ public:
static bool isVerboseBoot(bool fromsettings = false); static bool isVerboseBoot(bool fromsettings = false);
static uint8_t GetSDDevice(); static uint8_t GetSDDevice();
static const char *GetFirmwareTargetShortName(); static const char *GetFirmwareTargetShortName();
static String IPtoString(uint32_t ip_int);
static uint32_t StringtoIP(const char *s);
static const char *TargetBoard(); static const char *TargetBoard();
static bool isLocalPasswordValid (const char * password);
static bool isValidIPStringSetting(const char *value,
ESP3DSettingIndex settingElement);
static bool isValidStringSetting(const char *value,
ESP3DSettingIndex settingElement);
static bool isValidIntegerSetting(uint32_t value,
ESP3DSettingIndex settingElement);
static bool isValidByteSetting(uint8_t value,
ESP3DSettingIndex settingElement);
static uint32_t getDefaultIntegerSetting(ESP3DSettingIndex settingElement);
static const char *getDefaultStringSetting(ESP3DSettingIndex settingElement);
static uint8_t getDefaultByteSetting(ESP3DSettingIndex settingElement);
static const ESP3DSettingDescription *getSettingPtr(
const ESP3DSettingIndex index);
private: private:
static String _IpToString(uint32_t ip_int);
static uint32_t _stringToIP(const char *s);
static bool is_string(const char *s, uint len); static bool is_string(const char *s, uint len);
static uint8_t _FirmwareTarget; static uint8_t _FirmwareTarget;
static bool _isverboseboot; static bool _isverboseboot;
}; };
#endif //_SETTINGS_ESP3D_H #endif //_SETTINGS_ESP3D_H

View File

@ -36,14 +36,7 @@
#define GRBLHAL 80 #define GRBLHAL 80
#define HP_GL 90 #define HP_GL 90
// Default flags typedef uint ESP3DSettingIndex;
#define DEFAULT_SERIAL_OUTPUT_FLAG 1
#define DEFAULT_REMOTE_SCREEN_FLAG 1
#define DEFAULT_WEBSOCKET_FLAG 1
#define DEFAULT_TELNET_FLAG 1
#define DEFAULT_BT_FLAG 1
#define DEFAULT_SCREEN_FLAG 1
#define DEFAULT_SERIAL_BRIDGE_FLAG 1
// position in EEPROM / preferences will use `P_` + <position> to make a string // position in EEPROM / preferences will use `P_` + <position> to make a string
// : P_0 for 0 // : P_0 for 0

View File

@ -18,36 +18,30 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "../../include/esp3d_config.h"
#include "boot_delay.h" #include "boot_delay.h"
#include "../../core/settings_esp3d.h"
#include "../../core/esp3doutput.h" #include "../../core/esp3doutput.h"
#include "../../core/settings_esp3d.h"
#include "../../include/esp3d_config.h"
#if defined(RECOVERY_FEATURE) #if defined(RECOVERY_FEATURE)
#include "../recovery/recovery_service.h" #include "../recovery/recovery_service.h"
#endif // RECOVERY_FEATURE #endif // RECOVERY_FEATURE
BootDelay::BootDelay() BootDelay::BootDelay() {
{
_started = false; _started = false;
_startdelay = 0; _startdelay = 0;
_totalduration = 0; _totalduration = 0;
} }
BootDelay::~BootDelay() BootDelay::~BootDelay() { end(); }
{
end();
}
bool BootDelay::started() bool BootDelay::started() { return _started; }
{
return _started;
}
bool BootDelay::begin() bool BootDelay::begin() {
{
_totalduration = Settings_ESP3D::read_uint32(ESP_BOOT_DELAY); _totalduration = Settings_ESP3D::read_uint32(ESP_BOOT_DELAY);
log_esp3d("Boot delay %d", _totalduration); log_esp3d("Boot delay %d", _totalduration);
if (_totalduration > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) { if (!Settings_ESP3D::isValidIntegerSetting(_totalduration, ESP_BOOT_DELAY)) {
_totalduration = Settings_ESP3D::get_default_int32_value(ESP_BOOT_DELAY); _totalduration = Settings_ESP3D::getDefaultIntegerSetting(ESP_BOOT_DELAY);
log_esp3d("Boot delay modified %d", _totalduration); log_esp3d("Boot delay modified %d", _totalduration);
} }
_started = true; _started = true;
@ -60,12 +54,9 @@ bool BootDelay::begin()
log_esp3d("Boot delay done"); log_esp3d("Boot delay done");
return _started; return _started;
} }
void BootDelay::end() void BootDelay::end() {}
{
}
void BootDelay::handle() void BootDelay::handle() {
{
uint8_t lastpercent = 0; uint8_t lastpercent = 0;
uint32_t lastSent = millis(); uint32_t lastSent = millis();
while ((millis() - _startdelay) < _totalduration) { while ((millis() - _startdelay) < _totalduration) {

View File

@ -18,15 +18,14 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef _BOOT_DELAY_H #ifndef _BOOT_DELAY_H
#define _BOOT_DELAY_H #define _BOOT_DELAY_H
#include <cstdint>
typedef void(progress_t)(uint8_t percent); typedef void(progress_t)(uint8_t percent);
class BootDelay class BootDelay {
{
public: public:
BootDelay(); BootDelay();
~BootDelay(); ~BootDelay();
@ -34,6 +33,7 @@ public:
void end(); void end();
void handle(); void handle();
bool started(); bool started();
private: private:
bool _started; bool _started;
uint32_t _startdelay; uint32_t _startdelay;
@ -41,4 +41,3 @@ private:
}; };
#endif //_BOOT_DELAY_H #endif //_BOOT_DELAY_H

View File

@ -30,7 +30,6 @@
#include "../../../core/settings_esp3d.h" #include "../../../core/settings_esp3d.h"
#include "../../authentication/authentication_service.h" #include "../../authentication/authentication_service.h"
// login status check // login status check
void HTTP_Server::handle_login() { void HTTP_Server::handle_login() {
HTTP_Server::set_http_headers(); HTTP_Server::set_http_headers();
@ -67,7 +66,8 @@ void HTTP_Server::handle_login() {
if (_webserver->hasArg("NEWPASSWORD")) { if (_webserver->hasArg("NEWPASSWORD")) {
String newpassword = _webserver->arg("NEWPASSWORD"); String newpassword = _webserver->arg("NEWPASSWORD");
// check new password // check new password
if (Settings_ESP3D::isLocalPasswordValid(newpassword.c_str())) { if (Settings_ESP3D::isValidStringSetting(newpassword.c_str(),
ESP_ADMIN_PWD)) {
if (!Settings_ESP3D::write_string(ESP_ADMIN_PWD, if (!Settings_ESP3D::write_string(ESP_ADMIN_PWD,
newpassword.c_str())) { newpassword.c_str())) {
code = 500; code = 500;

View File

@ -80,30 +80,6 @@ String NetConfig::IP_string_from_int(uint32_t ip_int) {
return ipaddr.toString(); return ipaddr.toString();
} }
/**
* Check if Hostname string is valid
*/
bool NetConfig::isHostnameValid(const char* hostname) {
// limited size
char c;
if (strlen(hostname) > MAX_HOSTNAME_LENGTH ||
strlen(hostname) < MIN_HOSTNAME_LENGTH) {
return false;
}
// only letter and digit
for (uint i = 0; i < strlen(hostname); i++) {
c = hostname[i];
if (!(isdigit(c) || isalpha(c) || c == '-')) {
return false;
}
if (c == ' ') {
return false;
}
}
return true;
}
/** /**
* Get IP Integer what ever is enabled * Get IP Integer what ever is enabled
*/ */
@ -148,15 +124,6 @@ String NetConfig::localIP() {
return currentIP; return currentIP;
} }
/**
* Check if IP string is valid
*/
bool NetConfig::isValidIP(const char* string) {
IPAddress ip;
return ip.fromString(string);
}
// wifi event // wifi event
void NetConfig::onWiFiEvent(WiFiEvent_t event) { void NetConfig::onWiFiEvent(WiFiEvent_t event) {
ESP3DOutput output(ESP_ALL_CLIENTS); ESP3DOutput output(ESP_ALL_CLIENTS);

View File

@ -20,7 +20,6 @@
// boundaries // boundaries
#define MAX_WEBDAV_PORT 65001 #define MAX_WEBDAV_PORT 65001
#define MIN_WEBDAV_PORT 1 #define MIN_WEBDAV_PORT 1
#define MAX_HTTP_PORT 65001 #define MAX_HTTP_PORT 65001
@ -34,8 +33,6 @@
#define MAX_HOSTNAME_LENGTH 32 #define MAX_HOSTNAME_LENGTH 32
#define MIN_HOSTNAME_LENGTH 1 #define MIN_HOSTNAME_LENGTH 1
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h> #include <WiFi.h>
#endif // ARDUINO_ARCH_ESP32 #endif // ARDUINO_ARCH_ESP32
@ -46,11 +43,8 @@
#ifndef _NET_CONFIG_H #ifndef _NET_CONFIG_H
#define _NET_CONFIG_H #define _NET_CONFIG_H
class NetConfig class NetConfig {
{
public: public:
static bool isValidIP(const char * string);
static bool isHostnameValid (const char * hostname);
static uint32_t IP_int_from_string(const char* s); static uint32_t IP_int_from_string(const char* s);
static String IP_string_from_int(uint32_t ip_int); static String IP_string_from_int(uint32_t ip_int);
static bool isIPModeDHCP(uint8_t mode); static bool isIPModeDHCP(uint8_t mode);
@ -62,12 +56,10 @@ public:
static void handle(); static void handle();
static uint8_t getMode(); static uint8_t getMode();
static void setMode(uint8_t mode); static void setMode(uint8_t mode);
static bool started() static bool started() { return _started; }
{
return _started;
}
static String localIP(); static String localIP();
static IPAddress localIPAddress(); static IPAddress localIPAddress();
private: private:
static String _hostname; static String _hostname;
static void onWiFiEvent(WiFiEvent_t event); static void onWiFiEvent(WiFiEvent_t event);

View File

@ -66,6 +66,7 @@ TaskHandle_t _hserialtask = nullptr;
const long SupportedBaudList[] = {9600, 19200, 38400, 57600, const long SupportedBaudList[] = {9600, 19200, 38400, 57600,
74880, 115200, 230400, 250000, 74880, 115200, 230400, 250000,
500000, 921600, 1958400}; 500000, 921600, 1958400};
const size_t SupportedBaudListSize = sizeof(SupportedBaudList) / sizeof(long);
#define TIMEOUT_SERIAL_FLUSH 1500 #define TIMEOUT_SERIAL_FLUSH 1500
// Constructor // Constructor
@ -140,13 +141,13 @@ bool SerialService::begin(uint8_t serialIndex) {
switch (_id) { switch (_id) {
case MAIN_SERIAL: case MAIN_SERIAL:
br = Settings_ESP3D::read_uint32(ESP_BAUD_RATE); br = Settings_ESP3D::read_uint32(ESP_BAUD_RATE);
defaultBr = Settings_ESP3D::get_default_int32_value(ESP_BAUD_RATE); defaultBr = Settings_ESP3D::getDefaultIntegerSetting(ESP_BAUD_RATE);
break; break;
#if defined(ESP_SERIAL_BRIDGE_OUTPUT) #if defined(ESP_SERIAL_BRIDGE_OUTPUT)
case BRIDGE_SERIAL: case BRIDGE_SERIAL:
br = Settings_ESP3D::read_uint32(ESP_SERIAL_BRIDGE_BAUD); br = Settings_ESP3D::read_uint32(ESP_SERIAL_BRIDGE_BAUD);
defaultBr = defaultBr =
Settings_ESP3D::get_default_int32_value(ESP_SERIAL_BRIDGE_BAUD); Settings_ESP3D::getDefaultIntegerSetting(ESP_SERIAL_BRIDGE_BAUD);
break; break;
#endif // ESP_SERIAL_BRIDGE_OUTPUT #endif // ESP_SERIAL_BRIDGE_OUTPUT
default: default:
@ -159,7 +160,7 @@ bool SerialService::begin(uint8_t serialIndex) {
_buffer_size = 0; _buffer_size = 0;
// change only if different from current // change only if different from current
if (br != baudRate() || (_rxPin != -1) || (_txPin != -1)) { if (br != baudRate() || (_rxPin != -1) || (_txPin != -1)) {
if (!is_valid_baudrate(br)) { if (!Settings_ESP3D::isValidIntegerSetting(br, ESP_BAUD_RATE)) {
br = defaultBr; br = defaultBr;
} }
Serials[_serialIndex]->setRxBufferSize(SERIAL_RX_BUFFER_SIZE); Serials[_serialIndex]->setRxBufferSize(SERIAL_RX_BUFFER_SIZE);
@ -217,17 +218,6 @@ const long *SerialService::get_baudratelist(uint8_t *count) {
return SupportedBaudList; return SupportedBaudList;
} }
// check if value is in baudrate list
bool SerialService::is_valid_baudrate(long br) {
uint8_t listesize = sizeof(SupportedBaudList) / sizeof(long);
for (uint8_t i = 0; i < listesize; i++) {
if (SupportedBaudList[i] == br) {
return true;
}
}
return false;
}
// Function which could be called in other loop // Function which could be called in other loop
void SerialService::process() { void SerialService::process() {
if (!_started) { if (!_started) {
@ -421,15 +411,15 @@ bool SerialService::reset() {
case MAIN_SERIAL: case MAIN_SERIAL:
return Settings_ESP3D::write_uint32( return Settings_ESP3D::write_uint32(
ESP_BAUD_RATE, ESP_BAUD_RATE,
Settings_ESP3D::get_default_int32_value(ESP_BAUD_RATE)); Settings_ESP3D::getDefaultIntegerSetting(ESP_BAUD_RATE));
#if defined(ESP_SERIAL_BRIDGE_OUTPUT) #if defined(ESP_SERIAL_BRIDGE_OUTPUT)
case BRIDGE_SERIAL: case BRIDGE_SERIAL:
res = Settings_ESP3D::write_byte( res = Settings_ESP3D::write_byte(
ESP_SERIAL_BRIDGE_ON, ESP_SERIAL_BRIDGE_ON,
Settings_ESP3D::get_default_byte_value(ESP_SERIAL_BRIDGE_ON)); Settings_ESP3D::getDefaultByteSetting(ESP_SERIAL_BRIDGE_ON));
return res && Settings_ESP3D::write_uint32( return res && Settings_ESP3D::write_uint32(
ESP_SERIAL_BRIDGE_BAUD, ESP_SERIAL_BRIDGE_BAUD,
Settings_ESP3D::get_default_int32_value( Settings_ESP3D::getDefaultIntegerSetting(
ESP_SERIAL_BRIDGE_BAUD)); ESP_SERIAL_BRIDGE_BAUD));
#endif // ESP_SERIAL_BRIDGE_OUTPUT #endif // ESP_SERIAL_BRIDGE_OUTPUT
default: default:

View File

@ -25,6 +25,9 @@
#define ESP3D_SERIAL_BUFFER_SIZE 1024 #define ESP3D_SERIAL_BUFFER_SIZE 1024
extern const long SupportedBaudList[];
extern const size_t SupportedBaudListSize;
class SerialService : public Print { class SerialService : public Print {
public: public:
SerialService(uint8_t id); SerialService(uint8_t id);
@ -43,7 +46,6 @@ class SerialService : public Print {
void swap(); void swap();
int availableForWrite(); int availableForWrite();
int available(); int available();
bool is_valid_baudrate(long br);
size_t write(uint8_t c); size_t write(uint8_t c);
size_t write(const uint8_t *buffer, size_t size); size_t write(const uint8_t *buffer, size_t size);
inline size_t write(const char *s) { return write((uint8_t *)s, strlen(s)); } inline size_t write(const char *s) { return write((uint8_t *)s, strlen(s)); }

View File

@ -22,6 +22,7 @@
#define _TIME_SERVICE_H #define _TIME_SERVICE_H
#include <time.h> #include <time.h>
#include <Arduino.h>
class TimeService { class TimeService {
public: public:

View File

@ -104,7 +104,7 @@ void WebdavServer::handler_get(const char* url) {
} }
} else { } else {
code = 400; code = 400;
log_esp3d_e("Root cannot be deleted"); log_esp3d_e("Root cannot be used as it is");
} }
if (code != 200) { if (code != 200) {
log_esp3d_e("Sending response code %d", code); log_esp3d_e("Sending response code %d", code);

View File

@ -30,27 +30,8 @@
#include "../network/netconfig.h" #include "../network/netconfig.h"
#include "../wifi/wificonfig.h" #include "../wifi/wificonfig.h"
const uint8_t DEFAULT_AP_MASK_VALUE[] = {255, 255, 255, 0}; const uint8_t DEFAULT_AP_MASK_VALUE[] = {255, 255, 255, 0};
/**
* Check if SSID string is valid
*/
bool WiFiConfig::isSSIDValid(const char* ssid) {
// limited size
// char c;
if (strlen(ssid) > MAX_SSID_LENGTH || strlen(ssid) < MIN_SSID_LENGTH) {
return false;
}
// only printable
for (uint i = 0; i < strlen(ssid); i++) {
if (!isPrintable(ssid[i])) {
return false;
}
}
return true;
}
const char* WiFiConfig::hostname() { const char* WiFiConfig::hostname() {
static String tmp; static String tmp;
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
@ -73,22 +54,6 @@ const char* WiFiConfig::hostname() {
return tmp.c_str(); return tmp.c_str();
} }
/**
* Check if password string is valid
*/
bool WiFiConfig::isPasswordValid(const char* password) {
if (strlen(password) == 0) {
return true; // open network
}
// limited size
if ((strlen(password) > MAX_PASSWORD_LENGTH) ||
(strlen(password) < MIN_PASSWORD_LENGTH)) {
return false;
}
return true;
}
/* /*
* Get WiFi signal strength * Get WiFi signal strength
*/ */

View File

@ -35,7 +35,8 @@
#define WIFI_MODEM_SLEEP WIFI_PS_MAX_MODEM #define WIFI_MODEM_SLEEP WIFI_PS_MAX_MODEM
#define WIFI_PHY_MODE_11B WIFI_PROTOCOL_11B #define WIFI_PHY_MODE_11B WIFI_PROTOCOL_11B
#define WIFI_PHY_MODE_11G WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G #define WIFI_PHY_MODE_11G WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G
#define WIFI_PHY_MODE_11N WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N #define WIFI_PHY_MODE_11N \
WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N
#define AUTH_OPEN WIFI_AUTH_OPEN #define AUTH_OPEN WIFI_AUTH_OPEN
#define AUTH_WEP WIFI_AUTH_WEP #define AUTH_WEP WIFI_AUTH_WEP
#define AUTH_WPA_PSK WIFI_AUTH_WPA_PSK #define AUTH_WPA_PSK WIFI_AUTH_WPA_PSK
@ -51,11 +52,8 @@
#ifndef _WIFI_CONFIG_H #ifndef _WIFI_CONFIG_H
#define _WIFI_CONFIG_H #define _WIFI_CONFIG_H
class WiFiConfig class WiFiConfig {
{
public: public:
static bool isPasswordValid (const char * password);
static bool isSSIDValid (const char * ssid);
static bool StartAP(bool setupMode = false); static bool StartAP(bool setupMode = false);
static bool StartSTA(); static bool StartSTA();
static void StopWiFi(); static void StopWiFi();
@ -68,11 +66,13 @@ public:
static const char* AP_Auth_String(); static const char* AP_Auth_String();
static const char* AP_Gateway_String(); static const char* AP_Gateway_String();
static const char* AP_Mask_String(); static const char* AP_Mask_String();
static const char* getConnectedSTA(uint8_t * totalcount = NULL, bool reset = false); static const char* getConnectedSTA(uint8_t* totalcount = NULL,
bool reset = false);
static bool started(); static bool started();
static bool begin(int8_t& espMode); static bool begin(int8_t& espMode);
static void end(); static void end();
static void handle(); static void handle();
private: private:
static bool ConnectSTA2AP(); static bool ConnectSTA2AP();
}; };