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.
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):
* ESPAsyncWebServer from @me-no-dev
if you target ESP8266
@ -98,14 +98,14 @@ if you target ESP32:
Specific for ESP32
* ESP32SSDP
If you want sync webserver (recommended as stable):
* arduinoWebSockets fron @Links2004
* arduinoWebSockets from @Links2004
If you want OLED support:
* oled-ssd1306 from @squix78
If you want DHT11/22 support:
* 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)
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

View File

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

View File

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

View File

@ -142,7 +142,8 @@ void CONFIG::InitFirmwareTarget()
SetFirmwareTarget (UNKNOWN_FW) ;
}
}
void CONFIG::InitOutput(){
void CONFIG::InitOutput()
{
byte bflag = 0;
if (!CONFIG::read_byte (EP_OUTPUT_FLAG, &bflag ) ) {
bflag = 0;
@ -150,7 +151,8 @@ void CONFIG::InitOutput(){
CONFIG::output_flag = bflag;
}
bool CONFIG::is_locked(byte flag){
bool CONFIG::is_locked(byte flag)
{
return ((CONFIG::output_flag & flag) == flag);
}
@ -163,8 +165,9 @@ void CONFIG::InitDirectSD()
bool CONFIG::InitBaudrate(long value)
{
long baud_rate = 0;
if (value > 0)baud_rate = value;
else {
if (value > 0) {
baud_rate = value;
} else {
if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) {
return false;
}
@ -248,7 +251,8 @@ void CONFIG::esp_restart (bool async)
};
}
#ifdef DHT_FEATURE
void CONFIG::InitDHT(bool refresh) {
void CONFIG::InitDHT(bool refresh)
{
if (!refresh) {
byte bflag = DEFAULT_DHT_TYPE;
int ibuf = DEFAULT_DHT_INTERVAL;
@ -261,7 +265,9 @@ void CONFIG::InitDHT(bool refresh) {
}
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
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_buffer[0]='E';
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);
}
uint8_t CONFIG::get_EEPROM_version(){
uint8_t CONFIG::get_EEPROM_version()
{
byte byte_buffer[6];
long baud_rate;
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) return EEPROM_V0;
if ((byte_buffer[0]=='E') && (byte_buffer[1]=='S') && (byte_buffer[2]=='P')&& (byte_buffer[3]=='3') && (byte_buffer[4]=='D')){
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) {
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];
}
@ -530,10 +540,13 @@ uint8_t CONFIG::get_EEPROM_version(){
return EEPROM_V0;
}
bool CONFIG::adjust_EEPROM_settings(){
bool CONFIG::adjust_EEPROM_settings()
{
uint8_t v = get_EEPROM_version();
bool bdone =false;
if (v == EEPROM_CURRENT_VERSION) return true;
if (v == EEPROM_CURRENT_VERSION) {
return true;
}
if (v == 1) {
bdone =true;
#ifdef SDCARD_FEATURE
@ -554,7 +567,7 @@ bool CONFIG::adjust_EEPROM_settings(){
bdone =false;
}
}
if (bdone){
if (bdone) {
set_EEPROM_version(EEPROM_CURRENT_VERSION);
}
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((size_buffer == 0 ) || (byte_buffer == NULL )){
if((size_buffer == 0 ) || (byte_buffer == NULL )) {
LOG ("Error write string\r\n")
return false;
}
@ -984,8 +997,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
//if higher than 1MB take out SPIFFS
if (flashsize > 1024 * 1024) {
flashsize = (1024 * 1024)-ESP.getSketchSize()-1024;
}
else {
} else {
flashsize = flashsize - ESP.getSketchSize()-info.totalBytes-1024;
}
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);
}
#ifdef NOTIFICATION_FEATURE
if (!plaintext)
if (!plaintext)
{
ESPCOM::print (F ("\"Notifications\":\""), output, espresponse);
} else
@ -1933,11 +1945,11 @@ if (!plaintext)
ESPCOM::print (F ("FW version: "), output, espresponse);
}
ESPCOM::print (FW_VERSION, output, espresponse);
#ifdef ARDUINO_ARCH_ESP8266
#ifdef ARDUINO_ARCH_ESP8266
ESPCOM::print (" ESP8266/8586", output, espresponse);
#else
#else
ESPCOM::print (" ESP32", output, espresponse);
#endif
#endif
if (!plaintext)
{
ESPCOM::print (F ("\"}"), output, espresponse);

View File

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

View File

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

View File

@ -25,16 +25,16 @@
// Initialize the OLED display using I2C
#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
#include "SH1106.h" // alias for `#include "SH1106Wire.h"`
#include "SH1106.h" // alias for `#include "SH1106Wire.h"`
#endif
#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
SH1106 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
SH1106 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
#endif
@ -71,15 +71,19 @@ const char ESP3D_Logo[] = {
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x07, 0x00, 0x00,
0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF,
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00
};
};
void OLED_DISPLAY::splash(){
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
void OLED_DISPLAY::splash()
{
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo);
update_lcd();
}
void OLED_DISPLAY::begin(){
void OLED_DISPLAY::begin()
{
//For Embeded OLED on Wifi kit 32
#if HELTEC_EMBEDDED_PIN > 0
pinMode(HELTEC_EMBEDDED_PIN,OUTPUT);
@ -89,29 +93,39 @@ void OLED_DISPLAY::begin(){
#endif
esp_display.init();
esp_display.clear();
#if OLED_FLIP_VERTICALY
#if OLED_FLIP_VERTICALY
esp_display.flipScreenVertically();
#endif
}
void OLED_DISPLAY::setCursor(int col, int row){
if (col!=-1) OLED_DISPLAY::col = col;
if (row!=-1) OLED_DISPLAY::row = row;
void OLED_DISPLAY::setCursor(int col, int 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());
}
void OLED_DISPLAY::print(const char * s){
void OLED_DISPLAY::print(const char * s)
{
display_text(s, col, row);
}
void OLED_DISPLAY::display_signal(int value, int x, int y) {
if(CONFIG::is_locked(FLAG_BLOCK_OLED))return;
void OLED_DISPLAY::display_signal(int value, int x, int y)
{
if(CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
//clear area only
esp_display.setColor(BLACK);
esp_display.fillRect(x, y, x + 46, 16);
esp_display.setColor(WHITE);
if (value == -1){
if (value == -1) {
esp_display.setFont(ArialMT_Plain_10);
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) {
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
void OLED_DISPLAY::display_progress(int value, int x, int y)
{
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
esp_display.setFont(ArialMT_Plain_10);
esp_display.setColor(BLACK);
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());
}
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w) {
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w)
{
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
return;
}
esp_display.setColor(BLACK);
esp_display.fillRect(x, y, x + w, 2);
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
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 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_size = esp_display.getStringWidth( txt);
p=1;
}
else if (y==32){
} else if (y==32) {
OLED_DISPLAY::L2 = txt;
OLED_DISPLAY::L2_size = esp_display.getStringWidth( txt);
p=2;
}
else if (y==0){
} else if (y==0) {
max = 85;
OLED_DISPLAY::L0 = txt;
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
p=0;
}
else{
} else {
OLED_DISPLAY::L3 = txt;
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
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
while (esp_display.getStringWidth(Stxt) > max){
while (esp_display.getStringWidth(Stxt) > max) {
Stxt.remove(Stxt.length()-1, 1);
}
esp_display.drawString(x, y, Stxt.c_str());
}
void OLED_DISPLAY::update_lcd(){
void OLED_DISPLAY::update_lcd()
{
esp_display.display();
}
void OLED_DISPLAY::clear_lcd(){
void OLED_DISPLAY::clear_lcd()
{
esp_display.clear();
}
int OLED_DISPLAY::col = 0;

View File

@ -25,28 +25,28 @@
class OLED_DISPLAY
{
public:
static void begin();
static void setCursor(int col, int row = -1);
static void print(String & s);
static void print(const char * s);
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_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 update_lcd();
static void clear_lcd();
static void splash();
static String L0;
static String L1;
static String L2;
static String L3;
static int L0_size;
static int L1_size;
static int L2_size;
static int L3_size;
static void begin();
static void setCursor(int col, int row = -1);
static void print(String & s);
static void print(const char * s);
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_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 update_lcd();
static void clear_lcd();
static void splash();
static String L0;
static String L1;
static String L2;
static String L3;
static int L0_size;
static int L1_size;
static int L2_size;
static int L3_size;
private:
static int col;
static int row;
static int col;
static int row;
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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