Update Readme

Apply style to code
This commit is contained in:
Luc 2019-06-21 19:10:33 +02:00
parent 4d6bac193a
commit 02264b8da5
17 changed files with 1203 additions and 1077 deletions

View File

@ -88,7 +88,7 @@ Check wiki : https://github.com/luc-github/ESP3D/wiki/Direct-ESP3D-commands
Feedback on 2.0 was : ESP3D being a library is not really useful and make setup more complex, so now we are back to simple application. Feedback on 2.0 was : ESP3D being a library is not really useful and make setup more complex, so now we are back to simple application.
1. Please follow installation of the ESP core you want to use : [ESP8266 core version](https://github.com/esp8266/Arduino) or [ESP32 core version](https://github.com/espressif/arduino-esp32) 1. Please follow installation of the ESP core you want to use : [ESP8266 core version](https://github.com/esp8266/Arduino) or [ESP32 core version](https://github.com/espressif/arduino-esp32)
2. Add libraries 2. Add manually libraries present in libraries directory -these versions are verified to work with ESP3D
If you want async webserver (currently not recommended due to reliability issues): If you want async webserver (currently not recommended due to reliability issues):
* ESPAsyncWebServer from @me-no-dev * ESPAsyncWebServer from @me-no-dev
if you target ESP8266 if you target ESP8266
@ -98,14 +98,14 @@ if you target ESP32:
Specific for ESP32 Specific for ESP32
* ESP32SSDP * ESP32SSDP
If you want sync webserver (recommended as stable): If you want sync webserver (recommended as stable):
* arduinoWebSockets fron @Links2004 * arduinoWebSockets from @Links2004
If you want OLED support: If you want OLED support:
* oled-ssd1306 from @squix78 * oled-ssd1306 from @squix78
If you want DHT11/22 support: If you want DHT11/22 support:
* DHT_sensor_library_for_ESPx from @beegee-tokyo * DHT_sensor_library_for_ESPx from @beegee-tokyo
3. Compile project from examples\basicesp3d\basicesp3d.ino) according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled. 3. Compile project esp3d.ino according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled.
* for ESP8266 set CPU freq to 160MHz for better (https://github.com/luc-github/ESP3D/wiki/Install-Instructions) * for ESP8266 set CPU freq to 160MHz for better (https://github.com/luc-github/ESP3D/wiki/Install-Instructions)
4. Upload the data content on ESP3D file system 4. Upload the data content on ESP3D file system
* Using SPIFFS uploader, this plugin and install instructions is available on each ESP core - please refere to it * Using SPIFFS uploader, this plugin and install instructions is available on each ESP core - please refere to it

View File

@ -48,11 +48,11 @@
#include "espcom.h" #include "espcom.h"
#ifdef SSDP_FEATURE #ifdef SSDP_FEATURE
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <ESP32SSDP.h> #include <ESP32SSDP.h>
#else #else
#include <ESP8266SSDP.h> #include <ESP8266SSDP.h>
#endif #endif
#endif #endif
//embedded response file if no files on SPIFFS //embedded response file if no files on SPIFFS
@ -61,7 +61,7 @@ bool can_process_serial = true;
extern bool deleteRecursive(String path); extern bool deleteRecursive(String path);
extern bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb); extern bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb);
extern void CloseSerialUpload (bool iserror, String & filename , int32_t linenb); extern void CloseSerialUpload (bool iserror, String & filename, int32_t linenb);
extern bool purge_serial(); extern bool purge_serial();
extern long id_connection; extern long id_connection;
@ -710,7 +710,9 @@ void handle_web_command (AsyncWebServerRequest *request)
ESPCOM::processFromSerial (true); ESPCOM::processFromSerial (true);
LOG ("End PurgeSerial\r\n") LOG ("End PurgeSerial\r\n")
can_process_serial = false; can_process_serial = false;
request->onDisconnect([request](){can_process_serial = true;}); request->onDisconnect([request]() {
can_process_serial = true;
});
//send command //send command
LOG ("Send Command\r\n") LOG ("Send Command\r\n")
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE); ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
@ -1112,13 +1114,15 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
LOG("Upload Start\r\n") LOG("Upload Start\r\n")
String command = "M29"; String command = "M29";
String resetcmd = "M110 N0"; String resetcmd = "M110 N0";
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110"; if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
resetcmd = "N0 M110";
}
lineNb=1; lineNb=1;
//close any ongoing upload and get current line number //close any ongoing upload and get current line number
if(!sendLine2Serial (command,1, &lineNb)){ if(!sendLine2Serial (command,1, &lineNb)) {
//it can failed for repetier //it can failed for repetier
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) { if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
if(!sendLine2Serial (command,-1, NULL)){ if(!sendLine2Serial (command,-1, NULL)) {
LOG("Start Upload failed") LOG("Start Upload failed")
web_interface->_upload_status= UPLOAD_STATUS_FAILED; web_interface->_upload_status= UPLOAD_STATUS_FAILED;
return; return;
@ -1131,13 +1135,13 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
} }
//Mount SD card //Mount SD card
command = "M21"; command = "M21";
if(!sendLine2Serial (command,-1, NULL)){ if(!sendLine2Serial (command,-1, NULL)) {
LOG("Mounting SD failed") LOG("Mounting SD failed")
web_interface->_upload_status= UPLOAD_STATUS_FAILED; web_interface->_upload_status= UPLOAD_STATUS_FAILED;
return; return;
} }
//Reset line numbering //Reset line numbering
if(!sendLine2Serial (resetcmd,-1, NULL)){ if(!sendLine2Serial (resetcmd,-1, NULL)) {
LOG("Reset Numbering failed") LOG("Reset Numbering failed")
web_interface->_upload_status= UPLOAD_STATUS_FAILED; web_interface->_upload_status= UPLOAD_STATUS_FAILED;
return; return;
@ -1158,7 +1162,7 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
command = "M28 " + current_filename; command = "M28 " + current_filename;
//send start upload //send start upload
//no correction allowed because it means reset numbering was failed //no correction allowed because it means reset numbering was failed
if (sendLine2Serial(command, lineNb, NULL)){ if (sendLine2Serial(command, lineNb, NULL)) {
CONFIG::wait(1200); CONFIG::wait(1200);
//additional purge, in case it is slow to answer //additional purge, in case it is slow to answer
purge_serial(); purge_serial();
@ -1253,7 +1257,7 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
//on event connect function //on event connect function
void handle_onevent_connect(AsyncEventSourceClient *client) void handle_onevent_connect(AsyncEventSourceClient *client)
{ {
if (!client->lastId()){ if (!client->lastId()) {
//Init active ID //Init active ID
id_connection++; id_connection++;
client->send(String(id_connection).c_str(), "InitID", id_connection, 1000); client->send(String(id_connection).c_str(), "InitID", id_connection, 1000);
@ -1262,7 +1266,8 @@ void handle_onevent_connect(AsyncEventSourceClient *client)
} }
} }
void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)
{
//Handle WebSocket event //Handle WebSocket event
} }

View File

@ -28,7 +28,7 @@
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include "SPIFFS.h" #include "SPIFFS.h"
#define MAX_GPIO 37 #define MAX_GPIO 37
int ChannelAttached2Pin[16]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; int ChannelAttached2Pin[16]= {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
#else #else
#define MAX_GPIO 16 #define MAX_GPIO 16
#endif #endif
@ -150,17 +150,12 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
LOG("you are User\r\n"); LOG("you are User\r\n");
} }
#ifdef DEBUG_ESP3D #ifdef DEBUG_ESP3D
if ( auth_type == LEVEL_ADMIN) if ( auth_type == LEVEL_ADMIN) {
{
LOG("admin identified\r\n"); LOG("admin identified\r\n");
} } else {
else { if( auth_type == LEVEL_USER) {
if( auth_type == LEVEL_USER)
{
LOG("user identified\r\n"); LOG("user identified\r\n");
} } else {
else
{
LOG("guest identified\r\n"); LOG("guest identified\r\n");
} }
} }
@ -458,15 +453,25 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
time(&now); time(&now);
localtime_r(&now, &tmstruct); localtime_r(&now, &tmstruct);
stmp = String((tmstruct.tm_year)+1900) + "-"; stmp = String((tmstruct.tm_year)+1900) + "-";
if (((tmstruct.tm_mon)+1) < 10) stmp +="0"; if (((tmstruct.tm_mon)+1) < 10) {
stmp +="0";
}
stmp += String(( tmstruct.tm_mon)+1) + "-"; stmp += String(( tmstruct.tm_mon)+1) + "-";
if (tmstruct.tm_mday < 10) stmp +="0"; if (tmstruct.tm_mday < 10) {
stmp +="0";
}
stmp += String(tmstruct.tm_mday) + " "; stmp += String(tmstruct.tm_mday) + " ";
if (tmstruct.tm_hour < 10) stmp +="0"; if (tmstruct.tm_hour < 10) {
stmp +="0";
}
stmp += String(tmstruct.tm_hour) + ":"; stmp += String(tmstruct.tm_hour) + ":";
if (tmstruct.tm_min < 10) stmp +="0"; if (tmstruct.tm_min < 10) {
stmp +="0";
}
stmp += String(tmstruct.tm_min) + ":"; stmp += String(tmstruct.tm_min) + ":";
if (tmstruct.tm_sec < 10) stmp +="0"; if (tmstruct.tm_sec < 10) {
stmp +="0";
}
stmp += String(tmstruct.tm_sec); stmp += String(tmstruct.tm_sec);
ESPCOM::println(stmp.c_str(), output, espresponse); ESPCOM::println(stmp.c_str(), output, espresponse);
} }
@ -507,8 +512,8 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
parameter = get_param (cmd_params, "CLEARCHANNELS=", false); parameter = get_param (cmd_params, "CLEARCHANNELS=", false);
if (parameter == "YES") { if (parameter == "YES") {
for (uint8_t p = 0; p < 16;p++){ for (uint8_t p = 0; p < 16; p++) {
if(ChannelAttached2Pin[p] != -1){ if(ChannelAttached2Pin[p] != -1) {
ledcDetachPin(ChannelAttached2Pin[p]); ledcDetachPin(ChannelAttached2Pin[p]);
ChannelAttached2Pin[p] = -1; ChannelAttached2Pin[p] = -1;
} }
@ -535,21 +540,21 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
LOG ("Set as input pull up\r\n") LOG ("Set as input pull up\r\n")
pinMode (pin, INPUT_PULLUP); pinMode (pin, INPUT_PULLUP);
} }
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
else { else {
LOG ("Set as input pull down 16\r\n") LOG ("Set as input pull down 16\r\n")
pinMode (pin, INPUT_PULLDOWN_16); pinMode (pin, INPUT_PULLDOWN_16);
} }
#endif #endif
} }
} }
value = digitalRead (pin); value = digitalRead (pin);
} else { } else {
#ifdef ARDUINO_ARCH_ESP8266 //only one ADC on ESP8266 A0 #ifdef ARDUINO_ARCH_ESP8266 //only one ADC on ESP8266 A0
value = analogRead (A0); value = analogRead (A0);
#else #else
value = analogRead (pin); value = analogRead (pin);
#endif #endif
} }
LOG ("Read:"); LOG ("Read:");
LOG (String (value).c_str() ) LOG (String (value).c_str() )
@ -584,21 +589,21 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
LOG ("Set:") LOG ("Set:")
LOG (String ( value) ) LOG (String ( value) )
LOG ("\r\n") LOG ("\r\n")
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
analogWriteRange(analog_range); analogWriteRange(analog_range);
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
analogWrite(pin, value); analogWrite(pin, value);
#else #else
int channel = -1; int channel = -1;
for (uint8_t p = 0; p < 16;p++){ for (uint8_t p = 0; p < 16; p++) {
if(ChannelAttached2Pin[p] == pin){ if(ChannelAttached2Pin[p] == pin) {
channel = p; channel = p;
} }
} }
if (channel==-1){ if (channel==-1) {
for (uint8_t p = 0; p < 16;p++){ for (uint8_t p = 0; p < 16; p++) {
if(ChannelAttached2Pin[p] == -1){ if(ChannelAttached2Pin[p] == -1) {
channel = p; channel = p;
ChannelAttached2Pin[p] = pin; ChannelAttached2Pin[p] = pin;
p = 16; p = 16;
@ -607,7 +612,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
} }
uint8_t resolution = 0; uint8_t resolution = 0;
analog_range++; analog_range++;
switch(analog_range){ switch(analog_range) {
case 8191: case 8191:
resolution=13; resolution=13;
break; break;
@ -625,15 +630,15 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
analog_range = 255; analog_range = 255;
break; break;
} }
if ((channel==-1) || (value > (analog_range-1))){ if ((channel==-1) || (value > (analog_range-1))) {
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse); ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
return false; return false;
} }
ledcSetup(channel, 1000, resolution); ledcSetup(channel, 1000, resolution);
ledcAttachPin(pin, channel); ledcAttachPin(pin, channel);
ledcWrite(channel, value); ledcWrite(channel, value);
#endif #endif
} else{ } else {
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse); ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
response = false; response = false;
} }
@ -701,8 +706,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
break; break;
#endif #endif
//display ESP3D EEPROM version detected //display ESP3D EEPROM version detected
case 300: case 300: {
{
uint8_t v = CONFIG::get_EEPROM_version(); uint8_t v = CONFIG::get_EEPROM_version();
ESPCOM::println (String(v).c_str(), output, espresponse); ESPCOM::println (String(v).c_str(), output, espresponse);
} }
@ -1357,7 +1361,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
if (! (styp == "B" || styp == "S" || styp == "A" || styp == "I" || styp == "F") ) { if (! (styp == "B" || styp == "S" || styp == "A" || styp == "I" || styp == "F") ) {
response = false; response = false;
} }
if ((sval.length() == 0) && !((pos==EP_AP_PASSWORD) || (pos==EP_STA_PASSWORD))){ if ((sval.length() == 0) && !((pos==EP_AP_PASSWORD) || (pos==EP_STA_PASSWORD))) {
response = false; response = false;
} }
@ -1378,13 +1382,13 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
} }
#endif #endif
if (response) { if (response) {
if ((styp == "B") || (styp == "F")){ if ((styp == "B") || (styp == "F")) {
byte bbuf = sval.toInt(); byte bbuf = sval.toInt();
if (!CONFIG::write_byte (pos, bbuf) ) { if (!CONFIG::write_byte (pos, bbuf) ) {
response = false; response = false;
} else { } else {
//dynamique refresh is better than restart the board //dynamique refresh is better than restart the board
if (pos == EP_OUTPUT_FLAG){ if (pos == EP_OUTPUT_FLAG) {
CONFIG::output_flag = bbuf; CONFIG::output_flag = bbuf;
} }
if (pos == EP_TARGET_FW) { if (pos == EP_TARGET_FW) {
@ -1555,16 +1559,18 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
} }
int32_t linenb = 1; int32_t linenb = 1;
cmd_params.trim() ; cmd_params.trim() ;
if (sendLine2Serial (cmd_params, linenb, &linenb))ESPCOM::println (OK_CMD_MSG, output, espresponse); if (sendLine2Serial (cmd_params, linenb, &linenb)) {
else { //it may failed because of skip if repetier so let's reset numbering first ESPCOM::println (OK_CMD_MSG, output, espresponse);
} else { //it may failed because of skip if repetier so let's reset numbering first
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) { if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
//reset numbering //reset numbering
String cmd = "M110 N0"; String cmd = "M110 N0";
if (sendLine2Serial (cmd, -1, NULL)){ if (sendLine2Serial (cmd, -1, NULL)) {
linenb = 1; linenb = 1;
//if success let's try again to send the command //if success let's try again to send the command
if (sendLine2Serial (cmd_params, linenb, &linenb))ESPCOM::println (OK_CMD_MSG, output, espresponse); if (sendLine2Serial (cmd_params, linenb, &linenb)) {
else { ESPCOM::println (OK_CMD_MSG, output, espresponse);
} else {
ESPCOM::println (ERROR_CMD_MSG, output, espresponse); ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
response = false; response = false;
} }
@ -1656,7 +1662,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
//get //get
if (parameter.length() == 0) { if (parameter.length() == 0) {
uint8_t Ntype = 0; uint8_t Ntype = 0;
if (!CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &Ntype ) ){ if (!CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &Ntype ) ) {
Ntype =0; Ntype =0;
} }
char sbuf[MAX_DATA_LENGTH + 1]; char sbuf[MAX_DATA_LENGTH + 1];
@ -1887,7 +1893,9 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
ESPCOM::print (F (" # hostname:"), output, espresponse); ESPCOM::print (F (" # hostname:"), output, espresponse);
ESPCOM::print (shost, output, espresponse); ESPCOM::print (shost, output, espresponse);
if (WiFi.getMode() == WIFI_AP) ESPCOM::print (F("(AP mode)"), output, espresponse); if (WiFi.getMode() == WIFI_AP) {
ESPCOM::print (F("(AP mode)"), output, espresponse);
}
ESPCOM::println ("", output, espresponse); ESPCOM::println ("", output, espresponse);
} }
@ -1937,11 +1945,11 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
String ESP_Command; String ESP_Command;
int ESPpos = -1; int ESPpos = -1;
#ifdef MKS_TFT_FEATURE #ifdef MKS_TFT_FEATURE
if (buffer.startsWith("at+")){ if (buffer.startsWith("at+")) {
//echo //echo
ESPCOM::print (buffer, output); ESPCOM::print (buffer, output);
ESPCOM::print ("\r\r\n", output); ESPCOM::print ("\r\r\n", output);
if (buffer.startsWith("at+net_wanip=?")){ if (buffer.startsWith("at+net_wanip=?")) {
String ipstr; String ipstr;
if (WiFi.getMode() == WIFI_STA) { if (WiFi.getMode() == WIFI_STA) {
ipstr = WiFi.localIP().toString() + "," + WiFi.subnetMask().toString()+ "," + WiFi.gatewayIP().toString()+"\r\n"; ipstr = WiFi.localIP().toString() + "," + WiFi.subnetMask().toString()+ "," + WiFi.gatewayIP().toString()+"\r\n";
@ -1949,16 +1957,16 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
ipstr = WiFi.softAPIP().toString() + ",255.255.255.0," + WiFi.softAPIP().toString()+"\r\n"; ipstr = WiFi.softAPIP().toString() + ",255.255.255.0," + WiFi.softAPIP().toString()+"\r\n";
} }
ESPCOM::print (ipstr, output); ESPCOM::print (ipstr, output);
} else if (buffer.startsWith("at+wifi_ConState=?")){ } else if (buffer.startsWith("at+wifi_ConState=?")) {
ESPCOM::print ("Connected\r\n", output); ESPCOM::print ("Connected\r\n", output);
} else{ } else {
ESPCOM::print ("ok\r\n", output); ESPCOM::print ("ok\r\n", output);
} }
return false; return false;
} }
#endif #endif
ESPpos = buffer.indexOf ("[ESP"); ESPpos = buffer.indexOf ("[ESP");
if (ESPpos == -1 && (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)){ if (ESPpos == -1 && (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)) {
ESPpos = buffer.indexOf ("[esp"); ESPpos = buffer.indexOf ("[esp");
} }
if (ESPpos > -1) { if (ESPpos > -1) {

View File

@ -142,7 +142,8 @@ void CONFIG::InitFirmwareTarget()
SetFirmwareTarget (UNKNOWN_FW) ; SetFirmwareTarget (UNKNOWN_FW) ;
} }
} }
void CONFIG::InitOutput(){ void CONFIG::InitOutput()
{
byte bflag = 0; byte bflag = 0;
if (!CONFIG::read_byte (EP_OUTPUT_FLAG, &bflag ) ) { if (!CONFIG::read_byte (EP_OUTPUT_FLAG, &bflag ) ) {
bflag = 0; bflag = 0;
@ -150,7 +151,8 @@ void CONFIG::InitOutput(){
CONFIG::output_flag = bflag; CONFIG::output_flag = bflag;
} }
bool CONFIG::is_locked(byte flag){ bool CONFIG::is_locked(byte flag)
{
return ((CONFIG::output_flag & flag) == flag); return ((CONFIG::output_flag & flag) == flag);
} }
@ -163,8 +165,9 @@ void CONFIG::InitDirectSD()
bool CONFIG::InitBaudrate(long value) bool CONFIG::InitBaudrate(long value)
{ {
long baud_rate = 0; long baud_rate = 0;
if (value > 0)baud_rate = value; if (value > 0) {
else { baud_rate = value;
} else {
if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) { if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) {
return false; return false;
} }
@ -248,7 +251,8 @@ void CONFIG::esp_restart (bool async)
}; };
} }
#ifdef DHT_FEATURE #ifdef DHT_FEATURE
void CONFIG::InitDHT(bool refresh) { void CONFIG::InitDHT(bool refresh)
{
if (!refresh) { if (!refresh) {
byte bflag = DEFAULT_DHT_TYPE; byte bflag = DEFAULT_DHT_TYPE;
int ibuf = DEFAULT_DHT_INTERVAL; int ibuf = DEFAULT_DHT_INTERVAL;
@ -261,7 +265,9 @@ void CONFIG::InitDHT(bool refresh) {
} }
CONFIG::DHT_interval = ibuf; CONFIG::DHT_interval = ibuf;
} }
if (CONFIG::DHT_type != 255) dht.setup(ESP_DHT_PIN,(DHTesp::DHT_MODEL_t)CONFIG::DHT_type); // Connect DHT sensor to GPIO ESP_DHT_PIN if (CONFIG::DHT_type != 255) {
dht.setup(ESP_DHT_PIN,(DHTesp::DHT_MODEL_t)CONFIG::DHT_type); // Connect DHT sensor to GPIO ESP_DHT_PIN
}
} }
#endif #endif
void CONFIG::InitPins() void CONFIG::InitPins()
@ -502,7 +508,8 @@ char * CONFIG::mac2str (uint8_t mac [WL_MAC_ADDR_LENGTH])
} }
bool CONFIG::set_EEPROM_version(uint8_t v){ bool CONFIG::set_EEPROM_version(uint8_t v)
{
byte byte_buffer[6]; byte byte_buffer[6];
byte_buffer[0]='E'; byte_buffer[0]='E';
byte_buffer[1]='S'; byte_buffer[1]='S';
@ -513,11 +520,14 @@ bool CONFIG::set_EEPROM_version(uint8_t v){
return CONFIG::write_buffer (EP_EEPROM_VERSION, byte_buffer, 6); return CONFIG::write_buffer (EP_EEPROM_VERSION, byte_buffer, 6);
} }
uint8_t CONFIG::get_EEPROM_version(){ uint8_t CONFIG::get_EEPROM_version()
{
byte byte_buffer[6]; byte byte_buffer[6];
long baud_rate; long baud_rate;
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) return EEPROM_V0; if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) {
if ((byte_buffer[0]=='E') && (byte_buffer[1]=='S') && (byte_buffer[2]=='P')&& (byte_buffer[3]=='3') && (byte_buffer[4]=='D')){ return EEPROM_V0;
}
if ((byte_buffer[0]=='E') && (byte_buffer[1]=='S') && (byte_buffer[2]=='P')&& (byte_buffer[3]=='3') && (byte_buffer[4]=='D')) {
return byte_buffer[5]; return byte_buffer[5];
} }
@ -530,10 +540,13 @@ uint8_t CONFIG::get_EEPROM_version(){
return EEPROM_V0; return EEPROM_V0;
} }
bool CONFIG::adjust_EEPROM_settings(){ bool CONFIG::adjust_EEPROM_settings()
{
uint8_t v = get_EEPROM_version(); uint8_t v = get_EEPROM_version();
bool bdone =false; bool bdone =false;
if (v == EEPROM_CURRENT_VERSION) return true; if (v == EEPROM_CURRENT_VERSION) {
return true;
}
if (v == 1) { if (v == 1) {
bdone =true; bdone =true;
#ifdef SDCARD_FEATURE #ifdef SDCARD_FEATURE
@ -554,7 +567,7 @@ bool CONFIG::adjust_EEPROM_settings(){
bdone =false; bdone =false;
} }
} }
if (bdone){ if (bdone) {
set_EEPROM_version(EEPROM_CURRENT_VERSION); set_EEPROM_version(EEPROM_CURRENT_VERSION);
} }
return bdone; return bdone;
@ -698,7 +711,7 @@ bool CONFIG::write_string (int pos, const char * byte_buffer)
} }
if (!((pos == EP_STA_PASSWORD) || (pos == EP_AP_PASSWORD))) { if (!((pos == EP_STA_PASSWORD) || (pos == EP_AP_PASSWORD))) {
if((size_buffer == 0 ) || (byte_buffer == NULL )){ if((size_buffer == 0 ) || (byte_buffer == NULL )) {
LOG ("Error write string\r\n") LOG ("Error write string\r\n")
return false; return false;
} }
@ -984,8 +997,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
//if higher than 1MB take out SPIFFS //if higher than 1MB take out SPIFFS
if (flashsize > 1024 * 1024) { if (flashsize > 1024 * 1024) {
flashsize = (1024 * 1024)-ESP.getSketchSize()-1024; flashsize = (1024 * 1024)-ESP.getSketchSize()-1024;
} } else {
else {
flashsize = flashsize - ESP.getSketchSize()-info.totalBytes-1024; flashsize = flashsize - ESP.getSketchSize()-info.totalBytes-1024;
} }
ESPCOM::print(formatBytes(flashsize).c_str(), output, espresponse); ESPCOM::print(formatBytes(flashsize).c_str(), output, espresponse);
@ -1772,7 +1784,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
ESPCOM::print (F ("\n"), output, espresponse); ESPCOM::print (F ("\n"), output, espresponse);
} }
#ifdef NOTIFICATION_FEATURE #ifdef NOTIFICATION_FEATURE
if (!plaintext) if (!plaintext)
{ {
ESPCOM::print (F ("\"Notifications\":\""), output, espresponse); ESPCOM::print (F ("\"Notifications\":\""), output, espresponse);
} else } else
@ -1933,11 +1945,11 @@ if (!plaintext)
ESPCOM::print (F ("FW version: "), output, espresponse); ESPCOM::print (F ("FW version: "), output, espresponse);
} }
ESPCOM::print (FW_VERSION, output, espresponse); ESPCOM::print (FW_VERSION, output, espresponse);
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
ESPCOM::print (" ESP8266/8586", output, espresponse); ESPCOM::print (" ESP8266/8586", output, espresponse);
#else #else
ESPCOM::print (" ESP32", output, espresponse); ESPCOM::print (" ESP32", output, espresponse);
#endif #endif
if (!plaintext) if (!plaintext)
{ {
ESPCOM::print (F ("\"}"), output, espresponse); ESPCOM::print (F ("\"}"), output, espresponse);

View File

@ -504,11 +504,15 @@ const uint16_t Setting[][2] = {
class AsyncResponseStream; class AsyncResponseStream;
typedef AsyncResponseStream ESPResponseStream; typedef AsyncResponseStream ESPResponseStream;
#else #else
class ESPResponseStream{ class ESPResponseStream
public: {
public:
bool header_sent; bool header_sent;
String buffer_web; String buffer_web;
ESPResponseStream(){header_sent=false;}; ESPResponseStream()
{
header_sent=false;
};
}; };
#endif #endif

View File

@ -86,7 +86,8 @@ DHTesp dht;
#endif #endif
//Contructor //Contructor
Esp3D::Esp3D() { Esp3D::Esp3D()
{
} }
@ -127,7 +128,7 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
uint32_t start_display_time = millis(); uint32_t start_display_time = millis();
uint32_t now = millis(); uint32_t now = millis();
while ( now - start_display_time < startdelayms){ while ( now - start_display_time < startdelayms) {
int v = (100 * (millis() - start_display_time)) / startdelayms; int v = (100 * (millis() - start_display_time)) / startdelayms;
OLED_DISPLAY::display_mini_progress(v); OLED_DISPLAY::display_mini_progress(v);
OLED_DISPLAY::update_lcd(); OLED_DISPLAY::update_lcd();
@ -191,11 +192,11 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
SPIFFS.begin(); SPIFFS.begin();
#endif #endif
//basic autostart //basic autostart
if(SPIFFS.exists("/autostart.g")){ if(SPIFFS.exists("/autostart.g")) {
FS_FILE file = SPIFFS.open("/autostart.g", SPIFFS_FILE_READ); FS_FILE file = SPIFFS.open("/autostart.g", SPIFFS_FILE_READ);
if (file){ if (file) {
String autoscript = file.readString(); String autoscript = file.readString();
if (autoscript.length() > 0){ if (autoscript.length() > 0) {
//clean line //clean line
autoscript.replace("\n",""); autoscript.replace("\n","");
autoscript.replace("\r",""); autoscript.replace("\r","");
@ -218,7 +219,7 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
if (!wifi_config.Enable_servers() ) { if (!wifi_config.Enable_servers() ) {
ESPCOM::println (F ("Error enabling servers"), PRINTER_PIPE); ESPCOM::println (F ("Error enabling servers"), PRINTER_PIPE);
} }
/*#ifdef ARDUINO_ARCH_ESP8266 /*#ifdef ARDUINO_ARCH_ESP8266
if (rtc_info->reason == REASON_WDT_RST || if (rtc_info->reason == REASON_WDT_RST ||
rtc_info->reason == REASON_EXCEPTION_RST || rtc_info->reason == REASON_EXCEPTION_RST ||
@ -234,7 +235,7 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
} }
ESPCOM::println (s, PRINTER_PIPE); ESPCOM::println (s, PRINTER_PIPE);
} }
#else #else
if((( reason_0< 17) || ( reason_1< 17)) && !(((reason_0 == 1) && (reason_1 == 14)) || ((reason_0 == 16) && (reason_1 == 14)))) if((( reason_0< 17) || ( reason_1< 17)) && !(((reason_0 == 1) && (reason_1 == 14)) || ((reason_0 == 16) && (reason_1 == 14))))
{ {
String s = "reset "; String s = "reset ";
@ -244,7 +245,7 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
s+=String(reason_1); s+=String(reason_1);
} }
#endif*/ #endif*/
#ifdef ASYNCWEBSERVER #ifdef ASYNCWEBSERVER
if (WiFi.getMode() != WIFI_AP) { if (WiFi.getMode() != WIFI_AP) {
@ -281,21 +282,32 @@ void Esp3D::process()
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
static uint32_t last_oled_update= 0; static uint32_t last_oled_update= 0;
if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)){ if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)) {
uint32_t now_oled = millis(); uint32_t now_oled = millis();
if (now_oled - last_oled_update > 1000) { if (now_oled - last_oled_update > 1000) {
last_oled_update = now_oled; last_oled_update = now_oled;
//refresh signal //refresh signal
if ((WiFi.getMode() == WIFI_OFF) || !wifi_config.WiFi_on) OLED_DISPLAY::display_signal(-1); if ((WiFi.getMode() == WIFI_OFF) || !wifi_config.WiFi_on) {
else OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ())); OLED_DISPLAY::display_signal(-1);
} else {
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
}
//if line 0 is > 85 refresh //if line 0 is > 85 refresh
if(OLED_DISPLAY::L0_size >85)OLED_DISPLAY::display_text(OLED_DISPLAY::L0.c_str(), 0, 0, 85); if(OLED_DISPLAY::L0_size >85) {
OLED_DISPLAY::display_text(OLED_DISPLAY::L0.c_str(), 0, 0, 85);
}
//if line 1 is > 128 refresh //if line 1 is > 128 refresh
if(OLED_DISPLAY::L1_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L1.c_str(), 0, 16, 128); if(OLED_DISPLAY::L1_size >128) {
OLED_DISPLAY::display_text(OLED_DISPLAY::L1.c_str(), 0, 16, 128);
}
//if line 2 is > 128 refresh //if line 2 is > 128 refresh
if(OLED_DISPLAY::L2_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L2.c_str(), 0, 32, 128); if(OLED_DISPLAY::L2_size >128) {
OLED_DISPLAY::display_text(OLED_DISPLAY::L2.c_str(), 0, 32, 128);
}
//if line 3 is > 128 refresh //if line 3 is > 128 refresh
if(OLED_DISPLAY::L3_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L3.c_str(), 0, 48, 128); if(OLED_DISPLAY::L3_size >128) {
OLED_DISPLAY::display_text(OLED_DISPLAY::L3.c_str(), 0, 48, 128);
}
OLED_DISPLAY::update_lcd(); OLED_DISPLAY::update_lcd();
} }
} }
@ -312,19 +324,19 @@ void Esp3D::process()
if (strcmp(dht.getStatusString(),"OK") == 0) { if (strcmp(dht.getStatusString(),"OK") == 0) {
String s = String(temperature,2); String s = String(temperature,2);
String s2 = s + " " +String(humidity,2); String s2 = s + " " +String(humidity,2);
#if defined (ASYNCWEBSERVER) #if defined (ASYNCWEBSERVER)
web_interface->web_events.send( s2.c_str(),"DHT", millis()); web_interface->web_events.send( s2.c_str(),"DHT", millis());
#else #else
s = "DHT:" + s2; s = "DHT:" + s2;
socket_server->sendTXT(ESPCOM::current_socket_id, s); socket_server->sendTXT(ESPCOM::current_socket_id, s);
#endif #endif
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)){ if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)) {
s = String(temperature,2); s = String(temperature,2);
s +="°C"; s +="°C";
OLED_DISPLAY::display_text(s.c_str(), 84, 16); OLED_DISPLAY::display_text(s.c_str(), 84, 16);
} }
#endif #endif
} }
} }
} }

View File

@ -25,16 +25,16 @@
// Initialize the OLED display using I2C // Initialize the OLED display using I2C
#ifdef OLED_DISPLAY_SSD1306 #ifdef OLED_DISPLAY_SSD1306
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` #include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
#elif defined OLED_DISPLAY_SH1106 #elif defined OLED_DISPLAY_SH1106
#include "SH1106.h" // alias for `#include "SH1106Wire.h"` #include "SH1106.h" // alias for `#include "SH1106Wire.h"`
#endif #endif
#ifdef OLED_DISPLAY_SSD1306 #ifdef OLED_DISPLAY_SSD1306
SSD1306 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL); SSD1306 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
#elif defined OLED_DISPLAY_SH1106 #elif defined OLED_DISPLAY_SH1106
SH1106 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL); SH1106 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
#endif #endif
@ -71,15 +71,19 @@ const char ESP3D_Logo[] = {
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x07, 0x00, 0x00,
0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00
}; };
void OLED_DISPLAY::splash(){ void OLED_DISPLAY::splash()
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return; {
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo); esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo);
update_lcd(); update_lcd();
} }
void OLED_DISPLAY::begin(){ void OLED_DISPLAY::begin()
{
//For Embeded OLED on Wifi kit 32 //For Embeded OLED on Wifi kit 32
#if HELTEC_EMBEDDED_PIN > 0 #if HELTEC_EMBEDDED_PIN > 0
pinMode(HELTEC_EMBEDDED_PIN,OUTPUT); pinMode(HELTEC_EMBEDDED_PIN,OUTPUT);
@ -89,29 +93,39 @@ void OLED_DISPLAY::begin(){
#endif #endif
esp_display.init(); esp_display.init();
esp_display.clear(); esp_display.clear();
#if OLED_FLIP_VERTICALY #if OLED_FLIP_VERTICALY
esp_display.flipScreenVertically(); esp_display.flipScreenVertically();
#endif #endif
} }
void OLED_DISPLAY::setCursor(int col, int row){ void OLED_DISPLAY::setCursor(int col, int row)
if (col!=-1) OLED_DISPLAY::col = col; {
if (row!=-1) OLED_DISPLAY::row = row; if (col!=-1) {
OLED_DISPLAY::col = col;
}
if (row!=-1) {
OLED_DISPLAY::row = row;
}
} }
void OLED_DISPLAY::print(String & s){ void OLED_DISPLAY::print(String & s)
{
OLED_DISPLAY::print(s.c_str()); OLED_DISPLAY::print(s.c_str());
} }
void OLED_DISPLAY::print(const char * s){ void OLED_DISPLAY::print(const char * s)
{
display_text(s, col, row); display_text(s, col, row);
} }
void OLED_DISPLAY::display_signal(int value, int x, int y) { void OLED_DISPLAY::display_signal(int value, int x, int y)
if(CONFIG::is_locked(FLAG_BLOCK_OLED))return; {
if(CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
//clear area only //clear area only
esp_display.setColor(BLACK); esp_display.setColor(BLACK);
esp_display.fillRect(x, y, x + 46, 16); esp_display.fillRect(x, y, x + 46, 16);
esp_display.setColor(WHITE); esp_display.setColor(WHITE);
if (value == -1){ if (value == -1) {
esp_display.setFont(ArialMT_Plain_10); esp_display.setFont(ArialMT_Plain_10);
esp_display.drawString(x+20, y, "X"); esp_display.drawString(x+20, y, "X");
@ -150,8 +164,11 @@ void OLED_DISPLAY::display_signal(int value, int x, int y) {
} }
void OLED_DISPLAY::display_progress(int value, int x, int y) { void OLED_DISPLAY::display_progress(int value, int x, int y)
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return; {
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
esp_display.setFont(ArialMT_Plain_10); esp_display.setFont(ArialMT_Plain_10);
esp_display.setColor(BLACK); esp_display.setColor(BLACK);
esp_display.fillRect(x, y, x + 128, 16); esp_display.fillRect(x, y, x + 128, 16);
@ -161,17 +178,21 @@ void OLED_DISPLAY::display_progress(int value, int x, int y) {
esp_display.drawString(x+102, y - 1, p.c_str()); esp_display.drawString(x+102, y - 1, p.c_str());
} }
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w) { void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w)
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return; {
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
esp_display.setColor(BLACK); esp_display.setColor(BLACK);
esp_display.fillRect(x, y, x + w, 2); esp_display.fillRect(x, y, x + w, 2);
esp_display.setColor(WHITE); esp_display.setColor(WHITE);
esp_display.drawRect(x , y, value, 2); esp_display.drawRect(x, y, value, 2);
} }
//max is 128 by default but can be 85 for first line //max is 128 by default but can be 85 for first line
void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) { void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max)
{
static int shift_pos[4] = {-1, -1, -1, -1}; static int shift_pos[4] = {-1, -1, -1, -1};
static int t[4] = {0, 0, 0, 0}; static int t[4] = {0, 0, 0, 0};
@ -180,19 +201,16 @@ void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
OLED_DISPLAY::L1 = txt; OLED_DISPLAY::L1 = txt;
OLED_DISPLAY::L1_size = esp_display.getStringWidth( txt); OLED_DISPLAY::L1_size = esp_display.getStringWidth( txt);
p=1; p=1;
} } else if (y==32) {
else if (y==32){
OLED_DISPLAY::L2 = txt; OLED_DISPLAY::L2 = txt;
OLED_DISPLAY::L2_size = esp_display.getStringWidth( txt); OLED_DISPLAY::L2_size = esp_display.getStringWidth( txt);
p=2; p=2;
} } else if (y==0) {
else if (y==0){
max = 85; max = 85;
OLED_DISPLAY::L0 = txt; OLED_DISPLAY::L0 = txt;
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt); OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
p=0; p=0;
} } else {
else{
OLED_DISPLAY::L3 = txt; OLED_DISPLAY::L3 = txt;
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt); OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
p=3; p=3;
@ -216,16 +234,18 @@ void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
} }
} }
//be sure we stay in boundaries //be sure we stay in boundaries
while (esp_display.getStringWidth(Stxt) > max){ while (esp_display.getStringWidth(Stxt) > max) {
Stxt.remove(Stxt.length()-1, 1); Stxt.remove(Stxt.length()-1, 1);
} }
esp_display.drawString(x, y, Stxt.c_str()); esp_display.drawString(x, y, Stxt.c_str());
} }
void OLED_DISPLAY::update_lcd(){ void OLED_DISPLAY::update_lcd()
{
esp_display.display(); esp_display.display();
} }
void OLED_DISPLAY::clear_lcd(){ void OLED_DISPLAY::clear_lcd()
{
esp_display.clear(); esp_display.clear();
} }
int OLED_DISPLAY::col = 0; int OLED_DISPLAY::col = 0;

View File

@ -25,28 +25,28 @@
class OLED_DISPLAY class OLED_DISPLAY
{ {
public: public:
static void begin(); static void begin();
static void setCursor(int col, int row = -1); static void setCursor(int col, int row = -1);
static void print(String & s); static void print(String & s);
static void print(const char * s); static void print(const char * s);
static void display_signal( int value, int x=86, int y=0); static void display_signal( int value, int x=86, int y=0);
static void display_text(const char * txt, int x=0, int y=48, int max=128); static void display_text(const char * txt, int x=0, int y=48, int max=128);
static void display_progress(int value, int x=0, int y=48); static void display_progress(int value, int x=0, int y=48);
static void display_mini_progress(int value, int x = 14, int y=61, int w=100); static void display_mini_progress(int value, int x = 14, int y=61, int w=100);
static void update_lcd(); static void update_lcd();
static void clear_lcd(); static void clear_lcd();
static void splash(); static void splash();
static String L0; static String L0;
static String L1; static String L1;
static String L2; static String L2;
static String L3; static String L3;
static int L0_size; static int L0_size;
static int L1_size; static int L1_size;
static int L2_size; static int L2_size;
static int L3_size; static int L3_size;
private: private:
static int col; static int col;
static int row; static int row;
}; };

View File

@ -30,7 +30,7 @@
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
#include "esp_oled.h" #include "esp_oled.h"
bool ESPCOM::block_2_oled = false; bool ESPCOM::block_2_oled = false;
#endif #endif
uint8_t ESPCOM::current_socket_id=0; uint8_t ESPCOM::current_socket_id=0;
@ -55,7 +55,7 @@ void ESPCOM::bridge(bool async)
#endif #endif
} }
//read serial input //read serial input
ESPCOM::processFromSerial(); ESPCOM::processFromSerial();
#if defined (ASYNCWEBSERVER) #if defined (ASYNCWEBSERVER)
} }
#endif #endif
@ -116,9 +116,10 @@ long ESPCOM::baudRate(tpipe output)
br = 230400; br = 230400;
} }
#endif #endif
return br; return br;
} }
size_t ESPCOM::available(tpipe output){ size_t ESPCOM::available(tpipe output)
{
switch (output) { switch (output) {
#ifdef USE_SERIAL_0 #ifdef USE_SERIAL_0
case SERIAL_PIPE: case SERIAL_PIPE:
@ -140,9 +141,14 @@ size_t ESPCOM::available(tpipe output){
break; break;
} }
} }
size_t ESPCOM::write(tpipe output, uint8_t d){ size_t ESPCOM::write(tpipe output, uint8_t d)
if ((DEFAULT_PRINTER_PIPE == output) && (block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) return 0; {
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL))return 0; if ((DEFAULT_PRINTER_PIPE == output) && (block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) {
return 0;
}
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
return 0;
}
switch (output) { switch (output) {
#ifdef USE_SERIAL_0 #ifdef USE_SERIAL_0
case SERIAL_PIPE: case SERIAL_PIPE:
@ -213,16 +219,26 @@ void ESPCOM::print (String & data, tpipe output, ESPResponseStream *espresponse
} }
void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresponse) void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresponse)
{ {
if ((DEFAULT_PRINTER_PIPE == output) && ( block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) return; if ((DEFAULT_PRINTER_PIPE == output) && ( block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) {
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL))return; return;
}
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
return;
}
#ifdef TCP_IP_DATA_FEATURE #ifdef TCP_IP_DATA_FEATURE
if ((TCP_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_TCP))return; if ((TCP_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_TCP)) {
return;
}
#endif #endif
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
if ((WS_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_WSOCKET))return; if ((WS_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) {
return;
}
#endif #endif
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
if ((OLED_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_OLED))return; if ((OLED_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
#endif #endif
switch (output) { switch (output) {
#ifdef USE_SERIAL_0 #ifdef USE_SERIAL_0
@ -268,8 +284,7 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
} }
break; break;
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
case WS_PIPE: case WS_PIPE: {
{
#if defined(ASYNCWEBSERVER) #if defined(ASYNCWEBSERVER)
//Todo //Todo
#else #else
@ -280,8 +295,7 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
#endif #endif
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
case OLED_PIPE: case OLED_PIPE: {
{
if (!ESPCOM::block_2_oled) { if (!ESPCOM::block_2_oled) {
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) { if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
OLED_DISPLAY::print(data); OLED_DISPLAY::print(data);
@ -291,14 +305,17 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
} }
break; break;
#endif #endif
case PRINTER_PIPE: case PRINTER_PIPE: {
{
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
OLED_DISPLAY::setCursor(0, 48); OLED_DISPLAY::setCursor(0, 48);
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n")))ESPCOM::print(data, OLED_PIPE); if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
ESPCOM::print(data, OLED_PIPE);
}
#endif #endif
if (!CONFIG::is_locked(FLAG_BLOCK_M117)){ if (!CONFIG::is_locked(FLAG_BLOCK_M117)) {
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n")))ESPCOM::print ("M117 ", DEFAULT_PRINTER_PIPE); if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
ESPCOM::print ("M117 ", DEFAULT_PRINTER_PIPE);
}
ESPCOM::print (data, DEFAULT_PRINTER_PIPE); ESPCOM::print (data, DEFAULT_PRINTER_PIPE);
} }
} }
@ -363,7 +380,7 @@ bool ESPCOM::processFromSerial (bool async)
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) { if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE); size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
uint8_t * sbuf = (uint8_t *)malloc(len+1); uint8_t * sbuf = (uint8_t *)malloc(len+1);
if(!sbuf){ if(!sbuf) {
return false; return false;
} }
sbuf[len] = '\0'; sbuf[len] = '\0';
@ -384,9 +401,13 @@ bool ESPCOM::processFromSerial (bool async)
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
#if defined (ASYNCWEBSERVER) #if defined (ASYNCWEBSERVER)
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) web_interface->web_socket.textAll(sbuf, len); if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) {
web_interface->web_socket.textAll(sbuf, len);
}
#else #else
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server)socket_server->sendBIN(current_socket_id,sbuf,len); if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server) {
socket_server->sendBIN(current_socket_id,sbuf,len);
}
#endif #endif
#endif #endif

View File

@ -371,7 +371,7 @@ bool NotificationsService::begin()
end(); end();
byte bbuf = 0; byte bbuf = 0;
char sbuf[MAX_DATA_LENGTH + 1]; char sbuf[MAX_DATA_LENGTH + 1];
if (CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &bbuf ) ){ if (CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &bbuf ) ) {
_notificationType =bbuf; _notificationType =bbuf;
} }
switch(_notificationType) { switch(_notificationType) {

View File

@ -47,11 +47,11 @@
#include "espcom.h" #include "espcom.h"
#ifdef SSDP_FEATURE #ifdef SSDP_FEATURE
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <ESP32SSDP.h> #include <ESP32SSDP.h>
#else #else
#include <ESP8266SSDP.h> #include <ESP8266SSDP.h>
#endif #endif
#endif #endif
//embedded response file if no files on SPIFFS //embedded response file if no files on SPIFFS
@ -59,14 +59,14 @@
#include "syncwebserver.h" #include "syncwebserver.h"
WebSocketsServer * socket_server; WebSocketsServer * socket_server;
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length)
{
switch(type) { switch(type) {
case WStype_DISCONNECTED: case WStype_DISCONNECTED:
//USE_SERIAL.printf("[%u] Disconnected!\n", num); //USE_SERIAL.printf("[%u] Disconnected!\n", num);
break; break;
case WStype_CONNECTED: case WStype_CONNECTED: {
{
IPAddress ip = socket_server->remoteIP(num); IPAddress ip = socket_server->remoteIP(num);
//USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); //USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
String s = "CURRENT_ID:" + String(num); String s = "CURRENT_ID:" + String(num);
@ -159,10 +159,15 @@ void handle_login()
} }
level_authenticate_type auth_level= web_interface->is_authenticated(); level_authenticate_type auth_level= web_interface->is_authenticated();
if (auth_level == LEVEL_GUEST) auths = F("guest"); if (auth_level == LEVEL_GUEST) {
else if (auth_level == LEVEL_USER) auths = F("user"); auths = F("guest");
else if (auth_level == LEVEL_ADMIN) auths = F("admin"); } else if (auth_level == LEVEL_USER) {
else auths = F("???"); auths = F("user");
} else if (auth_level == LEVEL_ADMIN) {
auths = F("admin");
} else {
auths = F("???");
}
//check is it is a submission or a query //check is it is a submission or a query
if (web_interface->web_server.hasArg("SUBMIT")) { if (web_interface->web_server.hasArg("SUBMIT")) {
@ -207,9 +212,12 @@ void handle_login()
String newpassword = web_interface->web_server.arg("NEWPASSWORD"); String newpassword = web_interface->web_server.arg("NEWPASSWORD");
if (CONFIG::isLocalPasswordValid(newpassword.c_str())) { if (CONFIG::isLocalPasswordValid(newpassword.c_str())) {
int pos=0; int pos=0;
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) pos = EP_ADMIN_PWD; if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) {
else pos = EP_USER_PWD; pos = EP_ADMIN_PWD;
if (!CONFIG::write_string(pos,newpassword.c_str())){ } else {
pos = EP_USER_PWD;
}
if (!CONFIG::write_string(pos,newpassword.c_str())) {
msg_alert_error=true; msg_alert_error=true;
smsg = F("Error: Cannot apply changes"); smsg = F("Error: Cannot apply changes");
code = 500; code = 500;
@ -224,7 +232,7 @@ void handle_login()
level_authenticate_type current_auth_level; level_authenticate_type current_auth_level;
if(sUser == FPSTR(DEFAULT_ADMIN_LOGIN)) { if(sUser == FPSTR(DEFAULT_ADMIN_LOGIN)) {
current_auth_level = LEVEL_ADMIN; current_auth_level = LEVEL_ADMIN;
} else if(sUser == FPSTR(DEFAULT_USER_LOGIN)){ } else if(sUser == FPSTR(DEFAULT_USER_LOGIN)) {
current_auth_level = LEVEL_USER; current_auth_level = LEVEL_USER;
} else { } else {
current_auth_level = LEVEL_GUEST; current_auth_level = LEVEL_GUEST;
@ -261,7 +269,9 @@ void handle_login()
} }
} }
} }
if (code == 200) smsg = F("Ok"); if (code == 200) {
smsg = F("Ok");
}
//build JSON //build JSON
String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\""; String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\"";
@ -277,7 +287,7 @@ void handle_login()
int pos2 = cookie.indexOf(";",pos); int pos2 = cookie.indexOf(";",pos);
sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2); sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2);
auth_ip * current_auth_info = web_interface->GetAuth(web_interface->web_server.client().remoteIP(), sessionID.c_str()); auth_ip * current_auth_info = web_interface->GetAuth(web_interface->web_server.client().remoteIP(), sessionID.c_str());
if (current_auth_info != NULL){ if (current_auth_info != NULL) {
sUser = current_auth_info->userID; sUser = current_auth_info->userID;
} }
} }
@ -559,8 +569,11 @@ void SPIFFSFileupload()
if(upload.status == UPLOAD_FILE_START) { if(upload.status == UPLOAD_FILE_START) {
String upload_filename = upload.filename; String upload_filename = upload.filename;
String sizeargname = upload_filename + "S"; String sizeargname = upload_filename + "S";
if (upload_filename[0] != '/') filename = "/" + upload_filename; if (upload_filename[0] != '/') {
else filename = upload.filename; filename = "/" + upload_filename;
} else {
filename = upload.filename;
}
//according User or Admin the root is different as user is isolate to /user when admin has full access //according User or Admin the root is different as user is isolate to /user when admin has full access
if(auth_level != LEVEL_ADMIN) { if(auth_level != LEVEL_ADMIN) {
upload_filename = filename; upload_filename = filename;
@ -685,8 +698,11 @@ void WebUpdateUpload()
web_interface->web_server.client().stop(); web_interface->web_server.client().stop();
#endif #endif
} else { } else {
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESPCOM::println (F ("Update 0%%"), PRINTER_PIPE); if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
else ESPCOM::println (F ("Update 0%"), PRINTER_PIPE); ESPCOM::println (F ("Update 0%%"), PRINTER_PIPE);
} else {
ESPCOM::println (F ("Update 0%"), PRINTER_PIPE);
}
} }
//Upload write //Upload write
//************** //**************
@ -699,7 +715,9 @@ void WebUpdateUpload()
String s = "Update "; String s = "Update ";
s+= String(last_upload_update); s+= String(last_upload_update);
s+= "%"; s+= "%";
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) s+= "%"; if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
s+= "%";
}
ESPCOM::println (s.c_str(), PRINTER_PIPE); ESPCOM::println (s.c_str(), PRINTER_PIPE);
} }
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) { if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
@ -711,8 +729,11 @@ void WebUpdateUpload()
} else if(upload.status == UPLOAD_FILE_END) { } else if(upload.status == UPLOAD_FILE_END) {
if(Update.end(true)) { //true to set the size to the current progress if(Update.end(true)) { //true to set the size to the current progress
//Now Reboot //Now Reboot
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESPCOM::println (F("Update 100%%"), PRINTER_PIPE); if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
else ESPCOM::println (F("Update 100%"), PRINTER_PIPE); ESPCOM::println (F("Update 100%%"), PRINTER_PIPE);
} else {
ESPCOM::println (F("Update 100%"), PRINTER_PIPE);
}
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL; web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
} }
} else if(upload.status == UPLOAD_FILE_ABORTED) { } else if(upload.status == UPLOAD_FILE_ABORTED) {
@ -977,14 +998,14 @@ void handle_web_command()
LOG(current_line) LOG(current_line)
LOG("\r\n") LOG("\r\n")
//check command //check command
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)){ if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
//save time no need to continue //save time no need to continue
if (current_line.indexOf("busy:") > -1) { if (current_line.indexOf("busy:") > -1) {
temp_counter++; temp_counter++;
} else if (COMMAND::check_command(current_line, NO_PIPE, false)) { } else if (COMMAND::check_command(current_line, NO_PIPE, false)) {
temp_counter ++ ; temp_counter ++ ;
} }
}else { } else {
if (COMMAND::check_command(current_line, NO_PIPE, false)) { if (COMMAND::check_command(current_line, NO_PIPE, false)) {
temp_counter ++ ; temp_counter ++ ;
} }
@ -993,8 +1014,7 @@ void handle_web_command()
break; break;
} }
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) { if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
if (!current_line.startsWith( "ok ")) if (!current_line.startsWith( "ok ")) {
{
buffer2send +=current_line; buffer2send +=current_line;
buffer2send +="\n"; buffer2send +="\n";
} }
@ -1177,13 +1197,15 @@ void SDFile_serial_upload()
LOG("Upload Start\r\n") LOG("Upload Start\r\n")
String command = "M29"; String command = "M29";
String resetcmd = "M110 N0"; String resetcmd = "M110 N0";
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110"; if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
resetcmd = "N0 M110";
}
lineNb=1; lineNb=1;
//close any ongoing upload and get current line number //close any ongoing upload and get current line number
if(!sendLine2Serial (command,1, &lineNb)){ if(!sendLine2Serial (command,1, &lineNb)) {
//it can failed for repetier //it can failed for repetier
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) { if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
if(!sendLine2Serial (command,-1, NULL)){ if(!sendLine2Serial (command,-1, NULL)) {
LOG("Start Upload failed") LOG("Start Upload failed")
web_interface->_upload_status= UPLOAD_STATUS_FAILED; web_interface->_upload_status= UPLOAD_STATUS_FAILED;
return; return;
@ -1196,13 +1218,13 @@ void SDFile_serial_upload()
} }
//Mount SD card //Mount SD card
command = "M21"; command = "M21";
if(!sendLine2Serial (command,-1, NULL)){ if(!sendLine2Serial (command,-1, NULL)) {
LOG("Mounting SD failed") LOG("Mounting SD failed")
web_interface->_upload_status= UPLOAD_STATUS_FAILED; web_interface->_upload_status= UPLOAD_STATUS_FAILED;
return; return;
} }
//Reset line numbering //Reset line numbering
if(!sendLine2Serial (resetcmd,-1, NULL)){ if(!sendLine2Serial (resetcmd,-1, NULL)) {
LOG("Reset Numbering failed") LOG("Reset Numbering failed")
web_interface->_upload_status= UPLOAD_STATUS_FAILED; web_interface->_upload_status= UPLOAD_STATUS_FAILED;
return; return;
@ -1223,7 +1245,7 @@ void SDFile_serial_upload()
command = "M28 " + upload.filename; command = "M28 " + upload.filename;
//send start upload //send start upload
//no correction allowed because it means reset numbering was failed //no correction allowed because it means reset numbering was failed
if (sendLine2Serial(command, lineNb, NULL)){ if (sendLine2Serial(command, lineNb, NULL)) {
CONFIG::wait(1200); CONFIG::wait(1200);
//additional purge, in case it is slow to answer //additional purge, in case it is slow to answer
purge_serial(); purge_serial();

View File

@ -56,11 +56,11 @@
#include "espcom.h" #include "espcom.h"
#ifdef SSDP_FEATURE #ifdef SSDP_FEATURE
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <ESP32SSDP.h> #include <ESP32SSDP.h>
#else #else
#include <ESP8266SSDP.h> #include <ESP8266SSDP.h>
#endif #endif
#endif #endif
#if defined(ASYNCWEBSERVER) #if defined(ASYNCWEBSERVER)
@ -76,24 +76,28 @@ long id_connection = 0;
uint8_t Checksum(const char * line, uint16_t lineSize) uint8_t Checksum(const char * line, uint16_t lineSize)
{ {
uint8_t checksum_val =0; uint8_t checksum_val =0;
for (uint16_t i=0; i < lineSize; i++) checksum_val = checksum_val ^ ((uint8_t)line[i]); for (uint16_t i=0; i < lineSize; i++) {
checksum_val = checksum_val ^ ((uint8_t)line[i]);
}
return checksum_val; return checksum_val;
} }
String CheckSumLine(const char* line, uint32_t linenb){ String CheckSumLine(const char* line, uint32_t linenb)
{
String linechecksum = "N" + String(linenb)+ " " + line; String linechecksum = "N" + String(linenb)+ " " + line;
uint8_t crc = Checksum(linechecksum.c_str(), linechecksum.length()); uint8_t crc = Checksum(linechecksum.c_str(), linechecksum.length());
linechecksum+="*"+String(crc); linechecksum+="*"+String(crc);
return linechecksum; return linechecksum;
} }
bool purge_serial(){ bool purge_serial()
{
uint32_t start = millis(); uint32_t start = millis();
uint8_t buf [51]; uint8_t buf [51];
ESPCOM::flush (DEFAULT_PRINTER_PIPE); ESPCOM::flush (DEFAULT_PRINTER_PIPE);
CONFIG::wait (5); CONFIG::wait (5);
LOG("Purge Serial\r\n") LOG("Purge Serial\r\n")
while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ){ while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ) {
if ((millis() - start ) > 2000) { if ((millis() - start ) > 2000) {
LOG("Purge timeout\r\n") LOG("Purge timeout\r\n")
return false; return false;
@ -106,7 +110,9 @@ bool purge_serial(){
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) { if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
String s = (const char *)buf; String s = (const char *)buf;
//repetier never stop sending data so no need to wait if have 'wait' or 'busy' //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; if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
return true;
}
LOG("Purge interrupted\r\n") LOG("Purge interrupted\r\n")
} }
CONFIG::wait (5); CONFIG::wait (5);
@ -116,16 +122,20 @@ bool purge_serial(){
return true; return true;
} }
size_t wait_for_data(uint32_t timeout){ size_t wait_for_data(uint32_t timeout)
{
uint32_t start = millis(); uint32_t start = millis();
while ((ESPCOM::available(DEFAULT_PRINTER_PIPE) < 2) && ((millis()-start) < timeout))CONFIG::wait (10); while ((ESPCOM::available(DEFAULT_PRINTER_PIPE) < 2) && ((millis()-start) < timeout)) {
CONFIG::wait (10);
}
return ESPCOM::available(DEFAULT_PRINTER_PIPE); return ESPCOM::available(DEFAULT_PRINTER_PIPE);
} }
uint32_t Get_lineNumber(String & response){ uint32_t Get_lineNumber(String & response)
{
int32_t l = 0; int32_t l = 0;
String sresend = "Resend:"; String sresend = "Resend:";
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE){ if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
sresend = "rs N"; sresend = "rs N";
} }
int pos = response.indexOf(sresend); int pos = response.indexOf(sresend);
@ -156,12 +166,20 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
String line2send; String line2send;
String sok = "ok"; String sok = "ok";
String sresend = "Resend:"; String sresend = "Resend:";
if (newlinenb) *newlinenb = linenb; if (newlinenb) {
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)sresend = "rs N"; *newlinenb = linenb;
}
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
sresend = "rs N";
}
if (linenb != -1) { if (linenb != -1) {
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) sok+=" " + String(linenb); if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
sok+=" " + String(linenb);
}
line2send = CheckSumLine(line.c_str(),linenb); line2send = CheckSumLine(line.c_str(),linenb);
} else line2send = line; } else {
line2send = line;
}
//purge serial as nothing is supposed to interfere with upload //purge serial as nothing is supposed to interfere with upload
purge_serial(); purge_serial();
LOG ("Send line ") LOG ("Send line ")
@ -182,7 +200,7 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
//get size of buffer //get size of buffer
if (len > 0) { if (len > 0) {
uint8_t * sbuf = (uint8_t *)malloc(len+1); uint8_t * sbuf = (uint8_t *)malloc(len+1);
if(!sbuf){ if(!sbuf) {
return false; return false;
} }
//read buffer //read buffer
@ -202,11 +220,11 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
//it is resend ? //it is resend ?
int pos = response.indexOf (sresend); int pos = response.indexOf (sresend);
//be sure we get full line to be able to process properly //be sure we get full line to be able to process properly
if (( pos > -1) && (response.lastIndexOf("\n") > pos)){ if (( pos > -1) && (response.lastIndexOf("\n") > pos)) {
LOG ("Resend detected\r\n") LOG ("Resend detected\r\n")
uint32_t line_number = Get_lineNumber(response); uint32_t line_number = Get_lineNumber(response);
//this part is only if have newlinenb variable //this part is only if have newlinenb variable
if (newlinenb != nullptr){ if (newlinenb != nullptr) {
*newlinenb = line_number; *newlinenb = line_number;
free(sbuf); free(sbuf);
//no need newlinenb in this one in theory, but just in case... //no need newlinenb in this one in theory, but just in case...
@ -245,7 +263,7 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
free(sbuf); free(sbuf);
} }
//no answer or over buffer exit //no answer or over buffer exit
if ( (millis() - timeout > 2000) || (response.length() >200)){ if ( (millis() - timeout > 2000) || (response.length() >200)) {
LOG ("Time out\r\n") LOG ("Time out\r\n")
done = true; done = true;
} }
@ -257,7 +275,7 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
} }
//send M29 / M30 command to close file on SD//////////////////////////// //send M29 / M30 command to close file on SD////////////////////////////
void CloseSerialUpload (bool iserror, String & filename , int32_t linenb) void CloseSerialUpload (bool iserror, String & filename, int32_t linenb)
{ {
purge_serial(); purge_serial();
String command = "M29"; String command = "M29";
@ -321,7 +339,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
web_server.on ("/description.xml", HTTP_GET, handle_SSDP); web_server.on ("/description.xml", HTTP_GET, handle_SSDP);
#endif #endif
#ifdef CAPTIVE_PORTAL_FEATURE #ifdef CAPTIVE_PORTAL_FEATURE
#if defined(ASYNCWEBSERVER) #if defined(ASYNCWEBSERVER)
web_server.on ("/generate_204", HTTP_ANY, [] (AsyncWebServerRequest * request) { web_server.on ("/generate_204", HTTP_ANY, [] (AsyncWebServerRequest * request) {
request->redirect ("/"); request->redirect ("/");
}); });
@ -332,12 +350,12 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
web_server.on ("/fwlink/", HTTP_ANY, [] (AsyncWebServerRequest * request) { web_server.on ("/fwlink/", HTTP_ANY, [] (AsyncWebServerRequest * request) {
request->redirect ("/"); request->redirect ("/");
}); });
#else #else
web_server.on("/generate_204",HTTP_ANY, handle_web_interface_root); web_server.on("/generate_204",HTTP_ANY, handle_web_interface_root);
web_server.on("/gconnectivitycheck.gstatic.com",HTTP_ANY, handle_web_interface_root); web_server.on("/gconnectivitycheck.gstatic.com",HTTP_ANY, handle_web_interface_root);
//do not forget the / at the end //do not forget the / at the end
web_server.on("/fwlink/",HTTP_ANY, handle_web_interface_root); web_server.on("/fwlink/",HTTP_ANY, handle_web_interface_root);
#endif #endif
#endif #endif
//SPIFFS //SPIFFS
web_server.on ("/files", HTTP_ANY, handleFileList, SPIFFSFileupload); web_server.on ("/files", HTTP_ANY, handleFileList, SPIFFSFileupload);

View File

@ -63,11 +63,11 @@ public:
AsyncWebServer web_server; AsyncWebServer web_server;
AsyncEventSource web_events; AsyncEventSource web_events;
#else #else
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
ESP8266WebServer web_server; ESP8266WebServer web_server;
#else #else
WebServer web_server; WebServer web_server;
#endif #endif
#endif #endif
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
#if defined(ASYNCWEBSERVER) #if defined(ASYNCWEBSERVER)

View File

@ -41,11 +41,11 @@ DNSServer dnsServer;
const byte DNS_PORT = 53; const byte DNS_PORT = 53;
#endif #endif
#ifdef SSDP_FEATURE #ifdef SSDP_FEATURE
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266SSDP.h> #include <ESP8266SSDP.h>
#else #else
#include <ESP32SSDP.h> #include <ESP32SSDP.h>
#endif #endif
#endif #endif
#ifdef NETBIOS_FEATURE #ifdef NETBIOS_FEATURE
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
@ -175,7 +175,8 @@ void WIFI_CONFIG::Safe_Setup()
//wifi event //wifi event
void onWiFiEvent(WiFiEvent_t event){ void onWiFiEvent(WiFiEvent_t event)
{
switch (event) { switch (event) {
case WIFI_EVENT_STAMODE_CONNECTED: case WIFI_EVENT_STAMODE_CONNECTED:
@ -253,7 +254,7 @@ bool WIFI_CONFIG::Setup (bool force_ap)
#endif #endif
sleep_mode = bflag; sleep_mode = bflag;
if (force_ap){ if (force_ap) {
bmode = AP_MODE; bmode = AP_MODE;
} else { } else {
//AP or client ? //AP or client ?
@ -467,7 +468,7 @@ bool WIFI_CONFIG::Setup (bool force_ap)
#else #else
esp_wifi_set_protocol (ESP_IF_WIFI_STA, bflag); esp_wifi_set_protocol (ESP_IF_WIFI_STA, bflag);
#endif #endif
if (strlen(pwd) > 0){ if (strlen(pwd) > 0) {
WiFi.begin (sbuf, pwd); WiFi.begin (sbuf, pwd);
} else { } else {
WiFi.begin (sbuf); WiFi.begin (sbuf);
@ -477,7 +478,9 @@ bool WIFI_CONFIG::Setup (bool force_ap)
WiFi.setSleepMode ( (WiFiSleepType_t) sleep_mode); WiFi.setSleepMode ( (WiFiSleepType_t) sleep_mode);
#else #else
//for backward compatibility //for backward compatibility
if ((wifi_ps_type_t) sleep_mode == WIFI_PS_MAX_MODEM)sleep_mode=WIFI_PS_MIN_MODEM; if ((wifi_ps_type_t) sleep_mode == WIFI_PS_MAX_MODEM) {
sleep_mode=WIFI_PS_MIN_MODEM;
}
esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode); esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode);
#endif #endif
delay (100); delay (100);
@ -556,14 +559,15 @@ bool WIFI_CONFIG::Setup (bool force_ap)
} }
#ifdef ESP_OLED_FEATURE #ifdef ESP_OLED_FEATURE
OLED_DISPLAY::setCursor(0, 48); OLED_DISPLAY::setCursor(0, 48);
if (force_ap){ if (force_ap) {
ESPCOM::print("Safe mode 1", OLED_PIPE); ESPCOM::print("Safe mode 1", OLED_PIPE);
} else if ((WiFi.getMode() == WIFI_STA) && (WiFi.status() == WL_CONNECTED)) { } else if ((WiFi.getMode() == WIFI_STA) && (WiFi.status() == WL_CONNECTED)) {
ESPCOM::print("Connected", OLED_PIPE); ESPCOM::print("Connected", OLED_PIPE);
OLED_DISPLAY::setCursor(0, 0); OLED_DISPLAY::setCursor(0, 0);
ESPCOM::print(sbuf, OLED_PIPE); ESPCOM::print(sbuf, OLED_PIPE);
} else if (WiFi.getMode() != WIFI_STA) {
ESPCOM::print("AP Ready", OLED_PIPE);
} }
else if (WiFi.getMode() != WIFI_STA) ESPCOM::print("AP Ready", OLED_PIPE);
#endif #endif
ESPCOM::flush (DEFAULT_PRINTER_PIPE); ESPCOM::flush (DEFAULT_PRINTER_PIPE);
return true; return true;
@ -630,15 +634,15 @@ bool WIFI_CONFIG::Enable_servers()
SSDP.setSchemaURL ("description.xml"); SSDP.setSchemaURL ("description.xml");
SSDP.setHTTPPort ( wifi_config.iweb_port); SSDP.setHTTPPort ( wifi_config.iweb_port);
SSDP.setName (shost.c_str() ); SSDP.setName (shost.c_str() );
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
stmp = String (ESP.getChipId() ); stmp = String (ESP.getChipId() );
SSDP.setModelName (ESP8266_MODEL_NAME); SSDP.setModelName (ESP8266_MODEL_NAME);
SSDP.setModelURL (ESP8266_MODEL_URL); SSDP.setModelURL (ESP8266_MODEL_URL);
#else #else
stmp = String ( (uint16_t) (ESP.getEfuseMac() >> 32) ); stmp = String ( (uint16_t) (ESP.getEfuseMac() >> 32) );
SSDP.setModelName (ESP32_MODEL_NAME); SSDP.setModelName (ESP32_MODEL_NAME);
SSDP.setModelURL (ESP32_MODEL_URL); SSDP.setModelURL (ESP32_MODEL_URL);
#endif #endif
SSDP.setSerialNumber (stmp.c_str() ); SSDP.setSerialNumber (stmp.c_str() );
SSDP.setURL ("/"); SSDP.setURL ("/");
SSDP.setModelNumber (ESP_MODEL_NUMBER); SSDP.setModelNumber (ESP_MODEL_NUMBER);