mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-14 02:05:55 +08:00
Update Readme
Apply style to code
This commit is contained in:
parent
4d6bac193a
commit
02264b8da5
@ -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
|
||||||
|
@ -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;
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ void handle_login(AsyncWebServerRequest *request)
|
|||||||
{
|
{
|
||||||
#ifdef AUTHENTICATION_FEATURE
|
#ifdef AUTHENTICATION_FEATURE
|
||||||
#else
|
#else
|
||||||
AsyncWebServerResponse * response = request->beginResponse (200, "application/json", "{\"status\":\"Ok\",\"authentication_lvl\":\"admin\"}");
|
AsyncWebServerResponse * response = request->beginResponse (200, "application/json", "{\"status\":\"Ok\",\"authentication_lvl\":\"admin\"}");
|
||||||
response->addHeader("Cache-Control","no-cache");
|
response->addHeader("Cache-Control","no-cache");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -396,7 +396,7 @@ void SPIFFSFileupload (AsyncWebServerRequest *request, String filename, size_t i
|
|||||||
LOG ("Uploading: ")
|
LOG ("Uploading: ")
|
||||||
LOG (filename)
|
LOG (filename)
|
||||||
LOG ("\n")
|
LOG ("\n")
|
||||||
//get authentication status
|
//get authentication status
|
||||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
//Guest cannot upload - only admin
|
//Guest cannot upload - only admin
|
||||||
if (auth_level == LEVEL_GUEST) {
|
if (auth_level == LEVEL_GUEST) {
|
||||||
@ -414,9 +414,9 @@ void SPIFFSFileupload (AsyncWebServerRequest *request, String filename, size_t i
|
|||||||
LOG ("\n")
|
LOG ("\n")
|
||||||
}
|
}
|
||||||
if(auth_level != LEVEL_ADMIN) {
|
if(auth_level != LEVEL_ADMIN) {
|
||||||
String filename = upload_filename;
|
String filename = upload_filename;
|
||||||
upload_filename = "/user" + filename;
|
upload_filename = "/user" + filename;
|
||||||
}
|
}
|
||||||
//Upload start
|
//Upload start
|
||||||
//**************
|
//**************
|
||||||
if (!index) {
|
if (!index) {
|
||||||
@ -461,8 +461,8 @@ void SPIFFSFileupload (AsyncWebServerRequest *request, String filename, size_t i
|
|||||||
if (request->arg (sizeargname.c_str()) != String(filesize)) {
|
if (request->arg (sizeargname.c_str()) != String(filesize)) {
|
||||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||||
SPIFFS.remove (upload_filename);
|
SPIFFS.remove (upload_filename);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
LOG ("Close file\n")
|
LOG ("Close file\n")
|
||||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||||
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||||
@ -569,12 +569,12 @@ void WebUpdateUpload (AsyncWebServerRequest *request, String filename, size_t in
|
|||||||
String sizeargname = filename + "S";
|
String sizeargname = filename + "S";
|
||||||
if (request->hasArg (sizeargname.c_str()) ) {
|
if (request->hasArg (sizeargname.c_str()) ) {
|
||||||
ESPCOM::println (F ("Check integrity"), PRINTER_PIPE);
|
ESPCOM::println (F ("Check integrity"), PRINTER_PIPE);
|
||||||
if (request->arg (sizeargname.c_str()) != String(totalSize)) {
|
if (request->arg (sizeargname.c_str()) != String(totalSize)) {
|
||||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||||
ESPCOM::println (F ("Update Error"), PRINTER_PIPE);
|
ESPCOM::println (F ("Update Error"), PRINTER_PIPE);
|
||||||
Update.end();
|
Update.end();
|
||||||
request->client()->abort();
|
request->client()->abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
||||||
//Update is done
|
//Update is done
|
||||||
@ -628,13 +628,13 @@ void handle_not_found (AsyncWebServerRequest *request)
|
|||||||
//Handle web command query and send answer//////////////////////////////
|
//Handle web command query and send answer//////////////////////////////
|
||||||
void handle_web_command (AsyncWebServerRequest *request)
|
void handle_web_command (AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
//to save time if already disconnected
|
//to save time if already disconnected
|
||||||
if (request->hasArg ("PAGEID") ) {
|
if (request->hasArg ("PAGEID") ) {
|
||||||
if (request->arg ("PAGEID").length() > 0 ) {
|
if (request->arg ("PAGEID").length() > 0 ) {
|
||||||
if (request->arg ("PAGEID").toInt() != id_connection) {
|
if (request->arg ("PAGEID").toInt() != id_connection) {
|
||||||
request->send (200, "text/plain", "Invalid command");
|
request->send (200, "text/plain", "Invalid command");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||||
@ -709,8 +709,10 @@ void handle_web_command (AsyncWebServerRequest *request)
|
|||||||
LOG ("Start PurgeSerial\r\n")
|
LOG ("Start PurgeSerial\r\n")
|
||||||
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);
|
||||||
@ -982,10 +984,10 @@ void handle_web_command_silent (AsyncWebServerRequest *request)
|
|||||||
//to save time if already disconnected
|
//to save time if already disconnected
|
||||||
if (request->hasArg ("PAGEID") ) {
|
if (request->hasArg ("PAGEID") ) {
|
||||||
if (request->arg ("PAGEID").length() > 0 ) {
|
if (request->arg ("PAGEID").length() > 0 ) {
|
||||||
if (request->arg ("PAGEID").toInt() != id_connection) {
|
if (request->arg ("PAGEID").toInt() != id_connection) {
|
||||||
request->send (200, "text/plain", "Invalid command");
|
request->send (200, "text/plain", "Invalid command");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||||
@ -1109,16 +1111,18 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
|||||||
//Upload start
|
//Upload start
|
||||||
//**************
|
//**************
|
||||||
if (!index) {
|
if (!index) {
|
||||||
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();
|
||||||
@ -1167,7 +1171,7 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
LOG("Creation failed\r\n");
|
LOG("Creation failed\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Upload write
|
//Upload write
|
||||||
@ -1184,12 +1188,12 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
|||||||
}
|
}
|
||||||
//it is an end line
|
//it is an end line
|
||||||
else if ( (data[pos] == 13) || (data[pos] == 10) ) {
|
else if ( (data[pos] == 13) || (data[pos] == 10) ) {
|
||||||
is_comment = false;
|
is_comment = false;
|
||||||
//does line fit the buffer ?
|
//does line fit the buffer ?
|
||||||
if (current_line.length() < 126) {
|
if (current_line.length() < 126) {
|
||||||
//do we have something in buffer ?
|
//do we have something in buffer ?
|
||||||
if (current_line.length() > 0 ) {
|
if (current_line.length() > 0 ) {
|
||||||
lineNb++;
|
lineNb++;
|
||||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||||
LOG ("Error sending line\n")
|
LOG ("Error sending line\n")
|
||||||
CloseSerialUpload (true, current_filename,lineNb);
|
CloseSerialUpload (true, current_filename,lineNb);
|
||||||
@ -1253,17 +1257,18 @@ 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);
|
||||||
//Dispatch who is active ID
|
//Dispatch who is active ID
|
||||||
web_interface->web_events.send( String(id_connection).c_str(),"ActiveID");
|
web_interface->web_events.send( String(id_connection).c_str(),"ActiveID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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,20 +150,15 @@ 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 {
|
||||||
}
|
if( auth_type == LEVEL_USER) {
|
||||||
else {
|
LOG("user identified\r\n");
|
||||||
if( auth_type == LEVEL_USER)
|
} else {
|
||||||
{
|
LOG("guest identified\r\n");
|
||||||
LOG("user identified\r\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG("guest identified\r\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
//manage parameters
|
//manage parameters
|
||||||
@ -381,13 +376,13 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
//disable wifi
|
//disable wifi
|
||||||
ESPCOM::println ("Disabling Wifi", output, espresponse);
|
ESPCOM::println ("Disabling Wifi", output, espresponse);
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(-1);
|
OLED_DISPLAY::display_signal(-1);
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
ESPCOM::print("", OLED_PIPE);
|
ESPCOM::print("", OLED_PIPE);
|
||||||
OLED_DISPLAY::setCursor(0, 16);
|
OLED_DISPLAY::setCursor(0, 16);
|
||||||
ESPCOM::print("", OLED_PIPE);
|
ESPCOM::print("", OLED_PIPE);
|
||||||
OLED_DISPLAY::setCursor(0, 48);
|
OLED_DISPLAY::setCursor(0, 48);
|
||||||
ESPCOM::print("Wifi disabled", OLED_PIPE);
|
ESPCOM::print("Wifi disabled", OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
WiFi.enableSTA (false);
|
WiFi.enableSTA (false);
|
||||||
@ -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,56 +589,56 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
case 1024:
|
case 1024:
|
||||||
resolution=10;
|
resolution=10;
|
||||||
break;
|
break;
|
||||||
case 2047:
|
case 2047:
|
||||||
resolution=11;
|
resolution=11;
|
||||||
break;
|
break;
|
||||||
case 4095:
|
case 4095:
|
||||||
resolution=12;
|
resolution=12;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
resolution=8;
|
resolution=8;
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -658,51 +663,50 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
parameter = get_param (cmd_params, "L=", false);
|
parameter = get_param (cmd_params, "L=", false);
|
||||||
int l = parameter.toInt();
|
int l = parameter.toInt();
|
||||||
parameter = get_param (cmd_params, "T=", true);
|
parameter = get_param (cmd_params, "T=", true);
|
||||||
OLED_DISPLAY::setCursor(c, l);
|
OLED_DISPLAY::setCursor(c, l);
|
||||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Output to oled line 1
|
//Output to oled line 1
|
||||||
//[ESP211]<Text>
|
//[ESP211]<Text>
|
||||||
case 211: {
|
case 211: {
|
||||||
parameter = get_param (cmd_params, "", true);
|
parameter = get_param (cmd_params, "", true);
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Output to oled line 2
|
//Output to oled line 2
|
||||||
//[ESP212]<Text>
|
//[ESP212]<Text>
|
||||||
case 212: {
|
case 212: {
|
||||||
parameter = get_param (cmd_params, "", true);
|
parameter = get_param (cmd_params, "", true);
|
||||||
OLED_DISPLAY::setCursor(0, 16);
|
OLED_DISPLAY::setCursor(0, 16);
|
||||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Output to oled line 3
|
//Output to oled line 3
|
||||||
//[ESP213]<Text>
|
//[ESP213]<Text>
|
||||||
case 213: {
|
case 213: {
|
||||||
parameter = get_param (cmd_params, "", true);
|
parameter = get_param (cmd_params, "", true);
|
||||||
OLED_DISPLAY::setCursor(0, 32);
|
OLED_DISPLAY::setCursor(0, 32);
|
||||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Output to oled line 4
|
//Output to oled line 4
|
||||||
//[ESP214]<Text>
|
//[ESP214]<Text>
|
||||||
case 214: {
|
case 214: {
|
||||||
parameter = get_param (cmd_params, "", true);
|
parameter = get_param (cmd_params, "", true);
|
||||||
OLED_DISPLAY::setCursor(0, 48);
|
OLED_DISPLAY::setCursor(0, 48);
|
||||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -1269,7 +1273,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
ESPCOM::print (F ("\"}]}"), output, espresponse);
|
ESPCOM::print (F ("\"}]}"), output, espresponse);
|
||||||
ESPCOM::println (F (","), output, espresponse);
|
ESPCOM::println (F (","), output, espresponse);
|
||||||
|
|
||||||
//Output flag
|
//Output flag
|
||||||
ESPCOM::print (F ("{\"F\":\"printer\",\"P\":\""), output, espresponse);
|
ESPCOM::print (F ("{\"F\":\"printer\",\"P\":\""), output, espresponse);
|
||||||
ESPCOM::print ( (const char *) CONFIG::intTostr (EP_OUTPUT_FLAG), output, espresponse);
|
ESPCOM::print ( (const char *) CONFIG::intTostr (EP_OUTPUT_FLAG), output, espresponse);
|
||||||
ESPCOM::print (F ("\",\"T\":\"F\",\"V\":\""), output, espresponse);
|
ESPCOM::print (F ("\",\"T\":\"F\",\"V\":\""), output, espresponse);
|
||||||
@ -1283,7 +1287,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
s+= "\"}";
|
s+= "\"}";
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
s+=",{\"Oled\":\"";
|
s+=",{\"Oled\":\"";
|
||||||
s+= CONFIG::intTostr(FLAG_BLOCK_OLED);
|
s+= CONFIG::intTostr(FLAG_BLOCK_OLED);
|
||||||
s+="\"}";
|
s+="\"}";
|
||||||
#endif
|
#endif
|
||||||
s+=",{\"Serial\":\"";
|
s+=",{\"Serial\":\"";
|
||||||
@ -1318,11 +1322,11 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
ESPCOM::print ( (const char *) CONFIG::intTostr (DHTesp::DHT22), output, espresponse);
|
ESPCOM::print ( (const char *) CONFIG::intTostr (DHTesp::DHT22), output, espresponse);
|
||||||
ESPCOM::print (F ("\"},{\"AM2302\":\""), output, espresponse);
|
ESPCOM::print (F ("\"},{\"AM2302\":\""), output, espresponse);
|
||||||
ESPCOM::print ( (const char *) CONFIG::intTostr (DHTesp::RHT03), output, espresponse);
|
ESPCOM::print ( (const char *) CONFIG::intTostr (DHTesp::RHT03), output, espresponse);
|
||||||
ESPCOM::print (F ("\"},{\"RHT03\":\""), output, espresponse);
|
ESPCOM::print (F ("\"},{\"RHT03\":\""), output, espresponse);
|
||||||
ESPCOM::print ( (const char *) CONFIG::intTostr (DHTesp::AM2302), output, espresponse);
|
ESPCOM::print ( (const char *) CONFIG::intTostr (DHTesp::AM2302), output, espresponse);
|
||||||
ESPCOM::print (F ("\"}]}"), output, espresponse);
|
ESPCOM::print (F ("\"}]}"), output, espresponse);
|
||||||
|
|
||||||
//DHT interval
|
//DHT interval
|
||||||
ESPCOM::println (F (","), output, espresponse);
|
ESPCOM::println (F (","), output, espresponse);
|
||||||
ESPCOM::print (F ("{\"F\":\"printer\",\"P\":\""), output, espresponse);
|
ESPCOM::print (F ("{\"F\":\"printer\",\"P\":\""), output, espresponse);
|
||||||
ESPCOM::print ( (const char *) CONFIG::intTostr (EP_DHT_INTERVAL), output, espresponse);
|
ESPCOM::print ( (const char *) CONFIG::intTostr (EP_DHT_INTERVAL), 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) {
|
||||||
@ -1446,18 +1450,18 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
bool plain = (parameter == "plain");
|
bool plain = (parameter == "plain");
|
||||||
|
|
||||||
#if defined(ASYNCWEBSERVER)
|
#if defined(ASYNCWEBSERVER)
|
||||||
if (!plain) {
|
if (!plain) {
|
||||||
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
||||||
}
|
}
|
||||||
int n = WiFi.scanComplete();
|
int n = WiFi.scanComplete();
|
||||||
if (n == -2) {
|
if (n == -2) {
|
||||||
WiFi.scanNetworks (ESP_USE_ASYNC);
|
WiFi.scanNetworks (ESP_USE_ASYNC);
|
||||||
} else if (n) {
|
} else if (n) {
|
||||||
#else
|
#else
|
||||||
int n = WiFi.scanNetworks ();
|
int n = WiFi.scanNetworks ();
|
||||||
if (!plain) {
|
if (!plain) {
|
||||||
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -1579,7 +1585,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//[ESP501]<line>
|
//[ESP501]<line>
|
||||||
case 501: { //send line checksum
|
case 501: { //send line checksum
|
||||||
cmd_params.trim();
|
cmd_params.trim();
|
||||||
@ -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];
|
||||||
@ -1665,7 +1671,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) {
|
||||||
tmp+= " ";
|
tmp+= " ";
|
||||||
tmp += sbuf;
|
tmp += sbuf;
|
||||||
}
|
}
|
||||||
ESPCOM::println (tmp.c_str(), output, espresponse);
|
ESPCOM::println (tmp.c_str(), output, espresponse);
|
||||||
} else {
|
} else {
|
||||||
response = false;
|
response = false;
|
||||||
@ -1697,7 +1703,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
parameter = get_param (cmd_params, "TS=");
|
parameter = get_param (cmd_params, "TS=");
|
||||||
if (parameter.length() > 0) {
|
if (parameter.length() > 0) {
|
||||||
if (!CONFIG::write_string (ESP_NOTIFICATION_SETTINGS, parameter.c_str() ) ) {
|
if (!CONFIG::write_string (ESP_NOTIFICATION_SETTINGS, parameter.c_str() ) ) {
|
||||||
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
response = true;
|
response = true;
|
||||||
@ -1707,7 +1713,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
parameter = get_param (cmd_params, "T1=");
|
parameter = get_param (cmd_params, "T1=");
|
||||||
if (parameter.length() > 0) {
|
if (parameter.length() > 0) {
|
||||||
if (!CONFIG::write_string (ESP_NOTIFICATION_TOKEN1, parameter.c_str() ) ) {
|
if (!CONFIG::write_string (ESP_NOTIFICATION_TOKEN1, parameter.c_str() ) ) {
|
||||||
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
response = true;
|
response = true;
|
||||||
@ -1717,7 +1723,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
parameter = get_param (cmd_params, "T2=");
|
parameter = get_param (cmd_params, "T2=");
|
||||||
if (parameter.length() > 0) {
|
if (parameter.length() > 0) {
|
||||||
if (!CONFIG::write_string (ESP_NOTIFICATION_TOKEN2, parameter.c_str() ) ) {
|
if (!CONFIG::write_string (ESP_NOTIFICATION_TOKEN2, parameter.c_str() ) ) {
|
||||||
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
response = true;
|
response = true;
|
||||||
@ -1778,7 +1784,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
//flush to be sure send buffer is empty
|
//flush to be sure send buffer is empty
|
||||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||||
}
|
}
|
||||||
CONFIG::wait (1);
|
CONFIG::wait (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentfile.close();
|
currentfile.close();
|
||||||
@ -1876,7 +1882,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
#else
|
#else
|
||||||
ESPCOM::print (F ("no"), output, espresponse);
|
ESPCOM::print (F ("no"), output, espresponse);
|
||||||
#endif
|
#endif
|
||||||
ESPCOM::print (F (" # webcommunication:"), output, espresponse);
|
ESPCOM::print (F (" # webcommunication:"), output, espresponse);
|
||||||
#if defined (ASYNCWEBSERVER)
|
#if defined (ASYNCWEBSERVER)
|
||||||
ESPCOM::print (F ("Async"), output, espresponse);
|
ESPCOM::print (F ("Async"), output, espresponse);
|
||||||
#else
|
#else
|
||||||
@ -1886,8 +1892,10 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
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) {
|
||||||
|
126
esp3d/config.cpp
126
esp3d/config.cpp
@ -73,7 +73,7 @@ void CONFIG::wait (uint32_t milliseconds)
|
|||||||
wdtFeed();
|
wdtFeed();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
delay(milliseconds);
|
delay(milliseconds);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ const char* CONFIG::GetFirmwareTargetShortName()
|
|||||||
response = F ("marlinkimbra");
|
response = F ("marlinkimbra");
|
||||||
} else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) {
|
} else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) {
|
||||||
response = F ("smoothieware");
|
response = F ("smoothieware");
|
||||||
} else if ( CONFIG::FirmwareTarget == GRBL) {
|
} else if ( CONFIG::FirmwareTarget == GRBL) {
|
||||||
response = F ("grbl");
|
response = F ("grbl");
|
||||||
} else {
|
} else {
|
||||||
response = F ("???");
|
response = F ("???");
|
||||||
@ -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,12 +165,13 @@ 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;
|
||||||
if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) {
|
} else {
|
||||||
return false;
|
if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( ! (baud_rate == 9600 || baud_rate == 19200 || baud_rate == 38400 || baud_rate == 57600 || baud_rate == 115200 || baud_rate == 230400 || baud_rate == 250000 || baud_rate == 500000 || baud_rate == 921600 ) ) {
|
if ( ! (baud_rate == 9600 || baud_rate == 19200 || baud_rate == 38400 || baud_rate == 57600 || baud_rate == 115200 || baud_rate == 230400 || baud_rate == 250000 || baud_rate == 500000 || baud_rate == 921600 ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -178,9 +181,9 @@ bool CONFIG::InitBaudrate(long value)
|
|||||||
#ifdef USE_SERIAL_0
|
#ifdef USE_SERIAL_0
|
||||||
if (Serial.baudRate() != baud_rate) {
|
if (Serial.baudRate() != baud_rate) {
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
Serial.begin (baud_rate);
|
Serial.begin (baud_rate);
|
||||||
#else
|
#else
|
||||||
Serial.begin (baud_rate, ESP_SERIAL_PARAM, ESP_RX_PIN, ESP_TX_PIN);
|
Serial.begin (baud_rate, ESP_SERIAL_PARAM, ESP_RX_PIN, ESP_TX_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -188,18 +191,18 @@ bool CONFIG::InitBaudrate(long value)
|
|||||||
#ifdef USE_SERIAL_1
|
#ifdef USE_SERIAL_1
|
||||||
if (Serial1.baudRate() != baud_rate) {
|
if (Serial1.baudRate() != baud_rate) {
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
Serial1.begin (baud_rate);
|
Serial1.begin (baud_rate);
|
||||||
#else
|
#else
|
||||||
Serial1.begin (baud_rate, ESP_SERIAL_PARAM, ESP_RX_PIN, ESP_TX_PIN);
|
Serial1.begin (baud_rate, ESP_SERIAL_PARAM, ESP_RX_PIN, ESP_TX_PIN);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SERIAL_2
|
#ifdef USE_SERIAL_2
|
||||||
if (Serial2.baudRate() != baud_rate) {
|
if (Serial2.baudRate() != baud_rate) {
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
Serial2.begin (baud_rate);
|
Serial2.begin (baud_rate);
|
||||||
#else
|
#else
|
||||||
Serial2.begin (baud_rate, ESP_SERIAL_PARAM, ESP_RX_PIN, ESP_TX_PIN);
|
Serial2.begin (baud_rate, ESP_SERIAL_PARAM, ESP_RX_PIN, ESP_TX_PIN);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -237,7 +240,7 @@ void CONFIG::esp_restart (bool async)
|
|||||||
delay (1000);
|
delay (1000);
|
||||||
}
|
}
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
//ESP8266 has only serial
|
//ESP8266 has only serial
|
||||||
Serial.swap();
|
Serial.swap();
|
||||||
#endif
|
#endif
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
@ -248,20 +251,23 @@ 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;
|
||||||
if (!CONFIG::read_byte (EP_DHT_TYPE, &bflag ) ) {
|
if (!CONFIG::read_byte (EP_DHT_TYPE, &bflag ) ) {
|
||||||
bflag = DEFAULT_DHT_TYPE;
|
bflag = DEFAULT_DHT_TYPE;
|
||||||
}
|
}
|
||||||
CONFIG::DHT_type = bflag;
|
CONFIG::DHT_type = bflag;
|
||||||
if (!CONFIG::read_buffer (EP_DHT_INTERVAL, (byte *) &ibuf, INTEGER_LENGTH) ) {
|
if (!CONFIG::read_buffer (EP_DHT_INTERVAL, (byte *) &ibuf, INTEGER_LENGTH) ) {
|
||||||
ibuf = DEFAULT_DHT_INTERVAL;
|
ibuf = DEFAULT_DHT_INTERVAL;
|
||||||
}
|
}
|
||||||
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()
|
||||||
@ -299,13 +305,13 @@ void CONFIG::init_time_client()
|
|||||||
configTime (3600 * (t1), d1 * 3600, s1.c_str(), s2.c_str(), s3.c_str() );
|
configTime (3600 * (t1), d1 * 3600, s1.c_str(), s2.c_str(), s3.c_str() );
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
if (WiFi.getMode() == WIFI_STA) {
|
if (WiFi.getMode() == WIFI_STA) {
|
||||||
int nb = 0;
|
int nb = 0;
|
||||||
while ((now < 8 * 3600 * 2) && (nb < 6)) {
|
while ((now < 8 * 3600 * 2) && (nb < 6)) {
|
||||||
wait(500);
|
wait(500);
|
||||||
nb++;
|
nb++;
|
||||||
now = time(nullptr);
|
now = time(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -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,27 +520,33 @@ 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
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 EEPROM_V0;
|
return EEPROM_V0;
|
||||||
}
|
}
|
||||||
if ((baud_rate == 9600 || baud_rate == 19200 || baud_rate == 38400 || baud_rate == 57600 || baud_rate == 115200 || baud_rate == 230400 || baud_rate == 250000 || baud_rate == 500000 || baud_rate == 921600 ) ) {
|
if ((baud_rate == 9600 || baud_rate == 19200 || baud_rate == 38400 || baud_rate == 57600 || baud_rate == 115200 || baud_rate == 230400 || baud_rate == 250000 || baud_rate == 500000 || baud_rate == 921600 ) ) {
|
||||||
return EEPROM_V1;
|
return EEPROM_V1;
|
||||||
}
|
}
|
||||||
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
|
||||||
@ -550,11 +563,11 @@ bool CONFIG::adjust_EEPROM_settings(){
|
|||||||
bdone =false;
|
bdone =false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!CONFIG::write_byte (EP_OUTPUT_FLAG, DEFAULT_OUTPUT_FLAG) ) {
|
if (!CONFIG::write_byte (EP_OUTPUT_FLAG, DEFAULT_OUTPUT_FLAG) ) {
|
||||||
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,10 +711,10 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//copy the value(s)
|
//copy the value(s)
|
||||||
EEPROM.begin (EEPROM_SIZE);
|
EEPROM.begin (EEPROM_SIZE);
|
||||||
@ -841,7 +854,7 @@ bool CONFIG::reset_config()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CONFIG::write_string (EP_TIME_SERVER1, FPSTR (DEFAULT_TIME_SERVER1) ) ) {
|
if (!CONFIG::write_string (EP_TIME_SERVER1, FPSTR (DEFAULT_TIME_SERVER1) ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -983,11 +996,10 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
|||||||
SPIFFS.info (info);
|
SPIFFS.info (info);
|
||||||
//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);
|
||||||
if (!plaintext) {
|
if (!plaintext) {
|
||||||
ESPCOM::print (F ("\","), output, espresponse);
|
ESPCOM::print (F ("\","), output, espresponse);
|
||||||
@ -1017,7 +1029,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
|||||||
ESPCOM::print (F ("Available Size for update: "), output, espresponse);
|
ESPCOM::print (F ("Available Size for update: "), output, espresponse);
|
||||||
}
|
}
|
||||||
uint32_t flashsize = ESP.getFlashChipSize();
|
uint32_t flashsize = ESP.getFlashChipSize();
|
||||||
//Not OTA on 2Mb board per spec
|
//Not OTA on 2Mb board per spec
|
||||||
if (flashsize > 0x20000) {
|
if (flashsize > 0x20000) {
|
||||||
flashsize = 0x140000;
|
flashsize = 0x140000;
|
||||||
} else {
|
} else {
|
||||||
@ -1748,7 +1760,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
|||||||
{
|
{
|
||||||
ESPCOM::print (F ("\n"), output, espresponse);
|
ESPCOM::print (F ("\n"), output, espresponse);
|
||||||
}
|
}
|
||||||
//flag M117
|
//flag M117
|
||||||
if (!plaintext)
|
if (!plaintext)
|
||||||
{
|
{
|
||||||
ESPCOM::print (F ("\"M117_output\":\""), output, espresponse);
|
ESPCOM::print (F ("\"M117_output\":\""), 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);
|
||||||
|
@ -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:
|
{
|
||||||
bool header_sent;
|
public:
|
||||||
String buffer_web;
|
bool header_sent;
|
||||||
ESPResponseStream(){header_sent=false;};
|
String buffer_web;
|
||||||
|
ESPResponseStream()
|
||||||
|
{
|
||||||
|
header_sent=false;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
176
esp3d/esp3d.cpp
176
esp3d/esp3d.cpp
@ -86,7 +86,8 @@ DHTesp dht;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Contructor
|
//Contructor
|
||||||
Esp3D::Esp3D() {
|
Esp3D::Esp3D()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,15 +126,15 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
|
|||||||
startdelayms = 1000;
|
startdelayms = 1000;
|
||||||
#endif
|
#endif
|
||||||
#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();
|
||||||
delay(100);
|
delay(100);
|
||||||
now = millis();
|
now = millis();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
delay (startdelayms);
|
delay (startdelayms);
|
||||||
#endif
|
#endif
|
||||||
@ -191,19 +192,19 @@ 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","");
|
||||||
ESPCOM::println (autoscript.c_str(), DEFAULT_PRINTER_PIPE);
|
ESPCOM::println (autoscript.c_str(), DEFAULT_PRINTER_PIPE);
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//setup wifi according settings
|
//setup wifi according settings
|
||||||
if (!wifi_config.Setup() ) {
|
if (!wifi_config.Setup() ) {
|
||||||
ESPCOM::println (F ("Safe mode 1"), PRINTER_PIPE);
|
ESPCOM::println (F ("Safe mode 1"), PRINTER_PIPE);
|
||||||
@ -218,33 +219,33 @@ 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 ||
|
||||||
|
|
||||||
rtc_info->reason == REASON_SOFT_WDT_RST) {
|
rtc_info->reason == REASON_SOFT_WDT_RST) {
|
||||||
String s = "reset ";
|
String s = "reset ";
|
||||||
s+= String(rtc_info->reason);
|
s+= String(rtc_info->reason);
|
||||||
|
|
||||||
if (rtc_info->reason == REASON_EXCEPTION_RST) {
|
if (rtc_info->reason == REASON_EXCEPTION_RST) {
|
||||||
s+=" except ";
|
s+=" except ";
|
||||||
s+=String(rtc_info->exccause);
|
s+=String(rtc_info->exccause);
|
||||||
|
|
||||||
|
}
|
||||||
|
ESPCOM::println (s, PRINTER_PIPE);
|
||||||
}
|
}
|
||||||
ESPCOM::println (s, PRINTER_PIPE);
|
#else
|
||||||
}
|
if((( reason_0< 17) || ( reason_1< 17)) && !(((reason_0 == 1) && (reason_1 == 14)) || ((reason_0 == 16) && (reason_1 == 14))))
|
||||||
#else
|
{
|
||||||
if((( reason_0< 17) || ( reason_1< 17)) && !(((reason_0 == 1) && (reason_1 == 14)) || ((reason_0 == 16) && (reason_1 == 14))))
|
String s = "reset ";
|
||||||
{
|
ESPCOM::println (s, PRINTER_PIPE);
|
||||||
String s = "reset ";
|
s+=String(reason_0);
|
||||||
ESPCOM::println (s, PRINTER_PIPE);
|
s+="/";
|
||||||
s+=String(reason_0);
|
s+=String(reason_1);
|
||||||
s+="/";
|
|
||||||
s+=String(reason_1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif*/
|
#endif*/
|
||||||
|
|
||||||
#ifdef ASYNCWEBSERVER
|
#ifdef ASYNCWEBSERVER
|
||||||
if (WiFi.getMode() != WIFI_AP) {
|
if (WiFi.getMode() != WIFI_AP) {
|
||||||
@ -269,66 +270,77 @@ void Esp3D::process()
|
|||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//TODO use config
|
//TODO use config
|
||||||
CONFIG::wait(0);
|
CONFIG::wait(0);
|
||||||
}
|
}
|
||||||
//read / bridge all input
|
//read / bridge all input
|
||||||
ESPCOM::bridge();
|
ESPCOM::bridge();
|
||||||
//in case of restart requested
|
//in case of restart requested
|
||||||
if (web_interface->restartmodule) {
|
if (web_interface->restartmodule) {
|
||||||
CONFIG::esp_restart();
|
CONFIG::esp_restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
#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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DHT_FEATURE
|
#ifdef DHT_FEATURE
|
||||||
if (CONFIG::DHT_type != 255) {
|
if (CONFIG::DHT_type != 255) {
|
||||||
static uint32_t last_dht_update= 0;
|
static uint32_t last_dht_update= 0;
|
||||||
uint32_t now_dht = millis();
|
uint32_t now_dht = millis();
|
||||||
if (now_dht - last_dht_update > (CONFIG::DHT_interval * 1000)) {
|
if (now_dht - last_dht_update > (CONFIG::DHT_interval * 1000)) {
|
||||||
last_dht_update = now_dht;
|
last_dht_update = now_dht;
|
||||||
float humidity = dht.getHumidity();
|
float humidity = dht.getHumidity();
|
||||||
float temperature = dht.getTemperature();
|
float temperature = dht.getTemperature();
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//todo use config
|
//todo use config
|
||||||
CONFIG::wait(0);
|
CONFIG::wait(0);
|
||||||
}
|
}
|
||||||
|
@ -25,133 +25,150 @@
|
|||||||
|
|
||||||
// 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
|
||||||
|
|
||||||
|
|
||||||
#define ESP3D_Logo_width 62
|
#define ESP3D_Logo_width 62
|
||||||
#define ESP3D_Logo_height 45
|
#define ESP3D_Logo_height 45
|
||||||
const char ESP3D_Logo[] = {
|
const char ESP3D_Logo[] = {
|
||||||
0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF,
|
0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF,
|
||||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
||||||
0x00, 0x00, 0xF8, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
0x00, 0x00, 0xF8, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
||||||
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
|
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
|
||||||
0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
||||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xC0, 0xFF, 0xFF, 0xFF,
|
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xC0, 0xFF, 0xFF, 0xFF,
|
||||||
0xFF, 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x80, 0x01,
|
0xFF, 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x80, 0x01,
|
||||||
0xF0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x03, 0xF8, 0xFF, 0xFF, 0xFF,
|
0xF0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x03, 0xF8, 0xFF, 0xFF, 0xFF,
|
||||||
0x07, 0x00, 0x00, 0x06, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x0C,
|
0x07, 0x00, 0x00, 0x06, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x0C,
|
||||||
0x0C, 0x7C, 0x78, 0xC0, 0xC1, 0xC1, 0x0F, 0x18, 0x06, 0x38, 0x60, 0x80,
|
0x0C, 0x7C, 0x78, 0xC0, 0xC1, 0xC1, 0x0F, 0x18, 0x06, 0x38, 0x60, 0x80,
|
||||||
0xE1, 0xC3, 0x3F, 0x10, 0xC6, 0x19, 0x67, 0x1C, 0xF1, 0xC7, 0x7F, 0x10,
|
0xE1, 0xC3, 0x3F, 0x10, 0xC6, 0x19, 0x67, 0x1C, 0xF1, 0xC7, 0x7F, 0x10,
|
||||||
0xC6, 0x1F, 0x7F, 0x3C, 0x31, 0xCF, 0xF1, 0x10, 0xC7, 0x1F, 0x7F, 0x3C,
|
0xC6, 0x1F, 0x7F, 0x3C, 0x31, 0xCF, 0xF1, 0x10, 0xC7, 0x1F, 0x7F, 0x3C,
|
||||||
0x01, 0xCE, 0xE1, 0x20, 0xC7, 0x3F, 0x7E, 0x1C, 0x01, 0xC7, 0xC1, 0x21,
|
0x01, 0xCE, 0xE1, 0x20, 0xC7, 0x3F, 0x7E, 0x1C, 0x01, 0xC7, 0xC1, 0x21,
|
||||||
0x07, 0x3C, 0x78, 0x80, 0xE1, 0xC3, 0xC1, 0x21, 0x07, 0xFC, 0x70, 0xC0,
|
0x07, 0x3C, 0x78, 0x80, 0xE1, 0xC3, 0xC1, 0x21, 0x07, 0xFC, 0x70, 0xC0,
|
||||||
0xE1, 0xC7, 0xC1, 0x21, 0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCF, 0xC1, 0x21,
|
0xE1, 0xC7, 0xC1, 0x21, 0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCF, 0xC1, 0x21,
|
||||||
0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCE, 0xC1, 0x21, 0xC7, 0xDF, 0x63, 0xFC,
|
0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCE, 0xC1, 0x21, 0xC7, 0xDF, 0x63, 0xFC,
|
||||||
0x01, 0xCE, 0xE1, 0x20, 0xC6, 0x99, 0x73, 0xFC, 0x31, 0xCF, 0x7F, 0x10,
|
0x01, 0xCE, 0xE1, 0x20, 0xC6, 0x99, 0x73, 0xFC, 0x31, 0xCF, 0x7F, 0x10,
|
||||||
0x06, 0x18, 0x70, 0xFC, 0xF0, 0xC7, 0x3F, 0x10, 0x0E, 0x78, 0x78, 0xFC,
|
0x06, 0x18, 0x70, 0xFC, 0xF0, 0xC7, 0x3F, 0x10, 0x0E, 0x78, 0x78, 0xFC,
|
||||||
0xE0, 0xC3, 0x0F, 0x10, 0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x18,
|
0xE0, 0xC3, 0x0F, 0x10, 0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x18,
|
||||||
0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0xFF, 0xFF, 0x3F,
|
0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0xFF, 0xFF, 0x3F,
|
||||||
0x00, 0x00, 0x00, 0x06, 0xF0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x03,
|
0x00, 0x00, 0x00, 0x06, 0xF0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x03,
|
||||||
0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0x01, 0xC0, 0xFF, 0xFF, 0x03,
|
0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0x01, 0xC0, 0xFF, 0xFF, 0x03,
|
||||||
0x00, 0x00, 0xE0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,
|
0x00, 0x00, 0xE0, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
||||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00,
|
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00,
|
||||||
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
||||||
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;
|
{
|
||||||
esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo);
|
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||||
update_lcd();
|
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
|
{
|
||||||
|
//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);
|
||||||
digitalWrite(HELTEC_EMBEDDED_PIN, LOW); // turn the LED on (HIGH is the voltage level)
|
digitalWrite(HELTEC_EMBEDDED_PIN, LOW); // turn the LED on (HIGH is the voltage level)
|
||||||
delay(100); // wait for a second
|
delay(100); // wait for a second
|
||||||
digitalWrite(HELTEC_EMBEDDED_PIN, HIGH); // turn the LED off by making the voltage LOW
|
digitalWrite(HELTEC_EMBEDDED_PIN, HIGH); // turn the LED off by making the voltage LOW
|
||||||
#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");
|
||||||
|
|
||||||
} else {
|
|
||||||
if (value > 0) {
|
|
||||||
esp_display.fillRect(x, y + 6, 3, 4);
|
|
||||||
} else {
|
} else {
|
||||||
esp_display.drawRect(x, y + 6, 3, 4);
|
if (value > 0) {
|
||||||
}
|
esp_display.fillRect(x, y + 6, 3, 4);
|
||||||
|
} else {
|
||||||
|
esp_display.drawRect(x, y + 6, 3, 4);
|
||||||
|
}
|
||||||
|
|
||||||
if (value >= 25) {
|
if (value >= 25) {
|
||||||
esp_display.fillRect(x + 4, y + 4, 3, 6);
|
esp_display.fillRect(x + 4, y + 4, 3, 6);
|
||||||
} else {
|
} else {
|
||||||
esp_display.drawRect(x + 4, y + 4, 3, 6);
|
esp_display.drawRect(x + 4, y + 4, 3, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value >= 50) {
|
if (value >= 50) {
|
||||||
esp_display.fillRect(x + 8, y + 2, 3, 8);
|
esp_display.fillRect(x + 8, y + 2, 3, 8);
|
||||||
} else {
|
} else {
|
||||||
esp_display.drawRect(x + 8, y + 2, 3, 8);
|
esp_display.drawRect(x + 8, y + 2, 3, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value >= 75) {
|
if (value >= 75) {
|
||||||
esp_display.fillRect(x + 12, y, 3, 10);
|
esp_display.fillRect(x + 12, y, 3, 10);
|
||||||
} else {
|
} else {
|
||||||
esp_display.drawRect(x + 12, y, 3, 10);
|
esp_display.drawRect(x + 12, y, 3, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = CONFIG::intTostr (value);
|
String s = CONFIG::intTostr (value);
|
||||||
s+="%";
|
s+="%";
|
||||||
//set current font size
|
//set current font size
|
||||||
esp_display.setFont(ArialMT_Plain_10);
|
esp_display.setFont(ArialMT_Plain_10);
|
||||||
esp_display.drawString(x+16, y, s.c_str());
|
esp_display.drawString(x+16, y, s.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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,44 +178,45 @@ 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};
|
||||||
|
|
||||||
int p = 0;
|
int p = 0;
|
||||||
if (y==16) {
|
if (y==16) {
|
||||||
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) {
|
||||||
}
|
max = 85;
|
||||||
else if (y==0){
|
OLED_DISPLAY::L0 = txt;
|
||||||
max = 85;
|
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
|
||||||
OLED_DISPLAY::L0 = txt;
|
p=0;
|
||||||
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
|
} else {
|
||||||
p=0;
|
OLED_DISPLAY::L3 = txt;
|
||||||
}
|
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
|
||||||
else{
|
p=3;
|
||||||
OLED_DISPLAY::L3 = txt;
|
}
|
||||||
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
|
|
||||||
p=3;
|
|
||||||
}
|
|
||||||
esp_display.setFont(ArialMT_Plain_10);
|
esp_display.setFont(ArialMT_Plain_10);
|
||||||
//clear area only
|
//clear area only
|
||||||
esp_display.setColor(BLACK);
|
esp_display.setColor(BLACK);
|
||||||
esp_display.fillRect(x, y, max, 16);
|
esp_display.fillRect(x, y, max, 16);
|
||||||
esp_display.setColor(WHITE);
|
esp_display.setColor(WHITE);
|
||||||
@ -206,27 +224,29 @@ void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
|
|||||||
Stxt += " ";
|
Stxt += " ";
|
||||||
(t[p])++;
|
(t[p])++;
|
||||||
if ((esp_display.getStringWidth( Stxt) > max) && (t[p] > 1)) {
|
if ((esp_display.getStringWidth( Stxt) > max) && (t[p] > 1)) {
|
||||||
(shift_pos[p]) ++;
|
(shift_pos[p]) ++;
|
||||||
String s2 = Stxt.substring(shift_pos[p]);
|
String s2 = Stxt.substring(shift_pos[p]);
|
||||||
Stxt = s2;
|
Stxt = s2;
|
||||||
if (esp_display.getStringWidth( s2) < max) {
|
if (esp_display.getStringWidth( s2) < max) {
|
||||||
//reset for next time
|
//reset for next time
|
||||||
shift_pos[p] = -1;
|
shift_pos[p] = -1;
|
||||||
t[p] = 0;
|
t[p] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//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;
|
||||||
int OLED_DISPLAY::row = 0;
|
int OLED_DISPLAY::row = 0;
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
211
esp3d/espcom.cpp
211
esp3d/espcom.cpp
@ -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;
|
||||||
@ -45,25 +45,25 @@ bool ESPCOM::block_2_printer = false;
|
|||||||
void ESPCOM::bridge(bool async)
|
void ESPCOM::bridge(bool async)
|
||||||
{
|
{
|
||||||
#if defined (ASYNCWEBSERVER)
|
#if defined (ASYNCWEBSERVER)
|
||||||
if(can_process_serial) {
|
if(can_process_serial) {
|
||||||
#endif
|
#endif
|
||||||
//be sure wifi is on to proceed wifi function
|
//be sure wifi is on to proceed wifi function
|
||||||
if ((WiFi.getMode() != WIFI_OFF) || wifi_config.WiFi_on) {
|
if ((WiFi.getMode() != WIFI_OFF) || wifi_config.WiFi_on) {
|
||||||
//read tcp port input
|
//read tcp port input
|
||||||
#ifdef TCP_IP_DATA_FEATURE
|
#ifdef TCP_IP_DATA_FEATURE
|
||||||
ESPCOM::processFromTCP2Serial();
|
ESPCOM::processFromTCP2Serial();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//read serial input
|
//read serial input
|
||||||
ESPCOM::processFromSerial();
|
ESPCOM::processFromSerial();
|
||||||
#if defined (ASYNCWEBSERVER)
|
#if defined (ASYNCWEBSERVER)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len)
|
long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len)
|
||||||
{
|
{
|
||||||
switch (output) {
|
switch (output) {
|
||||||
#ifdef USE_SERIAL_0
|
#ifdef USE_SERIAL_0
|
||||||
case SERIAL_PIPE:
|
case SERIAL_PIPE:
|
||||||
return Serial.readBytes(sbuf,len);
|
return Serial.readBytes(sbuf,len);
|
||||||
@ -79,15 +79,15 @@ long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len)
|
|||||||
return Serial2.readBytes(sbuf,len);
|
return Serial2.readBytes(sbuf,len);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long ESPCOM::baudRate(tpipe output)
|
long ESPCOM::baudRate(tpipe output)
|
||||||
{
|
{
|
||||||
long br = 0;
|
long br = 0;
|
||||||
switch (output) {
|
switch (output) {
|
||||||
#ifdef USE_SERIAL_0
|
#ifdef USE_SERIAL_0
|
||||||
case SERIAL_PIPE:
|
case SERIAL_PIPE:
|
||||||
br = Serial.baudRate();
|
br = Serial.baudRate();
|
||||||
@ -103,10 +103,10 @@ long ESPCOM::baudRate(tpipe output)
|
|||||||
br = Serial2.baudRate();
|
br = Serial2.baudRate();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
//workaround for ESP32
|
//workaround for ESP32
|
||||||
if (br == 115201) {
|
if (br == 115201) {
|
||||||
@ -116,10 +116,11 @@ 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:
|
||||||
return Serial.available();
|
return Serial.available();
|
||||||
@ -135,15 +136,20 @@ size_t ESPCOM::available(tpipe output){
|
|||||||
return Serial2.available();
|
return Serial2.available();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
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))) {
|
||||||
switch (output) {
|
return 0;
|
||||||
|
}
|
||||||
|
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
switch (output) {
|
||||||
#ifdef USE_SERIAL_0
|
#ifdef USE_SERIAL_0
|
||||||
case SERIAL_PIPE:
|
case SERIAL_PIPE:
|
||||||
return Serial.write(d);
|
return Serial.write(d);
|
||||||
@ -159,14 +165,14 @@ size_t ESPCOM::write(tpipe output, uint8_t d){
|
|||||||
return Serial2.write(d);
|
return Serial2.write(d);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ESPCOM::flush (tpipe output, ESPResponseStream *espresponse)
|
void ESPCOM::flush (tpipe output, ESPResponseStream *espresponse)
|
||||||
{
|
{
|
||||||
switch (output) {
|
switch (output) {
|
||||||
#ifdef USE_SERIAL_0
|
#ifdef USE_SERIAL_0
|
||||||
case SERIAL_PIPE:
|
case SERIAL_PIPE:
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@ -183,23 +189,23 @@ void ESPCOM::flush (tpipe output, ESPResponseStream *espresponse)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if !defined (ASYNCWEBSERVER)
|
#if !defined (ASYNCWEBSERVER)
|
||||||
case WEB_PIPE:
|
case WEB_PIPE:
|
||||||
if (espresponse) {
|
if (espresponse) {
|
||||||
if(espresponse->header_sent) {
|
if(espresponse->header_sent) {
|
||||||
//send data
|
//send data
|
||||||
web_interface->web_server.sendContent(espresponse->buffer_web);
|
web_interface->web_server.sendContent(espresponse->buffer_web);
|
||||||
//close line
|
//close line
|
||||||
web_interface->web_server.sendContent("");
|
web_interface->web_server.sendContent("");
|
||||||
}
|
}
|
||||||
espresponse->header_sent = false;
|
espresponse->header_sent = false;
|
||||||
espresponse->buffer_web = String();
|
espresponse->buffer_web = String();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPCOM::print (const __FlashStringHelper *data, tpipe output, ESPResponseStream *espresponse)
|
void ESPCOM::print (const __FlashStringHelper *data, tpipe output, ESPResponseStream *espresponse)
|
||||||
@ -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
|
||||||
@ -248,61 +264,62 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
|
|||||||
case WEB_PIPE:
|
case WEB_PIPE:
|
||||||
if (espresponse != NULL) {
|
if (espresponse != NULL) {
|
||||||
#if defined(ASYNCWEBSERVER)
|
#if defined(ASYNCWEBSERVER)
|
||||||
espresponse->print (data);
|
espresponse->print (data);
|
||||||
#else
|
#else
|
||||||
if (!espresponse->header_sent) {
|
if (!espresponse->header_sent) {
|
||||||
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||||
web_interface->web_server.sendHeader("Content-Type","text/html");
|
web_interface->web_server.sendHeader("Content-Type","text/html");
|
||||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||||
web_interface->web_server.send(200);
|
web_interface->web_server.send(200);
|
||||||
espresponse->header_sent = true;
|
espresponse->header_sent = true;
|
||||||
}
|
}
|
||||||
espresponse->buffer_web+=data;
|
espresponse->buffer_web+=data;
|
||||||
if (espresponse->buffer_web.length() > 1200) {
|
if (espresponse->buffer_web.length() > 1200) {
|
||||||
//send data
|
//send data
|
||||||
web_interface->web_server.sendContent(espresponse->buffer_web);
|
web_interface->web_server.sendContent(espresponse->buffer_web);
|
||||||
//reset buffer
|
//reset buffer
|
||||||
espresponse->buffer_web="";
|
espresponse->buffer_web="";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
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
|
||||||
socket_server->sendBIN(current_socket_id,(const uint8_t *)data,strlen(data));
|
socket_server->sendBIN(current_socket_id,(const uint8_t *)data,strlen(data));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#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);
|
OLED_DISPLAY::update_lcd();
|
||||||
OLED_DISPLAY::update_lcd();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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"))) {
|
||||||
#endif
|
ESPCOM::print(data, OLED_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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
#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);
|
||||||
|
}
|
||||||
|
ESPCOM::print (data, DEFAULT_PRINTER_PIPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
|
@ -29,12 +29,12 @@ extern WiFiServer * data_server;
|
|||||||
class ESPCOM
|
class ESPCOM
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static size_t write(tpipe output, uint8_t d);
|
static size_t write(tpipe output, uint8_t d);
|
||||||
static long readBytes (tpipe output, uint8_t * sbuf, size_t len);
|
static long readBytes (tpipe output, uint8_t * sbuf, size_t len);
|
||||||
static long baudRate(tpipe output);
|
static long baudRate(tpipe output);
|
||||||
static size_t available(tpipe output);
|
static size_t available(tpipe output);
|
||||||
static void flush(tpipe output, ESPResponseStream *espresponse = NULL);
|
static void flush(tpipe output, ESPResponseStream *espresponse = NULL);
|
||||||
static void bridge(bool async = false);
|
static void bridge(bool async = false);
|
||||||
static bool processFromSerial (bool async = false);
|
static bool processFromSerial (bool async = false);
|
||||||
static void print (const __FlashStringHelper *data, tpipe output, ESPResponseStream *espresponse = NULL);
|
static void print (const __FlashStringHelper *data, tpipe output, ESPResponseStream *espresponse = NULL);
|
||||||
static void print (String & data, tpipe output, ESPResponseStream *espresponse = NULL);
|
static void print (String & data, tpipe output, ESPResponseStream *espresponse = NULL);
|
||||||
@ -49,9 +49,9 @@ public:
|
|||||||
static void send2TCP (String data, bool async = false);
|
static void send2TCP (String data, bool async = false);
|
||||||
static void send2TCP (const char * data, bool async = false);
|
static void send2TCP (const char * data, bool async = false);
|
||||||
#endif
|
#endif
|
||||||
static bool block_2_printer;
|
static bool block_2_printer;
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
static bool block_2_oled;
|
static bool block_2_oled;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -310,7 +310,7 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
|||||||
//Email#serveraddress:port
|
//Email#serveraddress:port
|
||||||
bool NotificationsService::getPortFromSettings()
|
bool NotificationsService::getPortFromSettings()
|
||||||
{
|
{
|
||||||
String tmp ;
|
String tmp ;
|
||||||
char sbuf[MAX_DATA_LENGTH + 1];
|
char sbuf[MAX_DATA_LENGTH + 1];
|
||||||
if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) {
|
||||||
tmp = sbuf;
|
tmp = sbuf;
|
||||||
@ -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) {
|
||||||
@ -379,27 +379,27 @@ bool NotificationsService::begin()
|
|||||||
return true;
|
return true;
|
||||||
case ESP_PUSHOVER_NOTIFICATION:
|
case ESP_PUSHOVER_NOTIFICATION:
|
||||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||||
_token1 = sbuf;
|
_token1 = sbuf;
|
||||||
}
|
}
|
||||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN2, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN2, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||||
_token2 = sbuf;
|
_token2 = sbuf;
|
||||||
}
|
}
|
||||||
_port = PUSHOVERPORT;
|
_port = PUSHOVERPORT;
|
||||||
_serveraddress = PUSHOVERSERVER;
|
_serveraddress = PUSHOVERSERVER;
|
||||||
break;
|
break;
|
||||||
case ESP_LINE_NOTIFICATION:
|
case ESP_LINE_NOTIFICATION:
|
||||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||||
_token1 = sbuf;
|
_token1 = sbuf;
|
||||||
}
|
}
|
||||||
_port = LINEPORT;
|
_port = LINEPORT;
|
||||||
_serveraddress = LINESERVER;
|
_serveraddress = LINESERVER;
|
||||||
break;
|
break;
|
||||||
case ESP_EMAIL_NOTIFICATION:
|
case ESP_EMAIL_NOTIFICATION:
|
||||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||||
_token1 = sbuf;
|
_token1 = sbuf;
|
||||||
}
|
}
|
||||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN2, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN2, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||||
_token2 = sbuf;
|
_token2 = sbuf;
|
||||||
}
|
}
|
||||||
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||||
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||||
|
@ -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,42 +59,42 @@
|
|||||||
#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);
|
// send message to client
|
||||||
// send message to client
|
ESPCOM::current_socket_id = num;
|
||||||
ESPCOM::current_socket_id = num;
|
socket_server->sendTXT(ESPCOM::current_socket_id, s);
|
||||||
socket_server->sendTXT(ESPCOM::current_socket_id, s);
|
s = "ACTIVE_ID:" + String(ESPCOM::current_socket_id);
|
||||||
s = "ACTIVE_ID:" + String(ESPCOM::current_socket_id);
|
socket_server->broadcastTXT(s);
|
||||||
socket_server->broadcastTXT(s);
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case WStype_TEXT:
|
||||||
case WStype_TEXT:
|
//USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
|
||||||
//USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
|
|
||||||
|
|
||||||
// send message to client
|
// send message to client
|
||||||
// webSocket.sendTXT(num, "message here");
|
// webSocket.sendTXT(num, "message here");
|
||||||
|
|
||||||
// send data to all connected clients
|
// send data to all connected clients
|
||||||
// webSocket.broadcastTXT("message here");
|
// webSocket.broadcastTXT("message here");
|
||||||
break;
|
break;
|
||||||
case WStype_BIN:
|
case WStype_BIN:
|
||||||
//USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
|
//USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
|
||||||
//hexdump(payload, length);
|
//hexdump(payload, length);
|
||||||
|
|
||||||
// send message to client
|
// send message to client
|
||||||
// webSocket.sendBIN(num, payload, length);
|
// webSocket.sendBIN(num, payload, length);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ void handle_web_interface_root()
|
|||||||
if(SPIFFS.exists(pathWithGz)) {
|
if(SPIFFS.exists(pathWithGz)) {
|
||||||
path = pathWithGz;
|
path = pathWithGz;
|
||||||
}
|
}
|
||||||
FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ);
|
FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ);
|
||||||
web_interface->web_server.streamFile(file, contentType);
|
web_interface->web_server.streamFile(file, contentType);
|
||||||
file.close();
|
file.close();
|
||||||
return;
|
return;
|
||||||
@ -148,7 +148,7 @@ void handle_login()
|
|||||||
if (pos!= -1) {
|
if (pos!= -1) {
|
||||||
int pos2 = cookie.indexOf(";",pos);
|
int pos2 = cookie.indexOf(";",pos);
|
||||||
sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2);
|
sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2);
|
||||||
}
|
}
|
||||||
web_interface->ClearAuthIP(web_interface->web_server.client().remoteIP(), sessionID.c_str());
|
web_interface->ClearAuthIP(web_interface->web_server.client().remoteIP(), sessionID.c_str());
|
||||||
web_interface->web_server.sendHeader("Set-Cookie","ESPSESSIONID=0");
|
web_interface->web_server.sendHeader("Set-Cookie","ESPSESSIONID=0");
|
||||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||||
@ -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,12 +212,15 @@ 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 {
|
||||||
msg_alert_error=true;
|
pos = EP_USER_PWD;
|
||||||
smsg = F("Error: Cannot apply changes");
|
}
|
||||||
code = 500;
|
if (!CONFIG::write_string(pos,newpassword.c_str())) {
|
||||||
|
msg_alert_error=true;
|
||||||
|
smsg = F("Error: Cannot apply changes");
|
||||||
|
code = 500;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
@ -220,77 +228,79 @@ void handle_login()
|
|||||||
code = 500;
|
code = 500;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((code == 200) || (code == 500)) {
|
if ((code == 200) || (code == 500)) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
//create Session
|
//create Session
|
||||||
if ((current_auth_level != auth_level) || (auth_level== LEVEL_GUEST)) {
|
if ((current_auth_level != auth_level) || (auth_level== LEVEL_GUEST)) {
|
||||||
auth_ip * current_auth = new auth_ip;
|
auth_ip * current_auth = new auth_ip;
|
||||||
current_auth->level = current_auth_level;
|
current_auth->level = current_auth_level;
|
||||||
current_auth->ip=web_interface->web_server.client().remoteIP();
|
current_auth->ip=web_interface->web_server.client().remoteIP();
|
||||||
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
||||||
strcpy(current_auth->userID,sUser.c_str());
|
strcpy(current_auth->userID,sUser.c_str());
|
||||||
current_auth->last_time=millis();
|
current_auth->last_time=millis();
|
||||||
if (web_interface->AddAuthIP(current_auth)) {
|
if (web_interface->AddAuthIP(current_auth)) {
|
||||||
String tmps ="ESPSESSIONID=";
|
String tmps ="ESPSESSIONID=";
|
||||||
tmps+=current_auth->sessionID;
|
tmps+=current_auth->sessionID;
|
||||||
web_interface->web_server.sendHeader("Set-Cookie",tmps);
|
web_interface->web_server.sendHeader("Set-Cookie",tmps);
|
||||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||||
switch(current_auth->level) {
|
switch(current_auth->level) {
|
||||||
case LEVEL_ADMIN:
|
case LEVEL_ADMIN:
|
||||||
auths = "admin";
|
auths = "admin";
|
||||||
break;
|
break;
|
||||||
case LEVEL_USER:
|
case LEVEL_USER:
|
||||||
auths = "user";
|
auths = "user";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
auths = "guest";
|
auths = "guest";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete current_auth;
|
delete current_auth;
|
||||||
msg_alert_error=true;
|
msg_alert_error=true;
|
||||||
code = 500;
|
code = 500;
|
||||||
smsg = F("Error: Too many connections");
|
smsg = F("Error: Too many connections");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (code == 200) {
|
||||||
if (code == 200) smsg = F("Ok");
|
smsg = F("Ok");
|
||||||
|
}
|
||||||
|
|
||||||
//build JSON
|
//build JSON
|
||||||
String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\"";
|
String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\"";
|
||||||
buffer2send += auths;
|
buffer2send += auths;
|
||||||
buffer2send += "\"}";
|
buffer2send += "\"}";
|
||||||
web_interface->web_server.send(code, "application/json", buffer2send);
|
web_interface->web_server.send(code, "application/json", buffer2send);
|
||||||
} else {
|
} else {
|
||||||
if (auth_level != LEVEL_GUEST) {
|
if (auth_level != LEVEL_GUEST) {
|
||||||
String cookie = web_interface->web_server.header("Cookie");
|
String cookie = web_interface->web_server.header("Cookie");
|
||||||
int pos = cookie.indexOf("ESPSESSIONID=");
|
int pos = cookie.indexOf("ESPSESSIONID=");
|
||||||
String sessionID;
|
String sessionID;
|
||||||
if (pos!= -1) {
|
if (pos!= -1) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
String buffer2send = "{\"status\":\"200\",\"authentication_lvl\":\"";
|
||||||
String buffer2send = "{\"status\":\"200\",\"authentication_lvl\":\"";
|
buffer2send += auths;
|
||||||
buffer2send += auths;
|
buffer2send += "\",\"user\":\"";
|
||||||
buffer2send += "\",\"user\":\"";
|
buffer2send += sUser;
|
||||||
buffer2send += sUser;
|
buffer2send +="\"}";
|
||||||
buffer2send +="\"}";
|
web_interface->web_server.send(code, "application/json", buffer2send);
|
||||||
web_interface->web_server.send(code, "application/json", buffer2send);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||||
web_interface->web_server.send(200, "application/json", "{\"status\":\"Ok\",\"authentication_lvl\":\"admin\"}");
|
web_interface->web_server.send(200, "application/json", "{\"status\":\"Ok\",\"authentication_lvl\":\"admin\"}");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -352,12 +362,12 @@ void handleFileList()
|
|||||||
FS_DIR dir = SPIFFS.openDir(path);
|
FS_DIR dir = SPIFFS.openDir(path);
|
||||||
if (!dir.next()) {
|
if (!dir.next()) {
|
||||||
#else
|
#else
|
||||||
String ptmp = path;
|
String ptmp = path;
|
||||||
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
||||||
ptmp = path.substring (0, path.length() - 1);
|
ptmp = path.substring (0, path.length() - 1);
|
||||||
}
|
}
|
||||||
FS_FILE dir = SPIFFS.open (ptmp);
|
FS_FILE dir = SPIFFS.open (ptmp);
|
||||||
FS_FILE dircontent = dir.openNextFile();
|
FS_FILE dircontent = dir.openNextFile();
|
||||||
if (!dircontent) {
|
if (!dircontent) {
|
||||||
#endif
|
#endif
|
||||||
//keep directory alive even empty
|
//keep directory alive even empty
|
||||||
@ -387,15 +397,15 @@ void handleFileList()
|
|||||||
{
|
{
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
#else
|
#else
|
||||||
FS_FILE dir = SPIFFS.open(path + shortname);
|
FS_FILE dir = SPIFFS.open(path + shortname);
|
||||||
{
|
{
|
||||||
FS_FILE file2deleted = dir.openNextFile();
|
FS_FILE file2deleted = dir.openNextFile();
|
||||||
while (file2deleted) {
|
while (file2deleted) {
|
||||||
#endif
|
#endif
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
String fullpath = dir.fileName();
|
String fullpath = dir.fileName();
|
||||||
#else
|
#else
|
||||||
String fullpath = file2deleted.name();
|
String fullpath = file2deleted.name();
|
||||||
#endif
|
#endif
|
||||||
if (!SPIFFS.remove(fullpath)) {
|
if (!SPIFFS.remove(fullpath)) {
|
||||||
delete_error = true;
|
delete_error = true;
|
||||||
@ -403,7 +413,7 @@ void handleFileList()
|
|||||||
status+=fullpath;
|
status+=fullpath;
|
||||||
}
|
}
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
file2deleted = dir.openNextFile();
|
file2deleted = dir.openNextFile();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,11 +448,11 @@ void handleFileList()
|
|||||||
#if defined ( ARDUINO_ARCH_ESP8266 )
|
#if defined ( ARDUINO_ARCH_ESP8266 )
|
||||||
FS_DIR dir = SPIFFS.openDir(path);
|
FS_DIR dir = SPIFFS.openDir(path);
|
||||||
#else
|
#else
|
||||||
String ptmp = path;
|
String ptmp = path;
|
||||||
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
||||||
ptmp = path.substring (0, path.length() - 1);
|
ptmp = path.substring (0, path.length() - 1);
|
||||||
}
|
}
|
||||||
FS_FILE dir = SPIFFS.open(ptmp);
|
FS_FILE dir = SPIFFS.open(ptmp);
|
||||||
#endif
|
#endif
|
||||||
jsonfile+="\"files\":[";
|
jsonfile+="\"files\":[";
|
||||||
bool firstentry=true;
|
bool firstentry=true;
|
||||||
@ -451,8 +461,8 @@ void handleFileList()
|
|||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
String filename = dir.fileName();
|
String filename = dir.fileName();
|
||||||
#else
|
#else
|
||||||
File fileparsed = dir.openNextFile();
|
File fileparsed = dir.openNextFile();
|
||||||
while (fileparsed) {
|
while (fileparsed) {
|
||||||
String filename = fileparsed.name();
|
String filename = fileparsed.name();
|
||||||
#endif
|
#endif
|
||||||
String size ="";
|
String size ="";
|
||||||
@ -482,7 +492,7 @@ void handleFileList()
|
|||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
size = CONFIG::formatBytes(dir.fileSize());
|
size = CONFIG::formatBytes(dir.fileSize());
|
||||||
#else
|
#else
|
||||||
size = CONFIG::formatBytes(fileparsed.size());
|
size = CONFIG::formatBytes(fileparsed.size());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -518,7 +528,7 @@ void handleFileList()
|
|||||||
totalBytes = info.totalBytes;
|
totalBytes = info.totalBytes;
|
||||||
usedBytes = info.usedBytes;
|
usedBytes = info.usedBytes;
|
||||||
#else
|
#else
|
||||||
totalBytes = SPIFFS.totalBytes();
|
totalBytes = SPIFFS.totalBytes();
|
||||||
usedBytes = SPIFFS.usedBytes();
|
usedBytes = SPIFFS.usedBytes();
|
||||||
#endif
|
#endif
|
||||||
jsonfile+="\"total\":\"" + CONFIG::formatBytes(totalBytes) + "\",";
|
jsonfile+="\"total\":\"" + CONFIG::formatBytes(totalBytes) + "\",";
|
||||||
@ -536,7 +546,7 @@ void handleFileList()
|
|||||||
//SPIFFS files uploader handle
|
//SPIFFS files uploader handle
|
||||||
void SPIFFSFileupload()
|
void SPIFFSFileupload()
|
||||||
{
|
{
|
||||||
static FS_FILE fsUploadFile = (FS_FILE)0;
|
static FS_FILE fsUploadFile = (FS_FILE)0;
|
||||||
//get authentication status
|
//get authentication status
|
||||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
//Guest cannot upload
|
//Guest cannot upload
|
||||||
@ -546,7 +556,7 @@ void SPIFFSFileupload()
|
|||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -557,13 +567,16 @@ void SPIFFSFileupload()
|
|||||||
//Upload start
|
//Upload start
|
||||||
//**************
|
//**************
|
||||||
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;
|
||||||
filename = "/user" + upload_filename;
|
filename = "/user" + upload_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +587,7 @@ void SPIFFSFileupload()
|
|||||||
fsUploadFile.close();
|
fsUploadFile.close();
|
||||||
}
|
}
|
||||||
//create file
|
//create file
|
||||||
fsUploadFile = SPIFFS.open(filename, SPIFFS_FILE_WRITE);
|
fsUploadFile = SPIFFS.open(filename, SPIFFS_FILE_WRITE);
|
||||||
//check If creation succeed
|
//check If creation succeed
|
||||||
if (fsUploadFile) {
|
if (fsUploadFile) {
|
||||||
//if yes upload is started
|
//if yes upload is started
|
||||||
@ -584,9 +597,9 @@ void SPIFFSFileupload()
|
|||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
ESPCOM::println (F ("Error ESP create"), PRINTER_PIPE);
|
ESPCOM::println (F ("Error ESP create"), PRINTER_PIPE);
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//Upload write
|
//Upload write
|
||||||
@ -600,11 +613,11 @@ void SPIFFSFileupload()
|
|||||||
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
ESPCOM::println (F ("Error ESP write"), PRINTER_PIPE);
|
ESPCOM::println (F ("Error ESP write"), PRINTER_PIPE);
|
||||||
}
|
}
|
||||||
//Upload end
|
//Upload end
|
||||||
//**************
|
//**************
|
||||||
@ -614,30 +627,30 @@ void SPIFFSFileupload()
|
|||||||
//close it
|
//close it
|
||||||
fsUploadFile.close();
|
fsUploadFile.close();
|
||||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||||
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
if (SPIFFS.exists (filename) ) {
|
if (SPIFFS.exists (filename) ) {
|
||||||
SPIFFS.remove (filename);
|
SPIFFS.remove (filename);
|
||||||
}
|
}
|
||||||
ESPCOM::println (F ("Error ESP close"), PRINTER_PIPE);
|
ESPCOM::println (F ("Error ESP close"), PRINTER_PIPE);
|
||||||
|
|
||||||
}
|
}
|
||||||
//Upload cancelled
|
//Upload cancelled
|
||||||
//**************
|
//**************
|
||||||
} else {
|
} else {
|
||||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||||
web_interface->_upload_status = UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status = UPLOAD_STATUS_CANCELLED;
|
||||||
}
|
}
|
||||||
ESPCOM::println (F ("Error ESP upload"), PRINTER_PIPE);
|
ESPCOM::println (F ("Error ESP upload"), PRINTER_PIPE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CONFIG::wait(0);
|
CONFIG::wait(0);
|
||||||
}
|
}
|
||||||
@ -654,7 +667,7 @@ void WebUpdateUpload()
|
|||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
ESPCOM::println (F ("Update failed"), PRINTER_PIPE);
|
ESPCOM::println (F ("Update failed"), PRINTER_PIPE);
|
||||||
LOG("Web Update failed\r\n");
|
LOG("Web Update failed\r\n");
|
||||||
@ -668,25 +681,28 @@ void WebUpdateUpload()
|
|||||||
ESPCOM::println (F ("Update Firmware"), PRINTER_PIPE);
|
ESPCOM::println (F ("Update Firmware"), PRINTER_PIPE);
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
WiFiUDP::stopAll();
|
WiFiUDP::stopAll();
|
||||||
#endif
|
#endif
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||||
#else
|
#else
|
||||||
//Not sure can do OTA on 2Mb board
|
//Not sure can do OTA on 2Mb board
|
||||||
maxSketchSpace = (ESP.getFlashChipSize()>0x20000)?0x140000:0x140000/2;
|
maxSketchSpace = (ESP.getFlashChipSize()>0x20000)?0x140000:0x140000/2;
|
||||||
#endif
|
#endif
|
||||||
last_upload_update = 0;
|
last_upload_update = 0;
|
||||||
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
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) {
|
||||||
@ -727,7 +748,7 @@ void handleUpdate()
|
|||||||
{
|
{
|
||||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||||
if (auth_level != LEVEL_ADMIN) {
|
if (auth_level != LEVEL_ADMIN) {
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n");
|
web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -739,7 +760,7 @@ void handleUpdate()
|
|||||||
web_interface->web_server.send(200, "application/json", jsonfile);
|
web_interface->web_server.send(200, "application/json", jsonfile);
|
||||||
//if success restart
|
//if success restart
|
||||||
if (web_interface->_upload_status==UPLOAD_STATUS_SUCCESSFUL) {
|
if (web_interface->_upload_status==UPLOAD_STATUS_SUCCESSFUL) {
|
||||||
CONFIG::wait(2000);
|
CONFIG::wait(2000);
|
||||||
web_interface->restartmodule=true;
|
web_interface->restartmodule=true;
|
||||||
} else {
|
} else {
|
||||||
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||||
@ -777,17 +798,17 @@ void handle_not_found()
|
|||||||
LOG("type:")
|
LOG("type:")
|
||||||
LOG(contentType)
|
LOG(contentType)
|
||||||
LOG("\r\n")
|
LOG("\r\n")
|
||||||
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
||||||
if(SPIFFS.exists(pathWithGz)) {
|
if(SPIFFS.exists(pathWithGz)) {
|
||||||
path = pathWithGz;
|
path = pathWithGz;
|
||||||
}
|
|
||||||
FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ);
|
|
||||||
web_interface->web_server.streamFile(file, contentType);
|
|
||||||
file.close();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
page_not_found = true;
|
|
||||||
}
|
}
|
||||||
|
FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ);
|
||||||
|
web_interface->web_server.streamFile(file, contentType);
|
||||||
|
file.close();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
page_not_found = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (page_not_found ) {
|
if (page_not_found ) {
|
||||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||||
@ -802,7 +823,7 @@ void handle_not_found()
|
|||||||
stmp+=CONFIG::intTostr(wifi_config.iweb_port);
|
stmp+=CONFIG::intTostr(wifi_config.iweb_port);
|
||||||
}
|
}
|
||||||
contentType.replace(KEY_IP,stmp);
|
contentType.replace(KEY_IP,stmp);
|
||||||
contentType.replace(KEY_IP,stmp);
|
contentType.replace(KEY_IP,stmp);
|
||||||
contentType.replace(KEY_QUERY,web_interface->web_server.uri());
|
contentType.replace(KEY_QUERY,web_interface->web_server.uri());
|
||||||
web_interface->web_server.send(200,"text/html",contentType);
|
web_interface->web_server.send(200,"text/html",contentType);
|
||||||
//web_interface->web_server.sendContent_P(NOT_AUTH_NF);
|
//web_interface->web_server.sendContent_P(NOT_AUTH_NF);
|
||||||
@ -849,10 +870,10 @@ void handle_not_found()
|
|||||||
void handle_web_command()
|
void handle_web_command()
|
||||||
{
|
{
|
||||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||||
/* if (auth_level == LEVEL_GUEST) {
|
/* if (auth_level == LEVEL_GUEST) {
|
||||||
web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n");
|
web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n");
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
String buffer2send = "";
|
String buffer2send = "";
|
||||||
ESPResponseStream espresponse;
|
ESPResponseStream espresponse;
|
||||||
LOG(String (web_interface->web_server.args()))
|
LOG(String (web_interface->web_server.args()))
|
||||||
@ -893,7 +914,7 @@ void handle_web_command()
|
|||||||
String cmd_part1=cmd.substring(ESPpos+4,ESPpos2);
|
String cmd_part1=cmd.substring(ESPpos+4,ESPpos2);
|
||||||
String cmd_part2="";
|
String cmd_part2="";
|
||||||
//only [ESP800] is allowed login free if authentication is enabled
|
//only [ESP800] is allowed login free if authentication is enabled
|
||||||
if ((auth_level == LEVEL_GUEST) && (cmd_part1.toInt()!=800)) {
|
if ((auth_level == LEVEL_GUEST) && (cmd_part1.toInt()!=800)) {
|
||||||
web_interface->web_server.send(401,"text/plain","Authentication failed!\n");
|
web_interface->web_server.send(401,"text/plain","Authentication failed!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -909,10 +930,10 @@ void handle_web_command()
|
|||||||
//if not is not a valid [ESPXXX] command
|
//if not is not a valid [ESPXXX] command
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (auth_level == LEVEL_GUEST) {
|
if (auth_level == LEVEL_GUEST) {
|
||||||
web_interface->web_server.send(401,"text/plain","Authentication failed!\n");
|
web_interface->web_server.send(401,"text/plain","Authentication failed!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//send command to serial as no need to transfer ESP command
|
//send command to serial as no need to transfer ESP command
|
||||||
//to avoid any pollution if Uploading file to SDCard
|
//to avoid any pollution if Uploading file to SDCard
|
||||||
if ((web_interface->blockserial) == false) {
|
if ((web_interface->blockserial) == false) {
|
||||||
@ -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,11 +1014,10 @@ 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";
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
buffer2send +=current_line;
|
buffer2send +=current_line;
|
||||||
buffer2send +="\n";
|
buffer2send +="\n";
|
||||||
@ -1163,9 +1183,9 @@ void SDFile_serial_upload()
|
|||||||
LOG("SD upload rejected\r\n");
|
LOG("SD upload rejected\r\n");
|
||||||
LOG("Need to stop");
|
LOG("Need to stop");
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -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();
|
||||||
@ -1232,85 +1254,85 @@ void SDFile_serial_upload()
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||||
LOG("Creation failed\r\n");
|
LOG("Creation failed\r\n");
|
||||||
}
|
}
|
||||||
//Upload write
|
//Upload write
|
||||||
//**************
|
//**************
|
||||||
//upload is on going with data coming by 2K blocks
|
//upload is on going with data coming by 2K blocks
|
||||||
} else if(upload.status == UPLOAD_FILE_WRITE) { //if com error no need to send more data to serial
|
} else if(upload.status == UPLOAD_FILE_WRITE) { //if com error no need to send more data to serial
|
||||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||||
for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data
|
for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data
|
||||||
//feed watchdog
|
//feed watchdog
|
||||||
CONFIG::wait(0);
|
CONFIG::wait(0);
|
||||||
//it is a comment
|
//it is a comment
|
||||||
if (upload.buf[pos] == ';') {
|
if (upload.buf[pos] == ';') {
|
||||||
LOG ("Comment\r\n")
|
LOG ("Comment\r\n")
|
||||||
is_comment = true;
|
is_comment = true;
|
||||||
}
|
}
|
||||||
//it is an end line
|
//it is an end line
|
||||||
else if ( (upload.buf[pos] == 13) || (upload.buf[pos] == 10) ) {
|
else if ( (upload.buf[pos] == 13) || (upload.buf[pos] == 10) ) {
|
||||||
//if comment line then reset
|
//if comment line then reset
|
||||||
is_comment = false;
|
is_comment = false;
|
||||||
//does line fit the buffer ?
|
//does line fit the buffer ?
|
||||||
if (current_line.length() < 126) {
|
if (current_line.length() < 126) {
|
||||||
//do we have something in buffer ?
|
//do we have something in buffer ?
|
||||||
if (current_line.length() > 0 ) {
|
if (current_line.length() > 0 ) {
|
||||||
lineNb++;
|
lineNb++;
|
||||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||||
LOG ("Error sending line\n")
|
LOG ("Error sending line\n")
|
||||||
CloseSerialUpload (true, current_filename,lineNb);
|
CloseSerialUpload (true, current_filename,lineNb);
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//reset line
|
//reset line
|
||||||
current_line = "";
|
current_line = "";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
LOG ("Empy line\n")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG ("Empy line\n")
|
//error buffer overload
|
||||||
|
LOG ("Error over buffer\n")
|
||||||
|
lineNb++;
|
||||||
|
CloseSerialUpload (true, current_filename, lineNb);
|
||||||
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
|
web_interface->web_server.client().stopAll();
|
||||||
|
#else
|
||||||
|
web_interface->web_server.client().stop();
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!is_comment) {
|
||||||
//error buffer overload
|
if (current_line.length() < 126) {
|
||||||
LOG ("Error over buffer\n")
|
current_line += char (upload.buf[pos]); //copy current char to buffer to send/resend
|
||||||
lineNb++;
|
} else {
|
||||||
CloseSerialUpload (true, current_filename, lineNb);
|
LOG ("Error over buffer\n")
|
||||||
|
lineNb++;
|
||||||
|
CloseSerialUpload (true, current_filename, lineNb);
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (!is_comment) {
|
|
||||||
if (current_line.length() < 126) {
|
|
||||||
current_line += char (upload.buf[pos]); //copy current char to buffer to send/resend
|
|
||||||
} else {
|
|
||||||
LOG ("Error over buffer\n")
|
|
||||||
lineNb++;
|
|
||||||
CloseSerialUpload (true, current_filename, lineNb);
|
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
|
||||||
web_interface->web_server.client().stopAll();
|
|
||||||
#else
|
|
||||||
web_interface->web_server.client().stop();
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOG ("Error upload\n")
|
LOG ("Error upload\n")
|
||||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||||
lineNb++;
|
lineNb++;
|
||||||
CloseSerialUpload (true, current_filename, lineNb);
|
CloseSerialUpload (true, current_filename, lineNb);
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Upload end
|
//Upload end
|
||||||
//**************
|
//**************
|
||||||
@ -1323,9 +1345,9 @@ void SDFile_serial_upload()
|
|||||||
lineNb++;
|
lineNb++;
|
||||||
CloseSerialUpload (true, current_filename, lineNb);
|
CloseSerialUpload (true, current_filename, lineNb);
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1338,11 +1360,11 @@ void SDFile_serial_upload()
|
|||||||
} else { //UPLOAD_FILE_ABORTED
|
} else { //UPLOAD_FILE_ABORTED
|
||||||
LOG("Error, Something happened\r\n");
|
LOG("Error, Something happened\r\n");
|
||||||
lineNb++;
|
lineNb++;
|
||||||
CloseSerialUpload (true, current_filename, lineNb);
|
CloseSerialUpload (true, current_filename, lineNb);
|
||||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||||
web_interface->web_server.client().stopAll();
|
web_interface->web_server.client().stopAll();
|
||||||
#else
|
#else
|
||||||
web_interface->web_server.client().stop();
|
web_interface->web_server.client().stop();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,32 +110,38 @@ 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);
|
||||||
}
|
}
|
||||||
CONFIG::wait (0);
|
CONFIG::wait (0);
|
||||||
LOG("Purge done\r\n")
|
LOG("Purge done\r\n")
|
||||||
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);
|
||||||
if (pos == -1 ) {
|
if (pos == -1 ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pos+=sresend.length();
|
pos+=sresend.length();
|
||||||
int pos2 = response.indexOf("\n", pos);
|
int pos2 = response.indexOf("\n", pos);
|
||||||
String snum = response.substring(pos, pos2);
|
String snum = response.substring(pos, pos2);
|
||||||
@ -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...
|
||||||
@ -237,15 +255,15 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
|||||||
} else {
|
} else {
|
||||||
if ( (response.indexOf (sok) > -1) ) { //we have ok so it is done
|
if ( (response.indexOf (sok) > -1) ) { //we have ok so it is done
|
||||||
free(sbuf);
|
free(sbuf);
|
||||||
LOG ("Got ok\r\n")
|
LOG ("Got ok\r\n")
|
||||||
purge_serial();
|
purge_serial();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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";
|
||||||
@ -291,18 +309,18 @@ void CloseSerialUpload (bool iserror, String & filename , int32_t linenb)
|
|||||||
//constructor
|
//constructor
|
||||||
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
||||||
#if defined(ASYNCWEBSERVER)
|
#if defined(ASYNCWEBSERVER)
|
||||||
, web_events("/events")
|
, web_events("/events")
|
||||||
#ifdef WS_DATA_FEATURE
|
#ifdef WS_DATA_FEATURE
|
||||||
, web_socket("/ws")
|
, web_socket("/ws")
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
//that handle "/" and default index.html.gz
|
//that handle "/" and default index.html.gz
|
||||||
#if defined(ASYNCWEBSERVER)
|
#if defined(ASYNCWEBSERVER)
|
||||||
//trick to catch command line on "/" before file being processed
|
//trick to catch command line on "/" before file being processed
|
||||||
web_server.serveStatic ("/", SPIFFS, "/").setDefaultFile ("index.html").setFilter (filterOnRoot);
|
web_server.serveStatic ("/", SPIFFS, "/").setDefaultFile ("index.html").setFilter (filterOnRoot);
|
||||||
web_server.serveStatic ("/", SPIFFS, "/Nowhere");
|
web_server.serveStatic ("/", SPIFFS, "/Nowhere");
|
||||||
//events functions
|
//events functions
|
||||||
web_events.onConnect(handle_onevent_connect);
|
web_events.onConnect(handle_onevent_connect);
|
||||||
//events management
|
//events management
|
||||||
web_server.addHandler(&web_events);
|
web_server.addHandler(&web_events);
|
||||||
@ -313,15 +331,15 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
|||||||
web_server.addHandler(&web_socket);
|
web_server.addHandler(&web_socket);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
web_server.on("/",HTTP_ANY, handle_web_interface_root);
|
web_server.on("/",HTTP_ANY, handle_web_interface_root);
|
||||||
#endif
|
#endif
|
||||||
//need to be there even no authentication to say to UI no authentication
|
//need to be there even no authentication to say to UI no authentication
|
||||||
web_server.on("/login", HTTP_ANY, handle_login);
|
web_server.on("/login", HTTP_ANY, handle_login);
|
||||||
#ifdef SSDP_FEATURE
|
#ifdef SSDP_FEATURE
|
||||||
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);
|
||||||
@ -348,9 +366,9 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
|||||||
web_server.onNotFound ( handle_not_found);
|
web_server.onNotFound ( handle_not_found);
|
||||||
//web commands
|
//web commands
|
||||||
web_server.on ("/command", HTTP_ANY, handle_web_command);
|
web_server.on ("/command", HTTP_ANY, handle_web_command);
|
||||||
web_server.on ("/command_silent", HTTP_ANY, handle_web_command_silent);
|
web_server.on ("/command_silent", HTTP_ANY, handle_web_command_silent);
|
||||||
//Serial SD management
|
//Serial SD management
|
||||||
web_server.on ("/upload_serial", HTTP_ANY, handle_serial_SDFileList, SDFile_serial_upload);
|
web_server.on ("/upload_serial", HTTP_ANY, handle_serial_SDFileList, SDFile_serial_upload);
|
||||||
|
|
||||||
blockserial = false;
|
blockserial = false;
|
||||||
restartmodule = false;
|
restartmodule = false;
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
@ -134,7 +134,7 @@ const char * WIFI_CONFIG::get_default_hostname()
|
|||||||
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
||||||
WiFi.macAddress (mac);
|
WiFi.macAddress (mac);
|
||||||
#if defined (ESP_HOST_NAME)
|
#if defined (ESP_HOST_NAME)
|
||||||
strcpy (hostname, ESP_DEFAULT_NAME);
|
strcpy (hostname, ESP_DEFAULT_NAME);
|
||||||
#else
|
#else
|
||||||
if (0 > sprintf (hostname, "ESP_%02X%02X%02X", mac[3], mac[4], mac[5]) ) {
|
if (0 > sprintf (hostname, "ESP_%02X%02X%02X", mac[3], mac[4], mac[5]) ) {
|
||||||
strcpy (hostname, ESP_DEFAULT_NAME);
|
strcpy (hostname, ESP_DEFAULT_NAME);
|
||||||
@ -164,66 +164,67 @@ void WIFI_CONFIG::Safe_Setup()
|
|||||||
WiFi.softAPConfig ( local_ip, gateway, subnet);
|
WiFi.softAPConfig ( local_ip, gateway, subnet);
|
||||||
CONFIG::wait (1000);
|
CONFIG::wait (1000);
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(100);
|
OLED_DISPLAY::display_signal(100);
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
ESPCOM::print(ssid.c_str(), OLED_PIPE);
|
ESPCOM::print(ssid.c_str(), OLED_PIPE);
|
||||||
OLED_DISPLAY::setCursor(0, 16);
|
OLED_DISPLAY::setCursor(0, 16);
|
||||||
ESPCOM::print(local_ip.toString().c_str(), OLED_PIPE);
|
ESPCOM::print(local_ip.toString().c_str(), OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
ESPCOM::println (F ("Safe mode started"), PRINTER_PIPE);
|
ESPCOM::println (F ("Safe mode started"), PRINTER_PIPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//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:
|
||||||
#ifndef MKS_TFT_FEATURE
|
#ifndef MKS_TFT_FEATURE
|
||||||
ESPCOM::println (F ("Connected"), PRINTER_PIPE);
|
ESPCOM::println (F ("Connected"), PRINTER_PIPE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
ESPCOM::print("", OLED_PIPE);
|
ESPCOM::print("", OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case WIFI_EVENT_STAMODE_DISCONNECTED:
|
case WIFI_EVENT_STAMODE_DISCONNECTED:
|
||||||
ESPCOM::println (F ("Disconnected"), PRINTER_PIPE);
|
ESPCOM::println (F ("Disconnected"), PRINTER_PIPE);
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(-1);
|
OLED_DISPLAY::display_signal(-1);
|
||||||
OLED_DISPLAY::setCursor(0, 16);
|
OLED_DISPLAY::setCursor(0, 16);
|
||||||
ESPCOM::print("", OLED_PIPE);
|
ESPCOM::print("", OLED_PIPE);
|
||||||
OLED_DISPLAY::setCursor(0, 48);
|
OLED_DISPLAY::setCursor(0, 48);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case WIFI_EVENT_STAMODE_GOT_IP:
|
case WIFI_EVENT_STAMODE_GOT_IP:
|
||||||
#ifndef MKS_TFT_FEATURE
|
#ifndef MKS_TFT_FEATURE
|
||||||
ESPCOM::println (WiFi.localIP().toString().c_str(), PRINTER_PIPE);
|
ESPCOM::println (WiFi.localIP().toString().c_str(), PRINTER_PIPE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::setCursor(0, 16);
|
OLED_DISPLAY::setCursor(0, 16);
|
||||||
ESPCOM::print(WiFi.localIP().toString().c_str(), OLED_PIPE);
|
ESPCOM::print(WiFi.localIP().toString().c_str(), OLED_PIPE);
|
||||||
OLED_DISPLAY::setCursor(0, 48);
|
OLED_DISPLAY::setCursor(0, 48);
|
||||||
ESPCOM::print("", OLED_PIPE);
|
ESPCOM::print("", OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
|
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
|
||||||
ESPCOM::println (F ("New client"), PRINTER_PIPE);
|
ESPCOM::println (F ("New client"), PRINTER_PIPE);
|
||||||
break;
|
break;
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case SYSTEM_EVENT_STA_LOST_IP:
|
case SYSTEM_EVENT_STA_LOST_IP:
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +241,7 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY);
|
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY);
|
||||||
#else
|
#else
|
||||||
WiFi.onEvent(onWiFiEvent);
|
WiFi.onEvent(onWiFiEvent);
|
||||||
#endif
|
#endif
|
||||||
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||||
//set the sleep mode
|
//set the sleep mode
|
||||||
@ -249,11 +250,11 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::clear_lcd();
|
OLED_DISPLAY::clear_lcd();
|
||||||
#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 ?
|
||||||
@ -275,10 +276,10 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(100);
|
OLED_DISPLAY::display_signal(100);
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
|
|
||||||
ESPCOM::print(sbuf, OLED_PIPE);
|
ESPCOM::print(sbuf, OLED_PIPE);
|
||||||
#else
|
#else
|
||||||
#ifndef MKS_TFT_FEATURE
|
#ifndef MKS_TFT_FEATURE
|
||||||
ESPCOM::println (sbuf, PRINTER_PIPE);
|
ESPCOM::println (sbuf, PRINTER_PIPE);
|
||||||
@ -346,9 +347,9 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
delay (50);
|
delay (50);
|
||||||
WiFi.softAP (sbuf, pwd);
|
WiFi.softAP (sbuf, pwd);
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(100);
|
OLED_DISPLAY::display_signal(100);
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
ESPCOM::print(sbuf, OLED_PIPE);
|
ESPCOM::print(sbuf, OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
delay (100);
|
delay (100);
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
@ -419,12 +420,12 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MKS_TFT_FEATURE
|
#ifndef MKS_TFT_FEATURE
|
||||||
ESPCOM::println (sbuf, PRINTER_PIPE);
|
ESPCOM::println (sbuf, PRINTER_PIPE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(-1);
|
OLED_DISPLAY::display_signal(-1);
|
||||||
OLED_DISPLAY::setCursor(0, 0);
|
OLED_DISPLAY::setCursor(0, 0);
|
||||||
ESPCOM::print(sbuf, OLED_PIPE);
|
ESPCOM::print(sbuf, OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
LOG ("SSID ")
|
LOG ("SSID ")
|
||||||
LOG (sbuf)
|
LOG (sbuf)
|
||||||
@ -467,18 +468,20 @@ 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);
|
||||||
}
|
}
|
||||||
delay (100);
|
delay (100);
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
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) {
|
||||||
esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode);
|
sleep_mode=WIFI_PS_MIN_MODEM;
|
||||||
|
}
|
||||||
|
esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode);
|
||||||
#endif
|
#endif
|
||||||
delay (100);
|
delay (100);
|
||||||
byte i = 0;
|
byte i = 0;
|
||||||
@ -490,16 +493,16 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
switch (WiFi.status() ) {
|
switch (WiFi.status() ) {
|
||||||
case 1:
|
case 1:
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(-1);
|
OLED_DISPLAY::display_signal(-1);
|
||||||
#endif
|
#endif
|
||||||
if ((dot == 0) || last!=WiFi.status()) {
|
if ((dot == 0) || last!=WiFi.status()) {
|
||||||
msg = F ("No SSID");
|
msg = F ("No SSID");
|
||||||
last=WiFi.status();
|
last=WiFi.status();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if ((dot == 0) || last!=WiFi.status()) {
|
if ((dot == 0) || last!=WiFi.status()) {
|
||||||
msg = F ("No Connection");
|
msg = F ("No Connection");
|
||||||
last=WiFi.status();
|
last=WiFi.status();
|
||||||
}
|
}
|
||||||
@ -507,26 +510,26 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||||
#endif
|
#endif
|
||||||
if ((dot == 0) || last!=WiFi.status()) {
|
if ((dot == 0) || last!=WiFi.status()) {
|
||||||
msg = F ("Connecting");
|
msg = F ("Connecting");
|
||||||
last=WiFi.status();
|
last=WiFi.status();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dot++;
|
dot++;
|
||||||
msg.trim();
|
msg.trim();
|
||||||
msg += F (".");
|
msg += F (".");
|
||||||
//for smoothieware to keep position
|
//for smoothieware to keep position
|
||||||
for (byte i = 0; i < 4 - dot; i++) {
|
for (byte i = 0; i < 4 - dot; i++) {
|
||||||
msg += F (" ");
|
msg += F (" ");
|
||||||
}
|
}
|
||||||
if (dot == 4) {
|
if (dot == 4) {
|
||||||
dot = 0;
|
dot = 0;
|
||||||
}
|
}
|
||||||
#ifndef MKS_TFT_FEATURE
|
#ifndef MKS_TFT_FEATURE
|
||||||
ESPCOM::println (msg, PRINTER_PIPE);
|
ESPCOM::println (msg, PRINTER_PIPE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay (500);
|
delay (500);
|
||||||
@ -547,23 +550,24 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
|||||||
|
|
||||||
//Get IP
|
//Get IP
|
||||||
if (WiFi.getMode()== WIFI_AP) {
|
if (WiFi.getMode()== WIFI_AP) {
|
||||||
currentIP = WiFi.softAPIP();
|
currentIP = WiFi.softAPIP();
|
||||||
ESPCOM::println (currentIP.toString().c_str(), PRINTER_PIPE);
|
ESPCOM::println (currentIP.toString().c_str(), PRINTER_PIPE);
|
||||||
#ifdef ESP_OLED_FEATURE
|
#ifdef ESP_OLED_FEATURE
|
||||||
OLED_DISPLAY::setCursor(0, 16);
|
OLED_DISPLAY::setCursor(0, 16);
|
||||||
ESPCOM::print(currentIP.toString().c_str(), OLED_PIPE);
|
ESPCOM::print(currentIP.toString().c_str(), OLED_PIPE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#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) {
|
||||||
else if (WiFi.getMode() != WIFI_STA) ESPCOM::print("AP Ready", OLED_PIPE);
|
ESPCOM::print("AP Ready", OLED_PIPE);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||||
return true;
|
return true;
|
||||||
@ -596,7 +600,7 @@ bool WIFI_CONFIG::Enable_servers()
|
|||||||
data_server->setNoDelay (true);
|
data_server->setNoDelay (true);
|
||||||
#endif
|
#endif
|
||||||
#if !defined (ASYNCWEBSERVER)
|
#if !defined (ASYNCWEBSERVER)
|
||||||
socket_server = new WebSocketsServer (wifi_config.iweb_port+1);
|
socket_server = new WebSocketsServer (wifi_config.iweb_port+1);
|
||||||
socket_server->begin();
|
socket_server->begin();
|
||||||
socket_server->onEvent(webSocketEvent);
|
socket_server->onEvent(webSocketEvent);
|
||||||
#endif
|
#endif
|
||||||
@ -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);
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
#ifdef MDNS_FEATURE
|
#ifdef MDNS_FEATURE
|
||||||
MDNSResponder mdns;
|
MDNSResponder mdns;
|
||||||
#endif
|
#endif
|
||||||
bool WiFi_on;
|
bool WiFi_on;
|
||||||
WIFI_CONFIG();
|
WIFI_CONFIG();
|
||||||
int iweb_port;
|
int iweb_port;
|
||||||
int idata_port;
|
int idata_port;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user