mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-02 04:20:37 +08:00
Apply astyle --style=otbs *.h *.cpp *.ino
This commit is contained in:
parent
fabf6c133f
commit
3ee67c022b
@ -27,7 +27,8 @@ WiFiServer * data_server;
|
|||||||
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool BRIDGE::processFromSerial2TCP(){
|
bool BRIDGE::processFromSerial2TCP()
|
||||||
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
//check UART for data
|
//check UART for data
|
||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
@ -46,11 +47,13 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
|
|||||||
//process data if any
|
//process data if any
|
||||||
COMMAND::read_buffer_serial(sbuf, len);
|
COMMAND::read_buffer_serial(sbuf, len);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else return false;
|
}
|
||||||
}
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
void BRIDGE::processFromTCP2Serial()
|
||||||
void BRIDGE::processFromTCP2Serial(){
|
{
|
||||||
uint8_t i,data;
|
uint8_t i,data;
|
||||||
//check if there are any new clients
|
//check if there are any new clients
|
||||||
if (data_server->hasClient()) {
|
if (data_server->hasClient()) {
|
||||||
@ -70,7 +73,7 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
|
|||||||
}
|
}
|
||||||
//check clients for data
|
//check clients for data
|
||||||
//to avoid any pollution if Uploading file to SDCard
|
//to avoid any pollution if Uploading file to SDCard
|
||||||
if ((web_interface->blockserial) == false){
|
if ((web_interface->blockserial) == false) {
|
||||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||||
if (serverClients[i] && serverClients[i].connected()) {
|
if (serverClients[i] && serverClients[i].connected()) {
|
||||||
if(serverClients[i].available()) {
|
if(serverClients[i].available()) {
|
||||||
@ -84,5 +87,5 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,7 +31,7 @@ class BRIDGE
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool processFromSerial2TCP();
|
static bool processFromSerial2TCP();
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
static void processFromTCP2Serial();
|
static void processFromTCP2Serial();
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -44,18 +44,30 @@ String COMMAND::get_param(String & cmd_params, const char * id, bool withspace)
|
|||||||
int end = -1;
|
int end = -1;
|
||||||
parameter = "";
|
parameter = "";
|
||||||
//if no id it means it is first part of cmd
|
//if no id it means it is first part of cmd
|
||||||
if (strlen(id) == 0) start = 0;
|
if (strlen(id) == 0) {
|
||||||
|
start = 0;
|
||||||
|
}
|
||||||
//else find id position
|
//else find id position
|
||||||
else start = cmd_params.indexOf(id);
|
else {
|
||||||
|
start = cmd_params.indexOf(id);
|
||||||
|
}
|
||||||
//if no id found and not first part leave
|
//if no id found and not first part leave
|
||||||
if (start == -1 ) return parameter;
|
if (start == -1 ) {
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
//password and SSID can have space so handle it
|
//password and SSID can have space so handle it
|
||||||
//if no space expected use space as delimiter
|
//if no space expected use space as delimiter
|
||||||
if (!withspace)end = cmd_params.indexOf(" ",start);
|
if (!withspace) {
|
||||||
|
end = cmd_params.indexOf(" ",start);
|
||||||
|
}
|
||||||
//if space expected only one parameter but additional password may be present
|
//if space expected only one parameter but additional password may be present
|
||||||
else if (sid!="pwd=")end = cmd_params.indexOf("pwd=",start);
|
else if (sid!="pwd=") {
|
||||||
|
end = cmd_params.indexOf("pwd=",start);
|
||||||
|
}
|
||||||
//if no end found - take all
|
//if no end found - take all
|
||||||
if (end == -1) end = cmd_params.length();
|
if (end == -1) {
|
||||||
|
end = cmd_params.length();
|
||||||
|
}
|
||||||
//extract parameter
|
//extract parameter
|
||||||
parameter = cmd_params.substring(start+strlen(id),end);
|
parameter = cmd_params.substring(start+strlen(id),end);
|
||||||
//be sure no extra space
|
//be sure no extra space
|
||||||
@ -75,8 +87,9 @@ bool COMMAND::isadmin(String & cmd_params)
|
|||||||
if (!sadminPassword.equals(adminpassword)) {
|
if (!sadminPassword.equals(adminpassword)) {
|
||||||
LOG("Not allowed \n")
|
LOG("Not allowed \n")
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else return true;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void COMMAND::execute_command(int cmd,String cmd_params)
|
void COMMAND::execute_command(int cmd,String cmd_params)
|
||||||
@ -89,12 +102,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//[ESP100]<SSID>[pwd=<admin password>]
|
//[ESP100]<SSID>[pwd=<admin password>]
|
||||||
case 100:
|
case 100:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (!CONFIG::isSSIDValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
if (!CONFIG::isSSIDValid(parameter.c_str())) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
|
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -106,12 +120,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//[ESP101]<Password>[pwd=<admin password>]
|
//[ESP101]<Password>[pwd=<admin password>]
|
||||||
case 101:
|
case 101:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (!CONFIG::isPasswordValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
if (!CONFIG::isPasswordValid(parameter.c_str())) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
|
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -123,12 +138,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//[ESP102]<hostname>[pwd=<admin password>]
|
//[ESP102]<hostname>[pwd=<admin password>]
|
||||||
case 102:
|
case 102:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (!CONFIG::isHostnameValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
if (!CONFIG::isHostnameValid(parameter.c_str())) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
|
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -147,12 +163,11 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
} else {
|
} else {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
if ((mode == CLIENT_MODE) || (mode == AP_MODE)){
|
if ((mode == CLIENT_MODE) || (mode == AP_MODE)) {
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
|
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -169,15 +184,14 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
mode = STATIC_IP_MODE;
|
mode = STATIC_IP_MODE;
|
||||||
} else if (parameter == "DHCP") {
|
} else if (parameter == "DHCP") {
|
||||||
mode = DHCP_MODE;
|
mode = DHCP_MODE;
|
||||||
} else{
|
} else {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)){
|
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) {
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
|
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -190,12 +204,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//[ESP105]<SSID>[pwd=<admin password>]
|
//[ESP105]<SSID>[pwd=<admin password>]
|
||||||
case 105:
|
case 105:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (!CONFIG::isSSIDValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
if (!CONFIG::isSSIDValid(parameter.c_str())) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) {
|
if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -207,12 +222,13 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//[ESP106]<Password>[pwd=<admin password>]
|
//[ESP106]<Password>[pwd=<admin password>]
|
||||||
case 106:
|
case 106:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (!CONFIG::isPasswordValid(parameter.c_str()))Serial.println(INCORRECT_CMD_MSG);
|
if (!CONFIG::isPasswordValid(parameter.c_str())) {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
|
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -228,15 +244,14 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
mode = STATIC_IP_MODE;
|
mode = STATIC_IP_MODE;
|
||||||
} else if (parameter == "DHCP") {
|
} else if (parameter == "DHCP") {
|
||||||
mode = DHCP_MODE;
|
mode = DHCP_MODE;
|
||||||
} else{
|
} else {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)){
|
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) {
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
@ -282,40 +297,40 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
parameter = get_param(cmd_params,"P", true);
|
parameter = get_param(cmd_params,"P", true);
|
||||||
LOG(parameter)
|
LOG(parameter)
|
||||||
LOG("\n")
|
LOG("\n")
|
||||||
if (parameter == "")
|
if (parameter == "") {
|
||||||
{
|
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
int pin = parameter.toInt();
|
int pin = parameter.toInt();
|
||||||
//check pin is valid and not serial used pins
|
//check pin is valid and not serial used pins
|
||||||
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3)))
|
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) {
|
||||||
{
|
|
||||||
//check if is set or get
|
//check if is set or get
|
||||||
parameter = get_param(cmd_params,"V", true);
|
parameter = get_param(cmd_params,"V", true);
|
||||||
//it is a get
|
//it is a get
|
||||||
if (parameter == "")
|
if (parameter == "") {
|
||||||
{ //GPIO16 is different than
|
//GPIO16 is different than
|
||||||
if (pin <16) pinMode(pin, INPUT_PULLUP);
|
if (pin <16) {
|
||||||
else pinMode(pin, INPUT_PULLDOWN_16);
|
pinMode(pin, INPUT_PULLUP);
|
||||||
|
} else {
|
||||||
|
pinMode(pin, INPUT_PULLDOWN_16);
|
||||||
|
}
|
||||||
delay(10);
|
delay(10);
|
||||||
int value = digitalRead(pin);
|
int value = digitalRead(pin);
|
||||||
Serial.println(String(value));
|
Serial.println(String(value));
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
//it is a set
|
//it is a set
|
||||||
int value = parameter.toInt();
|
int value = parameter.toInt();
|
||||||
//verify it is a 0 or a 1
|
//verify it is a 0 or a 1
|
||||||
if ((value == 0) || (value == 1))
|
if ((value == 0) || (value == 1)) {
|
||||||
{
|
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
delay(10);
|
delay(10);
|
||||||
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
||||||
}
|
} else {
|
||||||
else Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else Serial.println(INCORRECT_CMD_MSG);
|
} else {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -329,8 +344,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
if (!isadmin(cmd_params)) {
|
if (!isadmin(cmd_params)) {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (parameter=="RESET") {
|
if (parameter=="RESET") {
|
||||||
@ -350,39 +364,42 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
//Change / Reset user password
|
//Change / Reset user password
|
||||||
//[ESP555]<password>pwd=<admin password>
|
//[ESP555]<password>pwd=<admin password>
|
||||||
case 555:
|
case 555: {
|
||||||
{
|
|
||||||
if (isadmin(cmd_params)) {
|
if (isadmin(cmd_params)) {
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
if (parameter.length() == 0){
|
if (parameter.length() == 0) {
|
||||||
if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
|
if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) {
|
||||||
Serial.println(OK_CMD_MSG);
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (CONFIG::isLocalPasswordValid(parameter.c_str())){
|
if (CONFIG::isLocalPasswordValid(parameter.c_str())) {
|
||||||
if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) {
|
if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) {
|
||||||
Serial.println(OK_CMD_MSG);
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else Serial.println(INCORRECT_CMD_MSG);
|
} else {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//[ESP700]<filename>
|
//[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;
|
||||||
|
}
|
||||||
cmd_params.trim() ;
|
cmd_params.trim() ;
|
||||||
if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) cmd_params = "/" + cmd_params;
|
if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) {
|
||||||
|
cmd_params = "/" + cmd_params;
|
||||||
|
}
|
||||||
FSFILE currentfile = SPIFFS.open(cmd_params, "r");
|
FSFILE currentfile = SPIFFS.open(cmd_params, "r");
|
||||||
if (currentfile) {//if file open success
|
if (currentfile) {//if file open success
|
||||||
//flush to be sure send buffer is empty
|
//flush to be sure send buffer is empty
|
||||||
@ -390,8 +407,8 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//read content
|
//read content
|
||||||
String currentline = currentfile.readString();
|
String currentline = currentfile.readString();
|
||||||
//until no line in file
|
//until no line in file
|
||||||
while (currentline.length() >0)
|
while (currentline.length() >0) {
|
||||||
{ //send line to serial
|
//send line to serial
|
||||||
Serial.println(currentline);
|
Serial.println(currentline);
|
||||||
//flush to be sure send buffer is empty
|
//flush to be sure send buffer is empty
|
||||||
delay(0);
|
delay(0);
|
||||||
@ -649,12 +666,16 @@ void COMMAND::read_buffer_tcp(uint8_t b)
|
|||||||
iscomment = false;
|
iscomment = false;
|
||||||
}
|
}
|
||||||
//is comment ?
|
//is comment ?
|
||||||
if (char(b) == ';') iscomment = true;
|
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;
|
||||||
//add char if not a comment
|
//add char if not a comment
|
||||||
if (!iscomment)buffer_tcp+=char(b);
|
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
|
||||||
}
|
}
|
||||||
@ -680,11 +701,15 @@ void COMMAND::read_buffer_serial(uint8_t b)
|
|||||||
iscomment = false;
|
iscomment = false;
|
||||||
}
|
}
|
||||||
//is comment ?
|
//is comment ?
|
||||||
if (char(b) == ';') iscomment = true;
|
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;
|
||||||
if (!iscomment)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
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,8 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CONFIG::esp_restart(){
|
void CONFIG::esp_restart()
|
||||||
|
{
|
||||||
LOG("Restarting\n")
|
LOG("Restarting\n")
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
delay(500);
|
delay(500);
|
||||||
@ -270,7 +271,9 @@ bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
|
|||||||
//read until max size is reached or \0 is found
|
//read until max size is reached or \0 is found
|
||||||
while (i < size_max && b != 0) {
|
while (i < size_max && b != 0) {
|
||||||
b = EEPROM.read(pos+i);
|
b = EEPROM.read(pos+i);
|
||||||
if (b!=0)sbuffer+=char(b);
|
if (b!=0) {
|
||||||
|
sbuffer+=char(b);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
EEPROM.end();
|
EEPROM.end();
|
||||||
@ -324,8 +327,7 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
|
|||||||
int maxsize = EEPROM_SIZE;
|
int maxsize = EEPROM_SIZE;
|
||||||
size_buffer= strlen(byte_buffer);
|
size_buffer= strlen(byte_buffer);
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
switch (pos)
|
switch (pos) {
|
||||||
{
|
|
||||||
case EP_ADMIN_PWD:
|
case EP_ADMIN_PWD:
|
||||||
case EP_USER_PWD:
|
case EP_USER_PWD:
|
||||||
maxsize = MAX_LOCAL_PASSWORD_LENGTH;
|
maxsize = MAX_LOCAL_PASSWORD_LENGTH;
|
||||||
|
@ -97,16 +97,16 @@
|
|||||||
|
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
#ifdef DEBUG_OUTPUT_SPIFFS
|
#ifdef DEBUG_OUTPUT_SPIFFS
|
||||||
#define LOG(string) {FSFILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
#define LOG(string) {FSFILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
||||||
#else
|
#else
|
||||||
#ifdef SDCARD_FEATURE
|
#ifdef SDCARD_FEATURE
|
||||||
#ifdef DEBUG_OUTPUT_SD
|
#ifdef DEBUG_OUTPUT_SD
|
||||||
#define LOG(string) {if(CONFIG::hasSD()){LOCKSD() File logfile = SD.open("/log.txt", "a+");logfile.print(string);logfile.close();RELEASESD()}}
|
#define LOG(string) {if(CONFIG::hasSD()){LOCKSD() File logfile = SD.open("/log.txt", "a+");logfile.print(string);logfile.close();RELEASESD()}}
|
||||||
#else
|
|
||||||
#define LOG(string) {Serial.print(string);}
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
#define LOG(string) {Serial.print(string);}
|
#define LOG(string) {Serial.print(string);}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define LOG(string) {Serial.print(string);}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
@ -126,7 +126,7 @@ void setup()
|
|||||||
if (!wifi_config.Setup()) {
|
if (!wifi_config.Setup()) {
|
||||||
Serial.println(F("M117 Safe mode 1"));
|
Serial.println(F("M117 Safe mode 1"));
|
||||||
//try again in AP mode
|
//try again in AP mode
|
||||||
if (!wifi_config.Setup(true)){
|
if (!wifi_config.Setup(true)) {
|
||||||
Serial.println(F("M117 Safe mode 2"));
|
Serial.println(F("M117 Safe mode 2"));
|
||||||
wifi_config.Safe_Setup();
|
wifi_config.Safe_Setup();
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ void setup()
|
|||||||
wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port);
|
wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port);
|
||||||
#endif
|
#endif
|
||||||
#if defined(SSDP_FEATURE) || defined(NETBIOS_FEATURE)
|
#if defined(SSDP_FEATURE) || defined(NETBIOS_FEATURE)
|
||||||
String shost;
|
String shost;
|
||||||
if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) {
|
if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) {
|
||||||
shost=wifi_config.get_default_hostname();
|
shost=wifi_config.get_default_hostname();
|
||||||
}
|
}
|
||||||
|
@ -417,8 +417,11 @@ void WEBINTERFACE_CLASS::GeLogin(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLA
|
|||||||
if (auth_level != LEVEL_GUEST) {
|
if (auth_level != LEVEL_GUEST) {
|
||||||
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
|
ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE));
|
||||||
KeysList.add(FPSTR(KEY_LOGIN_ID));
|
KeysList.add(FPSTR(KEY_LOGIN_ID));
|
||||||
if (auth_level == LEVEL_ADMIN) ValuesList.add(FPSTR(DEFAULT_ADMIN_LOGIN));
|
if (auth_level == LEVEL_ADMIN) {
|
||||||
else ValuesList.add(FPSTR(DEFAULT_USER_LOGIN));
|
ValuesList.add(FPSTR(DEFAULT_ADMIN_LOGIN));
|
||||||
|
} else {
|
||||||
|
ValuesList.add(FPSTR(DEFAULT_USER_LOGIN));
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -958,9 +961,9 @@ void handle_web_interface_configSys()
|
|||||||
//is there a correct list of values?
|
//is there a correct list of values?
|
||||||
if (web_interface->WebServer.hasArg("BAUD_RATE")
|
if (web_interface->WebServer.hasArg("BAUD_RATE")
|
||||||
&& web_interface->WebServer.hasArg("SLEEP_MODE")
|
&& web_interface->WebServer.hasArg("SLEEP_MODE")
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
&& web_interface->WebServer.hasArg("DATAPORT")
|
&& web_interface->WebServer.hasArg("DATAPORT")
|
||||||
#endif
|
#endif
|
||||||
&& web_interface->WebServer.hasArg("WEBPORT")) {
|
&& web_interface->WebServer.hasArg("WEBPORT")) {
|
||||||
//is each value correct ?
|
//is each value correct ?
|
||||||
ibaud = web_interface->WebServer.arg("BAUD_RATE").toInt();
|
ibaud = web_interface->WebServer.arg("BAUD_RATE").toInt();
|
||||||
@ -1176,8 +1179,11 @@ void handle_password()
|
|||||||
if (msg_alert_error==false) {
|
if (msg_alert_error==false) {
|
||||||
//save
|
//save
|
||||||
bool res;
|
bool res;
|
||||||
if (auth_level == LEVEL_ADMIN) res = CONFIG::write_string(EP_ADMIN_PWD,sPassword.c_str()) ;
|
if (auth_level == LEVEL_ADMIN) {
|
||||||
else res = CONFIG::write_string(EP_USER_PWD,sPassword.c_str()) ;
|
res = CONFIG::write_string(EP_ADMIN_PWD,sPassword.c_str()) ;
|
||||||
|
} else {
|
||||||
|
res = CONFIG::write_string(EP_USER_PWD,sPassword.c_str()) ;
|
||||||
|
}
|
||||||
if (!res) {
|
if (!res) {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
smsg = FPSTR(EEPROM_NOWRITE);
|
smsg = FPSTR(EEPROM_NOWRITE);
|
||||||
@ -2311,8 +2317,7 @@ void SPIFFSFileupload()
|
|||||||
//get authentication status
|
//get authentication status
|
||||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
//Guest cannot upload
|
//Guest cannot upload
|
||||||
if (auth_level == LEVEL_GUEST)
|
if (auth_level == LEVEL_GUEST) {
|
||||||
{
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 Error ESP upload");
|
Serial.println("M117 Error ESP upload");
|
||||||
return;
|
return;
|
||||||
@ -2324,33 +2329,33 @@ void SPIFFSFileupload()
|
|||||||
if(upload.status == UPLOAD_FILE_START) {
|
if(upload.status == UPLOAD_FILE_START) {
|
||||||
String filename;
|
String filename;
|
||||||
//according User or Admin the root is different as user is isolate to /user when admin has full access
|
//according User or Admin the root is different as user is isolate to /user when admin has full access
|
||||||
if(auth_level == LEVEL_ADMIN) filename = upload.filename;
|
if(auth_level == LEVEL_ADMIN) {
|
||||||
else filename = "/user" + upload.filename;
|
filename = upload.filename;
|
||||||
|
} else {
|
||||||
|
filename = "/user" + upload.filename;
|
||||||
|
}
|
||||||
Serial.println("M117 Start ESP upload");
|
Serial.println("M117 Start ESP upload");
|
||||||
//create file
|
//create file
|
||||||
web_interface->fsUploadFile = SPIFFS.open(filename, "w");
|
web_interface->fsUploadFile = SPIFFS.open(filename, "w");
|
||||||
filename = String();
|
filename = String();
|
||||||
//check If creation succeed
|
//check If creation succeed
|
||||||
if (web_interface->fsUploadFile)
|
if (web_interface->fsUploadFile) {
|
||||||
{ //if yes upload is started
|
//if yes upload is started
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
}
|
} else {
|
||||||
else
|
//if no set cancel flag
|
||||||
{ //if no set cancel flag
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 Error ESP create");
|
Serial.println("M117 Error ESP create");
|
||||||
}
|
}
|
||||||
//Upload write
|
//Upload write
|
||||||
//**************
|
//**************
|
||||||
} else if(upload.status == UPLOAD_FILE_WRITE)
|
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
||||||
{ //check if file is availble and no error
|
//check if file is availble and no error
|
||||||
if(web_interface->fsUploadFile && web_interface->_upload_status == UPLOAD_STATUS_ONGOING)
|
if(web_interface->fsUploadFile && web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||||
{
|
|
||||||
//no error so write post date
|
//no error so write post date
|
||||||
web_interface->fsUploadFile.write(upload.buf, upload.currentSize);
|
web_interface->fsUploadFile.write(upload.buf, upload.currentSize);
|
||||||
}
|
} else {
|
||||||
else
|
//we have a proble set flag UPLOAD_STATUS_CANCELLED
|
||||||
{ //we have a proble set flag UPLOAD_STATUS_CANCELLED
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 Error ESP write");
|
Serial.println("M117 Error ESP write");
|
||||||
}
|
}
|
||||||
@ -2359,13 +2364,12 @@ void SPIFFSFileupload()
|
|||||||
} else if(upload.status == UPLOAD_FILE_END) {
|
} else if(upload.status == UPLOAD_FILE_END) {
|
||||||
Serial.println("M117 End ESP upload");
|
Serial.println("M117 End ESP upload");
|
||||||
//check if file is still open
|
//check if file is still open
|
||||||
if(web_interface->fsUploadFile)
|
if(web_interface->fsUploadFile) {
|
||||||
{ //close it
|
//close it
|
||||||
web_interface->fsUploadFile.close();
|
web_interface->fsUploadFile.close();
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||||
}
|
} else {
|
||||||
else
|
//we have a proble set flag UPLOAD_STATUS_CANCELLED
|
||||||
{ //we have a proble set flag UPLOAD_STATUS_CANCELLED
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 Error ESP close");
|
Serial.println("M117 Error ESP close");
|
||||||
}
|
}
|
||||||
@ -2390,8 +2394,7 @@ void SDFileupload()
|
|||||||
static bool is_comment = false;
|
static bool is_comment = false;
|
||||||
String response;
|
String response;
|
||||||
//Guest cannot upload - only admin and user
|
//Guest cannot upload - only admin and user
|
||||||
if(web_interface->is_authenticated() == LEVEL_GUEST)
|
if(web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
{
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 SD upload failed");
|
Serial.println("M117 SD upload failed");
|
||||||
LOG("SD upload failed\n");
|
LOG("SD upload failed\n");
|
||||||
@ -2420,9 +2423,9 @@ void SDFileupload()
|
|||||||
//now need to purge all serial data
|
//now need to purge all serial data
|
||||||
//let's sleep 1s
|
//let's sleep 1s
|
||||||
delay(1000);
|
delay(1000);
|
||||||
for (int retry=0;retry < 400; retry++) { //time out is 5x400ms = 2000ms
|
for (int retry=0; retry < 400; retry++) { //time out is 5x400ms = 2000ms
|
||||||
//if there is something in serial buffer
|
//if there is something in serial buffer
|
||||||
if(Serial.available()){
|
if(Serial.available()) {
|
||||||
//get size of buffer
|
//get size of buffer
|
||||||
size_t len = Serial.available();
|
size_t len = Serial.available();
|
||||||
uint8_t sbuf[len+1];
|
uint8_t sbuf[len+1];
|
||||||
@ -2433,46 +2436,43 @@ void SDFileupload()
|
|||||||
//use string because easier to handle
|
//use string because easier to handle
|
||||||
response = (const char*)sbuf;
|
response = (const char*)sbuf;
|
||||||
//if there is a wait it means purge is done
|
//if there is a wait it means purge is done
|
||||||
if (response.indexOf("wait")>-1)break;
|
if (response.indexOf("wait")>-1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
//Upload write
|
//Upload write
|
||||||
//**************
|
//**************
|
||||||
//upload is on going with data coming by 2K blocks
|
//upload is on going with data coming by 2K blocks
|
||||||
} else if((upload.status == UPLOAD_FILE_WRITE) && (com_error == false)){//if com error no need to send more data to serial
|
} else if((upload.status == UPLOAD_FILE_WRITE) && (com_error == false)) { //if com error no need to send more data to serial
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
for (int pos = 0; pos < upload.currentSize;pos++) //parse full post data
|
for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data
|
||||||
{
|
if (buffer_size < MAX_RESEND_BUFFER-1) { //raise error/handle if overbuffer - copy is space available
|
||||||
if (buffer_size < MAX_RESEND_BUFFER-1) //raise error/handle if overbuffer - copy is space available
|
|
||||||
{
|
|
||||||
//remove/ignore every comment to save transfert time and avoid over buffer issues
|
//remove/ignore every comment to save transfert time and avoid over buffer issues
|
||||||
if (upload.buf[pos] == ';'){
|
if (upload.buf[pos] == ';') {
|
||||||
is_comment = true;
|
is_comment = true;
|
||||||
previous = ';';
|
previous = ';';
|
||||||
}
|
}
|
||||||
if (!is_comment){
|
if (!is_comment) {
|
||||||
buffer_line[buffer_size] = upload.buf[pos]; //copy current char to buffer to send/resend
|
buffer_line[buffer_size] = upload.buf[pos]; //copy current char to buffer to send/resend
|
||||||
buffer_size++;
|
buffer_size++;
|
||||||
//convert buffer to zero end array
|
//convert buffer to zero end array
|
||||||
buffer_line[buffer_size] = '\0';
|
buffer_line[buffer_size] = '\0';
|
||||||
//check it is not an end line char and line is not empty
|
//check it is not an end line char and line is not empty
|
||||||
if (((buffer_line[0] == '\n') && (buffer_size==1)) ||((buffer_line[1] == '\n') && (buffer_line[0] == '\r') && (buffer_size==2)) || ((buffer_line[0] == ' ') && (buffer_size==1)) )
|
if (((buffer_line[0] == '\n') && (buffer_size==1)) ||((buffer_line[1] == '\n') && (buffer_line[0] == '\r') && (buffer_size==2)) || ((buffer_line[0] == ' ') && (buffer_size==1)) ) {
|
||||||
{
|
|
||||||
//ignore empty line
|
//ignore empty line
|
||||||
buffer_size=0;
|
buffer_size=0;
|
||||||
buffer_line[buffer_size] = '\0';
|
buffer_line[buffer_size] = '\0';
|
||||||
}
|
}
|
||||||
//line is not empty so check if last char is an end line
|
//line is not empty so check if last char is an end line
|
||||||
//if error no need to proceed
|
//if error no need to proceed
|
||||||
else if (((buffer_line[buffer_size-1] == '\n')) && (com_error == false)) //end of line and no error
|
else if (((buffer_line[buffer_size-1] == '\n')) && (com_error == false)) { //end of line and no error
|
||||||
{
|
|
||||||
//if resend use buffer
|
//if resend use buffer
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
//check NB_RETRY times if get no error when send line
|
//check NB_RETRY times if get no error when send line
|
||||||
for (int r = 0 ; r < NB_RETRY ; r++)
|
for (int r = 0 ; r < NB_RETRY ; r++) {
|
||||||
{
|
|
||||||
response = "";
|
response = "";
|
||||||
//print out line
|
//print out line
|
||||||
Serial.print(buffer_line);
|
Serial.print(buffer_line);
|
||||||
@ -2480,9 +2480,9 @@ void SDFileupload()
|
|||||||
//ensure buffer is empty before continuing
|
//ensure buffer is empty before continuing
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
//wait for answer with time out
|
//wait for answer with time out
|
||||||
for (int retry=0;retry < 30; retry++) { //time out 30x5ms = 150ms
|
for (int retry=0; retry < 30; retry++) { //time out 30x5ms = 150ms
|
||||||
//if there is serial data
|
//if there is serial data
|
||||||
if(Serial.available()){
|
if(Serial.available()) {
|
||||||
//get size of available data
|
//get size of available data
|
||||||
size_t len = Serial.available();
|
size_t len = Serial.available();
|
||||||
uint8_t sbuf[len+1];
|
uint8_t sbuf[len+1];
|
||||||
@ -2497,12 +2497,12 @@ void SDFileupload()
|
|||||||
LOG("\n");
|
LOG("\n");
|
||||||
LOG(response);
|
LOG(response);
|
||||||
//if buffer contain ok or wait - it means command is pass
|
//if buffer contain ok or wait - it means command is pass
|
||||||
if ((response.indexOf("wait")>-1)||(response.indexOf("ok")>-1)){
|
if ((response.indexOf("wait")>-1)||(response.indexOf("ok")>-1)) {
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//if buffer contain resend then need to resend
|
//if buffer contain resend then need to resend
|
||||||
if (response.indexOf("Resend") > -1){//if error
|
if (response.indexOf("Resend") > -1) { //if error
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2510,9 +2510,11 @@ void SDFileupload()
|
|||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
//if command is pass no need to retry
|
//if command is pass no need to retry
|
||||||
if (success == true)break;
|
if (success == true) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
//purge extra serial if any
|
//purge extra serial if any
|
||||||
if(Serial.available()){
|
if(Serial.available()) {
|
||||||
//get size of available data
|
//get size of available data
|
||||||
size_t len = Serial.available();
|
size_t len = Serial.available();
|
||||||
uint8_t sbuf[len+1];
|
uint8_t sbuf[len+1];
|
||||||
@ -2523,7 +2525,7 @@ void SDFileupload()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if even after the number of retry still have error - then we are in error
|
//if even after the number of retry still have error - then we are in error
|
||||||
if (!success){
|
if (!success) {
|
||||||
//raise error
|
//raise error
|
||||||
LOG("Error detected\n");
|
LOG("Error detected\n");
|
||||||
LOG(response);
|
LOG(response);
|
||||||
@ -2533,25 +2535,25 @@ void SDFileupload()
|
|||||||
buffer_size = 0;
|
buffer_size = 0;
|
||||||
buffer_line[buffer_size] = '\0';
|
buffer_line[buffer_size] = '\0';
|
||||||
}
|
}
|
||||||
}
|
} else { //it is a comment
|
||||||
else { //it is a comment
|
if (upload.buf[pos] == '\r') { //store if CR
|
||||||
if (upload.buf[pos] == '\r'){ //store if CR
|
|
||||||
previous = '\r';
|
previous = '\r';
|
||||||
}
|
} else if (upload.buf[pos] == '\n') { //this is the end of the comment
|
||||||
else if (upload.buf[pos] == '\n'){ //this is the end of the comment
|
|
||||||
is_comment = false;
|
is_comment = false;
|
||||||
if (buffer_size > 0) {
|
if (buffer_size > 0) {
|
||||||
if (previous == '\r') pos--;
|
if (previous == '\r') {
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
pos--; //do a loop back and process as normal
|
pos--; //do a loop back and process as normal
|
||||||
}
|
}
|
||||||
previous = '\n';
|
previous = '\n';
|
||||||
}//if not just ignore and continue
|
}//if not just ignore and continue
|
||||||
else previous = upload.buf[pos];
|
else {
|
||||||
|
previous = upload.buf[pos];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else { //raise error
|
||||||
else //raise error
|
|
||||||
{
|
|
||||||
LOG("\nlong line detected\n");
|
LOG("\nlong line detected\n");
|
||||||
LOG(buffer_line);
|
LOG(buffer_line);
|
||||||
com_error = true;
|
com_error = true;
|
||||||
@ -2560,42 +2562,46 @@ void SDFileupload()
|
|||||||
//Upload end
|
//Upload end
|
||||||
//**************
|
//**************
|
||||||
} else if(upload.status == UPLOAD_FILE_END) {
|
} else if(upload.status == UPLOAD_FILE_END) {
|
||||||
if (buffer_size > 0){//if last part does not have '\n'
|
if (buffer_size > 0) { //if last part does not have '\n'
|
||||||
//print the line
|
//print the line
|
||||||
Serial.print(buffer_line);
|
Serial.print(buffer_line);
|
||||||
if (is_comment && (previous == '\r'))Serial.print("\r\n");
|
if (is_comment && (previous == '\r')) {
|
||||||
else Serial.print("\n");
|
Serial.print("\r\n");
|
||||||
|
} else {
|
||||||
|
Serial.print("\n");
|
||||||
|
}
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
//if resend use buffer
|
//if resend use buffer
|
||||||
bool success = false;
|
bool success = false;
|
||||||
//check NB_RETRY times if get no error when send line
|
//check NB_RETRY times if get no error when send line
|
||||||
for (int r = 0 ; r < NB_RETRY ; r++)
|
for (int r = 0 ; r < NB_RETRY ; r++) {
|
||||||
{
|
|
||||||
response = "";
|
response = "";
|
||||||
Serial.print(buffer_line);
|
Serial.print(buffer_line);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
//wait for answer with time out
|
//wait for answer with time out
|
||||||
for (int retry=0;retry < 20; retry++) { //time out
|
for (int retry=0; retry < 20; retry++) { //time out
|
||||||
if(Serial.available()){
|
if(Serial.available()) {
|
||||||
size_t len = Serial.available();
|
size_t len = Serial.available();
|
||||||
uint8_t sbuf[len+1];
|
uint8_t sbuf[len+1];
|
||||||
Serial.readBytes(sbuf, len);
|
Serial.readBytes(sbuf, len);
|
||||||
sbuf[len]='\0';
|
sbuf[len]='\0';
|
||||||
response = (const char*)sbuf;
|
response = (const char*)sbuf;
|
||||||
if ((response.indexOf("wait")>-1)||(response.indexOf("ok")>-1)){
|
if ((response.indexOf("wait")>-1)||(response.indexOf("ok")>-1)) {
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (response.indexOf("Resend") > -1){//if error
|
if (response.indexOf("Resend") > -1) { //if error
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
if (success == true)break;
|
if (success == true) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!success){
|
}
|
||||||
|
if (!success) {
|
||||||
//raise error
|
//raise error
|
||||||
LOG("Error detected 2\n");
|
LOG("Error detected 2\n");
|
||||||
LOG(response);
|
LOG(response);
|
||||||
@ -2617,14 +2623,12 @@ void SDFileupload()
|
|||||||
//resend M29 command to close file on SD as first command may be lost
|
//resend M29 command to close file on SD as first command may be lost
|
||||||
Serial.print("\r\nM29\r\n");
|
Serial.print("\r\nM29\r\n");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
if (com_error){
|
if (com_error) {
|
||||||
LOG("with error\n");
|
LOG("with error\n");
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 SD upload failed");
|
Serial.println("M117 SD upload failed");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG("with success\n");
|
LOG("with success\n");
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||||
Serial.println("M117 SD upload done");
|
Serial.println("M117 SD upload done");
|
||||||
@ -2657,8 +2661,7 @@ void WebUpdateUpload()
|
|||||||
static size_t last_upload_update;
|
static size_t last_upload_update;
|
||||||
static uint32_t maxSketchSpace ;
|
static uint32_t maxSketchSpace ;
|
||||||
//only admin can update FW
|
//only admin can update FW
|
||||||
if(web_interface->is_authenticated() != LEVEL_ADMIN)
|
if(web_interface->is_authenticated() != LEVEL_ADMIN) {
|
||||||
{
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
Serial.println("M117 Update failed");
|
Serial.println("M117 Update failed");
|
||||||
LOG("SD Update failed\n");
|
LOG("SD Update failed\n");
|
||||||
@ -2676,23 +2679,22 @@ void WebUpdateUpload()
|
|||||||
last_upload_update = 0;
|
last_upload_update = 0;
|
||||||
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
|
} else {
|
||||||
|
Serial.println(F("M117 Update 0%"));
|
||||||
}
|
}
|
||||||
else Serial.println(F("M117 Update 0%"));
|
|
||||||
//Upload write
|
//Upload write
|
||||||
//**************
|
//**************
|
||||||
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
||||||
//check if no error
|
//check if no error
|
||||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING)
|
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||||
{
|
|
||||||
//we do not know the total file size yet but we know the available space so let's use it
|
//we do not know the total file size yet but we know the available space so let's use it
|
||||||
if ( ((100 * upload.totalSize) / maxSketchSpace) !=last_upload_update){
|
if ( ((100 * upload.totalSize) / maxSketchSpace) !=last_upload_update) {
|
||||||
last_upload_update = (100 * upload.totalSize) / maxSketchSpace;
|
last_upload_update = (100 * upload.totalSize) / maxSketchSpace;
|
||||||
Serial.print(F("M117 Update "));
|
Serial.print(F("M117 Update "));
|
||||||
Serial.print(last_upload_update);
|
Serial.print(last_upload_update);
|
||||||
Serial.println(F("%"));
|
Serial.println(F("%"));
|
||||||
}
|
}
|
||||||
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize)
|
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||||
{
|
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2738,14 +2740,21 @@ void handleFileList()
|
|||||||
String path ;
|
String path ;
|
||||||
String status = "Ok";
|
String status = "Ok";
|
||||||
//be sure root is correct according authentication
|
//be sure root is correct according authentication
|
||||||
if (auth_level == LEVEL_ADMIN) path = "/";
|
if (auth_level == LEVEL_ADMIN) {
|
||||||
else path = "/user";
|
path = "/";
|
||||||
|
} else {
|
||||||
|
path = "/user";
|
||||||
|
}
|
||||||
//get current path
|
//get current path
|
||||||
if(web_interface->WebServer.hasArg("path"))path += web_interface->WebServer.arg("path") ;
|
if(web_interface->WebServer.hasArg("path")) {
|
||||||
|
path += web_interface->WebServer.arg("path") ;
|
||||||
|
}
|
||||||
//to have a clean path
|
//to have a clean path
|
||||||
path.trim();
|
path.trim();
|
||||||
path.replace("//","/");
|
path.replace("//","/");
|
||||||
if (path[path.length()-1] !='/')path +="/";
|
if (path[path.length()-1] !='/') {
|
||||||
|
path +="/";
|
||||||
|
}
|
||||||
//check if query need some action
|
//check if query need some action
|
||||||
if(web_interface->WebServer.hasArg("action")) {
|
if(web_interface->WebServer.hasArg("action")) {
|
||||||
//delete a file
|
//delete a file
|
||||||
@ -2758,18 +2767,18 @@ void handleFileList()
|
|||||||
if(!SPIFFS.exists(filename)) {
|
if(!SPIFFS.exists(filename)) {
|
||||||
status = shortname + F(" does not exists!");
|
status = shortname + F(" does not exists!");
|
||||||
} else {
|
} else {
|
||||||
if (SPIFFS.remove(filename))
|
if (SPIFFS.remove(filename)) {
|
||||||
{
|
|
||||||
status = shortname + F(" deleted");
|
status = shortname + F(" deleted");
|
||||||
//what happen if no "/." and no other subfiles ?
|
//what happen if no "/." and no other subfiles ?
|
||||||
FSDIR dir = SPIFFS.openDir(path);
|
FSDIR dir = SPIFFS.openDir(path);
|
||||||
if (!dir.next())
|
if (!dir.next()) {
|
||||||
{ //keep directory alive even empty
|
//keep directory alive even empty
|
||||||
FSFILE r = SPIFFS.open(path+"/.","w");
|
FSFILE r = SPIFFS.open(path+"/.","w");
|
||||||
if (r)r.close();
|
if (r) {
|
||||||
|
r.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
status = F("Cannot deleted ") ;
|
status = F("Cannot deleted ") ;
|
||||||
status+=shortname ;
|
status+=shortname ;
|
||||||
}
|
}
|
||||||
@ -2783,8 +2792,7 @@ void handleFileList()
|
|||||||
filename = path + web_interface->WebServer.arg("filename");
|
filename = path + web_interface->WebServer.arg("filename");
|
||||||
filename += "/.";
|
filename += "/.";
|
||||||
filename.replace("//","/");
|
filename.replace("//","/");
|
||||||
if (filename != "/")
|
if (filename != "/") {
|
||||||
{
|
|
||||||
bool delete_error = false;
|
bool delete_error = false;
|
||||||
FSDIR dir = SPIFFS.openDir(path + shortname);
|
FSDIR dir = SPIFFS.openDir(path + shortname);
|
||||||
{
|
{
|
||||||
@ -2797,7 +2805,7 @@ void handleFileList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!delete_error){
|
if (!delete_error) {
|
||||||
status = shortname ;
|
status = shortname ;
|
||||||
status+=" deleted";
|
status+=" deleted";
|
||||||
}
|
}
|
||||||
@ -2817,8 +2825,7 @@ void handleFileList()
|
|||||||
if (!r) {
|
if (!r) {
|
||||||
status = F("Cannot create ");
|
status = F("Cannot create ");
|
||||||
status += shortname ;
|
status += shortname ;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
r.close();
|
r.close();
|
||||||
status = shortname + F(" created");
|
status = shortname + F(" created");
|
||||||
}
|
}
|
||||||
@ -2844,33 +2851,26 @@ void handleFileList()
|
|||||||
filename = filename.substring(0,filename.indexOf("/"));
|
filename = filename.substring(0,filename.indexOf("/"));
|
||||||
String tag="*";
|
String tag="*";
|
||||||
tag = filename + "*";
|
tag = filename + "*";
|
||||||
if (subdirlist.indexOf(tag)>-1) //already in list
|
if (subdirlist.indexOf(tag)>-1) { //already in list
|
||||||
{
|
|
||||||
addtolist = false; //no need to add
|
addtolist = false; //no need to add
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
size = -1; //it is subfile so display only directory, size will be -1 to describe it is directory
|
size = -1; //it is subfile so display only directory, size will be -1 to describe it is directory
|
||||||
if (subdirlist.length()==0)subdirlist+="*";
|
if (subdirlist.length()==0) {
|
||||||
|
subdirlist+="*";
|
||||||
|
}
|
||||||
subdirlist += filename + "*"; //add to list
|
subdirlist += filename + "*"; //add to list
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
//do not add "." file
|
//do not add "." file
|
||||||
if (filename!=".")
|
if (filename!=".") {
|
||||||
{
|
|
||||||
FSFILE f = dir.openFile("r");
|
FSFILE f = dir.openFile("r");
|
||||||
size = CONFIG::formatBytes(f.size());
|
size = CONFIG::formatBytes(f.size());
|
||||||
f.close();
|
f.close();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
addtolist = false;
|
addtolist = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(addtolist)
|
if(addtolist) {
|
||||||
{
|
|
||||||
if (!firstentry) {
|
if (!firstentry) {
|
||||||
jsonfile+=",";
|
jsonfile+=",";
|
||||||
} else {
|
} else {
|
||||||
@ -2913,11 +2913,15 @@ void handleSDFileList()
|
|||||||
uint32_t totalspace = 0;
|
uint32_t totalspace = 0;
|
||||||
uint32_t usedspace = 0;
|
uint32_t usedspace = 0;
|
||||||
//get current path
|
//get current path
|
||||||
if(web_interface->WebServer.hasArg("path"))path += web_interface->WebServer.arg("path") ;
|
if(web_interface->WebServer.hasArg("path")) {
|
||||||
|
path += web_interface->WebServer.arg("path") ;
|
||||||
|
}
|
||||||
//to have a clean path
|
//to have a clean path
|
||||||
path.trim();
|
path.trim();
|
||||||
path.replace("//","/");
|
path.replace("//","/");
|
||||||
if (path[path.length()-1] !='/')path +="/";
|
if (path[path.length()-1] !='/') {
|
||||||
|
path +="/";
|
||||||
|
}
|
||||||
//check if query need some action
|
//check if query need some action
|
||||||
if(web_interface->WebServer.hasArg("action")) {
|
if(web_interface->WebServer.hasArg("action")) {
|
||||||
LOG("action requested\n")
|
LOG("action requested\n")
|
||||||
@ -2971,11 +2975,10 @@ void handleSDFileList()
|
|||||||
String jsonfile = "{" ;
|
String jsonfile = "{" ;
|
||||||
#ifndef DIRECT_SDCARD_FEATURE
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
//if action is processing do not build list, but no need Serial for Direct SDCard Support
|
//if action is processing do not build list, but no need Serial for Direct SDCard Support
|
||||||
if ((web_interface->blockserial)){
|
if ((web_interface->blockserial)) {
|
||||||
LOG("Wait, blocking\n");
|
LOG("Wait, blocking\n");
|
||||||
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
|
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
jsonfile+="\"files\":[";
|
jsonfile+="\"files\":[";
|
||||||
@ -2992,22 +2995,18 @@ void handleSDFileList()
|
|||||||
sname = web_interface->fileslist.get(i);
|
sname = web_interface->fileslist.get(i);
|
||||||
#if FIRMWARE_TARGET == REPETIER4DV || FIRMWARE_TARGET == REPETIER
|
#if FIRMWARE_TARGET == REPETIER4DV || FIRMWARE_TARGET == REPETIER
|
||||||
//check if directory or file
|
//check if directory or file
|
||||||
if (sname[0] == '/' || sname[sname.length()-1]=='/')
|
if (sname[0] == '/' || sname[sname.length()-1]=='/') {
|
||||||
{
|
|
||||||
jsonfile+=sname;
|
jsonfile+=sname;
|
||||||
jsonfile+="\",\"size\":\"";
|
jsonfile+="\",\"size\":\"";
|
||||||
LOG(String(i+1));
|
LOG(String(i+1));
|
||||||
LOG(sname);
|
LOG(sname);
|
||||||
jsonfile+="-1";
|
jsonfile+="-1";
|
||||||
LOG(" -1");
|
LOG(" -1");
|
||||||
}
|
} else { //it is a file
|
||||||
else //it is a file
|
|
||||||
{
|
|
||||||
//get size position
|
//get size position
|
||||||
int posspace = sname.indexOf(" ");
|
int posspace = sname.indexOf(" ");
|
||||||
String ssize;
|
String ssize;
|
||||||
if (posspace !=-1)
|
if (posspace !=-1) {
|
||||||
{
|
|
||||||
ssize = sname.substring(posspace+1);
|
ssize = sname.substring(posspace+1);
|
||||||
sname = sname.substring(0,posspace);
|
sname = sname.substring(0,posspace);
|
||||||
}
|
}
|
||||||
@ -3025,13 +3024,11 @@ void handleSDFileList()
|
|||||||
jsonfile+="\",\"size\":\"";
|
jsonfile+="\",\"size\":\"";
|
||||||
LOG(String(i+1));
|
LOG(String(i+1));
|
||||||
LOG(sname);
|
LOG(sname);
|
||||||
if (sname[0] == '/' || sname[sname.length()-1]=='/')
|
if (sname[0] == '/' || sname[sname.length()-1]=='/') {
|
||||||
{
|
|
||||||
jsonfile+="-1";
|
jsonfile+="-1";
|
||||||
LOG(" -1");
|
LOG(" -1");
|
||||||
}
|
} else {
|
||||||
else
|
//nothing to add
|
||||||
{//nothing to add
|
|
||||||
jsonfile+="";
|
jsonfile+="";
|
||||||
}
|
}
|
||||||
LOG("\n");
|
LOG("\n");
|
||||||
@ -3085,10 +3082,11 @@ void handle_not_found()
|
|||||||
web_interface->WebServer.streamFile(file, contentType);
|
web_interface->WebServer.streamFile(file, contentType);
|
||||||
file.close();
|
file.close();
|
||||||
return;
|
return;
|
||||||
} else page_not_found = true;
|
} else {
|
||||||
|
page_not_found = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (page_not_found )
|
if (page_not_found ) {
|
||||||
{
|
|
||||||
LOG("Page not found it \n")
|
LOG("Page not found it \n")
|
||||||
if (SPIFFS.exists("/404.tpl")) {
|
if (SPIFFS.exists("/404.tpl")) {
|
||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
@ -3195,8 +3193,11 @@ void handle_login()
|
|||||||
if (msg_alert_error==false) {
|
if (msg_alert_error==false) {
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
auth_ip * current_auth = new auth_ip;
|
auth_ip * current_auth = new auth_ip;
|
||||||
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN))current_auth->level = LEVEL_ADMIN;
|
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) {
|
||||||
else current_auth->level = LEVEL_USER;
|
current_auth->level = LEVEL_ADMIN;
|
||||||
|
} else {
|
||||||
|
current_auth->level = LEVEL_USER;
|
||||||
|
}
|
||||||
current_auth->ip=web_interface->WebServer.client().remoteIP();
|
current_auth->ip=web_interface->WebServer.client().remoteIP();
|
||||||
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
||||||
current_auth->last_time=millis();
|
current_auth->last_time=millis();
|
||||||
@ -3328,11 +3329,12 @@ void handle_web_command()
|
|||||||
}
|
}
|
||||||
//if not is not a valid [ESPXXX] command
|
//if not is not a valid [ESPXXX] command
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
//send command to serial as no need to transfer ESP command
|
//send command to serial as no need to transfer ESP command
|
||||||
//to avoid any pollution if Uploading file to SDCard
|
//to avoid any pollution if Uploading file to SDCard
|
||||||
if ((web_interface->blockserial) == false)Serial.println(scmd);
|
if ((web_interface->blockserial) == false) {
|
||||||
|
Serial.println(scmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3540,8 +3542,7 @@ String WEBINTERFACE_CLASS::getContentType(String filename)
|
|||||||
return "image/gif";
|
return "image/gif";
|
||||||
} else if(filename.endsWith(".jpeg")) {
|
} else if(filename.endsWith(".jpeg")) {
|
||||||
return "image/jpeg";
|
return "image/jpeg";
|
||||||
}
|
} else if(filename.endsWith(".jpg")) {
|
||||||
else if(filename.endsWith(".jpg")) {
|
|
||||||
return "image/jpeg";
|
return "image/jpeg";
|
||||||
} else if(filename.endsWith(".ico")) {
|
} else if(filename.endsWith(".ico")) {
|
||||||
return "image/x-icon";
|
return "image/x-icon";
|
||||||
|
@ -43,8 +43,12 @@ WIFI_CONFIG::WIFI_CONFIG()
|
|||||||
|
|
||||||
int32_t WIFI_CONFIG::getSignal(int32_t RSSI)
|
int32_t WIFI_CONFIG::getSignal(int32_t RSSI)
|
||||||
{
|
{
|
||||||
if (RSSI <= -100) return 0;
|
if (RSSI <= -100) {
|
||||||
if (RSSI >= -50) return 100;
|
return 0;
|
||||||
|
}
|
||||||
|
if (RSSI >= -50) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
return (2* (RSSI+100));
|
return (2* (RSSI+100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +118,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
sleep_mode=bflag;
|
sleep_mode=bflag;
|
||||||
if (force_ap) {
|
if (force_ap) {
|
||||||
bmode = AP_MODE;
|
bmode = AP_MODE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
//AP or client ?
|
//AP or client ?
|
||||||
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) {
|
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) {
|
||||||
LOG("Error read wifi mode\n")
|
LOG("Error read wifi mode\n")
|
||||||
@ -128,8 +131,12 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
//this is AP mode
|
//this is AP mode
|
||||||
if (bmode==AP_MODE) {
|
if (bmode==AP_MODE) {
|
||||||
LOG("Set AP mode\n")
|
LOG("Set AP mode\n")
|
||||||
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH))return false;
|
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Serial.print(FPSTR(M117_));
|
Serial.print(FPSTR(M117_));
|
||||||
Serial.print(F("SSID "));
|
Serial.print(F("SSID "));
|
||||||
Serial.println(sbuf);
|
Serial.println(sbuf);
|
||||||
@ -222,8 +229,12 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG("Set STA mode\n")
|
LOG("Set STA mode\n")
|
||||||
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH))return false;
|
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
|
return false;
|
||||||
|
}
|
||||||
|
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Serial.print(FPSTR(M117_));
|
Serial.print(FPSTR(M117_));
|
||||||
Serial.print(F("SSID "));
|
Serial.print(F("SSID "));
|
||||||
Serial.println(sbuf);
|
Serial.println(sbuf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user