Merge pull request #447 from luc-github/2.1-devt

fixes and improvements from Devt
This commit is contained in:
Luc 2020-04-20 07:27:14 +02:00 committed by GitHub
commit 43b20506a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 253 additions and 225 deletions

View File

@ -1562,7 +1562,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
}
#else
//go next record
station = STAILQ_NEXT (station, next);
station = STAILQ_NEXT (station, next);
}
wifi_softap_free_station_info();
#endif
@ -1979,3 +1979,50 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
ESPCOM::print (F ("\n"), output, espresponse);
}
}
#ifdef DEBUG_OUTPUT_SOCKET
#if defined(ARDUINO_ARCH_ESP8266)
#define NODEBUG_WEBSOCKETS
#include <WebSocketsServer.h>
extern WebSocketsServer * socket_server;
const char * pathToFileName(const char * path)
{
size_t i = 0;
size_t pos = 0;
char * p = (char *)path;
while(*p) {
i++;
if(*p == '/' || *p == '\\') {
pos = i;
}
p++;
}
return path+pos;
}
#endif //ARDUINO_ARCH_ESP8266
void log_socket(const char *format, ...){
if(socket_server){
char loc_buf[255];
char * temp = loc_buf;
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
size_t len = vsnprintf(NULL, 0, format, arg);
va_end(copy);
if(len >= sizeof(loc_buf)){
temp = new char[len+1];
if(temp == NULL) {
return;
}
}
len = vsnprintf(temp, len+1, format, arg);
socket_server->sendBIN(ESPCOM::current_socket_id,(uint8_t *)temp,strlen(temp));
va_end(arg);
if(len > 255){
delete[] temp;
}
}
}
#endif

View File

@ -19,7 +19,7 @@
*/
//version and sources location
#define FW_VERSION "2.1.1.b1"
#define FW_VERSION "2.1.1.b6"
#define REPOSITORY "https://github.com/luc-github/ESP3D"
//Customize ESP3D ////////////////////////////////////////////////////////////////////////
@ -128,7 +128,7 @@
#define OLED_DISPLAY_SSD1306 // OLED Display Type: SSD1306(OLED_DISPLAY_SSD1306) / SH1106(OLED_DISPLAY_SH1106), comment this line out to disable oled
#define OLED_PIN_SDA 4 //5 //SDA; // i2c SDA Pin
#define OLED_PIN_SCL 15 //4 //SCL; // i2c SCL Pin
#define OLED_ADDR 0x3c
#define OLED_ADDR 0x3c
#define HELTEC_EMBEDDED_PIN 16 //0 to disable
#define OLED_FLIP_VERTICALY 1 //0 to disable
#endif
@ -136,14 +136,17 @@
//Supported FW /////////////////////////////////////////////////////////////
#define UNKNOWN_FW 0
#define REPETIER4DV 1
#define MARLIN 2
#define MARLINKIMBRA 3
#define SMOOTHIEWARE 4
#define REPETIER 5
#define GRBL 6
#define REPETIER4DV 1
#define MARLIN 2
#define MARLINKIMBRA 3
#define SMOOTHIEWARE 4
#define REPETIER 5
#define GRBL 6
#define MAX_FW_ID 6
//For FW which has issue with checksum or not handling M110 properly///////
//#define DISABLE_SERIAL_CHECKSUM
//Do not Edit after this line //////////////////////////////////////////////
//DEBUG Flag do not do this when connected to printer !!!
@ -152,6 +155,7 @@
//#define DEBUG_OUTPUT_SPIFFS
//#define DEBUG_OUTPUT_SERIAL
//#define DEBUG_OUTPUT_TCP
//#define DEBUG_OUTPUT_SOCKET
//Sanity check
#ifndef SDCARD_FEATURE
@ -162,6 +166,7 @@
#if defined(ASYNCWEBSERVER)
#define ESP_USE_ASYNC true
#error it no more supported
#else
#define ESP_USE_ASYNC false
#endif
@ -210,6 +215,14 @@ using fs::File;
//NOT YET IMPLEMENTED!!! Keep it as TODO
//#define WEBHOST_SDCARD_FEATURE
#ifdef DEBUG_OUTPUT_SOCKET
extern void log_socket(const char *format, ...);
extern const char * pathToFileName(const char * path);
#define log_esp3d(format, ...) log_socket("\n[ESP3D][%s:%u] %s(): " format "\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define log_esp3d(format, ...)
#endif
#ifdef DEBUG_ESP3D
#ifdef DEBUG_OUTPUT_SPIFFS
#ifndef FS_NO_GLOBALS
@ -290,54 +303,54 @@ typedef enum {
//flags
#define AP_MODE 1
#define CLIENT_MODE 2
#define DHCP_MODE 1
#define STATIC_IP_MODE 2
#define AP_MODE 1
#define CLIENT_MODE 2
#define DHCP_MODE 1
#define STATIC_IP_MODE 2
//position in EEPROM
//AP mode = 1; Station client mode = 2
#define EP_WIFI_MODE 0 //1 byte = flag
#define EP_STA_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define EP_STA_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
#define EP_STA_IP_MODE 99 //1 byte = flag
#define EP_STA_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx
#define EP_STA_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx
#define EP_STA_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx
#define EP_BAUD_RATE 112 //4 bytes = int
#define EP_STA_PHY_MODE 116 //1 byte = flag
#define EP_SLEEP_MODE 117 //1 byte = flag
#define EP_CHANNEL 118 //1 byte = flag
#define EP_AUTH_TYPE 119 //1 byte = flag
#define EP_SSID_VISIBLE 120 //1 byte = flag
#define EP_WEB_PORT 121 //4 bytes = int
#define EP_DATA_PORT 125 //4 bytes = int
#define EP_OUTPUT_FLAG 129 //1 bytes = flag
#define EP_HOSTNAME 130//33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define EP_DHT_INTERVAL 164//4 bytes = int
#define EP_WIFI_MODE 0 //1 byte = flag
#define EP_STA_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define EP_STA_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
#define EP_STA_IP_MODE 99 //1 byte = flag
#define EP_STA_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx
#define EP_STA_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx
#define EP_STA_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx
#define EP_BAUD_RATE 112 //4 bytes = int
#define EP_STA_PHY_MODE 116 //1 byte = flag
#define EP_SLEEP_MODE 117 //1 byte = flag
#define EP_CHANNEL 118 //1 byte = flag
#define EP_AUTH_TYPE 119 //1 byte = flag
#define EP_SSID_VISIBLE 120 //1 byte = flag
#define EP_WEB_PORT 121 //4 bytes = int
#define EP_DATA_PORT 125 //4 bytes = int
#define EP_OUTPUT_FLAG 129 //1 bytes = flag
#define EP_HOSTNAME 130//33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define EP_DHT_INTERVAL 164//4 bytes = int
#define ESP_NOTIFICATION_TYPE 168 //1 byte = flag
#define ESP_AUTO_NOTIFICATION 170//1 bytes = flag
#define EP_FREE_BYTE1 171//1 bytes = flag
#define EP_FREE_INT3 172//4 bytes = int
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
#define EP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define EP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
#define EP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx
#define EP_AP_MASK_VALUE 320 //4 bytes xxx.xxx.xxx.xxx
#define EP_AP_GATEWAY_VALUE 324 //4 bytes xxx.xxx.xxx.xxx
#define EP_AP_IP_MODE 329 //1 byte = flag
#define EP_AP_PHY_MODE 330 //1 byte = flag
#define EP_SD_SPEED_DIV 331 //1 byte = flag
#define EP_FREE_BYTE1 171//1 bytes = flag
#define EP_FREE_INT3 172//4 bytes = int
#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese
#define EP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define EP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
#define EP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx
#define EP_AP_MASK_VALUE 320 //4 bytes xxx.xxx.xxx.xxx
#define EP_AP_GATEWAY_VALUE 324 //4 bytes xxx.xxx.xxx.xxx
#define EP_AP_IP_MODE 329 //1 byte = flag
#define EP_AP_PHY_MODE 330 //1 byte = flag
#define EP_SD_SPEED_DIV 331 //1 byte = flag
#define ESP_NOTIFICATION_TOKEN1 332 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
#define ESP_NOTIFICATION_TOKEN2 396 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
#define EP_DHT_TYPE 460 //1 bytes = flag
#define EP_TARGET_FW 461 //1 bytes = flag
#define EP_DHT_TYPE 460 //1 bytes = flag
#define EP_TARGET_FW 461 //1 bytes = flag
#define EP_TIMEZONE 462//1 bytes = flag
#define EP_TIME_ISDST 463//1 bytes = flag
#define EP_TIME_SERVER1 464//129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define EP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define EP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define EP_TIME_SERVER1 464//128 bytes 127+1 = string ; warning does not support multibyte char like chinese
#define EP_TIME_SERVER2 593 //128 bytes 127+1 = string ; warning does not support multibyte char like chinese
#define EP_TIME_SERVER3 722 //128 bytes 127+1 = string ; warning does not support multibyte char like chinese
#define EP_IS_DIRECT_SD 850//1 bytes = flag
#define EP_PRIMARY_SD 851//1 bytes = flag
#define EP_SECONDARY_SD 852//1 bytes = flag
@ -350,35 +363,35 @@ typedef enum {
#define LAST_EEPROM_ADDRESS 983
//default values
#define DEFAULT_WIFI_MODE AP_MODE
const char DEFAULT_AP_SSID [] PROGMEM = "ESP3D";
const char DEFAULT_AP_PASSWORD [] PROGMEM = "12345678";
const char DEFAULT_STA_SSID [] PROGMEM = "ESP3D";
const char DEFAULT_STA_PASSWORD [] PROGMEM = "12345678";
const byte DEFAULT_STA_IP_MODE = DHCP_MODE;
const byte DEFAULT_AP_IP_MODE = STATIC_IP_MODE;
const byte DEFAULT_IP_VALUE[] = {192, 168, 0, 1};
const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0};
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
const long DEFAULT_BAUD_RATE = 115200;
#define DEFAULT_PHY_MODE WIFI_PHY_MODE_11G
#define DEFAULT_SLEEP_MODE WIFI_MODEM_SLEEP
#define DEFAULT_CHANNEL 11
#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK
#define DEFAULT_SSID_VISIBLE 1
#define DEFAULT_MAX_CONNECTIONS 4
#define DEFAULT_BEACON_INTERVAL 100
const int DEFAULT_WEB_PORT = 80;
const int DEFAULT_DATA_PORT = 8888;
const char DEFAULT_ADMIN_PWD [] PROGMEM = "admin";
const char DEFAULT_USER_PWD [] PROGMEM = "user";
const char DEFAULT_ADMIN_LOGIN [] PROGMEM = "admin";
const char DEFAULT_USER_LOGIN [] PROGMEM = "user";
const char DEFAULT_TIME_SERVER1 [] PROGMEM = "1.pool.ntp.org";
const char DEFAULT_TIME_SERVER2 [] PROGMEM = "2.pool.ntp.org";
const char DEFAULT_TIME_SERVER3 [] PROGMEM = "0.pool.ntp.org";
#define DEFAULT_TIME_ZONE 0
#define DEFAULT_TIME_DST 0
#define DEFAULT_WIFI_MODE AP_MODE
const char DEFAULT_AP_SSID [] PROGMEM = "ESP3D";
const char DEFAULT_AP_PASSWORD [] PROGMEM = "12345678";
const char DEFAULT_STA_SSID [] PROGMEM = "ESP3D";
const char DEFAULT_STA_PASSWORD [] PROGMEM = "12345678";
const byte DEFAULT_STA_IP_MODE = DHCP_MODE;
const byte DEFAULT_AP_IP_MODE = STATIC_IP_MODE;
const byte DEFAULT_IP_VALUE[] = {192, 168, 0, 1};
const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0};
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
const long DEFAULT_BAUD_RATE = 115200;
#define DEFAULT_PHY_MODE WIFI_PHY_MODE_11G
#define DEFAULT_SLEEP_MODE WIFI_MODEM_SLEEP
#define DEFAULT_CHANNEL 11
#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK
#define DEFAULT_SSID_VISIBLE 1
#define DEFAULT_MAX_CONNECTIONS 4
#define DEFAULT_BEACON_INTERVAL 100
const int DEFAULT_WEB_PORT = 80;
const int DEFAULT_DATA_PORT = 8888;
const char DEFAULT_ADMIN_PWD [] PROGMEM = "admin";
const char DEFAULT_USER_PWD [] PROGMEM = "user";
const char DEFAULT_ADMIN_LOGIN [] PROGMEM = "admin";
const char DEFAULT_USER_LOGIN [] PROGMEM = "user";
const char DEFAULT_TIME_SERVER1 [] PROGMEM = "1.pool.ntp.org";
const char DEFAULT_TIME_SERVER2 [] PROGMEM = "2.pool.ntp.org";
const char DEFAULT_TIME_SERVER3 [] PROGMEM = "0.pool.ntp.org";
#define DEFAULT_TIME_ZONE 0
#define DEFAULT_TIME_DST 0
#define DEFAULT_PRIMARY_SD 2
#define DEFAULT_SECONDARY_SD 1
#define DEFAULT_DIRECT_SD_CHECK 0
@ -401,9 +414,9 @@ const int DEFAULT_DHT_INTERVAL = 30;
#define NOTIFICATION_ESP_ONLINE "Hi, %ESP_NAME% is now online at %ESP_IP%"
//Notifications
#define ESP_PUSHOVER_NOTIFICATION 1
#define ESP_EMAIL_NOTIFICATION 2
#define ESP_LINE_NOTIFICATION 3
#define ESP_PUSHOVER_NOTIFICATION 1
#define ESP_EMAIL_NOTIFICATION 2
#define ESP_LINE_NOTIFICATION 3
#ifdef SDCARD_FEATURE
#define DEFAULT_IS_DIRECT_SD 1
@ -473,29 +486,29 @@ const uint16_t Setting[][2] = {
#define FLAG_BLOCK_TCP 0x010
//values
#define DEFAULT_MAX_WEB_PORT 65001
#define DEFAULT_MIN_WEB_PORT 1
#define DEFAULT_MAX_DATA_PORT 65001
#define DEFAULT_MIN_DATA_PORT 1
#define DEFAULT_MAX_WEB_PORT 65001
#define DEFAULT_MIN_WEB_PORT 1
#define DEFAULT_MAX_DATA_PORT 65001
#define DEFAULT_MIN_DATA_PORT 1
#define MAX_TRY 2000
//sizes
#define EEPROM_SIZE 1024 //max is 1024
#define MAX_SSID_LENGTH 32
#define MIN_SSID_LENGTH 1
#define MAX_PASSWORD_LENGTH 64
#define EEPROM_SIZE 1024 //max is 1024
#define MAX_SSID_LENGTH 32
#define MIN_SSID_LENGTH 1
#define MAX_PASSWORD_LENGTH 64
//min size of password is 0 or upper than 8 char
//so let set min is 0
#define MIN_PASSWORD_LENGTH 0
#define MAX_LOCAL_PASSWORD_LENGTH 16
#define MIN_LOCAL_PASSWORD_LENGTH 1
#define MAX_DATA_LENGTH 128
#define MIN_DATA_LENGTH 0
#define IP_LENGTH 4
#define INTEGER_LENGTH 4
#define MAX_HOSTNAME_LENGTH 32
#define MIN_HOSTNAME_LENGTH 1
#define MIN_PASSWORD_LENGTH 0
#define MAX_LOCAL_PASSWORD_LENGTH 16
#define MIN_LOCAL_PASSWORD_LENGTH 1
#define MAX_DATA_LENGTH 127
#define MIN_DATA_LENGTH 0
#define IP_LENGTH 4
#define INTEGER_LENGTH 4
#define MAX_HOSTNAME_LENGTH 32
#define MIN_HOSTNAME_LENGTH 1
#define WL_MAC_ADDR_LENGTH 6
//EEPROM Version

Binary file not shown.

View File

@ -65,8 +65,15 @@ long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len)
{
switch (output) {
#ifdef USE_SERIAL_0
case SERIAL_PIPE:
return Serial.readBytes(sbuf,len);
case SERIAL_PIPE:{
long l = Serial.readBytes(sbuf,len);
#ifdef DEBUG_OUTPUT_SOCKET
if(socket_server){
socket_server->sendBIN(ESPCOM::current_socket_id,sbuf,l);
}
#endif
return l;
}
break;
#endif
#ifdef USE_SERIAL_1
@ -243,6 +250,11 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
switch (output) {
#ifdef USE_SERIAL_0
case SERIAL_PIPE:
#ifdef DEBUG_OUTPUT_SOCKET
if(socket_server){
socket_server->sendBIN(ESPCOM::current_socket_id,(const uint8_t*)data,strlen(data));
}
#endif
Serial.print (data);
break;
#endif
@ -288,7 +300,9 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
#if defined(ASYNCWEBSERVER)
//Todo
#else
socket_server->sendBIN(current_socket_id,(const uint8_t *)data,strlen(data));
if(socket_server){
socket_server->sendBIN(current_socket_id,(const uint8_t *)data,strlen(data));
}
#endif
}
break;
@ -406,7 +420,11 @@ bool ESPCOM::processFromSerial (bool async)
}
#else
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server) {
socket_server->sendBIN(current_socket_id,sbuf,len);
#ifndef DEBUG_OUTPUT_SOCKET
if(socket_server){
socket_server->sendBIN(current_socket_id,sbuf,len);
}
#endif
}
#endif

View File

@ -61,6 +61,7 @@
#include "syncwebserver.h"
WebSocketsServer * socket_server;
#define ESP_ERROR_AUTHENTICATION 1
#define ESP_ERROR_FILE_CREATION 2
#define ESP_ERROR_FILE_WRITE 3
@ -74,6 +75,7 @@ WebSocketsServer * socket_server;
#define ESP_ERROR_BUFFER_OVERFLOW 11
#define ESP_ERROR_START_UPLOAD 12
void pushError(int code, const char * st, bool web_error = 500, uint16_t timeout = 1000){
if (socket_server && st) {
String s = "ERROR:" + String(code) + ":";
@ -601,7 +603,7 @@ void handleFileList()
//SPIFFS files uploader handle
void SPIFFSFileupload()
{
static FS_FILE fsUploadFile = (FS_FILE)0;
static FS_FILE fsUploadFile = (FS_FILE)0;
static String filename;
//get authentication status
level_authenticate_type auth_level= web_interface->is_authenticated();
@ -725,7 +727,7 @@ void WebUpdateUpload()
if(web_interface->is_authenticated() != LEVEL_ADMIN) {
web_interface->_upload_status=UPLOAD_STATUS_FAILED;
ESPCOM::println (F ("Update failed"), PRINTER_PIPE);
LOG("Web Update failed\r\n");
log_esp3d("Web Update failed");
pushError(ESP_ERROR_AUTHENTICATION, "Upload rejected",401);
} else {
//get current file ID
@ -853,22 +855,7 @@ void handle_not_found()
String path = web_interface->web_server.urlDecode(web_interface->web_server.uri());
String contentType = web_interface->getContentType(path);
String pathWithGz = path + ".gz";
LOG("request:")
LOG(path)
LOG("\r\n")
#ifdef DEBUG_ESP3D
int nb = web_interface->web_server.args();
for (int i = 0 ; i < nb; i++) {
LOG(web_interface->web_server.argName(i))
LOG(":")
LOG(web_interface->web_server.arg(i))
LOG("\r\n")
}
#endif
LOG("type:")
LOG(contentType)
LOG("\r\n")
log_esp3d("Not found %s, type %s", path.c_str(), contentType.c_str());
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
if(SPIFFS.exists(pathWithGz)) {
path = pathWithGz;
@ -901,7 +888,7 @@ void handle_not_found()
return;
}
#endif
LOG("Page not found\r\n")
log_esp3d("Page not found");
path = F("/404.htm");
contentType = web_interface->getContentType(path);
pathWithGz = path + F(".gz");
@ -946,30 +933,16 @@ void handle_web_command()
}*/
String buffer2send = "";
ESPResponseStream espresponse;
LOG(String (web_interface->web_server.args()))
LOG(" Web command\r\n")
#ifdef DEBUG_ESP3D
int nb = web_interface->web_server.args();
for (int i = 0 ; i < nb; i++) {
LOG(web_interface->web_server.argName(i))
LOG(":")
LOG(web_interface->web_server.arg(i))
LOG("\r\n")
}
#endif
String cmd = "";
int count ;
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
if (web_interface->web_server.hasArg("plain")) {
cmd = web_interface->web_server.arg("plain");
} else {
cmd = web_interface->web_server.arg("commandText");
}
LOG("Web Command:")
LOG(cmd)
LOG("\r\n")
log_esp3d("WebCommand %s",cmd.c_str());
} else {
LOG("invalid argument\r\n")
log_esp3d("Invalid arg");
web_interface->web_server.send(200,"text/plain","Invalid command");
return;
}
@ -1009,40 +982,40 @@ void handle_web_command()
if ((web_interface->blockserial) == false) {
//block every query
web_interface->blockserial = true;
LOG("Block Serial\r\n")
log_esp3d("Block Serial");
//empty the serial buffer and incoming data
LOG("Start PurgeSerial\r\n")
log_esp3d("Start PurgeSerial");
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
ESPCOM::bridge();
CONFIG::wait(1);
}
LOG("End PurgeSerial\r\n")
log_esp3d("End PurgeSerial");
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
web_interface->web_server.sendHeader("Content-Type","text/plain",true);
web_interface->web_server.sendHeader("Cache-Control","no-cache");
web_interface->web_server.send(200);
//send command
LOG(String(cmd.length()))
LOG("Start PurgeSerial\r\n")
log_esp3d("Start PurgeSerial");
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
ESPCOM::bridge();
CONFIG::wait(1);
}
LOG("End PurgeSerial\r\n")
LOG("Send Command\r\n")
log_esp3d("End PurgeSerial");
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
count = 0;
bool done = false;
String current_buffer;
String current_line;
//int pos;
int temp_counter = 0;
String tmp;
bool datasent = false;
uint32_t timeout = millis();
//pickup the list
while (count < MAX_TRY) {
while ((millis() - timeout < 2000) && !done) {
//give some time between each buffer
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
count = 0;
log_esp3d("Got data");
timeout = millis();
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
uint8_t sbuf[len+1];
//read buffer
@ -1052,21 +1025,20 @@ void handle_web_command()
//add buffer to current one if any
current_buffer += (char * ) sbuf;
while (current_buffer.indexOf("\n") !=-1) {
log_esp3d("Remove new line");
//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 ack - just exit so save the time out period
if ((current_line == "ok") || (current_line == "wait")) {
count = MAX_TRY;
LOG("Found ok\r\n")
if ((current_line == "ok") || (current_line == "wait") || (current_line.startsWith("ok") && !((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)))) {
done = true;
buffer2send +=current_line;
log_esp3d("Found ok/wait add New buffer %s", buffer2send.c_str());
buffer2send +="\n";
break;
}
//get the line and transmit it
LOG("Check command: ")
LOG(current_line)
LOG("\r\n")
//check command
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
//save time no need to continue
@ -1081,6 +1053,8 @@ void handle_web_command()
}
}
if (temp_counter > 5) {
log_esp3d("Timeout X5");
done = true;
break;
}
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
@ -1090,17 +1064,19 @@ void handle_web_command()
}
} else {
buffer2send +=current_line;
log_esp3d("New buffer %s", buffer2send.c_str());
buffer2send +="\n";
}
if (buffer2send.length() > 1200) {
web_interface->web_server.sendContent(buffer2send);
log_esp3d("Sending %s", buffer2send.c_str());
buffer2send = "";
datasent = true;
}
//current remove line from buffer
tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length());
current_buffer = tmp;
delay(0);
CONFIG::wait (0);
}
CONFIG::wait (0);
} else {
@ -1108,27 +1084,28 @@ void handle_web_command()
}
//it is sending too many temp status should be heating so let's exit the loop
if (temp_counter > 5) {
count = MAX_TRY;
done = true;
}
count++;
}
log_esp3d("Finished");
//to be sure connection close
if (buffer2send.length() > 0) {
web_interface->web_server.sendContent(buffer2send);
log_esp3d("Sending %s", buffer2send.c_str());
datasent = true;
}
if (!datasent) {
web_interface->web_server.sendContent(" \r\n");
}
web_interface->web_server.sendContent("");
LOG("Start PurgeSerial\r\n")
log_esp3d("Start PurgeSerial");
if(ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
ESPCOM::bridge();
CONFIG::wait(1);
}
LOG("End PurgeSerial\r\n")
log_esp3d("End PurgeSerial");
web_interface->blockserial = false;
LOG("Release Serial\r\n")
log_esp3d("Release PurgeSerial");
} else {
web_interface->web_server.send(200,"text/plain","Serial is busy, retry later!");
}
@ -1144,17 +1121,6 @@ void handle_web_command_silent()
return;
}
String buffer2send = "";
LOG(String (web_interface->web_server.args()))
LOG(" Web silent command\r\n")
#ifdef DEBUG_ESP3D
int nb = web_interface->web_server.args();
for (int i = 0 ; i < nb; i++) {
LOG(web_interface->web_server.argName(i))
LOG(":")
LOG(web_interface->web_server.arg(i))
LOG("\r\n")
}
#endif
String cmd = "";
//int count ;
if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) {
@ -1163,11 +1129,9 @@ void handle_web_command_silent()
} else {
cmd = web_interface->web_server.arg("commandText");
}
LOG("Web Command:")
LOG(cmd)
LOG("\r\n")
log_esp3d("Web Command:%s", cmd.c_str());
} else {
LOG("invalid argument\r\n")
log_esp3d("Invalid argument");
web_interface->web_server.send(200,"text/plain","Invalid command");
return;
}
@ -1200,7 +1164,6 @@ void handle_web_command_silent()
//send command to serial as no need to transfer ESP command
//to avoid any pollution if Uploading file to SDCard
if ((web_interface->blockserial) == false) {
LOG("Send Command\r\n")
//send command
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
web_interface->web_server.send(200,"text/plain","ok");
@ -1222,7 +1185,8 @@ void handle_serial_SDFileList()
web_interface->web_server.send(401, "application/json", "{\"status\":\"Authentication failed!\"}");
return;
}
LOG("serial SD upload done\r\n")
log_esp3d("Serial SD upload done");
String sstatus="Ok";
if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_FAILED)) {
sstatus = "Upload failed";
@ -1251,7 +1215,7 @@ void SDFile_serial_upload()
web_interface->_upload_status=UPLOAD_STATUS_FAILED;
ESPCOM::println (F ("SD upload rejected"), PRINTER_PIPE);
pushError(ESP_ERROR_AUTHENTICATION, "Upload rejected", 401);
LOG("SD upload rejected\r\n");
log_esp3d("SD upload rejected");
} else {
//retrieve current file id
HTTPUpload& upload = (web_interface->web_server).upload();
@ -1260,22 +1224,22 @@ void SDFile_serial_upload()
//**************
if(upload.status == UPLOAD_FILE_START) {
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
LOG("Upload Start\r\n")
log_esp3d("Upload start");
String command = "M29";
String resetcmd = "M110 N0";
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
lineNb=1;
//close any ongoing upload and get current line number
if(!sendLine2Serial (command,1, &lineNb)){
if(!sendLine2Serial (command,-1, &lineNb)){
//it can failed for repetier
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
if(!sendLine2Serial (command,-1, NULL)){
LOG("Start Upload failed")
if(!sendLine2Serial (command,1, NULL)){
log_esp3d("Upload start failed");
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_START_UPLOAD, "Upload rejected");
}
} else {
LOG("Start Upload failed")
log_esp3d("Upload start failed");
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_START_UPLOAD, "Upload rejected");
}
@ -1283,14 +1247,14 @@ void SDFile_serial_upload()
//Mount SD card
command = "M21";
if(!sendLine2Serial (command,-1, NULL)){
LOG("Mounting SD failed")
log_esp3d("Mounting SD failed");
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_MOUNT_SD, "Mounting SD failed");
}
if (web_interface->_upload_status != UPLOAD_STATUS_FAILED) {
//Reset line numbering
if(!sendLine2Serial (resetcmd,-1, NULL)){
LOG("Reset Numbering failed")
log_esp3d("Reset Numbering failed");
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_RESET_NUMBERING, "Reset Numbering failed");
}
@ -1317,11 +1281,11 @@ void SDFile_serial_upload()
//additional purge, in case it is slow to answer
purge_serial();
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
LOG("Creation Ok\r\n")
log_esp3d("Creation Ok");
} else {
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
LOG("Creation failed\r\n");
log_esp3d("Creation failed");
pushError(ESP_ERROR_FILE_CREATION, "File creation failed");
}
}
@ -1335,7 +1299,7 @@ void SDFile_serial_upload()
CONFIG::wait(0);
//it is a comment
if (upload.buf[pos] == ';') {
LOG ("Comment\r\n")
log_esp3d("Comment found");
is_comment = true;
}
//it is an end line
@ -1348,7 +1312,7 @@ void SDFile_serial_upload()
if (current_line.length() > 0 ) {
lineNb++;
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
LOG ("Error sending line\n")
log_esp3d("Error sending line");
CloseSerialUpload (true, current_filename,lineNb);
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
@ -1357,11 +1321,11 @@ void SDFile_serial_upload()
current_line = "";
} else {
LOG ("Empy line\n")
log_esp3d ("Empy line");
}
} else {
//error buffer overload
LOG ("Error over buffer\n")
log_esp3d ("Error over buffer(1)");
lineNb++;
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_BUFFER_OVERFLOW, "Error buffer overflow");
@ -1370,7 +1334,7 @@ void SDFile_serial_upload()
if (current_line.length() < MAX_RESEND_BUFFER) {
current_line += char (upload.buf[pos]); //copy current char to buffer to send/resend
} else {
LOG ("Error over buffer\n")
log_esp3d ("Error over buffer(2)");
lineNb++;
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_BUFFER_OVERFLOW, "Error buffer overflow");
@ -1384,20 +1348,20 @@ void SDFile_serial_upload()
if (current_line.length() > 0) {
lineNb++;
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
LOG ("Error sending buffer\n")
log_esp3d ("Error sending buffer");
lineNb++;
CloseSerialUpload (true, current_filename, lineNb);
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
pushError(ESP_ERROR_FILE_WRITE, "File write failed");
}
}
LOG ("Upload finished ");
log_esp3d ("Upload finished");
lineNb++;
CloseSerialUpload (false, current_filename, lineNb);
//Upload cancelled
//**************
} else { //UPLOAD_FILE_ABORTED
LOG("Error, Something happened\r\n");
log_esp3d("Error, Something happened");
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
//pushError(ESP_ERROR_UPLOAD_CANCELLED, "Upload cancelled");
}

View File

@ -96,29 +96,26 @@ bool purge_serial()
uint8_t buf [51];
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
CONFIG::wait (5);
LOG("Purge Serial\r\n")
log_esp3d("Purge Serial");
while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ) {
if ((millis() - start ) > 2000) {
LOG("Purge timeout\r\n")
log_esp3d("Purge timeout");
return false;
}
size_t len = ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, buf, 50);
buf[len] = '\0';
LOG("Purge: \r\n************\r\n")
LOG((const char *)buf)
LOG("\r\n************\r\n")
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
String s = (const char *)buf;
//repetier never stop sending data so no need to wait if have 'wait' or 'busy'
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
return true;
}
LOG("Purge interrupted\r\n")
log_esp3d("Purge interrupted");
}
CONFIG::wait (5);
}
CONFIG::wait (0);
LOG("Purge done\r\n")
log_esp3d("Purge done");
return true;
}
@ -148,9 +145,7 @@ uint32_t Get_lineNumber(String & response)
//remove potential unwished char
snum.replace("\r", "");
l = snum.toInt();
LOG("Line requested is ")
LOG(String(l))
LOG("\r\n")
log_esp3d("Line requested is %d", l);
return l;
}
@ -158,11 +153,7 @@ uint32_t Get_lineNumber(String & response)
//if newlinenb is NULL no auto correction of line number in case of resend
bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
{
LOG ("Send line ")
LOG (line )
LOG (" NB:")
LOG (String(linenb))
LOG ("\r\n")
log_esp3d ("Send line %d");
String line2send;
String sok = "ok";
String sresend = "Resend:";
@ -172,6 +163,9 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
sresend = "rs N";
}
#ifdef DISABLE_SERIAL_CHECKSUM
linenb = -1;
#endif
if (linenb != -1) {
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
sok+=" " + String(linenb);
@ -182,9 +176,6 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
}
//purge serial as nothing is supposed to interfere with upload
purge_serial();
LOG ("Send line ")
LOG (line2send )
LOG ("\r\n")
//send line
ESPCOM::println (line2send, DEFAULT_PRINTER_PIPE);
ESPCOM::flush(DEFAULT_PRINTER_PIPE);
@ -209,19 +200,16 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
sbuf[len] = '\0';
//use string because easier to handle and allow to re-assemble cutted answer
response += (const char*) sbuf;
LOG ("Response:\r\n************\r\n")
LOG (response)
LOG ("\r\n************\r\n")
//in that case there is no way to know what is the right number to use and so send should be failed
if (( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) && (response.indexOf ("skip") != -1)) {
LOG ("Wrong line requested\r\n")
log_esp3d ("Wrong line requested");
count = 5;
}
//it is resend ?
int pos = response.indexOf (sresend);
//be sure we get full line to be able to process properly
if (( pos > -1) && (response.lastIndexOf("\n") > pos)) {
LOG ("Resend detected\r\n")
log_esp3d ("Resend detected");
uint32_t line_number = Get_lineNumber(response);
//this part is only if have newlinenb variable
if (newlinenb != nullptr) {
@ -232,20 +220,18 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
} else {
//the line requested is not the current one so we stop
if (line_number !=linenb) {
LOG ("Wrong line requested\r\n")
log_esp3d ("Wrong line requested");
count = 5;
}
}
count++;
if (count > 5) {
free(sbuf);
LOG ("Exit too many resend or wrong line\r\n")
log_esp3d ("Exit too many resend or wrong line");
return false;
}
purge_serial();
LOG ("Resend ")
LOG (String(count))
LOG ("\r\n")
log_esp3d ("Resend x%d", count);
response="";
ESPCOM::println (line2send, DEFAULT_PRINTER_PIPE);
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
@ -255,7 +241,7 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
} else {
if ( (response.indexOf (sok) > -1) ) { //we have ok so it is done
free(sbuf);
LOG ("Got ok\r\n")
log_esp3d ("Got ok");
purge_serial();
return true;
}
@ -264,13 +250,13 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
}
//no answer or over buffer exit
if ( (millis() - timeout > 2000) || (response.length() >200)) {
LOG ("Time out\r\n")
log_esp3d("Time out");
done = true;
}
CONFIG::wait (5);
}
}
LOG ("Send line error\r\n")
log_esp3d ("Send line error");
return false;
}