mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-07-31 06:32:01 +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];
|
||||
#endif
|
||||
|
||||
bool BRIDGE::processFromSerial2TCP(){
|
||||
uint8_t i;
|
||||
//check UART for data
|
||||
bool BRIDGE::processFromSerial2TCP()
|
||||
{
|
||||
uint8_t i;
|
||||
//check UART for data
|
||||
if(Serial.available()) {
|
||||
size_t len = Serial.available();
|
||||
uint8_t sbuf[len];
|
||||
@ -46,12 +47,14 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||
//process data if any
|
||||
COMMAND::read_buffer_serial(sbuf, len);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
void BRIDGE::processFromTCP2Serial(){
|
||||
uint8_t i,data;
|
||||
}
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
void BRIDGE::processFromTCP2Serial()
|
||||
{
|
||||
uint8_t i,data;
|
||||
//check if there are any new clients
|
||||
if (data_server->hasClient()) {
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||
@ -70,19 +73,19 @@ WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||
}
|
||||
//check clients for data
|
||||
//to avoid any pollution if Uploading file to SDCard
|
||||
if ((web_interface->blockserial) == false){
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||
if (serverClients[i] && serverClients[i].connected()) {
|
||||
if(serverClients[i].available()) {
|
||||
//get data from the tcp client and push it to the UART
|
||||
while(serverClients[i].available()) {
|
||||
data = serverClients[i].read();
|
||||
Serial.write(data);
|
||||
COMMAND::read_buffer_tcp(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((web_interface->blockserial) == false) {
|
||||
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||
if (serverClients[i] && serverClients[i].connected()) {
|
||||
if(serverClients[i].available()) {
|
||||
//get data from the tcp client and push it to the UART
|
||||
while(serverClients[i].available()) {
|
||||
data = serverClients[i].read();
|
||||
Serial.write(data);
|
||||
COMMAND::read_buffer_tcp(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@ class BRIDGE
|
||||
{
|
||||
public:
|
||||
static bool processFromSerial2TCP();
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
static void processFromTCP2Serial();
|
||||
#endif
|
||||
};
|
||||
|
@ -44,18 +44,30 @@ String COMMAND::get_param(String & cmd_params, const char * id, bool withspace)
|
||||
int end = -1;
|
||||
parameter = "";
|
||||
//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 start = cmd_params.indexOf(id);
|
||||
else {
|
||||
start = cmd_params.indexOf(id);
|
||||
}
|
||||
//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
|
||||
//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
|
||||
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 (end == -1) end = cmd_params.length();
|
||||
if (end == -1) {
|
||||
end = cmd_params.length();
|
||||
}
|
||||
//extract parameter
|
||||
parameter = cmd_params.substring(start+strlen(id),end);
|
||||
//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)) {
|
||||
LOG("ERROR getting admin\n")
|
||||
sadminPassword=FPSTR(DEFAULT_ADMIN_PWD);
|
||||
}
|
||||
}
|
||||
adminpassword = get_param(cmd_params,"pwd=", true);
|
||||
if (!sadminPassword.equals(adminpassword)) {
|
||||
LOG("Not allowed \n")
|
||||
return false;
|
||||
}
|
||||
else return true;
|
||||
LOG("Not allowed \n")
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
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;
|
||||
String parameter;
|
||||
switch(cmd) {
|
||||
//STA SSID
|
||||
//STA SSID
|
||||
//[ESP100]<SSID>[pwd=<admin password>]
|
||||
case 100:
|
||||
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
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
} else
|
||||
#endif
|
||||
if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
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;
|
||||
//STA Password
|
||||
//STA Password
|
||||
//[ESP101]<Password>[pwd=<admin password>]
|
||||
case 101:
|
||||
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
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
} else
|
||||
#endif
|
||||
if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
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;
|
||||
//Hostname
|
||||
//[ESP102]<hostname>[pwd=<admin password>]
|
||||
case 102:
|
||||
//Hostname
|
||||
//[ESP102]<hostname>[pwd=<admin password>]
|
||||
case 102:
|
||||
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
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
} else
|
||||
#endif
|
||||
if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
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)
|
||||
break;
|
||||
//Wifi mode (STA/AP)
|
||||
//[ESP103]<mode>[pwd=<admin password>]
|
||||
case 103:
|
||||
parameter = get_param(cmd_params,"", true);
|
||||
@ -147,21 +163,20 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
} else {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
if ((mode == CLIENT_MODE) || (mode == AP_MODE)){
|
||||
if ((mode == CLIENT_MODE) || (mode == AP_MODE)) {
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
}
|
||||
break;
|
||||
//STA IP mode (DHCP/STATIC)
|
||||
//STA IP mode (DHCP/STATIC)
|
||||
//[ESP104]<mode>[pwd=<admin password>]
|
||||
case 104:
|
||||
parameter = get_param(cmd_params,"", true);
|
||||
@ -169,58 +184,59 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
mode = STATIC_IP_MODE;
|
||||
} else if (parameter == "DHCP") {
|
||||
mode = DHCP_MODE;
|
||||
} else{
|
||||
} else {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)){
|
||||
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) {
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) {
|
||||
} else
|
||||
#endif
|
||||
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);
|
||||
} 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);
|
||||
} else {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
break;
|
||||
//AP Password
|
||||
//AP Password
|
||||
//[ESP106]<Password>[pwd=<admin password>]
|
||||
case 106:
|
||||
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
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
} else
|
||||
#endif
|
||||
if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
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;
|
||||
//AP IP mode (DHCP/STATIC)
|
||||
//AP IP mode (DHCP/STATIC)
|
||||
//[ESP107]<mode>[pwd=<admin password>]
|
||||
case 107:
|
||||
parameter = get_param(cmd_params,"", true);
|
||||
@ -228,21 +244,20 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
mode = STATIC_IP_MODE;
|
||||
} else if (parameter == "DHCP") {
|
||||
mode = DHCP_MODE;
|
||||
} else{
|
||||
} else {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)){
|
||||
if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) {
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
} else {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
}
|
||||
break;
|
||||
//Get current IP
|
||||
@ -264,9 +279,9 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
//[ESP112]<header answer>
|
||||
case 112: {
|
||||
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();
|
||||
}
|
||||
}
|
||||
Serial.print("\n\r");
|
||||
Serial.print(cmd_params);
|
||||
Serial.println(shost);
|
||||
@ -275,114 +290,116 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
break;
|
||||
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
//Get/Set pin value
|
||||
//[ESP201]P<pin> V<value>
|
||||
//Get/Set pin value
|
||||
//[ESP201]P<pin> V<value>
|
||||
case 201: {
|
||||
//check if have pin
|
||||
//check if have pin
|
||||
parameter = get_param(cmd_params,"P", true);
|
||||
LOG(parameter)
|
||||
LOG("\n")
|
||||
if (parameter == "")
|
||||
{
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
else{
|
||||
int pin = parameter.toInt();
|
||||
//check pin is valid and not serial used pins
|
||||
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3)))
|
||||
{
|
||||
//check if is set or get
|
||||
parameter = get_param(cmd_params,"V", true);
|
||||
//it is a get
|
||||
if (parameter == "")
|
||||
{ //GPIO16 is different than
|
||||
if (pin <16) pinMode(pin, INPUT_PULLUP);
|
||||
else pinMode(pin, INPUT_PULLDOWN_16);
|
||||
delay(10);
|
||||
int value = digitalRead(pin);
|
||||
Serial.println(String(value));
|
||||
}
|
||||
else{
|
||||
//it is a set
|
||||
int value = parameter.toInt();
|
||||
//verify it is a 0 or a 1
|
||||
if ((value == 0) || (value == 1))
|
||||
{
|
||||
pinMode(pin, OUTPUT);
|
||||
delay(10);
|
||||
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
||||
}
|
||||
else Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
}
|
||||
else Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
}
|
||||
break;
|
||||
if (parameter == "") {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
} else {
|
||||
int pin = parameter.toInt();
|
||||
//check pin is valid and not serial used pins
|
||||
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) {
|
||||
//check if is set or get
|
||||
parameter = get_param(cmd_params,"V", true);
|
||||
//it is a get
|
||||
if (parameter == "") {
|
||||
//GPIO16 is different than
|
||||
if (pin <16) {
|
||||
pinMode(pin, INPUT_PULLUP);
|
||||
} else {
|
||||
pinMode(pin, INPUT_PULLDOWN_16);
|
||||
}
|
||||
delay(10);
|
||||
int value = digitalRead(pin);
|
||||
Serial.println(String(value));
|
||||
} else {
|
||||
//it is a set
|
||||
int value = parameter.toInt();
|
||||
//verify it is a 0 or a 1
|
||||
if ((value == 0) || (value == 1)) {
|
||||
pinMode(pin, OUTPUT);
|
||||
delay(10);
|
||||
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
||||
} else {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
//Get/Set ESP mode
|
||||
//cmd is RESET, SAFEMODE, CONFIG, RESTART
|
||||
//[ESP444]<cmd>pwd=<admin password>
|
||||
case 444:
|
||||
parameter = get_param(cmd_params,"", true);
|
||||
parameter = get_param(cmd_params,"", true);
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (!isadmin(cmd_params)) {
|
||||
Serial.println(INCORRECT_CMD_MSG);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (parameter=="RESET") {
|
||||
CONFIG::reset_config();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (parameter=="RESET") {
|
||||
CONFIG::reset_config();
|
||||
}
|
||||
if (parameter=="SAFEMODE") {
|
||||
wifi_config.Safe_Setup();
|
||||
}
|
||||
if (parameter=="RESTART") {
|
||||
CONFIG::esp_restart();
|
||||
}
|
||||
}
|
||||
if (parameter=="SAFEMODE") {
|
||||
wifi_config.Safe_Setup();
|
||||
}
|
||||
if (parameter=="RESTART") {
|
||||
CONFIG::esp_restart();
|
||||
}
|
||||
}
|
||||
if (parameter=="CONFIG") {
|
||||
CONFIG::print_config();
|
||||
}
|
||||
break;
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
//Change / Reset user password
|
||||
//[ESP555]<password>pwd=<admin password>
|
||||
case 555:
|
||||
{
|
||||
//Change / Reset user password
|
||||
//[ESP555]<password>pwd=<admin password>
|
||||
case 555: {
|
||||
if (isadmin(cmd_params)) {
|
||||
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))) {
|
||||
Serial.println(OK_CMD_MSG);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Serial.println(ERROR_CMD_MSG);
|
||||
}
|
||||
} else {
|
||||
if (CONFIG::isLocalPasswordValid(parameter.c_str())){
|
||||
if (CONFIG::isLocalPasswordValid(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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//[ESP700]<filename>
|
||||
case 700: //read local file
|
||||
{//be sure serial is locked
|
||||
if ((web_interface->blockserial)) break;
|
||||
case 700: { //read local file
|
||||
//be sure serial is locked
|
||||
if ((web_interface->blockserial)) {
|
||||
break;
|
||||
}
|
||||
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");
|
||||
if (currentfile) {//if file open success
|
||||
//flush to be sure send buffer is empty
|
||||
@ -390,20 +407,20 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
//read content
|
||||
String currentline = currentfile.readString();
|
||||
//until no line in file
|
||||
while (currentline.length() >0)
|
||||
{ //send line to serial
|
||||
Serial.println(currentline);
|
||||
//flush to be sure send buffer is empty
|
||||
delay(0);
|
||||
Serial.flush();
|
||||
currentline="";
|
||||
//read next line if any
|
||||
currentline = currentfile.readString();
|
||||
}
|
||||
currentfile.close();
|
||||
while (currentline.length() >0) {
|
||||
//send line to serial
|
||||
Serial.println(currentline);
|
||||
//flush to be sure send buffer is empty
|
||||
delay(0);
|
||||
Serial.flush();
|
||||
currentline="";
|
||||
//read next line if any
|
||||
currentline = currentfile.readString();
|
||||
}
|
||||
break;
|
||||
currentfile.close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
//get fw version
|
||||
//[ESP800]<header answer>
|
||||
case 800:
|
||||
@ -418,18 +435,18 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
#ifdef ERROR_MSG_FEATURE
|
||||
if (cmd_params=="ERROR") {
|
||||
web_interface->error_msg.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef INFO_MSG_FEATURE
|
||||
if (cmd_params=="INFO") {
|
||||
web_interface->info_msg.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef STATUS_MSG_FEATURE
|
||||
if (cmd_params=="STATUS") {
|
||||
web_interface->status_msg.clear();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (cmd_params=="ALL") {
|
||||
#ifdef ERROR_MSG_FEATURE
|
||||
web_interface->error_msg.clear();
|
||||
@ -452,7 +469,7 @@ void COMMAND::check_command(String buffer)
|
||||
String buffer2;
|
||||
//if direct access to SDCard no need to handle the M20 command answer
|
||||
#ifndef DIRECT_SDCARD_FEATURE
|
||||
static bool bfileslist=false;
|
||||
static bool bfileslist=false;
|
||||
static uint32_t start_list=0;
|
||||
//if SD list is not on going
|
||||
if (!bfileslist) {
|
||||
@ -604,7 +621,7 @@ void COMMAND::check_command(String buffer)
|
||||
#endif
|
||||
#ifndef DIRECT_SDCARD_FEATURE
|
||||
} 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
|
||||
bfileslist=false;
|
||||
(web_interface->blockserial) = false; //release serial
|
||||
@ -613,7 +630,7 @@ void COMMAND::check_command(String buffer)
|
||||
//check if this is the end
|
||||
if (buffer.indexOf("End file list")>-1) {
|
||||
bfileslist=false;
|
||||
(web_interface->blockserial) = false;
|
||||
(web_interface->blockserial) = false;
|
||||
LOG("End list\n");
|
||||
} else {
|
||||
//Serial.print(buffer);
|
||||
@ -649,19 +666,23 @@ void COMMAND::read_buffer_tcp(uint8_t b)
|
||||
iscomment = false;
|
||||
}
|
||||
//is comment ?
|
||||
if (char(b) == ';') iscomment = true;
|
||||
if (char(b) == ';') {
|
||||
iscomment = true;
|
||||
}
|
||||
//it is a char so add it to buffer
|
||||
if (isPrintable(b)) {
|
||||
previous_was_char=true;
|
||||
//add char if not a comment
|
||||
if (!iscomment)buffer_tcp+=char(b);
|
||||
if (!iscomment) {
|
||||
buffer_tcp+=char(b);
|
||||
}
|
||||
} else {
|
||||
previous_was_char=false; //next call will reset the buffer
|
||||
}
|
||||
//this is not printable but end of command check if need to handle it
|
||||
if (b==13 ||b==10) {
|
||||
//reset comment flag
|
||||
iscomment = false;
|
||||
//reset comment flag
|
||||
iscomment = false;
|
||||
//Minimum is something like M10 so 3 char
|
||||
if (buffer_tcp.length()>3) {
|
||||
check_command(buffer_tcp);
|
||||
@ -680,18 +701,22 @@ void COMMAND::read_buffer_serial(uint8_t b)
|
||||
iscomment = false;
|
||||
}
|
||||
//is comment ?
|
||||
if (char(b) == ';') iscomment = true;
|
||||
if (char(b) == ';') {
|
||||
iscomment = true;
|
||||
}
|
||||
//it is a char so add it to buffer
|
||||
if (isPrintable(b)) {
|
||||
previous_was_char=true;
|
||||
if (!iscomment)buffer_serial+=char(b);
|
||||
if (!iscomment) {
|
||||
buffer_serial+=char(b);
|
||||
}
|
||||
} else {
|
||||
previous_was_char=false; //next call will reset the buffer
|
||||
}
|
||||
//this is not printable but end of command check if need to handle it
|
||||
if (b==13) {
|
||||
//reset comment flag
|
||||
iscomment = false;
|
||||
//reset comment flag
|
||||
iscomment = false;
|
||||
//Minimum is something like M10 so 3 char
|
||||
if (buffer_serial.length()>3) {
|
||||
check_command(buffer_serial);
|
||||
|
@ -25,7 +25,8 @@ extern "C" {
|
||||
}
|
||||
|
||||
|
||||
void CONFIG::esp_restart(){
|
||||
void CONFIG::esp_restart()
|
||||
{
|
||||
LOG("Restarting\n")
|
||||
Serial.flush();
|
||||
delay(500);
|
||||
@ -178,7 +179,7 @@ String CONFIG::formatBytes(size_t bytes)
|
||||
}
|
||||
|
||||
//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
|
||||
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
|
||||
while (i < size_max && b != 0) {
|
||||
b = EEPROM.read(pos+i);
|
||||
if (b!=0)sbuffer+=char(b);
|
||||
if (b!=0) {
|
||||
sbuffer+=char(b);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
EEPROM.end();
|
||||
@ -324,26 +327,25 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
|
||||
int maxsize = EEPROM_SIZE;
|
||||
size_buffer= strlen(byte_buffer);
|
||||
//check if parameters are acceptable
|
||||
switch (pos)
|
||||
{
|
||||
case EP_ADMIN_PWD:
|
||||
case EP_USER_PWD:
|
||||
maxsize = MAX_LOCAL_PASSWORD_LENGTH;
|
||||
break;
|
||||
case EP_AP_SSID:
|
||||
case EP_STA_SSID:
|
||||
maxsize = MAX_SSID_LENGTH;
|
||||
break;
|
||||
case EP_AP_PASSWORD:
|
||||
case EP_STA_PASSWORD:
|
||||
maxsize = MAX_PASSWORD_LENGTH;
|
||||
break;
|
||||
case EP_HOSTNAME:
|
||||
maxsize = MAX_HOSTNAME_LENGTH;
|
||||
break;
|
||||
default:
|
||||
maxsize = EEPROM_SIZE;
|
||||
break;
|
||||
switch (pos) {
|
||||
case EP_ADMIN_PWD:
|
||||
case EP_USER_PWD:
|
||||
maxsize = MAX_LOCAL_PASSWORD_LENGTH;
|
||||
break;
|
||||
case EP_AP_SSID:
|
||||
case EP_STA_SSID:
|
||||
maxsize = MAX_SSID_LENGTH;
|
||||
break;
|
||||
case EP_AP_PASSWORD:
|
||||
case EP_STA_PASSWORD:
|
||||
maxsize = MAX_PASSWORD_LENGTH;
|
||||
break;
|
||||
case EP_HOSTNAME:
|
||||
maxsize = MAX_HOSTNAME_LENGTH;
|
||||
break;
|
||||
default:
|
||||
maxsize = EEPROM_SIZE;
|
||||
break;
|
||||
}
|
||||
if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) {
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
if(!CONFIG::write_buffer(EP_AP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) {
|
||||
@ -542,7 +544,7 @@ void CONFIG::print_config()
|
||||
} else {
|
||||
Serial.println(F("Error reading SSID"));
|
||||
}
|
||||
|
||||
|
||||
if (CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) {
|
||||
Serial.print(F("STA IP Mode: "));
|
||||
if (byte(bbuf)==STATIC_IP_MODE) {
|
||||
@ -575,9 +577,9 @@ void CONFIG::print_config()
|
||||
} else {
|
||||
Serial.println(F("Error reading IP mode"));
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
Serial.println(F("11b"));
|
||||
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
||||
@ -590,7 +592,7 @@ void CONFIG::print_config()
|
||||
} else {
|
||||
Serial.println(F("Error reading phy mode"));
|
||||
}
|
||||
|
||||
|
||||
if (CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||
Serial.print(F("AP SSID: "));
|
||||
Serial.println(sbuf);
|
||||
@ -602,7 +604,7 @@ void CONFIG::print_config()
|
||||
Serial.print(F("AP IP Mode: "));
|
||||
if (byte(bbuf)==STATIC_IP_MODE) {
|
||||
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.println(IPAddress(ipbuf).toString());
|
||||
} else {
|
||||
@ -633,7 +635,7 @@ void CONFIG::print_config()
|
||||
}
|
||||
|
||||
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) {
|
||||
Serial.println(F("11b"));
|
||||
} else if (byte(bbuf)==WIFI_PHY_MODE_11G) {
|
||||
@ -729,7 +731,7 @@ void CONFIG::print_config()
|
||||
} else {
|
||||
Serial.println(F("Error reading E feed rate"));
|
||||
}
|
||||
|
||||
|
||||
Serial.print(F("Free memory: "));
|
||||
Serial.println(formatBytes(ESP.getFreeHeap()));
|
||||
|
||||
@ -787,7 +789,7 @@ void CONFIG::print_config()
|
||||
#else
|
||||
Serial.println(F("???"));
|
||||
#endif
|
||||
Serial.print(F("SD Card support: "));
|
||||
Serial.print(F("SD Card support: "));
|
||||
#ifdef SDCARD_FEATURE
|
||||
Serial.println(F("Enabled"));
|
||||
#else
|
||||
|
@ -88,7 +88,7 @@
|
||||
|
||||
|
||||
//DEBUG Flag do not do this when connected to printer !!!
|
||||
//#define DEBUG_ESP3D
|
||||
//#define DEBUG_ESP3D
|
||||
//#define DEBUG_OUTPUT_SPIFFS
|
||||
//#define DEBUG_OUTPUT_SD
|
||||
//#define DEBUG_OUTPUT_SERIAL
|
||||
@ -97,16 +97,16 @@
|
||||
|
||||
#ifdef DEBUG_ESP3D
|
||||
#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
|
||||
#ifdef SDCARD_FEATURE
|
||||
#ifdef DEBUG_OUTPUT_SD
|
||||
#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
|
||||
#ifdef DEBUG_OUTPUT_SD
|
||||
#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);}
|
||||
#define LOG(string) {Serial.print(string);}
|
||||
#endif
|
||||
#else
|
||||
#define LOG(string) {Serial.print(string);}
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
@ -121,9 +121,9 @@
|
||||
#define FSFILE File
|
||||
#define FSDIR fs::Dir
|
||||
#define FSINFO FSInfo
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef TCP_IP_DATA_FEATURE
|
||||
#ifndef TCP_IP_DATA_FEATURE
|
||||
#undef MAX_SRV_CLIENTS
|
||||
#define MAX_SRV_CLIENTS 0
|
||||
#endif
|
||||
|
@ -53,8 +53,8 @@ DNSServer dnsServer;
|
||||
|
||||
void setup()
|
||||
{
|
||||
bool breset_config=false;
|
||||
long baud_rate=0;
|
||||
bool breset_config=false;
|
||||
long baud_rate=0;
|
||||
web_interface = NULL;
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
data_server = NULL;
|
||||
@ -91,14 +91,14 @@ void setup()
|
||||
breset_config=true; //cannot access to config settings=> reset settings
|
||||
LOG("Error no EEPROM access\n")
|
||||
}
|
||||
|
||||
|
||||
//reset is requested
|
||||
if(breset_config) {
|
||||
//update EEPROM with default settings
|
||||
Serial.begin(DEFAULT_BAUD_RATE);
|
||||
delay(2000);
|
||||
Serial.println(F("M117 ESP EEPROM reset"));
|
||||
#ifdef DEBUG_ESP3D
|
||||
#ifdef DEBUG_ESP3D
|
||||
CONFIG::print_config();
|
||||
delay(1000);
|
||||
#endif
|
||||
@ -109,7 +109,7 @@ void setup()
|
||||
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
|
||||
CONFIG::esp_restart();
|
||||
}
|
||||
#if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL)
|
||||
#if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL)
|
||||
LOG("\n");
|
||||
delay(500);
|
||||
Serial.flush();
|
||||
@ -120,16 +120,16 @@ void setup()
|
||||
LOG("Serial Set\n");
|
||||
wifi_config.baud_rate=baud_rate;
|
||||
//Update is done if any so should be Ok
|
||||
SPIFFS.begin();
|
||||
|
||||
SPIFFS.begin();
|
||||
|
||||
//setup wifi according settings
|
||||
if (!wifi_config.Setup()) {
|
||||
Serial.println(F("M117 Safe mode 1"));
|
||||
//try again in AP mode
|
||||
if (!wifi_config.Setup(true)){
|
||||
if (!wifi_config.Setup(true)) {
|
||||
Serial.println(F("M117 Safe mode 2"));
|
||||
wifi_config.Safe_Setup();
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(1000);
|
||||
//start web interface
|
||||
@ -159,8 +159,8 @@ void setup()
|
||||
wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port);
|
||||
#endif
|
||||
#if defined(SSDP_FEATURE) || defined(NETBIOS_FEATURE)
|
||||
String shost;
|
||||
if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) {
|
||||
String shost;
|
||||
if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) {
|
||||
shost=wifi_config.get_default_hostname();
|
||||
}
|
||||
#endif
|
||||
@ -198,10 +198,10 @@ void loop()
|
||||
//web requests
|
||||
web_interface->WebServer.handleClient();
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
BRIDGE::processFromTCP2Serial();
|
||||
BRIDGE::processFromTCP2Serial();
|
||||
#endif
|
||||
BRIDGE::processFromSerial2TCP();
|
||||
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
|
||||
|
||||
typedef enum {
|
||||
LEVEL_GUEST = 0,
|
||||
LEVEL_USER = 1,
|
||||
LEVEL_ADMIN = 2
|
||||
LEVEL_GUEST = 0,
|
||||
LEVEL_USER = 1,
|
||||
LEVEL_ADMIN = 2
|
||||
} level_authenticate_type;
|
||||
|
||||
struct auth_ip {
|
||||
@ -57,7 +57,7 @@ public:
|
||||
FSFILE fsUploadFile;
|
||||
#ifdef TEMP_MONITORING_FEATURE
|
||||
String answer4M105;
|
||||
uint32_t last_temp;
|
||||
uint32_t last_temp;
|
||||
#endif
|
||||
#ifdef POS_MONITORING_FEATURE
|
||||
String answer4M114;
|
||||
@ -88,7 +88,7 @@ public:
|
||||
void GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList);
|
||||
void GetPorts(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 ProcessAlertError(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 blockserial;
|
||||
#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();
|
||||
#endif
|
||||
uint8_t _upload_status;
|
||||
|
@ -43,8 +43,12 @@ WIFI_CONFIG::WIFI_CONFIG()
|
||||
|
||||
int32_t WIFI_CONFIG::getSignal(int32_t RSSI)
|
||||
{
|
||||
if (RSSI <= -100) return 0;
|
||||
if (RSSI >= -50) return 100;
|
||||
if (RSSI <= -100) {
|
||||
return 0;
|
||||
}
|
||||
if (RSSI >= -50) {
|
||||
return 100;
|
||||
}
|
||||
return (2* (RSSI+100));
|
||||
}
|
||||
|
||||
@ -71,7 +75,7 @@ const char * WIFI_CONFIG::get_default_hostname()
|
||||
return hostname;
|
||||
}
|
||||
|
||||
//safe setup if no connection
|
||||
//safe setup if no connection
|
||||
void WIFI_CONFIG::Safe_Setup()
|
||||
{
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
@ -114,8 +118,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
||||
sleep_mode=bflag;
|
||||
if (force_ap) {
|
||||
bmode = AP_MODE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//AP or client ?
|
||||
if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) {
|
||||
LOG("Error read wifi mode\n")
|
||||
@ -128,8 +131,12 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
||||
//this is AP mode
|
||||
if (bmode==AP_MODE) {
|
||||
LOG("Set AP mode\n")
|
||||
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH))return false;
|
||||
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
|
||||
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
if(!CONFIG::read_string(EP_AP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
Serial.print(FPSTR(M117_));
|
||||
Serial.print(F("SSID "));
|
||||
Serial.println(sbuf);
|
||||
@ -158,7 +165,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
||||
LOG("\nGW value:")
|
||||
//get the gateway
|
||||
if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) {
|
||||
LOG("Error\n")
|
||||
LOG("Error\n")
|
||||
return false;
|
||||
}
|
||||
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:")
|
||||
//get the mask
|
||||
if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,ip_buf , IP_LENGTH)) {
|
||||
LOG("Error Mask value\n")
|
||||
LOG("Error Mask value\n")
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
}
|
||||
LOG("Disable STA\n")
|
||||
WiFi.enableSTA(false);
|
||||
WiFi.enableSTA(false);
|
||||
delay(100);
|
||||
LOG("Set AP\n")
|
||||
//setup Soft AP
|
||||
@ -222,8 +229,12 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
||||
}
|
||||
} else {
|
||||
LOG("Set STA mode\n")
|
||||
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH))return false;
|
||||
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH))return false;
|
||||
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
if(!CONFIG::read_string(EP_STA_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
Serial.print(FPSTR(M117_));
|
||||
Serial.print(F("SSID "));
|
||||
Serial.println(sbuf);
|
||||
@ -233,7 +244,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
||||
if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
|
||||
return false;
|
||||
}
|
||||
if (bflag==STATIC_IP_MODE) {
|
||||
if (bflag==STATIC_IP_MODE) {
|
||||
byte ip_buf[4];
|
||||
//get the IP
|
||||
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
|
||||
WiFi.config( local_ip, gateway, subnet);
|
||||
}
|
||||
WiFi.enableAP(false);
|
||||
WiFi.enableAP(false);
|
||||
delay(100);
|
||||
//setup station mode
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
Loading…
x
Reference in New Issue
Block a user