add feature to disable network at boot suggested by @pmjdebruijn

Add ESP114 command to handle it
This commit is contained in:
Luc 2021-06-02 20:28:47 +02:00
parent 8753249cd9
commit b4a6ca3c54
11 changed files with 104 additions and 11 deletions

View File

@ -333,6 +333,11 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
case 112:
response = ESP112(cmd_params, auth_type, output);
break;
//Get/Set boot Network (WiFi/BT/Ethernet) state which can be ON, OFF
//[ESP114]<state>pwd=<admin password>
case 114:
response = ESP114(cmd_params, auth_type, output);
break;
//Get/Set immediate Network (WiFi/BT/Ethernet) state which can be ON, OFF
//[ESP115]<state>pwd=<admin password>
case 115:

View File

@ -59,6 +59,7 @@ public:
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
bool ESP112(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP114(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP115(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //WIFI_FEATURE || BLUETOOTH_FEATURE || ETH_FEATURE
#if defined(HTTP_FEATURE)

View File

@ -116,11 +116,14 @@ bool Esp3D::begin()
log_esp3d("Main screen");
#endif //DISPLAY_DEVICE
//Setup Network
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BLUETOOTH_FEATURE)
if (Settings_ESP3D::read_byte(ESP_BOOT_RADIO_STATE) == 1){
if (!NetConfig::begin()) {
log_esp3d("Error setup network");
res = false;
}
}
#endif //WIFI_FEATURE
#if defined(ESP_AUTOSTART_SCRIPT)
esp3d_gcode_host.processscript(ESP_AUTOSTART_SCRIPT);

View File

@ -45,6 +45,7 @@ const char * help[]= {"[ESP] - display this help",
#endif //WIFI_FEATURE || ETH_FEATURE
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
"[ESP112](Hostname) - display/set Hostname",
"[ESP114](State) - display/set boot Network state which can be ON, OFF",
"[ESP115](State) - display/set immediate Network state which can be ON, OFF",
#endif //WIFI_FEATURE || ETH_FEATURE || BT_FEATURE
#if defined(HTTP_FEATURE)

View File

@ -0,0 +1,69 @@
/*
ESP114.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(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
//Set Boot radio state which can be ON, OFF
//[ESP114]<state>pwd=<user/admin password>
bool Commands::ESP114(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_BOOT_RADIO_STATE) == 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_BOOT_RADIO_STATE, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
response = false;
}
else {
output->printMSG ("ok");
}
}
}
return response;
}
#endif //defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)

View File

@ -61,6 +61,7 @@ bool Commands::ESP115(const char* cmd_params, level_authenticate_type auth_type,
response = false;
}
} else {
output->printMSG ("OFF");
NetConfig::end();
}
} else {

View File

@ -71,6 +71,14 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print (",{\"eth-sta\":\"4\"}");
#endif //ETH_FEATURE
output->print ("]}");
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined(BT_FEATURE)
//Radio State at Boot
output->print (",{\"F\":\"network/network\",\"P\":\"");
output->print (ESP_BOOT_RADIO_STATE);
output->print ("\",\"T\":\"B\",\"R\":\"1\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_BOOT_RADIO_STATE));
output->print ("\",\"H\":\"radio_boot\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
#endif //
#ifdef WIFI_FEATURE
//STA SSID network/sta
output->print (",{\"F\":\"network/sta\",\"P\":\"");

View File

@ -119,7 +119,7 @@
#define DEFAULT_NOTIFICATION_SETTINGS ""
#define DEFAULT_AUTO_NOTIFICATION_STATE 1
#define DEFAULT_SECURE_SERIAL 1
#define DEFAULT_BOOT_RADIO_STATE 1
//default int values
#define DEFAULT_ESP_INT 0L
@ -240,6 +240,9 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
{
uint8_t res;
switch(pos) {
case ESP_BOOT_RADIO_STATE:
res = DEFAULT_BOOT_RADIO_STATE;
break;
case ESP_SECURE_SERIAL:
res = DEFAULT_SECURE_SERIAL;
break;
@ -1047,6 +1050,7 @@ bool Settings_ESP3D::reset(bool networkonly)
{
//radio mode
Settings_ESP3D::write_byte(ESP_RADIO_MODE,Settings_ESP3D::get_default_byte_value(ESP_RADIO_MODE));
Settings_ESP3D::write_byte(ESP_BOOT_RADIO_STATE,Settings_ESP3D::get_default_byte_value(ESP_BOOT_RADIO_STATE));
#if defined (WIFI_FEATURE)
//STA SSID
Settings_ESP3D::write_string(ESP_STA_SSID,Settings_ESP3D::get_default_string_value(ESP_STA_SSID).c_str());

View File

@ -106,6 +106,7 @@
#define ESP_WEBDAV_PORT 1025 //4 bytes= int
#define ESP_STA_DNS_VALUE 1029 //4 bytes= int
#define ESP_SECURE_SERIAL 1033 //1 byte = flag
#define ESP_BOOT_RADIO_STATE 1034 //1 byte = flag
//Hidden password

View File

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