mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-11 17:59:10 +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.
|
||||
|
||||
1. Please follow installation of the ESP core you want to use : [ESP8266 core version](https://github.com/esp8266/Arduino) or [ESP32 core version](https://github.com/espressif/arduino-esp32)
|
||||
2. Add libraries
|
||||
2. Add manually libraries present in libraries directory -these versions are verified to work with ESP3D
|
||||
If you want async webserver (currently not recommended due to reliability issues):
|
||||
* ESPAsyncWebServer from @me-no-dev
|
||||
if you target ESP8266
|
||||
@ -98,14 +98,14 @@ if you target ESP32:
|
||||
Specific for ESP32
|
||||
* ESP32SSDP
|
||||
If you want sync webserver (recommended as stable):
|
||||
* arduinoWebSockets fron @Links2004
|
||||
* arduinoWebSockets from @Links2004
|
||||
|
||||
If you want OLED support:
|
||||
* oled-ssd1306 from @squix78
|
||||
|
||||
If you want DHT11/22 support:
|
||||
* DHT_sensor_library_for_ESPx from @beegee-tokyo
|
||||
3. Compile project from examples\basicesp3d\basicesp3d.ino) according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled.
|
||||
3. Compile project esp3d.ino according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled.
|
||||
* for ESP8266 set CPU freq to 160MHz for better (https://github.com/luc-github/ESP3D/wiki/Install-Instructions)
|
||||
4. Upload the data content on ESP3D file system
|
||||
* Using SPIFFS uploader, this plugin and install instructions is available on each ESP core - please refere to it
|
||||
|
@ -48,11 +48,11 @@
|
||||
#include "espcom.h"
|
||||
|
||||
#ifdef SSDP_FEATURE
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESP32SSDP.h>
|
||||
#else
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESP32SSDP.h>
|
||||
#else
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//embedded response file if no files on SPIFFS
|
||||
@ -61,7 +61,7 @@ bool can_process_serial = true;
|
||||
|
||||
extern bool deleteRecursive(String path);
|
||||
extern bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb);
|
||||
extern void CloseSerialUpload (bool iserror, String & filename , int32_t linenb);
|
||||
extern void CloseSerialUpload (bool iserror, String & filename, int32_t linenb);
|
||||
extern bool purge_serial();
|
||||
extern long id_connection;
|
||||
|
||||
@ -87,8 +87,8 @@ void handle_login(AsyncWebServerRequest *request)
|
||||
{
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
#else
|
||||
AsyncWebServerResponse * response = request->beginResponse (200, "application/json", "{\"status\":\"Ok\",\"authentication_lvl\":\"admin\"}");
|
||||
response->addHeader("Cache-Control","no-cache");
|
||||
AsyncWebServerResponse * response = request->beginResponse (200, "application/json", "{\"status\":\"Ok\",\"authentication_lvl\":\"admin\"}");
|
||||
response->addHeader("Cache-Control","no-cache");
|
||||
request->send(response);
|
||||
#endif
|
||||
}
|
||||
@ -396,7 +396,7 @@ void SPIFFSFileupload (AsyncWebServerRequest *request, String filename, size_t i
|
||||
LOG ("Uploading: ")
|
||||
LOG (filename)
|
||||
LOG ("\n")
|
||||
//get authentication status
|
||||
//get authentication status
|
||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||
//Guest cannot upload - only admin
|
||||
if (auth_level == LEVEL_GUEST) {
|
||||
@ -414,9 +414,9 @@ void SPIFFSFileupload (AsyncWebServerRequest *request, String filename, size_t i
|
||||
LOG ("\n")
|
||||
}
|
||||
if(auth_level != LEVEL_ADMIN) {
|
||||
String filename = upload_filename;
|
||||
String filename = upload_filename;
|
||||
upload_filename = "/user" + filename;
|
||||
}
|
||||
}
|
||||
//Upload start
|
||||
//**************
|
||||
if (!index) {
|
||||
@ -461,8 +461,8 @@ void SPIFFSFileupload (AsyncWebServerRequest *request, String filename, size_t i
|
||||
if (request->arg (sizeargname.c_str()) != String(filesize)) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||
SPIFFS.remove (upload_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG ("Close file\n")
|
||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||
@ -569,12 +569,12 @@ void WebUpdateUpload (AsyncWebServerRequest *request, String filename, size_t in
|
||||
String sizeargname = filename + "S";
|
||||
if (request->hasArg (sizeargname.c_str()) ) {
|
||||
ESPCOM::println (F ("Check integrity"), PRINTER_PIPE);
|
||||
if (request->arg (sizeargname.c_str()) != String(totalSize)) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||
ESPCOM::println (F ("Update Error"), PRINTER_PIPE);
|
||||
Update.end();
|
||||
request->client()->abort();
|
||||
}
|
||||
if (request->arg (sizeargname.c_str()) != String(totalSize)) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||
ESPCOM::println (F ("Update Error"), PRINTER_PIPE);
|
||||
Update.end();
|
||||
request->client()->abort();
|
||||
}
|
||||
}
|
||||
if (Update.end (true) ) { //true to set the size to the current progress
|
||||
//Update is done
|
||||
@ -584,7 +584,7 @@ void WebUpdateUpload (AsyncWebServerRequest *request, String filename, size_t in
|
||||
ESPCOM::println (F ("Update 100%"), PRINTER_PIPE);
|
||||
}
|
||||
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -628,13 +628,13 @@ void handle_not_found (AsyncWebServerRequest *request)
|
||||
//Handle web command query and send answer//////////////////////////////
|
||||
void handle_web_command (AsyncWebServerRequest *request)
|
||||
{
|
||||
//to save time if already disconnected
|
||||
if (request->hasArg ("PAGEID") ) {
|
||||
//to save time if already disconnected
|
||||
if (request->hasArg ("PAGEID") ) {
|
||||
if (request->arg ("PAGEID").length() > 0 ) {
|
||||
if (request->arg ("PAGEID").toInt() != id_connection) {
|
||||
request->send (200, "text/plain", "Invalid command");
|
||||
return;
|
||||
}
|
||||
if (request->arg ("PAGEID").toInt() != id_connection) {
|
||||
request->send (200, "text/plain", "Invalid command");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||
@ -709,8 +709,10 @@ void handle_web_command (AsyncWebServerRequest *request)
|
||||
LOG ("Start PurgeSerial\r\n")
|
||||
ESPCOM::processFromSerial (true);
|
||||
LOG ("End PurgeSerial\r\n")
|
||||
can_process_serial = false;
|
||||
request->onDisconnect([request](){can_process_serial = true;});
|
||||
can_process_serial = false;
|
||||
request->onDisconnect([request]() {
|
||||
can_process_serial = true;
|
||||
});
|
||||
//send command
|
||||
LOG ("Send Command\r\n")
|
||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||
@ -982,10 +984,10 @@ void handle_web_command_silent (AsyncWebServerRequest *request)
|
||||
//to save time if already disconnected
|
||||
if (request->hasArg ("PAGEID") ) {
|
||||
if (request->arg ("PAGEID").length() > 0 ) {
|
||||
if (request->arg ("PAGEID").toInt() != id_connection) {
|
||||
request->send (200, "text/plain", "Invalid command");
|
||||
return;
|
||||
}
|
||||
if (request->arg ("PAGEID").toInt() != id_connection) {
|
||||
request->send (200, "text/plain", "Invalid command");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||
@ -1052,7 +1054,7 @@ void handle_web_command_silent (AsyncWebServerRequest *request)
|
||||
LOG ("Send Command\r\n")
|
||||
//send command
|
||||
ESPCOM::println (cmd, DEFAULT_PRINTER_PIPE);
|
||||
|
||||
|
||||
request->send (200, "text/plain", "ok");
|
||||
} else {
|
||||
request->send (200, "text/plain", "Serial is busy, retry later!");
|
||||
@ -1109,16 +1111,18 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
//Upload start
|
||||
//**************
|
||||
if (!index) {
|
||||
LOG("Upload Start\r\n")
|
||||
LOG("Upload Start\r\n")
|
||||
String command = "M29";
|
||||
String resetcmd = "M110 N0";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
resetcmd = "N0 M110";
|
||||
}
|
||||
lineNb=1;
|
||||
//close any ongoing upload and get current line number
|
||||
if(!sendLine2Serial (command,1, &lineNb)){
|
||||
if(!sendLine2Serial (command,1, &lineNb)) {
|
||||
//it can failed for repetier
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
if(!sendLine2Serial (command,-1, NULL)){
|
||||
if(!sendLine2Serial (command,-1, NULL)) {
|
||||
LOG("Start Upload failed")
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
return;
|
||||
@ -1131,13 +1135,13 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
}
|
||||
//Mount SD card
|
||||
command = "M21";
|
||||
if(!sendLine2Serial (command,-1, NULL)){
|
||||
if(!sendLine2Serial (command,-1, NULL)) {
|
||||
LOG("Mounting SD failed")
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
//Reset line numbering
|
||||
if(!sendLine2Serial (resetcmd,-1, NULL)){
|
||||
if(!sendLine2Serial (resetcmd,-1, NULL)) {
|
||||
LOG("Reset Numbering failed")
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
return;
|
||||
@ -1158,16 +1162,16 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
command = "M28 " + current_filename;
|
||||
//send start upload
|
||||
//no correction allowed because it means reset numbering was failed
|
||||
if (sendLine2Serial(command, lineNb, NULL)){
|
||||
if (sendLine2Serial(command, lineNb, NULL)) {
|
||||
CONFIG::wait(1200);
|
||||
//additional purge, in case it is slow to answer
|
||||
purge_serial();
|
||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||
LOG("Creation Ok\r\n")
|
||||
|
||||
|
||||
} else {
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
LOG("Creation failed\r\n");
|
||||
LOG("Creation failed\r\n");
|
||||
}
|
||||
}
|
||||
//Upload write
|
||||
@ -1184,12 +1188,12 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
}
|
||||
//it is an end line
|
||||
else if ( (data[pos] == 13) || (data[pos] == 10) ) {
|
||||
is_comment = false;
|
||||
is_comment = false;
|
||||
//does line fit the buffer ?
|
||||
if (current_line.length() < 126) {
|
||||
//do we have something in buffer ?
|
||||
if (current_line.length() > 0 ) {
|
||||
lineNb++;
|
||||
lineNb++;
|
||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||
LOG ("Error sending line\n")
|
||||
CloseSerialUpload (true, current_filename,lineNb);
|
||||
@ -1251,19 +1255,20 @@ void SDFile_serial_upload (AsyncWebServerRequest *request, String filename, size
|
||||
|
||||
|
||||
//on event connect function
|
||||
void handle_onevent_connect(AsyncEventSourceClient *client)
|
||||
{
|
||||
if (!client->lastId()){
|
||||
//Init active ID
|
||||
id_connection++;
|
||||
client->send(String(id_connection).c_str(), "InitID", id_connection, 1000);
|
||||
//Dispatch who is active ID
|
||||
web_interface->web_events.send( String(id_connection).c_str(),"ActiveID");
|
||||
}
|
||||
void handle_onevent_connect(AsyncEventSourceClient *client)
|
||||
{
|
||||
if (!client->lastId()) {
|
||||
//Init active ID
|
||||
id_connection++;
|
||||
client->send(String(id_connection).c_str(), "InitID", id_connection, 1000);
|
||||
//Dispatch who is active ID
|
||||
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){
|
||||
//Handle WebSocket event
|
||||
void handle_Websocket_Event(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)
|
||||
{
|
||||
//Handle WebSocket event
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include "SPIFFS.h"
|
||||
#define MAX_GPIO 37
|
||||
int ChannelAttached2Pin[16]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
|
||||
int ChannelAttached2Pin[16]= {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
|
||||
#else
|
||||
#define MAX_GPIO 16
|
||||
#endif
|
||||
@ -42,7 +42,7 @@ int ChannelAttached2Pin[16]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
|
||||
#ifdef DHT_FEATURE
|
||||
#include "DHTesp.h"
|
||||
extern DHTesp dht;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "notifications_service.h"
|
||||
@ -140,7 +140,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
bool response = true;
|
||||
level_authenticate_type auth_type = auth_level;
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
|
||||
|
||||
if (isadmin(cmd_params)) {
|
||||
auth_type = LEVEL_ADMIN;
|
||||
LOG("you are Admin\r\n");
|
||||
@ -150,20 +150,15 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
LOG("you are User\r\n");
|
||||
}
|
||||
#ifdef DEBUG_ESP3D
|
||||
if ( auth_type == LEVEL_ADMIN)
|
||||
{
|
||||
LOG("admin identified\r\n");
|
||||
}
|
||||
else {
|
||||
if( auth_type == LEVEL_USER)
|
||||
{
|
||||
LOG("user identified\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("guest identified\r\n");
|
||||
}
|
||||
if ( auth_type == LEVEL_ADMIN) {
|
||||
LOG("admin identified\r\n");
|
||||
} else {
|
||||
if( auth_type == LEVEL_USER) {
|
||||
LOG("user identified\r\n");
|
||||
} else {
|
||||
LOG("guest identified\r\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
//manage parameters
|
||||
@ -381,13 +376,13 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
//disable wifi
|
||||
ESPCOM::println ("Disabling Wifi", output, espresponse);
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
ESPCOM::print("Wifi disabled", OLED_PIPE);
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
ESPCOM::print("Wifi disabled", OLED_PIPE);
|
||||
#endif
|
||||
WiFi.disconnect(true);
|
||||
WiFi.enableSTA (false);
|
||||
@ -458,15 +453,25 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
time(&now);
|
||||
localtime_r(&now, &tmstruct);
|
||||
stmp = String((tmstruct.tm_year)+1900) + "-";
|
||||
if (((tmstruct.tm_mon)+1) < 10) stmp +="0";
|
||||
if (((tmstruct.tm_mon)+1) < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(( tmstruct.tm_mon)+1) + "-";
|
||||
if (tmstruct.tm_mday < 10) stmp +="0";
|
||||
if (tmstruct.tm_mday < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_mday) + " ";
|
||||
if (tmstruct.tm_hour < 10) stmp +="0";
|
||||
if (tmstruct.tm_hour < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_hour) + ":";
|
||||
if (tmstruct.tm_min < 10) stmp +="0";
|
||||
if (tmstruct.tm_min < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_min) + ":";
|
||||
if (tmstruct.tm_sec < 10) stmp +="0";
|
||||
if (tmstruct.tm_sec < 10) {
|
||||
stmp +="0";
|
||||
}
|
||||
stmp += String(tmstruct.tm_sec);
|
||||
ESPCOM::println(stmp.c_str(), output, espresponse);
|
||||
}
|
||||
@ -495,11 +500,11 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
response = false;
|
||||
} else {
|
||||
int pin = parameter.toInt();
|
||||
//check pin is valid
|
||||
//check pin is valid
|
||||
if ((pin >= 0) && (pin <= MAX_GPIO)) {
|
||||
//check if analog or digital
|
||||
bool isdigital = true;
|
||||
|
||||
|
||||
parameter = get_param (cmd_params, "ANALOG=", false);
|
||||
if (parameter == "YES") {
|
||||
LOG ("Set as analog\r\n")
|
||||
@ -507,8 +512,8 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
parameter = get_param (cmd_params, "CLEARCHANNELS=", false);
|
||||
if (parameter == "YES") {
|
||||
for (uint8_t p = 0; p < 16;p++){
|
||||
if(ChannelAttached2Pin[p] != -1){
|
||||
for (uint8_t p = 0; p < 16; p++) {
|
||||
if(ChannelAttached2Pin[p] != -1) {
|
||||
ledcDetachPin(ChannelAttached2Pin[p]);
|
||||
ChannelAttached2Pin[p] = -1;
|
||||
}
|
||||
@ -535,21 +540,21 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
LOG ("Set as input pull up\r\n")
|
||||
pinMode (pin, INPUT_PULLUP);
|
||||
}
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
else {
|
||||
LOG ("Set as input pull down 16\r\n")
|
||||
pinMode (pin, INPUT_PULLDOWN_16);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
value = digitalRead (pin);
|
||||
} else {
|
||||
#ifdef ARDUINO_ARCH_ESP8266 //only one ADC on ESP8266 A0
|
||||
#ifdef ARDUINO_ARCH_ESP8266 //only one ADC on ESP8266 A0
|
||||
value = analogRead (A0);
|
||||
#else
|
||||
#else
|
||||
value = analogRead (pin);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
LOG ("Read:");
|
||||
LOG (String (value).c_str() )
|
||||
@ -584,56 +589,56 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
LOG ("Set:")
|
||||
LOG (String ( value) )
|
||||
LOG ("\r\n")
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
|
||||
analogWriteRange(analog_range);
|
||||
pinMode(pin, OUTPUT);
|
||||
analogWrite(pin, value);
|
||||
#else
|
||||
#else
|
||||
int channel = -1;
|
||||
for (uint8_t p = 0; p < 16;p++){
|
||||
if(ChannelAttached2Pin[p] == pin){
|
||||
for (uint8_t p = 0; p < 16; p++) {
|
||||
if(ChannelAttached2Pin[p] == pin) {
|
||||
channel = p;
|
||||
}
|
||||
}
|
||||
if (channel==-1){
|
||||
for (uint8_t p = 0; p < 16;p++){
|
||||
if(ChannelAttached2Pin[p] == -1){
|
||||
channel = p;
|
||||
ChannelAttached2Pin[p] = pin;
|
||||
p = 16;
|
||||
if (channel==-1) {
|
||||
for (uint8_t p = 0; p < 16; p++) {
|
||||
if(ChannelAttached2Pin[p] == -1) {
|
||||
channel = p;
|
||||
ChannelAttached2Pin[p] = pin;
|
||||
p = 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uint8_t resolution = 0;
|
||||
analog_range++;
|
||||
switch(analog_range){
|
||||
case 8191:
|
||||
resolution=13;
|
||||
break;
|
||||
case 1024:
|
||||
resolution=10;
|
||||
break;
|
||||
case 2047:
|
||||
resolution=11;
|
||||
break;
|
||||
case 4095:
|
||||
resolution=12;
|
||||
break;
|
||||
default:
|
||||
resolution=8;
|
||||
analog_range = 255;
|
||||
break;
|
||||
switch(analog_range) {
|
||||
case 8191:
|
||||
resolution=13;
|
||||
break;
|
||||
case 1024:
|
||||
resolution=10;
|
||||
break;
|
||||
case 2047:
|
||||
resolution=11;
|
||||
break;
|
||||
case 4095:
|
||||
resolution=12;
|
||||
break;
|
||||
default:
|
||||
resolution=8;
|
||||
analog_range = 255;
|
||||
break;
|
||||
}
|
||||
if ((channel==-1) || (value > (analog_range-1))){
|
||||
if ((channel==-1) || (value > (analog_range-1))) {
|
||||
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
ledcSetup(channel, 1000, resolution);
|
||||
ledcAttachPin(pin, channel);
|
||||
ledcWrite(channel, value);
|
||||
#endif
|
||||
} else{
|
||||
#endif
|
||||
} else {
|
||||
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
|
||||
response = false;
|
||||
}
|
||||
@ -650,7 +655,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
|
||||
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
//Output to oled
|
||||
//Output to oled
|
||||
//[ESP210]<Text>
|
||||
case 210: {
|
||||
parameter = get_param (cmd_params, "C=", 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);
|
||||
int l = parameter.toInt();
|
||||
parameter = get_param (cmd_params, "T=", true);
|
||||
OLED_DISPLAY::setCursor(c, l);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
OLED_DISPLAY::setCursor(c, l);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
//Output to oled line 1
|
||||
//[ESP211]<Text>
|
||||
case 211: {
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
//Output to oled line 2
|
||||
//[ESP212]<Text>
|
||||
case 212: {
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
//Output to oled line 3
|
||||
//[ESP213]<Text>
|
||||
case 213: {
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 32);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 32);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
//Output to oled line 4
|
||||
//[ESP214]<Text>
|
||||
case 214: {
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
ESPCOM::print(parameter.c_str(), OLED_PIPE);
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
//display ESP3D EEPROM version detected
|
||||
case 300:
|
||||
{
|
||||
case 300: {
|
||||
uint8_t v = CONFIG::get_EEPROM_version();
|
||||
ESPCOM::println (String(v).c_str(), output, espresponse);
|
||||
}
|
||||
@ -1268,8 +1272,8 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
ESPCOM::print ( (const char *) CONFIG::intTostr (UNKNOWN_FW), output, espresponse);
|
||||
ESPCOM::print (F ("\"}]}"), output, espresponse);
|
||||
ESPCOM::println (F (","), output, espresponse);
|
||||
|
||||
//Output flag
|
||||
|
||||
//Output flag
|
||||
ESPCOM::print (F ("{\"F\":\"printer\",\"P\":\""), output, espresponse);
|
||||
ESPCOM::print ( (const char *) CONFIG::intTostr (EP_OUTPUT_FLAG), 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+= "\"}";
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
s+=",{\"Oled\":\"";
|
||||
s+= CONFIG::intTostr(FLAG_BLOCK_OLED);
|
||||
s+= CONFIG::intTostr(FLAG_BLOCK_OLED);
|
||||
s+="\"}";
|
||||
#endif
|
||||
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 (F ("\"},{\"AM2302\":\""), 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 (F ("\"}]}"), output, espresponse);
|
||||
|
||||
//DHT interval
|
||||
|
||||
//DHT interval
|
||||
ESPCOM::println (F (","), output, espresponse);
|
||||
ESPCOM::print (F ("{\"F\":\"printer\",\"P\":\""), output, espresponse);
|
||||
ESPCOM::print ( (const char *) CONFIG::intTostr (EP_DHT_INTERVAL), output, espresponse);
|
||||
@ -1334,7 +1338,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
ESPCOM::print ( (const char *) CONFIG::intTostr (0), output, espresponse);
|
||||
ESPCOM::print (F ("\"}"), output, espresponse);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
//end JSON
|
||||
@ -1357,7 +1361,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
if (! (styp == "B" || styp == "S" || styp == "A" || styp == "I" || styp == "F") ) {
|
||||
response = false;
|
||||
}
|
||||
if ((sval.length() == 0) && !((pos==EP_AP_PASSWORD) || (pos==EP_STA_PASSWORD))){
|
||||
if ((sval.length() == 0) && !((pos==EP_AP_PASSWORD) || (pos==EP_STA_PASSWORD))) {
|
||||
response = false;
|
||||
}
|
||||
|
||||
@ -1378,13 +1382,13 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
}
|
||||
#endif
|
||||
if (response) {
|
||||
if ((styp == "B") || (styp == "F")){
|
||||
if ((styp == "B") || (styp == "F")) {
|
||||
byte bbuf = sval.toInt();
|
||||
if (!CONFIG::write_byte (pos, bbuf) ) {
|
||||
response = false;
|
||||
} else {
|
||||
//dynamique refresh is better than restart the board
|
||||
if (pos == EP_OUTPUT_FLAG){
|
||||
if (pos == EP_OUTPUT_FLAG) {
|
||||
CONFIG::output_flag = bbuf;
|
||||
}
|
||||
if (pos == EP_TARGET_FW) {
|
||||
@ -1444,22 +1448,22 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
case 410: {
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
bool plain = (parameter == "plain");
|
||||
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
if (!plain) {
|
||||
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
||||
}
|
||||
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
if (!plain) {
|
||||
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
||||
}
|
||||
int n = WiFi.scanComplete();
|
||||
if (n == -2) {
|
||||
WiFi.scanNetworks (ESP_USE_ASYNC);
|
||||
} else if (n) {
|
||||
#else
|
||||
int n = WiFi.scanNetworks ();
|
||||
if (!plain) {
|
||||
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
||||
}
|
||||
int n = WiFi.scanNetworks ();
|
||||
if (!plain) {
|
||||
ESPCOM::print (F ("{\"AP_LIST\":["), output, espresponse);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (i > 0) {
|
||||
if (!plain) {
|
||||
@ -1500,7 +1504,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
}
|
||||
}
|
||||
WiFi.scanDelete();
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
if (WiFi.scanComplete() == -2) {
|
||||
WiFi.scanNetworks (ESP_USE_ASYNC);
|
||||
}
|
||||
@ -1555,16 +1559,18 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
}
|
||||
int32_t linenb = 1;
|
||||
cmd_params.trim() ;
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb))ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
else { //it may failed because of skip if repetier so let's reset numbering first
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb)) {
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
} else { //it may failed because of skip if repetier so let's reset numbering first
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
//reset numbering
|
||||
String cmd = "M110 N0";
|
||||
if (sendLine2Serial (cmd, -1, NULL)){
|
||||
if (sendLine2Serial (cmd, -1, NULL)) {
|
||||
linenb = 1;
|
||||
//if success let's try again to send the command
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb))ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
else {
|
||||
if (sendLine2Serial (cmd_params, linenb, &linenb)) {
|
||||
ESPCOM::println (OK_CMD_MSG, output, espresponse);
|
||||
} else {
|
||||
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
||||
response = false;
|
||||
}
|
||||
@ -1573,13 +1579,13 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
response = false;
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
ESPCOM::println (ERROR_CMD_MSG, output, espresponse);
|
||||
response = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
//[ESP501]<line>
|
||||
case 501: { //send line checksum
|
||||
cmd_params.trim();
|
||||
@ -1656,7 +1662,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
//get
|
||||
if (parameter.length() == 0) {
|
||||
uint8_t Ntype = 0;
|
||||
if (!CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &Ntype ) ){
|
||||
if (!CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &Ntype ) ) {
|
||||
Ntype =0;
|
||||
}
|
||||
char sbuf[MAX_DATA_LENGTH + 1];
|
||||
@ -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) ) {
|
||||
tmp+= " ";
|
||||
tmp += sbuf;
|
||||
}
|
||||
}
|
||||
ESPCOM::println (tmp.c_str(), output, espresponse);
|
||||
} else {
|
||||
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=");
|
||||
if (parameter.length() > 0) {
|
||||
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;
|
||||
} else {
|
||||
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=");
|
||||
if (parameter.length() > 0) {
|
||||
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;
|
||||
} else {
|
||||
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=");
|
||||
if (parameter.length() > 0) {
|
||||
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;
|
||||
} else {
|
||||
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
|
||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
CONFIG::wait (1);
|
||||
CONFIG::wait (1);
|
||||
}
|
||||
}
|
||||
currentfile.close();
|
||||
@ -1876,7 +1882,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
#else
|
||||
ESPCOM::print (F ("no"), output, espresponse);
|
||||
#endif
|
||||
ESPCOM::print (F (" # webcommunication:"), output, espresponse);
|
||||
ESPCOM::print (F (" # webcommunication:"), output, espresponse);
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
ESPCOM::print (F ("Async"), output, espresponse);
|
||||
#else
|
||||
@ -1884,10 +1890,12 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
String sp = String(wifi_config.iweb_port+1);
|
||||
ESPCOM::print (sp.c_str(), output, espresponse);
|
||||
#endif
|
||||
|
||||
|
||||
ESPCOM::print (F (" # hostname:"), output, espresponse);
|
||||
ESPCOM::print (shost, output, espresponse);
|
||||
if (WiFi.getMode() == WIFI_AP) ESPCOM::print (F("(AP mode)"), output, espresponse);
|
||||
ESPCOM::print (shost, output, espresponse);
|
||||
if (WiFi.getMode() == WIFI_AP) {
|
||||
ESPCOM::print (F("(AP mode)"), output, espresponse);
|
||||
}
|
||||
|
||||
ESPCOM::println ("", output, espresponse);
|
||||
}
|
||||
@ -1901,7 +1909,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
||||
case 810:
|
||||
web_interface->blockserial = false;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
|
||||
response = false;
|
||||
@ -1937,11 +1945,11 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
|
||||
String ESP_Command;
|
||||
int ESPpos = -1;
|
||||
#ifdef MKS_TFT_FEATURE
|
||||
if (buffer.startsWith("at+")){
|
||||
if (buffer.startsWith("at+")) {
|
||||
//echo
|
||||
ESPCOM::print (buffer, output);
|
||||
ESPCOM::print ("\r\r\n", output);
|
||||
if (buffer.startsWith("at+net_wanip=?")){
|
||||
if (buffer.startsWith("at+net_wanip=?")) {
|
||||
String ipstr;
|
||||
if (WiFi.getMode() == WIFI_STA) {
|
||||
ipstr = WiFi.localIP().toString() + "," + WiFi.subnetMask().toString()+ "," + WiFi.gatewayIP().toString()+"\r\n";
|
||||
@ -1949,16 +1957,16 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
|
||||
ipstr = WiFi.softAPIP().toString() + ",255.255.255.0," + WiFi.softAPIP().toString()+"\r\n";
|
||||
}
|
||||
ESPCOM::print (ipstr, output);
|
||||
} else if (buffer.startsWith("at+wifi_ConState=?")){
|
||||
} else if (buffer.startsWith("at+wifi_ConState=?")) {
|
||||
ESPCOM::print ("Connected\r\n", output);
|
||||
} else{
|
||||
} else {
|
||||
ESPCOM::print ("ok\r\n", output);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
ESPpos = buffer.indexOf ("[ESP");
|
||||
if (ESPpos == -1 && (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)){
|
||||
if (ESPpos == -1 && (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)) {
|
||||
ESPpos = buffer.indexOf ("[esp");
|
||||
}
|
||||
if (ESPpos > -1) {
|
||||
|
158
esp3d/config.cpp
158
esp3d/config.cpp
@ -41,7 +41,7 @@ extern "C" {
|
||||
#ifdef DHT_FEATURE
|
||||
#include "DHTesp.h"
|
||||
extern DHTesp dht;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
#include "notifications_service.h"
|
||||
@ -73,7 +73,7 @@ void CONFIG::wait (uint32_t milliseconds)
|
||||
wdtFeed();
|
||||
}
|
||||
#else
|
||||
delay(milliseconds);
|
||||
delay(milliseconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ const char* CONFIG::GetFirmwareTargetShortName()
|
||||
response = F ("marlinkimbra");
|
||||
} else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) {
|
||||
response = F ("smoothieware");
|
||||
} else if ( CONFIG::FirmwareTarget == GRBL) {
|
||||
} else if ( CONFIG::FirmwareTarget == GRBL) {
|
||||
response = F ("grbl");
|
||||
} else {
|
||||
response = F ("???");
|
||||
@ -142,7 +142,8 @@ void CONFIG::InitFirmwareTarget()
|
||||
SetFirmwareTarget (UNKNOWN_FW) ;
|
||||
}
|
||||
}
|
||||
void CONFIG::InitOutput(){
|
||||
void CONFIG::InitOutput()
|
||||
{
|
||||
byte bflag = 0;
|
||||
if (!CONFIG::read_byte (EP_OUTPUT_FLAG, &bflag ) ) {
|
||||
bflag = 0;
|
||||
@ -150,7 +151,8 @@ void CONFIG::InitOutput(){
|
||||
CONFIG::output_flag = bflag;
|
||||
}
|
||||
|
||||
bool CONFIG::is_locked(byte flag){
|
||||
bool CONFIG::is_locked(byte flag)
|
||||
{
|
||||
return ((CONFIG::output_flag & flag) == flag);
|
||||
}
|
||||
|
||||
@ -163,12 +165,13 @@ void CONFIG::InitDirectSD()
|
||||
bool CONFIG::InitBaudrate(long value)
|
||||
{
|
||||
long baud_rate = 0;
|
||||
if (value > 0)baud_rate = value;
|
||||
else {
|
||||
if ( !CONFIG::read_buffer (EP_BAUD_RATE, (byte *) &baud_rate, INTEGER_LENGTH) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (value > 0) {
|
||||
baud_rate = value;
|
||||
} else {
|
||||
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 ) ) {
|
||||
return false;
|
||||
}
|
||||
@ -178,28 +181,28 @@ bool CONFIG::InitBaudrate(long value)
|
||||
#ifdef USE_SERIAL_0
|
||||
if (Serial.baudRate() != baud_rate) {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
Serial.begin (baud_rate);
|
||||
Serial.begin (baud_rate);
|
||||
#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
|
||||
#ifdef USE_SERIAL_1
|
||||
if (Serial1.baudRate() != baud_rate) {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
Serial1.begin (baud_rate);
|
||||
Serial1.begin (baud_rate);
|
||||
#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
|
||||
#ifdef USE_SERIAL_2
|
||||
if (Serial2.baudRate() != baud_rate) {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
Serial2.begin (baud_rate);
|
||||
Serial2.begin (baud_rate);
|
||||
#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
|
||||
@ -237,7 +240,7 @@ void CONFIG::esp_restart (bool async)
|
||||
delay (1000);
|
||||
}
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
//ESP8266 has only serial
|
||||
//ESP8266 has only serial
|
||||
Serial.swap();
|
||||
#endif
|
||||
ESP.restart();
|
||||
@ -248,20 +251,23 @@ void CONFIG::esp_restart (bool async)
|
||||
};
|
||||
}
|
||||
#ifdef DHT_FEATURE
|
||||
void CONFIG::InitDHT(bool refresh) {
|
||||
void CONFIG::InitDHT(bool refresh)
|
||||
{
|
||||
if (!refresh) {
|
||||
byte bflag = DEFAULT_DHT_TYPE;
|
||||
int ibuf = DEFAULT_DHT_INTERVAL;
|
||||
int ibuf = DEFAULT_DHT_INTERVAL;
|
||||
if (!CONFIG::read_byte (EP_DHT_TYPE, &bflag ) ) {
|
||||
bflag = DEFAULT_DHT_TYPE;
|
||||
}
|
||||
CONFIG::DHT_type = bflag;
|
||||
if (!CONFIG::read_buffer (EP_DHT_INTERVAL, (byte *) &ibuf, INTEGER_LENGTH) ) {
|
||||
ibuf = DEFAULT_DHT_INTERVAL;
|
||||
}
|
||||
CONFIG::DHT_interval = ibuf;
|
||||
if (!CONFIG::read_buffer (EP_DHT_INTERVAL, (byte *) &ibuf, INTEGER_LENGTH) ) {
|
||||
ibuf = DEFAULT_DHT_INTERVAL;
|
||||
}
|
||||
CONFIG::DHT_interval = ibuf;
|
||||
}
|
||||
if (CONFIG::DHT_type != 255) {
|
||||
dht.setup(ESP_DHT_PIN,(DHTesp::DHT_MODEL_t)CONFIG::DHT_type); // Connect DHT sensor to GPIO ESP_DHT_PIN
|
||||
}
|
||||
if (CONFIG::DHT_type != 255) dht.setup(ESP_DHT_PIN,(DHTesp::DHT_MODEL_t)CONFIG::DHT_type); // Connect DHT sensor to GPIO ESP_DHT_PIN
|
||||
}
|
||||
#endif
|
||||
void CONFIG::InitPins()
|
||||
@ -299,13 +305,13 @@ void CONFIG::init_time_client()
|
||||
configTime (3600 * (t1), d1 * 3600, s1.c_str(), s2.c_str(), s3.c_str() );
|
||||
time_t now = time(nullptr);
|
||||
if (WiFi.getMode() == WIFI_STA) {
|
||||
int nb = 0;
|
||||
while ((now < 8 * 3600 * 2) && (nb < 6)) {
|
||||
wait(500);
|
||||
nb++;
|
||||
now = time(nullptr);
|
||||
}
|
||||
}
|
||||
int nb = 0;
|
||||
while ((now < 8 * 3600 * 2) && (nb < 6)) {
|
||||
wait(500);
|
||||
nb++;
|
||||
now = time(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#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_buffer[0]='E';
|
||||
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);
|
||||
}
|
||||
|
||||
uint8_t CONFIG::get_EEPROM_version(){
|
||||
uint8_t CONFIG::get_EEPROM_version()
|
||||
{
|
||||
byte byte_buffer[6];
|
||||
long baud_rate;
|
||||
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) return EEPROM_V0;
|
||||
if ((byte_buffer[0]=='E') && (byte_buffer[1]=='S') && (byte_buffer[2]=='P')&& (byte_buffer[3]=='3') && (byte_buffer[4]=='D')){
|
||||
if (!CONFIG::read_buffer (EP_EEPROM_VERSION, byte_buffer, 6)) {
|
||||
return EEPROM_V0;
|
||||
}
|
||||
if ((byte_buffer[0]=='E') && (byte_buffer[1]=='S') && (byte_buffer[2]=='P')&& (byte_buffer[3]=='3') && (byte_buffer[4]=='D')) {
|
||||
return byte_buffer[5];
|
||||
}
|
||||
|
||||
|
||||
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 ) ) {
|
||||
return EEPROM_V1;
|
||||
}
|
||||
return EEPROM_V0;
|
||||
}
|
||||
|
||||
bool CONFIG::adjust_EEPROM_settings(){
|
||||
bool CONFIG::adjust_EEPROM_settings()
|
||||
{
|
||||
uint8_t v = get_EEPROM_version();
|
||||
bool bdone =false;
|
||||
if (v == EEPROM_CURRENT_VERSION) return true;
|
||||
if (v == EEPROM_CURRENT_VERSION) {
|
||||
return true;
|
||||
}
|
||||
if (v == 1) {
|
||||
bdone =true;
|
||||
#ifdef SDCARD_FEATURE
|
||||
@ -545,16 +558,16 @@ bool CONFIG::adjust_EEPROM_settings(){
|
||||
if (!CONFIG::write_buffer (EP_DHT_INTERVAL, (const byte *) &DEFAULT_DHT_INTERVAL, INTEGER_LENGTH) ) {
|
||||
bdone =false;
|
||||
}
|
||||
|
||||
|
||||
if (!CONFIG::write_byte (EP_DHT_TYPE, DEFAULT_DHT_TYPE) ) {
|
||||
bdone =false;
|
||||
}
|
||||
#endif
|
||||
if (!CONFIG::write_byte (EP_OUTPUT_FLAG, DEFAULT_OUTPUT_FLAG) ) {
|
||||
if (!CONFIG::write_byte (EP_OUTPUT_FLAG, DEFAULT_OUTPUT_FLAG) ) {
|
||||
bdone =false;
|
||||
}
|
||||
}
|
||||
if (bdone){
|
||||
if (bdone) {
|
||||
set_EEPROM_version(EEPROM_CURRENT_VERSION);
|
||||
}
|
||||
return bdone;
|
||||
@ -696,12 +709,12 @@ bool CONFIG::write_string (int pos, const char * byte_buffer)
|
||||
LOG ("Error write string\r\n")
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!((pos == EP_STA_PASSWORD) || (pos == EP_AP_PASSWORD))) {
|
||||
if((size_buffer == 0 ) || (byte_buffer == NULL )){
|
||||
if((size_buffer == 0 ) || (byte_buffer == NULL )) {
|
||||
LOG ("Error write string\r\n")
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//copy the value(s)
|
||||
EEPROM.begin (EEPROM_SIZE);
|
||||
@ -817,11 +830,11 @@ bool CONFIG::reset_config()
|
||||
if (!CONFIG::write_buffer (EP_DATA_PORT, (const byte *) &DEFAULT_DATA_PORT, INTEGER_LENGTH) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!CONFIG::write_string (EP_HOSTNAME, wifi_config.get_default_hostname() ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!CONFIG::write_string (EP_ADMIN_PWD, FPSTR (DEFAULT_ADMIN_PWD) ) ) {
|
||||
return false;
|
||||
}
|
||||
@ -839,9 +852,9 @@ bool CONFIG::reset_config()
|
||||
|
||||
if (!CONFIG::write_byte (EP_TIME_ISDST, DEFAULT_TIME_DST) ) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -853,7 +866,7 @@ bool CONFIG::reset_config()
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (!CONFIG::write_byte (EP_OUTPUT_FLAG, DEFAULT_OUTPUT_FLAG) ) {
|
||||
return false;
|
||||
}
|
||||
@ -861,12 +874,12 @@ bool CONFIG::reset_config()
|
||||
if (!CONFIG::write_buffer (EP_DHT_INTERVAL, (const byte *) &DEFAULT_DHT_INTERVAL, INTEGER_LENGTH) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!CONFIG::write_byte (EP_DHT_TYPE, DEFAULT_DHT_TYPE) ) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
if (!CONFIG::write_byte (ESP_NOTIFICATION_TYPE, DEFAULT_NOTIFICATION_TYPE) ) {
|
||||
return false;
|
||||
@ -881,7 +894,7 @@ bool CONFIG::reset_config()
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return set_EEPROM_version(EEPROM_CURRENT_VERSION);
|
||||
}
|
||||
|
||||
@ -983,11 +996,10 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
||||
SPIFFS.info (info);
|
||||
//if higher than 1MB take out SPIFFS
|
||||
if (flashsize > 1024 * 1024) {
|
||||
flashsize = (1024 * 1024)-ESP.getSketchSize()-1024;
|
||||
}
|
||||
else {
|
||||
flashsize = flashsize - ESP.getSketchSize()-info.totalBytes-1024;
|
||||
}
|
||||
flashsize = (1024 * 1024)-ESP.getSketchSize()-1024;
|
||||
} else {
|
||||
flashsize = flashsize - ESP.getSketchSize()-info.totalBytes-1024;
|
||||
}
|
||||
ESPCOM::print(formatBytes(flashsize).c_str(), output, espresponse);
|
||||
if (!plaintext) {
|
||||
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);
|
||||
}
|
||||
uint32_t flashsize = ESP.getFlashChipSize();
|
||||
//Not OTA on 2Mb board per spec
|
||||
//Not OTA on 2Mb board per spec
|
||||
if (flashsize > 0x20000) {
|
||||
flashsize = 0x140000;
|
||||
} else {
|
||||
@ -1748,7 +1760,7 @@ void CONFIG::print_config (tpipe output, bool plaintext, ESPResponseStream *esp
|
||||
{
|
||||
ESPCOM::print (F ("\n"), output, espresponse);
|
||||
}
|
||||
//flag M117
|
||||
//flag M117
|
||||
if (!plaintext)
|
||||
{
|
||||
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);
|
||||
}
|
||||
#ifdef NOTIFICATION_FEATURE
|
||||
if (!plaintext)
|
||||
if (!plaintext)
|
||||
{
|
||||
ESPCOM::print (F ("\"Notifications\":\""), output, espresponse);
|
||||
} else
|
||||
@ -1795,7 +1807,7 @@ if (!plaintext)
|
||||
ESPCOM::print (F ("\n"), output, espresponse);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//Flag Oled
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
if (!plaintext)
|
||||
@ -1845,7 +1857,7 @@ if (!plaintext)
|
||||
{
|
||||
ESPCOM::print (F ("\n"), output, espresponse);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WS_DATA_FEATURE
|
||||
//flag websocket
|
||||
if (!plaintext)
|
||||
@ -1870,7 +1882,7 @@ if (!plaintext)
|
||||
{
|
||||
ESPCOM::print (F ("\n"), output, espresponse);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
//flag tcp
|
||||
if (!plaintext)
|
||||
@ -1933,11 +1945,11 @@ if (!plaintext)
|
||||
ESPCOM::print (F ("FW version: "), output, espresponse);
|
||||
}
|
||||
ESPCOM::print (FW_VERSION, output, espresponse);
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
ESPCOM::print (" ESP8266/8586", output, espresponse);
|
||||
#else
|
||||
ESPCOM::print (" ESP32", output, espresponse);
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
ESPCOM::print (" ESP8266/8586", output, espresponse);
|
||||
#else
|
||||
ESPCOM::print (" ESP32", output, espresponse);
|
||||
#endif
|
||||
if (!plaintext)
|
||||
{
|
||||
ESPCOM::print (F ("\"}"), output, espresponse);
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define ESP8266_MODEL_URL "http://espressif.com/en/products/esp8266/"
|
||||
#define ESP32_MODEL_NAME "ESP32"
|
||||
#define ESP32_MODEL_URL "https://www.espressif.com/en/products/hardware/esp-wroom-32/overview"
|
||||
#define ESP_MODEL_NUMBER "ESP3D 2.1"
|
||||
#define ESP_MODEL_NUMBER "ESP3D 2.1"
|
||||
#define ESP_MANUFACTURER_NAME "Espressif Systems"
|
||||
#define ESP_MANUFACTURER_URL "http://espressif.com"
|
||||
//default name if no mac address is valid
|
||||
@ -120,7 +120,7 @@
|
||||
#define ESP_DHT_PIN 2
|
||||
#endif
|
||||
|
||||
//Pins where the screen is connected
|
||||
//Pins where the screen is connected
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
#define OLED_DISPLAY_SSD1306 // OLED Display Type: SSD1306(OLED_DISPLAY_SSD1306) / SH1106(OLED_DISPLAY_SH1106), comment this line out to disable oled
|
||||
#define OLED_PIN_SDA 4 //5 //SDA; // i2c SDA Pin
|
||||
@ -502,13 +502,17 @@ const uint16_t Setting[][2] = {
|
||||
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
class AsyncResponseStream;
|
||||
typedef AsyncResponseStream ESPResponseStream;
|
||||
typedef AsyncResponseStream ESPResponseStream;
|
||||
#else
|
||||
class ESPResponseStream{
|
||||
public:
|
||||
bool header_sent;
|
||||
String buffer_web;
|
||||
ESPResponseStream(){header_sent=false;};
|
||||
class ESPResponseStream
|
||||
{
|
||||
public:
|
||||
bool header_sent;
|
||||
String buffer_web;
|
||||
ESPResponseStream()
|
||||
{
|
||||
header_sent=false;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
192
esp3d/esp3d.cpp
192
esp3d/esp3d.cpp
@ -77,7 +77,7 @@ extern DNSServer dnsServer;
|
||||
#ifdef DHT_FEATURE
|
||||
#include "DHTesp.h"
|
||||
DHTesp dht;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
#include "asyncwebserver.h"
|
||||
@ -86,8 +86,9 @@ DHTesp dht;
|
||||
#endif
|
||||
|
||||
//Contructor
|
||||
Esp3D::Esp3D() {
|
||||
|
||||
Esp3D::Esp3D()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Begin which setup everything
|
||||
@ -111,7 +112,7 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
struct rst_info *rtc_info = system_get_rst_info();
|
||||
#else
|
||||
#else
|
||||
RESET_REASON reason_0 = rtc_get_reset_reason(0);
|
||||
RESET_REASON reason_1 = rtc_get_reset_reason(1);
|
||||
#endif
|
||||
@ -122,18 +123,18 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
|
||||
#endif
|
||||
|
||||
#ifdef MKS_TFT_FEATURE
|
||||
startdelayms = 1000;
|
||||
startdelayms = 1000;
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
uint32_t start_display_time = millis();
|
||||
uint32_t now = millis();
|
||||
while ( now - start_display_time < startdelayms){
|
||||
int v = (100 * (millis() - start_display_time)) / startdelayms;
|
||||
OLED_DISPLAY::display_mini_progress(v);
|
||||
OLED_DISPLAY::update_lcd();
|
||||
delay(100);
|
||||
now = millis();
|
||||
}
|
||||
uint32_t start_display_time = millis();
|
||||
uint32_t now = millis();
|
||||
while ( now - start_display_time < startdelayms) {
|
||||
int v = (100 * (millis() - start_display_time)) / startdelayms;
|
||||
OLED_DISPLAY::display_mini_progress(v);
|
||||
OLED_DISPLAY::update_lcd();
|
||||
delay(100);
|
||||
now = millis();
|
||||
}
|
||||
#else
|
||||
delay (startdelayms);
|
||||
#endif
|
||||
@ -191,19 +192,19 @@ void Esp3D::begin(uint16_t startdelayms, uint16_t recoverydelayms)
|
||||
SPIFFS.begin();
|
||||
#endif
|
||||
//basic autostart
|
||||
if(SPIFFS.exists("/autostart.g")){
|
||||
FS_FILE file = SPIFFS.open("/autostart.g", SPIFFS_FILE_READ);
|
||||
if (file){
|
||||
String autoscript = file.readString();
|
||||
if (autoscript.length() > 0){
|
||||
//clean line
|
||||
autoscript.replace("\n","");
|
||||
autoscript.replace("\r","");
|
||||
ESPCOM::println (autoscript.c_str(), DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
if(SPIFFS.exists("/autostart.g")) {
|
||||
FS_FILE file = SPIFFS.open("/autostart.g", SPIFFS_FILE_READ);
|
||||
if (file) {
|
||||
String autoscript = file.readString();
|
||||
if (autoscript.length() > 0) {
|
||||
//clean line
|
||||
autoscript.replace("\n","");
|
||||
autoscript.replace("\r","");
|
||||
ESPCOM::println (autoscript.c_str(), DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
//setup wifi according settings
|
||||
if (!wifi_config.Setup() ) {
|
||||
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() ) {
|
||||
ESPCOM::println (F ("Error enabling servers"), PRINTER_PIPE);
|
||||
}
|
||||
/*#ifdef ARDUINO_ARCH_ESP8266
|
||||
if (rtc_info->reason == REASON_WDT_RST ||
|
||||
/*#ifdef ARDUINO_ARCH_ESP8266
|
||||
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) {
|
||||
String s = "reset ";
|
||||
s+= String(rtc_info->reason);
|
||||
|
||||
if (rtc_info->reason == REASON_EXCEPTION_RST) {
|
||||
s+=" except ";
|
||||
s+=String(rtc_info->exccause);
|
||||
rtc_info->reason == REASON_SOFT_WDT_RST) {
|
||||
String s = "reset ";
|
||||
s+= String(rtc_info->reason);
|
||||
|
||||
}
|
||||
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))))
|
||||
{
|
||||
String s = "reset ";
|
||||
ESPCOM::println (s, PRINTER_PIPE);
|
||||
s+=String(reason_0);
|
||||
s+="/";
|
||||
s+=String(reason_1);
|
||||
|
||||
}
|
||||
#endif*/
|
||||
if (rtc_info->reason == REASON_EXCEPTION_RST) {
|
||||
s+=" except ";
|
||||
s+=String(rtc_info->exccause);
|
||||
|
||||
}
|
||||
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))))
|
||||
{
|
||||
String s = "reset ";
|
||||
ESPCOM::println (s, PRINTER_PIPE);
|
||||
s+=String(reason_0);
|
||||
s+="/";
|
||||
s+=String(reason_1);
|
||||
|
||||
}
|
||||
#endif*/
|
||||
|
||||
#ifdef ASYNCWEBSERVER
|
||||
if (WiFi.getMode() != WIFI_AP) {
|
||||
@ -269,66 +270,77 @@ void Esp3D::process()
|
||||
dnsServer.processNextRequest();
|
||||
}
|
||||
#endif
|
||||
//TODO use config
|
||||
CONFIG::wait(0);
|
||||
//TODO use config
|
||||
CONFIG::wait(0);
|
||||
}
|
||||
//read / bridge all input
|
||||
ESPCOM::bridge();
|
||||
ESPCOM::bridge();
|
||||
//in case of restart requested
|
||||
if (web_interface->restartmodule) {
|
||||
CONFIG::esp_restart();
|
||||
}
|
||||
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
static uint32_t last_oled_update= 0;
|
||||
if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)){
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
static uint32_t last_oled_update= 0;
|
||||
if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
uint32_t now_oled = millis();
|
||||
if (now_oled - last_oled_update > 1000) {
|
||||
last_oled_update = now_oled;
|
||||
//refresh signal
|
||||
if ((WiFi.getMode() == WIFI_OFF) || !wifi_config.WiFi_on) OLED_DISPLAY::display_signal(-1);
|
||||
else OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
if ((WiFi.getMode() == WIFI_OFF) || !wifi_config.WiFi_on) {
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
} else {
|
||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
}
|
||||
//if line 0 is > 85 refresh
|
||||
if(OLED_DISPLAY::L0_size >85)OLED_DISPLAY::display_text(OLED_DISPLAY::L0.c_str(), 0, 0, 85);
|
||||
if(OLED_DISPLAY::L0_size >85) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L0.c_str(), 0, 0, 85);
|
||||
}
|
||||
//if line 1 is > 128 refresh
|
||||
if(OLED_DISPLAY::L1_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L1.c_str(), 0, 16, 128);
|
||||
if(OLED_DISPLAY::L1_size >128) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L1.c_str(), 0, 16, 128);
|
||||
}
|
||||
//if line 2 is > 128 refresh
|
||||
if(OLED_DISPLAY::L2_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L2.c_str(), 0, 32, 128);
|
||||
if(OLED_DISPLAY::L2_size >128) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L2.c_str(), 0, 32, 128);
|
||||
}
|
||||
//if line 3 is > 128 refresh
|
||||
if(OLED_DISPLAY::L3_size >128) OLED_DISPLAY::display_text(OLED_DISPLAY::L3.c_str(), 0, 48, 128);
|
||||
if(OLED_DISPLAY::L3_size >128) {
|
||||
OLED_DISPLAY::display_text(OLED_DISPLAY::L3.c_str(), 0, 48, 128);
|
||||
}
|
||||
OLED_DISPLAY::update_lcd();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DHT_FEATURE
|
||||
if (CONFIG::DHT_type != 255) {
|
||||
static uint32_t last_dht_update= 0;
|
||||
uint32_t now_dht = millis();
|
||||
if (now_dht - last_dht_update > (CONFIG::DHT_interval * 1000)) {
|
||||
last_dht_update = now_dht;
|
||||
float humidity = dht.getHumidity();
|
||||
float temperature = dht.getTemperature();
|
||||
if (strcmp(dht.getStatusString(),"OK") == 0) {
|
||||
String s = String(temperature,2);
|
||||
String s2 = s + " " +String(humidity,2);
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
web_interface->web_events.send( s2.c_str(),"DHT", millis());
|
||||
#else
|
||||
s = "DHT:" + s2;
|
||||
socket_server->sendTXT(ESPCOM::current_socket_id, s);
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)){
|
||||
s = String(temperature,2);
|
||||
s +="°C";
|
||||
OLED_DISPLAY::display_text(s.c_str(), 84, 16);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CONFIG::DHT_type != 255) {
|
||||
static uint32_t last_dht_update= 0;
|
||||
uint32_t now_dht = millis();
|
||||
if (now_dht - last_dht_update > (CONFIG::DHT_interval * 1000)) {
|
||||
last_dht_update = now_dht;
|
||||
float humidity = dht.getHumidity();
|
||||
float temperature = dht.getTemperature();
|
||||
if (strcmp(dht.getStatusString(),"OK") == 0) {
|
||||
String s = String(temperature,2);
|
||||
String s2 = s + " " +String(humidity,2);
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
web_interface->web_events.send( s2.c_str(),"DHT", millis());
|
||||
#else
|
||||
s = "DHT:" + s2;
|
||||
socket_server->sendTXT(ESPCOM::current_socket_id, s);
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
if ( !CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
s = String(temperature,2);
|
||||
s +="°C";
|
||||
OLED_DISPLAY::display_text(s.c_str(), 84, 16);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//todo use config
|
||||
CONFIG::wait(0);
|
||||
CONFIG::wait(0);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "Arduino.h"
|
||||
class Esp3D
|
||||
{
|
||||
public:
|
||||
public:
|
||||
Esp3D();
|
||||
void begin(uint16_t startdelayms = 8000, uint16_t recoverydelayms = 8000);
|
||||
void process();
|
||||
|
@ -25,133 +25,150 @@
|
||||
|
||||
// Initialize the OLED display using I2C
|
||||
#ifdef OLED_DISPLAY_SSD1306
|
||||
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
|
||||
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
|
||||
#elif defined OLED_DISPLAY_SH1106
|
||||
#include "SH1106.h" // alias for `#include "SH1106Wire.h"`
|
||||
#include "SH1106.h" // alias for `#include "SH1106Wire.h"`
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef OLED_DISPLAY_SSD1306
|
||||
SSD1306 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
|
||||
SSD1306 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
|
||||
#elif defined OLED_DISPLAY_SH1106
|
||||
SH1106 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
|
||||
SH1106 esp_display(OLED_ADDR, OLED_PIN_SDA, OLED_PIN_SCL);
|
||||
#endif
|
||||
|
||||
|
||||
#define ESP3D_Logo_width 62
|
||||
#define ESP3D_Logo_height 45
|
||||
const char ESP3D_Logo[] = {
|
||||
0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF8, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
||||
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
|
||||
0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xC0, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x80, 0x01,
|
||||
0xF0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x03, 0xF8, 0xFF, 0xFF, 0xFF,
|
||||
0x07, 0x00, 0x00, 0x06, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x0C,
|
||||
0x0C, 0x7C, 0x78, 0xC0, 0xC1, 0xC1, 0x0F, 0x18, 0x06, 0x38, 0x60, 0x80,
|
||||
0xE1, 0xC3, 0x3F, 0x10, 0xC6, 0x19, 0x67, 0x1C, 0xF1, 0xC7, 0x7F, 0x10,
|
||||
0xC6, 0x1F, 0x7F, 0x3C, 0x31, 0xCF, 0xF1, 0x10, 0xC7, 0x1F, 0x7F, 0x3C,
|
||||
0x01, 0xCE, 0xE1, 0x20, 0xC7, 0x3F, 0x7E, 0x1C, 0x01, 0xC7, 0xC1, 0x21,
|
||||
0x07, 0x3C, 0x78, 0x80, 0xE1, 0xC3, 0xC1, 0x21, 0x07, 0xFC, 0x70, 0xC0,
|
||||
0xE1, 0xC7, 0xC1, 0x21, 0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCF, 0xC1, 0x21,
|
||||
0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCE, 0xC1, 0x21, 0xC7, 0xDF, 0x63, 0xFC,
|
||||
0x01, 0xCE, 0xE1, 0x20, 0xC6, 0x99, 0x73, 0xFC, 0x31, 0xCF, 0x7F, 0x10,
|
||||
0x06, 0x18, 0x70, 0xFC, 0xF0, 0xC7, 0x3F, 0x10, 0x0E, 0x78, 0x78, 0xFC,
|
||||
0xE0, 0xC3, 0x0F, 0x10, 0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x18,
|
||||
0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0xFF, 0xFF, 0x3F,
|
||||
0x00, 0x00, 0x00, 0x06, 0xF0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
||||
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x07, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF,
|
||||
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00
|
||||
};
|
||||
0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF8, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
||||
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
|
||||
0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0xC0, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x80, 0x01,
|
||||
0xF0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x03, 0xF8, 0xFF, 0xFF, 0xFF,
|
||||
0x07, 0x00, 0x00, 0x06, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x0C,
|
||||
0x0C, 0x7C, 0x78, 0xC0, 0xC1, 0xC1, 0x0F, 0x18, 0x06, 0x38, 0x60, 0x80,
|
||||
0xE1, 0xC3, 0x3F, 0x10, 0xC6, 0x19, 0x67, 0x1C, 0xF1, 0xC7, 0x7F, 0x10,
|
||||
0xC6, 0x1F, 0x7F, 0x3C, 0x31, 0xCF, 0xF1, 0x10, 0xC7, 0x1F, 0x7F, 0x3C,
|
||||
0x01, 0xCE, 0xE1, 0x20, 0xC7, 0x3F, 0x7E, 0x1C, 0x01, 0xC7, 0xC1, 0x21,
|
||||
0x07, 0x3C, 0x78, 0x80, 0xE1, 0xC3, 0xC1, 0x21, 0x07, 0xFC, 0x70, 0xC0,
|
||||
0xE1, 0xC7, 0xC1, 0x21, 0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCF, 0xC1, 0x21,
|
||||
0xC7, 0xFF, 0x63, 0xFC, 0x01, 0xCE, 0xC1, 0x21, 0xC7, 0xDF, 0x63, 0xFC,
|
||||
0x01, 0xCE, 0xE1, 0x20, 0xC6, 0x99, 0x73, 0xFC, 0x31, 0xCF, 0x7F, 0x10,
|
||||
0x06, 0x18, 0x70, 0xFC, 0xF0, 0xC7, 0x3F, 0x10, 0x0E, 0x78, 0x78, 0xFC,
|
||||
0xE0, 0xC3, 0x0F, 0x10, 0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x18,
|
||||
0xFC, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0xFF, 0xFF, 0x3F,
|
||||
0x00, 0x00, 0x00, 0x06, 0xF0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF,
|
||||
0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x07, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF,
|
||||
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x1F, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void OLED_DISPLAY::splash(){
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo);
|
||||
update_lcd();
|
||||
void OLED_DISPLAY::splash()
|
||||
{
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
esp_display.drawXbm(33, 10, ESP3D_Logo_width, ESP3D_Logo_height, ESP3D_Logo);
|
||||
update_lcd();
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::begin(){
|
||||
//For Embeded OLED on Wifi kit 32
|
||||
void OLED_DISPLAY::begin()
|
||||
{
|
||||
//For Embeded OLED on Wifi kit 32
|
||||
#if HELTEC_EMBEDDED_PIN > 0
|
||||
pinMode(HELTEC_EMBEDDED_PIN,OUTPUT);
|
||||
digitalWrite(HELTEC_EMBEDDED_PIN, LOW); // turn the LED on (HIGH is the voltage level)
|
||||
delay(100); // wait for a second
|
||||
digitalWrite(HELTEC_EMBEDDED_PIN, HIGH); // turn the LED off by making the voltage LOW
|
||||
#endif
|
||||
pinMode(HELTEC_EMBEDDED_PIN,OUTPUT);
|
||||
digitalWrite(HELTEC_EMBEDDED_PIN, LOW); // turn the LED on (HIGH is the voltage level)
|
||||
delay(100); // wait for a second
|
||||
digitalWrite(HELTEC_EMBEDDED_PIN, HIGH); // turn the LED off by making the voltage LOW
|
||||
#endif
|
||||
esp_display.init();
|
||||
esp_display.clear();
|
||||
#if OLED_FLIP_VERTICALY
|
||||
#if OLED_FLIP_VERTICALY
|
||||
esp_display.flipScreenVertically();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::setCursor(int col, int row){
|
||||
if (col!=-1) OLED_DISPLAY::col = col;
|
||||
if (row!=-1) OLED_DISPLAY::row = row;
|
||||
void OLED_DISPLAY::setCursor(int col, int row)
|
||||
{
|
||||
if (col!=-1) {
|
||||
OLED_DISPLAY::col = col;
|
||||
}
|
||||
if (row!=-1) {
|
||||
OLED_DISPLAY::row = row;
|
||||
}
|
||||
}
|
||||
void OLED_DISPLAY::print(String & s){
|
||||
OLED_DISPLAY::print(s.c_str());
|
||||
void OLED_DISPLAY::print(String & s)
|
||||
{
|
||||
OLED_DISPLAY::print(s.c_str());
|
||||
}
|
||||
void OLED_DISPLAY::print(const char * s){
|
||||
display_text(s, col, row);
|
||||
void OLED_DISPLAY::print(const char * s)
|
||||
{
|
||||
display_text(s, col, row);
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::display_signal(int value, int x, int y) {
|
||||
if(CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::display_signal(int value, int x, int y)
|
||||
{
|
||||
if(CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
//clear area only
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, x + 46, 16);
|
||||
esp_display.setColor(WHITE);
|
||||
if (value == -1){
|
||||
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
esp_display.drawString(x+20, y, "X");
|
||||
|
||||
} else {
|
||||
if (value > 0) {
|
||||
esp_display.fillRect(x, y + 6, 3, 4);
|
||||
} else {
|
||||
esp_display.drawRect(x, y + 6, 3, 4);
|
||||
}
|
||||
|
||||
if (value >= 25) {
|
||||
esp_display.fillRect(x + 4, y + 4, 3, 6);
|
||||
} else {
|
||||
esp_display.drawRect(x + 4, y + 4, 3, 6);
|
||||
}
|
||||
|
||||
if (value >= 50) {
|
||||
esp_display.fillRect(x + 8, y + 2, 3, 8);
|
||||
} else {
|
||||
esp_display.drawRect(x + 8, y + 2, 3, 8);
|
||||
}
|
||||
|
||||
if (value >= 75) {
|
||||
esp_display.fillRect(x + 12, y, 3, 10);
|
||||
} else {
|
||||
esp_display.drawRect(x + 12, y, 3, 10);
|
||||
}
|
||||
if (value == -1) {
|
||||
|
||||
String s = CONFIG::intTostr (value);
|
||||
s+="%";
|
||||
//set current font size
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
esp_display.drawString(x+16, y, s.c_str());
|
||||
}
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
esp_display.drawString(x+20, y, "X");
|
||||
|
||||
} else {
|
||||
if (value > 0) {
|
||||
esp_display.fillRect(x, y + 6, 3, 4);
|
||||
} else {
|
||||
esp_display.drawRect(x, y + 6, 3, 4);
|
||||
}
|
||||
|
||||
if (value >= 25) {
|
||||
esp_display.fillRect(x + 4, y + 4, 3, 6);
|
||||
} else {
|
||||
esp_display.drawRect(x + 4, y + 4, 3, 6);
|
||||
}
|
||||
|
||||
if (value >= 50) {
|
||||
esp_display.fillRect(x + 8, y + 2, 3, 8);
|
||||
} else {
|
||||
esp_display.drawRect(x + 8, y + 2, 3, 8);
|
||||
}
|
||||
|
||||
if (value >= 75) {
|
||||
esp_display.fillRect(x + 12, y, 3, 10);
|
||||
} else {
|
||||
esp_display.drawRect(x + 12, y, 3, 10);
|
||||
}
|
||||
|
||||
String s = CONFIG::intTostr (value);
|
||||
s+="%";
|
||||
//set current font size
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
esp_display.drawString(x+16, y, s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OLED_DISPLAY::display_progress(int value, int x, int y) {
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::display_progress(int value, int x, int y)
|
||||
{
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, x + 128, 16);
|
||||
@ -161,72 +178,75 @@ void OLED_DISPLAY::display_progress(int value, int x, int y) {
|
||||
esp_display.drawString(x+102, y - 1, p.c_str());
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w) {
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
void OLED_DISPLAY::display_mini_progress(int value, int x, int y, int w)
|
||||
{
|
||||
if ( CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, x + w, 2);
|
||||
esp_display.setColor(WHITE);
|
||||
esp_display.drawRect(x , y, value, 2);
|
||||
esp_display.drawRect(x, y, value, 2);
|
||||
}
|
||||
|
||||
//max is 128 by default but can be 85 for first line
|
||||
|
||||
void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max) {
|
||||
void OLED_DISPLAY::display_text(const char * txt, int x, int y, int max)
|
||||
{
|
||||
static int shift_pos[4] = {-1, -1, -1, -1};
|
||||
static int t[4] = {0, 0, 0, 0};
|
||||
|
||||
|
||||
int p = 0;
|
||||
if (y==16) {
|
||||
OLED_DISPLAY::L1 = txt;
|
||||
OLED_DISPLAY::L1_size = esp_display.getStringWidth( txt);
|
||||
p=1;
|
||||
}
|
||||
else if (y==32){
|
||||
OLED_DISPLAY::L2 = txt;
|
||||
OLED_DISPLAY::L2_size = esp_display.getStringWidth( txt);
|
||||
p=2;
|
||||
}
|
||||
else if (y==0){
|
||||
max = 85;
|
||||
OLED_DISPLAY::L0 = txt;
|
||||
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
|
||||
p=0;
|
||||
}
|
||||
else{
|
||||
OLED_DISPLAY::L3 = txt;
|
||||
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
|
||||
p=3;
|
||||
}
|
||||
OLED_DISPLAY::L1 = txt;
|
||||
OLED_DISPLAY::L1_size = esp_display.getStringWidth( txt);
|
||||
p=1;
|
||||
} else if (y==32) {
|
||||
OLED_DISPLAY::L2 = txt;
|
||||
OLED_DISPLAY::L2_size = esp_display.getStringWidth( txt);
|
||||
p=2;
|
||||
} else if (y==0) {
|
||||
max = 85;
|
||||
OLED_DISPLAY::L0 = txt;
|
||||
OLED_DISPLAY::L0_size = esp_display.getStringWidth( txt);
|
||||
p=0;
|
||||
} else {
|
||||
OLED_DISPLAY::L3 = txt;
|
||||
OLED_DISPLAY::L3_size = esp_display.getStringWidth( txt);
|
||||
p=3;
|
||||
}
|
||||
esp_display.setFont(ArialMT_Plain_10);
|
||||
//clear area only
|
||||
//clear area only
|
||||
esp_display.setColor(BLACK);
|
||||
esp_display.fillRect(x, y, max, 16);
|
||||
esp_display.setColor(WHITE);
|
||||
esp_display.setColor(WHITE);
|
||||
String Stxt = txt;
|
||||
Stxt += " ";
|
||||
(t[p])++;
|
||||
if ((esp_display.getStringWidth( Stxt) > max) && (t[p] > 1)) {
|
||||
(shift_pos[p]) ++;
|
||||
String s2 = Stxt.substring(shift_pos[p]);
|
||||
Stxt = s2;
|
||||
if (esp_display.getStringWidth( s2) < max) {
|
||||
//reset for next time
|
||||
shift_pos[p] = -1;
|
||||
t[p] = 0;
|
||||
(shift_pos[p]) ++;
|
||||
String s2 = Stxt.substring(shift_pos[p]);
|
||||
Stxt = s2;
|
||||
if (esp_display.getStringWidth( s2) < max) {
|
||||
//reset for next time
|
||||
shift_pos[p] = -1;
|
||||
t[p] = 0;
|
||||
}
|
||||
}
|
||||
//be sure we stay in boundaries
|
||||
while (esp_display.getStringWidth(Stxt) > max){
|
||||
Stxt.remove(Stxt.length()-1, 1);
|
||||
}
|
||||
while (esp_display.getStringWidth(Stxt) > max) {
|
||||
Stxt.remove(Stxt.length()-1, 1);
|
||||
}
|
||||
esp_display.drawString(x, y, Stxt.c_str());
|
||||
}
|
||||
|
||||
void OLED_DISPLAY::update_lcd(){
|
||||
esp_display.display();
|
||||
void OLED_DISPLAY::update_lcd()
|
||||
{
|
||||
esp_display.display();
|
||||
}
|
||||
void OLED_DISPLAY::clear_lcd(){
|
||||
esp_display.clear();
|
||||
void OLED_DISPLAY::clear_lcd()
|
||||
{
|
||||
esp_display.clear();
|
||||
}
|
||||
int OLED_DISPLAY::col = 0;
|
||||
int OLED_DISPLAY::row = 0;
|
||||
|
@ -25,28 +25,28 @@
|
||||
class OLED_DISPLAY
|
||||
{
|
||||
public:
|
||||
static void begin();
|
||||
static void setCursor(int col, int row = -1);
|
||||
static void print(String & s);
|
||||
static void print(const char * s);
|
||||
static void display_signal( int value, int x=86, int y=0);
|
||||
static void display_text(const char * txt, int x=0, int y=48, int max=128);
|
||||
static void display_progress(int value, int x=0, int y=48);
|
||||
static void display_mini_progress(int value, int x = 14, int y=61, int w=100);
|
||||
static void update_lcd();
|
||||
static void clear_lcd();
|
||||
static void splash();
|
||||
static String L0;
|
||||
static String L1;
|
||||
static String L2;
|
||||
static String L3;
|
||||
static int L0_size;
|
||||
static int L1_size;
|
||||
static int L2_size;
|
||||
static int L3_size;
|
||||
static void begin();
|
||||
static void setCursor(int col, int row = -1);
|
||||
static void print(String & s);
|
||||
static void print(const char * s);
|
||||
static void display_signal( int value, int x=86, int y=0);
|
||||
static void display_text(const char * txt, int x=0, int y=48, int max=128);
|
||||
static void display_progress(int value, int x=0, int y=48);
|
||||
static void display_mini_progress(int value, int x = 14, int y=61, int w=100);
|
||||
static void update_lcd();
|
||||
static void clear_lcd();
|
||||
static void splash();
|
||||
static String L0;
|
||||
static String L1;
|
||||
static String L2;
|
||||
static String L3;
|
||||
static int L0_size;
|
||||
static int L1_size;
|
||||
static int L2_size;
|
||||
static int L3_size;
|
||||
private:
|
||||
static int col;
|
||||
static int row;
|
||||
static int col;
|
||||
static int row;
|
||||
|
||||
|
||||
};
|
||||
|
215
esp3d/espcom.cpp
215
esp3d/espcom.cpp
@ -30,7 +30,7 @@
|
||||
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
#include "esp_oled.h"
|
||||
bool ESPCOM::block_2_oled = false;
|
||||
bool ESPCOM::block_2_oled = false;
|
||||
#endif
|
||||
|
||||
uint8_t ESPCOM::current_socket_id=0;
|
||||
@ -45,25 +45,25 @@ bool ESPCOM::block_2_printer = false;
|
||||
void ESPCOM::bridge(bool async)
|
||||
{
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
if(can_process_serial) {
|
||||
if(can_process_serial) {
|
||||
#endif
|
||||
//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
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
ESPCOM::processFromTCP2Serial();
|
||||
ESPCOM::processFromTCP2Serial();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
//read serial input
|
||||
ESPCOM::processFromSerial();
|
||||
ESPCOM::processFromSerial();
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
long ESPCOM::readBytes (tpipe output, uint8_t * sbuf, size_t len)
|
||||
{
|
||||
switch (output) {
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
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);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
long ESPCOM::baudRate(tpipe output)
|
||||
{
|
||||
long br = 0;
|
||||
switch (output) {
|
||||
long br = 0;
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
br = Serial.baudRate();
|
||||
@ -103,10 +103,10 @@ long ESPCOM::baudRate(tpipe output)
|
||||
br = Serial2.baudRate();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
//workaround for ESP32
|
||||
if (br == 115201) {
|
||||
@ -116,10 +116,11 @@ long ESPCOM::baudRate(tpipe output)
|
||||
br = 230400;
|
||||
}
|
||||
#endif
|
||||
return br;
|
||||
return br;
|
||||
}
|
||||
size_t ESPCOM::available(tpipe output){
|
||||
switch (output) {
|
||||
size_t ESPCOM::available(tpipe output)
|
||||
{
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
return Serial.available();
|
||||
@ -135,15 +136,20 @@ size_t ESPCOM::available(tpipe output){
|
||||
return Serial2.available();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
size_t ESPCOM::write(tpipe output, uint8_t d){
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && (block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) return 0;
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL))return 0;
|
||||
switch (output) {
|
||||
size_t ESPCOM::write(tpipe output, uint8_t d)
|
||||
{
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && (block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) {
|
||||
return 0;
|
||||
}
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
|
||||
return 0;
|
||||
}
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
return Serial.write(d);
|
||||
@ -159,14 +165,14 @@ size_t ESPCOM::write(tpipe output, uint8_t d){
|
||||
return Serial2.write(d);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ESPCOM::flush (tpipe output, ESPResponseStream *espresponse)
|
||||
{
|
||||
switch (output) {
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
case SERIAL_PIPE:
|
||||
Serial.flush();
|
||||
@ -183,23 +189,23 @@ void ESPCOM::flush (tpipe output, ESPResponseStream *espresponse)
|
||||
break;
|
||||
#endif
|
||||
#if !defined (ASYNCWEBSERVER)
|
||||
case WEB_PIPE:
|
||||
if (espresponse) {
|
||||
if(espresponse->header_sent) {
|
||||
//send data
|
||||
web_interface->web_server.sendContent(espresponse->buffer_web);
|
||||
//close line
|
||||
web_interface->web_server.sendContent("");
|
||||
}
|
||||
espresponse->header_sent = false;
|
||||
espresponse->buffer_web = String();
|
||||
}
|
||||
case WEB_PIPE:
|
||||
if (espresponse) {
|
||||
if(espresponse->header_sent) {
|
||||
//send data
|
||||
web_interface->web_server.sendContent(espresponse->buffer_web);
|
||||
//close line
|
||||
web_interface->web_server.sendContent("");
|
||||
}
|
||||
espresponse->header_sent = false;
|
||||
espresponse->buffer_web = String();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && ( block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) return;
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL))return;
|
||||
if ((DEFAULT_PRINTER_PIPE == output) && ( block_2_printer || CONFIG::is_locked(FLAG_BLOCK_SERIAL))) {
|
||||
return;
|
||||
}
|
||||
if ((SERIAL_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_SERIAL)) {
|
||||
return;
|
||||
}
|
||||
#ifdef TCP_IP_DATA_FEATURE
|
||||
if ((TCP_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_TCP))return;
|
||||
if ((TCP_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_TCP)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef WS_DATA_FEATURE
|
||||
if ((WS_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_WSOCKET))return;
|
||||
if ((WS_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
if ((OLED_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_OLED))return;
|
||||
if ((OLED_PIPE == output) && CONFIG::is_locked(FLAG_BLOCK_OLED)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
switch (output) {
|
||||
#ifdef USE_SERIAL_0
|
||||
@ -248,61 +264,62 @@ void ESPCOM::print (const char * data, tpipe output, ESPResponseStream *espresp
|
||||
case WEB_PIPE:
|
||||
if (espresponse != NULL) {
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
espresponse->print (data);
|
||||
espresponse->print (data);
|
||||
#else
|
||||
if (!espresponse->header_sent) {
|
||||
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
web_interface->web_server.sendHeader("Content-Type","text/html");
|
||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||
web_interface->web_server.send(200);
|
||||
espresponse->header_sent = true;
|
||||
}
|
||||
espresponse->buffer_web+=data;
|
||||
if (espresponse->buffer_web.length() > 1200) {
|
||||
//send data
|
||||
web_interface->web_server.sendContent(espresponse->buffer_web);
|
||||
//reset buffer
|
||||
espresponse->buffer_web="";
|
||||
}
|
||||
if (!espresponse->header_sent) {
|
||||
web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
web_interface->web_server.sendHeader("Content-Type","text/html");
|
||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||
web_interface->web_server.send(200);
|
||||
espresponse->header_sent = true;
|
||||
}
|
||||
espresponse->buffer_web+=data;
|
||||
if (espresponse->buffer_web.length() > 1200) {
|
||||
//send data
|
||||
web_interface->web_server.sendContent(espresponse->buffer_web);
|
||||
//reset buffer
|
||||
espresponse->buffer_web="";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#ifdef WS_DATA_FEATURE
|
||||
case WS_PIPE:
|
||||
{
|
||||
case WS_PIPE: {
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
//Todo
|
||||
#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
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
case OLED_PIPE:
|
||||
{
|
||||
if (!ESPCOM::block_2_oled) {
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
|
||||
OLED_DISPLAY::print(data);
|
||||
OLED_DISPLAY::update_lcd();
|
||||
}
|
||||
}
|
||||
case OLED_PIPE: {
|
||||
if (!ESPCOM::block_2_oled) {
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
|
||||
OLED_DISPLAY::print(data);
|
||||
OLED_DISPLAY::update_lcd();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case PRINTER_PIPE:
|
||||
{
|
||||
case PRINTER_PIPE: {
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n")))ESPCOM::print(data, OLED_PIPE);
|
||||
#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);
|
||||
}
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
if(!(!strcmp(data,"\n")||!strcmp(data,"\r")||!strcmp(data,"\r\n"))) {
|
||||
ESPCOM::print(data, OLED_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:
|
||||
break;
|
||||
}
|
||||
@ -363,7 +380,7 @@ bool ESPCOM::processFromSerial (bool async)
|
||||
if (ESPCOM::available(DEFAULT_PRINTER_PIPE)) {
|
||||
size_t len = ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
if(!sbuf){
|
||||
if(!sbuf) {
|
||||
return false;
|
||||
}
|
||||
sbuf[len] = '\0';
|
||||
@ -382,13 +399,17 @@ bool ESPCOM::processFromSerial (bool async)
|
||||
}
|
||||
#endif
|
||||
#ifdef WS_DATA_FEATURE
|
||||
|
||||
|
||||
#if defined (ASYNCWEBSERVER)
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) web_interface->web_socket.textAll(sbuf, len);
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET)) {
|
||||
web_interface->web_socket.textAll(sbuf, len);
|
||||
}
|
||||
#else
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server)socket_server->sendBIN(current_socket_id,sbuf,len);
|
||||
if (!CONFIG::is_locked(FLAG_BLOCK_WSOCKET) && socket_server) {
|
||||
socket_server->sendBIN(current_socket_id,sbuf,len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
//process data if any
|
||||
COMMAND::read_buffer_serial (sbuf, len);
|
||||
|
@ -29,12 +29,12 @@ extern WiFiServer * data_server;
|
||||
class ESPCOM
|
||||
{
|
||||
public:
|
||||
static size_t write(tpipe output, uint8_t d);
|
||||
static long readBytes (tpipe output, uint8_t * sbuf, size_t len);
|
||||
static long baudRate(tpipe output);
|
||||
static size_t available(tpipe output);
|
||||
static void flush(tpipe output, ESPResponseStream *espresponse = NULL);
|
||||
static void bridge(bool async = false);
|
||||
static size_t write(tpipe output, uint8_t d);
|
||||
static long readBytes (tpipe output, uint8_t * sbuf, size_t len);
|
||||
static long baudRate(tpipe output);
|
||||
static size_t available(tpipe output);
|
||||
static void flush(tpipe output, ESPResponseStream *espresponse = NULL);
|
||||
static void bridge(bool async = false);
|
||||
static bool processFromSerial (bool async = false);
|
||||
static void print (const __FlashStringHelper *data, tpipe output, ESPResponseStream *espresponse = NULL);
|
||||
static void print (String & data, tpipe output, ESPResponseStream *espresponse = NULL);
|
||||
@ -47,11 +47,11 @@ public:
|
||||
static void processFromTCP2Serial();
|
||||
static void send2TCP (const __FlashStringHelper *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
|
||||
static bool block_2_printer;
|
||||
static bool block_2_printer;
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
static bool block_2_oled;
|
||||
static bool block_2_oled;
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
@ -310,11 +310,11 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
||||
//Email#serveraddress:port
|
||||
bool NotificationsService::getPortFromSettings()
|
||||
{
|
||||
String tmp ;
|
||||
String tmp ;
|
||||
char sbuf[MAX_DATA_LENGTH + 1];
|
||||
if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) {
|
||||
tmp = sbuf;
|
||||
}
|
||||
}
|
||||
int pos = tmp.lastIndexOf(':');
|
||||
if (pos == -1) {
|
||||
return false;
|
||||
@ -334,7 +334,7 @@ bool NotificationsService::getServerAddressFromSettings()
|
||||
char sbuf[MAX_DATA_LENGTH + 1];
|
||||
if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) {
|
||||
tmp = sbuf;
|
||||
}
|
||||
}
|
||||
int pos1 = tmp.indexOf('#');
|
||||
int pos2 = tmp.lastIndexOf(':');
|
||||
if ((pos1 == -1) || (pos2 == -1)) {
|
||||
@ -371,7 +371,7 @@ bool NotificationsService::begin()
|
||||
end();
|
||||
byte bbuf = 0;
|
||||
char sbuf[MAX_DATA_LENGTH + 1];
|
||||
if (CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &bbuf ) ){
|
||||
if (CONFIG::read_byte (ESP_NOTIFICATION_TYPE, &bbuf ) ) {
|
||||
_notificationType =bbuf;
|
||||
}
|
||||
switch(_notificationType) {
|
||||
@ -379,27 +379,27 @@ bool NotificationsService::begin()
|
||||
return true;
|
||||
case ESP_PUSHOVER_NOTIFICATION:
|
||||
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) ) {
|
||||
_token2 = sbuf;
|
||||
_token2 = sbuf;
|
||||
}
|
||||
_port = PUSHOVERPORT;
|
||||
_serveraddress = PUSHOVERSERVER;
|
||||
break;
|
||||
case ESP_LINE_NOTIFICATION:
|
||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||
_token1 = sbuf;
|
||||
_token1 = sbuf;
|
||||
}
|
||||
_port = LINEPORT;
|
||||
_serveraddress = LINESERVER;
|
||||
break;
|
||||
case ESP_EMAIL_NOTIFICATION:
|
||||
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) ) {
|
||||
_token2 = sbuf;
|
||||
_token2 = sbuf;
|
||||
}
|
||||
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN1));
|
||||
//log_esp3d("%s",Settings_ESP3D::read_string(ESP_NOTIFICATION_TOKEN2));
|
||||
|
@ -47,11 +47,11 @@
|
||||
#include "espcom.h"
|
||||
|
||||
#ifdef SSDP_FEATURE
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESP32SSDP.h>
|
||||
#else
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESP32SSDP.h>
|
||||
#else
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//embedded response file if no files on SPIFFS
|
||||
@ -59,42 +59,42 @@
|
||||
#include "syncwebserver.h"
|
||||
WebSocketsServer * socket_server;
|
||||
|
||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
|
||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length)
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
//USE_SERIAL.printf("[%u] Disconnected!\n", num);
|
||||
break;
|
||||
case WStype_CONNECTED:
|
||||
{
|
||||
IPAddress ip = socket_server->remoteIP(num);
|
||||
//USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
|
||||
String s = "CURRENT_ID:" + String(num);
|
||||
// send message to client
|
||||
ESPCOM::current_socket_id = num;
|
||||
socket_server->sendTXT(ESPCOM::current_socket_id, s);
|
||||
s = "ACTIVE_ID:" + String(ESPCOM::current_socket_id);
|
||||
socket_server->broadcastTXT(s);
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
//USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
|
||||
case WStype_DISCONNECTED:
|
||||
//USE_SERIAL.printf("[%u] Disconnected!\n", num);
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
IPAddress ip = socket_server->remoteIP(num);
|
||||
//USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
|
||||
String s = "CURRENT_ID:" + String(num);
|
||||
// send message to client
|
||||
ESPCOM::current_socket_id = num;
|
||||
socket_server->sendTXT(ESPCOM::current_socket_id, s);
|
||||
s = "ACTIVE_ID:" + String(ESPCOM::current_socket_id);
|
||||
socket_server->broadcastTXT(s);
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
//USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
|
||||
|
||||
// send message to client
|
||||
// webSocket.sendTXT(num, "message here");
|
||||
// send message to client
|
||||
// webSocket.sendTXT(num, "message here");
|
||||
|
||||
// send data to all connected clients
|
||||
// webSocket.broadcastTXT("message here");
|
||||
break;
|
||||
case WStype_BIN:
|
||||
//USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
|
||||
//hexdump(payload, length);
|
||||
// send data to all connected clients
|
||||
// webSocket.broadcastTXT("message here");
|
||||
break;
|
||||
case WStype_BIN:
|
||||
//USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
|
||||
//hexdump(payload, length);
|
||||
|
||||
// send message to client
|
||||
// webSocket.sendBIN(num, payload, length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
// send message to client
|
||||
// webSocket.sendBIN(num, payload, length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@ -121,7 +121,7 @@ void handle_web_interface_root()
|
||||
if(SPIFFS.exists(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);
|
||||
file.close();
|
||||
return;
|
||||
@ -148,7 +148,7 @@ void handle_login()
|
||||
if (pos!= -1) {
|
||||
int pos2 = cookie.indexOf(";",pos);
|
||||
sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2);
|
||||
}
|
||||
}
|
||||
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("Cache-Control","no-cache");
|
||||
@ -159,10 +159,15 @@ void handle_login()
|
||||
}
|
||||
|
||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||
if (auth_level == LEVEL_GUEST) auths = F("guest");
|
||||
else if (auth_level == LEVEL_USER) auths = F("user");
|
||||
else if (auth_level == LEVEL_ADMIN) auths = F("admin");
|
||||
else auths = F("???");
|
||||
if (auth_level == LEVEL_GUEST) {
|
||||
auths = F("guest");
|
||||
} else if (auth_level == LEVEL_USER) {
|
||||
auths = F("user");
|
||||
} else if (auth_level == LEVEL_ADMIN) {
|
||||
auths = F("admin");
|
||||
} else {
|
||||
auths = F("???");
|
||||
}
|
||||
|
||||
//check is it is a submission or a query
|
||||
if (web_interface->web_server.hasArg("SUBMIT")) {
|
||||
@ -207,12 +212,15 @@ void handle_login()
|
||||
String newpassword = web_interface->web_server.arg("NEWPASSWORD");
|
||||
if (CONFIG::isLocalPasswordValid(newpassword.c_str())) {
|
||||
int pos=0;
|
||||
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) pos = EP_ADMIN_PWD;
|
||||
else pos = EP_USER_PWD;
|
||||
if (!CONFIG::write_string(pos,newpassword.c_str())){
|
||||
msg_alert_error=true;
|
||||
smsg = F("Error: Cannot apply changes");
|
||||
code = 500;
|
||||
if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) {
|
||||
pos = EP_ADMIN_PWD;
|
||||
} else {
|
||||
pos = EP_USER_PWD;
|
||||
}
|
||||
if (!CONFIG::write_string(pos,newpassword.c_str())) {
|
||||
msg_alert_error=true;
|
||||
smsg = F("Error: Cannot apply changes");
|
||||
code = 500;
|
||||
}
|
||||
} else {
|
||||
msg_alert_error=true;
|
||||
@ -220,77 +228,79 @@ void handle_login()
|
||||
code = 500;
|
||||
}
|
||||
}
|
||||
if ((code == 200) || (code == 500)) {
|
||||
level_authenticate_type current_auth_level;
|
||||
if(sUser == FPSTR(DEFAULT_ADMIN_LOGIN)) {
|
||||
current_auth_level = LEVEL_ADMIN;
|
||||
} else if(sUser == FPSTR(DEFAULT_USER_LOGIN)){
|
||||
current_auth_level = LEVEL_USER;
|
||||
} else {
|
||||
current_auth_level = LEVEL_GUEST;
|
||||
}
|
||||
//create Session
|
||||
if ((current_auth_level != auth_level) || (auth_level== LEVEL_GUEST)) {
|
||||
auth_ip * current_auth = new auth_ip;
|
||||
current_auth->level = current_auth_level;
|
||||
current_auth->ip=web_interface->web_server.client().remoteIP();
|
||||
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
||||
strcpy(current_auth->userID,sUser.c_str());
|
||||
current_auth->last_time=millis();
|
||||
if (web_interface->AddAuthIP(current_auth)) {
|
||||
String tmps ="ESPSESSIONID=";
|
||||
tmps+=current_auth->sessionID;
|
||||
web_interface->web_server.sendHeader("Set-Cookie",tmps);
|
||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||
switch(current_auth->level) {
|
||||
if ((code == 200) || (code == 500)) {
|
||||
level_authenticate_type current_auth_level;
|
||||
if(sUser == FPSTR(DEFAULT_ADMIN_LOGIN)) {
|
||||
current_auth_level = LEVEL_ADMIN;
|
||||
} else if(sUser == FPSTR(DEFAULT_USER_LOGIN)) {
|
||||
current_auth_level = LEVEL_USER;
|
||||
} else {
|
||||
current_auth_level = LEVEL_GUEST;
|
||||
}
|
||||
//create Session
|
||||
if ((current_auth_level != auth_level) || (auth_level== LEVEL_GUEST)) {
|
||||
auth_ip * current_auth = new auth_ip;
|
||||
current_auth->level = current_auth_level;
|
||||
current_auth->ip=web_interface->web_server.client().remoteIP();
|
||||
strcpy(current_auth->sessionID,web_interface->create_session_ID());
|
||||
strcpy(current_auth->userID,sUser.c_str());
|
||||
current_auth->last_time=millis();
|
||||
if (web_interface->AddAuthIP(current_auth)) {
|
||||
String tmps ="ESPSESSIONID=";
|
||||
tmps+=current_auth->sessionID;
|
||||
web_interface->web_server.sendHeader("Set-Cookie",tmps);
|
||||
web_interface->web_server.sendHeader("Cache-Control","no-cache");
|
||||
switch(current_auth->level) {
|
||||
case LEVEL_ADMIN:
|
||||
auths = "admin";
|
||||
break;
|
||||
case LEVEL_USER:
|
||||
case LEVEL_USER:
|
||||
auths = "user";
|
||||
break;
|
||||
default:
|
||||
auths = "guest";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
delete current_auth;
|
||||
msg_alert_error=true;
|
||||
code = 500;
|
||||
smsg = F("Error: Too many connections");
|
||||
} else {
|
||||
delete current_auth;
|
||||
msg_alert_error=true;
|
||||
code = 500;
|
||||
smsg = F("Error: Too many connections");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (code == 200) smsg = F("Ok");
|
||||
if (code == 200) {
|
||||
smsg = F("Ok");
|
||||
}
|
||||
|
||||
//build JSON
|
||||
String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\"";
|
||||
buffer2send += auths;
|
||||
buffer2send += "\"}";
|
||||
web_interface->web_server.send(code, "application/json", buffer2send);
|
||||
//build JSON
|
||||
String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\"";
|
||||
buffer2send += auths;
|
||||
buffer2send += "\"}";
|
||||
web_interface->web_server.send(code, "application/json", buffer2send);
|
||||
} else {
|
||||
if (auth_level != LEVEL_GUEST) {
|
||||
String cookie = web_interface->web_server.header("Cookie");
|
||||
int pos = cookie.indexOf("ESPSESSIONID=");
|
||||
String sessionID;
|
||||
if (pos!= -1) {
|
||||
int pos2 = cookie.indexOf(";",pos);
|
||||
sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2);
|
||||
auth_ip * current_auth_info = web_interface->GetAuth(web_interface->web_server.client().remoteIP(), sessionID.c_str());
|
||||
if (current_auth_info != NULL){
|
||||
if (auth_level != LEVEL_GUEST) {
|
||||
String cookie = web_interface->web_server.header("Cookie");
|
||||
int pos = cookie.indexOf("ESPSESSIONID=");
|
||||
String sessionID;
|
||||
if (pos!= -1) {
|
||||
int pos2 = cookie.indexOf(";",pos);
|
||||
sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2);
|
||||
auth_ip * current_auth_info = web_interface->GetAuth(web_interface->web_server.client().remoteIP(), sessionID.c_str());
|
||||
if (current_auth_info != NULL) {
|
||||
sUser = current_auth_info->userID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String buffer2send = "{\"status\":\"200\",\"authentication_lvl\":\"";
|
||||
buffer2send += auths;
|
||||
buffer2send += "\",\"user\":\"";
|
||||
buffer2send += sUser;
|
||||
buffer2send +="\"}";
|
||||
web_interface->web_server.send(code, "application/json", buffer2send);
|
||||
String buffer2send = "{\"status\":\"200\",\"authentication_lvl\":\"";
|
||||
buffer2send += auths;
|
||||
buffer2send += "\",\"user\":\"";
|
||||
buffer2send += sUser;
|
||||
buffer2send +="\"}";
|
||||
web_interface->web_server.send(code, "application/json", buffer2send);
|
||||
}
|
||||
#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\"}");
|
||||
#endif
|
||||
}
|
||||
@ -352,12 +362,12 @@ void handleFileList()
|
||||
FS_DIR dir = SPIFFS.openDir(path);
|
||||
if (!dir.next()) {
|
||||
#else
|
||||
String ptmp = path;
|
||||
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
||||
String ptmp = path;
|
||||
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
||||
ptmp = path.substring (0, path.length() - 1);
|
||||
}
|
||||
FS_FILE dir = SPIFFS.open (ptmp);
|
||||
FS_FILE dircontent = dir.openNextFile();
|
||||
FS_FILE dir = SPIFFS.open (ptmp);
|
||||
FS_FILE dircontent = dir.openNextFile();
|
||||
if (!dircontent) {
|
||||
#endif
|
||||
//keep directory alive even empty
|
||||
@ -387,23 +397,23 @@ void handleFileList()
|
||||
{
|
||||
while (dir.next()) {
|
||||
#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) {
|
||||
#endif
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
String fullpath = dir.fileName();
|
||||
#else
|
||||
String fullpath = file2deleted.name();
|
||||
String fullpath = file2deleted.name();
|
||||
#endif
|
||||
if (!SPIFFS.remove(fullpath)) {
|
||||
delete_error = true;
|
||||
status = F("Cannot deleted ") ;
|
||||
status+=fullpath;
|
||||
}
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
file2deleted = dir.openNextFile();
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
file2deleted = dir.openNextFile();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -438,11 +448,11 @@ void handleFileList()
|
||||
#if defined ( ARDUINO_ARCH_ESP8266 )
|
||||
FS_DIR dir = SPIFFS.openDir(path);
|
||||
#else
|
||||
String ptmp = path;
|
||||
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
||||
String ptmp = path;
|
||||
if ( (path != "/") && (path[path.length() - 1] = '/') ) {
|
||||
ptmp = path.substring (0, path.length() - 1);
|
||||
}
|
||||
FS_FILE dir = SPIFFS.open(ptmp);
|
||||
FS_FILE dir = SPIFFS.open(ptmp);
|
||||
#endif
|
||||
jsonfile+="\"files\":[";
|
||||
bool firstentry=true;
|
||||
@ -451,8 +461,8 @@ void handleFileList()
|
||||
while (dir.next()) {
|
||||
String filename = dir.fileName();
|
||||
#else
|
||||
File fileparsed = dir.openNextFile();
|
||||
while (fileparsed) {
|
||||
File fileparsed = dir.openNextFile();
|
||||
while (fileparsed) {
|
||||
String filename = fileparsed.name();
|
||||
#endif
|
||||
String size ="";
|
||||
@ -482,9 +492,9 @@ void handleFileList()
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
size = CONFIG::formatBytes(dir.fileSize());
|
||||
#else
|
||||
size = CONFIG::formatBytes(fileparsed.size());
|
||||
size = CONFIG::formatBytes(fileparsed.size());
|
||||
#endif
|
||||
|
||||
|
||||
} else {
|
||||
addtolist = false;
|
||||
}
|
||||
@ -518,7 +528,7 @@ void handleFileList()
|
||||
totalBytes = info.totalBytes;
|
||||
usedBytes = info.usedBytes;
|
||||
#else
|
||||
totalBytes = SPIFFS.totalBytes();
|
||||
totalBytes = SPIFFS.totalBytes();
|
||||
usedBytes = SPIFFS.usedBytes();
|
||||
#endif
|
||||
jsonfile+="\"total\":\"" + CONFIG::formatBytes(totalBytes) + "\",";
|
||||
@ -536,7 +546,7 @@ void handleFileList()
|
||||
//SPIFFS files uploader handle
|
||||
void SPIFFSFileupload()
|
||||
{
|
||||
static FS_FILE fsUploadFile = (FS_FILE)0;
|
||||
static FS_FILE fsUploadFile = (FS_FILE)0;
|
||||
//get authentication status
|
||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||
//Guest cannot upload
|
||||
@ -545,8 +555,8 @@ void SPIFFSFileupload()
|
||||
ESPCOM::println (F ("Upload rejected"), PRINTER_PIPE);
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@ -557,16 +567,19 @@ void SPIFFSFileupload()
|
||||
//Upload start
|
||||
//**************
|
||||
if(upload.status == UPLOAD_FILE_START) {
|
||||
String upload_filename = upload.filename;
|
||||
String sizeargname = upload_filename + "S";
|
||||
if (upload_filename[0] != '/') filename = "/" + upload_filename;
|
||||
else filename = upload.filename;
|
||||
String upload_filename = upload.filename;
|
||||
String sizeargname = upload_filename + "S";
|
||||
if (upload_filename[0] != '/') {
|
||||
filename = "/" + upload_filename;
|
||||
} else {
|
||||
filename = upload.filename;
|
||||
}
|
||||
//according User or Admin the root is different as user is isolate to /user when admin has full access
|
||||
if(auth_level != LEVEL_ADMIN) {
|
||||
upload_filename = filename;
|
||||
upload_filename = filename;
|
||||
filename = "/user" + upload_filename;
|
||||
}
|
||||
|
||||
|
||||
if (SPIFFS.exists (filename) ) {
|
||||
SPIFFS.remove (filename);
|
||||
}
|
||||
@ -574,7 +587,7 @@ void SPIFFSFileupload()
|
||||
fsUploadFile.close();
|
||||
}
|
||||
//create file
|
||||
fsUploadFile = SPIFFS.open(filename, SPIFFS_FILE_WRITE);
|
||||
fsUploadFile = SPIFFS.open(filename, SPIFFS_FILE_WRITE);
|
||||
//check If creation succeed
|
||||
if (fsUploadFile) {
|
||||
//if yes upload is started
|
||||
@ -584,9 +597,9 @@ void SPIFFSFileupload()
|
||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||
ESPCOM::println (F ("Error ESP create"), PRINTER_PIPE);
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
}
|
||||
//Upload write
|
||||
@ -600,11 +613,11 @@ void SPIFFSFileupload()
|
||||
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
ESPCOM::println (F ("Error ESP write"), PRINTER_PIPE);
|
||||
ESPCOM::println (F ("Error ESP write"), PRINTER_PIPE);
|
||||
}
|
||||
//Upload end
|
||||
//**************
|
||||
@ -614,30 +627,30 @@ void SPIFFSFileupload()
|
||||
//close it
|
||||
fsUploadFile.close();
|
||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||
}
|
||||
web_interface->_upload_status = UPLOAD_STATUS_SUCCESSFUL;
|
||||
}
|
||||
} else {
|
||||
//we have a problem set flag UPLOAD_STATUS_CANCELLED
|
||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
if (SPIFFS.exists (filename) ) {
|
||||
SPIFFS.remove (filename);
|
||||
}
|
||||
SPIFFS.remove (filename);
|
||||
}
|
||||
ESPCOM::println (F ("Error ESP close"), PRINTER_PIPE);
|
||||
|
||||
|
||||
}
|
||||
//Upload cancelled
|
||||
//**************
|
||||
} else {
|
||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_CANCELLED;
|
||||
}
|
||||
ESPCOM::println (F ("Error ESP upload"), PRINTER_PIPE);
|
||||
return;
|
||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
web_interface->_upload_status = UPLOAD_STATUS_CANCELLED;
|
||||
}
|
||||
ESPCOM::println (F ("Error ESP upload"), PRINTER_PIPE);
|
||||
return;
|
||||
}
|
||||
CONFIG::wait(0);
|
||||
}
|
||||
@ -653,8 +666,8 @@ void WebUpdateUpload()
|
||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
ESPCOM::println (F ("Update failed"), PRINTER_PIPE);
|
||||
LOG("Web Update failed\r\n");
|
||||
@ -668,25 +681,28 @@ void WebUpdateUpload()
|
||||
ESPCOM::println (F ("Update Firmware"), PRINTER_PIPE);
|
||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
WiFiUDP::stopAll();
|
||||
WiFiUDP::stopAll();
|
||||
#endif
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
#else
|
||||
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
#else
|
||||
//Not sure can do OTA on 2Mb board
|
||||
maxSketchSpace = (ESP.getFlashChipSize()>0x20000)?0x140000:0x140000/2;
|
||||
maxSketchSpace = (ESP.getFlashChipSize()>0x20000)?0x140000:0x140000/2;
|
||||
#endif
|
||||
last_upload_update = 0;
|
||||
if(!Update.begin(maxSketchSpace)) { //start with max available size
|
||||
web_interface->_upload_status=UPLOAD_STATUS_CANCELLED;
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
} else {
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESPCOM::println (F ("Update 0%%"), PRINTER_PIPE);
|
||||
else ESPCOM::println (F ("Update 0%"), PRINTER_PIPE);
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
|
||||
ESPCOM::println (F ("Update 0%%"), PRINTER_PIPE);
|
||||
} else {
|
||||
ESPCOM::println (F ("Update 0%"), PRINTER_PIPE);
|
||||
}
|
||||
}
|
||||
//Upload write
|
||||
//**************
|
||||
@ -699,7 +715,9 @@ void WebUpdateUpload()
|
||||
String s = "Update ";
|
||||
s+= String(last_upload_update);
|
||||
s+= "%";
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) s+= "%";
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
|
||||
s+= "%";
|
||||
}
|
||||
ESPCOM::println (s.c_str(), PRINTER_PIPE);
|
||||
}
|
||||
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||
@ -711,8 +729,11 @@ void WebUpdateUpload()
|
||||
} else if(upload.status == UPLOAD_FILE_END) {
|
||||
if(Update.end(true)) { //true to set the size to the current progress
|
||||
//Now Reboot
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESPCOM::println (F("Update 100%%"), PRINTER_PIPE);
|
||||
else ESPCOM::println (F("Update 100%"), PRINTER_PIPE);
|
||||
if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) {
|
||||
ESPCOM::println (F("Update 100%%"), PRINTER_PIPE);
|
||||
} else {
|
||||
ESPCOM::println (F("Update 100%"), PRINTER_PIPE);
|
||||
}
|
||||
web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL;
|
||||
}
|
||||
} else if(upload.status == UPLOAD_FILE_ABORTED) {
|
||||
@ -727,7 +748,7 @@ void handleUpdate()
|
||||
{
|
||||
level_authenticate_type auth_level = web_interface->is_authenticated();
|
||||
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");
|
||||
return;
|
||||
}
|
||||
@ -739,7 +760,7 @@ void handleUpdate()
|
||||
web_interface->web_server.send(200, "application/json", jsonfile);
|
||||
//if success restart
|
||||
if (web_interface->_upload_status==UPLOAD_STATUS_SUCCESSFUL) {
|
||||
CONFIG::wait(2000);
|
||||
CONFIG::wait(2000);
|
||||
web_interface->restartmodule=true;
|
||||
} else {
|
||||
web_interface->_upload_status=UPLOAD_STATUS_NONE;
|
||||
@ -777,17 +798,17 @@ void handle_not_found()
|
||||
LOG("type:")
|
||||
LOG(contentType)
|
||||
LOG("\r\n")
|
||||
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
||||
if(SPIFFS.exists(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;
|
||||
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
||||
if(SPIFFS.exists(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;
|
||||
}
|
||||
|
||||
if (page_not_found ) {
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
@ -802,7 +823,7 @@ void handle_not_found()
|
||||
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_QUERY,web_interface->web_server.uri());
|
||||
web_interface->web_server.send(200,"text/html",contentType);
|
||||
//web_interface->web_server.sendContent_P(NOT_AUTH_NF);
|
||||
@ -821,7 +842,7 @@ void handle_not_found()
|
||||
FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ);
|
||||
web_interface->web_server.streamFile(file, contentType);
|
||||
file.close();
|
||||
|
||||
|
||||
} else {
|
||||
//if not template use default page
|
||||
contentType=FPSTR(PAGE_404);
|
||||
@ -849,10 +870,10 @@ void handle_not_found()
|
||||
void handle_web_command()
|
||||
{
|
||||
level_authenticate_type auth_level= web_interface->is_authenticated();
|
||||
/* if (auth_level == LEVEL_GUEST) {
|
||||
web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n");
|
||||
return;
|
||||
}*/
|
||||
/* if (auth_level == LEVEL_GUEST) {
|
||||
web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n");
|
||||
return;
|
||||
}*/
|
||||
String buffer2send = "";
|
||||
ESPResponseStream espresponse;
|
||||
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_part2="";
|
||||
//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");
|
||||
return;
|
||||
}
|
||||
@ -909,10 +930,10 @@ void handle_web_command()
|
||||
//if not is not a valid [ESPXXX] command
|
||||
}
|
||||
} else {
|
||||
if (auth_level == LEVEL_GUEST) {
|
||||
web_interface->web_server.send(401,"text/plain","Authentication failed!\n");
|
||||
return;
|
||||
}
|
||||
if (auth_level == LEVEL_GUEST) {
|
||||
web_interface->web_server.send(401,"text/plain","Authentication failed!\n");
|
||||
return;
|
||||
}
|
||||
//send command to serial as no need to transfer ESP command
|
||||
//to avoid any pollution if Uploading file to SDCard
|
||||
if ((web_interface->blockserial) == false) {
|
||||
@ -977,14 +998,14 @@ void handle_web_command()
|
||||
LOG(current_line)
|
||||
LOG("\r\n")
|
||||
//check command
|
||||
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)){
|
||||
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
||||
//save time no need to continue
|
||||
if (current_line.indexOf("busy:") > -1) {
|
||||
temp_counter++;
|
||||
} else if (COMMAND::check_command(current_line, NO_PIPE, false)) {
|
||||
temp_counter ++ ;
|
||||
}
|
||||
}else {
|
||||
temp_counter ++ ;
|
||||
}
|
||||
} else {
|
||||
if (COMMAND::check_command(current_line, NO_PIPE, false)) {
|
||||
temp_counter ++ ;
|
||||
}
|
||||
@ -993,11 +1014,10 @@ void handle_web_command()
|
||||
break;
|
||||
}
|
||||
if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) {
|
||||
if (!current_line.startsWith( "ok "))
|
||||
{
|
||||
buffer2send +=current_line;
|
||||
buffer2send +="\n";
|
||||
}
|
||||
if (!current_line.startsWith( "ok ")) {
|
||||
buffer2send +=current_line;
|
||||
buffer2send +="\n";
|
||||
}
|
||||
} else {
|
||||
buffer2send +=current_line;
|
||||
buffer2send +="\n";
|
||||
@ -1163,9 +1183,9 @@ void SDFile_serial_upload()
|
||||
LOG("SD upload rejected\r\n");
|
||||
LOG("Need to stop");
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@ -1177,13 +1197,15 @@ void SDFile_serial_upload()
|
||||
LOG("Upload Start\r\n")
|
||||
String command = "M29";
|
||||
String resetcmd = "M110 N0";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)resetcmd = "N0 M110";
|
||||
if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
resetcmd = "N0 M110";
|
||||
}
|
||||
lineNb=1;
|
||||
//close any ongoing upload and get current line number
|
||||
if(!sendLine2Serial (command,1, &lineNb)){
|
||||
if(!sendLine2Serial (command,1, &lineNb)) {
|
||||
//it can failed for repetier
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
if(!sendLine2Serial (command,-1, NULL)){
|
||||
if(!sendLine2Serial (command,-1, NULL)) {
|
||||
LOG("Start Upload failed")
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
return;
|
||||
@ -1196,13 +1218,13 @@ void SDFile_serial_upload()
|
||||
}
|
||||
//Mount SD card
|
||||
command = "M21";
|
||||
if(!sendLine2Serial (command,-1, NULL)){
|
||||
if(!sendLine2Serial (command,-1, NULL)) {
|
||||
LOG("Mounting SD failed")
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
return;
|
||||
}
|
||||
//Reset line numbering
|
||||
if(!sendLine2Serial (resetcmd,-1, NULL)){
|
||||
if(!sendLine2Serial (resetcmd,-1, NULL)) {
|
||||
LOG("Reset Numbering failed")
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
return;
|
||||
@ -1223,94 +1245,94 @@ void SDFile_serial_upload()
|
||||
command = "M28 " + upload.filename;
|
||||
//send start upload
|
||||
//no correction allowed because it means reset numbering was failed
|
||||
if (sendLine2Serial(command, lineNb, NULL)){
|
||||
if (sendLine2Serial(command, lineNb, NULL)) {
|
||||
CONFIG::wait(1200);
|
||||
//additional purge, in case it is slow to answer
|
||||
purge_serial();
|
||||
web_interface->_upload_status= UPLOAD_STATUS_ONGOING;
|
||||
LOG("Creation Ok\r\n")
|
||||
|
||||
|
||||
} else {
|
||||
web_interface->_upload_status= UPLOAD_STATUS_FAILED;
|
||||
LOG("Creation failed\r\n");
|
||||
LOG("Creation failed\r\n");
|
||||
}
|
||||
//Upload write
|
||||
//**************
|
||||
//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
|
||||
if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data
|
||||
//feed watchdog
|
||||
CONFIG::wait(0);
|
||||
//it is a comment
|
||||
if (upload.buf[pos] == ';') {
|
||||
LOG ("Comment\r\n")
|
||||
is_comment = true;
|
||||
}
|
||||
//it is an end line
|
||||
else if ( (upload.buf[pos] == 13) || (upload.buf[pos] == 10) ) {
|
||||
//if comment line then reset
|
||||
is_comment = false;
|
||||
//does line fit the buffer ?
|
||||
if (current_line.length() < 126) {
|
||||
//do we have something in buffer ?
|
||||
if (current_line.length() > 0 ) {
|
||||
lineNb++;
|
||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||
LOG ("Error sending line\n")
|
||||
CloseSerialUpload (true, current_filename,lineNb);
|
||||
for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data
|
||||
//feed watchdog
|
||||
CONFIG::wait(0);
|
||||
//it is a comment
|
||||
if (upload.buf[pos] == ';') {
|
||||
LOG ("Comment\r\n")
|
||||
is_comment = true;
|
||||
}
|
||||
//it is an end line
|
||||
else if ( (upload.buf[pos] == 13) || (upload.buf[pos] == 10) ) {
|
||||
//if comment line then reset
|
||||
is_comment = false;
|
||||
//does line fit the buffer ?
|
||||
if (current_line.length() < 126) {
|
||||
//do we have something in buffer ?
|
||||
if (current_line.length() > 0 ) {
|
||||
lineNb++;
|
||||
if (!sendLine2Serial (current_line, lineNb, NULL) ) {
|
||||
LOG ("Error sending line\n")
|
||||
CloseSerialUpload (true, current_filename,lineNb);
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
//reset line
|
||||
current_line = "";
|
||||
return;
|
||||
}
|
||||
//reset line
|
||||
current_line = "";
|
||||
|
||||
} else {
|
||||
LOG ("Empy line\n")
|
||||
}
|
||||
} 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 {
|
||||
//error buffer overload
|
||||
LOG ("Error over buffer\n")
|
||||
lineNb++;
|
||||
CloseSerialUpload (true, current_filename, lineNb);
|
||||
} 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();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
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;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOG ("Error upload\n")
|
||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||
lineNb++;
|
||||
CloseSerialUpload (true, current_filename, lineNb);
|
||||
LOG ("Error upload\n")
|
||||
web_interface->_upload_status = UPLOAD_STATUS_FAILED;
|
||||
lineNb++;
|
||||
CloseSerialUpload (true, current_filename, lineNb);
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
return;
|
||||
return;
|
||||
}
|
||||
//Upload end
|
||||
//**************
|
||||
@ -1323,9 +1345,9 @@ void SDFile_serial_upload()
|
||||
lineNb++;
|
||||
CloseSerialUpload (true, current_filename, lineNb);
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@ -1338,11 +1360,11 @@ void SDFile_serial_upload()
|
||||
} else { //UPLOAD_FILE_ABORTED
|
||||
LOG("Error, Something happened\r\n");
|
||||
lineNb++;
|
||||
CloseSerialUpload (true, current_filename, lineNb);
|
||||
CloseSerialUpload (true, current_filename, lineNb);
|
||||
#if defined ( ARDUINO_ARCH_ESP8266)
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
web_interface->web_server.client().stopAll();
|
||||
#else
|
||||
web_interface->web_server.client().stop();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -56,11 +56,11 @@
|
||||
#include "espcom.h"
|
||||
|
||||
#ifdef SSDP_FEATURE
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESP32SSDP.h>
|
||||
#else
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <ESP32SSDP.h>
|
||||
#else
|
||||
#include <ESP8266SSDP.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
@ -76,24 +76,28 @@ long id_connection = 0;
|
||||
uint8_t Checksum(const char * line, uint16_t lineSize)
|
||||
{
|
||||
uint8_t checksum_val =0;
|
||||
for (uint16_t i=0; i < lineSize; i++) checksum_val = checksum_val ^ ((uint8_t)line[i]);
|
||||
for (uint16_t i=0; i < lineSize; i++) {
|
||||
checksum_val = checksum_val ^ ((uint8_t)line[i]);
|
||||
}
|
||||
return checksum_val;
|
||||
}
|
||||
|
||||
String CheckSumLine(const char* line, uint32_t linenb){
|
||||
String linechecksum = "N" + String(linenb)+ " " + line;
|
||||
String CheckSumLine(const char* line, uint32_t linenb)
|
||||
{
|
||||
String linechecksum = "N" + String(linenb)+ " " + line;
|
||||
uint8_t crc = Checksum(linechecksum.c_str(), linechecksum.length());
|
||||
linechecksum+="*"+String(crc);
|
||||
return linechecksum;
|
||||
}
|
||||
|
||||
bool purge_serial(){
|
||||
bool purge_serial()
|
||||
{
|
||||
uint32_t start = millis();
|
||||
uint8_t buf [51];
|
||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||
CONFIG::wait (5);
|
||||
LOG("Purge Serial\r\n")
|
||||
while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ){
|
||||
while (ESPCOM::available(DEFAULT_PRINTER_PIPE) > 0 ) {
|
||||
if ((millis() - start ) > 2000) {
|
||||
LOG("Purge timeout\r\n")
|
||||
return false;
|
||||
@ -106,32 +110,38 @@ bool purge_serial(){
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
String s = (const char *)buf;
|
||||
//repetier never stop sending data so no need to wait if have 'wait' or 'busy'
|
||||
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1))return true;
|
||||
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
|
||||
return true;
|
||||
}
|
||||
LOG("Purge interrupted\r\n")
|
||||
}
|
||||
CONFIG::wait (5);
|
||||
}
|
||||
}
|
||||
CONFIG::wait (0);
|
||||
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();
|
||||
while ((ESPCOM::available(DEFAULT_PRINTER_PIPE) < 2) && ((millis()-start) < timeout))CONFIG::wait (10);
|
||||
while ((ESPCOM::available(DEFAULT_PRINTER_PIPE) < 2) && ((millis()-start) < timeout)) {
|
||||
CONFIG::wait (10);
|
||||
}
|
||||
return ESPCOM::available(DEFAULT_PRINTER_PIPE);
|
||||
}
|
||||
|
||||
uint32_t Get_lineNumber(String & response){
|
||||
uint32_t Get_lineNumber(String & response)
|
||||
{
|
||||
int32_t l = 0;
|
||||
String sresend = "Resend:";
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE){
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
sresend = "rs N";
|
||||
}
|
||||
int pos = response.indexOf(sresend);
|
||||
if (pos == -1 ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
pos+=sresend.length();
|
||||
int pos2 = response.indexOf("\n", pos);
|
||||
String snum = response.substring(pos, pos2);
|
||||
@ -156,12 +166,20 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
||||
String line2send;
|
||||
String sok = "ok";
|
||||
String sresend = "Resend:";
|
||||
if (newlinenb) *newlinenb = linenb;
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)sresend = "rs N";
|
||||
if (newlinenb) {
|
||||
*newlinenb = linenb;
|
||||
}
|
||||
if ( CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) {
|
||||
sresend = "rs N";
|
||||
}
|
||||
if (linenb != -1) {
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) sok+=" " + String(linenb);
|
||||
if ( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) {
|
||||
sok+=" " + String(linenb);
|
||||
}
|
||||
line2send = CheckSumLine(line.c_str(),linenb);
|
||||
} else line2send = line;
|
||||
} else {
|
||||
line2send = line;
|
||||
}
|
||||
//purge serial as nothing is supposed to interfere with upload
|
||||
purge_serial();
|
||||
LOG ("Send line ")
|
||||
@ -182,14 +200,14 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
||||
//get size of buffer
|
||||
if (len > 0) {
|
||||
uint8_t * sbuf = (uint8_t *)malloc(len+1);
|
||||
if(!sbuf){
|
||||
if(!sbuf) {
|
||||
return false;
|
||||
}
|
||||
//read buffer
|
||||
ESPCOM::readBytes (DEFAULT_PRINTER_PIPE, sbuf, len);
|
||||
//convert buffer to zero end array
|
||||
sbuf[len] = '\0';
|
||||
//use string because easier to handle and allow to re-assemble cutted answer
|
||||
//use string because easier to handle and allow to re-assemble cutted answer
|
||||
response += (const char*) sbuf;
|
||||
LOG ("Response:\r\n************\r\n")
|
||||
LOG (response)
|
||||
@ -197,16 +215,16 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
||||
//in that case there is no way to know what is the right number to use and so send should be failed
|
||||
if (( ( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER) ) && (response.indexOf ("skip") != -1)) {
|
||||
LOG ("Wrong line requested\r\n")
|
||||
count = 5;
|
||||
count = 5;
|
||||
}
|
||||
//it is resend ?
|
||||
int pos = response.indexOf (sresend);
|
||||
//be sure we get full line to be able to process properly
|
||||
if (( pos > -1) && (response.lastIndexOf("\n") > pos)){
|
||||
if (( pos > -1) && (response.lastIndexOf("\n") > pos)) {
|
||||
LOG ("Resend detected\r\n")
|
||||
uint32_t line_number = Get_lineNumber(response);
|
||||
//this part is only if have newlinenb variable
|
||||
if (newlinenb != nullptr){
|
||||
if (newlinenb != nullptr) {
|
||||
*newlinenb = line_number;
|
||||
free(sbuf);
|
||||
//no need newlinenb in this one in theory, but just in case...
|
||||
@ -233,31 +251,31 @@ bool sendLine2Serial (String & line, int32_t linenb, int32_t * newlinenb)
|
||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||
wait_for_data(1000);
|
||||
timeout = millis();
|
||||
|
||||
|
||||
} else {
|
||||
if ( (response.indexOf (sok) > -1) ) { //we have ok so it is done
|
||||
free(sbuf);
|
||||
LOG ("Got ok\r\n")
|
||||
purge_serial();
|
||||
return true;
|
||||
LOG ("Got ok\r\n")
|
||||
purge_serial();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
free(sbuf);
|
||||
}
|
||||
//no answer or over buffer exit
|
||||
if ( (millis() - timeout > 2000) || (response.length() >200)){
|
||||
if ( (millis() - timeout > 2000) || (response.length() >200)) {
|
||||
LOG ("Time out\r\n")
|
||||
done = true;
|
||||
}
|
||||
CONFIG::wait (5);
|
||||
}
|
||||
}
|
||||
LOG ("Send line error\r\n")
|
||||
LOG ("Send line error\r\n")
|
||||
return false;
|
||||
}
|
||||
|
||||
//send M29 / M30 command to close file on SD////////////////////////////
|
||||
void CloseSerialUpload (bool iserror, String & filename , int32_t linenb)
|
||||
void CloseSerialUpload (bool iserror, String & filename, int32_t linenb)
|
||||
{
|
||||
purge_serial();
|
||||
String command = "M29";
|
||||
@ -289,20 +307,20 @@ void CloseSerialUpload (bool iserror, String & filename , int32_t linenb)
|
||||
|
||||
|
||||
//constructor
|
||||
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
||||
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
, web_events("/events")
|
||||
, web_events("/events")
|
||||
#ifdef WS_DATA_FEATURE
|
||||
, web_socket("/ws")
|
||||
, web_socket("/ws")
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
//that handle "/" and default index.html.gz
|
||||
#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, "/Nowhere");
|
||||
//events functions
|
||||
//events functions
|
||||
web_events.onConnect(handle_onevent_connect);
|
||||
//events management
|
||||
web_server.addHandler(&web_events);
|
||||
@ -312,16 +330,16 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
||||
//Websocket management
|
||||
web_server.addHandler(&web_socket);
|
||||
#endif
|
||||
#else
|
||||
web_server.on("/",HTTP_ANY, handle_web_interface_root);
|
||||
#else
|
||||
web_server.on("/",HTTP_ANY, handle_web_interface_root);
|
||||
#endif
|
||||
//need to be there even no authentication to say to UI no authentication
|
||||
web_server.on("/login", HTTP_ANY, handle_login);
|
||||
//need to be there even no authentication to say to UI no authentication
|
||||
web_server.on("/login", HTTP_ANY, handle_login);
|
||||
#ifdef SSDP_FEATURE
|
||||
web_server.on ("/description.xml", HTTP_GET, handle_SSDP);
|
||||
#endif
|
||||
#ifdef CAPTIVE_PORTAL_FEATURE
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
web_server.on ("/generate_204", HTTP_ANY, [] (AsyncWebServerRequest * request) {
|
||||
request->redirect ("/");
|
||||
});
|
||||
@ -332,12 +350,12 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
||||
web_server.on ("/fwlink/", HTTP_ANY, [] (AsyncWebServerRequest * request) {
|
||||
request->redirect ("/");
|
||||
});
|
||||
#else
|
||||
#else
|
||||
web_server.on("/generate_204",HTTP_ANY, handle_web_interface_root);
|
||||
web_server.on("/gconnectivitycheck.gstatic.com",HTTP_ANY, handle_web_interface_root);
|
||||
//do not forget the / at the end
|
||||
//do not forget the / at the end
|
||||
web_server.on("/fwlink/",HTTP_ANY, handle_web_interface_root);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
//SPIFFS
|
||||
web_server.on ("/files", HTTP_ANY, handleFileList, SPIFFSFileupload);
|
||||
@ -348,9 +366,9 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port) : web_server (port)
|
||||
web_server.onNotFound ( handle_not_found);
|
||||
//web commands
|
||||
web_server.on ("/command", HTTP_ANY, handle_web_command);
|
||||
web_server.on ("/command_silent", HTTP_ANY, handle_web_command_silent);
|
||||
//Serial SD management
|
||||
web_server.on ("/upload_serial", HTTP_ANY, handle_serial_SDFileList, SDFile_serial_upload);
|
||||
web_server.on ("/command_silent", HTTP_ANY, handle_web_command_silent);
|
||||
//Serial SD management
|
||||
web_server.on ("/upload_serial", HTTP_ANY, handle_serial_SDFileList, SDFile_serial_upload);
|
||||
|
||||
blockserial = false;
|
||||
restartmodule = false;
|
||||
|
@ -63,11 +63,11 @@ public:
|
||||
AsyncWebServer web_server;
|
||||
AsyncEventSource web_events;
|
||||
#else
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
ESP8266WebServer web_server;
|
||||
#else
|
||||
WebServer web_server;
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
ESP8266WebServer web_server;
|
||||
#else
|
||||
WebServer web_server;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef WS_DATA_FEATURE
|
||||
#if defined(ASYNCWEBSERVER)
|
||||
|
@ -41,11 +41,11 @@ DNSServer dnsServer;
|
||||
const byte DNS_PORT = 53;
|
||||
#endif
|
||||
#ifdef SSDP_FEATURE
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266SSDP.h>
|
||||
#else
|
||||
#include <ESP32SSDP.h>
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266SSDP.h>
|
||||
#else
|
||||
#include <ESP32SSDP.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NETBIOS_FEATURE
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
@ -134,7 +134,7 @@ const char * WIFI_CONFIG::get_default_hostname()
|
||||
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
||||
WiFi.macAddress (mac);
|
||||
#if defined (ESP_HOST_NAME)
|
||||
strcpy (hostname, ESP_DEFAULT_NAME);
|
||||
strcpy (hostname, ESP_DEFAULT_NAME);
|
||||
#else
|
||||
if (0 > sprintf (hostname, "ESP_%02X%02X%02X", mac[3], mac[4], mac[5]) ) {
|
||||
strcpy (hostname, ESP_DEFAULT_NAME);
|
||||
@ -164,66 +164,67 @@ void WIFI_CONFIG::Safe_Setup()
|
||||
WiFi.softAPConfig ( local_ip, gateway, subnet);
|
||||
CONFIG::wait (1000);
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(100);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(ssid.c_str(), OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(local_ip.toString().c_str(), OLED_PIPE);
|
||||
OLED_DISPLAY::display_signal(100);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(ssid.c_str(), OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(local_ip.toString().c_str(), OLED_PIPE);
|
||||
#endif
|
||||
ESPCOM::println (F ("Safe mode started"), PRINTER_PIPE);
|
||||
}
|
||||
|
||||
|
||||
//wifi event
|
||||
void onWiFiEvent(WiFiEvent_t event){
|
||||
void onWiFiEvent(WiFiEvent_t event)
|
||||
{
|
||||
|
||||
switch (event) {
|
||||
case WIFI_EVENT_STAMODE_CONNECTED:
|
||||
switch (event) {
|
||||
case WIFI_EVENT_STAMODE_CONNECTED:
|
||||
#ifndef MKS_TFT_FEATURE
|
||||
ESPCOM::println (F ("Connected"), PRINTER_PIPE);
|
||||
ESPCOM::println (F ("Connected"), PRINTER_PIPE);
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_DISCONNECTED:
|
||||
ESPCOM::println (F ("Disconnected"), PRINTER_PIPE);
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_DISCONNECTED:
|
||||
ESPCOM::println (F ("Disconnected"), PRINTER_PIPE);
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_GOT_IP:
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_GOT_IP:
|
||||
#ifndef MKS_TFT_FEATURE
|
||||
ESPCOM::println (WiFi.localIP().toString().c_str(), PRINTER_PIPE);
|
||||
ESPCOM::println (WiFi.localIP().toString().c_str(), PRINTER_PIPE);
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(WiFi.localIP().toString().c_str(), OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(WiFi.localIP().toString().c_str(), OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
ESPCOM::print("", OLED_PIPE);
|
||||
#endif
|
||||
break;
|
||||
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
|
||||
ESPCOM::println (F ("New client"), PRINTER_PIPE);
|
||||
break;
|
||||
break;
|
||||
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
|
||||
ESPCOM::println (F ("New client"), PRINTER_PIPE);
|
||||
break;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
case SYSTEM_EVENT_STA_LOST_IP:
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_LOST_IP:
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -240,7 +241,7 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY);
|
||||
#else
|
||||
WiFi.onEvent(onWiFiEvent);
|
||||
WiFi.onEvent(onWiFiEvent);
|
||||
#endif
|
||||
//system_update_cpu_freq(SYS_CPU_160MHZ);
|
||||
//set the sleep mode
|
||||
@ -249,11 +250,11 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
return false;
|
||||
}
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::clear_lcd();
|
||||
OLED_DISPLAY::clear_lcd();
|
||||
#endif
|
||||
|
||||
sleep_mode = bflag;
|
||||
if (force_ap){
|
||||
if (force_ap) {
|
||||
bmode = AP_MODE;
|
||||
} else {
|
||||
//AP or client ?
|
||||
@ -275,10 +276,10 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
return false;
|
||||
}
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(100);
|
||||
OLED_DISPLAY::display_signal(100);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
#else
|
||||
#ifndef MKS_TFT_FEATURE
|
||||
ESPCOM::println (sbuf, PRINTER_PIPE);
|
||||
@ -346,9 +347,9 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
delay (50);
|
||||
WiFi.softAP (sbuf, pwd);
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(100);
|
||||
OLED_DISPLAY::display_signal(100);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
#endif
|
||||
delay (100);
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
@ -417,14 +418,14 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
if (!CONFIG::read_string (EP_STA_PASSWORD, pwd, MAX_PASSWORD_LENGTH) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifndef MKS_TFT_FEATURE
|
||||
ESPCOM::println (sbuf, PRINTER_PIPE);
|
||||
ESPCOM::println (sbuf, PRINTER_PIPE);
|
||||
#endif
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
#endif
|
||||
LOG ("SSID ")
|
||||
LOG (sbuf)
|
||||
@ -467,18 +468,20 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
#else
|
||||
esp_wifi_set_protocol (ESP_IF_WIFI_STA, bflag);
|
||||
#endif
|
||||
if (strlen(pwd) > 0){
|
||||
if (strlen(pwd) > 0) {
|
||||
WiFi.begin (sbuf, pwd);
|
||||
} else {
|
||||
WiFi.begin (sbuf);
|
||||
}
|
||||
delay (100);
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
WiFi.setSleepMode ( (WiFiSleepType_t) sleep_mode);
|
||||
WiFi.setSleepMode ( (WiFiSleepType_t) sleep_mode);
|
||||
#else
|
||||
//for backward compatibility
|
||||
if ((wifi_ps_type_t) sleep_mode == WIFI_PS_MAX_MODEM)sleep_mode=WIFI_PS_MIN_MODEM;
|
||||
esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode);
|
||||
//for backward compatibility
|
||||
if ((wifi_ps_type_t) sleep_mode == WIFI_PS_MAX_MODEM) {
|
||||
sleep_mode=WIFI_PS_MIN_MODEM;
|
||||
}
|
||||
esp_wifi_set_ps ( (wifi_ps_type_t) sleep_mode);
|
||||
#endif
|
||||
delay (100);
|
||||
byte i = 0;
|
||||
@ -490,16 +493,16 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
switch (WiFi.status() ) {
|
||||
case 1:
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
OLED_DISPLAY::display_signal(-1);
|
||||
#endif
|
||||
if ((dot == 0) || last!=WiFi.status()) {
|
||||
if ((dot == 0) || last!=WiFi.status()) {
|
||||
msg = F ("No SSID");
|
||||
last=WiFi.status();
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if ((dot == 0) || last!=WiFi.status()) {
|
||||
if ((dot == 0) || last!=WiFi.status()) {
|
||||
msg = F ("No Connection");
|
||||
last=WiFi.status();
|
||||
}
|
||||
@ -507,26 +510,26 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
|
||||
default:
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
OLED_DISPLAY::display_signal(wifi_config.getSignal (WiFi.RSSI ()));
|
||||
#endif
|
||||
if ((dot == 0) || last!=WiFi.status()) {
|
||||
msg = F ("Connecting");
|
||||
last=WiFi.status();
|
||||
}
|
||||
break;
|
||||
}
|
||||
dot++;
|
||||
msg.trim();
|
||||
msg += F (".");
|
||||
//for smoothieware to keep position
|
||||
for (byte i = 0; i < 4 - dot; i++) {
|
||||
msg += F (" ");
|
||||
}
|
||||
if (dot == 4) {
|
||||
dot = 0;
|
||||
}
|
||||
if ((dot == 0) || last!=WiFi.status()) {
|
||||
msg = F ("Connecting");
|
||||
last=WiFi.status();
|
||||
}
|
||||
break;
|
||||
}
|
||||
dot++;
|
||||
msg.trim();
|
||||
msg += F (".");
|
||||
//for smoothieware to keep position
|
||||
for (byte i = 0; i < 4 - dot; i++) {
|
||||
msg += F (" ");
|
||||
}
|
||||
if (dot == 4) {
|
||||
dot = 0;
|
||||
}
|
||||
#ifndef MKS_TFT_FEATURE
|
||||
ESPCOM::println (msg, PRINTER_PIPE);
|
||||
ESPCOM::println (msg, PRINTER_PIPE);
|
||||
#endif
|
||||
|
||||
delay (500);
|
||||
@ -547,23 +550,24 @@ bool WIFI_CONFIG::Setup (bool force_ap)
|
||||
|
||||
//Get IP
|
||||
if (WiFi.getMode()== WIFI_AP) {
|
||||
currentIP = WiFi.softAPIP();
|
||||
ESPCOM::println (currentIP.toString().c_str(), PRINTER_PIPE);
|
||||
currentIP = WiFi.softAPIP();
|
||||
ESPCOM::println (currentIP.toString().c_str(), PRINTER_PIPE);
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::setCursor(0, 16);
|
||||
ESPCOM::print(currentIP.toString().c_str(), OLED_PIPE);
|
||||
ESPCOM::print(currentIP.toString().c_str(), OLED_PIPE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef ESP_OLED_FEATURE
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
if (force_ap){
|
||||
ESPCOM::print("Safe mode 1", OLED_PIPE);
|
||||
} else if ((WiFi.getMode() == WIFI_STA) && (WiFi.status() == WL_CONNECTED)) {
|
||||
ESPCOM::print("Connected", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
}
|
||||
else if (WiFi.getMode() != WIFI_STA) ESPCOM::print("AP Ready", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 48);
|
||||
if (force_ap) {
|
||||
ESPCOM::print("Safe mode 1", OLED_PIPE);
|
||||
} else if ((WiFi.getMode() == WIFI_STA) && (WiFi.status() == WL_CONNECTED)) {
|
||||
ESPCOM::print("Connected", OLED_PIPE);
|
||||
OLED_DISPLAY::setCursor(0, 0);
|
||||
ESPCOM::print(sbuf, OLED_PIPE);
|
||||
} else if (WiFi.getMode() != WIFI_STA) {
|
||||
ESPCOM::print("AP Ready", OLED_PIPE);
|
||||
}
|
||||
#endif
|
||||
ESPCOM::flush (DEFAULT_PRINTER_PIPE);
|
||||
return true;
|
||||
@ -596,7 +600,7 @@ bool WIFI_CONFIG::Enable_servers()
|
||||
data_server->setNoDelay (true);
|
||||
#endif
|
||||
#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->onEvent(webSocketEvent);
|
||||
#endif
|
||||
@ -630,15 +634,15 @@ bool WIFI_CONFIG::Enable_servers()
|
||||
SSDP.setSchemaURL ("description.xml");
|
||||
SSDP.setHTTPPort ( wifi_config.iweb_port);
|
||||
SSDP.setName (shost.c_str() );
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
stmp = String (ESP.getChipId() );
|
||||
SSDP.setModelName (ESP8266_MODEL_NAME);
|
||||
SSDP.setModelURL (ESP8266_MODEL_URL);
|
||||
#else
|
||||
#else
|
||||
stmp = String ( (uint16_t) (ESP.getEfuseMac() >> 32) );
|
||||
SSDP.setModelName (ESP32_MODEL_NAME);
|
||||
SSDP.setModelURL (ESP32_MODEL_URL);
|
||||
#endif
|
||||
#endif
|
||||
SSDP.setSerialNumber (stmp.c_str() );
|
||||
SSDP.setURL ("/");
|
||||
SSDP.setModelNumber (ESP_MODEL_NUMBER);
|
||||
@ -668,7 +672,7 @@ bool WIFI_CONFIG::Enable_servers()
|
||||
#if defined(NOTIFICATION_FEATURE)
|
||||
notificationsservice.begin();
|
||||
#endif
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
#ifdef MDNS_FEATURE
|
||||
MDNSResponder mdns;
|
||||
#endif
|
||||
bool WiFi_on;
|
||||
bool WiFi_on;
|
||||
WIFI_CONFIG();
|
||||
int iweb_port;
|
||||
int idata_port;
|
||||
|
Loading…
x
Reference in New Issue
Block a user