mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-13 06:19:02 +08:00
Merge from upstream
Add TCP debug Add monitor for command sent Fix random issue when listing SD file as Flag may be incomplete
This commit is contained in:
parent
e33e83771d
commit
5aebdb5a60
@ -27,6 +27,29 @@ WiFiServer * data_server;
|
|||||||
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
|
void BRIDGE::send2TCP(const __FlashStringHelper *data){
|
||||||
|
String tmp = data;
|
||||||
|
BRIDGE::send2TCP(tmp.c_str());
|
||||||
|
}
|
||||||
|
void BRIDGE::send2TCP(String data){
|
||||||
|
BRIDGE::send2TCP(data.c_str());
|
||||||
|
}
|
||||||
|
void BRIDGE::send2TCP(const char * data)
|
||||||
|
{
|
||||||
|
for(uint8_t i = 0; i < MAX_SRV_CLIENTS; i++) {
|
||||||
|
if (serverClients[i] && serverClients[i].connected()) {
|
||||||
|
serverClients[i].write(data, strlen(data));
|
||||||
|
delay(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void debug_esp(String st){
|
||||||
|
BRIDGE::send2TCP(st);
|
||||||
|
}
|
||||||
|
|
||||||
bool BRIDGE::processFromSerial2TCP()
|
bool BRIDGE::processFromSerial2TCP()
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
@ -40,7 +63,7 @@ bool BRIDGE::processFromSerial2TCP()
|
|||||||
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()) {
|
||||||
serverClients[i].write(sbuf, len);
|
serverClients[i].write(sbuf, len);
|
||||||
delay(1);
|
delay(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,11 +18,10 @@
|
|||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifndef BRIDGE_H
|
#ifndef BRIDGE_H
|
||||||
#define BRIDGE_H
|
#define BRIDGE_H
|
||||||
|
#include <WiFiServer.h>
|
||||||
|
#include "config.h"
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
extern WiFiServer * data_server;
|
extern WiFiServer * data_server;
|
||||||
#endif
|
#endif
|
||||||
@ -33,7 +32,9 @@ public:
|
|||||||
static bool processFromSerial2TCP();
|
static bool processFromSerial2TCP();
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
static void processFromTCP2Serial();
|
static void processFromTCP2Serial();
|
||||||
|
static void send2TCP(const __FlashStringHelper *data);
|
||||||
|
static void send2TCP(String data);
|
||||||
|
static void send2TCP(const char * data);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -80,12 +80,12 @@ bool COMMAND::isadmin(String & cmd_params)
|
|||||||
String adminpassword;
|
String adminpassword;
|
||||||
String sadminPassword;
|
String sadminPassword;
|
||||||
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\r\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\r\n")
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
@ -97,6 +97,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
//manage parameters
|
//manage parameters
|
||||||
byte mode = 254;
|
byte mode = 254;
|
||||||
String parameter;
|
String parameter;
|
||||||
|
LOG("Execute Command\r\n")
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
//STA SSID
|
//STA SSID
|
||||||
//[ESP100]<SSID>[pwd=<admin password>]
|
//[ESP100]<SSID>[pwd=<admin password>]
|
||||||
@ -273,6 +274,9 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
Serial.print(cmd_params);
|
Serial.print(cmd_params);
|
||||||
Serial.println(currentIP);
|
Serial.println(currentIP);
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
|
LOG(cmd_params)
|
||||||
|
LOG(currentIP)
|
||||||
|
LOG("\r\n")
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Get hostname
|
//Get hostname
|
||||||
@ -286,6 +290,9 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
Serial.print(cmd_params);
|
Serial.print(cmd_params);
|
||||||
Serial.println(shost);
|
Serial.println(shost);
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
|
LOG(cmd_params)
|
||||||
|
LOG(shost)
|
||||||
|
LOG("\r\n")
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -297,7 +304,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
parameter = get_param(cmd_params,"P", false);
|
parameter = get_param(cmd_params,"P", false);
|
||||||
LOG("Pin:")
|
LOG("Pin:")
|
||||||
LOG(parameter)
|
LOG(parameter)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
if (parameter == "") {
|
if (parameter == "") {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
} else {
|
} else {
|
||||||
@ -308,21 +315,26 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
parameter = get_param(cmd_params,"V", false);
|
parameter = get_param(cmd_params,"V", false);
|
||||||
//it is a get
|
//it is a get
|
||||||
if (parameter == "") {
|
if (parameter == "") {
|
||||||
parameter = get_param(cmd_params,"PULLUP=", false);
|
//this is to not set pin mode
|
||||||
if (parameter == "YES"){
|
parameter = get_param(cmd_params,"RAW=", false);
|
||||||
//GPIO16 is different than others
|
if (parameter !="YES")
|
||||||
if (pin <16) {
|
{
|
||||||
LOG("Set as input pull up\n")
|
parameter = get_param(cmd_params,"PULLUP=", false);
|
||||||
pinMode(pin, INPUT_PULLUP);
|
if (parameter == "YES"){
|
||||||
} else {
|
//GPIO16 is different than others
|
||||||
LOG("Set as input pull down 16\n")
|
if (pin <16) {
|
||||||
pinMode(pin, INPUT_PULLDOWN_16);
|
LOG("Set as input pull up\r\n")
|
||||||
|
pinMode(pin, INPUT_PULLUP);
|
||||||
|
} else {
|
||||||
|
LOG("Set as input pull down 16\r\n")
|
||||||
|
pinMode(pin, INPUT_PULLDOWN_16);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
LOG("Set as input\r\n")
|
||||||
|
pinMode(pin, INPUT);
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
LOG("Set as input\n")
|
|
||||||
pinMode(pin, INPUT);
|
|
||||||
}
|
|
||||||
delay(100);
|
|
||||||
int value = digitalRead(pin);
|
int value = digitalRead(pin);
|
||||||
LOG("Read:");
|
LOG("Read:");
|
||||||
Serial.println(String(value));
|
Serial.println(String(value));
|
||||||
@ -335,7 +347,7 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
delay(10);
|
delay(10);
|
||||||
LOG("Set:")
|
LOG("Set:")
|
||||||
LOG(String((value == 0)?LOW:HIGH))
|
LOG(String((value == 0)?LOW:HIGH))
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
digitalWrite(pin, (value == 0)?LOW:HIGH);
|
||||||
} else {
|
} else {
|
||||||
Serial.println(INCORRECT_CMD_MSG);
|
Serial.println(INCORRECT_CMD_MSG);
|
||||||
@ -477,9 +489,12 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void COMMAND::check_command(String buffer)
|
void COMMAND::check_command(String buffer, bool handlelockserial)
|
||||||
{
|
{
|
||||||
String buffer2;
|
String buffer2;
|
||||||
|
LOG("Check Command:")
|
||||||
|
LOG(buffer)
|
||||||
|
LOG("\r\n")
|
||||||
//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;
|
||||||
@ -487,9 +502,11 @@ void COMMAND::check_command(String buffer)
|
|||||||
//if SD list is not on going
|
//if SD list is not on going
|
||||||
if (!bfileslist) {
|
if (!bfileslist) {
|
||||||
//check if command is a start of SD File list
|
//check if command is a start of SD File list
|
||||||
int filesstart = buffer.indexOf("Begin file list");
|
LOG("No File list ongoing\r\n")
|
||||||
|
int filesstart = buffer.indexOf("egin file list");
|
||||||
//yes it is file list starting to be displayed
|
//yes it is file list starting to be displayed
|
||||||
if (filesstart>-1) {
|
if (filesstart>-1) {
|
||||||
|
LOG("Found start File list\r\n")
|
||||||
//init time out
|
//init time out
|
||||||
start_list = millis();
|
start_list = millis();
|
||||||
//set file list started
|
//set file list started
|
||||||
@ -497,7 +514,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
//clear current list
|
//clear current list
|
||||||
web_interface->fileslist.clear();
|
web_interface->fileslist.clear();
|
||||||
//block any new output to serial from ESP to avoid pollution
|
//block any new output to serial from ESP to avoid pollution
|
||||||
(web_interface->blockserial) = true;
|
if (handlelockserial)(web_interface->blockserial) = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -634,17 +651,19 @@ 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
|
||||||
|
LOG("File list is ongoing\r\n")
|
||||||
//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
|
if(handlelockserial)(web_interface->blockserial) = false; //release serial
|
||||||
LOG("Time out\n");
|
LOG("Time out\r\n");
|
||||||
} else {
|
} else {
|
||||||
//check if this is the end
|
//check if this is the end
|
||||||
if (buffer.indexOf("End file list")>-1) {
|
if (buffer.indexOf("nd file list")>-1) {
|
||||||
|
LOG("End File list detected\r\n")
|
||||||
bfileslist=false;
|
bfileslist=false;
|
||||||
(web_interface->blockserial) = false;
|
if(handlelockserial)(web_interface->blockserial) = false;
|
||||||
LOG("End list\n");
|
LOG("End list\r\n");
|
||||||
} else {
|
} else {
|
||||||
//Serial.print(buffer);
|
//Serial.print(buffer);
|
||||||
//add list to buffer
|
//add list to buffer
|
||||||
@ -652,7 +671,7 @@ void COMMAND::check_command(String buffer)
|
|||||||
LOG(String(web_interface->fileslist.size()));
|
LOG(String(web_interface->fileslist.size()));
|
||||||
LOG(":");
|
LOG(":");
|
||||||
LOG(buffer);
|
LOG(buffer);
|
||||||
LOG('\n');
|
LOG("\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
static void read_buffer_serial(uint8_t *b, size_t len);
|
static void read_buffer_serial(uint8_t *b, size_t len);
|
||||||
static void read_buffer_serial(uint8_t b);
|
static void read_buffer_serial(uint8_t b);
|
||||||
static void read_buffer_tcp(uint8_t b);
|
static void read_buffer_tcp(uint8_t b);
|
||||||
static void check_command(String buffer);
|
static void check_command(String buffer,bool handlelockserial = true);
|
||||||
static void execute_command(int cmd,String cmd_params);
|
static void execute_command(int cmd,String cmd_params);
|
||||||
static String get_param(String & cmd_params, const char * id, bool withspace = false);
|
static String get_param(String & cmd_params, const char * id, bool withspace = false);
|
||||||
static bool isadmin(String & cmd_params);
|
static bool isadmin(String & cmd_params);
|
||||||
|
@ -27,7 +27,7 @@ extern "C" {
|
|||||||
|
|
||||||
void CONFIG::esp_restart()
|
void CONFIG::esp_restart()
|
||||||
{
|
{
|
||||||
LOG("Restarting\n")
|
LOG("Restarting\r\n")
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.swap();
|
Serial.swap();
|
||||||
@ -233,7 +233,7 @@ bool CONFIG::read_string(int pos, char byte_buffer[], int size_max)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL) {
|
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL) {
|
||||||
LOG("Error read string\n")
|
LOG("Error read string\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -260,7 +260,7 @@ bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE ) {
|
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE ) {
|
||||||
LOG("Error read string\n")
|
LOG("Error read string\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
byte b = 13; // non zero for the while loop below
|
byte b = 13; // non zero for the while loop below
|
||||||
@ -286,7 +286,7 @@ bool CONFIG::read_buffer(int pos, byte byte_buffer[], int size_buffer)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
||||||
LOG("Error read buffer\n")
|
LOG("Error read buffer\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int i=0;
|
int i=0;
|
||||||
@ -305,7 +305,7 @@ bool CONFIG::read_byte(int pos, byte * value)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (pos+1 > EEPROM_SIZE) {
|
if (pos+1 > EEPROM_SIZE) {
|
||||||
LOG("Error read byte\n")
|
LOG("Error read byte\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -348,7 +348,7 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
|
|||||||
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\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//copy the value(s)
|
//copy the value(s)
|
||||||
@ -369,7 +369,7 @@ bool CONFIG::write_buffer(int pos, const byte * byte_buffer, int size_buffer)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) {
|
||||||
LOG("Error write buffer\n")
|
LOG("Error write buffer\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -387,7 +387,7 @@ bool CONFIG::write_byte(int pos, const byte value)
|
|||||||
{
|
{
|
||||||
//check if parameters are acceptable
|
//check if parameters are acceptable
|
||||||
if (pos+1 > EEPROM_SIZE) {
|
if (pos+1 > EEPROM_SIZE) {
|
||||||
LOG("Error write byte\n")
|
LOG("Error write byte\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
@ -806,5 +806,8 @@ void CONFIG::print_config()
|
|||||||
#ifdef DEBUG_OUTPUT_SERIAL
|
#ifdef DEBUG_OUTPUT_SERIAL
|
||||||
Serial.println(F("serial"));
|
Serial.println(F("serial"));
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DEBUG_OUTPUT_TCP
|
||||||
|
Serial.println(F("TCP"));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#define SMOOTHIEWARE 4
|
#define SMOOTHIEWARE 4
|
||||||
|
|
||||||
//FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware)
|
//FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware)
|
||||||
#define FIRMWARE_TARGET SMOOTHIEWARE
|
#define FIRMWARE_TARGET REPETIER
|
||||||
|
|
||||||
//number of clients allowed to use data port at once
|
//number of clients allowed to use data port at once
|
||||||
#define MAX_SRV_CLIENTS 1
|
#define MAX_SRV_CLIENTS 1
|
||||||
@ -58,7 +58,7 @@
|
|||||||
#define TCP_IP_DATA_FEATURE
|
#define TCP_IP_DATA_FEATURE
|
||||||
|
|
||||||
//RECOVERY_FEATURE: allow to use GPIO2 pin as hardware reset for EEPROM, add 8s to boot time to let user to jump GPIO2 to GND
|
//RECOVERY_FEATURE: allow to use GPIO2 pin as hardware reset for EEPROM, add 8s to boot time to let user to jump GPIO2 to GND
|
||||||
#define RECOVERY_FEATURE
|
//#define RECOVERY_FEATURE
|
||||||
|
|
||||||
#ifdef RECOVERY_FEATURE
|
#ifdef RECOVERY_FEATURE
|
||||||
//pin used to reset setting
|
//pin used to reset setting
|
||||||
@ -92,22 +92,28 @@
|
|||||||
//#define DEBUG_OUTPUT_SPIFFS
|
//#define DEBUG_OUTPUT_SPIFFS
|
||||||
//#define DEBUG_OUTPUT_SD
|
//#define DEBUG_OUTPUT_SD
|
||||||
//#define DEBUG_OUTPUT_SERIAL
|
//#define DEBUG_OUTPUT_SERIAL
|
||||||
|
//#define DEBUG_OUTPUT_TCP
|
||||||
|
|
||||||
#include <FS.h>
|
//store performance result in storestring variable : info_msg / status_msg
|
||||||
|
//#define DEBUG_PERFORMANCE
|
||||||
|
#define DEBUG_PERF_VARIABLE (web_interface->info_msg)
|
||||||
|
|
||||||
#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();}
|
/*#ifdef SDCARD_FEATURE
|
||||||
#else
|
#ifndef FS_NO_GLOBALS
|
||||||
#ifdef SDCARD_FEATURE
|
#define FS_NO_GLOBALS
|
||||||
#ifdef DEBUG_OUTPUT_SD
|
#endif
|
||||||
#define LOG(string) {if(CONFIG::hasSD()){LOCKSD() File logfile = SD.open("/log.txt", "a+");logfile.print(string);logfile.close();RELEASESD()}}
|
#endif
|
||||||
#else
|
#include <FS.h>*/
|
||||||
#define LOG(string) {Serial.print(string);}
|
#define LOG(string) {FSFILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#ifdef DEBUG_OUTPUT_SERIAL
|
||||||
#define LOG(string) {Serial.print(string);}
|
#define LOG(string) {Serial.print(string);}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DEBUG_OUTPUT_TCP
|
||||||
|
#include "bridge.h"
|
||||||
|
#define LOG(string) {BRIDGE::send2TCP(string);}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define LOG(string) {}
|
#define LOG(string) {}
|
||||||
@ -137,7 +143,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
//version and sources location
|
//version and sources location
|
||||||
#define FW_VERSION "0.8.50"
|
#define FW_VERSION "0.9.70"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ $INCLUDE[css2.inc]$
|
|||||||
<table width="100%"><tr>
|
<table width="100%"><tr>
|
||||||
<td width="100%"><input class="form-control" id="cmd" type="text" style="width: 100%;"></td>
|
<td width="100%"><input class="form-control" id="cmd" type="text" style="width: 100%;"></td>
|
||||||
<td width="auto"><input type="button" class="btn btn-primary" value="Send" onclick="Sendcustomcommand();"></td></tr></table>
|
<td width="auto"><input type="button" class="btn btn-primary" value="Send" onclick="Sendcustomcommand();"></td></tr></table>
|
||||||
|
<textarea style="overflow: scroll;width: 100%" rows="10" id="logwindow" readonly></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -383,9 +384,19 @@ function expand_collapse(flag, targetpin,targetdiv){
|
|||||||
var XYfeedrate=$XY_FEEDRATE$;
|
var XYfeedrate=$XY_FEEDRATE$;
|
||||||
var Zfeedrate=$Z_FEEDRATE$;
|
var Zfeedrate=$Z_FEEDRATE$;
|
||||||
var Efeedrate=$E_FEEDRATE$;
|
var Efeedrate=$E_FEEDRATE$;
|
||||||
function Sendcommand(commandtxt){
|
|
||||||
|
function Sendcommand(commandtxt, showresult=false){
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
var url = "http://$WEB_ADDRESS$/CMD?COM="+encodeURIComponent(commandtxt);;
|
var url = "/command?plain="+encodeURIComponent(commandtxt);;
|
||||||
|
if (showresult){
|
||||||
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
if (xmlhttp.readyState == 4 && xmlhttp.status === 200) {
|
||||||
|
var textarea = document.getElementById("logwindow");
|
||||||
|
textarea.innerHTML = textarea.innerHTML + xmlhttp.responseText;
|
||||||
|
textarea.scrollTop = textarea.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
xmlhttp.open("GET", url, true);
|
xmlhttp.open("GET", url, true);
|
||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}
|
}
|
||||||
@ -407,7 +418,7 @@ Sendcommand(cmd + document.getElementById("numberinput"+item).value);
|
|||||||
}
|
}
|
||||||
function Sendcustomcommand(){
|
function Sendcustomcommand(){
|
||||||
var cmd = document.getElementById("cmd").value;
|
var cmd = document.getElementById("cmd").value;
|
||||||
if (cmd.trim().length > 0) Sendcommand(cmd);
|
if (cmd.trim().length > 0) Sendcommand(cmd,true);
|
||||||
document.getElementById("cmd").value="";
|
document.getElementById("cmd").value="";
|
||||||
}
|
}
|
||||||
function OnclickEmergency(){
|
function OnclickEmergency(){
|
||||||
@ -847,11 +858,5 @@ Sendcommand("M23 " + currentpath + filename);
|
|||||||
delay(100);
|
delay(100);
|
||||||
Sendcommand("M24");}
|
Sendcommand("M24");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
$INCLUDE[footer.inc]$
|
$INCLUDE[footer.inc]$
|
||||||
|
@ -63,7 +63,7 @@ void setup()
|
|||||||
#ifdef DEBUG_ESP3D
|
#ifdef DEBUG_ESP3D
|
||||||
Serial.begin(DEFAULT_BAUD_RATE);
|
Serial.begin(DEFAULT_BAUD_RATE);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
LOG("\nDebug Serial set\n")
|
LOG("\r\nDebug Serial set\r\n")
|
||||||
#endif
|
#endif
|
||||||
//WiFi.disconnect();
|
//WiFi.disconnect();
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
@ -79,17 +79,17 @@ void setup()
|
|||||||
if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port) , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port) , INTEGER_LENGTH)) {
|
if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port) , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port) , INTEGER_LENGTH)) {
|
||||||
//check if baud value is one of allowed ones
|
//check if baud value is one of allowed ones
|
||||||
if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) {
|
if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) {
|
||||||
LOG("Error for EEPROM baud rate\n")
|
LOG("Error for EEPROM baud rate\r\n")
|
||||||
breset_config=true; //baud rate is incorrect =>reset settings
|
breset_config=true; //baud rate is incorrect =>reset settings
|
||||||
}
|
}
|
||||||
if (wifi_config.iweb_port<1 ||wifi_config.iweb_port>65001 || wifi_config.idata_port <1 || wifi_config.idata_port >65001) {
|
if (wifi_config.iweb_port<1 ||wifi_config.iweb_port>65001 || wifi_config.idata_port <1 || wifi_config.idata_port >65001) {
|
||||||
breset_config=true; //out of range =>reset settings
|
breset_config=true; //out of range =>reset settings
|
||||||
LOG("Error for EEPROM port values\n")
|
LOG("Error for EEPROM port values\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
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\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
//reset is requested
|
//reset is requested
|
||||||
@ -110,14 +110,14 @@ void setup()
|
|||||||
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("\r\n");
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
#endif
|
#endif
|
||||||
//setup serial
|
//setup serial
|
||||||
Serial.begin(baud_rate);
|
Serial.begin(baud_rate);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
LOG("Serial Set\n");
|
LOG("Serial Set\r\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();
|
||||||
@ -183,7 +183,7 @@ void setup()
|
|||||||
#ifdef NETBIOS_FEATURE
|
#ifdef NETBIOS_FEATURE
|
||||||
NBNS.begin(shost.c_str());
|
NBNS.begin(shost.c_str());
|
||||||
#endif
|
#endif
|
||||||
LOG("Setup Done\n");
|
LOG("Setup Done\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,8 +213,10 @@ const char KEY_IS_DEFAULT_MODE [] PROGMEM = "$IS_DEFAULT_MODE$";
|
|||||||
|
|
||||||
bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList )
|
bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList )
|
||||||
{
|
{
|
||||||
|
LOG("process template\r\n")
|
||||||
if(KeysList.size() != ValuesList.size()) { //Sanity check
|
if(KeysList.size() != ValuesList.size()) { //Sanity check
|
||||||
Serial.print("Error");
|
Serial.print("M117 Error");
|
||||||
|
LOG("Error\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,9 +348,9 @@ bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CL
|
|||||||
//send header with calculated size
|
//send header with calculated size
|
||||||
header_sent=true;
|
header_sent=true;
|
||||||
web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
web_interface->WebServer.send(200);
|
|
||||||
web_interface->WebServer.sendHeader("Content-Type","text/html");
|
web_interface->WebServer.sendHeader("Content-Type","text/html");
|
||||||
web_interface->WebServer.sendHeader("Cache-Control","no-cache");
|
web_interface->WebServer.sendHeader("Cache-Control","no-cache");
|
||||||
|
web_interface->WebServer.send(200);
|
||||||
}
|
}
|
||||||
//send data
|
//send data
|
||||||
web_interface->WebServer.sendContent(buffer2send);
|
web_interface->WebServer.sendContent(buffer2send);
|
||||||
@ -359,7 +361,7 @@ bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CL
|
|||||||
//reset line
|
//reset line
|
||||||
sLine="";
|
sLine="";
|
||||||
//add a delay for safety for WDT
|
//add a delay for safety for WDT
|
||||||
delay(1);
|
delay(0);
|
||||||
}
|
}
|
||||||
} else { //EOF is reached
|
} else { //EOF is reached
|
||||||
//close current file
|
//close current file
|
||||||
@ -390,6 +392,7 @@ bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CL
|
|||||||
}
|
}
|
||||||
//close line
|
//close line
|
||||||
web_interface->WebServer.sendContent("");
|
web_interface->WebServer.sendContent("");
|
||||||
|
LOG("Process template done\r\n")
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,7 +608,7 @@ void handle_web_interface_home()
|
|||||||
struct softap_config apconfig;
|
struct softap_config apconfig;
|
||||||
struct ip_info info;
|
struct ip_info info;
|
||||||
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
||||||
|
LOG("request /HOME\r\n")
|
||||||
//login
|
//login
|
||||||
web_interface->GeLogin(KeysList, ValuesList,web_interface->is_authenticated());
|
web_interface->GeLogin(KeysList, ValuesList,web_interface->is_authenticated());
|
||||||
|
|
||||||
@ -917,6 +920,7 @@ void handle_web_interface_home()
|
|||||||
//need to clean to speed up memory recovery
|
//need to clean to speed up memory recovery
|
||||||
KeysList.clear();
|
KeysList.clear();
|
||||||
ValuesList.clear();
|
ValuesList.clear();
|
||||||
|
LOG("request /HOME done\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_web_interface_configSys()
|
void handle_web_interface_configSys()
|
||||||
@ -1312,10 +1316,10 @@ void handle_web_interface_configAP()
|
|||||||
//Default mode ?
|
//Default mode ?
|
||||||
if (web_interface->WebServer.hasArg("DEFAULT_MODE") ) {
|
if (web_interface->WebServer.hasArg("DEFAULT_MODE") ) {
|
||||||
default_mode=AP_MODE;
|
default_mode=AP_MODE;
|
||||||
LOG("Set AP Mode\n")
|
LOG("Set AP Mode\r\n")
|
||||||
} else {
|
} else {
|
||||||
default_mode=CLIENT_MODE;
|
default_mode=CLIENT_MODE;
|
||||||
LOG("Set Station mode\n")
|
LOG("Set Station mode\r\n")
|
||||||
}
|
}
|
||||||
//phy mode
|
//phy mode
|
||||||
phy_mode_buf = byte(web_interface->WebServer.arg("NETWORK").toInt());
|
phy_mode_buf = byte(web_interface->WebServer.arg("NETWORK").toInt());
|
||||||
@ -1345,10 +1349,10 @@ void handle_web_interface_configAP()
|
|||||||
//Static IP ?
|
//Static IP ?
|
||||||
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
||||||
static_ip_buf=STATIC_IP_MODE;
|
static_ip_buf=STATIC_IP_MODE;
|
||||||
LOG("Set Static\n")
|
LOG("Set Static\r\n")
|
||||||
} else {
|
} else {
|
||||||
static_ip_buf=DHCP_MODE;
|
static_ip_buf=DHCP_MODE;
|
||||||
LOG("Set DHCP\n")
|
LOG("Set DHCP\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
//IP
|
//IP
|
||||||
@ -1686,10 +1690,10 @@ void handle_web_interface_configSTA()
|
|||||||
//Default mode ?
|
//Default mode ?
|
||||||
if (web_interface->WebServer.hasArg("DEFAULT_MODE") ) {
|
if (web_interface->WebServer.hasArg("DEFAULT_MODE") ) {
|
||||||
default_mode=CLIENT_MODE;
|
default_mode=CLIENT_MODE;
|
||||||
LOG("Set STA mode\n")
|
LOG("Set STA mode\r\n")
|
||||||
} else {
|
} else {
|
||||||
default_mode=AP_MODE;
|
default_mode=AP_MODE;
|
||||||
LOG("Set AP mode\n")
|
LOG("Set AP mode\r\n")
|
||||||
}
|
}
|
||||||
//Static IP ?
|
//Static IP ?
|
||||||
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
if (web_interface->WebServer.hasArg("STATIC_IP") ) {
|
||||||
@ -2384,7 +2388,7 @@ void SPIFFSFileupload()
|
|||||||
|
|
||||||
#define NB_RETRY 5
|
#define NB_RETRY 5
|
||||||
#define MAX_RESEND_BUFFER 128
|
#define MAX_RESEND_BUFFER 128
|
||||||
|
//SD file upload by serial
|
||||||
void SDFileupload()
|
void SDFileupload()
|
||||||
{
|
{
|
||||||
static char buffer_line[MAX_RESEND_BUFFER]; //if need to resend
|
static char buffer_line[MAX_RESEND_BUFFER]; //if need to resend
|
||||||
@ -2397,9 +2401,14 @@ void SDFileupload()
|
|||||||
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\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_PERFORMANCE
|
||||||
|
static uint32_t startupload;
|
||||||
|
static uint32_t write_time;
|
||||||
|
static size_t filesize;
|
||||||
|
#endif
|
||||||
//retrieve current file id
|
//retrieve current file id
|
||||||
HTTPUpload& upload = (web_interface->WebServer).upload();
|
HTTPUpload& upload = (web_interface->WebServer).upload();
|
||||||
//Upload start
|
//Upload start
|
||||||
@ -2414,8 +2423,13 @@ void SDFileupload()
|
|||||||
previous = 0;
|
previous = 0;
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
Serial.println("M117 Uploading...");
|
Serial.println("M117 Uploading...");
|
||||||
|
#ifdef DEBUG_PERFORMANCE
|
||||||
|
startupload = millis();
|
||||||
|
write_time = 0;
|
||||||
|
filesize = 0;
|
||||||
|
#endif
|
||||||
LOG(String(upload.filename));
|
LOG(String(upload.filename));
|
||||||
LOG("\n");
|
LOG("\r\n");
|
||||||
//command to pritnter to start print
|
//command to pritnter to start print
|
||||||
String filename = "M28 " + upload.filename;
|
String filename = "M28 " + upload.filename;
|
||||||
Serial.println(filename);
|
Serial.println(filename);
|
||||||
@ -2447,6 +2461,10 @@ void SDFileupload()
|
|||||||
//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;
|
||||||
|
#ifdef DEBUG_PERFORMANCE
|
||||||
|
filesize+=upload.currentSize;
|
||||||
|
uint32_t startwrite = millis();
|
||||||
|
#endif
|
||||||
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
|
||||||
@ -2494,7 +2512,7 @@ void SDFileupload()
|
|||||||
response = (const char*)sbuf;
|
response = (const char*)sbuf;
|
||||||
LOG("Retry:");
|
LOG("Retry:");
|
||||||
LOG(String(retry));
|
LOG(String(retry));
|
||||||
LOG("\n");
|
LOG("\r\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)) {
|
||||||
@ -2527,7 +2545,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\r\n");
|
||||||
LOG(response);
|
LOG(response);
|
||||||
com_error = true;
|
com_error = true;
|
||||||
}
|
}
|
||||||
@ -2554,11 +2572,14 @@ void SDFileupload()
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else { //raise error
|
} else { //raise error
|
||||||
LOG("\nlong line detected\n");
|
LOG("\r\nlong line detected\r\n");
|
||||||
LOG(buffer_line);
|
LOG(buffer_line);
|
||||||
com_error = true;
|
com_error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_PERFORMANCE
|
||||||
|
write_time += (millis()-startwrite);
|
||||||
|
#endif
|
||||||
//Upload end
|
//Upload end
|
||||||
//**************
|
//**************
|
||||||
} else if(upload.status == UPLOAD_FILE_END) {
|
} else if(upload.status == UPLOAD_FILE_END) {
|
||||||
@ -2603,7 +2624,7 @@ void SDFileupload()
|
|||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
//raise error
|
//raise error
|
||||||
LOG("Error detected 2\n");
|
LOG("Error detected 2\r\n");
|
||||||
LOG(response);
|
LOG(response);
|
||||||
com_error = true;
|
com_error = true;
|
||||||
}
|
}
|
||||||
@ -2623,13 +2644,19 @@ 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();
|
||||||
|
#ifdef DEBUG_PERFORMANCE
|
||||||
|
uint32_t endupload = millis();
|
||||||
|
DEBUG_PERF_VARIABLE.add(String(endupload-startupload).c_str());
|
||||||
|
DEBUG_PERF_VARIABLE.add(String(write_time).c_str());
|
||||||
|
DEBUG_PERF_VARIABLE.add(String(filesize).c_str());
|
||||||
|
#endif
|
||||||
if (com_error) {
|
if (com_error) {
|
||||||
LOG("with error\n");
|
LOG("with error\r\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\r\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");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@ -2637,7 +2664,7 @@ void SDFileupload()
|
|||||||
//Upload cancelled
|
//Upload cancelled
|
||||||
//**************
|
//**************
|
||||||
} else { //UPLOAD_FILE_ABORTED
|
} else { //UPLOAD_FILE_ABORTED
|
||||||
LOG("Error, Something happened\n");
|
LOG("Error, Something happened\r\n");
|
||||||
com_error = true;
|
com_error = true;
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
buffer_size=0;
|
buffer_size=0;
|
||||||
@ -2664,7 +2691,7 @@ void WebUpdateUpload()
|
|||||||
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\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//get current file ID
|
//get current file ID
|
||||||
@ -2907,7 +2934,7 @@ void handleSDFileList()
|
|||||||
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG("List SD FILES\n")
|
LOG("List SD FILES\r\n")
|
||||||
String path="/";
|
String path="/";
|
||||||
String sstatus="Ok";
|
String sstatus="Ok";
|
||||||
uint32_t totalspace = 0;
|
uint32_t totalspace = 0;
|
||||||
@ -2924,51 +2951,51 @@ void handleSDFileList()
|
|||||||
}
|
}
|
||||||
//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\r\n")
|
||||||
//delete a file
|
//delete a file
|
||||||
if(web_interface->WebServer.arg("action") == "delete" && web_interface->WebServer.hasArg("filename")) {
|
if(web_interface->WebServer.arg("action") == "delete" && web_interface->WebServer.hasArg("filename")) {
|
||||||
LOG("delete requested\n")
|
LOG("delete requested\r\n")
|
||||||
String filename;
|
String filename;
|
||||||
String shortname = web_interface->WebServer.arg("filename");
|
String shortname = web_interface->WebServer.arg("filename");
|
||||||
shortname.replace("/","");
|
shortname.replace("/","");
|
||||||
filename = path + web_interface->WebServer.arg("filename");
|
filename = path + web_interface->WebServer.arg("filename");
|
||||||
filename.replace("//","/");
|
filename.replace("//","/");
|
||||||
LOG(shortname)
|
LOG(shortname)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
LOG(filename)
|
LOG(filename)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
LOG(sstatus)
|
LOG(sstatus)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
}
|
}
|
||||||
//delete a directory
|
//delete a directory
|
||||||
if(web_interface->WebServer.arg("action") == "deletedir" && web_interface->WebServer.hasArg("filename")) {
|
if(web_interface->WebServer.arg("action") == "deletedir" && web_interface->WebServer.hasArg("filename")) {
|
||||||
LOG("deletedir requested\n")
|
LOG("deletedir requested\r\n")
|
||||||
String filename;
|
String filename;
|
||||||
String shortname = web_interface->WebServer.arg("filename");
|
String shortname = web_interface->WebServer.arg("filename");
|
||||||
shortname.replace("/","");
|
shortname.replace("/","");
|
||||||
filename = path + web_interface->WebServer.arg("filename");
|
filename = path + web_interface->WebServer.arg("filename");
|
||||||
filename.replace("//","/");
|
filename.replace("//","/");
|
||||||
LOG(shortname)
|
LOG(shortname)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
LOG(filename)
|
LOG(filename)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
LOG(sstatus)
|
LOG(sstatus)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
}
|
}
|
||||||
//create a directory
|
//create a directory
|
||||||
if(web_interface->WebServer.arg("action")=="createdir" && web_interface->WebServer.hasArg("filename")) {
|
if(web_interface->WebServer.arg("action")=="createdir" && web_interface->WebServer.hasArg("filename")) {
|
||||||
String filename;
|
String filename;
|
||||||
LOG("createdir requested\n")
|
LOG("createdir requested\r\n")
|
||||||
filename = path + web_interface->WebServer.arg("filename") ;
|
filename = path + web_interface->WebServer.arg("filename") ;
|
||||||
String shortname = web_interface->WebServer.arg("filename");
|
String shortname = web_interface->WebServer.arg("filename");
|
||||||
shortname.replace("/","");
|
shortname.replace("/","");
|
||||||
filename.replace("//","/");
|
filename.replace("//","/");
|
||||||
LOG(shortname)
|
LOG(shortname)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
LOG(filename)
|
LOG(filename)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
LOG(sstatus)
|
LOG(sstatus)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2976,16 +3003,16 @@ void handleSDFileList()
|
|||||||
#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\r\n");
|
||||||
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
|
jsonfile+="\"status\":\"processing\",\"mode\":\"serial\"}";
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
jsonfile+="\"files\":[";
|
jsonfile+="\"files\":[";
|
||||||
LOG("No Blocking \n");
|
LOG("No Blocking\r\n");
|
||||||
LOG("JSON File\n");
|
LOG("JSON File\r\n");
|
||||||
LOG(String(web_interface->fileslist.size()));
|
LOG(String(web_interface->fileslist.size()));
|
||||||
LOG(" entries\n");
|
LOG(" entries\r\n");
|
||||||
String sname;
|
String sname;
|
||||||
for (int i=0; i<web_interface->fileslist.size(); i++) {
|
for (int i=0; i<web_interface->fileslist.size(); i++) {
|
||||||
if (i>0) {
|
if (i>0) {
|
||||||
@ -3031,7 +3058,7 @@ void handleSDFileList()
|
|||||||
//nothing to add
|
//nothing to add
|
||||||
jsonfile+="";
|
jsonfile+="";
|
||||||
}
|
}
|
||||||
LOG("\n");
|
LOG("\r\n");
|
||||||
#endif
|
#endif
|
||||||
jsonfile+="\"}";
|
jsonfile+="\"}";
|
||||||
}
|
}
|
||||||
@ -3046,7 +3073,7 @@ void handleSDFileList()
|
|||||||
jsonfile+= "\"";
|
jsonfile+= "\"";
|
||||||
jsonfile+= "}";
|
jsonfile+= "}";
|
||||||
|
|
||||||
LOG("JSON done\n");
|
LOG("JSON done\r\n");
|
||||||
}
|
}
|
||||||
path = String();
|
path = String();
|
||||||
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
web_interface->WebServer.sendHeader("Cache-Control", "no-cache");
|
||||||
@ -3070,24 +3097,34 @@ void handle_not_found()
|
|||||||
String pathWithGz = path + ".gz";
|
String pathWithGz = path + ".gz";
|
||||||
LOG("request:")
|
LOG("request:")
|
||||||
LOG(path)
|
LOG(path)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
|
#ifdef DEBUG_ESP3D
|
||||||
|
int nb = web_interface->WebServer.args();
|
||||||
|
for (int i = 0 ; i < nb;i++){
|
||||||
|
LOG(web_interface->WebServer.argName(i))
|
||||||
|
LOG(":")
|
||||||
|
LOG(web_interface->WebServer.arg(i))
|
||||||
|
LOG("\r\n")
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
LOG("type:")
|
LOG("type:")
|
||||||
LOG(contentType)
|
LOG(contentType)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
||||||
if(SPIFFS.exists(pathWithGz)) {
|
if(SPIFFS.exists(pathWithGz)) {
|
||||||
path = pathWithGz;
|
path = pathWithGz;
|
||||||
|
}
|
||||||
|
FSFILE file = SPIFFS.open(path, "r");
|
||||||
|
web_interface->WebServer.streamFile(file, contentType);
|
||||||
|
file.close();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
page_not_found = true;
|
||||||
}
|
}
|
||||||
FSFILE file = SPIFFS.open(path, "r");
|
|
||||||
web_interface->WebServer.streamFile(file, contentType);
|
|
||||||
file.close();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
page_not_found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page_not_found ) {
|
if (page_not_found ) {
|
||||||
LOG("Page not found it \n")
|
LOG("Page not found it \r\n")
|
||||||
if (SPIFFS.exists("/404.tpl")) {
|
if (SPIFFS.exists("/404.tpl")) {
|
||||||
STORESTRINGS_CLASS KeysList ;
|
STORESTRINGS_CLASS KeysList ;
|
||||||
STORESTRINGS_CLASS ValuesList ;
|
STORESTRINGS_CLASS ValuesList ;
|
||||||
@ -3297,31 +3334,50 @@ void handle_restart()
|
|||||||
web_interface->restartmodule=true;
|
web_interface->restartmodule=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_web_command()
|
#define MAX_TRY 2000
|
||||||
{
|
void handle_web_command(){
|
||||||
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
if (web_interface->is_authenticated() == LEVEL_GUEST) {
|
||||||
|
web_interface->WebServer.send(200,"text/plain","Not allowed, log in first!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//check we have proper parameter
|
String buffer2send = "";
|
||||||
if (web_interface->WebServer.hasArg("COM")) {
|
LOG(String (web_interface->WebServer.args()))
|
||||||
String scmd;
|
LOG(" Web command\r\n")
|
||||||
//decode command
|
#ifdef DEBUG_ESP3D
|
||||||
scmd = web_interface->WebServer.arg("COM");
|
int nb = web_interface->WebServer.args();
|
||||||
scmd.trim();
|
for (int i = 0 ; i < nb;i++){
|
||||||
//give an ack - we need to be polite, right ?
|
LOG(web_interface->WebServer.argName(i))
|
||||||
web_interface->WebServer.send(200,"text/plain","Ok");
|
LOG(":")
|
||||||
|
LOG(web_interface->WebServer.arg(i))
|
||||||
|
LOG("\r\n")
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
String cmd;
|
||||||
|
int count ;
|
||||||
|
if (web_interface->WebServer.hasArg("plain") || web_interface->WebServer.hasArg("commandText")){
|
||||||
|
if (web_interface->WebServer.hasArg("plain")) cmd = web_interface->WebServer.arg("plain");
|
||||||
|
else cmd = web_interface->WebServer.arg("commandText");
|
||||||
|
LOG("Web Command:")
|
||||||
|
LOG(cmd)
|
||||||
|
LOG("\r\n")
|
||||||
|
} else {
|
||||||
|
LOG("invalid argument\r\n")
|
||||||
|
web_interface->WebServer.send(200,"text/plain","Invalid command");
|
||||||
|
return;
|
||||||
|
}
|
||||||
//if it is for ESP module [ESPXXX]<parameter>
|
//if it is for ESP module [ESPXXX]<parameter>
|
||||||
int ESPpos = scmd.indexOf("[ESP");
|
cmd.trim();
|
||||||
|
int ESPpos = cmd.indexOf("[ESP");
|
||||||
if (ESPpos>-1) {
|
if (ESPpos>-1) {
|
||||||
//is there the second part?
|
//is there the second part?
|
||||||
int ESPpos2 = scmd.indexOf("]",ESPpos);
|
int ESPpos2 = cmd.indexOf("]",ESPpos);
|
||||||
if (ESPpos2>-1) {
|
if (ESPpos2>-1) {
|
||||||
//Split in command and parameters
|
//Split in command and parameters
|
||||||
String cmd_part1=scmd.substring(ESPpos+4,ESPpos2);
|
String cmd_part1=cmd.substring(ESPpos+4,ESPpos2);
|
||||||
String cmd_part2="";
|
String cmd_part2="";
|
||||||
//is there space for parameters?
|
//is there space for parameters?
|
||||||
if (ESPpos2<scmd.length()) {
|
if (ESPpos2<cmd.length()) {
|
||||||
cmd_part2=scmd.substring(ESPpos2+1);
|
cmd_part2=cmd.substring(ESPpos2+1);
|
||||||
}
|
}
|
||||||
//if command is a valid number then execute command
|
//if command is a valid number then execute command
|
||||||
if(cmd_part1.toInt()!=0) {
|
if(cmd_part1.toInt()!=0) {
|
||||||
@ -3333,10 +3389,98 @@ void handle_web_command()
|
|||||||
//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) {
|
if ((web_interface->blockserial) == false) {
|
||||||
Serial.println(scmd);
|
//block every query
|
||||||
}
|
web_interface->blockserial = true;
|
||||||
|
LOG("Block Serial\r\n")
|
||||||
|
//empty the serial buffer and incoming data
|
||||||
|
LOG("Start PurgeSerial\r\n")
|
||||||
|
while(Serial.available()){
|
||||||
|
BRIDGE::processFromSerial2TCP();
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
LOG("End PurgeSerial\r\n")
|
||||||
|
web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
|
web_interface->WebServer.send(200);
|
||||||
|
web_interface->WebServer.sendHeader("Content-Type","text/plain");
|
||||||
|
web_interface->WebServer.sendHeader("Cache-Control","no-cache");
|
||||||
|
//send command
|
||||||
|
LOG(String(cmd.length()))
|
||||||
|
LOG("Start PurgeSerial\r\n")
|
||||||
|
while(Serial.available()){
|
||||||
|
BRIDGE::processFromSerial2TCP();
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
LOG("End PurgeSerial\r\n")
|
||||||
|
LOG("Send Command\r\n")
|
||||||
|
Serial.println(cmd);
|
||||||
|
count = 0;
|
||||||
|
String current_buffer;
|
||||||
|
String current_line;
|
||||||
|
int pos;
|
||||||
|
String tmp;
|
||||||
|
bool datasent = false;
|
||||||
|
//pickup the list
|
||||||
|
while (count < MAX_TRY){
|
||||||
|
//give some time between each buffer
|
||||||
|
if (Serial.available()){
|
||||||
|
count = 0;
|
||||||
|
size_t len = Serial.available();
|
||||||
|
uint8_t sbuf[len+1];
|
||||||
|
//read buffer
|
||||||
|
Serial.readBytes(sbuf, len);
|
||||||
|
//change buffer as string
|
||||||
|
sbuf[len]='\0';
|
||||||
|
//add buffer to current one if any
|
||||||
|
current_buffer += (char * ) sbuf;
|
||||||
|
while (current_buffer.indexOf("\n") !=-1){
|
||||||
|
//remove the possible "\r"
|
||||||
|
current_buffer.replace("\r","");
|
||||||
|
pos = current_buffer.indexOf("\n");
|
||||||
|
//get line
|
||||||
|
current_line = current_buffer.substring(0,current_buffer.indexOf("\n"));
|
||||||
|
//if line is command acck - just exit so save the time out period
|
||||||
|
if ((current_line.indexOf("ok" ) == 0) && (current_line.length() == 2))
|
||||||
|
{
|
||||||
|
count = MAX_TRY;
|
||||||
|
LOG("Found ok\r\n")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//get the line and transmit it
|
||||||
|
LOG(current_line)
|
||||||
|
LOG("\r\n")
|
||||||
|
//check command
|
||||||
|
COMMAND::check_command(current_line,false);
|
||||||
|
buffer2send +=current_line;
|
||||||
|
buffer2send +="\n";
|
||||||
|
if (buffer2send.length() > 1200) {
|
||||||
|
web_interface->WebServer.sendContent(buffer2send);
|
||||||
|
buffer2send = "";
|
||||||
|
datasent = true;
|
||||||
|
}
|
||||||
|
//current remove line from buffer
|
||||||
|
tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length());
|
||||||
|
current_buffer = tmp;
|
||||||
|
}
|
||||||
|
} else delay(1);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
//to be sure connection close
|
||||||
|
if (buffer2send.length() > 0) {
|
||||||
|
web_interface->WebServer.sendContent(buffer2send);
|
||||||
|
datasent = true;
|
||||||
|
}
|
||||||
|
if (!datasent)web_interface->WebServer.sendContent(" \r\n");
|
||||||
|
web_interface->WebServer.sendContent("");
|
||||||
|
LOG("Start PurgeSerial\r\n")
|
||||||
|
while(Serial.available()){
|
||||||
|
BRIDGE::processFromSerial2TCP();
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
LOG("End PurgeSerial\r\n")
|
||||||
|
web_interface->blockserial = false;
|
||||||
|
LOG("Release Serial\r\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SSDP_FEATURE
|
#ifdef SSDP_FEATURE
|
||||||
@ -3358,13 +3502,19 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
|||||||
WebServer.on("/STATUS",HTTP_ANY, handle_web_interface_status);
|
WebServer.on("/STATUS",HTTP_ANY, handle_web_interface_status);
|
||||||
WebServer.on("/SETTINGS",HTTP_ANY, handle_web_settings);
|
WebServer.on("/SETTINGS",HTTP_ANY, handle_web_settings);
|
||||||
WebServer.on("/PRINTER",HTTP_ANY, handle_web_interface_printer);
|
WebServer.on("/PRINTER",HTTP_ANY, handle_web_interface_printer);
|
||||||
WebServer.on("/CMD",HTTP_ANY, handle_web_command);
|
WebServer.on("/command",HTTP_ANY, handle_web_command);
|
||||||
|
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
||||||
|
WebServer.on("/command_silent",HTTP_ANY, handle_web_command);
|
||||||
|
#endif
|
||||||
WebServer.on("/RESTART",HTTP_GET, handle_restart);
|
WebServer.on("/RESTART",HTTP_GET, handle_restart);
|
||||||
#ifdef WEB_UPDATE_FEATURE
|
#ifdef WEB_UPDATE_FEATURE
|
||||||
WebServer.on("/UPDATE",HTTP_ANY, handleUpdate,WebUpdateUpload);
|
WebServer.on("/UPDATE",HTTP_ANY, handleUpdate,WebUpdateUpload);
|
||||||
#endif
|
#endif
|
||||||
WebServer.on("/FILES", HTTP_ANY, handleFileList,SPIFFSFileupload);
|
WebServer.on("/FILES", HTTP_ANY, handleFileList,SPIFFSFileupload);
|
||||||
WebServer.on("/SDFILES", HTTP_ANY, handleSDFileList,SDFileupload);
|
WebServer.on("/SDFILES", HTTP_ANY, handleSDFileList,SDFileupload);
|
||||||
|
#if FIRMWARE_TARGET == SMOOTHIEWARE
|
||||||
|
WebServer.on("/upload", HTTP_ANY, handleSDFileList,SDFileupload);
|
||||||
|
#endif
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
WebServer.on("/LOGIN", HTTP_ANY, handle_login);
|
WebServer.on("/LOGIN", HTTP_ANY, handle_login);
|
||||||
WebServer.on("/PASSWORD", HTTP_ANY, handle_password);
|
WebServer.on("/PASSWORD", HTTP_ANY, handle_password);
|
||||||
|
@ -111,7 +111,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||||
//set the sleep mode
|
//set the sleep mode
|
||||||
if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) {
|
||||||
LOG("Error read Sleep mode\n")
|
LOG("Error read Sleep mode\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WiFi.setSleepMode ((WiFiSleepType_t)bflag);
|
WiFi.setSleepMode ((WiFiSleepType_t)bflag);
|
||||||
@ -121,7 +121,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
} 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\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ 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\r\n")
|
||||||
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
if(!CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -142,65 +142,65 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
Serial.println(sbuf);
|
Serial.println(sbuf);
|
||||||
LOG("SSID ")
|
LOG("SSID ")
|
||||||
LOG(sbuf)
|
LOG(sbuf)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
//DHCP or Static IP ?
|
//DHCP or Static IP ?
|
||||||
if (!CONFIG::read_byte(EP_AP_IP_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_AP_IP_MODE, &bflag )) {
|
||||||
LOG("Error IP mode\n")
|
LOG("Error IP mode\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOG("IP Mode: ")
|
LOG("IP Mode: ")
|
||||||
LOG(CONFIG::intTostr(bflag))
|
LOG(CONFIG::intTostr(bflag))
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
if (bflag==STATIC_IP_MODE) {
|
if (bflag==STATIC_IP_MODE) {
|
||||||
byte ip_buf[4];
|
byte ip_buf[4];
|
||||||
LOG("Static mode\n")
|
LOG("Static mode\r\n")
|
||||||
//get the IP
|
//get the IP
|
||||||
LOG("IP value:")
|
LOG("IP value:")
|
||||||
if (!CONFIG::read_buffer(EP_AP_IP_VALUE,ip_buf , IP_LENGTH)) {
|
if (!CONFIG::read_buffer(EP_AP_IP_VALUE,ip_buf , IP_LENGTH)) {
|
||||||
LOG("Error\n")
|
LOG("Error\r\n")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]);
|
||||||
LOG(local_ip.toString())
|
LOG(local_ip.toString())
|
||||||
LOG("\nGW value:")
|
LOG("\r\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\r\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]);
|
||||||
LOG(gateway.toString())
|
LOG(gateway.toString())
|
||||||
LOG("\nMask value:")
|
LOG("\r\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\r\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]);
|
||||||
LOG(subnet.toString())
|
LOG(subnet.toString())
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
//apply according active wifi mode
|
//apply according active wifi mode
|
||||||
LOG("Set IP\n")
|
LOG("Set IP\r\n")
|
||||||
WiFi.softAPConfig( local_ip, gateway, subnet);
|
WiFi.softAPConfig( local_ip, gateway, subnet);
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
LOG("Disable STA\n")
|
LOG("Disable STA\r\n")
|
||||||
WiFi.enableSTA(false);
|
WiFi.enableSTA(false);
|
||||||
delay(100);
|
delay(100);
|
||||||
LOG("Set AP\n")
|
LOG("Set AP\r\n")
|
||||||
//setup Soft AP
|
//setup Soft AP
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
delay(50);
|
delay(50);
|
||||||
WiFi.softAP(sbuf, pwd);
|
WiFi.softAP(sbuf, pwd);
|
||||||
delay(100);
|
delay(100);
|
||||||
LOG("Set phy mode\n")
|
LOG("Set phy mode\r\n")
|
||||||
//setup PHY_MODE
|
//setup PHY_MODE
|
||||||
if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bflag )) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
WiFi.setPhyMode((WiFiPhyMode_t)bflag);
|
||||||
delay(100);
|
delay(100);
|
||||||
LOG("Get current config\n")
|
LOG("Get current config\r\n")
|
||||||
//get current config
|
//get current config
|
||||||
struct softap_config apconfig;
|
struct softap_config apconfig;
|
||||||
wifi_softap_get_config(&apconfig);
|
wifi_softap_get_config(&apconfig);
|
||||||
@ -228,7 +228,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG("Set STA mode\n")
|
LOG("Set STA mode\r\n")
|
||||||
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) {
|
if(!CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ bool WIFI_CONFIG::Setup(bool force_ap)
|
|||||||
Serial.println(sbuf);
|
Serial.println(sbuf);
|
||||||
LOG("SSID ")
|
LOG("SSID ")
|
||||||
LOG(sbuf)
|
LOG(sbuf)
|
||||||
LOG("\n")
|
LOG("\r\n")
|
||||||
if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
|
if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user