mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-01 09:52:03 +08:00
Apply astyle --style=otbs *.h *.cpp *.ino
This commit is contained in:
parent
fabf6c133f
commit
3ee67c022b
@ -27,9 +27,10 @@ WiFiServer * data_server;
|
|||||||
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool BRIDGE::processFromSerial2TCP(){
|
bool BRIDGE::processFromSerial2TCP()
|
||||||
uint8_t i;
|
{
|
||||||
//check UART for data
|
uint8_t i;
|
||||||
|
//check UART for data
|
||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
size_t len = Serial.available();
|
size_t len = Serial.available();
|
||||||
uint8_t sbuf[len];
|
uint8_t sbuf[len];
|
||||||
@ -46,12 +47,14 @@ 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()) {
|
||||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||||
@ -70,19 +73,19 @@ 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()) {
|
||||||
//get data from the tcp client and push it to the UART
|
//get data from the tcp client and push it to the UART
|
||||||
while(serverClients[i].available()) {
|
while(serverClients[i].available()) {
|
||||||
data = serverClients[i].read();
|
data = serverClients[i].read();
|
||||||
Serial.write(data);
|
Serial.write(data);
|
||||||
COMMAND::read_buffer_tcp(data);
|
COMMAND::read_buffer_tcp(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#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
|
||||||
@ -70,13 +82,14 @@ bool COMMAND::isadmin(String & cmd_params)
|
|||||||
if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) {
|
||||||
LOG("ERROR getting admin\n")
|
LOG("ERROR getting admin\n")
|
||||||
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
||||||
}
|
}
|
||||||
adminpassword = get_param(cmd_params,"pwd=", true);
|
adminpassword = get_param(cmd_params,"pwd=", true);
|
||||||
if (!sadminPassword.equals(adminpassword)) {
|
if (!sadminPassword.equals(adminpassword)) {
|
||||||
LOG("Not allowed \n")
|
LOG("Not allowed \n")
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void COMMAND::execute_command(int cmd,String cmd_params)
|
void COMMAND::execute_command(int cmd,String cmd_params)
|
||||||
@ -85,58 +98,61 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
byte mode = 254;
|
byte mode = 254;
|
||||||
String parameter;
|
String parameter;
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
//STA SSID
|
//STA SSID
|
||||||
//[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
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
|
||||||
} else {
|
|
||||||
Serial.println(OK_CMD_MSG);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
//STA Password
|
//STA Password
|
||||||
//[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
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
|
||||||
} else {
|
|
||||||
Serial.println(OK_CMD_MSG);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
//Hostname
|
//Hostname
|
||||||
//[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
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
#endif
|
//Wifi mode (STA/AP)
|
||||||
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
|
||||||
} else {
|
|
||||||
Serial.println(OK_CMD_MSG);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//Wifi mode (STA/AP)
|
|
||||||
//[ESP103]<mode>[pwd=<admin password>]
|
//[ESP103]<mode>[pwd=<admin password>]
|
||||||
case 103:
|
case 103:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
@ -147,21 +163,20 @@ 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);
|
} else {
|
||||||
} else {
|
Serial.println(OK_CMD_MSG);
|
||||||
Serial.println(OK_CMD_MSG);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//STA IP mode (DHCP/STATIC)
|
//STA IP mode (DHCP/STATIC)
|
||||||
//[ESP104]<mode>[pwd=<admin password>]
|
//[ESP104]<mode>[pwd=<admin password>]
|
||||||
case 104:
|
case 104:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
@ -169,58 +184,59 @@ 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);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//AP SSID
|
||||||
|
//[ESP105]<SSID>[pwd=<admin password>]
|
||||||
|
case 105:
|
||||||
|
parameter = get_param(cmd_params,"", true);
|
||||||
|
if (!CONFIG::isSSIDValid(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_SSID,parameter.c_str())) {
|
||||||
Serial.println(ERROR_CMD_MSG);
|
Serial.println(ERROR_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
Serial.println(OK_CMD_MSG);
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
//AP SSID
|
//AP Password
|
||||||
//[ESP105]<SSID>[pwd=<admin password>]
|
|
||||||
case 105:
|
|
||||||
parameter = get_param(cmd_params,"", true);
|
|
||||||
if (!CONFIG::isSSIDValid(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_SSID,parameter.c_str())) {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
|
||||||
} else {
|
|
||||||
Serial.println(OK_CMD_MSG);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//AP Password
|
|
||||||
//[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
|
||||||
|
#endif
|
||||||
|
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
} else {
|
||||||
|
Serial.println(OK_CMD_MSG);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
|
||||||
} else {
|
|
||||||
Serial.println(OK_CMD_MSG);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
//AP IP mode (DHCP/STATIC)
|
//AP IP mode (DHCP/STATIC)
|
||||||
//[ESP107]<mode>[pwd=<admin password>]
|
//[ESP107]<mode>[pwd=<admin password>]
|
||||||
case 107:
|
case 107:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
@ -228,21 +244,20 @@ 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);
|
} else {
|
||||||
} else {
|
Serial.println(OK_CMD_MSG);
|
||||||
Serial.println(OK_CMD_MSG);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Get current IP
|
//Get current IP
|
||||||
@ -264,9 +279,9 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//[ESP112]<header answer>
|
//[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)) {
|
||||||
shost=wifi_config.get_default_hostname();
|
shost=wifi_config.get_default_hostname();
|
||||||
}
|
}
|
||||||
Serial.print("\n\r");
|
Serial.print("\n\r");
|
||||||
Serial.print(cmd_params);
|
Serial.print(cmd_params);
|
||||||
Serial.println(shost);
|
Serial.println(shost);
|
||||||
@ -275,114 +290,116 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef DIRECT_PIN_FEATURE
|
#ifdef DIRECT_PIN_FEATURE
|
||||||
//Get/Set pin value
|
//Get/Set pin value
|
||||||
//[ESP201]P<pin> V<value>
|
//[ESP201]P<pin> V<value>
|
||||||
case 201: {
|
case 201: {
|
||||||
//check if have pin
|
//check if have pin
|
||||||
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 {
|
||||||
}
|
int pin = parameter.toInt();
|
||||||
else{
|
//check pin is valid and not serial used pins
|
||||||
int pin = parameter.toInt();
|
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) {
|
||||||
//check pin is valid and not serial used pins
|
//check if is set or get
|
||||||
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3)))
|
parameter = get_param(cmd_params,"V", true);
|
||||||
{
|
//it is a get
|
||||||
//check if is set or get
|
if (parameter == "") {
|
||||||
parameter = get_param(cmd_params,"V", true);
|
//GPIO16 is different than
|
||||||
//it is a get
|
if (pin <16) {
|
||||||
if (parameter == "")
|
pinMode(pin, INPUT_PULLUP);
|
||||||
{ //GPIO16 is different than
|
} else {
|
||||||
if (pin <16) pinMode(pin, INPUT_PULLUP);
|
pinMode(pin, INPUT_PULLDOWN_16);
|
||||||
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);
|
||||||
{
|
delay(10);
|
||||||
pinMode(pin, OUTPUT);
|
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
||||||
delay(10);
|
} else {
|
||||||
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
else Serial.println(INCORRECT_CMD_MSG);
|
}
|
||||||
}
|
} else {
|
||||||
}
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
else Serial.println(INCORRECT_CMD_MSG);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Get/Set ESP mode
|
//Get/Set ESP mode
|
||||||
//cmd is RESET, SAFEMODE, CONFIG, RESTART
|
//cmd is RESET, SAFEMODE, CONFIG, RESTART
|
||||||
//[ESP444]<cmd>pwd=<admin password>
|
//[ESP444]<cmd>pwd=<admin password>
|
||||||
case 444:
|
case 444:
|
||||||
parameter = get_param(cmd_params,"", true);
|
parameter = get_param(cmd_params,"", true);
|
||||||
#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
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (parameter=="RESET") {
|
||||||
|
CONFIG::reset_config();
|
||||||
}
|
}
|
||||||
else
|
if (parameter=="SAFEMODE") {
|
||||||
#endif
|
wifi_config.Safe_Setup();
|
||||||
{
|
}
|
||||||
if (parameter=="RESET") {
|
if (parameter=="RESTART") {
|
||||||
CONFIG::reset_config();
|
CONFIG::esp_restart();
|
||||||
}
|
}
|
||||||
if (parameter=="SAFEMODE") {
|
}
|
||||||
wifi_config.Safe_Setup();
|
|
||||||
}
|
|
||||||
if (parameter=="RESTART") {
|
|
||||||
CONFIG::esp_restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (parameter=="CONFIG") {
|
if (parameter=="CONFIG") {
|
||||||
CONFIG::print_config();
|
CONFIG::print_config();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#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 {
|
||||||
|
Serial.println(ERROR_CMD_MSG);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Serial.println(ERROR_CMD_MSG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else 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,20 +407,20 @@ 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);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
currentline="";
|
currentline="";
|
||||||
//read next line if any
|
//read next line if any
|
||||||
currentline = currentfile.readString();
|
currentline = currentfile.readString();
|
||||||
}
|
|
||||||
currentfile.close();
|
|
||||||
}
|
}
|
||||||
break;
|
currentfile.close();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
//get fw version
|
//get fw version
|
||||||
//[ESP800]<header answer>
|
//[ESP800]<header answer>
|
||||||
case 800:
|
case 800:
|
||||||
@ -418,18 +435,18 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
#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();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef INFO_MSG_FEATURE
|
#ifdef INFO_MSG_FEATURE
|
||||||
if (cmd_params=="INFO") {
|
if (cmd_params=="INFO") {
|
||||||
web_interface->info_msg.clear();
|
web_interface->info_msg.clear();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef STATUS_MSG_FEATURE
|
#ifdef STATUS_MSG_FEATURE
|
||||||
if (cmd_params=="STATUS") {
|
if (cmd_params=="STATUS") {
|
||||||
web_interface->status_msg.clear();
|
web_interface->status_msg.clear();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (cmd_params=="ALL") {
|
if (cmd_params=="ALL") {
|
||||||
#ifdef ERROR_MSG_FEATURE
|
#ifdef ERROR_MSG_FEATURE
|
||||||
web_interface->error_msg.clear();
|
web_interface->error_msg.clear();
|
||||||
@ -452,7 +469,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
String buffer2;
|
String buffer2;
|
||||||
//if direct access to SDCard no need to handle the M20 command answer
|
//if direct access to SDCard no need to handle the M20 command answer
|
||||||
#ifndef DIRECT_SDCARD_FEATURE
|
#ifndef DIRECT_SDCARD_FEATURE
|
||||||
static bool bfileslist=false;
|
static bool bfileslist=false;
|
||||||
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) {
|
||||||
@ -604,7 +621,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
#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
|
||||||
@ -613,7 +630,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
//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;
|
||||||
LOG("End list\n");
|
LOG("End list\n");
|
||||||
} else {
|
} else {
|
||||||
//Serial.print(buffer);
|
//Serial.print(buffer);
|
||||||
@ -649,19 +666,23 @@ 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
|
||||||
}
|
}
|
||||||
//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
|
//reset comment flag
|
||||||
iscomment = false;
|
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);
|
||||||
@ -680,18 +701,22 @@ 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
|
||||||
}
|
}
|
||||||
//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
|
//reset comment flag
|
||||||
iscomment = false;
|
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);
|
||||||
|
@ -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);
|
||||||
@ -178,7 +179,7 @@ String CONFIG::formatBytes(size_t bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//helper to convert string to IP
|
//helper to convert string to IP
|
||||||
//do not use IPAddress.fromString() because lack of check point and error result
|
//do not use IPAddress.fromString() because lack of check point and error result
|
||||||
//return number of parts
|
//return number of parts
|
||||||
byte CONFIG::split_ip (const char * ptr,byte * part)
|
byte CONFIG::split_ip (const char * ptr,byte * part)
|
||||||
{
|
{
|
||||||
@ -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,26 +327,25 @@ 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;
|
break;
|
||||||
break;
|
case EP_AP_SSID:
|
||||||
case EP_AP_SSID:
|
case EP_STA_SSID:
|
||||||
case EP_STA_SSID:
|
maxsize = MAX_SSID_LENGTH;
|
||||||
maxsize = MAX_SSID_LENGTH;
|
break;
|
||||||
break;
|
case EP_AP_PASSWORD:
|
||||||
case EP_AP_PASSWORD:
|
case EP_STA_PASSWORD:
|
||||||
case EP_STA_PASSWORD:
|
maxsize = MAX_PASSWORD_LENGTH;
|
||||||
maxsize = MAX_PASSWORD_LENGTH;
|
break;
|
||||||
break;
|
case EP_HOSTNAME:
|
||||||
case EP_HOSTNAME:
|
maxsize = MAX_HOSTNAME_LENGTH;
|
||||||
maxsize = MAX_HOSTNAME_LENGTH;
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
maxsize = EEPROM_SIZE;
|
||||||
maxsize = EEPROM_SIZE;
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) {
|
if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) {
|
||||||
LOG("Error write string\n")
|
LOG("Error write string\n")
|
||||||
@ -430,7 +432,7 @@ bool CONFIG::reset_config()
|
|||||||
if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
|
if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_byte(EP_STA_PHY_MODE,DEFAULT_PHY_MODE)) {
|
if(!CONFIG::write_byte(EP_STA_PHY_MODE,DEFAULT_PHY_MODE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!CONFIG::write_buffer(EP_AP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
|
if(!CONFIG::write_buffer(EP_AP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
|
||||||
@ -542,7 +544,7 @@ void CONFIG::print_config()
|
|||||||
} else {
|
} else {
|
||||||
Serial.println(F("Error reading SSID"));
|
Serial.println(F("Error reading SSID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) {
|
if (CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) {
|
||||||
Serial.print(F("STA IP Mode: "));
|
Serial.print(F("STA IP Mode: "));
|
||||||
if (byte(bbuf)==STATIC_IP_MODE) {
|
if (byte(bbuf)==STATIC_IP_MODE) {
|
||||||
@ -575,9 +577,9 @@ void CONFIG::print_config()
|
|||||||
} else {
|
} else {
|
||||||
Serial.println(F("Error reading IP mode"));
|
Serial.println(F("Error reading IP mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) {
|
if (CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) {
|
||||||
Serial.print(F("STA Phy mode: "));
|
Serial.print(F("STA Phy mode: "));
|
||||||
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
||||||
Serial.println(F("11b"));
|
Serial.println(F("11b"));
|
||||||
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
||||||
@ -590,7 +592,7 @@ void CONFIG::print_config()
|
|||||||
} else {
|
} else {
|
||||||
Serial.println(F("Error reading phy mode"));
|
Serial.println(F("Error reading phy mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
if (CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
Serial.print(F("AP SSID: "));
|
Serial.print(F("AP SSID: "));
|
||||||
Serial.println(sbuf);
|
Serial.println(sbuf);
|
||||||
@ -602,7 +604,7 @@ void CONFIG::print_config()
|
|||||||
Serial.print(F("AP IP Mode: "));
|
Serial.print(F("AP IP Mode: "));
|
||||||
if (byte(bbuf)==STATIC_IP_MODE) {
|
if (byte(bbuf)==STATIC_IP_MODE) {
|
||||||
Serial.println(F("Static"));
|
Serial.println(F("Static"));
|
||||||
if (CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) {
|
if (CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) {
|
||||||
Serial.print(F("IP: "));
|
Serial.print(F("IP: "));
|
||||||
Serial.println(IPAddress(ipbuf).toString());
|
Serial.println(IPAddress(ipbuf).toString());
|
||||||
} else {
|
} else {
|
||||||
@ -633,7 +635,7 @@ void CONFIG::print_config()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) {
|
if (CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) {
|
||||||
Serial.print(F("AP Phy mode: "));
|
Serial.print(F("AP Phy mode: "));
|
||||||
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
if (byte(bbuf)==WIFI_PHY_MODE_11B) {
|
||||||
Serial.println(F("11b"));
|
Serial.println(F("11b"));
|
||||||
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
||||||
@ -729,7 +731,7 @@ void CONFIG::print_config()
|
|||||||
} else {
|
} else {
|
||||||
Serial.println(F("Error reading E feed rate"));
|
Serial.println(F("Error reading E feed rate"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print(F("Free memory: "));
|
Serial.print(F("Free memory: "));
|
||||||
Serial.println(formatBytes(ESP.getFreeHeap()));
|
Serial.println(formatBytes(ESP.getFreeHeap()));
|
||||||
|
|
||||||
@ -787,7 +789,7 @@ void CONFIG::print_config()
|
|||||||
#else
|
#else
|
||||||
Serial.println(F("???"));
|
Serial.println(F("???"));
|
||||||
#endif
|
#endif
|
||||||
Serial.print(F("SD Card support: "));
|
Serial.print(F("SD Card support: "));
|
||||||
#ifdef SDCARD_FEATURE
|
#ifdef SDCARD_FEATURE
|
||||||
Serial.println(F("Enabled"));
|
Serial.println(F("Enabled"));
|
||||||
#else
|
#else
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
|
|
||||||
//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
|
||||||
@ -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
|
||||||
@ -121,9 +121,9 @@
|
|||||||
#define FSFILE File
|
#define FSFILE File
|
||||||
#define FSDIR fs::Dir
|
#define FSDIR fs::Dir
|
||||||
#define FSINFO FSInfo
|
#define FSINFO FSInfo
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TCP_IP_DATA_FEATURE
|
#ifndef TCP_IP_DATA_FEATURE
|
||||||
#undef MAX_SRV_CLIENTS
|
#undef MAX_SRV_CLIENTS
|
||||||
#define MAX_SRV_CLIENTS 0
|
#define MAX_SRV_CLIENTS 0
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,8 +53,8 @@ DNSServer dnsServer;
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
bool breset_config=false;
|
bool breset_config=false;
|
||||||
long baud_rate=0;
|
long baud_rate=0;
|
||||||
web_interface = NULL;
|
web_interface = NULL;
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
data_server = NULL;
|
data_server = NULL;
|
||||||
@ -91,14 +91,14 @@ void setup()
|
|||||||
breset_config=true; //cannot access to config settings=> reset settings
|
breset_config=true; //cannot access to config settings=> reset settings
|
||||||
LOG("Error no EEPROM access\n")
|
LOG("Error no EEPROM access\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
//reset is requested
|
//reset is requested
|
||||||
if(breset_config) {
|
if(breset_config) {
|
||||||
//update EEPROM with default settings
|
//update EEPROM with default settings
|
||||||
Serial.begin(DEFAULT_BAUD_RATE);
|
Serial.begin(DEFAULT_BAUD_RATE);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
Serial.println(F("M117 ESP EEPROM reset"));
|
Serial.println(F("M117 ESP EEPROM reset"));
|
||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
CONFIG::print_config();
|
CONFIG::print_config();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
#endif
|
#endif
|
||||||
@ -109,7 +109,7 @@ void setup()
|
|||||||
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
|
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
|
||||||
CONFIG::esp_restart();
|
CONFIG::esp_restart();
|
||||||
}
|
}
|
||||||
#if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL)
|
#if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL)
|
||||||
LOG("\n");
|
LOG("\n");
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@ -120,16 +120,16 @@ void setup()
|
|||||||
LOG("Serial Set\n");
|
LOG("Serial Set\n");
|
||||||
wifi_config.baud_rate=baud_rate;
|
wifi_config.baud_rate=baud_rate;
|
||||||
//Update is done if any so should be Ok
|
//Update is done if any so should be Ok
|
||||||
SPIFFS.begin();
|
SPIFFS.begin();
|
||||||
|
|
||||||
//setup wifi according settings
|
//setup wifi according settings
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(1000);
|
||||||
//start web interface
|
//start web interface
|
||||||
@ -159,8 +159,8 @@ 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();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -198,10 +198,10 @@ void loop()
|
|||||||
//web requests
|
//web requests
|
||||||
web_interface->WebServer.handleClient();
|
web_interface->WebServer.handleClient();
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
BRIDGE::processFromTCP2Serial();
|
BRIDGE::processFromTCP2Serial();
|
||||||
#endif
|
#endif
|
||||||
BRIDGE::processFromSerial2TCP();
|
BRIDGE::processFromSerial2TCP();
|
||||||
if (web_interface->restartmodule) {
|
if (web_interface->restartmodule) {
|
||||||
CONFIG::esp_restart();
|
CONFIG::esp_restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -35,9 +35,9 @@
|
|||||||
#define MAX_EXTRUDERS 4
|
#define MAX_EXTRUDERS 4
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LEVEL_GUEST = 0,
|
LEVEL_GUEST = 0,
|
||||||
LEVEL_USER = 1,
|
LEVEL_USER = 1,
|
||||||
LEVEL_ADMIN = 2
|
LEVEL_ADMIN = 2
|
||||||
} level_authenticate_type;
|
} level_authenticate_type;
|
||||||
|
|
||||||
struct auth_ip {
|
struct auth_ip {
|
||||||
@ -57,7 +57,7 @@ public:
|
|||||||
FSFILE fsUploadFile;
|
FSFILE fsUploadFile;
|
||||||
#ifdef TEMP_MONITORING_FEATURE
|
#ifdef TEMP_MONITORING_FEATURE
|
||||||
String answer4M105;
|
String answer4M105;
|
||||||
uint32_t last_temp;
|
uint32_t last_temp;
|
||||||
#endif
|
#endif
|
||||||
#ifdef POS_MONITORING_FEATURE
|
#ifdef POS_MONITORING_FEATURE
|
||||||
String answer4M114;
|
String answer4M114;
|
||||||
@ -88,7 +88,7 @@ public:
|
|||||||
void GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
void GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
||||||
void GetPorts(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
void GetPorts(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
||||||
void SetPageProp(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList,
|
void SetPageProp(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList,
|
||||||
const __FlashStringHelper *title, const __FlashStringHelper *filename);
|
const __FlashStringHelper *title, const __FlashStringHelper *filename);
|
||||||
void GetDHCPStatus(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
void GetDHCPStatus(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
||||||
void ProcessAlertError(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, String & smsg);
|
void ProcessAlertError(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, String & smsg);
|
||||||
void ProcessAlertSuccess(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, String & smsg);
|
void ProcessAlertSuccess(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, String & smsg);
|
||||||
@ -98,7 +98,7 @@ public:
|
|||||||
bool AddAuthIP(auth_ip * item);
|
bool AddAuthIP(auth_ip * item);
|
||||||
bool blockserial;
|
bool blockserial;
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
level_authenticate_type ResetAuthIP(IPAddress ip,const char * sessionID);
|
level_authenticate_type ResetAuthIP(IPAddress ip,const char * sessionID);
|
||||||
char * create_session_ID();
|
char * create_session_ID();
|
||||||
#endif
|
#endif
|
||||||
uint8_t _upload_status;
|
uint8_t _upload_status;
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +75,7 @@ const char * WIFI_CONFIG::get_default_hostname()
|
|||||||
return hostname;
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
//safe setup if no connection
|
//safe setup if no connection
|
||||||
void WIFI_CONFIG::Safe_Setup()
|
void WIFI_CONFIG::Safe_Setup()
|
||||||
{
|
{
|
||||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||||
@ -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);
|
||||||
@ -158,7 +165,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
LOG("\nGW value:")
|
LOG("\nGW value:")
|
||||||
//get the gateway
|
//get the gateway
|
||||||
if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
LOG("Error\n")
|
LOG("Error\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
@ -166,7 +173,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
LOG("\nMask value:")
|
LOG("\nMask value:")
|
||||||
//get the mask
|
//get the mask
|
||||||
if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
LOG("Error Mask value\n")
|
LOG("Error Mask value\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
@ -178,7 +185,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
LOG("Disable STA\n")
|
LOG("Disable STA\n")
|
||||||
WiFi.enableSTA(false);
|
WiFi.enableSTA(false);
|
||||||
delay(100);
|
delay(100);
|
||||||
LOG("Set AP\n")
|
LOG("Set AP\n")
|
||||||
//setup Soft AP
|
//setup Soft AP
|
||||||
@ -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);
|
||||||
@ -233,7 +244,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (bflag==STATIC_IP_MODE) {
|
if (bflag==STATIC_IP_MODE) {
|
||||||
byte ip_buf[4];
|
byte ip_buf[4];
|
||||||
//get the IP
|
//get the IP
|
||||||
if (!CONFIG::read_buffer(EP_STA_IP_VALUE,ip_buf , IP_LENGTH)) {
|
if (!CONFIG::read_buffer(EP_STA_IP_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
@ -253,7 +264,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
//apply according active wifi mode
|
//apply according active wifi mode
|
||||||
WiFi.config( local_ip, gateway, subnet);
|
WiFi.config( local_ip, gateway, subnet);
|
||||||
}
|
}
|
||||||
WiFi.enableAP(false);
|
WiFi.enableAP(false);
|
||||||
delay(100);
|
delay(100);
|
||||||
//setup station mode
|
//setup station mode
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user