Code cleaning / change flag message EEPROM storage way -Need to reset settings

new command [ESP920] to configure outputs
Remove REPETIER for Davinci definition that should be pure REPETIER from now
Change FW Target ID numbering to support different Flavors more easily
Add Ini file configuration file from SD (espconf.ini) to configure ESP3D at start
Add  Target FW  ID in ESP800 command in addition to Target  FW short name
Bumb version

Warning this commit is breaking EEPROM org so - check then in webUI after
This commit is contained in:
Luc 2020-12-09 16:44:12 +01:00
parent 0072feb6d8
commit 5963eca3a6
30 changed files with 1466 additions and 84 deletions

View File

@ -79,7 +79,9 @@ function build_sketch()
sed -i "s/#define FILESYSTEM_FEATURE ESP_LITTLEFS_FILESYSTEM/#define FILESYSTEM_FEATURE ESP_SPIFFS_FILESYSTEM/g" $TRAVIS_BUILD_DIR/esp3d/configuration.h sed -i "s/#define FILESYSTEM_FEATURE ESP_LITTLEFS_FILESYSTEM/#define FILESYSTEM_FEATURE ESP_SPIFFS_FILESYSTEM/g" $TRAVIS_BUILD_DIR/esp3d/configuration.h
rm -fr $HOME/arduino_ide rm -fr $HOME/arduino_ide
rm -fr $HOME/.arduino15 rm -fr $HOME/.arduino15
platformio run platformio run -e esp32dev
sed -i "s/#define FILESYSTEM_FEATURE ESP_SPIFFS_FILESYSTEM/#define FILESYSTEM_FEATURE ESP_LITTLEFS_FILESYSTEM/g" $TRAVIS_BUILD_DIR/esp3d/configuration.h
platformio run -e esp8266dev
fi fi
} }

View File

@ -122,7 +122,7 @@ ESP_BUZZER 119 //1 byte = flag
ESP_INTERNET_TIME 120 //1 byte = flag ESP_INTERNET_TIME 120 //1 byte = flag
ESP_HTTP_PORT 121 //4 bytes = int ESP_HTTP_PORT 121 //4 bytes = int
ESP_TELNET_PORT 125 //4 bytes = int ESP_TELNET_PORT 125 //4 bytes = int
ESP_OUTPUT_FLAG 129 //1 bytes = flag ESP_SERIAL_FLAG 129 //1 bytes = flag
ESP_HOSTNAME 130 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese ESP_HOSTNAME 130 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
ESP_SENSOR_INTERVAL 164 //4 bytes = int ESP_SENSOR_INTERVAL 164 //4 bytes = int
ESP_SETTINGS_VERSION 168 //8 bytes = 7+1 = string ESP3D + 2 digits ESP_SETTINGS_VERSION 168 //8 bytes = 7+1 = string ESP3D + 2 digits
@ -131,8 +131,8 @@ ESP_USER_PWD 197 //21 bytes 20+1 = string ; warning does not su
ESP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese ESP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
ESP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese ESP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
ESP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx ESP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx
ESP_BOOT_DELAY 320 //4 bytes xxx.xxx.xxx.xxx ESP_BOOT_DELAY 320 //4 bytes = int
ESP_WEBSOCKET_PORT 324 //4 bytes xxx.xxx.xxx.xxx ESP_WEBSOCKET_PORT 324 //4 bytes= int
ESP_HTTP_ON 328 //1 byte = flag ESP_HTTP_ON 328 //1 byte = flag
ESP_TELNET_ON 329 //1 byte = flag ESP_TELNET_ON 329 //1 byte = flag
ESP_WEBSOCKET_ON 330 //1 byte = flag ESP_WEBSOCKET_ON 330 //1 byte = flag
@ -146,10 +146,10 @@ ESP_TIME_IS_DST 463 //1 bytes = flag
ESP_TIME_SERVER1 464 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese ESP_TIME_SERVER1 464 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
ESP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese ESP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
ESP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese ESP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
ESP_SD_DEVICE_TYPE 851 //1 bytes = flag ESP_PRINTER_LCD 851 //1 bytes = flag
ESP_SD_MOUNT 852 //1 bytes = flag ESP_SD_MOUNT 852 //1 bytes = flag
ESP_SESSION_TIMEOUT 853 //1 bytes = flag ESP_SESSION_TIMEOUT 853 //1 bytes = flag
ESP_DIRECT_SD_CHECK 854 //1 bytes = flag ESP_WEBSOCKET_FLAG 854 //1 bytes = flag
ESP_SD_CHECK_UPDATE_AT_BOOT 855//1 bytes = flag ESP_SD_CHECK_UPDATE_AT_BOOT 855//1 bytes = flag
ESP_NOTIFICATION_SETTINGS 856 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese ESP_NOTIFICATION_SETTINGS 856 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
ESP_CALIBRATION_1 985 //4 bytes = int ESP_CALIBRATION_1 985 //4 bytes = int
@ -157,13 +157,19 @@ ESP_CALIBRATION_2 989 //4 bytes = int
ESP_CALIBRATION_3 993 //4 bytes = int ESP_CALIBRATION_3 993 //4 bytes = int
ESP_CALIBRATION_4 997 //4 bytes = int ESP_CALIBRATION_4 997 //4 bytes = int
ESP_CALIBRATION_5 1001 //4 bytes = int ESP_CALIBRATION_5 1001 //4 bytes = int
ESP_FREE_ENTRY 1005 //4 bytes = int ESP_SETUP 1005 //1 byte = flag
ESP_TELNET_FLAG 1006 //1 byte = flag
ESP_BT_FLAG 1007 //1 byte = flag
ESP_LCD_FLAG 1008 //1 byte = flag
ESP_FTP_CTRL_PORT 1009 //4 bytes = int ESP_FTP_CTRL_PORT 1009 //4 bytes = int
ESP_FTP_DATA_ACTIVE_PORT 1013 //4 bytes = int ESP_FTP_DATA_ACTIVE_PORT 1013 //4 bytes = int
ESP_FTP_DATA_PASSIVE_PORT 1017 //4 bytes = int ESP_FTP_DATA_PASSIVE_PORT 1017 //4 bytes = int
ESP_FTP_ON 1021 //1 byte = flag ESP_FTP_ON 1021 //1 byte = flag
ESP_AUTO_NOTIFICATION 1022 //1 byte = flag ESP_AUTO_NOTIFICATION 1022 //1 byte = flag
* Get/Set Check update at boot state which can be ON, OFF
[ESP402]<state>pwd=<admin password>
*Get available AP list (limited to 30) *Get available AP list (limited to 30)
output is JSON or plain text according parameter output is JSON or plain text according parameter
[ESP410]<plain><pwd=admin/user> [ESP410]<plain><pwd=admin/user>
@ -217,3 +223,6 @@ rmdir / remove / mkdir / exists / create
* Get state / Set Enable / Disable buzzer * Get state / Set Enable / Disable buzzer
[ESP910]<ENABLE/DISABLE>[pwd=<admin/user password>] [ESP910]<ENABLE/DISABLE>[pwd=<admin/user password>]
*Get state / Set state of output message clients
[ESP910]<SERIAL / LCD / PRINTER_LCD/ WEBSOCKET / TELNET /BT / ALL>=<ON/OFF>[pwd=<admin/user password>]

141
docs/espconf.ini Normal file
View File

@ -0,0 +1,141 @@
[network]
#Hostname string of 32 chars max
hostname = myesp
#Radio mode BT, WIFI-STA, WIFI-AP, ETH-STA, OFF
radio_mode = WIFI-STA
#STA SSID string of 32 chars max
STA_SSID = myssid
#STA Password string of 64 chars max, minimum 0 or 8 chars
STA_Password = *******
#STA IP Mode DHCP / STATIC
STA_IP_mode = DHCP
#STA static IP
STA_IP = 192.168.0.2
#STA static gateway
STA_GW = 192.168.0.1
#STA static mask
STA_MSK = 255.255.255.0
#AP SSID string of 32 chars max
AP_SSID = myssid
#AP Password string of 64 chars max, minimum 0 or 8 chars
AP_Password = 12345678
#AP static IP
AP_IP = 192.168.0.1
#AP channel 1~14
AP_channel = 11
[services]
#Active or not HTTP Yes / No
HTTP_active = Yes
#HTTP Port
HTTP_Port = 80
#Active or not Telnet Yes / No
TELNET_active = Yes
#Telnet Port
TELNET_Port = 23
#Active or not WebSocket Yes / No
WebSocket_active = Yes
#WebSocket Port
WebSocket_Port = 8282
#Active or not FTP Yes / No
FTP_active = Yes
#FTP control Port
FTP_Control_Port = 21
#FTP active Port
FTP_Active_Port = 20
#FTP passive Port
FTP_Passive_Port = 55600
#Auto notification
AUTONOTIFICATION = Yes
#Notification type None / PushOver / Line / Email / Telegram
NOTIF_TYPE = None
#Notification token 1 string of 64 chars max
NOTIF_TOKEN1 =
#Notification token 2 string of 64 chars max
NOTIF_TOKEN2 =
#Notification settings string of 127 chars max
NOTIF_TOKEN_Settings=
#SD card Speed factor 1 2 4 6 8 16 32
SD_SPEED = 4
#Check update from SD Yes / No
CHECK_FOR_UPDATE = Yes
#Enable Buzzer Yes / No
Active_buzzer = yes
#Active Internet time Yes / No
Active_Internet_time = yes
#Time servers string of 127 chars max
Time_server1 = 1.pool.ntp.org
Time_server2 = 2.pool.ntp.org
Time_server3 = 3.pool.ntp.org
#time zone -12~12
Time_zone = 2
#is DST Yes/No
Time_DST = No
#Authentication passwords string of 20 chars max
ADMIN_PASSWORD = xxxxxxx
USER_PASSWORD = xxxxxxx
#session time out in min
Sesion_timeout = 3
#Sensor type if enabled None / DHT11 / DHT22 / ANALOG / BMP280 / BME280
SENSOR_TYPE = NONE
#sensor poiling interval in ms
SENSOR_INTERVAL = 30000
[system]
#Target Firmware Marlin / Repetier / MarlinKimbra / Smoothieware / GRBL
TargetFW=Marlin
#Baud Rate
Baud_rate = 115200
#Boot delay in ms
Boot_delay = 5000
#Outputs
#printer LCD
Active_Printer_LCD = Yes
#esp3d lcd
Active_ESP3D_LCD = Yes
#ESP3D Serial
Active_Serial = Yes
#Websocket
Active_WebSocket = Yes
#Telnet
Active_Telnet = Yes
#Bluetooth[ESP]
Active_BT = Yes

View File

@ -126,7 +126,7 @@
//ESP_SD_NATIVE 1 //esp32 / esp8266 //ESP_SD_NATIVE 1 //esp32 / esp8266
//ESP_SDIO 2 //esp32 only //ESP_SDIO 2 //esp32 only
//ESP_SDFAT 3 //esp8266 (same as native) / esp32 //ESP_SDFAT 3 //esp8266 (same as native) / esp32
//#define SD_DEVICE ESP_SDIO #define SD_DEVICE ESP_SD_NATIVE
//SDIO mode //SDIO mode
#define SD_ONE_BIT_MODE true #define SD_ONE_BIT_MODE true
@ -139,15 +139,17 @@
//pin if reader has insert detection feature //pin if reader has insert detection feature
//let -1 or comment if none //let -1 or comment if none
//#define ESP_SD_DETECT_PIN -1 //#define ESP_SD_DETECT_PIN 4
//value expected for ESP_SD_DETECT_PIN (0 or 1) //value expected for ESP_SD_DETECT_PIN (0 or 1)
#define ESP_SD_DETECT_VALUE 1 #define ESP_SD_DETECT_VALUE 0
//#define ESP_SD_CS_PIN 5
//FILESYSTEM_FEATURE: to host some files on flash //FILESYSTEM_FEATURE: to host some files on flash
//ESP_SPIFFS_FILESYSTEM 0 //ESP_SPIFFS_FILESYSTEM 0
//ESP_FAT_FILESYSTEM 1 //ESP_FAT_FILESYSTEM 1
//ESP_LITTLEFS_FILESYSTEM 2 //ESP_LITTLEFS_FILESYSTEM 2
#define FILESYSTEM_FEATURE ESP_SPIFFS_FILESYSTEM #define FILESYSTEM_FEATURE ESP_LITTLEFS_FILESYSTEM
//Allows to mount /FS and /SD under / for FTP server //Allows to mount /FS and /SD under / for FTP server
#define GLOBAL_FILESYSTEM_FEATURE #define GLOBAL_FILESYSTEM_FEATURE
@ -188,6 +190,9 @@
//WEB_UPDATE_FEATURE: allow to flash fw using web UI //WEB_UPDATE_FEATURE: allow to flash fw using web UI
#define WEB_UPDATE_FEATURE #define WEB_UPDATE_FEATURE
//SD_UPDATE_FEATURE: allow to flash/configure fw using SD
#define SD_UPDATE_FEATURE
//NOTIFICATION_FEATURE : allow to push notifications //NOTIFICATION_FEATURE : allow to push notifications
#define NOTIFICATION_FEATURE #define NOTIFICATION_FEATURE
@ -242,7 +247,7 @@
//DEBUG_OUTPUT_SERIAL2 3 //DEBUG_OUTPUT_SERIAL2 3
//DEBUG_OUTPUT_TELNET 4 //DEBUG_OUTPUT_TELNET 4
//DEBUG_OUTPUT_WEBSOCKET 5 //DEBUG_OUTPUT_WEBSOCKET 5
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL2 //#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
#ifdef ESP_DEBUG_FEATURE #ifdef ESP_DEBUG_FEATURE
#define DEBUG_BAUDRATE 115200 #define DEBUG_BAUDRATE 115200

View File

@ -414,6 +414,13 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
case 200: case 200:
response = ESP200(cmd_params, auth_type, output); response = ESP200(cmd_params, auth_type, output);
break; break;
#ifdef SD_UPDATE_FEATURE
//Get/Set SD Check at boot state which can be ON, OFF
//[ESP402]<state>pwd=<admin password>
case 402:
response = ESP402(cmd_params, auth_type, output);
break;
#endif //#ifdef SD_UPDATE_FEATURE
#endif //SD_DEVICE #endif //SD_DEVICE
#ifdef DIRECT_PIN_FEATURE #ifdef DIRECT_PIN_FEATURE
//Get/Set pin value //Get/Set pin value
@ -596,6 +603,11 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
response = ESP910(cmd_params, auth_type, output); response = ESP910(cmd_params, auth_type, output);
break; break;
#endif //BUZZER_DEVICE #endif //BUZZER_DEVICE
case 920:
//Get state / Set state of output message clients
//[ESP910]<SERIAL / LCD / PRINTER_LCD/ WEBSOCKET / TELNET /BT / ALL>=<ON/OFF>[pwd=<admin password>]
response = ESP920(cmd_params, auth_type, output);
break;
default: default:
output->printERROR ("Invalid Command"); output->printERROR ("Invalid Command");
response = false; response = false;

View File

@ -86,6 +86,9 @@ public:
#endif //FTP_FEATURE #endif //FTP_FEATURE
#if defined (SD_DEVICE) #if defined (SD_DEVICE)
bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#ifdef SD_UPDATE_FEATURE
bool ESP402(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //SD_UPDATE_FEATURE
#endif //SD_DEVICE #endif //SD_DEVICE
#ifdef DIRECT_PIN_FEATURE #ifdef DIRECT_PIN_FEATURE
bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
@ -137,6 +140,7 @@ public:
#endif //GLOBAL_FILESYSTEM_FEATURE #endif //GLOBAL_FILESYSTEM_FEATURE
bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP920(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#ifdef BUZZER_DEVICE #ifdef BUZZER_DEVICE
bool ESP910(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP910(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP250(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP250(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);

View File

@ -46,6 +46,9 @@
#ifdef ESP_LUA_INTERPRETER_FEATURE #ifdef ESP_LUA_INTERPRETER_FEATURE
#include "../modules/lua_interpreter/lua_interpreter_service.h" #include "../modules/lua_interpreter/lua_interpreter_service.h"
#endif //#ifdef #endif //#ifdef
#ifdef SD_UPDATE_FEATURE
#include "../modules/update/update_service.h"
#endif // SD_UPDATE_FEATURE
#include "esp3doutput.h" #include "esp3doutput.h"
#include "../modules/boot_delay/boot_delay.h" #include "../modules/boot_delay/boot_delay.h"
@ -81,6 +84,13 @@ bool Esp3D::begin()
#endif //CONNECTED_DEVICES_FEATURE #endif //CONNECTED_DEVICES_FEATURE
//delay to avoid to disturb printer //delay to avoid to disturb printer
bd.begin(); bd.begin();
#ifdef SD_UPDATE_FEATURE
if (update_service.begin()) {
log_esp3d("Need restart due to update");
//no need to continue as there was an update
restart_now();
}
#endif // SD_UPDATE_FEATURE
log_esp3d("Mode %d", WiFi.getMode()); log_esp3d("Mode %d", WiFi.getMode());
if (!Settings_ESP3D::begin()) { if (!Settings_ESP3D::begin()) {
log_esp3d("Need reset settings"); log_esp3d("Need reset settings");

View File

@ -31,7 +31,12 @@
#if defined (TELNET_FEATURE) #if defined (TELNET_FEATURE)
#include "../modules/telnet/telnet_server.h" #include "../modules/telnet/telnet_server.h"
#endif //TELNET_FEATURE #endif //TELNET_FEATURE
uint8_t ESP3DOutput::_outputflags = ESP_ALL_CLIENTS; uint8_t ESP3DOutput::_serialoutputflags = DEFAULT_SERIAL_OUTPUT_FLAG;
uint8_t ESP3DOutput::_printerlcdoutputflags = DEFAULT_PRINTER_LCD_FLAG;
uint8_t ESP3DOutput::_websocketoutputflags = DEFAULT_WEBSOCKET_FLAG;
uint8_t ESP3DOutput::_telnetoutputflags = DEFAULT_TELNET_FLAG;
uint8_t ESP3DOutput::_lcdoutputflags = DEFAULT_LCD_FLAG;
uint8_t ESP3DOutput::_BToutputflags = DEFAULT_BT_FLAG;
#if defined (HTTP_FEATURE) #if defined (HTTP_FEATURE)
#if defined (ARDUINO_ARCH_ESP32) #if defined (ARDUINO_ARCH_ESP32)
#include <WebServer.h> #include <WebServer.h>
@ -95,10 +100,29 @@ ESP3DOutput::~ESP3DOutput()
bool ESP3DOutput::isOutput(uint8_t flag, bool fromsettings) bool ESP3DOutput::isOutput(uint8_t flag, bool fromsettings)
{ {
if(fromsettings) { if(fromsettings) {
_outputflags = Settings_ESP3D::read_byte (ESP_OUTPUT_FLAG); _serialoutputflags= Settings_ESP3D::read_byte (ESP_SERIAL_FLAG);
_printerlcdoutputflags= Settings_ESP3D::read_byte (ESP_PRINTER_LCD_FLAG);
_websocketoutputflags= Settings_ESP3D::read_byte (ESP_WEBSOCKET_FLAG);
_telnetoutputflags= Settings_ESP3D::read_byte (ESP_TELNET_FLAG);
_lcdoutputflags= Settings_ESP3D::read_byte (ESP_LCD_FLAG);
_BToutputflags= Settings_ESP3D::read_byte (ESP_BT_FLAG);
}
switch(flag) {
case ESP_SERIAL_CLIENT:
return _serialoutputflags;
case ESP_PRINTER_LCD_CLIENT:
return _printerlcdoutputflags;
case ESP_WEBSOCKET_CLIENT:
return _websocketoutputflags;
case ESP_TELNET_CLIENT:
return _telnetoutputflags;
case ESP_SCREEN_CLIENT:
return _lcdoutputflags;
case ESP_BT_CLIENT:
return _BToutputflags;
default:
return true;
} }
return ((_outputflags & flag) == flag);
} }
size_t ESP3DOutput::dispatch (uint8_t * sbuf, size_t len) size_t ESP3DOutput::dispatch (uint8_t * sbuf, size_t len)
@ -251,7 +275,6 @@ size_t ESP3DOutput::printMSG(const char * s, bool withNL)
display = "M117 "; display = "M117 ";
display += s; display += s;
break; break;
case REPETIER4DV:
case SMOOTHIEWARE: case SMOOTHIEWARE:
case REPETIER: case REPETIER:
default: default:
@ -303,7 +326,6 @@ size_t ESP3DOutput::printERROR(const char * s, int code_error)
display = "error: "; display = "error: ";
display += s; display += s;
break; break;
case REPETIER4DV:
case SMOOTHIEWARE: case SMOOTHIEWARE:
case REPETIER: case REPETIER:
default: default:

View File

@ -97,7 +97,12 @@ private:
bool _footerSent; bool _footerSent;
WEBSERVER * _webserver; WEBSERVER * _webserver;
#endif //HTTP_FEATURE #endif //HTTP_FEATURE
static uint8_t _outputflags; static uint8_t _serialoutputflags;
static uint8_t _printerlcdoutputflags;
static uint8_t _websocketoutputflags;
static uint8_t _telnetoutputflags;
static uint8_t _lcdoutputflags;
static uint8_t _BToutputflags;
}; };
class ESP3DGlobalOutput class ESP3DGlobalOutput

View File

@ -94,6 +94,9 @@ const char * help[]= {"[ESP] - display this help",
"[ESP290](delay in ms) - do a pause", "[ESP290](delay in ms) - do a pause",
"[ESP400] - display ESP3D settings in JSON", "[ESP400] - display ESP3D settings in JSON",
"[ESP401]P=(position) T=(type) V=(value) - Set specific setting", "[ESP401]P=(position) T=(type) V=(value) - Set specific setting",
#ifdef SD_UPDATE_FEATURE
"[ESP402](State) - display/set check update at boot from SD which can be ON, OFF",
#endif //SD_UPDATE_FEATURE
#if defined (WIFI_FEATURE) #if defined (WIFI_FEATURE)
"[ESP410](plain) - display available AP list (limited to 30) in plain/JSON", "[ESP410](plain) - display available AP list (limited to 30) in plain/JSON",
#endif //WIFI_FEATURE #endif //WIFI_FEATURE
@ -133,6 +136,7 @@ const char * help[]= {"[ESP] - display this help",
#ifdef BUZZER_DEVICE #ifdef BUZZER_DEVICE
"[ESP910](ENABLE/DISABLE) - display/set buzzer state", "[ESP910](ENABLE/DISABLE) - display/set buzzer state",
#endif //BUZZER_DEVICE #endif //BUZZER_DEVICE
"[ESP920](client)=(ON/OFF) - display/set SERIAL / LCD / PRINTER_LCD/ WEBSOCKET / TELNET /BT / ALL client state",
"" ""
}; };
const uint cmdlist[]= {0, const uint cmdlist[]= {0,

View File

@ -462,6 +462,14 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print("\",\"T\":\"B\",\"V\":\""); output->print("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV)); output->print (Settings_ESP3D::read_byte(ESP_SD_SPEED_DIV));
output->print("\",\"H\":\"speedx\",\"O\":[{\"1\":\"1\"},{\"2\":\"2\"},{\"3\":\"3\"},{\"4\":\"4\"},{\"6\":\"6\"},{\"8\":\"8\"},{\"16\":\"16\"},{\"32\":\"32\"}]}"); output->print("\",\"H\":\"speedx\",\"O\":[{\"1\":\"1\"},{\"2\":\"2\"},{\"3\":\"3\"},{\"4\":\"4\"},{\"6\":\"6\"},{\"8\":\"8\"},{\"16\":\"16\"},{\"32\":\"32\"}]}");
#ifdef SD_UPDATE_FEATURE
//SD CHECK UPDATE AT BOOT feature
output->print(",{\"F\":\"device/sd\",\"P\":\"");
output->print(ESP_SD_CHECK_UPDATE_AT_BOOT);
output->print("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT));
output->print("\",\"H\":\"SD updater\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#endif //SD_UPDATE_FEATURE
#endif //SD_DEVICE #endif //SD_DEVICE
//Target FW //Target FW
output->print (",{\"F\":\"system/system\",\"P\":\""); output->print (",{\"F\":\"system/system\",\"P\":\"");
@ -470,8 +478,6 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print (Settings_ESP3D::read_byte(ESP_TARGET_FW)); output->print (Settings_ESP3D::read_byte(ESP_TARGET_FW));
output->print ("\",\"H\":\"targetfw\",\"O\":[{\"repetier\":\""); output->print ("\",\"H\":\"targetfw\",\"O\":[{\"repetier\":\"");
output->print (REPETIER); output->print (REPETIER);
output->print ("\"},{\"repetier4davinci\":\"");
output->print (REPETIER4DV);
output->print ("\"},{\"marlin\":\""); output->print ("\"},{\"marlin\":\"");
output->print (MARLIN); output->print (MARLIN);
output->print ("\"},{\"marlinkimbra\":\""); output->print ("\"},{\"marlinkimbra\":\"");
@ -509,25 +515,51 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print (Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY)); output->print (Settings_ESP3D::get_min_int32_value(ESP_BOOT_DELAY));
output->print ("\"}"); output->print ("\"}");
//Output flag //Output flag
output->print (",{\"F\":\"system/system\",\"P\":\""); //Serial
output->print (ESP_OUTPUT_FLAG); output->print (",{\"F\":\"system/outputmsg\",\"P\":\"");
output->print ("\",\"T\":\"F\",\"V\":\""); output->print (ESP_SERIAL_FLAG);
output->print (Settings_ESP3D::read_byte(ESP_OUTPUT_FLAG)); output->print ("\",\"T\":\"B\",\"V\":\"");
output->printf ("\",\"H\":\"outputmsg\",\"O\":[{\"M117\":\"%d\"}", ESP_PRINTER_LCD_CLIENT); output->print (Settings_ESP3D::read_byte(ESP_SERIAL_FLAG));
output->print ("\",\"H\":\"serial\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
//Printer LCD
output->print (",{\"F\":\"system/outputmsg\",\"P\":\"");
output->print (ESP_PRINTER_LCD_FLAG);
output->print ("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_PRINTER_LCD_FLAG));
output->print ("\",\"H\":\"M117\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#ifdef DISPLAY_DEVICE #ifdef DISPLAY_DEVICE
output->printf (",{\"screen\":\"%d\"}", ESP_SCREEN_CLIENT); //ESP LCD
output->print (",{\"F\":\"system/outputmsg\",\"P\":\"");
output->print (ESP_LCD_FLAG);
output->print ("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_LCD_FLAG));
output->print ("\",\"H\":\"M117\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#endif //DISPLAY_DEVICE #endif //DISPLAY_DEVICE
output->printf (",{\"serial\":\"%d\"}", ESP_SERIAL_CLIENT);
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
output->printf (",{\"ws\":\"%d\"}", ESP_WEBSOCKET_CLIENT); //Websocket
output->print (",{\"F\":\"system/outputmsg\",\"P\":\"");
output->print (ESP_WEBSOCKET_FLAG);
output->print ("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_WEBSOCKET_FLAG));
output->print ("\",\"H\":\"ws\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE #ifdef BLUETOOTH_FEATURE
output->printf (",{\"bt\":\"%d\"}", ESP_BT_CLIENT); //BT
output->print (",{\"F\":\"system/outputmsg\",\"P\":\"");
output->print (ESP_BT_FLAG);
output->print ("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_BT_FLAG));
output->print ("\",\"H\":\"BT\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#endif //BLUETOOTH_FEATURE #endif //BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE #ifdef TELNET_FEATURE
output->printf (",{\"telnet\":\"%d\"}", ESP_TELNET_CLIENT); //Telnet
output->print (",{\"F\":\"system/outputmsg\",\"P\":\"");
output->print (ESP_TELNET_FLAG);
output->print ("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_TELNET_FLAG));
output->print ("\",\"H\":\"telnet\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#endif //TELNET_FEATURE #endif //TELNET_FEATURE
output->print ("]}");
output->print ("]}"); output->print ("]}");
return true; return true;

View File

@ -70,6 +70,14 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type,
} else { } else {
//dynamique refresh is better than restart the boards //dynamique refresh is better than restart the boards
switch(spos.toInt()) { switch(spos.toInt()) {
case ESP_SERIAL_FLAG:
case ESP_PRINTER_LCD_FLAG:
case ESP_WEBSOCKET_FLAG:
case ESP_TELNET_FLAG:
case ESP_LCD_FLAG:
case ESP_BT_FLAG:
ESP3DOutput::isOutput(ESP_ALL_CLIENTS,true);
break;
case ESP_TARGET_FW: case ESP_TARGET_FW:
Settings_ESP3D::GetFirmwareTarget(true); Settings_ESP3D::GetFirmwareTarget(true);
break; break;

View File

@ -0,0 +1,67 @@
/*
ESP402.cpp - ESP3D command class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (SD_UPDATE_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
//Set SD Check at boot state which can be ON, OFF
//[ESP402]<state>pwd=<admin password>
bool Commands::ESP402(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool response = true;
String parameter;
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
parameter = get_param (cmd_params, "");
//get
if (parameter.length() == 0) {
output->printMSG((Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT) == 0)?"OFF":"ON");
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#endif //AUTHENTICATION_FEATURE
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF"))) {
output->printERROR("Only ON or OFF mode supported!");
return false;
} else {
if (!Settings_ESP3D::write_byte (ESP_SD_CHECK_UPDATE_AT_BOOT, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
response = false;
}
output->printMSG ("ok");
}
}
return response;
}
#endif //SD_UPDATE_FEATURE

View File

@ -333,7 +333,7 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
} else { } else {
output->print (": "); output->print (": ");
} }
output->print ((bt_service.started())?"ONN":"OFF"); output->print ((bt_service.started())?"ON":"OFF");
if (!plain) { if (!plain) {
output->print ("\"}"); output->print ("\"}");
} else { } else {
@ -1185,6 +1185,24 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
} else { } else {
output->printLN(""); output->printLN("");
} }
#ifdef SD_UPDATE_FEATURE
if (!plain) {
output->print (",{\"id\":\"");
}
output->print ("SD updater");
if (!plain) {
output->print ("\",\"value\":\"");
} else {
output->print (": ");
}
output->print (Settings_ESP3D::read_byte (ESP_SD_CHECK_UPDATE_AT_BOOT)!=0?"ON":"OFF");
if (!plain) {
output->print ("\"}");
} else {
output->printLN("");
}
#endif //SD_UPDATE_FEATURE
#endif //SD_DEVICE #endif //SD_DEVICE
#if defined (SENSOR_DEVICE) #if defined (SENSOR_DEVICE)
if (!plain) { if (!plain) {

View File

@ -100,6 +100,18 @@ bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type,
} else { } else {
output->print("\""); output->print("\"");
} }
//FW ID
if (plain) {
output->print("FW ID:");
} else {
output->print(",\"FWTargetID\":\"");
}
output->print(Settings_ESP3D::GetFirmwareTarget());
if(plain) {
output->printLN("");
} else {
output->print("\"");
}
//Setup done //Setup done
if (plain) { if (plain) {
output->print("Setup:"); output->print("Setup:");

View File

@ -0,0 +1,189 @@
/*
ESP910.cpp - ESP3D command class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
//Get state / Set state of output message clients
//[ESP920]<SERIAL / LCD / PRINTER_LCD/ WEBSOCKET / TELNET /BT / ALL>=<ON/OFF>[pwd=<admin password>]
bool Commands::ESP920(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool response = true;
String parameter;
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
parameter = get_param (cmd_params, "");
//get
if (parameter.length() == 0) {
String s = "SERIAL=";
s += ESP3DOutput::isOutput(ESP_SERIAL_CLIENT)?"ON":"OFF";
s += " PRINTER_LCD=";
s += ESP3DOutput::isOutput(ESP_PRINTER_LCD_CLIENT)?"ON":"OFF";
#ifdef DISPLAY_DEVICE
s += " LCD=";
s += ESP3DOutput::isOutput(ESP_SCREEN_CLIENT)?"ON":"OFF";
#endif //DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
s += " WEBSOCKET=";
s += ESP3DOutput::isOutput(ESP_WEBSOCKET_CLIENT)?"ON":"OFF";
#endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
s += " BT=";
s += ESP3DOutput::isOutput(ESP_BT_CLIENT)?"ON":"OFF";
#endif //BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
s += " TELNET=";
s += ESP3DOutput::isOutput(ESP_TELNET_CLIENT)?"ON":"OFF";
#endif //TELNET_FEATURE
output->printMSG(s.c_str());
return true;
} else { //set
response = false;
parameter = get_param (cmd_params, "SERIAL=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_SERIAL_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
parameter = get_param (cmd_params, "PRINTER_LCD=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_PRINTER_LCD_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
parameter = get_param (cmd_params, "ALL=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_SERIAL_FLAG, (parameter == "ON")?1:0)||
#ifdef DISPLAY_DEVICE
!Settings_ESP3D::write_byte (ESP_LCD_FLAG, (parameter == "ON")?1:0)||
#endif //DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
!Settings_ESP3D::write_byte (ESP_WEBSOCKET_FLAG, (parameter == "ON")?1:0)||
#endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
!Settings_ESP3D::write_byte (ESP_BT_FLAG, (parameter == "ON")?1:0)||
#endif //BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
!Settings_ESP3D::write_byte (ESP_TELNET_FLAG, (parameter == "ON")?1:0)||
#endif //TELNET_FEATURE
!Settings_ESP3D::write_byte (ESP_PRINTER_LCD_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
#ifdef DISPLAY_DEVICE
parameter = get_param (cmd_params, "LCD=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_LCD_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
#endif //DISPLAY_DEVICE
#ifdef WS_DATA_FEATURE
parameter = get_param (cmd_params, "WEBSOCKET=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_WEBSOCKET_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
#endif //WS_DATA_FEATURE
#ifdef BLUETOOTH_FEATURE
parameter = get_param (cmd_params, "BT=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_BT_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
#endif //BLUETOOTH_FEATURE
#ifdef TELNET_FEATURE
parameter = get_param (cmd_params, "TELNET=");
if (parameter.length() != 0) {
if ((parameter == "ON")|| (parameter == "OFF")) {
if (!Settings_ESP3D::write_byte (ESP_TELNET_FLAG, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
return false;
}
} else {
output->printERROR ("Incorrect command!");
return false;
}
response = true;
}
#endif //TELNET_FEATURE
//all ok we do the hot change
if(response) {
ESP3DOutput::isOutput(ESP_ALL_CLIENTS,true);
output->printMSG ("ok");
return true;
}
}
output->printERROR ("Incorrect command!");
return false;
}

View File

@ -86,6 +86,7 @@
#define DEFAULT_INTERNET_TIME 0 #define DEFAULT_INTERNET_TIME 0
#endif //TIMESTAMP_FEATURE #endif //TIMESTAMP_FEATURE
#define DEFAULT_SETUP 0 #define DEFAULT_SETUP 0
#define DEFAULT_ESP_BYTE 0 #define DEFAULT_ESP_BYTE 0
@ -104,14 +105,8 @@
#define DEFAULT_TIME_ZONE 0 #define DEFAULT_TIME_ZONE 0
#define DEFAULT_TIME_DST 0 #define DEFAULT_TIME_DST 0
#define DEFAULT_SD_MOUNT ESP_SD_ROOT #define DEFAULT_SD_MOUNT ESP_SD_ROOT
#define DEFAULT_DIRECT_SD_CHECK 0
#define DEFAULT_SD_CHECK_UPDATE_AT_BOOT 1 #define DEFAULT_SD_CHECK_UPDATE_AT_BOOT 1
#define DEFAULT_SENSOR_TYPE NO_SENSOR_DEVICE #define DEFAULT_SENSOR_TYPE NO_SENSOR_DEVICE
#ifdef SD_DEVICE
#define DEFAULT_SD_DEVICE_TYPE SD_DEVICE_CONNECTION
#else
#define DEFAULT_SD_DEVICE_TYPE ESP_NO_SD
#endif //SD_DEVICE
#define DEFAULT_HTTP_ON 1 #define DEFAULT_HTTP_ON 1
#define DEFAULT_FTP_ON 1 #define DEFAULT_FTP_ON 1
#define DEFAULT_TELNET_ON 1 #define DEFAULT_TELNET_ON 1
@ -205,9 +200,7 @@ uint8_t Settings_ESP3D::GetSDDevice()
const char* Settings_ESP3D::GetFirmwareTargetShortName() const char* Settings_ESP3D::GetFirmwareTargetShortName()
{ {
static String response; static String response;
if ( _FirmwareTarget == REPETIER4DV) { if ( _FirmwareTarget == REPETIER) {
response = F ("repetier4davinci");
} else if ( _FirmwareTarget == REPETIER) {
response = F ("repetier"); response = F ("repetier");
} else if ( _FirmwareTarget == MARLIN) { } else if ( _FirmwareTarget == MARLIN) {
response = F ("marlin"); response = F ("marlin");
@ -280,8 +273,23 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
// res = DEFAULT_SSID_VISIBLE; // res = DEFAULT_SSID_VISIBLE;
// break; // break;
#endif //WIFI_FEATURE #endif //WIFI_FEATURE
case ESP_OUTPUT_FLAG: case ESP_SERIAL_FLAG:
res = DEFAULT_OUTPUT_FLAG; res = DEFAULT_SERIAL_OUTPUT_FLAG;
break;
case ESP_PRINTER_LCD_FLAG:
res = DEFAULT_PRINTER_LCD_FLAG;
break;
case ESP_WEBSOCKET_FLAG:
res = DEFAULT_WEBSOCKET_FLAG;
break;
case ESP_TELNET_FLAG:
res = DEFAULT_TELNET_FLAG;
break;
case ESP_BT_FLAG:
res = DEFAULT_BT_FLAG;
break;
case ESP_LCD_FLAG:
res = DEFAULT_LCD_FLAG;
break; break;
#ifdef FTP_FEATURE #ifdef FTP_FEATURE
case ESP_FTP_ON: case ESP_FTP_ON:
@ -310,15 +318,9 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
case ESP_SD_MOUNT: case ESP_SD_MOUNT:
res = DEFAULT_SD_MOUNT; res = DEFAULT_SD_MOUNT;
break; break;
case ESP_DIRECT_SD_CHECK:
res = DEFAULT_DIRECT_SD_CHECK;
break;
case ESP_SD_CHECK_UPDATE_AT_BOOT: case ESP_SD_CHECK_UPDATE_AT_BOOT:
res = DEFAULT_SD_CHECK_UPDATE_AT_BOOT; res = DEFAULT_SD_CHECK_UPDATE_AT_BOOT;
break; break;
case ESP_SD_DEVICE_TYPE:
res = DEFAULT_SD_DEVICE_TYPE;
break;
#endif //SD_DEVICE #endif //SD_DEVICE
case ESP_TARGET_FW: case ESP_TARGET_FW:
res = DEFAULT_FW; res = DEFAULT_FW;
@ -1134,13 +1136,20 @@ bool Settings_ESP3D::reset()
#endif //AUTHENTICATION_FEATURE #endif //AUTHENTICATION_FEATURE
//Target FW //Target FW
Settings_ESP3D::write_byte(ESP_TARGET_FW,Settings_ESP3D::get_default_byte_value(ESP_TARGET_FW)); Settings_ESP3D::write_byte(ESP_TARGET_FW,Settings_ESP3D::get_default_byte_value(ESP_TARGET_FW));
//Output flag //Output flags
Settings_ESP3D::write_byte(ESP_OUTPUT_FLAG,Settings_ESP3D::get_default_byte_value(ESP_OUTPUT_FLAG)); Settings_ESP3D::write_byte(ESP_SERIAL_FLAG,Settings_ESP3D::get_default_byte_value(ESP_SERIAL_FLAG));
Settings_ESP3D::write_byte(ESP_PRINTER_LCD_FLAG,Settings_ESP3D::get_default_byte_value(ESP_PRINTER_LCD_FLAG));
Settings_ESP3D::write_byte(ESP_WEBSOCKET_FLAG,Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_FLAG));
Settings_ESP3D::write_byte(ESP_TELNET_FLAG,Settings_ESP3D::get_default_byte_value(ESP_TELNET_FLAG));
Settings_ESP3D::write_byte(ESP_BT_FLAG,Settings_ESP3D::get_default_byte_value(ESP_BT_FLAG));
Settings_ESP3D::write_byte(ESP_LCD_FLAG,Settings_ESP3D::get_default_byte_value(ESP_LCD_FLAG));
#ifdef SD_DEVICE #ifdef SD_DEVICE
//Direct SD
Settings_ESP3D::write_byte(ESP_SD_DEVICE_TYPE,Settings_ESP3D::get_default_byte_value(ESP_SD_DEVICE_TYPE));
//SPI SD Divider //SPI SD Divider
Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV,Settings_ESP3D::get_default_byte_value(ESP_SD_SPEED_DIV)); Settings_ESP3D::write_byte(ESP_SD_SPEED_DIV,Settings_ESP3D::get_default_byte_value(ESP_SD_SPEED_DIV));
#ifdef SD_UPDATE_FEATURE
//SD Update feature
Settings_ESP3D::write_byte(ESP_SD_CHECK_UPDATE_AT_BOOT,Settings_ESP3D::get_default_byte_value(ESP_SD_CHECK_UPDATE_AT_BOOT));
#endif //SD_UPDATE_FEATURE
#endif //SD_DEVICE #endif //SD_DEVICE
#ifdef TIMESTAMP_FEATURE #ifdef TIMESTAMP_FEATURE

View File

@ -26,13 +26,19 @@
//Supported FW ///////////////////////////////////////////////////////////// //Supported FW /////////////////////////////////////////////////////////////
#define UNKNOWN_FW 0 #define UNKNOWN_FW 0
#define REPETIER4DV 1 #define GRBL 10
#define MARLIN 2 #define MARLIN 20
#define MARLINKIMBRA 3 #define MARLINKIMBRA 35
#define SMOOTHIEWARE 4 #define SMOOTHIEWARE 40
#define REPETIER 5 #define REPETIER 50
#define GRBL 6
#define MAX_FW_ID 6 //Default flags
#define DEFAULT_SERIAL_OUTPUT_FLAG 1
#define DEFAULT_PRINTER_LCD_FLAG 1
#define DEFAULT_WEBSOCKET_FLAG 1
#define DEFAULT_TELNET_FLAG 1
#define DEFAULT_BT_FLAG 1
#define DEFAULT_LCD_FLAG 1
#define NO_NETWORK 0 #define NO_NETWORK 0
//position in EEPROM / preferences will use `P_` + <position> to make a string : P_0 for 0 //position in EEPROM / preferences will use `P_` + <position> to make a string : P_0 for 0
@ -51,7 +57,7 @@
#define ESP_INTERNET_TIME 120 //1 byte = flag #define ESP_INTERNET_TIME 120 //1 byte = flag
#define ESP_HTTP_PORT 121 //4 bytes = int #define ESP_HTTP_PORT 121 //4 bytes = int
#define ESP_TELNET_PORT 125 //4 bytes = int #define ESP_TELNET_PORT 125 //4 bytes = int
#define ESP_OUTPUT_FLAG 129 //1 bytes = flag #define ESP_SERIAL_FLAG 129 //1 bytes = flag
#define ESP_HOSTNAME 130 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese #define ESP_HOSTNAME 130 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define ESP_SENSOR_INTERVAL 164 //4 bytes = int #define ESP_SENSOR_INTERVAL 164 //4 bytes = int
#define ESP_SETTINGS_VERSION 168 //8 bytes = 7+1 = string ESP3D + 2 digits #define ESP_SETTINGS_VERSION 168 //8 bytes = 7+1 = string ESP3D + 2 digits
@ -60,8 +66,8 @@
#define ESP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese #define ESP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese
#define ESP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese #define ESP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese
#define ESP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx #define ESP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx
#define ESP_BOOT_DELAY 320 //4 bytes xxx.xxx.xxx.xxx #define ESP_BOOT_DELAY 320 //4 bytes = int
#define ESP_WEBSOCKET_PORT 324 //4 bytes xxx.xxx.xxx.xxx #define ESP_WEBSOCKET_PORT 324 //4 bytes= int
#define ESP_HTTP_ON 328 //1 byte = flag #define ESP_HTTP_ON 328 //1 byte = flag
#define ESP_TELNET_ON 329 //1 byte = flag #define ESP_TELNET_ON 329 //1 byte = flag
#define ESP_WEBSOCKET_ON 330 //1 byte = flag #define ESP_WEBSOCKET_ON 330 //1 byte = flag
@ -75,10 +81,10 @@
#define ESP_TIME_SERVER1 464 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese #define ESP_TIME_SERVER1 464 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define ESP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese #define ESP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define ESP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese #define ESP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define ESP_SD_DEVICE_TYPE 851 //1 bytes = flag #define ESP_PRINTER_LCD_FLAG 851 //1 bytes = flag
#define ESP_SD_MOUNT 852 //1 bytes = flag #define ESP_SD_MOUNT 852 //1 bytes = flag
#define ESP_SESSION_TIMEOUT 853 //1 bytes = flag #define ESP_SESSION_TIMEOUT 853 //1 bytes = flag
#define ESP_DIRECT_SD_CHECK 854 //1 bytes = flag #define ESP_WEBSOCKET_FLAG 854 //1 bytes = flag
#define ESP_SD_CHECK_UPDATE_AT_BOOT 855//1 bytes = flag #define ESP_SD_CHECK_UPDATE_AT_BOOT 855//1 bytes = flag
#define ESP_NOTIFICATION_SETTINGS 856 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese #define ESP_NOTIFICATION_SETTINGS 856 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese
#define ESP_CALIBRATION_1 985 //4 bytes = int #define ESP_CALIBRATION_1 985 //4 bytes = int
@ -87,7 +93,9 @@
#define ESP_CALIBRATION_4 997 //4 bytes = int #define ESP_CALIBRATION_4 997 //4 bytes = int
#define ESP_CALIBRATION_5 1001 //4 bytes = int #define ESP_CALIBRATION_5 1001 //4 bytes = int
#define ESP_SETUP 1005 //1 byte = flag #define ESP_SETUP 1005 //1 byte = flag
#define ESP_FREE_ENTRY 1006 //3 bytes #define ESP_TELNET_FLAG 1006 //1 byte = flag
#define ESP_BT_FLAG 1007 //1 byte = flag
#define ESP_LCD_FLAG 1008 //1 byte = flag
#define ESP_FTP_CTRL_PORT 1009 //4 bytes = int #define ESP_FTP_CTRL_PORT 1009 //4 bytes = int
#define ESP_FTP_DATA_ACTIVE_PORT 1013 //4 bytes = int #define ESP_FTP_DATA_ACTIVE_PORT 1013 //4 bytes = int
#define ESP_FTP_DATA_PASSIVE_PORT 1017 //4 bytes = int #define ESP_FTP_DATA_PASSIVE_PORT 1017 //4 bytes = int

View File

@ -63,7 +63,17 @@
#define ESP_UPLOAD_FAST_SERIAL_USB 5 #define ESP_UPLOAD_FAST_SERIAL_USB 5
#define ESP_UPLOAD_DIRECT_USB 6 #define ESP_UPLOAD_DIRECT_USB 6
//IP mode
#define DHCP_MODE 1
#define STATIC_IP_MODE 0
//Network Mode
#define ESP_RADIO_OFF 0
#define ESP_WIFI_STA 1
#define ESP_WIFI_AP 2
#define ESP_BT 3
#define ESP_ETH_STA 4
//#define ESP_ETH_SRV 5
//SD mount point //SD mount point
#define ESP_SD_ROOT 1 #define ESP_SD_ROOT 1
@ -92,6 +102,7 @@
#define ESP_SDCARD_BUSY 2 #define ESP_SDCARD_BUSY 2
//Notifications //Notifications
#define ESP_NO_NOTIFICATION 0
#define ESP_PUSHOVER_NOTIFICATION 1 #define ESP_PUSHOVER_NOTIFICATION 1
#define ESP_EMAIL_NOTIFICATION 2 #define ESP_EMAIL_NOTIFICATION 2
#define ESP_LINE_NOTIFICATION 3 #define ESP_LINE_NOTIFICATION 3

View File

@ -136,4 +136,11 @@
#endif #endif
#endif #endif
/**************************
* Update
* ***********************/
#if defined(SD_UPDATE_FEATURE) && !defined(SD_DEVICE)
#error SD_UPDATE_FEATURE is not available because SD_DEVICE is not enabled
#endif
#endif //SANITY_ESP3D_H #endif //SANITY_ESP3D_H

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H #define _VERSION_ESP3D_H
//version and sources location //version and sources location
#define FW_VERSION "3.0.0.a70" #define FW_VERSION "3.0.0.a71"
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
#endif //_VERSION_ESP3D_H #endif //_VERSION_ESP3D_H

View File

@ -32,14 +32,11 @@
#define DEFAULT_FRAME_SIZE FRAMESIZE_SVGA #define DEFAULT_FRAME_SIZE FRAMESIZE_SVGA
#define PART_BUFFER_SIZE 64
#define JPEG_COMPRESSION 80 #define JPEG_COMPRESSION 80
#define MIN_WIDTH_COMPRESSION 400 #define MIN_WIDTH_COMPRESSION 400
#define PART_BOUNDARY "123456789000000000000987654321"
Camera esp3d_camera; Camera esp3d_camera;
void Camera::handle_snap(WebServer * webserver) void Camera::handle_snap(WebServer * webserver)
{ {
log_esp3d("Camera stream reached"); log_esp3d("Camera stream reached");
@ -70,7 +67,6 @@ void Camera::handle_snap(WebServer * webserver)
bool res_error = false; bool res_error = false;
size_t _jpg_buf_len = 0; size_t _jpg_buf_len = 0;
uint8_t * _jpg_buf = NULL; uint8_t * _jpg_buf = NULL;
char * part_buf[PART_BUFFER_SIZE];
dl_matrix3du_t *image_matrix = NULL; dl_matrix3du_t *image_matrix = NULL;
webserver->sendHeader(String(F("Content-Type")), String(F("image/jpeg")),true); webserver->sendHeader(String(F("Content-Type")), String(F("image/jpeg")),true);
webserver->sendHeader(String(F("Content-Disposition")), String(F("inline; filename=capture.jpg")),true); webserver->sendHeader(String(F("Content-Disposition")), String(F("inline; filename=capture.jpg")),true);

View File

@ -44,6 +44,7 @@ void dateTime (uint16_t* date, uint16_t* dtime)
time_t getDateTimeFile(sdfat::File & filehandle) time_t getDateTimeFile(sdfat::File & filehandle)
{ {
static time_t dt = 0; static time_t dt = 0;
#ifdef SD_TIMESTAMP_FEATURE
struct tm timefile; struct tm timefile;
dir_t d; dir_t d;
if(filehandle) { if(filehandle) {
@ -65,6 +66,7 @@ time_t getDateTimeFile(sdfat::File & filehandle)
} else { } else {
log_esp3d("check file for stat failed"); log_esp3d("check file for stat failed");
} }
#endif //SD_TIMESTAMP_FEATURE
return dt; return dt;
} }
@ -637,13 +639,16 @@ bool ESP_SD::exists(const char* path)
if (strcmp(path, "/") == 0) { if (strcmp(path, "/") == 0) {
return _started; return _started;
} }
log_esp3d("%s exists ?", path);
res = SD.exists(path); res = SD.exists(path);
if (!res) { if (!res) {
log_esp3d("Seems not - trying open it");
ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ); ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ);
if (root) { if (root) {
res = root.isDirectory(); res = root.isDirectory();
} }
} }
log_esp3d("Seems %s", res?"yes":"no");
return res; return res;
} }

View File

@ -249,7 +249,7 @@ bool GcodeHost::purge(uint32_t timeout)
size_t len = serial_service.readBytes (buf, 50); size_t len = serial_service.readBytes (buf, 50);
buf[len] = '\0'; buf[len] = '\0';
log_esp3d("**\n%s\n", (const char *)buf); log_esp3d("**\n%s\n", (const char *)buf);
if ( (Settings_ESP3D::GetFirmwareTarget() == REPETIER4DV) || (Settings_ESP3D::GetFirmwareTarget() == REPETIER) || _waitwhenidle) { if ( (Settings_ESP3D::GetFirmwareTarget() == REPETIER) || _waitwhenidle) {
String s = (const char *)buf; String s = (const char *)buf;
//repetier never stop sending data so no need to wait if have 'wait' or 'busy' //repetier never stop sending data so no need to wait if have 'wait' or 'busy'
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) { if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {

View File

@ -74,7 +74,7 @@ bool HostServices::purge_serial()
size_t len = serial_service.readBytes (buf, 50); size_t len = serial_service.readBytes (buf, 50);
buf[len] = '\0'; buf[len] = '\0';
log_esp3d ("Purge: %s",(const char *)buf); log_esp3d ("Purge: %s",(const char *)buf);
if ( (Settings_ESP3D::GetFirmwareTarget() == REPETIER4DV) || (Settings_ESP3D::GetFirmwareTarget() == REPETIER) ) { if ((Settings_ESP3D::GetFirmwareTarget() == REPETIER) ) {
String s = (const char *)buf; String s = (const char *)buf;
//repetier never stop sending data so no need to wait if have 'wait' or 'busy' //repetier never stop sending data so no need to wait if have 'wait' or 'busy'
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) { if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {

View File

@ -32,17 +32,7 @@
#define MAX_HOSTNAME_LENGTH 32 #define MAX_HOSTNAME_LENGTH 32
#define MIN_HOSTNAME_LENGTH 1 #define MIN_HOSTNAME_LENGTH 1
//IP mode
#define DHCP_MODE 1
#define STATIC_IP_MODE 0
//Network Mode
#define ESP_RADIO_OFF 0
#define ESP_WIFI_STA 1
#define ESP_WIFI_AP 2
#define ESP_BT 3
#define ESP_ETH_STA 4
//#define ESP_ETH_SRV 5
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h> #include <WiFi.h>

View File

@ -0,0 +1,279 @@
/*
esp_config_file.cpp - ESP3D configuration file support class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#ifdef SD_UPDATE_FEATURE
#include "esp_config_file.h"
#include "../filesystem/esp_sd.h"
#define LINE_MAX_SIZE 255
#define SECTION_MAX_SIZE 10
#define KEY_MAX_SIZE 30
#define VALUE_MAX_SIZE 128
const char * protectedkeys[] = {"NOTIF_TOKEN1","NOTIF_TOKEN2","AP_Password","STA_Password","ADMIN_PASSWORD","USER_PASSWORD"} ;
ESP_ConfigFile::ESP_ConfigFile(const char * path, TProcessingFunction fn)
{
_filename = (char *)malloc(strlen(path)+1);
strcpy(_filename, path);
_pfunction = fn;
}
bool ESP_ConfigFile::processFile()
{
bool res = true;
if (ESP_SD::getState(true) != ESP_SDCARD_IDLE) {
log_esp3d("No SD");
return false;
}
if (!ESP_SD::exists(_filename)) {
log_esp3d("No ini file");
return false;
}
ESP_SDFile rFile = ESP_SD::open(_filename);
if (rFile) {
bool processing = true;
char line[LINE_MAX_SIZE+1];
char section[SECTION_MAX_SIZE+1]; //system / network / services
char key[KEY_MAX_SIZE+1];
uint8_t pos = 0;
line[0] = '\0';
section[0]='\0';
while (processing) {
//to handle file without endline
processing = rFile.available();
char c = '\0';
if (processing) {
c = (char)rFile.read();
if (!((c =='\n') || (c =='\r')) && (pos<(LINE_MAX_SIZE-1))) {
line[pos] = c;
pos++;
}
}
if ((c =='\n') || (c =='\r') || !processing || (pos==(LINE_MAX_SIZE-1))) {
line[pos] = '\0';
char * stmp = trimSpaces(line);
if(strlen(stmp)>0) {
//is comment ?
if (!isComment(stmp)) {
//is section ?
if(isSection(stmp)) {
strcpy(section,getSectionName(stmp));
} else {
//is key + value?
if (isValue(stmp) && strlen(section)>0) {
strcpy(key,getKeyName(stmp));
if(_pfunction) {
if(!_pfunction(section, key, getValue(stmp))) {
res=false;
}
}
}
}
}
}
pos = 0;
line[pos] = '\0';
}
}
rFile.close();
return res;
}
log_esp3d("Cannot open ini file");
return false;
}
bool ESP_ConfigFile::isComment(char * line)
{
if (strlen(line) > 0) {
if((line[0]==';') || (line[0]=='#')) {
return true;
}
}
return false;
}
bool ESP_ConfigFile::isSection(char * line)
{
if (strlen(line) > 0) {
if((line[0]=='[') && (line[strlen(line)-1]==']')) {
return true;
}
}
return false;
}
bool ESP_ConfigFile::isValue(char * line)
{
if (strlen(line) > 3) {
for(uint8_t i = 1; i < strlen(line)-2; i++) {
if(line[i]=='=') {
return true;
}
}
}
return false;
}
char * ESP_ConfigFile::getSectionName(char * line)
{
line[strlen(line)-1]='\0';
return trimSpaces(&line[1],SECTION_MAX_SIZE);
}
char * ESP_ConfigFile::getKeyName(char * line)
{
for(uint8_t i = 0; i < strlen(line); i++) {
if (line[i]=='=') {
line[i]='\0';
return trimSpaces(line,KEY_MAX_SIZE);
}
}
return NULL;
}
char * ESP_ConfigFile::getValue(char * line)
{
char * startptr = line + strlen(line)+1;
while ( * startptr == '\0') {
startptr++;
}
return trimSpaces(startptr,VALUE_MAX_SIZE);
}
char * ESP_ConfigFile::trimSpaces(char * line, uint8_t maxsize)
{
char *endptr = line + strlen(line) - 1;
char * startptr = line;
while (endptr >= line && isspace(*endptr)) {
*endptr-- = '\0';
}
endptr = line + strlen(line) - 1;
while (endptr != startptr && isspace(*startptr)) {
startptr++;
}
if((maxsize>0) && (strlen(startptr)> maxsize)) {
startptr[maxsize]='\0';
}
return startptr;
}
ESP_ConfigFile::~ESP_ConfigFile()
{
free(_filename);
}
bool ESP_ConfigFile::isScrambleKey(const char *key, const char * str)
{
if (strlen(key)>strlen(str)) {
return false;
}
for(uint8_t p = 0; p< strlen(str) ; p++) {
if (p <strlen(key)) {
if(key[p]!=str[p]) {
return false;
}
} else {
if (str[p]!=' ') {
if (str[p]=='=') {
return true;
} else {
return false;
}
}
}
}
return false;
}
bool ESP_ConfigFile::revokeFile()
{
char * filename;
if (!ESP_SD::exists(_filename)) {
log_esp3d("No ini file to revoke");
return false;
}
filename = (char *)malloc(strlen(_filename)+1);
strcpy(filename, _filename);
filename[strlen(filename)-3]='o';
filename[strlen(filename)-2]='k';
filename[strlen(filename)-1]='\0';
ESP_SD::remove(filename);
ESP_SDFile wFile = ESP_SD::open(filename, ESP_FILE_WRITE);
ESP_SDFile rFile = ESP_SD::open(_filename);
free(filename);
if (wFile && rFile) {
bool processing = true;
char line[LINE_MAX_SIZE+1];
uint8_t pos = 0;
line[0] = '\0';
while (processing) {
processing = rFile.available();
char c = '\0';
if (processing) {
c = (char)rFile.read();
if (!((c =='\n') || (c =='\r')) && (pos<(LINE_MAX_SIZE-1))) {
line[pos] = c;
pos++;
}
}
if ((c =='\n') || (c =='\r') || !processing || (pos==(LINE_MAX_SIZE-1))) {
line[pos] = '\0';
char * stmp = trimSpaces(line);
if (strlen(stmp) > 0 ) {
if(sizeof(protectedkeys) > 0) {
bool foundscramble = false;
uint8_t size = sizeof(protectedkeys)/sizeof(char*);
for(uint8_t i = 0; (i < size) && !foundscramble; i++) {
if (isScrambleKey(protectedkeys[i],stmp)) {
strcpy(line, protectedkeys[i]);
strcat(line, "=********");
stmp = line;
foundscramble = true;
}
}
}
wFile.write((const uint8_t *)stmp, strlen(stmp));
wFile.write('\r');
wFile.write('\n');
}
pos = 0;
line[pos] = '\0';
}
}
wFile.close();
rFile.close();
ESP_SD::remove(_filename);
return true;
}
log_esp3d("Cannot open / create revoked file");
if (wFile ) {
wFile.close();
}
if (rFile ) {
rFile.close();
}
return false;
}
#endif //SD_UPDATE_FEATURE

View File

@ -0,0 +1,46 @@
/*
esp_config_file.h - ESP3D configuration file support class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _ESP_CONFIG_FILE_H
#define _ESP_CONFIG_FILE_H
#include <Arduino.h>
typedef std::function<bool(const char*, const char*,const char*)> TProcessingFunction;
class ESP_ConfigFile
{
public:
ESP_ConfigFile(const char * path, TProcessingFunction fn);
~ESP_ConfigFile();
char * trimSpaces(char * line, uint8_t maxsize=0);
bool isComment(char * line);
bool isSection(char * line);
bool isValue(char * line);
char * getSectionName(char * line);
char * getKeyName(char * line);
char * getValue(char * line);
bool processFile();
bool revokeFile();
private:
bool isScrambleKey(const char *key, const char * str);
char * _filename;
TProcessingFunction _pfunction;
};
#endif //_ESP_CONFIG_FILE_H

View File

@ -0,0 +1,451 @@
/*
update_service.cpp - update services functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#ifdef SD_UPDATE_FEATURE
#include "update_service.h"
#include "../../core/settings_esp3d.h"
#include "../../core/esp3doutput.h"
#include "../../core/commands.h"
#include "esp_config_file.h"
UpdateService update_service;
#define CONFIG_FILE "/espconf.ini"
const char * NetstringKeysVal[] = {"hostname",
"STA_SSID",
"STA_Password",
"AP_SSID",
"AP_Password"
} ;
const uint16_t NetstringKeysPos[] = {ESP_HOSTNAME,
ESP_STA_SSID,
ESP_STA_PASSWORD,
ESP_AP_SSID,
ESP_AP_PASSWORD
} ;
const char * ServstringKeysVal[] = {
"Time_server1",
"Time_server2",
"Time_server3",
"ADMIN_PASSWORD",
"USER_PASSWORD",
"NOTIF_TOKEN1",
"NOTIF_TOKEN2",
"NOTIF_TOKEN_Settings"
} ;
const uint16_t ServstringKeysPos[] = {
ESP_TIME_SERVER1,
ESP_TIME_SERVER2,
ESP_TIME_SERVER3,
ESP_ADMIN_PWD,
ESP_USER_PWD,
ESP_NOTIFICATION_TOKEN1,
ESP_NOTIFICATION_TOKEN2,
ESP_NOTIFICATION_SETTINGS
} ;
const char * IPKeysVal[] = {"STA_IP",
"STA_GW",
"STA_MSK",
"AP_IP"
} ;
const uint16_t IPKeysPos[] = {ESP_STA_IP_VALUE,
ESP_STA_MASK_VALUE,
ESP_STA_GATEWAY_VALUE,
ESP_AP_IP_VALUE
} ;
const char * ServintKeysVal[] = {
"HTTP_Port",
"TELNET_Port",
"SENSOR_INTERVAL",
"WebSocket_Port",
"FTP_Control_Port",
"FTP_Active_Port ",
"FTP_Passive_Port"
} ;
const uint16_t ServintKeysPos[] = {
ESP_HTTP_PORT,
ESP_TELNET_PORT,
ESP_SENSOR_INTERVAL,
ESP_WEBSOCKET_PORT,
ESP_FTP_CTRL_PORT,
ESP_FTP_DATA_ACTIVE_PORT,
ESP_FTP_DATA_PASSIVE_PORT
} ;
const char * SysintKeysVal[] = {"Baud_rate",
"Boot_delay"
} ;
const uint16_t SysintKeysPos[] = {ESP_BAUD_RATE,
ESP_BOOT_DELAY
} ;
const char * ServboolKeysVal[] = {"HTTP_active",
"TELNET_active",
"WebSocket_active",
"Time_DST",
"CHECK_FOR_UPDATE",
"Active_buzzer",
"Active_Internet_time"
} ;
const uint16_t ServboolKeysPos[] = {ESP_HTTP_ON,
ESP_TELNET_ON,
ESP_WEBSOCKET_ON,
ESP_TIME_IS_DST,
ESP_SD_CHECK_UPDATE_AT_BOOT,
ESP_BUZZER,
ESP_INTERNET_TIME
} ;
const char * SysboolKeysVal[] = {"Active_Printer_LCD",
"Active_ESP3D_LCD",
"Active_Serial ",
"Active_WebSocket",
"Active_Telnet",
"Active_BT"
} ;
const uint16_t SysboolKeysPos[] = {ESP_PRINTER_LCD_FLAG,
ESP_LCD_FLAG,
ESP_SERIAL_FLAG,
ESP_WEBSOCKET_FLAG,
ESP_TELNET_FLAG,
ESP_BT_FLAG
} ;
const char * NetbyteKeysVal[] = {
"AP_channel"
} ;
const uint16_t NetbyteKeysPos[] = {
ESP_AP_CHANNEL
} ;
const char * ServbyteKeysVal[] = {"Time_zone",
"Sesion_timeout",
"SD_SPEED",
"Time_DST"
} ;
const uint16_t ServbyteKeysPos[] = {ESP_TIMEZONE,
ESP_SESSION_TIMEOUT,
ESP_SD_SPEED_DIV
} ;
//Parsing all entries of file once is faster that checking all possible parameters for each line of file
bool processingFileFunction (const char * section, const char * key, const char * value)
{
bool res = true;
char T = '\0';
int P = -1;
uint32_t v = 0;
byte b = 0;
bool done=false;
uint8_t size = 0;
log_esp3d("[%s]%s=%s",section, key,value);
//network / services / system sections
if (strcasecmp("network",section)==0) {
size = sizeof(NetstringKeysVal)/sizeof(char*);
//Look in string entries
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(NetstringKeysVal[i],key)==0) {
//if it is a previouly saved scrambled password ignore it
if (strcasecmp(value,"********")!=0) {
T='S';
P=NetstringKeysPos[i];
done=true;
}
}
}
if (!done) {
size = sizeof(IPKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(IPKeysVal[i],key)==0) {
T='A';
P=IPKeysPos[i];
v=String(value).toInt();
done=true;
}
}
}
if (!done) {
size = sizeof(NetbyteKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(NetbyteKeysVal[i],key)==0) {
T='B';
P=NetbyteKeysPos[i];
b=String(value).toInt();
done=true;
}
}
}
//Radio mode BT, WIFI-STA, WIFI-AP, ETH-STA, OFF
if (!done) {
if (strcasecmp("radio_mode",key)==0) {
T='B';
P=ESP_RADIO_MODE;
done = true;
if (strcasecmp("BT",value)==0) {
b=ESP_BT;
} else if (strcasecmp("WIFI-STA",value)==0) {
b=ESP_WIFI_STA;
} else if (strcasecmp("WIFI-AP",value)==0) {
b=ESP_WIFI_AP;
} else if (strcasecmp("ETH-STA",value)==0) {
b=ESP_ETH_STA;
} else if (strcasecmp("OFF",value)==0) {
b=ESP_RADIO_OFF;
} else {
P=-1; //invalide value
}
}
}
//STA IP Mode DHCP / STATIC
if (!done) {
if (strcasecmp("STA_IP_mode",key)==0) {
T='B';
P=ESP_STA_IP_MODE;
done = true;
if (strcasecmp("DHCP",value)==0) {
b=DHCP_MODE;
} else if (strcasecmp("STATIC",key)==0) {
b=STATIC_IP_MODE;
} else {
P=-1; //invalide value
}
}
}
} else if (strcasecmp("services",section)==0) {
size = sizeof(ServstringKeysVal)/sizeof(char*);
//Look in string entries
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(ServstringKeysVal[i],key)==0) {
//if it is a previouly saved scrambled password ignore it
if (strcasecmp(value,"********")!=0) {
T='S';
P=ServstringKeysPos[i];
done=true;
}
}
}
if (!done) {
size = sizeof(ServintKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(ServintKeysVal[i],key)==0) {
T='I';
P=ServintKeysPos[i];
done=true;
}
}
}
if (!done) {
size = sizeof(ServboolKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(ServboolKeysVal[i],key)==0) {
T='B';
P=ServboolKeysPos[i];
if ((strcasecmp("yes",value)==0)||(strcasecmp("true", value)==0)||(strcasecmp("1", value)==0) ) {
b = 1;
} else if ((strcasecmp("no", value)==0)||(strcasecmp("false", value)==0)||(strcasecmp("0", value)==0) ) {
b = 0;
} else {
P=-1;
}
done=true;
}
}
}
if (!done) {
size = sizeof(ServbyteKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(ServbyteKeysVal[i],key)==0) {
T='B';
P=ServbyteKeysPos[i];
b=String(value).toInt();
done=true;
}
}
}
//Notification type None / PushOver / Line / Email / Telegram
if (!done) {
if (strcasecmp("NOTIF_TYPE",key)==0) {
T='B';
P=ESP_NOTIFICATION_TYPE;
done = true;
if (strcasecmp("None",value)==0) {
b=ESP_NO_NOTIFICATION;
} else if (strcasecmp("PushOver",value)==0) {
b=ESP_PUSHOVER_NOTIFICATION;
} else if (strcasecmp("Line",value)==0) {
b=ESP_LINE_NOTIFICATION;
} else if (strcasecmp("Email",value)==0) {
b=ESP_EMAIL_NOTIFICATION;
} else if (strcasecmp("Telegram",value)==0) {
b=ESP_TELEGRAM_NOTIFICATION;
} else {
P=-1; //invalide value
}
}
}
//Sensor type if enabled None / DHT11 / DHT22 / ANALOG / BMP280 / BME280
if (!done) {
if (strcasecmp("SENSOR_TYPE",key)==0) {
T='B';
P=ESP_SENSOR_TYPE;
done = true;
if (strcasecmp("None",value)==0) {
b=NO_SENSOR_DEVICE;
} else if (strcasecmp("DHT11",key)==0) {
b=DHT11_DEVICE;
} else if (strcasecmp("DHT22",key)==0) {
b=DHT22_DEVICE;
} else if (strcasecmp("ANALOG",key)==0) {
b=ANALOG_DEVICE;
} else if (strcasecmp("BMP280",key)==0) {
b=BMP280_DEVICE;
} else if (strcasecmp("BME280",key)==0) {
b=BME280_DEVICE;
} else {
P=-1; //invalide value
}
}
}
}
if (strcasecmp("system",section)==0) {
if (!done) {
size = sizeof(SysintKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(SysintKeysVal[i],key)==0) {
T='I';
P=SysintKeysPos[i];
done=true;
}
}
}
if (!done) {
size = sizeof(SysboolKeysVal)/sizeof(char*);
for(uint i=0; i< size && !done; i++) {
if (strcasecmp(SysboolKeysVal[i],key)==0) {
T='B';
P=SysboolKeysPos[i];
if ((strcasecmp("yes",value)==0)||(strcasecmp("true", value)==0)||(strcasecmp("1", value)==0) ) {
b = 1;
} else if ((strcasecmp("no", value)==0)||(strcasecmp("false", value)==0)||(strcasecmp("0", value)==0) ) {
b = 0;
} else {
P=-1;
}
done=true;
}
}
}
//Target Firmware None / Marlin / Repetier / MarlinKimbra / Smoothieware / GRBL
if (!done) {
if (strcasecmp("TargetFW",key)==0) {
T='B';
P=ESP_TARGET_FW;
done = true;
if (strcasecmp("None",value)==0) {
b=UNKNOWN_FW;
} else if (strcasecmp("MARLIN",value)==0) {
b=MARLIN;
} else if (strcasecmp("MARLINKIMBRA",value)==0) {
b=MARLINKIMBRA;
} else if (strcasecmp("GRBL",value)==0) {
b=GRBL;
} else if (strcasecmp("REPETIER",value)==0) {
b=REPETIER;
} else if (strcasecmp("SMOOTHIEWARE",value)==0) {
b=SMOOTHIEWARE;
} else {
P=-1; //invalide value
}
}
}
}
//now we save -handle saving status
//if setting is not recognized it is not a problem
//but if save is fail - that is a problem - so report it
if(P!=-1) {
switch(T) {
case 'S':
log_esp3d("Saving setting to ESP3D");
res = Settings_ESP3D::write_string (P, value);
break;
case 'B':
case 'F':
res = Settings_ESP3D::write_byte (P, b);
break;
case 'I':
res = Settings_ESP3D::write_uint32 (P, v);
break;
case 'A':
res = Settings_ESP3D::write_IP_String (P, value);
break;
default:
log_esp3d("Unknown flag");
}
}
return res;
}
UpdateService::UpdateService() {}
UpdateService::~UpdateService() {}
bool UpdateService::begin()
{
if(Settings_ESP3D::read_byte(ESP_SD_CHECK_UPDATE_AT_BOOT)!=0) {
log_esp3d("Update SD for update requestest");
ESP_ConfigFile updateConfig(CONFIG_FILE, processingFileFunction);
if (updateConfig.processFile()) {
log_esp3d("Processing ini file done");
if(updateConfig.revokeFile()) {
log_esp3d("Revoking ini file done");
return true;
} else {
log_esp3d("Revoking ini file failed");
}
} else {
log_esp3d("Processing ini file done");
}
log_esp3d("Update failed");
return false;
}
log_esp3d("No need to check for update");
return false;
}
void UpdateService::end()
{
}
void UpdateService::handle() {}
#endif //SD_UPDATE_FEATURE

View File

@ -0,0 +1,40 @@
/*
update_service.h - update services functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _UPDATE_SERVICES_H
#define _UPDATE_SERVICES_H
class UpdateService
{
public:
UpdateService();
~UpdateService();
void handle();
bool begin();
void end();
private:
};
extern UpdateService update_service;
#endif //_UPDATE_SERVICES_H