mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-01 10:23:19 +02:00
More #define removal
.. by creating stub classes for bluetooth and wifi things
This commit is contained in:
@@ -65,6 +65,12 @@ SSD1306Wire display(OLED_ADDRESS, OLED_SDA, OLED_SCL, OLED_GEOMETRY);
|
||||
|
||||
static TaskHandle_t displayUpdateTaskHandle = 0;
|
||||
|
||||
//Radio Mode
|
||||
const int ESP_RADIO_OFF = 0;
|
||||
const int ESP_WIFI_STA = 1;
|
||||
const int ESP_WIFI_AP = 2;
|
||||
const int ESP_BT = 3;
|
||||
|
||||
// This displays the status of the ESP32 Radios...BT, WiFi, etc
|
||||
void displayRadioInfo() {
|
||||
String radio_addr = "";
|
||||
|
@@ -89,29 +89,6 @@ const char* const DEFAULT_ADMIN_LOGIN = "admin";
|
||||
const char* const DEFAULT_USER_LOGIN = "user";
|
||||
#endif
|
||||
|
||||
//Radio Mode
|
||||
const int ESP_RADIO_OFF = 0;
|
||||
const int ESP_WIFI_STA = 1;
|
||||
const int ESP_WIFI_AP = 2;
|
||||
const int ESP_BT = 3;
|
||||
|
||||
//Default mode
|
||||
#ifdef ENABLE_WIFI
|
||||
# ifdef CONNECT_TO_SSID
|
||||
const int DEFAULT_RADIO_MODE = ESP_WIFI_STA;
|
||||
# else
|
||||
const int DEFAULT_RADIO_MODE = ESP_WIFI_AP;
|
||||
# endif //CONNECT_TO_SSID
|
||||
#else
|
||||
|
||||
// TODO FIXME!
|
||||
# ifdef ENABLE_BLUETOOTH
|
||||
const int DEFAULT_RADIO_MODE = ESP_BT;
|
||||
# else
|
||||
const int DEFAULT_RADIO_MODE = ESP_RADIO_OFF;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Number of homing cycles performed after when the machine initially jogs to limit switches.
|
||||
// This help in preventing overshoot and should improve repeatability. This value should be one or
|
||||
// greater.
|
||||
@@ -206,13 +183,6 @@ const int REPORT_WCO_REFRESH_IDLE_COUNT = 10; // (2-255) Must be less than or e
|
||||
// certain the step segment buffer is increased/decreased to account for these changes.
|
||||
const int ACCELERATION_TICKS_PER_SECOND = 100;
|
||||
|
||||
// Sets the maximum step rate allowed to be written as a Grbl setting. This option enables an error
|
||||
// check in the settings module to prevent settings values that will exceed this limitation. The maximum
|
||||
// step rate is strictly limited by the CPU speed and will change if something other than an AVR running
|
||||
// at 16MHz is used.
|
||||
// NOTE: For now disabled, will enable if flash space permits.
|
||||
// #define MAX_STEP_RATE_HZ 30000 // Hz
|
||||
|
||||
// Sets which axis the tool length offset is applied. Assumes the spindle is always parallel with
|
||||
// the selected axis with the tool oriented toward the negative direction. In other words, a positive
|
||||
// tool length offset value is subtracted from the current location.
|
||||
@@ -338,23 +308,3 @@ const double PARKING_RATE = 800.0; // Parking fast rate after pull
|
||||
const double PARKING_PULLOUT_RATE = 250.0; // Pull-out/plunge slow feed rate in mm/min.
|
||||
const double PARKING_PULLOUT_INCREMENT = 5.0; // Spindle pull-out and plunge distance in mm. Incremental distance.
|
||||
// Must be positive value or equal to zero.
|
||||
|
||||
// Enables a piecewise linear model of the spindle PWM/speed output. Requires a solution by the
|
||||
// 'fit_nonlinear_spindle.py' script in the /doc/script folder of the repo. See file comments
|
||||
// on how to gather spindle data and run the script to generate a solution.
|
||||
// #define ENABLE_PIECEWISE_LINEAR_SPINDLE // Default disabled. Uncomment to enable.
|
||||
|
||||
// N_PIECES, RPM_MAX, RPM_MIN, RPM_POINTxx, and RPM_LINE_XX constants are all set and given by
|
||||
// the 'fit_nonlinear_spindle.py' script solution. Used only when ENABLE_PIECEWISE_LINEAR_SPINDLE
|
||||
// is enabled. Make sure the constant values are exactly the same as the script solution.
|
||||
// NOTE: When N_PIECES < 4, unused RPM_LINE and RPM_POINT defines are not required and omitted.
|
||||
/*
|
||||
#define N_PIECES 4 // Integer (1-4). Number of piecewise lines used in script solution.
|
||||
#define RPM_MAX 11686.4 // Max RPM of model. $30 > RPM_MAX will be limited to RPM_MAX.
|
||||
#define RPM_MIN 202.5 // Min RPM of model. $31 < RPM_MIN will be limited to RPM_MIN.
|
||||
*/
|
||||
|
||||
const int N_PIECES = 3;
|
||||
|
||||
const double RPM_MAX = 23935.2;
|
||||
const double RPM_MIN = 2412.2;
|
||||
|
@@ -41,8 +41,6 @@ void grbl_init() {
|
||||
info_serial("Grbl_ESP32 Ver %s Date %s", GRBL_VERSION, GRBL_VERSION_BUILD); // print grbl_esp32 verion info
|
||||
info_serial("Compiled with ESP32 SDK:%s", ESP.getSdkVersion()); // print the SDK version
|
||||
// show the map name at startup
|
||||
report_machine_type(CLIENT_SERIAL);
|
||||
|
||||
if (!SPIFFS.begin(true)) {
|
||||
log_error("Cannot mount the local filesystem");
|
||||
}
|
||||
@@ -53,7 +51,7 @@ void grbl_init() {
|
||||
config->load(config_filename->get());
|
||||
make_grbl_commands();
|
||||
|
||||
info_serial("Name: %s", config->_name.c_str());
|
||||
report_machine_type(CLIENT_SERIAL);
|
||||
info_serial("Board: %s", config->_board.c_str());
|
||||
|
||||
if (config->_i2so) {
|
||||
@@ -114,17 +112,10 @@ void grbl_init() {
|
||||
limits_init();
|
||||
config->_probe->init();
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
info_serial("Initializing WiFi...");
|
||||
WebUI::wifi_config.begin();
|
||||
#endif
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
info_serial("Initializing Bluetooth...");
|
||||
|
||||
if (config->_comms->_bluetoothConfig) {
|
||||
config->_comms->_bluetoothConfig->begin();
|
||||
}
|
||||
#endif
|
||||
WebUI::inputBuffer.begin();
|
||||
} catch (const AssertionFailed& ex) {
|
||||
// This means something is terribly broken:
|
||||
|
@@ -70,12 +70,11 @@ const char* const GRBL_VERSION_BUILD = "20210326";
|
||||
// Do not guard this because it is needed for local files too
|
||||
#include "SDCard.h"
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
# include "WebUI/WifiConfig.h"
|
||||
# include "WebUI/Serial2Socket.h"
|
||||
# include "WebUI/TelnetServer.h"
|
||||
# include "WebUI/NotificationsService.h"
|
||||
#endif
|
||||
// These WebUI components create stub classes if not enabled
|
||||
#include "WebUI/WifiConfig.h"
|
||||
#include "WebUI/TelnetServer.h"
|
||||
#include "WebUI/Serial2Socket.h"
|
||||
#include "WebUI/NotificationsService.h"
|
||||
|
||||
#include "I2SOut.h"
|
||||
|
||||
|
@@ -282,11 +282,6 @@ class Communications : public Configuration::Configurable {
|
||||
public:
|
||||
Communications() = default;
|
||||
|
||||
// Passwords don't belong in a YAML!
|
||||
//
|
||||
// String _userPassword = "";
|
||||
// String _adminPassword = "";
|
||||
|
||||
bool _telnetEnable = true;
|
||||
int _telnetPort = 23;
|
||||
|
||||
@@ -295,18 +290,20 @@ public:
|
||||
|
||||
String _hostname = "grblesp";
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
WebUI::BTConfig* _bluetoothConfig = nullptr;
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
WifiAPConfig* _apConfig = nullptr;
|
||||
WifiSTAConfig* _staConfig = nullptr;
|
||||
#endif
|
||||
WifiAPConfig* _apConfig = nullptr;
|
||||
WifiSTAConfig* _staConfig = nullptr;
|
||||
|
||||
void group(Configuration::HandlerBase& handler) override {
|
||||
// handler.item("user_password", _userPassword);
|
||||
// handler.item("admin_password", _adminPassword);
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
// If BT is not compiled in, attempts to configure it will be ignored,
|
||||
// but the BTConfig class methods that might be called from elsewhere
|
||||
// exist in an stub class implementation, so the compiler will not
|
||||
// complain. This lets us minimize the number of ifdefs to this one
|
||||
// plus a couple in BTConfig.h and BTConfig.cpp which select either
|
||||
// the real BTConfig class or the stub version.
|
||||
handler.section("bluetooth", _bluetoothConfig);
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
handler.item("telnet_enable", _telnetEnable);
|
||||
handler.item("telnet_port", _telnetPort);
|
||||
@@ -315,25 +312,15 @@ public:
|
||||
handler.item("http_port", _httpPort);
|
||||
|
||||
handler.item("hostname", _hostname);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
handler.section("bluetooth", _bluetoothConfig);
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
handler.section("wifi_ap", _apConfig);
|
||||
handler.section("wifi_sta", _staConfig);
|
||||
#endif
|
||||
}
|
||||
|
||||
~Communications() {
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
delete _bluetoothConfig;
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
delete _apConfig;
|
||||
delete _staConfig;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -417,18 +404,3 @@ public:
|
||||
};
|
||||
|
||||
extern MachineConfig* config;
|
||||
|
||||
inline bool hasWiFi() {
|
||||
#ifdef ENABLE_WIFI
|
||||
return config && config->_comms && (config->_comms->_staConfig != nullptr || config->_comms->_apConfig != nullptr);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
inline bool hasBluetooth() {
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
return !hasWiFi() && (config && config->_comms && config->_comms->_bluetoothConfig != nullptr);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
@@ -39,11 +39,9 @@ void show_setting(const char* name, const char* value, const char* description,
|
||||
}
|
||||
|
||||
void settings_restore(uint8_t restore_flag) {
|
||||
#ifdef ENABLE_WIFI
|
||||
if (restore_flag & SettingsRestore::Wifi) {
|
||||
WebUI::wifi_config.reset_settings();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (restore_flag & SettingsRestore::Defaults) {
|
||||
bool restore_startup = restore_flag & SettingsRestore::StartupLines;
|
||||
|
@@ -147,11 +147,8 @@ void error_serial(const char* format, ...) {
|
||||
va_end(arg);
|
||||
}
|
||||
|
||||
//function to notify
|
||||
void grbl_notify(const char* title, const char* msg) {
|
||||
#ifdef ENABLE_WIFI
|
||||
WebUI::notificationsservice.sendMSG(title, msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
void grbl_notifyf(const char* title, const char* format, ...) {
|
||||
@@ -543,41 +540,30 @@ void report_build_info(const char* line, uint8_t client) {
|
||||
if (ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES) {
|
||||
grbl_send(client, "A");
|
||||
}
|
||||
if (hasBluetooth()) {
|
||||
grbl_send(client, "B");
|
||||
}
|
||||
grbl_send(client, config->_comms->_bluetoothConfig ? "B" : "");
|
||||
grbl_send(client, "S");
|
||||
if (config->_enableParkingOverrideControl) {
|
||||
grbl_send(client, "R");
|
||||
}
|
||||
#ifdef ENABLE_WIFI
|
||||
grbl_send(client, "W");
|
||||
#endif
|
||||
grbl_send(client, FORCE_BUFFER_SYNC_DURING_NVS_WRITE ? "" : "E"); // Shown when disabled
|
||||
grbl_send(client, FORCE_BUFFER_SYNC_DURING_WCO_CHANGE ? "" : "W"); // Shown when disabled.
|
||||
|
||||
grbl_send(client, "*"); // wipe all
|
||||
grbl_send(client, "$"); // deft settings
|
||||
grbl_send(client, "#"); // clear parameters
|
||||
|
||||
if (FORCE_BUFFER_SYNC_DURING_NVS_WRITE) // NOTE: Shown when disabled.
|
||||
{
|
||||
grbl_send(client, "E");
|
||||
}
|
||||
if (FORCE_BUFFER_SYNC_DURING_WCO_CHANGE) // NOTE: Shown when disabled.
|
||||
{
|
||||
grbl_send(client, "W");
|
||||
}
|
||||
// NOTE: Compiled values, like override increments/max/min values, may be added at some point later.
|
||||
// These will likely have a comma delimiter to separate them.
|
||||
grbl_send(client, "]\r\n");
|
||||
|
||||
report_machine_type(client);
|
||||
#ifdef ENABLE_WIFI
|
||||
grbl_send(client, (char*)WebUI::wifi_config.info());
|
||||
#endif
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
grbl_send(client, config->_comms->_bluetoothConfig->info().c_str());
|
||||
String info;
|
||||
info = WebUI::wifi_config.info();
|
||||
if (info.length()) {
|
||||
info_client(client, info.c_str());
|
||||
}
|
||||
if (config->_comms->_bluetoothConfig) {
|
||||
info = config->_comms->_bluetoothConfig->info();
|
||||
if (info.length()) {
|
||||
info_client(client, info.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Prints the character string line Grbl has received from the user, which has been pre-parsed,
|
||||
@@ -623,17 +609,14 @@ void report_realtime_status(uint8_t client) {
|
||||
// Returns planner and serial read buffer states.
|
||||
if (bit_istrue(status_mask->get(), RtStatus::Buffer)) {
|
||||
int bufsize = DEFAULTBUFFERSIZE;
|
||||
#ifdef ENABLE_WIFI
|
||||
if (client == CLIENT_TELNET) {
|
||||
bufsize = WebUI::telnet_server.get_rx_buffer_available();
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth() && client == CLIENT_BT) {
|
||||
if (client == CLIENT_BT) {
|
||||
//TODO FIXME
|
||||
bufsize = 512 - WebUI::SerialBT.available();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (client == CLIENT_SERIAL) {
|
||||
bufsize = client_get_rx_buffer_available(CLIENT_SERIAL);
|
||||
}
|
||||
@@ -794,7 +777,7 @@ void report_gcode_comment(char* comment) {
|
||||
}
|
||||
|
||||
void report_machine_type(uint8_t client) {
|
||||
info_client(client, "Using machine:%s", config->_name.c_str());
|
||||
info_client(client, "Machine: %s", config->_name.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -114,38 +114,24 @@ void client_init() {
|
||||
);
|
||||
}
|
||||
|
||||
static uint8_t getClientChar(uint8_t* data) {
|
||||
int res;
|
||||
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (res = Uart0.read()) != -1) {
|
||||
*data = res;
|
||||
static uint8_t getClientChar(uint8_t& data) {
|
||||
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (data = Uart0.read()) != -1) {
|
||||
return CLIENT_SERIAL;
|
||||
}
|
||||
if (WebUI::inputBuffer.available()) {
|
||||
*data = WebUI::inputBuffer.read();
|
||||
data = WebUI::inputBuffer.read();
|
||||
return CLIENT_INPUT;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
//currently is wifi or BT but better to prepare both can be live
|
||||
if (hasBluetooth()) {
|
||||
if (WebUI::SerialBT.hasClient()) {
|
||||
if ((res = WebUI::SerialBT.read()) != -1) {
|
||||
*data = res;
|
||||
return CLIENT_BT;
|
||||
}
|
||||
}
|
||||
if ((data = WebUI::SerialBT.read()) != -1) {
|
||||
return CLIENT_BT;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
if (WebUI::Serial2Socket.available()) {
|
||||
*data = WebUI::Serial2Socket.read();
|
||||
if ((data = WebUI::Serial2Socket.read()) != -1) {
|
||||
return CLIENT_WEBUI;
|
||||
}
|
||||
if (WebUI::telnet_server.available()) {
|
||||
*data = WebUI::telnet_server.read();
|
||||
if ((data = WebUI::telnet_server.read()) != -1) {
|
||||
return CLIENT_TELNET;
|
||||
}
|
||||
#endif
|
||||
return CLIENT_ALL;
|
||||
}
|
||||
|
||||
@@ -156,7 +142,7 @@ void clientCheckTask(void* pvParameters) {
|
||||
uint8_t client; // who sent the data
|
||||
while (true) { // run continuously
|
||||
std::atomic_thread_fence(std::memory_order::memory_order_seq_cst); // read fence for settings
|
||||
while ((client = getClientChar(&data)) != CLIENT_ALL) {
|
||||
while ((client = getClientChar(data)) != CLIENT_ALL) {
|
||||
// Pick off realtime command characters directly from the serial stream. These characters are
|
||||
// not passed into the main buffer, but these set system state flag bits for realtime execution.
|
||||
if (is_realtime_command(data)) {
|
||||
@@ -176,15 +162,12 @@ void clientCheckTask(void* pvParameters) {
|
||||
} // if something available
|
||||
WebUI::COMMANDS::handle();
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
if (config->_comms->_bluetoothConfig) {
|
||||
config->_comms->_bluetoothConfig->handle();
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
|
||||
WebUI::wifi_config.handle();
|
||||
WebUI::Serial2Socket.handle_flush();
|
||||
#endif
|
||||
|
||||
vTaskDelay(1 / portTICK_RATE_MS); // Yield to other tasks
|
||||
|
||||
@@ -332,25 +315,13 @@ void client_write(uint8_t client, const char* text) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
if (WebUI::SerialBT.hasClient() && (client == CLIENT_BT || client == CLIENT_ALL)) {
|
||||
// TODO: This can be .print() for consistency with other clients,
|
||||
// and it is not necessary to call .hasClient() because .write()
|
||||
// checks for a client and does nothing if one is not present.
|
||||
WebUI::SerialBT.print(text);
|
||||
//delay(10); // possible fix for dropped characters
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
WebUI::SerialBT.print(text);
|
||||
if (client == CLIENT_WEBUI || client == CLIENT_ALL) {
|
||||
WebUI::Serial2Socket.write((const uint8_t*)text, strlen(text));
|
||||
}
|
||||
if (client == CLIENT_TELNET || client == CLIENT_ALL) {
|
||||
WebUI::telnet_server.write((const uint8_t*)text, strlen(text));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (client == CLIENT_SERIAL || client == CLIENT_ALL) {
|
||||
#ifdef REVERT_TO_ARDUINO_SERIAL
|
||||
|
@@ -243,11 +243,9 @@ Error StringSetting::setStringValue(char* s) {
|
||||
}
|
||||
|
||||
static bool isPassword(bool (*_checker)(char*)) {
|
||||
#ifdef ENABLE_WIFI
|
||||
if (_checker == (bool (*)(char*))WebUI::WiFiConfig::isPasswordValid) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return _checker == (bool (*)(char*))WebUI::COMMANDS::isLocalPasswordValid;
|
||||
}
|
||||
|
||||
|
@@ -20,19 +20,21 @@
|
||||
|
||||
#include "../Grbl.h"
|
||||
#include "../MachineConfig.h"
|
||||
#include "BTConfig.h"
|
||||
|
||||
// SerialBT sends the data over Bluetooth
|
||||
namespace WebUI {
|
||||
BluetoothSerial SerialBT;
|
||||
}
|
||||
// The instance variable for the BTConfig class is in config->_comms
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
|
||||
#include "BTConfig.h"
|
||||
|
||||
extern "C" {
|
||||
const uint8_t* esp_bt_dev_get_address(void);
|
||||
}
|
||||
|
||||
namespace WebUI {
|
||||
BTConfig bt_config;
|
||||
BluetoothSerial SerialBT;
|
||||
|
||||
BTConfig* BTConfig::instance = nullptr;
|
||||
|
||||
BTConfig::BTConfig() {}
|
||||
@@ -60,7 +62,6 @@ namespace WebUI {
|
||||
String BTConfig::info() {
|
||||
String result;
|
||||
String tmp;
|
||||
result = "[MSG:";
|
||||
if (Is_BT_on()) {
|
||||
result += "Mode=BT:Name=";
|
||||
result += _btname;
|
||||
@@ -75,7 +76,6 @@ namespace WebUI {
|
||||
} else {
|
||||
result += "No BT";
|
||||
}
|
||||
result += "]\r\n";
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
@@ -111,22 +111,29 @@ namespace WebUI {
|
||||
/**
|
||||
* begin WiFi setup
|
||||
*/
|
||||
void BTConfig::begin() {
|
||||
bool BTConfig::begin() {
|
||||
instance = this;
|
||||
|
||||
debug_serial("Begin");
|
||||
//stop active services
|
||||
end();
|
||||
|
||||
if (hasBluetooth()) {
|
||||
debug_serial("end");
|
||||
if (_btname.length()) {
|
||||
debug_serial("length");
|
||||
if (!SerialBT.begin(_btname)) {
|
||||
debug_serial("name");
|
||||
report_status_message(Error::BtFailBegin, CLIENT_ALL);
|
||||
} else {
|
||||
SerialBT.register_callback(&my_spp_cb);
|
||||
info_all("BT Started with %s", _btname.c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
end();
|
||||
debug_serial("register");
|
||||
SerialBT.register_callback(&my_spp_cb);
|
||||
info_all("BT Started with %s", _btname.c_str());
|
||||
return true;
|
||||
}
|
||||
info_all("BT is not enabled");
|
||||
end();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,10 +145,10 @@ namespace WebUI {
|
||||
* Reset ESP
|
||||
*/
|
||||
void BTConfig::reset_settings() {
|
||||
#ifdef LATER
|
||||
# ifdef LATER
|
||||
// Implement this in YAML land
|
||||
// was wifi_radio_mode->setDefault();
|
||||
#endif
|
||||
# endif
|
||||
info_all("BT reset done");
|
||||
}
|
||||
|
||||
|
@@ -24,8 +24,36 @@
|
||||
|
||||
#include "../Configuration/Configurable.h"
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
#ifndef ENABLE_BLUETOOTH
|
||||
namespace WebUI {
|
||||
class BluetoothSerial {
|
||||
public:
|
||||
BluetoothSerial() = default;
|
||||
int read() { return -1; };
|
||||
// This is hardwired at 512 because the real BluetoothSerial hardwires
|
||||
// the Rx queue size to 512 and code in Report.cpp subtracts available()
|
||||
// from that to determine how many characters can be sent.
|
||||
int available() { return 512; };
|
||||
void print(const char* text) {};
|
||||
};
|
||||
extern BluetoothSerial SerialBT;
|
||||
|
||||
class BTConfig : public Configuration::Configurable {
|
||||
private:
|
||||
String _btname = "";
|
||||
|
||||
public:
|
||||
BTConfig() = default;
|
||||
void handle() {}
|
||||
bool begin() { return false; }
|
||||
void end() {}
|
||||
bool Is_BT_on() { return false; }
|
||||
String info() { return String(); }
|
||||
const String& BTname() const { return _btname; }
|
||||
void group(Configuration::HandlerBase& handler) override {}
|
||||
};
|
||||
}
|
||||
#else
|
||||
# include <BluetoothSerial.h>
|
||||
|
||||
namespace WebUI {
|
||||
@@ -62,7 +90,7 @@ namespace WebUI {
|
||||
const String& BTname() const { return _btname; }
|
||||
const String& client_name() const { return _btclient; }
|
||||
const char* device_address();
|
||||
void begin();
|
||||
bool begin();
|
||||
void end();
|
||||
void handle();
|
||||
void reset_settings();
|
||||
|
@@ -30,10 +30,13 @@
|
||||
|
||||
#include "../Grbl.h"
|
||||
#include "../MachineConfig.h"
|
||||
#include "NotificationsService.h"
|
||||
|
||||
namespace WebUI {
|
||||
NotificationsService notificationsservice;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
|
||||
# include "NotificationsService.h"
|
||||
# include <WiFiClientSecure.h>
|
||||
# include <base64.h>
|
||||
|
||||
@@ -48,8 +51,6 @@ namespace WebUI {
|
||||
|
||||
static const int EMAILTIMEOUT = 5000;
|
||||
|
||||
NotificationsService notificationsservice;
|
||||
|
||||
NotificationsService::NotificationsService() {
|
||||
_started = false;
|
||||
_notificationType = 0;
|
||||
|
@@ -20,8 +20,16 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
|
||||
#ifndef ENABLE_WIFI
|
||||
namespace WebUI {
|
||||
class NotificationsService {
|
||||
public:
|
||||
NotificationsService() = default;
|
||||
bool sendMSG(const char* title, const char* message) { return false; };
|
||||
};
|
||||
extern NotificationsService notificationsservice;
|
||||
}
|
||||
#else
|
||||
# include <WString.h>
|
||||
# include <cstdint>
|
||||
|
||||
|
@@ -19,17 +19,18 @@
|
||||
*/
|
||||
|
||||
#include "../Grbl.h"
|
||||
#include "Serial2Socket.h"
|
||||
|
||||
namespace WebUI {
|
||||
Serial_2_Socket Serial2Socket;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
|
||||
# include "Serial2Socket.h"
|
||||
# include "WebServer.h"
|
||||
# include <WebSocketsServer.h>
|
||||
# include <WiFi.h>
|
||||
|
||||
namespace WebUI {
|
||||
Serial_2_Socket Serial2Socket;
|
||||
|
||||
Serial_2_Socket::Serial_2_Socket() {
|
||||
_web_socket = NULL;
|
||||
_TXbufferSize = 0;
|
||||
@@ -180,5 +181,4 @@ namespace WebUI {
|
||||
_RXbufferpos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -20,11 +20,22 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
#ifndef ENABLE_WIFI
|
||||
namespace WebUI {
|
||||
class Serial_2_Socket {
|
||||
public:
|
||||
Serial_2_Socket() = default;
|
||||
int read() { return -1; }
|
||||
void handle_flush() {}
|
||||
size_t write(const uint8_t* buffer, size_t size) { return 0; }
|
||||
};
|
||||
extern Serial_2_Socket Serial2Socket;
|
||||
}
|
||||
#else
|
||||
|
||||
#include <Print.h>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
# include <Print.h>
|
||||
# include <cstring>
|
||||
# include <cstdint>
|
||||
|
||||
class WebSocketsServer;
|
||||
|
||||
|
@@ -20,21 +20,24 @@
|
||||
|
||||
#include "../Grbl.h"
|
||||
#include "../MachineConfig.h"
|
||||
#include "TelnetServer.h"
|
||||
|
||||
namespace WebUI {
|
||||
Telnet_Server telnet_server;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
|
||||
# include "WifiServices.h"
|
||||
|
||||
# include "TelnetServer.h"
|
||||
# include "WifiConfig.h"
|
||||
# include <WiFi.h>
|
||||
|
||||
namespace WebUI {
|
||||
Telnet_Server telnet_server;
|
||||
bool Telnet_Server::_setupdone = false;
|
||||
uint16_t Telnet_Server::_port = 0;
|
||||
WiFiServer* Telnet_Server::_telnetserver = NULL;
|
||||
WiFiClient Telnet_Server::_telnetClients[MAX_TLNT_CLIENTS];
|
||||
bool Telnet_Server::_setupdone = false;
|
||||
uint16_t Telnet_Server::_port = 0;
|
||||
WiFiServer* Telnet_Server::_telnetserver = NULL;
|
||||
WiFiClient Telnet_Server::_telnetClients[MAX_TLNT_CLIENTS];
|
||||
|
||||
IPAddress Telnet_Server::_telnetClientsIP[MAX_TLNT_CLIENTS];
|
||||
|
||||
@@ -49,7 +52,7 @@ namespace WebUI {
|
||||
_RXbufferSize = 0;
|
||||
_RXbufferpos = 0;
|
||||
|
||||
if (!hasWiFi() || !config->_comms->_telnetEnable) {
|
||||
if (!config->_comms->_telnetEnable) {
|
||||
return false;
|
||||
}
|
||||
_port = config->_comms->_telnetPort;
|
||||
@@ -232,4 +235,5 @@ namespace WebUI {
|
||||
|
||||
Telnet_Server::~Telnet_Server() { end(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -22,7 +22,18 @@
|
||||
|
||||
#include "../Config.h"
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
#ifndef ENABLE_WIFI
|
||||
namespace WebUI {
|
||||
class Telnet_Server {
|
||||
public:
|
||||
Telnet_Server() = default;
|
||||
int read() { return -1; }
|
||||
size_t write(const uint8_t* buffer, size_t size) { return 0; }
|
||||
size_t get_rx_buffer_available() { return 0; }
|
||||
};
|
||||
extern Telnet_Server telnet_server;
|
||||
}
|
||||
#else
|
||||
|
||||
class WiFiServer;
|
||||
class WiFiClient;
|
||||
@@ -57,8 +68,8 @@ namespace WebUI {
|
||||
static bool _setupdone;
|
||||
static WiFiServer* _telnetserver;
|
||||
static WiFiClient _telnetClients[MAX_TLNT_CLIENTS];
|
||||
static IPAddress _telnetClientsIP[MAX_TLNT_CLIENTS];
|
||||
static uint16_t _port;
|
||||
static IPAddress _telnetClientsIP[MAX_TLNT_CLIENTS];
|
||||
static uint16_t _port;
|
||||
|
||||
void clearClients();
|
||||
|
||||
|
@@ -98,7 +98,7 @@ namespace WebUI {
|
||||
bool no_error = true;
|
||||
_setupdone = false;
|
||||
|
||||
if (!hasWiFi() || !config->_comms->_httpEnable) {
|
||||
if (!config->_comms->_httpEnable) {
|
||||
return false;
|
||||
}
|
||||
_port = config->_comms->_httpPort;
|
||||
|
@@ -40,21 +40,6 @@
|
||||
namespace WebUI {
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
StringSetting* wifi_sta_password;
|
||||
StringSetting* wifi_ap_password;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
enum_opt_t notificationOptions = {
|
||||
{ "NONE", 0 },
|
||||
{ "LINE", 3 },
|
||||
{ "PUSHOVER", 1 },
|
||||
{ "EMAIL", 2 },
|
||||
};
|
||||
EnumSetting* notification_type;
|
||||
StringSetting* notification_t1;
|
||||
StringSetting* notification_t2;
|
||||
StringSetting* notification_ts;
|
||||
#endif
|
||||
|
||||
enum_opt_t onoffOptions = { { "OFF", 0 }, { "ON", 1 } };
|
||||
@@ -314,6 +299,17 @@ namespace WebUI {
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
enum_opt_t notificationOptions = {
|
||||
{ "NONE", 0 },
|
||||
{ "LINE", 3 },
|
||||
{ "PUSHOVER", 1 },
|
||||
{ "EMAIL", 2 },
|
||||
};
|
||||
EnumSetting* notification_type;
|
||||
StringSetting* notification_t1;
|
||||
StringSetting* notification_t2;
|
||||
StringSetting* notification_ts;
|
||||
|
||||
static Error showSetNotification(char* parameter, AuthenticationLevel auth_level) { // ESP610
|
||||
if (*parameter == '\0') {
|
||||
webPrint("", notification_type->getStringValue());
|
||||
@@ -378,18 +374,7 @@ namespace WebUI {
|
||||
return Error::Ok;
|
||||
}
|
||||
|
||||
static Error showSysStats(char* parameter, AuthenticationLevel auth_level) { // ESP420
|
||||
webPrintln("Chip ID: ", String((uint16_t)(ESP.getEfuseMac() >> 32)));
|
||||
webPrintln("CPU Frequency: ", String(ESP.getCpuFreqMHz()) + "Mhz");
|
||||
webPrintln("CPU Temperature: ", String(temperatureRead(), 1) + "C");
|
||||
webPrintln("Free memory: ", ESPResponseStream::formatBytes(ESP.getFreeHeap()));
|
||||
webPrintln("SDK: ", ESP.getSdkVersion());
|
||||
webPrintln("Flash Size: ", ESPResponseStream::formatBytes(ESP.getFlashChipSize()));
|
||||
|
||||
// Round baudRate to nearest 100 because ESP32 can say e.g. 115201
|
||||
// webPrintln("Baud rate: ", String((Serial.baudRate() / 100) * 100)); // TODO FIXME: Commented out, because we're using Uart
|
||||
webPrintln("Sleep mode: ", WiFi.getSleep() ? "Modem" : "None");
|
||||
|
||||
static void showWifiStats() {
|
||||
#ifdef ENABLE_WIFI
|
||||
int mode = WiFi.getMode();
|
||||
if (mode != WIFI_MODE_NULL) {
|
||||
@@ -524,31 +509,24 @@ namespace WebUI {
|
||||
}
|
||||
webPrintln("");
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
auto bt_config = config->_comms->_bluetoothConfig;
|
||||
webPrint("Current BT Mode: ");
|
||||
if (bt_config->Is_BT_on()) {
|
||||
webPrintln("On");
|
||||
static Error showSysStats(char* parameter, AuthenticationLevel auth_level) { // ESP420
|
||||
webPrintln("Chip ID: ", String((uint16_t)(ESP.getEfuseMac() >> 32)));
|
||||
webPrintln("CPU Frequency: ", String(ESP.getCpuFreqMHz()) + "Mhz");
|
||||
webPrintln("CPU Temperature: ", String(temperatureRead(), 1) + "C");
|
||||
webPrintln("Free memory: ", ESPResponseStream::formatBytes(ESP.getFreeHeap()));
|
||||
webPrintln("SDK: ", ESP.getSdkVersion());
|
||||
webPrintln("Flash Size: ", ESPResponseStream::formatBytes(ESP.getFlashChipSize()));
|
||||
|
||||
webPrint("BT Name: ");
|
||||
webPrint(bt_config->BTname());
|
||||
webPrint("(");
|
||||
webPrint(bt_config->device_address());
|
||||
webPrintln(")");
|
||||
// Round baudRate to nearest 100 because ESP32 can say e.g. 115201
|
||||
// webPrintln("Baud rate: ", String((Serial.baudRate() / 100) * 100)); // TODO FIXME: Commented out, because we're using Uart
|
||||
webPrintln("Sleep mode: ", WiFi.getSleep() ? "Modem" : "None");
|
||||
|
||||
webPrint("Status: ");
|
||||
if (SerialBT.hasClient()) {
|
||||
webPrintln("Connected with ", bt_config->client_name());
|
||||
} else {
|
||||
webPrintln("Not connected");
|
||||
}
|
||||
} else {
|
||||
webPrintln("Off");
|
||||
}
|
||||
showWifiStats();
|
||||
if (config->_comms->_bluetoothConfig) {
|
||||
webPrintln(config->_comms->_bluetoothConfig->info().c_str());
|
||||
}
|
||||
#endif
|
||||
webPrint("FW version: ");
|
||||
webPrint(GRBL_VERSION);
|
||||
webPrint(" (");
|
||||
@@ -559,6 +537,9 @@ namespace WebUI {
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
StringSetting* wifi_sta_password;
|
||||
StringSetting* wifi_ap_password;
|
||||
|
||||
static Error listAPs(char* parameter, AuthenticationLevel auth_level) { // ESP410
|
||||
JSONencoder j(espresponse->client() != CLIENT_WEBUI, espresponse);
|
||||
j.begin();
|
||||
@@ -871,11 +852,9 @@ namespace WebUI {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth() && config->_comms->_bluetoothConfig->Is_BT_on()) {
|
||||
if (config->_comms->_bluetoothConfig && config->_comms->_bluetoothConfig->Is_BT_on()) {
|
||||
on = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
webPrintln(on ? "ON" : "OFF");
|
||||
return Error::Ok;
|
||||
@@ -897,13 +876,9 @@ namespace WebUI {
|
||||
wifi_config.StopWiFi();
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
if (config->_comms->_bluetoothConfig->Is_BT_on()) {
|
||||
config->_comms->_bluetoothConfig->end();
|
||||
}
|
||||
if (config->_comms->_bluetoothConfig && config->_comms->_bluetoothConfig->Is_BT_on()) {
|
||||
config->_comms->_bluetoothConfig->end();
|
||||
}
|
||||
#endif
|
||||
|
||||
//if On start proper service
|
||||
if (!on) {
|
||||
@@ -912,24 +887,13 @@ namespace WebUI {
|
||||
}
|
||||
|
||||
//On
|
||||
#ifdef ENABLE_WIFI
|
||||
if (hasWiFi()) {
|
||||
wifi_config.begin();
|
||||
if (wifi_config.begin()) {
|
||||
return Error::Ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (hasBluetooth()) {
|
||||
if (hasBluetooth()) {
|
||||
webPrintln("Bluetooth is not enabled!");
|
||||
return Error::BtFailBegin;
|
||||
} else {
|
||||
config->_comms->_bluetoothConfig->begin();
|
||||
return Error::Ok;
|
||||
}
|
||||
if (config->_comms->_bluetoothConfig) {
|
||||
config->_comms->_bluetoothConfig->begin();
|
||||
}
|
||||
#endif
|
||||
|
||||
webPrintln("[MSG: Radio is Off]");
|
||||
return Error::Ok;
|
||||
@@ -1016,63 +980,10 @@ namespace WebUI {
|
||||
return Error::Ok;
|
||||
}
|
||||
|
||||
// WEB_COMMON should always be defined. It is a trick to make the definitions
|
||||
// line up while allowing VSCode code folding to work correction.
|
||||
#define WEB_COMMON
|
||||
|
||||
void make_web_settings() {
|
||||
// If authentication enabled, display_settings skips or displays <Authentication Required>
|
||||
// RU - need user or admin password to read
|
||||
// WU - need user or admin password to set
|
||||
// WA - need admin password to set
|
||||
#ifdef WEB_COMMON
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP800", "Firmware/Info", showFwInfo, anyState);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP720", "LocalFS/Size", SPIFFSSize);
|
||||
new WebCommand("FORMAT", WEBCMD, WA, "ESP710", "LocalFS/Format", formatSpiffs);
|
||||
new WebCommand("path", WEBCMD, WU, "ESP701", "LocalFS/Show", showLocalFile);
|
||||
new WebCommand("path", WEBCMD, WU, "ESP700", "LocalFS/Run", runLocalFile);
|
||||
new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/List", listLocalFiles);
|
||||
new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/ListJSON", listLocalFilesJSON);
|
||||
new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/Delete", deleteLocalFile);
|
||||
#endif
|
||||
void make_wifi_settings() {
|
||||
#ifdef ENABLE_WIFI
|
||||
new WebCommand(
|
||||
"TYPE=NONE|PUSHOVER|EMAIL|LINE T1=token1 T2=token2 TS=settings", WEBCMD, WA, "ESP610", "Notification/Setup", showSetNotification);
|
||||
new WebCommand("message", WEBCMD, WU, "ESP600", "Notification/Send", sendMessage);
|
||||
#endif
|
||||
#ifdef ENABLE_AUTHENTICATION
|
||||
new WebCommand("password", WEBCMD, WA, "ESP555", "WebUI/SetUserPassword", setUserPassword);
|
||||
#endif
|
||||
#ifdef WEB_COMMON
|
||||
new WebCommand("RESTART", WEBCMD, WA, "ESP444", "System/Control", setSystemMode);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP420", "System/Stats", showSysStats, anyState);
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP410", "WiFi/ListAPs", listAPs);
|
||||
#endif
|
||||
#ifdef WEB_COMMON
|
||||
new WebCommand("P=position T=type V=value", WEBCMD, WA, "ESP401", "WebUI/Set", setWebSetting);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP400", "WebUI/List", listSettings, anyState);
|
||||
#endif
|
||||
new WebCommand("path", WEBCMD, WU, "ESP221", "SD/Show", showSDFile);
|
||||
new WebCommand("path", WEBCMD, WU, "ESP220", "SD/Run", runSDFile);
|
||||
new WebCommand("file_or_directory_path", WEBCMD, WU, "ESP215", "SD/Delete", deleteSDObject);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP210", "SD/List", listSDFiles);
|
||||
#ifdef WEB_COMMON
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP200", "SD/Status", showSDStatus);
|
||||
new WebCommand("STA|AP|BT|OFF", WEBCMD, WA, "ESP115", "Radio/State", setRadioState);
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP111", "System/IP", showIP);
|
||||
new WebCommand("IP=ipaddress MSK=netmask GW=gateway", WEBCMD, WA, "ESP103", "Sta/Setup", showSetStaParams);
|
||||
#endif
|
||||
#ifdef WEB_COMMON
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP0", "WebUI/Help", showWebHelp, anyState);
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP", "WebUI/Help", showWebHelp, anyState);
|
||||
#endif
|
||||
// WebUI Settings
|
||||
// Standard WEBUI authentication is user+ to get, admin to set unless otherwise specified
|
||||
#ifdef ENABLE_WIFI
|
||||
notification_ts = new StringSetting(
|
||||
"Notification Settings", WEBSET, WA, NULL, "Notification/TS", DEFAULT_TOKEN, 0, MAX_NOTIFICATION_SETTING_LENGTH, NULL);
|
||||
notification_t2 = new StringSetting("Notification Token 2",
|
||||
@@ -1095,28 +1006,11 @@ namespace WebUI {
|
||||
NULL);
|
||||
notification_type = new EnumSetting(
|
||||
"Notification type", WEBSET, WA, NULL, "Notification/Type", DEFAULT_NOTIFICATION_TYPE, ¬ificationOptions, NULL);
|
||||
#endif
|
||||
#ifdef ENABLE_AUTHENTICATION
|
||||
user_password = new StringSetting("User password",
|
||||
WEBSET,
|
||||
WA,
|
||||
NULL,
|
||||
"WebUI/UserPassword",
|
||||
DEFAULT_USER_PWD,
|
||||
MIN_LOCAL_PASSWORD_LENGTH,
|
||||
MAX_LOCAL_PASSWORD_LENGTH,
|
||||
&COMMANDS::isLocalPasswordValid);
|
||||
admin_password = new StringSetting("Admin password",
|
||||
WEBSET,
|
||||
WA,
|
||||
NULL,
|
||||
"WebUI/AdminPassword",
|
||||
DEFAULT_ADMIN_PWD,
|
||||
MIN_LOCAL_PASSWORD_LENGTH,
|
||||
MAX_LOCAL_PASSWORD_LENGTH,
|
||||
&COMMANDS::isLocalPasswordValid);
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
new WebCommand("message", WEBCMD, WU, "ESP600", "Notification/Send", sendMessage);
|
||||
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP410", "WiFi/ListAPs", listAPs);
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP111", "System/IP", showIP);
|
||||
new WebCommand("IP=ipaddress MSK=netmask GW=gateway", WEBCMD, WA, "ESP103", "Sta/Setup", showSetStaParams);
|
||||
// no get, admin to set
|
||||
wifi_ap_password = new StringSetting("AP Password",
|
||||
WEBSET,
|
||||
@@ -1139,4 +1033,61 @@ namespace WebUI {
|
||||
(bool (*)(char*))WiFiConfig::isPasswordValid);
|
||||
#endif
|
||||
}
|
||||
|
||||
void make_authentication_settings() {
|
||||
#ifdef ENABLE_AUTHENTICATION
|
||||
new WebCommand("password", WEBCMD, WA, "ESP555", "WebUI/SetUserPassword", setUserPassword);
|
||||
user_password = new StringSetting("User password",
|
||||
WEBSET,
|
||||
WA,
|
||||
NULL,
|
||||
"WebUI/UserPassword",
|
||||
DEFAULT_USER_PWD,
|
||||
MIN_LOCAL_PASSWORD_LENGTH,
|
||||
MAX_LOCAL_PASSWORD_LENGTH,
|
||||
&COMMANDS::isLocalPasswordValid);
|
||||
admin_password = new StringSetting("Admin password",
|
||||
WEBSET,
|
||||
WA,
|
||||
NULL,
|
||||
"WebUI/AdminPassword",
|
||||
DEFAULT_ADMIN_PWD,
|
||||
MIN_LOCAL_PASSWORD_LENGTH,
|
||||
MAX_LOCAL_PASSWORD_LENGTH,
|
||||
&COMMANDS::isLocalPasswordValid);
|
||||
#endif
|
||||
}
|
||||
|
||||
void make_web_settings() {
|
||||
make_wifi_settings();
|
||||
make_authentication_settings();
|
||||
// If authentication enabled, display_settings skips or displays <Authentication Required>
|
||||
// RU - need user or admin password to read
|
||||
// WU - need user or admin password to set
|
||||
// WA - need admin password to set
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP800", "Firmware/Info", showFwInfo, anyState);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP420", "System/Stats", showSysStats, anyState);
|
||||
new WebCommand("RESTART", WEBCMD, WA, "ESP444", "System/Control", setSystemMode);
|
||||
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP720", "LocalFS/Size", SPIFFSSize);
|
||||
new WebCommand("FORMAT", WEBCMD, WA, "ESP710", "LocalFS/Format", formatSpiffs);
|
||||
new WebCommand("path", WEBCMD, WU, "ESP701", "LocalFS/Show", showLocalFile);
|
||||
new WebCommand("path", WEBCMD, WU, "ESP700", "LocalFS/Run", runLocalFile);
|
||||
new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/List", listLocalFiles);
|
||||
new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/ListJSON", listLocalFilesJSON);
|
||||
new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/Delete", deleteLocalFile);
|
||||
|
||||
new WebCommand("path", WEBCMD, WU, "ESP221", "SD/Show", showSDFile);
|
||||
new WebCommand("path", WEBCMD, WU, "ESP220", "SD/Run", runSDFile);
|
||||
new WebCommand("file_or_directory_path", WEBCMD, WU, "ESP215", "SD/Delete", deleteSDObject);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP210", "SD/List", listSDFiles);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP200", "SD/Status", showSDStatus);
|
||||
|
||||
new WebCommand("STA|AP|BT|OFF", WEBCMD, WA, "ESP115", "Radio/State", setRadioState);
|
||||
|
||||
new WebCommand("P=position T=type V=value", WEBCMD, WA, "ESP401", "WebUI/Set", setWebSetting);
|
||||
new WebCommand(NULL, WEBCMD, WU, "ESP400", "WebUI/List", listSettings, anyState);
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP0", "WebUI/Help", showWebHelp, anyState);
|
||||
new WebCommand(NULL, WEBCMD, WG, "ESP", "WebUI/Help", showWebHelp, anyState);
|
||||
}
|
||||
}
|
||||
|
@@ -21,15 +21,15 @@
|
||||
*/
|
||||
|
||||
namespace WebUI {
|
||||
extern StringSetting* wifi_sta_password;
|
||||
extern StringSetting* wifi_ap_password;
|
||||
|
||||
#ifdef ENABLE_AUTHENTICATION
|
||||
extern StringSetting* user_password;
|
||||
extern StringSetting* admin_password;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
extern StringSetting* wifi_sta_password;
|
||||
extern StringSetting* wifi_ap_password;
|
||||
|
||||
extern EnumSetting* notification_type;
|
||||
extern StringSetting* notification_t1;
|
||||
extern StringSetting* notification_t2;
|
||||
|
@@ -21,8 +21,9 @@
|
||||
#include "../Grbl.h"
|
||||
#include "../MachineConfig.h"
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
WebUI::WiFiConfig wifi_config;
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
# include <WiFi.h>
|
||||
# include <esp_wifi.h>
|
||||
# include <ESPmDNS.h>
|
||||
@@ -32,8 +33,6 @@
|
||||
# include "WifiServices.h"
|
||||
|
||||
namespace WebUI {
|
||||
WiFiConfig wifi_config;
|
||||
|
||||
String WiFiConfig::_hostname = "";
|
||||
bool WiFiConfig::_events_registered = false;
|
||||
|
||||
@@ -48,10 +47,9 @@ namespace WebUI {
|
||||
return macstr;
|
||||
}
|
||||
|
||||
const char* WiFiConfig::info() {
|
||||
String WiFiConfig::info() {
|
||||
static String result;
|
||||
String tmp;
|
||||
result = "[MSG:";
|
||||
|
||||
if ((WiFi.getMode() == WIFI_MODE_STA) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
|
||||
result += "Mode=STA:SSID=";
|
||||
@@ -84,8 +82,7 @@ namespace WebUI {
|
||||
if (WiFi.getMode() == WIFI_MODE_NULL) {
|
||||
result += "No Wifi";
|
||||
}
|
||||
result += "]\r\n";
|
||||
return result.c_str();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,38 +396,35 @@ namespace WebUI {
|
||||
/**
|
||||
* begin WiFi setup
|
||||
*/
|
||||
void WiFiConfig::begin() {
|
||||
bool WiFiConfig::begin() {
|
||||
//stop active services
|
||||
wifi_services.end();
|
||||
if (!hasWiFi()) {
|
||||
goto wifi_off;
|
||||
|
||||
if (config->_comms->_staConfig && StartSTA()) {
|
||||
// WIFI mode is STA; fall back on AP if necessary
|
||||
goto wifi_on;
|
||||
}
|
||||
if (config->_comms->_apConfig && StartAP()) {
|
||||
goto wifi_on;
|
||||
}
|
||||
|
||||
info_serial("WiFi off");
|
||||
WiFi.mode(WIFI_OFF);
|
||||
return false;
|
||||
|
||||
wifi_on:
|
||||
//Get hostname
|
||||
_hostname = config->_comms->_hostname;
|
||||
|
||||
//setup events
|
||||
if (!_events_registered) {
|
||||
//cumulative function and no remove so only do once
|
||||
WiFi.onEvent(WiFiConfig::WiFiEvent);
|
||||
_events_registered = true;
|
||||
}
|
||||
|
||||
//Get hostname
|
||||
_hostname = config->_comms->_hostname;
|
||||
|
||||
if (config->_comms->_staConfig != nullptr) {
|
||||
// WIFI mode is STA; fall back on AP if necessary
|
||||
if (StartSTA()) {
|
||||
goto wifi_on;
|
||||
}
|
||||
}
|
||||
if (StartAP()) {
|
||||
goto wifi_on;
|
||||
}
|
||||
|
||||
wifi_off:
|
||||
info_serial("WiFi off");
|
||||
WiFi.mode(WIFI_OFF);
|
||||
return;
|
||||
wifi_on:
|
||||
info_serial("WiFi on");
|
||||
wifi_services.begin();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,7 +22,23 @@
|
||||
|
||||
//Preferences entries
|
||||
|
||||
#include <WiFi.h>
|
||||
#include "../Config.h"
|
||||
|
||||
#ifndef ENABLE_WIFI
|
||||
namespace WebUI {
|
||||
class WiFiConfig {
|
||||
public:
|
||||
static String info() { return String(); }
|
||||
static bool isPasswordValid(const char* password) { return false; }
|
||||
static bool begin() { return false; };
|
||||
static void reset_settings() {}
|
||||
static void handle() {}
|
||||
static bool Is_WiFi_on() { return false; }
|
||||
};
|
||||
extern WiFiConfig wifi_config;
|
||||
}
|
||||
#else
|
||||
# include <WiFi.h>
|
||||
|
||||
namespace WebUI {
|
||||
// TODO: Clean these constants up. Some of them don't belong here.
|
||||
@@ -83,24 +99,24 @@ namespace WebUI {
|
||||
public:
|
||||
WiFiConfig();
|
||||
|
||||
static const char* info();
|
||||
static bool isValidIP(const char* string);
|
||||
static bool isPasswordValid(const char* password);
|
||||
static bool isSSIDValid(const char* ssid);
|
||||
static bool isHostnameValid(const char* hostname);
|
||||
static uint32_t IP_int_from_string(String& s);
|
||||
static String IP_string_from_int(uint32_t ip_int);
|
||||
static String Hostname() { return _hostname; }
|
||||
static char* mac2str(uint8_t mac[8]);
|
||||
static bool StartAP();
|
||||
static bool StartSTA();
|
||||
static void StopWiFi();
|
||||
static int32_t getSignal(int32_t RSSI);
|
||||
static void begin();
|
||||
static void end();
|
||||
static void handle();
|
||||
static void reset_settings();
|
||||
static bool Is_WiFi_on();
|
||||
static String info();
|
||||
static bool isValidIP(const char* string);
|
||||
static bool isPasswordValid(const char* password);
|
||||
static bool isSSIDValid(const char* ssid);
|
||||
static bool isHostnameValid(const char* hostname);
|
||||
static uint32_t IP_int_from_string(String& s);
|
||||
static String IP_string_from_int(uint32_t ip_int);
|
||||
static String Hostname() { return _hostname; }
|
||||
static char* mac2str(uint8_t mac[8]);
|
||||
static bool StartAP();
|
||||
static bool StartSTA();
|
||||
static void StopWiFi();
|
||||
static int32_t getSignal(int32_t RSSI);
|
||||
static bool begin();
|
||||
static void end();
|
||||
static void handle();
|
||||
static void reset_settings();
|
||||
static bool Is_WiFi_on();
|
||||
|
||||
~WiFiConfig();
|
||||
|
||||
@@ -113,3 +129,4 @@ namespace WebUI {
|
||||
|
||||
extern WiFiConfig wifi_config;
|
||||
}
|
||||
#endif
|
||||
|
@@ -43,7 +43,10 @@ namespace WebUI {
|
||||
bool WiFiServices::begin() {
|
||||
bool no_error = true;
|
||||
//Sanity check
|
||||
if (WiFi.getMode() == WIFI_OFF || !hasWiFi()) {
|
||||
if (!(config->_comms->_staConfig || config->_comms->_apConfig)) {
|
||||
return false;
|
||||
}
|
||||
if (WiFi.getMode() == WIFI_OFF) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,7 @@ src_dir = Grbl_Esp32
|
||||
lib_dir = libraries
|
||||
test_dir = Grbl_Esp32/test
|
||||
data_dir = Grbl_Esp32/data
|
||||
default_envs = wifi
|
||||
default_envs = wifibt
|
||||
;extra_configs=debug.ini
|
||||
|
||||
[common_env_data]
|
||||
@@ -86,3 +86,18 @@ lib_deps =
|
||||
BluetoothSerial
|
||||
|
||||
build_flags = ${common.build_flags} -DENABLE_BLUETOOTH
|
||||
|
||||
[env:wifibt]
|
||||
lib_deps =
|
||||
TMCStepper@>=0.7.0,<1.0.0
|
||||
ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0
|
||||
BluetoothSerial
|
||||
ArduinoOTA
|
||||
DNSServer
|
||||
ESPmDNS
|
||||
Update
|
||||
WebServer
|
||||
WiFi
|
||||
WiFiClientSecure
|
||||
|
||||
build_flags = ${common.build_flags} -DENABLE_BLUETOOTH -DENABLE_WIFI
|
||||
|
Reference in New Issue
Block a user