diff --git a/esp3d/bridge.cpp b/esp3d/bridge.cpp index dfa9e51d..8ad4b98e 100644 --- a/esp3d/bridge.cpp +++ b/esp3d/bridge.cpp @@ -27,16 +27,110 @@ WiFiServer * data_server; WiFiClient serverClients[MAX_SRV_CLIENTS]; #endif +bool BRIDGE::header_sent = false; +String BRIDGE::buffer_web = ""; +void BRIDGE::print (const __FlashStringHelper *data, tpipe output){ + String tmp = data; + BRIDGE::print(tmp.c_str(), output); +} +void BRIDGE::print (String & data, tpipe output){ + BRIDGE::print(data.c_str(), output); +} +void BRIDGE::print (const char * data, tpipe output){ + switch(output){ + case SERIAL_PIPE: + header_sent = false; + Serial.print(data); + break; + case SERIAL1_PIPE: + header_sent = false; + Serial1.print(data); + break; +#ifdef TCP_IP_DATA_FEATURE + case TCP_PIPE: + header_sent = false; + BRIDGE::send2TCP(data); + break; +#endif + case WEB_PIPE: + if (!header_sent){ + web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN); + web_interface->WebServer.sendHeader("Content-Type","text/html"); + web_interface->WebServer.sendHeader("Cache-Control","no-cache"); + web_interface->WebServer.send(200); + header_sent = true; + } + buffer_web+=data; + if (buffer_web.length() > 1200) + { + //send data + web_interface->WebServer.sendContent(buffer_web); + //reset buffer + buffer_web=""; + } + break; + default: + break; + } +} +void BRIDGE::println (const __FlashStringHelper *data, tpipe output){ + BRIDGE::print(data,output); +#ifdef TCP_IP_DATA_FEATURE + BRIDGE::print("\r",output); +#endif + BRIDGE::print("\n",output); +} +void BRIDGE::println (String & data, tpipe output){ + BRIDGE::print(data,output); +#ifdef TCP_IP_DATA_FEATURE + BRIDGE::print("\r",output); +#endif + BRIDGE::print("\n",output); +} +void BRIDGE::println (const char * data, tpipe output){ + BRIDGE::print(data,output); +#ifdef TCP_IP_DATA_FEATURE + BRIDGE::print("\r",output); +#endif + BRIDGE::print("\n",output); +} +void BRIDGE::flush (tpipe output){ + switch(output){ + case SERIAL_PIPE: + Serial.flush(); + break; + case SERIAL1_PIPE: + Serial1.flush(); + break; +#ifdef TCP_IP_DATA_FEATURE + case TCP_PIPE: + break; +#endif + case WEB_PIPE: + if(header_sent){ + //send data + web_interface->WebServer.sendContent(buffer_web); + //close line + web_interface->WebServer.sendContent(""); + } + break; + default: + break; + } + header_sent = false; + buffer_web = String(); +} + + #ifdef TCP_IP_DATA_FEATURE void BRIDGE::send2TCP(const __FlashStringHelper *data){ String tmp = data; BRIDGE::send2TCP(tmp.c_str()); } -void BRIDGE::send2TCP(String data){ +void BRIDGE::send2TCP(String & data){ BRIDGE::send2TCP(data.c_str()); } -void BRIDGE::send2TCP(const char * data) -{ +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)); diff --git a/esp3d/bridge.h b/esp3d/bridge.h index d3de9a13..1eaa2eec 100644 --- a/esp3d/bridge.h +++ b/esp3d/bridge.h @@ -29,11 +29,20 @@ extern WiFiServer * data_server; class BRIDGE { public: + static bool header_sent; + static String buffer_web; static bool processFromSerial2TCP(); + static void print (const __FlashStringHelper *data, tpipe output); + static void print (String & data, tpipe output); + static void print (const char * data, tpipe output); + static void println (const __FlashStringHelper *data, tpipe output); + static void println (String & data, tpipe output); + static void println (const char * data, tpipe output); + static void flush (tpipe output); #ifdef TCP_IP_DATA_FEATURE static void processFromTCP2Serial(); static void send2TCP(const __FlashStringHelper *data); - static void send2TCP(String data); + static void send2TCP(String & data); static void send2TCP(const char * data); #endif }; diff --git a/esp3d/command.cpp b/esp3d/command.cpp index 9fca3d12..e8b6aed9 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -32,9 +32,9 @@ String COMMAND::buffer_serial; String COMMAND::buffer_tcp; -#define ERROR_CMD_MSG F("\nM117 Cmd Error") -#define INCORRECT_CMD_MSG F("\nM117 Incorrect Cmd") -#define OK_CMD_MSG F("\nM117 Cmd Ok") +#define ERROR_CMD_MSG F("M117 Cmd Error") +#define INCORRECT_CMD_MSG F("M117 Incorrect Cmd") +#define OK_CMD_MSG F("M117 Cmd Ok") String COMMAND::get_param(String & cmd_params, const char * id, bool withspace) { @@ -92,7 +92,7 @@ bool COMMAND::isadmin(String & cmd_params) } } #endif -void COMMAND::execute_command(int cmd,String cmd_params) +void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) { //manage parameters byte mode = 254; @@ -104,17 +104,17 @@ void COMMAND::execute_command(int cmd,String cmd_params) case 100: parameter = get_param(cmd_params,"", true); if (!CONFIG::isSSIDValid(parameter.c_str())) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } break; //STA Password @@ -122,17 +122,17 @@ void COMMAND::execute_command(int cmd,String cmd_params) case 101: parameter = get_param(cmd_params,"", true); if (!CONFIG::isPasswordValid(parameter.c_str())) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } break; //Hostname @@ -140,17 +140,17 @@ void COMMAND::execute_command(int cmd,String cmd_params) case 102: parameter = get_param(cmd_params,"", true); if (!CONFIG::isHostnameValid(parameter.c_str())) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } break; //Wifi mode (STA/AP) @@ -162,18 +162,18 @@ void COMMAND::execute_command(int cmd,String cmd_params) } else if (parameter == "AP") { mode = AP_MODE; } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } if ((mode == CLIENT_MODE) || (mode == AP_MODE)) { #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } } break; @@ -186,18 +186,18 @@ void COMMAND::execute_command(int cmd,String cmd_params) } else if (parameter == "DHCP") { mode = DHCP_MODE; } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) { #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } } break; @@ -206,17 +206,17 @@ void COMMAND::execute_command(int cmd,String cmd_params) case 105: parameter = get_param(cmd_params,"", true); if (!CONFIG::isSSIDValid(parameter.c_str())) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } break; //AP Password @@ -224,17 +224,17 @@ void COMMAND::execute_command(int cmd,String cmd_params) case 106: parameter = get_param(cmd_params,"", true); if (!CONFIG::isPasswordValid(parameter.c_str())) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } break; //AP IP mode (DHCP/STATIC) @@ -246,18 +246,18 @@ void COMMAND::execute_command(int cmd,String cmd_params) } else if (parameter == "DHCP") { mode = DHCP_MODE; } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) { #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } else { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } } break; @@ -270,10 +270,8 @@ void COMMAND::execute_command(int cmd,String cmd_params) } else { currentIP=WiFi.softAPIP().toString(); } - Serial.print("\n\r"); - Serial.print(cmd_params); - Serial.println(currentIP); - Serial.print("\r\n"); + BRIDGE::print(cmd_params, output); + BRIDGE::println(currentIP, output); LOG(cmd_params) LOG(currentIP) LOG("\r\n") @@ -286,10 +284,8 @@ void COMMAND::execute_command(int cmd,String cmd_params) if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) { shost=wifi_config.get_default_hostname(); } - Serial.print("\n\r"); - Serial.print(cmd_params); - Serial.println(shost); - Serial.print("\r\n"); + BRIDGE::print(cmd_params, output); + BRIDGE::println(shost, output); LOG(cmd_params) LOG(shost) LOG("\r\n") @@ -306,7 +302,7 @@ void COMMAND::execute_command(int cmd,String cmd_params) LOG(parameter) LOG("\r\n") if (parameter == "") { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else { int pin = parameter.toInt(); //check pin is valid and not serial used pins @@ -337,7 +333,7 @@ void COMMAND::execute_command(int cmd,String cmd_params) } int value = digitalRead(pin); LOG("Read:"); - Serial.println(String(value)); + BRIDGE::println(String(value).c_str(), output); } else { //it is a set int value = parameter.toInt(); @@ -350,11 +346,11 @@ void COMMAND::execute_command(int cmd,String cmd_params) LOG("\r\n") digitalWrite(pin, (value == 0)?LOW:HIGH); } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } } } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } } } @@ -368,7 +364,7 @@ void COMMAND::execute_command(int cmd,String cmd_params) parameter = get_param(cmd_params,"", true); #ifdef AUTHENTICATION_FEATURE if (!isadmin(cmd_params)) { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif { @@ -383,7 +379,7 @@ void COMMAND::execute_command(int cmd,String cmd_params) } } if (parameter=="CONFIG") { - CONFIG::print_config(); + CONFIG::print_config(output); } break; #ifdef AUTHENTICATION_FEATURE @@ -394,23 +390,23 @@ void COMMAND::execute_command(int cmd,String cmd_params) parameter = get_param(cmd_params,"", true); if (parameter.length() == 0) { if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } else { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } } else { if (CONFIG::isLocalPasswordValid(parameter.c_str())) { if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) { - Serial.println(OK_CMD_MSG); + BRIDGE::println(OK_CMD_MSG, output); } else { - Serial.println(ERROR_CMD_MSG); + BRIDGE::println(ERROR_CMD_MSG, output); } } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } } } else { - Serial.println(INCORRECT_CMD_MSG); + BRIDGE::println(INCORRECT_CMD_MSG, output); } break; } @@ -449,9 +445,9 @@ void COMMAND::execute_command(int cmd,String cmd_params) //get fw version //[ESP800]
case 800: - Serial.print(cmd_params); - Serial.print("\nFW version:"); - Serial.println(FW_VERSION); + BRIDGE::print(cmd_params, output); + BRIDGE::print("FW version:", output); + BRIDGE::println(FW_VERSION, output); break; //clear status/error/info list //[ESP999] @@ -485,16 +481,15 @@ void COMMAND::execute_command(int cmd,String cmd_params) } break; //default: - } } -void COMMAND::check_command(String buffer, bool handlelockserial) +void COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) { String buffer2; LOG("Check Command:") LOG(buffer) - LOG("\r\n") + LOG("\r\n") //if direct access to SDCard no need to handle the M20 command answer #ifndef DIRECT_SDCARD_FEATURE static bool bfileslist=false; @@ -576,7 +571,7 @@ void COMMAND::check_command(String buffer, bool handlelockserial) } //if command is a valid number then execute command if(cmd_part1.toInt()!=0) { - execute_command(cmd_part1.toInt(),cmd_part2); + execute_command(cmd_part1.toInt(),cmd_part2,output); } //if not is not a valid [ESPXXX] command } @@ -717,7 +712,7 @@ void COMMAND::read_buffer_tcp(uint8_t b) iscomment = false; //Minimum is something like M10 so 3 char if (buffer_tcp.length()>3) { - check_command(buffer_tcp); + check_command(buffer_tcp, TCP_PIPE); } } } @@ -751,7 +746,7 @@ void COMMAND::read_buffer_serial(uint8_t b) iscomment = false; //Minimum is something like M10 so 3 char if (buffer_serial.length()>3) { - check_command(buffer_serial); + check_command(buffer_serial, SERIAL_PIPE); } } } diff --git a/esp3d/command.h b/esp3d/command.h index c6f74f45..64e56aec 100644 --- a/esp3d/command.h +++ b/esp3d/command.h @@ -21,6 +21,7 @@ #ifndef COMMAND_h #define COMMAND_h #include +#include "bridge.h" class COMMAND { @@ -30,8 +31,8 @@ public: static void read_buffer_serial(uint8_t *b, size_t len); static void read_buffer_serial(uint8_t b); static void read_buffer_tcp(uint8_t b); - static void check_command(String buffer,bool handlelockserial = true); - static void execute_command(int cmd,String cmd_params); + static void check_command(String buffer, tpipe output, bool handlelockserial = true); + static void execute_command(int cmd,String cmd_params, tpipe output); static String get_param(String & cmd_params, const char * id, bool withspace = false); static bool isadmin(String & cmd_params); diff --git a/esp3d/config.cpp b/esp3d/config.cpp index f6f27a55..c28039d3 100644 --- a/esp3d/config.cpp +++ b/esp3d/config.cpp @@ -23,7 +23,7 @@ extern "C" { #include "user_interface.h" } - +#include "bridge.h" void CONFIG::esp_restart() { @@ -489,7 +489,7 @@ bool CONFIG::reset_config() return true; } -void CONFIG::print_config() +void CONFIG::print_config(tpipe output) { //use biggest size for buffer char sbuf[MAX_PASSWORD_LENGTH+1]; @@ -497,317 +497,317 @@ void CONFIG::print_config() byte bbuf=0; int ibuf=0; if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGTH)) { - Serial.print(F("Baud rate: ")); - Serial.println(ibuf); + BRIDGE::print(F("Baud rate: "), output); + BRIDGE::println(String(ibuf).c_str(), output); } else { - Serial.println(F("Error reading baud rate")); + BRIDGE::println(F("Error reading baud rate"), output); } if (CONFIG::read_byte(EP_SLEEP_MODE, &bbuf )) { - Serial.print(F("Sleep mode: ")); + BRIDGE::print(F("Sleep mode: "), output); if (byte(bbuf)==WIFI_NONE_SLEEP) { - Serial.println(F("None")); + BRIDGE::println(F("None"), output); } else if (byte(bbuf)==WIFI_LIGHT_SLEEP) { - Serial.println(F("Light")); + BRIDGE::println(F("Light"), output); } else if (byte(bbuf)==WIFI_MODEM_SLEEP) { - Serial.println(F("Modem")); + BRIDGE::println(F("Modem"), output); } else { - Serial.println(F("???")); + BRIDGE::println(F("???"), output); } } else { - Serial.println(F("Error reading sleep mode")); + BRIDGE::println(F("Error reading sleep mode"), output); } if (CONFIG::read_string(EP_HOSTNAME, sbuf , MAX_HOSTNAME_LENGTH)) { - Serial.print(F("Hostname: ")); - Serial.println(sbuf); + BRIDGE::print(F("Hostname: "), output); + BRIDGE::println(sbuf, output); } else { - Serial.println(F("Error reading hostname")); + BRIDGE::println(F("Error reading hostname"), output); } if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) { - Serial.print(F("Mode: ")); + BRIDGE::print(F("Mode: "), output); if (byte(bbuf) == CLIENT_MODE) { - Serial.println(F("Station")); - Serial.print(F("Signal: ")); - Serial.print(wifi_config.getSignal(WiFi.RSSI())); - Serial.println(F("%")); + BRIDGE::println(F("Station"), output); + BRIDGE::print(F("Signal: "), output); + BRIDGE::print(String(wifi_config.getSignal(WiFi.RSSI())).c_str(), output); + BRIDGE::println(F("%"), output); } else if (byte(bbuf)==AP_MODE) { - Serial.println(F("Access Point")); + BRIDGE::println(F("Access Point"), output); } else { - Serial.println("???"); + BRIDGE::println("???", output); } } else { - Serial.println(F("Error reading mode")); + BRIDGE::println(F("Error reading mode"), output); } if (CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) { - Serial.print(F("Client SSID: ")); - Serial.println(sbuf); + BRIDGE::print(F("Client SSID: "), output); + BRIDGE::println(sbuf, output); } else { - Serial.println(F("Error reading SSID")); + BRIDGE::println(F("Error reading SSID"), output); } if (CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) { - Serial.print(F("STA IP Mode: ")); + BRIDGE::print(F("STA IP Mode: "), output); if (byte(bbuf)==STATIC_IP_MODE) { - Serial.println(F("Static")); + BRIDGE::println(F("Static"), output); if (CONFIG::read_buffer(EP_STA_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) { - Serial.print(F("IP: ")); - Serial.println(IPAddress(ipbuf).toString()); + BRIDGE::print(F("IP: "), output); + BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); } else { - Serial.println(F("Error reading IP")); + BRIDGE::println(F("Error reading IP"), output); } if (CONFIG::read_buffer(EP_STA_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) { - Serial.print(F("Subnet: ")); - Serial.println(IPAddress(ipbuf).toString()); + BRIDGE::print(F("Subnet: "), output); + BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); } else { - Serial.println(F("Error reading subnet")); + BRIDGE::println(F("Error reading subnet"), output); } if (CONFIG::read_buffer(EP_STA_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) { - Serial.print(F("Gateway: ")); - Serial.println(IPAddress(ipbuf).toString()); + BRIDGE::print(F("Gateway: "), output); + BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); } else { - Serial.println(F("Error reading gateway")); + BRIDGE::println(F("Error reading gateway"), output); } } else if (byte(bbuf)==DHCP_MODE) { - Serial.println(F("DHCP")); + BRIDGE::println(F("DHCP"), output); } else { - Serial.println(F("???")); + BRIDGE::println(F("???"), output); } } else { - Serial.println(F("Error reading IP mode")); + BRIDGE::println(F("Error reading IP mode"), output); } if (CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) { - Serial.print(F("STA Phy mode: ")); + BRIDGE::print(F("STA Phy mode: "), output); if (byte(bbuf)==WIFI_PHY_MODE_11B) { - Serial.println(F("11b")); + BRIDGE::println(F("11b"), output); } else if (byte(bbuf)==WIFI_PHY_MODE_11G) { - Serial.println(F("11g")); + BRIDGE::println(F("11g"), output); } else if (byte(bbuf)==WIFI_PHY_MODE_11N) { - Serial.println(F("11n")); + BRIDGE::println(F("11n"), output); } else { - Serial.println(F("???")); + BRIDGE::println(F("???"), output); } } else { - Serial.println(F("Error reading phy mode")); + BRIDGE::println(F("Error reading phy mode"), output); } if (CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) { - Serial.print(F("AP SSID: ")); - Serial.println(sbuf); + BRIDGE::print(F("AP SSID: "), output); + BRIDGE::println(sbuf, output); } else { - Serial.println(F("Error reading SSID")); + BRIDGE::println(F("Error reading SSID"), output); } if (CONFIG::read_byte(EP_AP_IP_MODE, &bbuf )) { - Serial.print(F("AP IP Mode: ")); + BRIDGE::print(F("AP IP Mode: "), output); if (byte(bbuf)==STATIC_IP_MODE) { - Serial.println(F("Static")); + BRIDGE::println(F("Static"), output); if (CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) { - Serial.print(F("IP: ")); - Serial.println(IPAddress(ipbuf).toString()); + BRIDGE::print(F("IP: "), output); + BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); } else { - Serial.println(F("Error reading IP")); + BRIDGE::println(F("Error reading IP"), output); } if (CONFIG::read_buffer(EP_AP_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) { - Serial.print(F("Subnet: ")); - Serial.println(IPAddress(ipbuf).toString()); + BRIDGE::print(F("Subnet: "), output); + BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); } else { - Serial.println(F("Error reading subnet")); + BRIDGE::println(F("Error reading subnet"), output); } if (CONFIG::read_buffer(EP_AP_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) { - Serial.print(F("Gateway: ")); - Serial.println(IPAddress(ipbuf).toString()); + BRIDGE::print(F("Gateway: "), output); + BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); } else { - Serial.println(F("Error reading gateway")); + BRIDGE::println(F("Error reading gateway"), output); } } else if (byte(bbuf)==DHCP_MODE) { - Serial.println(F("DHCP")); + BRIDGE::println(F("DHCP"), output); } else { - Serial.println(intTostr(bbuf)); - Serial.println(F("???")); + BRIDGE::println(intTostr(bbuf), output); + BRIDGE::println(F("???"), output); } } else { - Serial.println(F("Error reading IP mode")); + BRIDGE::println(F("Error reading IP mode"), output); } if (CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) { - Serial.print(F("AP Phy mode: ")); + BRIDGE::print(F("AP Phy mode: "), output); if (byte(bbuf)==WIFI_PHY_MODE_11B) { - Serial.println(F("11b")); + BRIDGE::println(F("11b"), output); } else if (byte(bbuf)==WIFI_PHY_MODE_11G) { - Serial.println(F("11g")); + BRIDGE::println(F("11g"), output); } else if (byte(bbuf)==WIFI_PHY_MODE_11N) { - Serial.println(F("11n")); + BRIDGE::println(F("11n"), output); } else { - Serial.println(F("???")); + BRIDGE::println(F("???"), output); } } else { - Serial.println(F("Error reading phy mode")); + BRIDGE::println(F("Error reading phy mode"), output); } if (CONFIG::read_byte(EP_CHANNEL, &bbuf )) { - Serial.print(F("Channel: ")); - Serial.println(byte(bbuf)); + BRIDGE::print(F("Channel: "), output); + BRIDGE::println(String(byte(bbuf)).c_str(), output); } else { - Serial.println(F("Error reading channel")); + BRIDGE::println(F("Error reading channel"), output); } if (CONFIG::read_byte(EP_AUTH_TYPE, &bbuf )) { - Serial.print(F("Authentification: ")); + BRIDGE::print(F("Authentification: "), output); if (byte(bbuf)==AUTH_OPEN) { - Serial.println(F("None")); + BRIDGE::println(F("None"), output); } else if (byte(bbuf)==AUTH_WEP) { - Serial.println(F("WEP")); + BRIDGE::println(F("WEP"), output); } else if (byte(bbuf)==AUTH_WPA_PSK) { - Serial.println(F("WPA")); + BRIDGE::println(F("WPA"), output); } else if (byte(bbuf)==AUTH_WPA2_PSK) { - Serial.println(F("WPA2")); + BRIDGE::println(F("WPA2"), output); } else if (byte(bbuf)==AUTH_WPA_WPA2_PSK) { - Serial.println(F("WPA/WPA2")); + BRIDGE::println(F("WPA/WPA2"), output); } else { - Serial.println(F("???")); + BRIDGE::println(F("???"), output); } } else { - Serial.println(F("Error reading authentification")); + BRIDGE::println(F("Error reading authentification"), output); } if (CONFIG::read_byte(EP_SSID_VISIBLE, &bbuf )) { - Serial.print(F("SSID visibility: ")); + BRIDGE::print(F("SSID visibility: "), output); if (bbuf==0) { - Serial.println(F("Hidden")); + BRIDGE::println(F("Hidden"), output); } else if (bbuf==1) { - Serial.println(F("Visible")); + BRIDGE::println(F("Visible"), output); } else { - Serial.println(bbuf); + BRIDGE::println(String(bbuf).c_str(), output); } } else { - Serial.println(F("Error reading SSID visibility")); + BRIDGE::println(F("Error reading SSID visibility"), output); } if (CONFIG::read_buffer(EP_WEB_PORT, (byte *)&ibuf , INTEGER_LENGTH)) { - Serial.print(F("Web port: ")); - Serial.println(ibuf); + BRIDGE::print(F("Web port: "), output); + BRIDGE::println(String(ibuf).c_str(), output); } else { - Serial.println(F("Error reading web port")); + BRIDGE::println(F("Error reading web port"), output); } - Serial.print(F("Data port: ")); + BRIDGE::print(F("Data port: "), output); #ifdef TCP_IP_DATA_FEATURE if (CONFIG::read_buffer(EP_DATA_PORT, (byte *)&ibuf , INTEGER_LENGTH)) { - Serial.println(ibuf); + BRIDGE::println(String(ibuf).c_str(), output); } else { - Serial.println(F("Error reading data port")); + BRIDGE::println(F("Error reading data port"), output); } #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif if (CONFIG::read_byte(EP_REFRESH_PAGE_TIME, &bbuf )) { - Serial.print(F("Web page refresh time: ")); - Serial.println(byte(bbuf)); + BRIDGE::print(F("Web page refresh time: "), output); + BRIDGE::println(String(byte(bbuf)).c_str(), output); } else { - Serial.println(F("Error reading refresh page")); + BRIDGE::println(F("Error reading refresh page"), output); } if (CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) { - Serial.print(F("XY feed rate: ")); - Serial.println(ibuf); + BRIDGE::print(F("XY feed rate: "), output); + BRIDGE::println(String(ibuf).c_str(), output); } else { - Serial.println(F("Error reading XY feed rate")); + BRIDGE::println(F("Error reading XY feed rate"), output); } if (CONFIG::read_buffer(EP_Z_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) { - Serial.print(F("Z feed rate: ")); - Serial.println(ibuf); + BRIDGE::print(F("Z feed rate: "), output); + BRIDGE::println(String(ibuf).c_str(), output); } else { - Serial.println(F("Error reading Z feed rate")); + BRIDGE::println(F("Error reading Z feed rate"), output); } if (CONFIG::read_buffer(EP_E_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) { - Serial.print(F("E feed rate: ")); - Serial.println(ibuf); + BRIDGE::print(F("E feed rate: "), output); + BRIDGE::println(String(ibuf).c_str(), output); } else { - Serial.println(F("Error reading E feed rate")); + BRIDGE::println(F("Error reading E feed rate"), output); } - Serial.print(F("Free memory: ")); - Serial.println(formatBytes(ESP.getFreeHeap())); + BRIDGE::print(F("Free memory: "), output); + BRIDGE::println(formatBytes(ESP.getFreeHeap()).c_str(), output); - Serial.print(F("Captive portal: ")); + BRIDGE::print(F("Captive portal: "), output); #ifdef CAPTIVE_PORTAL_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("SSDP: ")); + BRIDGE::print(F("SSDP: "), output); #ifdef SSDP_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("NetBios: ")); + BRIDGE::print(F("NetBios: "), output); #ifdef NETBIOS_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("mDNS: ")); + BRIDGE::print(F("mDNS: "), output); #ifdef MDNS_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("Web update: ")); + BRIDGE::print(F("Web update: "), output); #ifdef WEB_UPDATE_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("Pin 2 Recovery: ")); + BRIDGE::print(F("Pin 2 Recovery: "), output); #ifdef RECOVERY_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("Authentication: ")); + BRIDGE::print(F("Authentication: "), output); #ifdef AUTHENTICATION_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif - Serial.print(F("Target Firmware: ")); + BRIDGE::print(F("Target Firmware: "), output); #if FIRMWARE_TARGET == REPETIER - Serial.println(F("Repetier")); + BRIDGE::println(F("Repetier"), output); #elif FIRMWARE_TARGET == REPETIER4DV - Serial.println(F("Repetier for DaVinci")); + BRIDGE::println(F("Repetier for DaVinci"), output); #elif FIRMWARE_TARGET == MALRLIN - Serial.println(F("Marlin")); + BRIDGE::println(F("Marlin"), output); #elif FIRMWARE_TARGET == SMOOTHIEWARE - Serial.println(F("Smoothieware")); + BRIDGE::println(F("Smoothieware"), output); #else - Serial.println(F("???")); + BRIDGE::println(F("???"), output); #endif - Serial.print(F("SD Card support: ")); + BRIDGE::print(F("SD Card support: "), output); #ifdef SDCARD_FEATURE - Serial.println(F("Enabled")); + BRIDGE::println(F("Enabled"), output); #else - Serial.println(F("Disabled")); + BRIDGE::println(F("Disabled"), output); #endif #ifdef DEBUG_ESP3D - Serial.print(F("Debug Enabled :")); + BRIDGE::print(F("Debug Enabled :"), output); #ifdef DEBUG_OUTPUT_SPIFFS - Serial.println(F("SPIFFS")); + BRIDGE::println(F("SPIFFS"), output); #endif #ifdef DEBUG_OUTPUT_SD - Serial.println(F("SD")); + BRIDGE::println(F("SD"), output); #endif #ifdef DEBUG_OUTPUT_SERIAL - Serial.println(F("serial")); + BRIDGE::println(F("serial"), output); #endif #ifdef DEBUG_OUTPUT_TCP - Serial.println(F("TCP")); + BRIDGE::println(F("TCP"), output); #endif #endif } diff --git a/esp3d/config.h b/esp3d/config.h index dda730ab..e324c638 100644 --- a/esp3d/config.h +++ b/esp3d/config.h @@ -20,10 +20,10 @@ //definition #define REPETIER 0 -#define REPETIER4DV 1 +#define REPETIER4DV 1 #define MARLIN 2 #define MARLINKIMBRA 3 -#define SMOOTHIEWARE 4 +#define SMOOTHIEWARE 4 //FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware) #define FIRMWARE_TARGET REPETIER4DV @@ -102,6 +102,7 @@ //Serial rx buffer size is 256 but can be extended #define SERIAL_RX_BUFFER_SIZE 512 + //DEBUG Flag do not do this when connected to printer !!! //#define DEBUG_ESP3D //#define DEBUG_OUTPUT_SPIFFS @@ -158,9 +159,18 @@ extern "C" { } #include "wifi.h" //version and sources location -#define FW_VERSION "0.9.71" +#define FW_VERSION "0.9.72" #define REPOSITORY "https://github.com/luc-github/ESP3D" +typedef enum { + NO_PIPE = 0, + SERIAL_PIPE = 2, + SERIAL1_PIPE = 3, +#ifdef TCP_IP_DATA_FEATURE + TCP_PIPE = 4, +#endif + WEB_PIPE = 5 + } tpipe; //flags #define AP_MODE 1 @@ -259,7 +269,7 @@ public: static bool write_buffer(int pos, const byte * byte_buffer, int size_buffer); static bool write_byte(int pos, const byte value); static bool reset_config(); - static void print_config(); + static void print_config(tpipe output); static bool isHostnameValid(const char * hostname); static bool isSSIDValid(const char * ssid); static bool isPasswordValid(const char * password); diff --git a/esp3d/esp3d.ino.generic.bin b/esp3d/esp3d.ino.generic.bin new file mode 100644 index 00000000..83cedfa8 Binary files /dev/null and b/esp3d/esp3d.ino.generic.bin differ diff --git a/esp3d/webinterface.cpp b/esp3d/webinterface.cpp index 00ad8bfd..64cdfc63 100644 --- a/esp3d/webinterface.cpp +++ b/esp3d/webinterface.cpp @@ -3407,7 +3407,8 @@ void handle_web_command(){ } //if command is a valid number then execute command if(cmd_part1.toInt()!=0) { - COMMAND::execute_command(cmd_part1.toInt(),cmd_part2); + COMMAND::execute_command(cmd_part1.toInt(),cmd_part2,WEB_PIPE); + BRIDGE::flush(WEB_PIPE); } //if not is not a valid [ESPXXX] command } @@ -3479,7 +3480,7 @@ void handle_web_command(){ LOG(current_line) LOG("\r\n") //check command - COMMAND::check_command(current_line,false); + COMMAND::check_command(current_line, NO_PIPE, false); #if ((FIRMWARE_TARGET == REPETIER) || (FIRMWARE_TARGET == REPETIER4DV)) if (!current_line.startsWith( "ok ")) #endif