mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 09:29:02 +08:00
Rewrite ESP commands
add password protection if authentication is set
This commit is contained in:
parent
a7c4c44bfc
commit
a7aedc5599
79
README.md
79
README.md
@ -103,19 +103,72 @@ Additionally 404.tpl (the page not found) and restart.tpl(restart page when appl
|
|||||||
|
|
||||||
##Direct commands:
|
##Direct commands:
|
||||||
```
|
```
|
||||||
-Restart module from host/printer: [ESP888]RESTART
|
* Change STA SSID
|
||||||
-Send file line by line from SPIFFS: [ESP700]<file name>
|
[ESP100]<SSID>
|
||||||
-Get IP (only printer see answer): [ESP111]M117
|
if authentication is on, need admin password
|
||||||
-Reset EEPROM and restart: [ESP444]RESET
|
[ESP100]<SSID>pwd=<admin password>
|
||||||
-Reset user password: [ESP555]<admin password>
|
|
||||||
-Display EEPROM content: [ESP444]CONFIG
|
* Change STA Password
|
||||||
-Go to safe mode without restart: [ESP444]SAFEMODE
|
[ESP101]<Password>
|
||||||
-SSID: [ESP100]<SSID>
|
if authentication is on, need admin password
|
||||||
-Password: [ESP101]<Password>
|
[ESP101]<Password>pwd=<admin password>
|
||||||
-Station mode: [ESP103]STA
|
|
||||||
-AP mode: [ESP103]AP
|
* Change Hostname
|
||||||
-IP Static: [ESP104]STATIC
|
[ESP102]<hostname>
|
||||||
-IP DHCP: [ESP104]DHCP
|
if authentication is on, need admin password
|
||||||
|
[ESP102]<hostname>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change Wifi mode (STA/AP)
|
||||||
|
[ESP103]<mode>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP103]<mode>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change STA IP mode (DHCP/STATIC)
|
||||||
|
[ESP104]<mode>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP104]<mode>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change AP SSID
|
||||||
|
[ESP105]<SSID>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP105]<SSID>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change AP Password
|
||||||
|
[ESP106]<Password>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP106]<Password>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change AP IP mode (DHCP/STATIC)
|
||||||
|
[ESP107]<mode>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP107]<mode>pwd=<admin password>
|
||||||
|
|
||||||
|
* Get current IP
|
||||||
|
[ESP111]<header answer>
|
||||||
|
|
||||||
|
* Get hostname
|
||||||
|
[ESP112]<header answer>
|
||||||
|
|
||||||
|
* Get/Set ESP mode
|
||||||
|
cmd can be RESET, SAFEMODE, CONFIG, RESTART
|
||||||
|
[ESP444]<cmd>
|
||||||
|
if authentication is on, need admin password for RESET, RESTART and SAFEMODE
|
||||||
|
[ESP444]<cmd>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change / Reset user password
|
||||||
|
[ESP555]<password>pwd=<admin password>
|
||||||
|
if no password set it use default one
|
||||||
|
|
||||||
|
* Read SPIFFS file and send each line to serial
|
||||||
|
[ESP700]<filename>
|
||||||
|
|
||||||
|
* Get fw version
|
||||||
|
[ESP800]<header answer>
|
||||||
|
|
||||||
|
* Clear status/error/info list
|
||||||
|
cmd can be ALL, ERROR, INFO, STATUS
|
||||||
|
[ESP999]<cmd>
|
||||||
|
|
||||||
```
|
```
|
||||||
##Installation
|
##Installation
|
||||||
* For stable:
|
* For stable:
|
||||||
|
66
docs/Commands.txt
Normal file
66
docs/Commands.txt
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
* Change STA SSID
|
||||||
|
[ESP100]<SSID>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP100]<SSID>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change STA Password
|
||||||
|
[ESP101]<Password>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP101]<Password>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change Hostname
|
||||||
|
[ESP102]<hostname>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP102]<hostname>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change Wifi mode (STA/AP)
|
||||||
|
[ESP103]<mode>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP103]<mode>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change STA IP mode (DHCP/STATIC)
|
||||||
|
[ESP104]<mode>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP104]<mode>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change AP SSID
|
||||||
|
[ESP105]<SSID>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP105]<SSID>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change AP Password
|
||||||
|
[ESP106]<Password>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP106]<Password>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change AP IP mode (DHCP/STATIC)
|
||||||
|
[ESP107]<mode>
|
||||||
|
if authentication is on, need admin password
|
||||||
|
[ESP107]<mode>pwd=<admin password>
|
||||||
|
|
||||||
|
* Get current IP
|
||||||
|
[ESP111]<header answer>
|
||||||
|
|
||||||
|
* Get hostname
|
||||||
|
[ESP112]<header answer>
|
||||||
|
|
||||||
|
* Get/Set ESP mode
|
||||||
|
cmd can be RESET, SAFEMODE, CONFIG, RESTART
|
||||||
|
[ESP444]<cmd>
|
||||||
|
if authentication is on, need admin password for RESET, RESTART and SAFEMODE
|
||||||
|
[ESP444]<cmd>pwd=<admin password>
|
||||||
|
|
||||||
|
* Change / Reset user password
|
||||||
|
[ESP555]<password>pwd=<admin password>
|
||||||
|
if no password set it use default one
|
||||||
|
|
||||||
|
* Read SPIFFS file and send each line to serial
|
||||||
|
[ESP700]<filename>
|
||||||
|
|
||||||
|
* Get fw version
|
||||||
|
[ESP800]<header answer>
|
||||||
|
|
||||||
|
* Clear status/error/info list
|
||||||
|
cmd can be ALL, ERROR, INFO, STATUS
|
||||||
|
[ESP999]<cmd>
|
||||||
|
|
@ -32,93 +32,221 @@
|
|||||||
String COMMAND::buffer_serial;
|
String COMMAND::buffer_serial;
|
||||||
String COMMAND::buffer_tcp;
|
String COMMAND::buffer_tcp;
|
||||||
|
|
||||||
|
#define ERROR_CMD_MSG F("\nM117 Cmd Error")
|
||||||
|
#define INCORRECT_CMD_MSG F("\nM117 Incorrect Cmd")
|
||||||
|
#define OK_CMD_MSG F("\nM117 Cmd Ok")
|
||||||
|
|
||||||
|
String COMMAND::get_param(String & cmd_params, const char * id, bool withspace)
|
||||||
|
{
|
||||||
|
static String parameter;
|
||||||
|
String sid=id;
|
||||||
|
int start;
|
||||||
|
int end = -1;
|
||||||
|
parameter = "";
|
||||||
|
//if no id it means it is first part of cmd
|
||||||
|
if (strlen(id) == 0) start = 0;
|
||||||
|
//else find id position
|
||||||
|
else start = cmd_params.indexOf(id);
|
||||||
|
//if no id found and not first part leave
|
||||||
|
if (start == -1 ) return parameter;
|
||||||
|
//password and SSID can have space so handle it
|
||||||
|
//if no space expected use space as delimiter
|
||||||
|
if (!withspace)end = cmd_params.indexOf(" ",start);
|
||||||
|
//if space expected only one parameter but additional password may be present
|
||||||
|
else if (sid!="pwd=")end = cmd_params.indexOf("pwd=",start);
|
||||||
|
//if no end found - take all
|
||||||
|
if (end == -1) end = cmd_params.length();
|
||||||
|
//extract parameter
|
||||||
|
parameter = cmd_params.substring(start+strlen(id),end);
|
||||||
|
//be sure no extra space
|
||||||
|
parameter.trim();
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
bool COMMAND::isadmin(String & cmd_params)
|
||||||
|
{
|
||||||
|
String adminpassword;
|
||||||
|
String sadminPassword;
|
||||||
|
if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
||||||
|
LOG("ERROR getting admin\n")
|
||||||
|
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
||||||
|
}
|
||||||
|
adminpassword = get_param(cmd_params,"pwd=", true);
|
||||||
|
if (!sadminPassword.equals(adminpassword)) {
|
||||||
|
LOG("Not allowed \n")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
void COMMAND::execute_command(int cmd,String cmd_params)
|
void COMMAND::execute_command(int cmd,String cmd_params)
|
||||||
{
|
{
|
||||||
//manage parameters
|
//manage parameters
|
||||||
|
byte mode = 254;
|
||||||
|
String parameter;
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
byte mode;
|
//STA SSID
|
||||||
case 800:
|
//[ESP100]<SSID>[pwd=<admin password>]
|
||||||
Serial.print(cmd_params);
|
|
||||||
Serial.print("\nFW version:");
|
|
||||||
Serial.println(FW_VERSION);
|
|
||||||
break;
|
|
||||||
case 100:
|
case 100:
|
||||||
if (!CONFIG::isSSIDValid(cmd_params.c_str()))Serial.println("\nError");
|
parameter = get_param(cmd_params,"", true);
|
||||||
if(!CONFIG::write_string(EP_STA_SSID,cmd_params.c_str())) {
|
if (!CONFIG::isSSIDValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
||||||
Serial.println("\nError");
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
if (!isadmin(cmd_params)) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//STA Password
|
||||||
|
//[ESP101]<Password>[pwd=<admin password>]
|
||||||
case 101:
|
case 101:
|
||||||
if(!CONFIG::write_string(EP_STA_PASSWORD,cmd_params.c_str())) {
|
parameter = get_param(cmd_params,"", true);
|
||||||
Serial.println("\nError");
|
if (!CONFIG::isPasswordValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
if (!isadmin(cmd_params)) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//Hostname
|
||||||
|
//[ESP102]<hostname>[pwd=<admin password>]
|
||||||
case 102:
|
case 102:
|
||||||
if (!CONFIG::isHostnameValid(cmd_params.c_str()))Serial.println("\nError");
|
parameter = get_param(cmd_params,"", true);
|
||||||
if(!CONFIG::write_string(EP_HOSTNAME,cmd_params.c_str())) {
|
if (!CONFIG::isHostnameValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
||||||
Serial.println("\nError");
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
if (!isadmin(cmd_params)) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//Wifi mode (STA/AP)
|
||||||
|
//[ESP103]<mode>[pwd=<admin password>]
|
||||||
case 103:
|
case 103:
|
||||||
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (cmd_params=="STA") {
|
if (parameter == "STA") {
|
||||||
mode = CLIENT_MODE;
|
mode = CLIENT_MODE;
|
||||||
|
} else if (parameter == "AP") {
|
||||||
|
mode = AP_MODE;
|
||||||
} else {
|
} else {
|
||||||
mode=AP_MODE;
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
|
if ((mode == CLIENT_MODE) || (mode == AP_MODE)){
|
||||||
Serial.println("\nError");
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
} else {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println("\nOk");
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//STA IP mode (DHCP/STATIC)
|
||||||
|
//[ESP104]<mode>[pwd=<admin password>]
|
||||||
case 104:
|
case 104:
|
||||||
if (cmd_params=="STATIC") {
|
parameter = get_param(cmd_params,"", true);
|
||||||
|
if (parameter == "STATIC") {
|
||||||
mode = STATIC_IP_MODE;
|
mode = STATIC_IP_MODE;
|
||||||
} else {
|
} else if (parameter == "DHCP") {
|
||||||
mode=DHCP_MODE;
|
mode = DHCP_MODE;
|
||||||
|
} else{
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
|
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)){
|
||||||
Serial.println("\nError");
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
} else {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println("\nOk");
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//AP SSID
|
||||||
|
//[ESP105]<SSID>[pwd=<admin password>]
|
||||||
case 105:
|
case 105:
|
||||||
if (!CONFIG::isSSIDValid(cmd_params.c_str()))Serial.println("\nError");
|
parameter = get_param(cmd_params,"", true);
|
||||||
if(!CONFIG::write_string(EP_AP_SSID,cmd_params.c_str())) {
|
if (!CONFIG::isSSIDValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
||||||
Serial.println("\nError");
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
if (!isadmin(cmd_params)) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//AP Password
|
||||||
|
//[ESP106]<Password>[pwd=<admin password>]
|
||||||
case 106:
|
case 106:
|
||||||
if(!CONFIG::write_string(EP_AP_PASSWORD,cmd_params.c_str())) {
|
parameter = get_param(cmd_params,"", true);
|
||||||
Serial.println("\nError");
|
if (!CONFIG::isPasswordValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
if (!isadmin(cmd_params)) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nOk");
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//AP IP mode (DHCP/STATIC)
|
||||||
|
//[ESP107]<mode>[pwd=<admin password>]
|
||||||
case 107:
|
case 107:
|
||||||
if (cmd_params=="STATIC") {
|
parameter = get_param(cmd_params,"", true);
|
||||||
|
if (parameter == "STATIC") {
|
||||||
mode = STATIC_IP_MODE;
|
mode = STATIC_IP_MODE;
|
||||||
} else {
|
} else if (parameter == "DHCP") {
|
||||||
mode=DHCP_MODE;
|
mode = DHCP_MODE;
|
||||||
|
} else{
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)){
|
||||||
Serial.println("\nError");
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
} else {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println("\nOk");
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//Get current IP
|
||||||
|
//[ESP111]<header answer>
|
||||||
case 111: {
|
case 111: {
|
||||||
String currentIP ;
|
String currentIP ;
|
||||||
if (WiFi.getMode()==WIFI_STA) {
|
if (WiFi.getMode()==WIFI_STA) {
|
||||||
@ -132,6 +260,8 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//Get hostname
|
||||||
|
//[ESP112]<header answer>
|
||||||
case 112: {
|
case 112: {
|
||||||
String shost ;
|
String shost ;
|
||||||
if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) {
|
if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) {
|
||||||
@ -143,36 +273,63 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//Get/Set ESP mode
|
||||||
|
//cmd is RESET, SAFEMODE, CONFIG, RESTART
|
||||||
|
//[ESP444]<cmd>pwd=<admin password>
|
||||||
case 444:
|
case 444:
|
||||||
if (cmd_params=="RESET") {
|
parameter = get_param(cmd_params,"", true);
|
||||||
CONFIG::reset_config();
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
}
|
if (!isadmin(cmd_params)) {
|
||||||
if (cmd_params=="SAFEMODE") {
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
wifi_config.Safe_Setup();
|
}
|
||||||
}
|
else
|
||||||
if (cmd_params=="CONFIG") {
|
#endif
|
||||||
|
{
|
||||||
|
if (parameter=="RESET") {
|
||||||
|
CONFIG::reset_config();
|
||||||
|
}
|
||||||
|
if (parameter=="SAFEMODE") {
|
||||||
|
wifi_config.Safe_Setup();
|
||||||
|
}
|
||||||
|
if (parameter=="RESTART") {
|
||||||
|
CONFIG::esp_restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parameter=="CONFIG") {
|
||||||
CONFIG::print_config();
|
CONFIG::print_config();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
|
//Change / Reset user password
|
||||||
|
//[ESP555]<password>pwd=<admin password>
|
||||||
case 555:
|
case 555:
|
||||||
{
|
{
|
||||||
String sadminPassword;
|
if (isadmin(cmd_params)) {
|
||||||
if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
parameter = get_param(cmd_params,"", true);
|
||||||
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
if (parameter.length() == 0){
|
||||||
}
|
if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
|
||||||
if (cmd_params == sadminPassword.c_str()) {
|
Serial.println(OK_CMD_MSG);
|
||||||
if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
|
}
|
||||||
Serial.println("\nOk");
|
else {
|
||||||
}
|
Serial.println(ERROR_CMD_MSG);
|
||||||
else {
|
}
|
||||||
Serial.println("\nFailed");
|
} else {
|
||||||
|
if (CONFIG::isLocalPasswordValid(parameter.c_str())){
|
||||||
|
if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else Serial.println("\nFailed");
|
else Serial.println(INCORRECT_CMD_MSG);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
//[ESP700]<filename>
|
||||||
case 700: //read local file
|
case 700: //read local file
|
||||||
{//be sure serial is locked
|
{//be sure serial is locked
|
||||||
if ((web_interface->blockserial)) break;
|
if ((web_interface->blockserial)) break;
|
||||||
@ -195,19 +352,21 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//read next line if any
|
//read next line if any
|
||||||
currentline = currentfile.readString();
|
currentline = currentfile.readString();
|
||||||
}
|
}
|
||||||
currentfile.close()
|
currentfile.close();
|
||||||
; }
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 888:
|
//get fw version
|
||||||
if (cmd_params=="RESTART") {
|
//[ESP800]<header answer>
|
||||||
Serial.print("\r");
|
case 800:
|
||||||
Serial.print(cmd_params);
|
Serial.print(cmd_params);
|
||||||
web_interface->restartmodule=true;
|
Serial.print("\nFW version:");
|
||||||
Serial.print("\r\n");
|
Serial.println(FW_VERSION);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
//clear status/error/info list
|
||||||
|
//[ESP999]<cmd>
|
||||||
case 999:
|
case 999:
|
||||||
|
cmd_params.trim();
|
||||||
#ifdef ERROR_MSG_FEATURE
|
#ifdef ERROR_MSG_FEATURE
|
||||||
if (cmd_params=="ERROR") {
|
if (cmd_params=="ERROR") {
|
||||||
web_interface->error_msg.clear();
|
web_interface->error_msg.clear();
|
||||||
@ -249,11 +408,11 @@ void COMMAND::check_command(String buffer)
|
|||||||
static uint32_t start_list=0;
|
static uint32_t start_list=0;
|
||||||
//if SD list is not on going
|
//if SD list is not on going
|
||||||
if (!bfileslist) {
|
if (!bfileslist) {
|
||||||
//check if command is a start of SD File list
|
//check if command is a start of SD File list
|
||||||
int filesstart = buffer.indexOf("Begin file list");
|
int filesstart = buffer.indexOf("Begin file list");
|
||||||
//yes it is file list starting to be displayed
|
//yes it is file list starting to be displayed
|
||||||
if (filesstart>-1) {
|
if (filesstart>-1) {
|
||||||
//init time out
|
//init time out
|
||||||
start_list = millis();
|
start_list = millis();
|
||||||
//set file list started
|
//set file list started
|
||||||
bfileslist=true;
|
bfileslist=true;
|
||||||
@ -290,7 +449,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#ifdef SPEED_MONITORING_FEATURE
|
#ifdef SPEED_MONITORING_FEATURE
|
||||||
int Speedpos = buffer.indexOf("SpeedMultiply:");
|
int Speedpos = buffer.indexOf("SpeedMultiply:");
|
||||||
#endif
|
#endif
|
||||||
#ifdef FLOW_MONITORING_FEATURE
|
#ifdef FLOW_MONITORING_FEATURE
|
||||||
int Flowpos = buffer.indexOf("FlowMultiply:");
|
int Flowpos = buffer.indexOf("FlowMultiply:");
|
||||||
@ -350,26 +509,26 @@ void COMMAND::check_command(String buffer)
|
|||||||
#ifdef SPEED_MONITORING_FEATURE
|
#ifdef SPEED_MONITORING_FEATURE
|
||||||
//Speed
|
//Speed
|
||||||
if (Speedpos>-1) {
|
if (Speedpos>-1) {
|
||||||
//get just the value
|
//get just the value
|
||||||
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
||||||
buffer2 =buffer.substring(Speedpos+16);
|
buffer2 =buffer.substring(Speedpos+16);
|
||||||
int p2 = buffer2.indexOf(".");
|
int p2 = buffer2.indexOf(".");
|
||||||
web_interface->answer4M220=buffer2.substring(0,p2);
|
web_interface->answer4M220=buffer2.substring(0,p2);
|
||||||
#else
|
#else
|
||||||
web_interface->answer4M220=buffer.substring(Speedpos+14);
|
web_interface->answer4M220=buffer.substring(Speedpos+14);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef FLOW_MONITORING_FEATURE
|
#ifdef FLOW_MONITORING_FEATURE
|
||||||
//Flow
|
//Flow
|
||||||
if (Flowpos>-1) {
|
if (Flowpos>-1) {
|
||||||
//get just the value
|
//get just the value
|
||||||
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
||||||
buffer2 =buffer.substring(Flowpos+13);
|
buffer2 =buffer.substring(Flowpos+13);
|
||||||
int p2 = buffer2.indexOf(".");
|
int p2 = buffer2.indexOf(".");
|
||||||
web_interface->answer4M221=buffer2.substring(0,p2);
|
web_interface->answer4M221=buffer2.substring(0,p2);
|
||||||
#else
|
#else
|
||||||
web_interface->answer4M221=buffer.substring(Flowpos+13);
|
web_interface->answer4M221=buffer.substring(Flowpos+13);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -391,19 +550,19 @@ void COMMAND::check_command(String buffer)
|
|||||||
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
||||||
(web_interface->status_msg).add(buffer.substring(Statuspos+8).c_str());
|
(web_interface->status_msg).add(buffer.substring(Statuspos+8).c_str());
|
||||||
#else
|
#else
|
||||||
(web_interface->status_msg).add(buffer.substring(Statuspos+7).c_str());
|
(web_interface->status_msg).add(buffer.substring(Statuspos+7).c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef DIRECT_SDCARD_FEATURE
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
} else { //listing file is on going
|
} else { //listing file is on going
|
||||||
//check if we are too long
|
//check if we are too long
|
||||||
if ((millis()-start_list)>30000) { //timeout in case of problem
|
if ((millis()-start_list)>30000) { //timeout in case of problem
|
||||||
bfileslist=false;
|
bfileslist=false;
|
||||||
(web_interface->blockserial) = false; //release serial
|
(web_interface->blockserial) = false; //release serial
|
||||||
LOG("Time out\n");
|
LOG("Time out\n");
|
||||||
} else {
|
} else {
|
||||||
//check if this is the end
|
//check if this is the end
|
||||||
if (buffer.indexOf("End file list")>-1) {
|
if (buffer.indexOf("End file list")>-1) {
|
||||||
bfileslist=false;
|
bfileslist=false;
|
||||||
(web_interface->blockserial) = false;
|
(web_interface->blockserial) = false;
|
||||||
@ -415,7 +574,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
LOG(String(web_interface->fileslist.size()));
|
LOG(String(web_interface->fileslist.size()));
|
||||||
LOG(":");
|
LOG(":");
|
||||||
LOG(buffer);
|
LOG(buffer);
|
||||||
LOG('\n');
|
LOG('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -435,19 +594,26 @@ void COMMAND::read_buffer_serial(uint8_t *b, size_t len)
|
|||||||
void COMMAND::read_buffer_tcp(uint8_t b)
|
void COMMAND::read_buffer_tcp(uint8_t b)
|
||||||
{
|
{
|
||||||
static bool previous_was_char=false;
|
static bool previous_was_char=false;
|
||||||
|
static bool iscomment=false;
|
||||||
//to ensure it is continuous string, no char separated by binaries
|
//to ensure it is continuous string, no char separated by binaries
|
||||||
if (!previous_was_char) {
|
if (!previous_was_char) {
|
||||||
buffer_tcp="";
|
buffer_tcp="";
|
||||||
|
iscomment = false;
|
||||||
}
|
}
|
||||||
|
//is comment ?
|
||||||
|
if (char(b) == ';') iscomment = true;
|
||||||
//it is a char so add it to buffer
|
//it is a char so add it to buffer
|
||||||
if (isPrintable(b)) {
|
if (isPrintable(b)) {
|
||||||
previous_was_char=true;
|
previous_was_char=true;
|
||||||
buffer_tcp+=char(b);
|
//add char if not a comment
|
||||||
|
if (!iscomment)buffer_tcp+=char(b);
|
||||||
} else {
|
} else {
|
||||||
previous_was_char=false; //next call will reset the buffer
|
previous_was_char=false; //next call will reset the buffer
|
||||||
}
|
}
|
||||||
//this is not printable but end of command check if need to handle it
|
//this is not printable but end of command check if need to handle it
|
||||||
if (b==13 ||b==10) {
|
if (b==13 ||b==10) {
|
||||||
|
//reset comment flag
|
||||||
|
iscomment = false;
|
||||||
//Minimum is something like M10 so 3 char
|
//Minimum is something like M10 so 3 char
|
||||||
if (buffer_tcp.length()>3) {
|
if (buffer_tcp.length()>3) {
|
||||||
check_command(buffer_tcp);
|
check_command(buffer_tcp);
|
||||||
@ -459,19 +625,25 @@ void COMMAND::read_buffer_tcp(uint8_t b)
|
|||||||
void COMMAND::read_buffer_serial(uint8_t b)
|
void COMMAND::read_buffer_serial(uint8_t b)
|
||||||
{
|
{
|
||||||
static bool previous_was_char=false;
|
static bool previous_was_char=false;
|
||||||
|
static bool iscomment=false;
|
||||||
//to ensure it is continuous string, no char separated by binaries
|
//to ensure it is continuous string, no char separated by binaries
|
||||||
if (!previous_was_char) {
|
if (!previous_was_char) {
|
||||||
buffer_serial="";
|
buffer_serial="";
|
||||||
|
iscomment = false;
|
||||||
}
|
}
|
||||||
|
//is comment ?
|
||||||
|
if (char(b) == ';') iscomment = true;
|
||||||
//it is a char so add it to buffer
|
//it is a char so add it to buffer
|
||||||
if (isPrintable(b)) {
|
if (isPrintable(b)) {
|
||||||
previous_was_char=true;
|
previous_was_char=true;
|
||||||
buffer_serial+=char(b);
|
if (!iscomment)buffer_serial+=char(b);
|
||||||
} else {
|
} else {
|
||||||
previous_was_char=false; //next call will reset the buffer
|
previous_was_char=false; //next call will reset the buffer
|
||||||
}
|
}
|
||||||
//this is not printable but end of command check if need to handle it
|
//this is not printable but end of command check if need to handle it
|
||||||
if (b==13) {
|
if (b==13) {
|
||||||
|
//reset comment flag
|
||||||
|
iscomment = false;
|
||||||
//Minimum is something like M10 so 3 char
|
//Minimum is something like M10 so 3 char
|
||||||
if (buffer_serial.length()>3) {
|
if (buffer_serial.length()>3) {
|
||||||
check_command(buffer_serial);
|
check_command(buffer_serial);
|
||||||
|
@ -32,6 +32,8 @@ public:
|
|||||||
static void read_buffer_tcp(uint8_t b);
|
static void read_buffer_tcp(uint8_t b);
|
||||||
static void check_command(String buffer);
|
static void check_command(String buffer);
|
||||||
static void execute_command(int cmd,String cmd_params);
|
static void execute_command(int cmd,String cmd_params);
|
||||||
|
static String get_param(String & cmd_params, const char * id, bool withspace = false);
|
||||||
|
static bool isadmin(String & cmd_params);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,13 +40,13 @@
|
|||||||
#define SSDP_FEATURE
|
#define SSDP_FEATURE
|
||||||
|
|
||||||
//NETBIOS_FEATURE: this feature is a discovery protocol, supported on Windows out of the box
|
//NETBIOS_FEATURE: this feature is a discovery protocol, supported on Windows out of the box
|
||||||
#define NETBIOS_FEATURE
|
//#define NETBIOS_FEATURE
|
||||||
|
|
||||||
//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page
|
//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page
|
||||||
#define CAPTIVE_PORTAL_FEATURE
|
#define CAPTIVE_PORTAL_FEATURE
|
||||||
|
|
||||||
//AUTHENTICATION_FEATURE: protect pages by login password
|
//AUTHENTICATION_FEATURE: protect pages by login password
|
||||||
//#define AUTHENTICATION_FEATURE
|
#define AUTHENTICATION_FEATURE
|
||||||
|
|
||||||
//WEB_UPDATE_FEATURE: allow to flash fw using web UI
|
//WEB_UPDATE_FEATURE: allow to flash fw using web UI
|
||||||
#define WEB_UPDATE_FEATURE
|
#define WEB_UPDATE_FEATURE
|
||||||
@ -85,10 +85,10 @@
|
|||||||
|
|
||||||
|
|
||||||
//DEBUG Flag do not do this when connected to printer !!!
|
//DEBUG Flag do not do this when connected to printer !!!
|
||||||
//#define DEBUG_ESP3D
|
#define DEBUG_ESP3D
|
||||||
//#define DEBUG_OUTPUT_SPIFFS
|
//#define DEBUG_OUTPUT_SPIFFS
|
||||||
//#define DEBUG_OUTPUT_SD
|
//#define DEBUG_OUTPUT_SD
|
||||||
//#define DEBUG_OUTPUT_SERIAL
|
#define DEBUG_OUTPUT_SERIAL
|
||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user