mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 06:49:05 +08:00
Add Websocket support
Add command 160 + 161 for websocket configuration Add Websocket monitor page for debug in tools Add Telnet and Websocket debug default port is 8000 Fix boot delay value to default instead of max when invalid Minor fixes
This commit is contained in:
parent
3b380bac12
commit
6f5d87a927
@ -56,6 +56,12 @@ Note:
|
||||
* Get/Set boot delay
|
||||
[ESP150]<time in milliseconds>[pwd=<admin password>]
|
||||
|
||||
* Get/Set WebSocket state which can be ON, OFF
|
||||
[ESP160]<state>pwd=<admin password>
|
||||
|
||||
* Get/Set WebSocket port
|
||||
[ESP161]<port>pwd=<admin password>
|
||||
|
||||
*Get/Set pin value
|
||||
[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES]pwd=<admin password>
|
||||
if no V<value> get P<pin> value
|
||||
|
@ -43,19 +43,19 @@
|
||||
#define TELNET_FEATURE
|
||||
|
||||
//WS_DATA_FEATURE: allow to connect serial from Websocket
|
||||
//#define WS_DATA_FEATURE
|
||||
#define WS_DATA_FEATURE
|
||||
|
||||
//DISPLAY_DEVICE: allow screen output
|
||||
//OLED_I2C_SSD1306 1
|
||||
//OLED_I2C_SSDSH1106 2
|
||||
//TFT_SPI_ILI9341_320X240 3
|
||||
#define DISPLAY_DEVICE OLED_I2C_SSD1306
|
||||
//#define DISPLAY_DEVICE OLED_I2C_SSD1306
|
||||
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
//for ILI9143 edit User_Setup.h of TFT_eSPI library
|
||||
#define DISPLAY_I2C_PIN_SDA 4
|
||||
#define DISPLAY_I2C_PIN_SCL 5
|
||||
//#define DISPLAY_I2C_PIN_RST 16 //comment if not applicable
|
||||
#define DISPLAY_I2C_PIN_SCL 15
|
||||
#define DISPLAY_I2C_PIN_RST 16 //comment if not applicable
|
||||
#define DISPLAY_I2C_ADDR 0x3c
|
||||
#define DISPLAY_FLIP_VERTICALY 1 //comment to disable
|
||||
#endif //DISPLAY_DEVICE
|
||||
@ -119,10 +119,15 @@
|
||||
* **********************************/
|
||||
//Do not do this when connected to printer !!!
|
||||
//be noted all upload may failed if enabled
|
||||
//DEBUG_OUTPUT_SERIAL0 0
|
||||
//DEBUG_OUTPUT_SERIAL1 1
|
||||
//DEBUG_OUTPUT_SERIAL2 2
|
||||
//DEBUG_OUTPUT_SERIAL0 1
|
||||
//DEBUG_OUTPUT_SERIAL1 2
|
||||
//DEBUG_OUTPUT_SERIAL2 3
|
||||
//DEBUG_OUTPUT_TELNET 4
|
||||
//DEBUG_OUTPUT_WEBSOCKET 5
|
||||
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||
#ifdef ESP_DEBUG_FEATURE
|
||||
#define DEBUG_ESP3D_OUTPUT_PORT 8000
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
|
||||
/************************************
|
||||
*
|
||||
|
@ -311,6 +311,18 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
|
||||
case 150:
|
||||
response = ESP150(cmd_params, auth_type, output);
|
||||
break;
|
||||
#ifdef WS_DATA_FEATURE
|
||||
//Set WebSocket state which can be ON, OFF
|
||||
//[ESP160]<state>pwd=<admin password>
|
||||
case 160:
|
||||
response = ESP160(cmd_params, auth_type, output);
|
||||
break;
|
||||
//Set WebSocket port
|
||||
//[ESP161]<port>pwd=<admin password>
|
||||
case 161:
|
||||
response = ESP161(cmd_params, auth_type, output);
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
//Get/Set pin value
|
||||
//[ESP201]P<pin> V<value> [PULLUP=YES RAW=YES]pwd=<admin password>
|
||||
|
@ -71,6 +71,10 @@ public:
|
||||
bool ESP140(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
bool ESP150(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
bool ESP160(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
bool ESP161(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //WS_DATA_FEATURE
|
||||
#ifdef DIRECT_PIN_FEATURE
|
||||
bool ESP201(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
|
||||
#endif //DIRECT_PIN_FEATURE
|
||||
|
@ -19,8 +19,9 @@
|
||||
*/
|
||||
|
||||
#include "../include/esp3d_config.h"
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && defined(ESP_DEBUG_FEATURE)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
const char * pathToFileName(const char * path)
|
||||
{
|
||||
size_t i = 0;
|
||||
@ -35,4 +36,15 @@ const char * pathToFileName(const char * path)
|
||||
}
|
||||
return path+pos;
|
||||
}
|
||||
#endif //ARDUINO_ARCH_ESP8266 && ESP_DEBUG_FEATURE
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
|
||||
//Telnet
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
Telnet_Server telnet_debug;
|
||||
#endif // ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
|
||||
//Websocket
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
WebSocket_Server websocket_debug;
|
||||
#endif // ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
|
@ -25,15 +25,18 @@
|
||||
#define log_esp3d(format, ...)
|
||||
#define log_esp3dS(format, ...)
|
||||
#define DEBUG_ESP3D_INIT
|
||||
#define DEBUG_ESP3D_NETWORK_INIT
|
||||
#define DEBUG_ESP3D_NETWORK_HANDLE
|
||||
#define DEBUG_ESP3D_NETWORK_END
|
||||
#if defined(ESP_DEBUG_FEATURE)
|
||||
//Serial
|
||||
#if (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2)
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
extern const char * pathToFileName(const char * path);
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
#undef DEBUG_ESP3D_INIT
|
||||
#undef log_esp3d
|
||||
#undef log_esp3dS
|
||||
//Serial
|
||||
#if (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1) || (ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2)
|
||||
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0
|
||||
#define DEBUG_OUTPUT_SERIAL Serial
|
||||
#endif //DEBUG_OUTPUT_SERIAL0
|
||||
@ -43,9 +46,39 @@ extern const char * pathToFileName(const char * path);
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2
|
||||
#define DEBUG_OUTPUT_SERIAL Serial2
|
||||
#endif //DEBUG_OUTPUT_SERIAL2
|
||||
#undef DEBUG_ESP3D_INIT
|
||||
#define DEBUG_ESP3D_INIT DEBUG_OUTPUT_SERIAL.begin(115200);
|
||||
#define log_esp3d(format, ...) DEBUG_OUTPUT_SERIAL.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define log_esp3dS(format, ...) DEBUG_OUTPUT_SERIAL.printf(format "\r\n", ##__VA_ARGS__)
|
||||
#endif //DEBUG_OUTPUT_SERIAL0 || DEBUG_OUTPUT_SERIAL1 || DEBUG_OUTPUT_SERIAL2
|
||||
|
||||
//Telnet
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
#include "../modules/telnet/telnet_server.h"
|
||||
extern Telnet_Server telnet_debug;
|
||||
#undef DEBUG_ESP3D_NETWORK_INIT
|
||||
#undef DEBUG_ESP3D_NETWORK_END
|
||||
#undef DEBUG_ESP3D_NETWORK_HANDLE
|
||||
#define DEBUG_ESP3D_NETWORK_INIT telnet_debug.begin(DEBUG_ESP3D_OUTPUT_PORT, true);
|
||||
#define DEBUG_ESP3D_NETWORK_HANDLE telnet_debug.handle();
|
||||
#define DEBUG_ESP3D_NETWORK_END telnet_debug.end();
|
||||
#define log_esp3d(format, ...) telnet_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define log_esp3dS(format, ...) telnet_debug.printf(format "\r\n", ##__VA_ARGS__)
|
||||
#endif // DEBUG_OUTPUT_TELNET
|
||||
|
||||
//Telnet
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
#include "../modules/websocket/websocket_server.h"
|
||||
extern WebSocket_Server websocket_debug;
|
||||
#undef DEBUG_ESP3D_NETWORK_INIT
|
||||
#undef DEBUG_ESP3D_NETWORK_END
|
||||
#undef DEBUG_ESP3D_NETWORK_HANDLE
|
||||
#define DEBUG_ESP3D_NETWORK_INIT websocket_debug.begin(DEBUG_ESP3D_OUTPUT_PORT, true);
|
||||
#define DEBUG_ESP3D_NETWORK_HANDLE websocket_debug.handle();
|
||||
#define DEBUG_ESP3D_NETWORK_END websocket_debug.end();
|
||||
#define log_esp3d(format, ...) websocket_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define log_esp3dS(format, ...) websocket_debug.printf(format "\r\n", ##__VA_ARGS__)
|
||||
#endif // DEBUG_OUTPUT_WEBSOCKET
|
||||
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
#endif //_DEBUG_ESP3D_H
|
||||
|
@ -113,6 +113,14 @@ size_t ESP3DOutput::dispatch (uint8_t * sbuf, size_t len)
|
||||
}
|
||||
}
|
||||
#endif //TELNET_FEATURE
|
||||
#if defined (WS_DATA_FEATURE)
|
||||
if (_client != ESP_WEBSOCKET_CLIENT) {
|
||||
if (isOutput(ESP_WEBSOCKET_CLIENT) && websocket_data_server.started()) {
|
||||
log_esp3d("Dispatch to websocket data server");
|
||||
websocket_data_server.write(sbuf, len);
|
||||
}
|
||||
}
|
||||
#endif //WS_DATA_FEATURE
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -205,9 +213,9 @@ size_t ESP3DOutput::printMSG(const char * s)
|
||||
display+= s;
|
||||
return printLN(display.c_str());
|
||||
}
|
||||
if (_client == ESP_SCREEN_CLIENT){
|
||||
return print(s);
|
||||
}
|
||||
if (_client == ESP_SCREEN_CLIENT) {
|
||||
return print(s);
|
||||
}
|
||||
switch(Settings_ESP3D::GetFirmwareTarget()) {
|
||||
case GRBL:
|
||||
display = "[MSG:";
|
||||
@ -234,9 +242,9 @@ size_t ESP3DOutput::printERROR(const char * s, int code_error)
|
||||
if (!isOutput(_client)) {
|
||||
return 0;
|
||||
}
|
||||
if (_client == ESP_SCREEN_CLIENT){
|
||||
return print(s);
|
||||
}
|
||||
if (_client == ESP_SCREEN_CLIENT) {
|
||||
return print(s);
|
||||
}
|
||||
#ifdef HTTP_FEATURE
|
||||
_code = code_error;
|
||||
if (_client == ESP_HTTP_CLIENT) {
|
||||
@ -284,14 +292,19 @@ int ESP3DOutput::availableforwrite()
|
||||
return serial_service.availableForWrite();
|
||||
#if defined (BLUETOOTH_FEATURE)
|
||||
case ESP_BT_CLIENT:
|
||||
bt_service.availableForWrite();
|
||||
return bt_service.availableForWrite();
|
||||
break;
|
||||
#endif //BLUETOOTH_FEATURE
|
||||
#if defined (TELNET_FEATURE)
|
||||
case ESP_TELNET_CLIENT:
|
||||
telnet_server.availableForWrite();
|
||||
return telnet_server.availableForWrite();
|
||||
break;
|
||||
#endif //TELNET_FEATURE
|
||||
#if defined (WS_DATA_FEATURE)
|
||||
case ESP_WEBSOCKET_CLIENT:
|
||||
return websocket_data_server.availableForWrite();
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
case ESP_ALL_CLIENTS:
|
||||
return serial_service.availableForWrite();
|
||||
default :
|
||||
@ -317,6 +330,10 @@ size_t ESP3DOutput::write(uint8_t c)
|
||||
case ESP_TELNET_CLIENT:
|
||||
return telnet_server.write(c);
|
||||
#endif //TELNET_FEATURE
|
||||
#if defined (WS_DATA_FEATURE)
|
||||
case ESP_WEBSOCKET_CLIENT:
|
||||
return websocket_data_server.write(c);
|
||||
#endif //WS_DATA_FEATURE
|
||||
case ESP_ALL_CLIENTS:
|
||||
#if defined (BLUETOOTH_FEATURE)
|
||||
if(bt_service.started()) {
|
||||
@ -359,8 +376,8 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
#endif //HTTP_FEATURE
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
case ESP_SCREEN_CLIENT:
|
||||
esp3d_display.SetStatus((const char *)buffer);
|
||||
return size;
|
||||
esp3d_display.SetStatus((const char *)buffer);
|
||||
return size;
|
||||
#endif //DISPLAY_DEVICE
|
||||
#if defined (BLUETOOTH_FEATURE)
|
||||
case ESP_BT_CLIENT:
|
||||
@ -374,6 +391,12 @@ size_t ESP3DOutput::write(const uint8_t *buffer, size_t size)
|
||||
return telnet_server.write(buffer, size);
|
||||
}
|
||||
#endif //TELNET_FEATURE
|
||||
#if defined (WS_DATA_FEATURE)
|
||||
case ESP_WEBSOCKET_CLIENT:
|
||||
if(websocket_data_server.started()) {
|
||||
return websocket_data_server.write(buffer, size);
|
||||
}
|
||||
#endif //WS_DATA_FEATURE
|
||||
case ESP_PRINTER_LCD_CLIENT:
|
||||
case ESP_SERIAL_CLIENT:
|
||||
return serial_service.write(buffer, size);
|
||||
|
73
esp3d/src/core/espcmd/ESP160.cpp
Normal file
73
esp3d/src/core/espcmd/ESP160.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
ESP160.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library 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 library 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 library; 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 (WS_DATA_FEATURE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
#include "../../modules/websocket/websocket_server.h"
|
||||
//Set WebSocket state which can be ON, OFF, CLOSE
|
||||
//[ESP160]<state>pwd=<admin password>
|
||||
bool Commands::ESP160(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_WEBSOCKET_ON) == 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") || (parameter == "CLOSE"))) {
|
||||
output->printERROR("Only ON or OFF or CLOSE mode supported!");
|
||||
return false;
|
||||
} else {
|
||||
if (parameter == "CLOSE") {
|
||||
websocket_data_server.closeClients();
|
||||
output->printMSG ("ok");
|
||||
} else {
|
||||
if (!Settings_ESP3D::write_byte (ESP_WEBSOCKET_ON, (parameter == "ON")?1:0)) {
|
||||
output->printERROR ("Set failed!");
|
||||
response = false;
|
||||
}
|
||||
|
||||
output->printMSG ("ok");
|
||||
}
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#endif //WS_DATA_FEATURE
|
66
esp3d/src/core/espcmd/ESP161.cpp
Normal file
66
esp3d/src/core/espcmd/ESP161.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
ESP161.cpp - ESP3D command class
|
||||
|
||||
Copyright (c) 2014 Luc Lebosse. All rights reserved.
|
||||
|
||||
This library 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 library 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 library; 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 (WS_DATA_FEATURE)
|
||||
#include "../commands.h"
|
||||
#include "../esp3doutput.h"
|
||||
#include "../settings_esp3d.h"
|
||||
#include "../../modules/authentication/authentication_service.h"
|
||||
//Set Websocket port
|
||||
//[ESP161]<port>pwd=<admin password>
|
||||
bool Commands::ESP161(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(String(Settings_ESP3D::read_uint32(ESP_WEBSOCKET_PORT)).c_str());
|
||||
} else { //set
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
if (auth_type != LEVEL_ADMIN) {
|
||||
output->printERROR("Wrong authentication!", 401);
|
||||
return false;
|
||||
}
|
||||
#endif //AUTHENTICATION_FEATURE
|
||||
uint ibuf = parameter.toInt();
|
||||
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBSOCKET_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBSOCKET_PORT))) {
|
||||
output->printERROR ("Incorrect port!");
|
||||
return false;
|
||||
}
|
||||
if (!Settings_ESP3D::write_uint32 (ESP_WEBSOCKET_PORT, ibuf)) {
|
||||
output->printERROR ("Set failed!");
|
||||
response = false;
|
||||
} else {
|
||||
output->printMSG ("ok");
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#endif //WS_DATA_FEATURE
|
@ -44,6 +44,9 @@
|
||||
#ifdef TELNET_FEATURE
|
||||
#include "../../modules/telnet/telnet_server.h"
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
#include "../../modules/websocket/websocket_server.h"
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined (TIMESTAMP_FEATURE)
|
||||
#include "../../modules/time/time_server.h"
|
||||
#endif //TIMESTAMP_FEATURE
|
||||
@ -388,6 +391,26 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
}
|
||||
#endif //TELNET_FEATURE
|
||||
#if defined (WS_DATA_FEATURE)
|
||||
if (websocket_data_server.started()) {
|
||||
//websocket port
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
}
|
||||
output->print ("Websocket port");
|
||||
if (!plain) {
|
||||
output->print ("\",\"value\":\"");
|
||||
} else {
|
||||
output->print (": ");
|
||||
}
|
||||
output->printf ("%d",websocket_data_server.port());
|
||||
if (!plain) {
|
||||
output->print ("\"}");
|
||||
} else {
|
||||
output->printLN("");
|
||||
}
|
||||
}
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined (BLUETOOTH_FEATURE)
|
||||
if (bt_service.started()) {
|
||||
//BT mode
|
||||
@ -993,6 +1016,38 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //DHT_DEVICE
|
||||
#if defined (ESP_DEBUG_FEATURE)
|
||||
//debug
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
}
|
||||
output->print ("Debug");
|
||||
if (!plain) {
|
||||
output->print ("\",\"value\":\"");
|
||||
} else {
|
||||
output->print (": ");
|
||||
}
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL0
|
||||
output->print ("Serial");
|
||||
#endif //DEBUG_OUTPUT_SERIAL0
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL1
|
||||
output->print ("Serial1");
|
||||
#endif //DEBUG_OUTPUT_SERIAL1
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_SERIAL2
|
||||
output->print ("Serial2");
|
||||
#endif //DEBUG_OUTPUT_SERIAL2
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_TELNET
|
||||
output->printf ("Telnet(%d)", DEBUG_ESP3D_OUTPUT_PORT);
|
||||
#endif //DEBUG_OUTPUT_TELNET
|
||||
#if ESP_DEBUG_FEATURE == DEBUG_OUTPUT_WEBSOCKET
|
||||
output->printf ("Websocket(%d)", DEBUG_ESP3D_OUTPUT_PORT);
|
||||
#endif //DEBUG_OUTPUT_WEBSOCKET
|
||||
if (!plain) {
|
||||
output->print ("\"}");
|
||||
} else {
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
//FW version
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"");
|
||||
|
@ -100,6 +100,7 @@
|
||||
#define DEFAULT_IS_DIRECT_SD 0
|
||||
#define DEFAULT_HTTP_ON 1
|
||||
#define DEFAULT_TELNET_ON 1
|
||||
#define DEFAULT_WEBSOCKET_ON 1
|
||||
#define DEFAULT_NOTIFICATION_TYPE 0
|
||||
#define DEFAULT_NOTIFICATION_TOKEN1 ""
|
||||
#define DEFAULT_NOTIFICATION_TOKEN2 ""
|
||||
@ -110,6 +111,7 @@
|
||||
#define DEFAULT_ESP_INT 0L
|
||||
#define DEFAULT_BAUD_RATE 115200L
|
||||
#define DEFAULT_HTTP_PORT 80L
|
||||
#define DEFAULT_WEBSOCKET_PORT 8282L
|
||||
#define DEFAULT_TELNET_PORT 23L
|
||||
#define DEFAULT_DHT_INTERVAL 30000L
|
||||
#define DEFAULT_BOOT_DELAY 10000L
|
||||
@ -256,6 +258,11 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
|
||||
res = DEFAULT_TELNET_ON;
|
||||
break;
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
case ESP_WEBSOCKET_ON:
|
||||
res = DEFAULT_WEBSOCKET_ON;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#ifdef SDCARD_FEATURE
|
||||
case ESP_SD_SPEED_DIV:
|
||||
res = DEFAULT_SDREADER_SPEED;
|
||||
@ -332,6 +339,11 @@ uint32_t Settings_ESP3D::get_default_int32_value(int pos)
|
||||
res = DEFAULT_TELNET_PORT;
|
||||
break;
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
case ESP_WEBSOCKET_PORT:
|
||||
res = DEFAULT_WEBSOCKET_PORT;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_INTERVAL:
|
||||
res = DEFAULT_DHT_INTERVAL;
|
||||
@ -361,6 +373,11 @@ uint32_t Settings_ESP3D::get_max_int32_value(int pos)
|
||||
res = MAX_TELNET_PORT;
|
||||
break;
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
case ESP_WEBSOCKET_PORT:
|
||||
res = MAX_WEBSOCKET_PORT;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_INTERVAL:
|
||||
res = MAX_DHT_INTERVAL;
|
||||
@ -390,6 +407,11 @@ uint32_t Settings_ESP3D::get_min_int32_value(int pos)
|
||||
res = MIN_TELNET_PORT;
|
||||
break;
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
case ESP_WEBSOCKET_PORT:
|
||||
res = MIN_WEBSOCKET_PORT;
|
||||
break;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(DHT_DEVICE)
|
||||
case ESP_DHT_INTERVAL:
|
||||
res = MIN_DHT_INTERVAL;
|
||||
@ -989,6 +1011,13 @@ bool Settings_ESP3D::reset()
|
||||
//TELNET Port
|
||||
Settings_ESP3D::write_uint32 (ESP_TELNET_PORT, Settings_ESP3D::get_default_int32_value(ESP_TELNET_PORT));
|
||||
#endif //TELNET
|
||||
|
||||
#ifdef WS_DATA_FEATURE
|
||||
//Websocket On
|
||||
Settings_ESP3D::write_byte(ESP_WEBSOCKET_ON,Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_ON));
|
||||
//Websocket Port
|
||||
Settings_ESP3D::write_uint32 (ESP_WEBSOCKET_PORT, Settings_ESP3D::get_default_int32_value(ESP_WEBSOCKET_PORT));
|
||||
#endif //WS_DATA_FEATURE
|
||||
#ifdef AUTHENTICATION_FEATURE
|
||||
//Admin password
|
||||
Settings_ESP3D::write_string(ESP_ADMIN_PWD,Settings_ESP3D::get_default_string_value(ESP_ADMIN_PWD).c_str());
|
||||
|
@ -60,10 +60,10 @@
|
||||
#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_BOOT_DELAY 320 //4 bytes xxx.xxx.xxx.xxx
|
||||
//#define EP_FREE_INT5 324 //4 bytes xxx.xxx.xxx.xxx
|
||||
#define ESP_WEBSOCKET_PORT 324 //4 bytes xxx.xxx.xxx.xxx
|
||||
#define ESP_HTTP_ON 328 //1 byte = flag
|
||||
#define ESP_TELNET_ON 329 //1 byte = flag
|
||||
//#define ESP_AP_PHY_MODE 330 //1 byte = flag
|
||||
#define ESP_WEBSOCKET_ON 330 //1 byte = flag
|
||||
#define ESP_SD_SPEED_DIV 331 //1 byte = flag
|
||||
#define ESP_NOTIFICATION_TOKEN1 332 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
|
||||
#define ESP_NOTIFICATION_TOKEN2 396 //64 bytes 63+1 = string ; warning does not support multibyte char like chinese
|
||||
|
@ -29,6 +29,9 @@
|
||||
#define DEBUG_OUTPUT_SERIAL0 1
|
||||
#define DEBUG_OUTPUT_SERIAL1 2
|
||||
#define DEBUG_OUTPUT_SERIAL2 3
|
||||
#define DEBUG_OUTPUT_TELNET 4
|
||||
#define DEBUG_OUTPUT_WEBSOCKET 5
|
||||
|
||||
|
||||
//Serial
|
||||
#define USE_SERIAL_0 1
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a6"
|
||||
#define FW_VERSION "3.0.0.a7"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -69,8 +69,8 @@ static void my_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
||||
{
|
||||
ESP3DOutput output(ESP_ALL_CLIENTS);
|
||||
switch (event) {
|
||||
case ESP_SPP_SRV_OPEN_EVT:
|
||||
{ //Server connection open
|
||||
case ESP_SPP_SRV_OPEN_EVT: {
|
||||
//Server connection open
|
||||
char str[18];
|
||||
str[17]='\0';
|
||||
uint8_t * addr = param->srv_open.rem_bda;
|
||||
@ -80,22 +80,22 @@ static void my_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
|
||||
stmp += str;
|
||||
output.printMSG(stmp.c_str());
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG(stmp.c_str());
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG(stmp.c_str());
|
||||
#endif //DISPLAY_DEVICE
|
||||
}
|
||||
break;
|
||||
|
||||
case ESP_SPP_CLOSE_EVT:
|
||||
{//Client connection closed
|
||||
case ESP_SPP_CLOSE_EVT: {
|
||||
//Client connection closed
|
||||
output.printMSG("BT Disconnected");
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("BT Disconnected");
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("BT Disconnected");
|
||||
#endif //DISPLAY_DEVICE
|
||||
BTService::setClientAddress("");
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ bool BootDelay::begin(progress_t* fn)
|
||||
_totalduration = Settings_ESP3D::read_uint32(ESP_BOOT_DELAY);
|
||||
log_esp3d("Boot delay %d", _totalduration);
|
||||
if (_totalduration > Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY)) {
|
||||
_totalduration = Settings_ESP3D::get_max_int32_value(ESP_BOOT_DELAY);
|
||||
_totalduration = Settings_ESP3D::get_default_int32_value(ESP_BOOT_DELAY);
|
||||
log_esp3d("Boot delay modified %d", _totalduration);
|
||||
}
|
||||
_callbackfn = fn;
|
||||
|
@ -62,13 +62,13 @@ Display esp3d_display;
|
||||
|
||||
bool Display::splash()
|
||||
{
|
||||
log_esp3d("Splash");
|
||||
//log_esp3d("Splash");
|
||||
if ( !ESP3DOutput::isOutput(ESP_SCREEN_CLIENT)) {
|
||||
return false;
|
||||
}
|
||||
if (!_splash_displayed) {
|
||||
drawXbm((_screenwidth-ESP3D_Logo_width)/2, (_screenheight-ESP3D_Logo_height)/2, ESP3D_Logo_width, ESP3D_Logo_height, SPLASH_FG, SPLASH_BG ,ESP3D_Logo);
|
||||
log_esp3d("Display Splash");
|
||||
drawXbm((_screenwidth-ESP3D_Logo_width)/2, (_screenheight-ESP3D_Logo_height)/2, ESP3D_Logo_width, ESP3D_Logo_height, SPLASH_FG, SPLASH_BG,ESP3D_Logo);
|
||||
//log_esp3d("Display Splash");
|
||||
_splash_displayed = true;
|
||||
return true;
|
||||
}
|
||||
@ -78,246 +78,246 @@ bool Display::splash()
|
||||
|
||||
void Display::showStatus()
|
||||
{
|
||||
//Display Status
|
||||
String status = _status;
|
||||
setTextFont(FONTSTATUS);
|
||||
uint16_t size = sizetoFitSpace(status.c_str(), STATUS_AREA_W);
|
||||
//check the need for resize
|
||||
if (size < status.length()){
|
||||
static int status_shift = -1;
|
||||
status+=" ";
|
||||
log_esp3d("current %s", status.c_str());
|
||||
if (status_shift > status.length()){
|
||||
status_shift = -1;
|
||||
}
|
||||
log_esp3d("shift %d", status_shift);
|
||||
if (status_shift > 0){
|
||||
status.remove(0,status_shift);
|
||||
}
|
||||
log_esp3d("shifted %s", status.c_str());
|
||||
size = sizetoFitSpace(status.c_str(), STATUS_AREA_W);
|
||||
log_esp3d("size available %d existing %d",size, status.length());
|
||||
if (size < status.length()){
|
||||
//cut
|
||||
status = status.substring(0,size);
|
||||
status_shift++;
|
||||
} else{
|
||||
status_shift = -1;
|
||||
}
|
||||
log_esp3d("sized %s", status.c_str());
|
||||
}
|
||||
//clear area
|
||||
fillRect(STATUS_AREA_X, STATUS_AREA_Y, STATUS_AREA_W, STATUS_AREA_H, SCREEN_BG);
|
||||
drawString(status.c_str(), STATUS_AREA_X, STATUS_AREA_Y, STATUS_FG);
|
||||
//Display Status
|
||||
String status = _status;
|
||||
setTextFont(FONTSTATUS);
|
||||
uint16_t size = sizetoFitSpace(status.c_str(), STATUS_AREA_W);
|
||||
//check the need for resize
|
||||
if (size < status.length()) {
|
||||
static int status_shift = -1;
|
||||
status+=" ";
|
||||
//log_esp3d("current %s", status.c_str());
|
||||
if (status_shift > status.length()) {
|
||||
status_shift = -1;
|
||||
}
|
||||
//log_esp3d("shift %d", status_shift);
|
||||
if (status_shift > 0) {
|
||||
status.remove(0,status_shift);
|
||||
}
|
||||
//log_esp3d("shifted %s", status.c_str());
|
||||
size = sizetoFitSpace(status.c_str(), STATUS_AREA_W);
|
||||
//log_esp3d("size available %d existing %d",size, status.length());
|
||||
if (size < status.length()) {
|
||||
//cut
|
||||
status = status.substring(0,size);
|
||||
status_shift++;
|
||||
} else {
|
||||
status_shift = -1;
|
||||
}
|
||||
//log_esp3d("sized %s", status.c_str());
|
||||
}
|
||||
//clear area
|
||||
fillRect(STATUS_AREA_X, STATUS_AREA_Y, STATUS_AREA_W, STATUS_AREA_H, SCREEN_BG);
|
||||
drawString(status.c_str(), STATUS_AREA_X, STATUS_AREA_Y, STATUS_FG);
|
||||
}
|
||||
|
||||
bool Display::main_screen()
|
||||
{
|
||||
log_esp3d("Mainscreen");
|
||||
//Signal
|
||||
int sig = -1;
|
||||
|
||||
//log_esp3d("Mainscreen");
|
||||
//Signal
|
||||
int sig = -1;
|
||||
|
||||
#if defined (WIFI_FEATURE)
|
||||
if (WiFiConfig::started()){
|
||||
String ssid;
|
||||
if (WiFi.getMode() == WIFI_AP) {
|
||||
sig = 100;
|
||||
ssid = WiFiConfig::AP_SSID();
|
||||
} else {
|
||||
if (WiFi.isConnected()) {
|
||||
sig = WiFiConfig::getSignal (WiFi.RSSI ());
|
||||
ssid = WiFi.SSID();
|
||||
if (WiFiConfig::started()) {
|
||||
String ssid;
|
||||
if (WiFi.getMode() == WIFI_AP) {
|
||||
sig = 100;
|
||||
ssid = WiFiConfig::AP_SSID();
|
||||
} else {
|
||||
if (WiFi.isConnected()) {
|
||||
sig = WiFiConfig::getSignal (WiFi.RSSI ());
|
||||
ssid = WiFi.SSID();
|
||||
}
|
||||
}
|
||||
|
||||
//Display SSID
|
||||
setTextFont(FONTSSID);
|
||||
uint16_t size = sizetoFitSpace(ssid.c_str(), SSID_AREA_W);
|
||||
//check the need for resize
|
||||
if (size < ssid.length()){
|
||||
static int ssid_shift = -1;
|
||||
ssid+=" ";
|
||||
log_esp3d("current %s", ssid.c_str());
|
||||
if (ssid_shift > ssid.length()){
|
||||
ssid_shift = -1;
|
||||
}
|
||||
log_esp3d("shift %d", ssid_shift);
|
||||
if (ssid_shift > 0){
|
||||
ssid.remove(0,ssid_shift);
|
||||
}
|
||||
log_esp3d("shifted %s", ssid.c_str());
|
||||
size = sizetoFitSpace(ssid.c_str(), SSID_AREA_W);
|
||||
log_esp3d("size available %d existing %d",size, ssid.length());
|
||||
if (size < ssid.length()){
|
||||
//cut
|
||||
ssid = ssid.substring(0,size);
|
||||
ssid_shift++;
|
||||
} else{
|
||||
ssid_shift = -1;
|
||||
}
|
||||
log_esp3d("sized %s", ssid.c_str());
|
||||
}
|
||||
//clear area
|
||||
fillRect(SSID_AREA_X, SSID_AREA_Y, SSID_AREA_W, SSID_AREA_H, SCREEN_BG);
|
||||
drawString(ssid.c_str(), SSID_AREA_X, SSID_AREA_Y, SSID_FG);
|
||||
}
|
||||
}
|
||||
|
||||
//Display SSID
|
||||
setTextFont(FONTSSID);
|
||||
uint16_t size = sizetoFitSpace(ssid.c_str(), SSID_AREA_W);
|
||||
//check the need for resize
|
||||
if (size < ssid.length()) {
|
||||
static int ssid_shift = -1;
|
||||
ssid+=" ";
|
||||
//log_esp3d("current %s", ssid.c_str());
|
||||
if (ssid_shift > ssid.length()) {
|
||||
ssid_shift = -1;
|
||||
}
|
||||
//log_esp3d("shift %d", ssid_shift);
|
||||
if (ssid_shift > 0) {
|
||||
ssid.remove(0,ssid_shift);
|
||||
}
|
||||
//log_esp3d("shifted %s", ssid.c_str());
|
||||
size = sizetoFitSpace(ssid.c_str(), SSID_AREA_W);
|
||||
//log_esp3d("size available %d existing %d",size, ssid.length());
|
||||
if (size < ssid.length()) {
|
||||
//cut
|
||||
ssid = ssid.substring(0,size);
|
||||
ssid_shift++;
|
||||
} else {
|
||||
ssid_shift = -1;
|
||||
}
|
||||
//log_esp3d("sized %s", ssid.c_str());
|
||||
}
|
||||
//clear area
|
||||
fillRect(SSID_AREA_X, SSID_AREA_Y, SSID_AREA_W, SSID_AREA_H, SCREEN_BG);
|
||||
drawString(ssid.c_str(), SSID_AREA_X, SSID_AREA_Y, SSID_FG);
|
||||
}
|
||||
#endif // WIFI_FEATURE
|
||||
#if defined (ETH_FEATURE)
|
||||
if (EthConfig::started()){
|
||||
sig = -2;
|
||||
setTextFont(FONTSSID);
|
||||
//clear area
|
||||
fillRect(SSID_AREA_X, SSID_AREA_Y, SSID_AREA_W, SSID_AREA_H, SCREEN_BG);
|
||||
//display connection speed
|
||||
if(ETH.linkUp()){
|
||||
ssid = ETH.linkSpeed();
|
||||
ssid+= "Mbps";
|
||||
drawString(ssid.c_str(), SSID_AREA_X, SSID_AREA_Y, SSID_FG);
|
||||
}
|
||||
}
|
||||
if (EthConfig::started()) {
|
||||
sig = -2;
|
||||
setTextFont(FONTSSID);
|
||||
//clear area
|
||||
fillRect(SSID_AREA_X, SSID_AREA_Y, SSID_AREA_W, SSID_AREA_H, SCREEN_BG);
|
||||
//display connection speed
|
||||
if(ETH.linkUp()) {
|
||||
ssid = ETH.linkSpeed();
|
||||
ssid+= "Mbps";
|
||||
drawString(ssid.c_str(), SSID_AREA_X, SSID_AREA_Y, SSID_FG);
|
||||
}
|
||||
}
|
||||
#endif //ETH_FEATURE
|
||||
#if defined (BLUETOOTH_FEATURE)
|
||||
if (bt_service.started()){
|
||||
sig = -3;
|
||||
//Display hostname
|
||||
String hostname = bt_service.hostname();
|
||||
setTextFont(FONTSSID);
|
||||
uint16_t size = sizetoFitSpace(hostname.c_str(), SSID_AREA_W);
|
||||
//check the need for resize
|
||||
if (size < hostname.length()){
|
||||
static int hostname_shift = -1;
|
||||
hostname+=" ";
|
||||
log_esp3d("current %s", hostname.c_str());
|
||||
if (hostname_shift > hostname.length()){
|
||||
hostname_shift = -1;
|
||||
}
|
||||
log_esp3d("shift %d", hostname_shift);
|
||||
if (hostname_shift > 0){
|
||||
hostname.remove(0,hostname_shift);
|
||||
}
|
||||
log_esp3d("shifted %s", hostname.c_str());
|
||||
size = sizetoFitSpace(hostname.c_str(), SSID_AREA_W);
|
||||
log_esp3d("size available %d existing %d",size, hostname.length());
|
||||
if (size < hostname.length()){
|
||||
//cut
|
||||
hostname = hostname.substring(0,size);
|
||||
hostname_shift++;
|
||||
} else{
|
||||
hostname_shift = -1;
|
||||
}
|
||||
log_esp3d("sized %s", hostname.c_str());
|
||||
}
|
||||
//clear area
|
||||
fillRect(SSID_AREA_X, SSID_AREA_Y, SSID_AREA_W, SSID_AREA_H, SCREEN_BG);
|
||||
if (hostname.length()>0){
|
||||
drawString(hostname.c_str(), SSID_AREA_X, SSID_AREA_Y, SSID_FG);
|
||||
}
|
||||
}
|
||||
if (bt_service.started()) {
|
||||
sig = -3;
|
||||
//Display hostname
|
||||
String hostname = bt_service.hostname();
|
||||
setTextFont(FONTSSID);
|
||||
uint16_t size = sizetoFitSpace(hostname.c_str(), SSID_AREA_W);
|
||||
//check the need for resize
|
||||
if (size < hostname.length()) {
|
||||
static int hostname_shift = -1;
|
||||
hostname+=" ";
|
||||
//log_esp3d("current %s", hostname.c_str());
|
||||
if (hostname_shift > hostname.length()) {
|
||||
hostname_shift = -1;
|
||||
}
|
||||
//log_esp3d("shift %d", hostname_shift);
|
||||
if (hostname_shift > 0) {
|
||||
hostname.remove(0,hostname_shift);
|
||||
}
|
||||
//log_esp3d("shifted %s", hostname.c_str());
|
||||
size = sizetoFitSpace(hostname.c_str(), SSID_AREA_W);
|
||||
//log_esp3d("size available %d existing %d",size, hostname.length());
|
||||
if (size < hostname.length()) {
|
||||
//cut
|
||||
hostname = hostname.substring(0,size);
|
||||
hostname_shift++;
|
||||
} else {
|
||||
hostname_shift = -1;
|
||||
}
|
||||
//log_esp3d("sized %s", hostname.c_str());
|
||||
}
|
||||
//clear area
|
||||
fillRect(SSID_AREA_X, SSID_AREA_Y, SSID_AREA_W, SSID_AREA_H, SCREEN_BG);
|
||||
if (hostname.length()>0) {
|
||||
drawString(hostname.c_str(), SSID_AREA_X, SSID_AREA_Y, SSID_FG);
|
||||
}
|
||||
}
|
||||
#endif //BLUETOOTH_FEATURE
|
||||
//set current font size
|
||||
setTextFont(FONTSIGNAL);
|
||||
fillRect(SIGNAL_X, SIGNAL_Y, SIGNAL_W, SIGNAL_H,SCREEN_BG);
|
||||
fillRect(SIGNAL_ICON_X, SIGNAL_ICON_Y, SIGNAL_ICON_W, SIGNAL_ICON_H,SCREEN_BG);
|
||||
String s;
|
||||
if (sig > 0) {
|
||||
//Signal %
|
||||
s = String(sig);
|
||||
s+="%";
|
||||
//Signal Icon according %
|
||||
if (sig > 0) {
|
||||
fillRect(SIGNAL_ICON_X, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.6), SIGNAL_ICON_W_BAR, SIGNAL_ICON_H * 0.4, SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.6), SIGNAL_ICON_W_BAR, SIGNAL_ICON_H * 0.4, SIGNAL_FG);
|
||||
}
|
||||
|
||||
if (sig >= 25) {
|
||||
fillRect(SIGNAL_ICON_X + SIGNAL_ICON_SPACER_X +SIGNAL_ICON_W_BAR, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.4), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.6), SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X + SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.4), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.6), SIGNAL_FG);
|
||||
}
|
||||
|
||||
if (sig >= 50) {
|
||||
fillRect(SIGNAL_ICON_X + (2*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.2), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.8), SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X + (2*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.2), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.8), SIGNAL_FG);
|
||||
}
|
||||
|
||||
if (sig >= 75) {
|
||||
fillRect(SIGNAL_ICON_X + (3*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y, SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H), SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X + (3*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y, SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H), SIGNAL_FG);
|
||||
}
|
||||
|
||||
}
|
||||
//No signal / no connection
|
||||
if (sig == -1) {
|
||||
s = " X";
|
||||
}
|
||||
//Ethernet is connected
|
||||
if (sig == -2) {
|
||||
s = "Eth";
|
||||
}
|
||||
//BT is active
|
||||
if (sig == -3) {
|
||||
s = "BT";
|
||||
}
|
||||
//Show Connection type
|
||||
drawString(s.c_str(), SIGNAL_X, SIGNAL_Y, SIGNAL_FG);
|
||||
|
||||
//IP
|
||||
setTextFont(FONTIP);
|
||||
fillRect(IP_AREA_X, IP_AREA_Y, IP_AREA_W, IP_AREA_H, SCREEN_BG);
|
||||
//set current font size
|
||||
setTextFont(FONTSIGNAL);
|
||||
fillRect(SIGNAL_X, SIGNAL_Y, SIGNAL_W, SIGNAL_H,SCREEN_BG);
|
||||
fillRect(SIGNAL_ICON_X, SIGNAL_ICON_Y, SIGNAL_ICON_W, SIGNAL_ICON_H,SCREEN_BG);
|
||||
String s;
|
||||
if (sig > 0) {
|
||||
//Signal %
|
||||
s = String(sig);
|
||||
s+="%";
|
||||
//Signal Icon according %
|
||||
if (sig > 0) {
|
||||
fillRect(SIGNAL_ICON_X, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.6), SIGNAL_ICON_W_BAR, SIGNAL_ICON_H * 0.4, SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.6), SIGNAL_ICON_W_BAR, SIGNAL_ICON_H * 0.4, SIGNAL_FG);
|
||||
}
|
||||
|
||||
if (sig >= 25) {
|
||||
fillRect(SIGNAL_ICON_X + SIGNAL_ICON_SPACER_X +SIGNAL_ICON_W_BAR, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.4), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.6), SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X + SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR, SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.4), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.6), SIGNAL_FG);
|
||||
}
|
||||
|
||||
if (sig >= 50) {
|
||||
fillRect(SIGNAL_ICON_X + (2*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.2), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.8), SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X + (2*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y + (SIGNAL_ICON_H * 0.2), SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H * 0.8), SIGNAL_FG);
|
||||
}
|
||||
|
||||
if (sig >= 75) {
|
||||
fillRect(SIGNAL_ICON_X + (3*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y, SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H), SIGNAL_FG);
|
||||
} else {
|
||||
drawRect(SIGNAL_ICON_X + (3*(SIGNAL_ICON_SPACER_X + SIGNAL_ICON_W_BAR)), SIGNAL_ICON_Y, SIGNAL_ICON_W_BAR, (SIGNAL_ICON_H), SIGNAL_FG);
|
||||
}
|
||||
|
||||
}
|
||||
//No signal / no connection
|
||||
if (sig == -1) {
|
||||
s = " X";
|
||||
}
|
||||
//Ethernet is connected
|
||||
if (sig == -2) {
|
||||
s = "Eth";
|
||||
}
|
||||
//BT is active
|
||||
if (sig == -3) {
|
||||
s = "BT";
|
||||
}
|
||||
//Show Connection type
|
||||
drawString(s.c_str(), SIGNAL_X, SIGNAL_Y, SIGNAL_FG);
|
||||
|
||||
//IP
|
||||
setTextFont(FONTIP);
|
||||
fillRect(IP_AREA_X, IP_AREA_Y, IP_AREA_W, IP_AREA_H, SCREEN_BG);
|
||||
#if defined (WIFI_FEATURE) || defined (ETH_FEATURE) || defined (BLUETOOTH_FEATURE)
|
||||
if (NetConfig::started()){
|
||||
switch(NetConfig::getMode()){
|
||||
if (NetConfig::started()) {
|
||||
switch(NetConfig::getMode()) {
|
||||
#if defined (WIFI_FEATURE)
|
||||
case ESP_WIFI_STA:
|
||||
s = WiFi.localIP().toString();
|
||||
break;
|
||||
case ESP_WIFI_AP:
|
||||
s = WiFi.softAPIP().toString();
|
||||
break;
|
||||
case ESP_WIFI_STA:
|
||||
s = WiFi.localIP().toString();
|
||||
break;
|
||||
case ESP_WIFI_AP:
|
||||
s = WiFi.softAPIP().toString();
|
||||
break;
|
||||
#endif //WIFI_FEATURE
|
||||
#if defined (ETH_FEATURE)
|
||||
case ESP_ETH_STA:
|
||||
s = ETH.localIP().toString();
|
||||
break;
|
||||
case ESP_ETH_STA:
|
||||
s = ETH.localIP().toString();
|
||||
break;
|
||||
#endif //ETH_FEATURE
|
||||
#if defined (BLUETOOTH_FEATURE)
|
||||
case ESP_BT:
|
||||
s = bt_service.isConnected()?"Connected":"";
|
||||
break;
|
||||
case ESP_BT:
|
||||
s = bt_service.isConnected()?"Connected":"";
|
||||
break;
|
||||
#endif //BLUETOOTH_FEATURE
|
||||
default:
|
||||
s="";
|
||||
break;
|
||||
}
|
||||
if (s.length()>0){
|
||||
drawString(s.c_str(), IP_AREA_X, IP_AREA_Y, IP_FG);
|
||||
}
|
||||
}
|
||||
default:
|
||||
s="";
|
||||
break;
|
||||
}
|
||||
if (s.length()>0) {
|
||||
drawString(s.c_str(), IP_AREA_X, IP_AREA_Y, IP_FG);
|
||||
}
|
||||
}
|
||||
#endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
|
||||
//status
|
||||
showStatus();
|
||||
return true;
|
||||
//status
|
||||
showStatus();
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t Display::sizetoFitSpace(const char * string, uint16_t maxwidth)
|
||||
{
|
||||
String s = string;
|
||||
while (getStringWidth(s.c_str()) > maxwidth) {
|
||||
if (s.length() > 0) {
|
||||
s.remove(s.length()-1);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return s.length();
|
||||
String s = string;
|
||||
while (getStringWidth(s.c_str()) > maxwidth) {
|
||||
if (s.length() > 0) {
|
||||
s.remove(s.length()-1);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return s.length();
|
||||
}
|
||||
|
||||
void Display::show_screenID(uint8_t screenID)
|
||||
{
|
||||
clear_screen();
|
||||
clear_screen();
|
||||
_screenID = screenID;
|
||||
}
|
||||
|
||||
@ -338,7 +338,7 @@ bool Display::begin()
|
||||
{
|
||||
bool res = true;
|
||||
_started = false;
|
||||
log_esp3d("Init Display");
|
||||
//log_esp3d("Init Display");
|
||||
#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
#if defined(DISPLAY_I2C_PIN_RST)
|
||||
pinMode(DISPLAY_I2C_PIN_RST,OUTPUT);
|
||||
@ -384,17 +384,17 @@ void Display::end()
|
||||
|
||||
void Display::SetStatus(const char * status)
|
||||
{
|
||||
_status= status;
|
||||
_status= status;
|
||||
}
|
||||
|
||||
void Display::clear_screen()
|
||||
{
|
||||
log_esp3d("clear screen");
|
||||
//log_esp3d("clear screen");
|
||||
#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
esp3d_screen.clear();
|
||||
#endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
#if DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240
|
||||
log_esp3d("Fill black");
|
||||
//log_esp3d("Fill black");
|
||||
esp3d_screen.fillScreen(SCREEN_BG); // Black screen fill
|
||||
#endif //TFT_SPI_ILI9341_240X320
|
||||
}
|
||||
@ -407,9 +407,9 @@ void Display::update_screen(bool force)
|
||||
bool need_update = force;
|
||||
switch(_screenID) {
|
||||
case SPLASH_SCREEN:
|
||||
if (!_splash_displayed) {
|
||||
need_update = splash();
|
||||
}
|
||||
if (!_splash_displayed) {
|
||||
need_update = splash();
|
||||
}
|
||||
break;
|
||||
case MAIN_SCREEN:
|
||||
need_update = main_screen();
|
||||
@ -420,9 +420,9 @@ void Display::update_screen(bool force)
|
||||
if (need_update) {
|
||||
#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
esp3d_screen.display();
|
||||
log_esp3d("Update display");
|
||||
//log_esp3d("Update display");
|
||||
#endif //DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
Hal::wait(0);
|
||||
Hal::wait(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -488,16 +488,16 @@ void Display::setTextFont(uint8_t font)
|
||||
{
|
||||
#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
switch(font) {
|
||||
case 3:
|
||||
esp3d_screen.setFont(ArialMT_Plain_16);
|
||||
break;
|
||||
case 3:
|
||||
esp3d_screen.setFont(ArialMT_Plain_16);
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
esp3d_screen.setFont(ArialMT_Plain_10);
|
||||
}
|
||||
#endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
#if DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240
|
||||
esp3d_screen.setTextFont(font);
|
||||
esp3d_screen.setTextFont(font);
|
||||
#endif //TFT_SPI_ILI9341_240X320
|
||||
}
|
||||
void Display::drawString(const char *string, int32_t poX, int32_t poY, int16_t color)
|
||||
@ -510,7 +510,7 @@ void Display::drawString(const char *string, int32_t poX, int32_t poY, int16_t c
|
||||
esp3d_screen.drawString(poX, poY, string);
|
||||
#endif //#if DISPLAY_DEVICE == OLED_I2C_SSD1306 || DISPLAY_DEVICE == OLED_I2C_SSDSH1106
|
||||
#if DISPLAY_DEVICE == TFT_SPI_ILI9341_320X240
|
||||
esp3d_screen.setTextColor(color);
|
||||
esp3d_screen.setTextColor(color);
|
||||
esp3d_screen.drawString(string, poX, poY);
|
||||
#endif //TFT_SPI_ILI9341_240X320
|
||||
}
|
||||
@ -564,11 +564,11 @@ void Display::progress(uint8_t v)
|
||||
}
|
||||
static uint8_t previous = 0;
|
||||
if (previous > v) {
|
||||
//clear
|
||||
fillRect(10, _screenheight-2, _screenwidth-20, 2, SCREEN_BG);
|
||||
}
|
||||
log_esp3d("%d", v);
|
||||
previous = v;
|
||||
//clear
|
||||
fillRect(10, _screenheight-2, _screenwidth-20, 2, SCREEN_BG);
|
||||
}
|
||||
//log_esp3d("%d", v);
|
||||
previous = v;
|
||||
//display bar
|
||||
drawRect(10, _screenheight-2, ((_screenwidth-20) * v)/100, 2, PROGRESS_FG);
|
||||
//update screen
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
void progress(uint8_t v);
|
||||
void SetStatus(const char * status);
|
||||
private:
|
||||
bool main_screen();
|
||||
bool main_screen();
|
||||
bool splash();
|
||||
void showStatus();
|
||||
bool _started;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "host_services.h"
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
|
||||
#include "../serial/serial_service.h"
|
||||
|
||||
HostServices::HostServices()
|
||||
{
|
||||
@ -59,3 +59,32 @@ void HostServices::handle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool HostServices::purge_serial()
|
||||
{
|
||||
uint32_t start = millis();
|
||||
uint8_t buf [51];
|
||||
serial_service.flush();
|
||||
log_esp3d("Purge Serial");
|
||||
while (serial_service.available() > 0 ) {
|
||||
if ((millis() - start ) > 2000) {
|
||||
log_esp3d("Purge timeout");
|
||||
return false;
|
||||
}
|
||||
size_t len = serial_service.readBytes (buf, 50);
|
||||
buf[len] = '\0';
|
||||
log_esp3d ("Purge: %s",(const char *)buf);
|
||||
if ( (Settings_ESP3D::GetFirmwareTarget() == REPETIER4DV) || (Settings_ESP3D::GetFirmwareTarget() == REPETIER) ) {
|
||||
String s = (const char *)buf;
|
||||
//repetier never stop sending data so no need to wait if have 'wait' or 'busy'
|
||||
if((s.indexOf ("wait") > -1) || (s.indexOf ("busy") > -1)) {
|
||||
return true;
|
||||
}
|
||||
log_esp3d("Purge interrupted");
|
||||
}
|
||||
Hal::wait (5);
|
||||
}
|
||||
Hal::wait (0);
|
||||
log_esp3d("Purge done");
|
||||
return true;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
void handle();
|
||||
private:
|
||||
bool _started;
|
||||
bool purge_serial();
|
||||
};
|
||||
|
||||
#endif //_HOST_SERVICES_H
|
||||
|
@ -132,38 +132,35 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
case WIFI_EVENT_STAMODE_CONNECTED:
|
||||
_needReconnect2AP = false;
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_DISCONNECTED:
|
||||
{
|
||||
case WIFI_EVENT_STAMODE_DISCONNECTED: {
|
||||
if(_started) {
|
||||
output.printMSG ("Disconnected");
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
#endif //DISPLAY_DEVICE
|
||||
_needReconnect2AP = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_GOT_IP:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case WIFI_EVENT_STAMODE_GOT_IP: {
|
||||
output.printMSG ("Connected");
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
{
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("Connected");
|
||||
}
|
||||
{
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("Connected");
|
||||
}
|
||||
#endif //DISPLAY_DEVICE
|
||||
output.printMSG (WiFi.localIP().toString().c_str());
|
||||
}
|
||||
break;
|
||||
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case WIFI_EVENT_SOFTAPMODE_STACONNECTED: {
|
||||
output.printMSG ("New client");
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("New client");
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("New client");
|
||||
#endif //DISPLAY_DEVICE
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
case SYSTEM_EVENT_STA_LOST_IP:
|
||||
if(_started) {
|
||||
@ -171,24 +168,22 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
}
|
||||
break;
|
||||
#ifdef ETH_FEATURE
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
{
|
||||
case SYSTEM_EVENT_ETH_CONNECTED: {
|
||||
output.printMSG ("Cable connected");
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("Cable connected");
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("Cable connected");
|
||||
#endif //DISPLAY_DEVICE
|
||||
}
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED: {
|
||||
output.printMSG ("Cable disconnected");
|
||||
#if defined (DISPLAY_DEVICE)
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("Cable disconnected");
|
||||
ESP3DOutput outputscr(ESP_SCREEN_CLIENT);
|
||||
outputscr.printMSG("Cable disconnected");
|
||||
#endif //DISPLAY_DEVICE
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
output.printMSG (ETH.localIP().toString().c_str());
|
||||
break;
|
||||
@ -201,7 +196,7 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event)
|
||||
|
||||
uint8_t NetConfig::getMode()
|
||||
{
|
||||
return _mode;
|
||||
return _mode;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,6 +269,7 @@ bool NetConfig::begin()
|
||||
}
|
||||
#endif //WIFI_FEATURE
|
||||
#endif //ARDUINO_ARCH_ESP32
|
||||
DEBUG_ESP3D_NETWORK_INIT
|
||||
if (res) {
|
||||
_started = true;
|
||||
} else {
|
||||
@ -289,7 +285,8 @@ bool NetConfig::begin()
|
||||
void NetConfig::end()
|
||||
{
|
||||
NetServices::end();
|
||||
_mode = ESP_RADIO_OFF;
|
||||
DEBUG_ESP3D_NETWORK_END
|
||||
_mode = ESP_RADIO_OFF;
|
||||
#if defined (WIFI_FEATURE)
|
||||
WiFiConfig::end();
|
||||
_needReconnect2AP=false;
|
||||
@ -357,6 +354,8 @@ void NetConfig::handle()
|
||||
bt_service.handle();
|
||||
#endif //BLUETOOTH_FEATURE
|
||||
NetServices::handle();
|
||||
//Debug
|
||||
DEBUG_ESP3D_NETWORK_HANDLE
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
#define MIN_HTTP_PORT 1
|
||||
#define MAX_TELNET_PORT 65001
|
||||
#define MIN_TELNET_PORT 1
|
||||
#define MAX_WEBSOCKET_PORT 65001
|
||||
#define MIN_WEBSOCKET_PORT 1
|
||||
#define MAX_HOSTNAME_LENGTH 32
|
||||
#define MIN_HOSTNAME_LENGTH 1
|
||||
|
||||
|
@ -200,11 +200,19 @@ bool NetServices::begin()
|
||||
output.printMSG(stmp.c_str());
|
||||
}
|
||||
#endif //TELNET_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
if (!websocket_data_server.begin(Settings_ESP3D::read_uint32(ESP_WEBSOCKET_PORT))) {
|
||||
output.printMSG("Failed start Terminal Web Socket");
|
||||
} else {
|
||||
String stmp = "Websocket server started port " + String(websocket_data_server.port());
|
||||
output.printMSG(stmp.c_str());
|
||||
}
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(HTTP_FEATURE)
|
||||
if (!websocket_terminal_server.begin()) {
|
||||
output.printMSG("Failed start Terminal Web Socket");
|
||||
}
|
||||
#endif //HTTP_FEATURE || WS_DATA_FEATURE
|
||||
#endif //HTTP_FEATURE
|
||||
#ifdef MDNS_FEATURE
|
||||
if(WiFi.getMode() != WIFI_AP) {
|
||||
// Add service to MDNS-SD
|
||||
@ -283,7 +291,9 @@ void NetServices::end()
|
||||
#ifdef HTTP_FEATURE
|
||||
HTTP_Server::end();
|
||||
#endif //HTTP_FEATURE
|
||||
|
||||
#ifdef WS_DATA_FEATURE
|
||||
websocket_data_server.end();
|
||||
#endif //WS_DATA_FEATURE
|
||||
#ifdef TELNET_FEATURE
|
||||
telnet_server.end();
|
||||
#endif //TELNET_FEATURE
|
||||
@ -309,6 +319,9 @@ void NetServices::handle()
|
||||
#ifdef HTTP_FEATURE
|
||||
HTTP_Server::handle();
|
||||
#endif //HTTP_FEATURE
|
||||
#ifdef WS_DATA_FEATURE
|
||||
websocket_data_server.handle();
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined(HTTP_FEATURE)
|
||||
websocket_terminal_server.handle();
|
||||
#endif //HTTP_FEATURE
|
||||
|
@ -77,7 +77,9 @@ Telnet_Server::Telnet_Server()
|
||||
{
|
||||
_buffer_size = 0;
|
||||
_started = false;
|
||||
_isdebug = false;
|
||||
_port = 0;
|
||||
_buffer = nullptr;
|
||||
_telnetserver = nullptr;
|
||||
}
|
||||
Telnet_Server::~Telnet_Server()
|
||||
@ -88,11 +90,22 @@ Telnet_Server::~Telnet_Server()
|
||||
/**
|
||||
* begin Telnet setup
|
||||
*/
|
||||
bool Telnet_Server::begin()
|
||||
bool Telnet_Server::begin(uint16_t port, bool debug)
|
||||
{
|
||||
end();
|
||||
//Get telnet port
|
||||
_port = Settings_ESP3D::read_uint32(ESP_TELNET_PORT);
|
||||
if (port == 0) {
|
||||
_port = Settings_ESP3D::read_uint32(ESP_TELNET_PORT);
|
||||
} else {
|
||||
_port = port;
|
||||
}
|
||||
_isdebug = debug;
|
||||
if (!_isdebug) {
|
||||
_buffer= (uint8_t *)malloc(ESP3D_TELNET_BUFFER_SIZE +1);
|
||||
if (!_buffer) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//create instance
|
||||
_telnetserver= new WiFiServer(_port);
|
||||
if (!_telnetserver) {
|
||||
@ -113,11 +126,17 @@ void Telnet_Server::end()
|
||||
_started = false;
|
||||
_buffer_size = 0;
|
||||
_port = 0;
|
||||
_isdebug = false;
|
||||
closeClient();
|
||||
if (_telnetserver) {
|
||||
delete _telnetserver;
|
||||
_telnetserver = nullptr;
|
||||
}
|
||||
|
||||
if (_buffer) {
|
||||
free(_buffer);
|
||||
_buffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +168,7 @@ void Telnet_Server::handle()
|
||||
if (count > 0) {
|
||||
push2buffer(sbuf, count);
|
||||
}
|
||||
//freen buffer
|
||||
//free buffer
|
||||
free(sbuf);
|
||||
}
|
||||
}
|
||||
@ -164,6 +183,10 @@ void Telnet_Server::handle()
|
||||
|
||||
void Telnet_Server::flushbuffer()
|
||||
{
|
||||
if (!_buffer || _started) {
|
||||
_buffer_size = 0;
|
||||
return;
|
||||
}
|
||||
ESP3DOutput output(ESP_TELNET_CLIENT);
|
||||
_buffer[_buffer_size] = 0x0;
|
||||
//dispatch command
|
||||
@ -174,6 +197,9 @@ void Telnet_Server::flushbuffer()
|
||||
|
||||
void Telnet_Server::push2buffer(uint8_t * sbuf, size_t len)
|
||||
{
|
||||
if (!_buffer) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
_lastflush = millis();
|
||||
//command is defined
|
||||
@ -212,7 +238,7 @@ size_t Telnet_Server::write(uint8_t c)
|
||||
|
||||
size_t Telnet_Server::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if (isConnected()) {
|
||||
if (isConnected() && (size>0)) {
|
||||
if (availableForWrite() >= size) {
|
||||
//push data to connected telnet client
|
||||
return _telnetClients.write(buffer, size);
|
||||
|
@ -23,15 +23,16 @@
|
||||
|
||||
class WiFiServer;
|
||||
class WiFiClient;
|
||||
#include "Print.h"
|
||||
|
||||
#define ESP3D_TELNET_BUFFER_SIZE 1200
|
||||
|
||||
class Telnet_Server
|
||||
class Telnet_Server : public Print
|
||||
{
|
||||
public:
|
||||
Telnet_Server();
|
||||
~Telnet_Server();
|
||||
bool begin();
|
||||
bool begin(uint16_t port = 0, bool debug=false);
|
||||
void end();
|
||||
void handle();
|
||||
bool reset();
|
||||
@ -75,8 +76,9 @@ private:
|
||||
WiFiServer * _telnetserver;
|
||||
WiFiClient _telnetClients;
|
||||
uint16_t _port;
|
||||
bool _isdebug;
|
||||
uint32_t _lastflush;
|
||||
uint8_t _buffer[ESP3D_TELNET_BUFFER_SIZE +1]; //keep space of 0x0 terminal
|
||||
uint8_t *_buffer;
|
||||
size_t _buffer_size;
|
||||
void push2buffer(uint8_t * sbuf, size_t len);
|
||||
void flushbuffer();
|
||||
|
@ -27,9 +27,13 @@
|
||||
#include "websocket_server.h"
|
||||
#include <WebSocketsServer.h>
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../../core/esp3doutput.h"
|
||||
#include "../../core/commands.h"
|
||||
|
||||
WebSocket_Server websocket_terminal_server;
|
||||
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
WebSocket_Server websocket_data_server;
|
||||
#endif //WS_DATA_FEATURE
|
||||
void WebSocket_Server::pushMSG (const char * data)
|
||||
{
|
||||
_websocket_server->broadcastTXT(data);
|
||||
@ -37,16 +41,53 @@ void WebSocket_Server::pushMSG (const char * data)
|
||||
|
||||
void WebSocket_Server::pushMSG (uint num, const char * data)
|
||||
{
|
||||
_websocket_server->sendTXT(num, data);
|
||||
if (_websocket_server) {
|
||||
_websocket_server->sendTXT(num, data);
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket_Server::closeClients()
|
||||
{
|
||||
if (_websocket_server) {
|
||||
_websocket_server->disconnect();
|
||||
}
|
||||
}
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
//Events for Websocket bridge
|
||||
void handle_Websocket_Server_Event(uint8_t num, uint8_t type, uint8_t * payload, size_t length)
|
||||
{
|
||||
(void)num;
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
log_esp3d("[%u] Disconnected! port %d", num,websocket_data_server.port());
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
log_esp3d("[%u] Connected! port %d", num,websocket_data_server.port());
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
log_esp3d("[%u] get Text: %s port %d", num, payload,websocket_data_server.port());
|
||||
websocket_data_server.push2RXbuffer(payload, length);
|
||||
break;
|
||||
case WStype_BIN:
|
||||
log_esp3d("[%u] get binary length: %u port %d", num, length,websocket_data_server.port());
|
||||
websocket_data_server.push2RXbuffer(payload, length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
#endif //WS_DATA_FEATURE
|
||||
#if defined (HTTP_FEATURE)
|
||||
//Events for Websocket used in WebUI for events and serial bridge
|
||||
void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payload, size_t length)
|
||||
{
|
||||
(void)payload;
|
||||
(void)length;
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
//Serial.printf("[%u] Disconnected!\n", num);
|
||||
log_esp3d("[%u] Socket Disconnected port %d!", num,websocket_terminal_server.port());
|
||||
break;
|
||||
case WStype_CONNECTED: {
|
||||
String s = "currentID:" + String(num);
|
||||
@ -55,43 +96,48 @@ void handle_Websocket_Terminal_Event(uint8_t num, uint8_t type, uint8_t * payloa
|
||||
websocket_terminal_server.pushMSG(num, s.c_str());
|
||||
s = "activeID:" + String(num);
|
||||
websocket_terminal_server.pushMSG(s.c_str());
|
||||
log_esp3d("[%u] Socket connected port %d", num,websocket_terminal_server.port());
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
//USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
|
||||
|
||||
// send message to client
|
||||
// webSocket.sendTXT(num, "message here");
|
||||
|
||||
// send data to all connected clients
|
||||
// webSocket.broadcastTXT("message here");
|
||||
//we do not expect any input
|
||||
log_esp3d("[IGNORED][%u] get Text: %s port %d", num, payload, num,websocket_terminal_server.port());
|
||||
break;
|
||||
case WStype_BIN:
|
||||
//USE_SERIAL.printf("[%u] get binary length: %u\n", num, length);
|
||||
//hexdump(payload, length);
|
||||
|
||||
// send message to client
|
||||
// webSocket.sendBIN(num, payload, length);
|
||||
//we do not expect any input
|
||||
log_esp3d("[IGNORED][%u] get binary length: %u port %d", num, length, num,websocket_terminal_server.port());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
#endif //HTTP_FEATURE
|
||||
|
||||
int WebSocket_Server::available()
|
||||
{
|
||||
return _RXbufferSize;
|
||||
}
|
||||
uint WebSocket_Server::availableForWrite()
|
||||
{
|
||||
return TXBUFFERSIZE -_TXbufferSize;
|
||||
}
|
||||
WebSocket_Server::WebSocket_Server()
|
||||
{
|
||||
_websocket_server = nullptr;
|
||||
_started = false;
|
||||
_port = 0;
|
||||
_current_id = 0;
|
||||
_isdebug = false;
|
||||
_RXbuffer = nullptr;
|
||||
_RXbufferSize = 0;
|
||||
|
||||
}
|
||||
WebSocket_Server::~WebSocket_Server()
|
||||
{
|
||||
end();
|
||||
}
|
||||
bool WebSocket_Server::begin(uint16_t port)
|
||||
bool WebSocket_Server::begin(uint16_t port, bool debug)
|
||||
{
|
||||
end();
|
||||
if(port == 0) {
|
||||
@ -99,6 +145,7 @@ bool WebSocket_Server::begin(uint16_t port)
|
||||
} else {
|
||||
_port = port;
|
||||
}
|
||||
_isdebug = debug;
|
||||
_websocket_server = new WebSocketsServer(_port);
|
||||
if (_websocket_server) {
|
||||
_websocket_server->begin();
|
||||
@ -107,6 +154,15 @@ bool WebSocket_Server::begin(uint16_t port)
|
||||
_websocket_server->onEvent(handle_Websocket_Terminal_Event);
|
||||
}
|
||||
#endif //HTTP_FEATURE
|
||||
#if defined (WS_DATA_FEATURE) //terminal websocket for HTTP
|
||||
if((port != 0) && !_isdebug) {
|
||||
_websocket_server->onEvent(handle_Websocket_Server_Event);
|
||||
_RXbuffer= (uint8_t *)malloc(RXBUFFERSIZE +1);
|
||||
if (!_RXbuffer) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif //WS_DATA_FEATURE
|
||||
_started = true;
|
||||
} else {
|
||||
end();
|
||||
@ -118,8 +174,12 @@ void WebSocket_Server::end()
|
||||
{
|
||||
_current_id = 0;
|
||||
_TXbufferSize = 0;
|
||||
//_RXbufferSize = 0;
|
||||
//_RXbufferpos = 0;
|
||||
_isdebug = false;
|
||||
if(_RXbuffer) {
|
||||
free(_RXbuffer);
|
||||
_RXbuffer = nullptr;
|
||||
}
|
||||
_RXbufferSize = 0;
|
||||
if (_websocket_server) {
|
||||
_websocket_server->close();
|
||||
delete _websocket_server;
|
||||
@ -144,11 +204,6 @@ uint8_t WebSocket_Server::get_currentID()
|
||||
return _current_id;
|
||||
}
|
||||
|
||||
/*int WebSocket_Server::available(){
|
||||
return _RXbufferSize;
|
||||
}*/
|
||||
|
||||
|
||||
size_t WebSocket_Server::write(uint8_t c)
|
||||
{
|
||||
return write(&c,1);;
|
||||
@ -156,84 +211,128 @@ size_t WebSocket_Server::write(uint8_t c)
|
||||
|
||||
size_t WebSocket_Server::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if((buffer == NULL) ||(!_websocket_server) || (size == 0)) {
|
||||
log_esp3d("%s %d",_websocket_server?"[SOCKET]No socket":"[SOCKET]No buffer", size);
|
||||
return 0;
|
||||
if (_started) {
|
||||
if((buffer == nullptr) ||(!_websocket_server) || (size == 0)) {
|
||||
return 0;
|
||||
}
|
||||
if (_TXbufferSize==0) {
|
||||
_lastTXflush = millis();
|
||||
}
|
||||
//send full line
|
||||
if (_TXbufferSize + size > TXBUFFERSIZE) {
|
||||
flushTXbuffer();
|
||||
}
|
||||
if(_websocket_server->connectedClients() == 0) {
|
||||
return 0;
|
||||
}
|
||||
//need periodic check to force to flush in case of no end
|
||||
for (uint i = 0; i < size; i++) {
|
||||
_TXbuffer[_TXbufferSize] = buffer[i];
|
||||
_TXbufferSize++;
|
||||
}
|
||||
//if(!_isdebug) {
|
||||
// log_esp3d("[SOCKET]buffer size %d",_TXbufferSize);
|
||||
//}
|
||||
return size;
|
||||
}
|
||||
if (_TXbufferSize==0) {
|
||||
_lastflush = millis();
|
||||
}
|
||||
//send full line
|
||||
if (_TXbufferSize + size > TXBUFFERSIZE) {
|
||||
flush();
|
||||
}
|
||||
//need periodic check to force to flush in case of no end
|
||||
for (uint i = 0; i < size; i++) {
|
||||
_TXbuffer[_TXbufferSize] = buffer[i];
|
||||
_TXbufferSize++;
|
||||
}
|
||||
log_esp3d("[SOCKET]buffer size %d",_TXbufferSize);
|
||||
return size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*int WebSocket_Server::peek(void){
|
||||
if (_RXbufferSize > 0)return _RXbuffer[_RXbufferpos];
|
||||
else return -1;
|
||||
}*/
|
||||
|
||||
/*bool WebSocket_Server::push (const char * data){
|
||||
int data_size = strlen(data);
|
||||
if ((data_size + _RXbufferSize) <= RXBUFFERSIZE){
|
||||
int current = _RXbufferpos + _RXbufferSize;
|
||||
if (current > RXBUFFERSIZE) current = current - RXBUFFERSIZE;
|
||||
for (int i = 0; i < data_size; i++){
|
||||
if (current > (RXBUFFERSIZE-1)) current = 0;
|
||||
_RXbuffer[current] = data[i];
|
||||
current ++;
|
||||
}
|
||||
_RXbufferSize+=strlen(data);
|
||||
return true;
|
||||
void WebSocket_Server::push2RXbuffer(uint8_t * sbuf, size_t len)
|
||||
{
|
||||
if (!_RXbuffer || !_started) {
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
_lastRXflush = millis();
|
||||
//command is defined
|
||||
if (char(sbuf[i]) == '\n') {
|
||||
if (_RXbufferSize < RXBUFFERSIZE) {
|
||||
_RXbuffer[_RXbufferSize] = sbuf[i];
|
||||
_RXbufferSize++;
|
||||
}
|
||||
flushRXbuffer();
|
||||
} else if (isPrintable (char(sbuf[i]) ) || char(sbuf[i]) == '\r') {
|
||||
if (_RXbufferSize < RXBUFFERSIZE) {
|
||||
_RXbuffer[_RXbufferSize] = sbuf[i];
|
||||
_RXbufferSize++;
|
||||
} else {
|
||||
flushRXbuffer();
|
||||
_RXbuffer[_RXbufferSize] = sbuf[i];
|
||||
_RXbufferSize++;
|
||||
}
|
||||
} else { //it is not printable char
|
||||
//clean buffer first
|
||||
if (_RXbufferSize > 0) {
|
||||
flushRXbuffer();
|
||||
}
|
||||
//process char
|
||||
_RXbuffer[_RXbufferSize] = sbuf[i];
|
||||
_RXbufferSize++;
|
||||
flushRXbuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket_Server::flushRXbuffer()
|
||||
{
|
||||
if (!_RXbuffer || !_started) {
|
||||
_RXbufferSize = 0;
|
||||
return;
|
||||
}
|
||||
ESP3DOutput output(ESP_WEBSOCKET_CLIENT);
|
||||
_RXbuffer[_RXbufferSize] = 0x0;
|
||||
//dispatch command
|
||||
esp3d_commands.process(_RXbuffer, _RXbufferSize, &output);
|
||||
_lastRXflush = millis();
|
||||
_RXbufferSize = 0;
|
||||
}
|
||||
|
||||
/*int WebSocket_Server::read(void){
|
||||
if (_RXbufferSize > 0) {
|
||||
int v = _RXbuffer[_RXbufferpos];
|
||||
_RXbufferpos++;
|
||||
if (_RXbufferpos > (RXBUFFERSIZE-1))_RXbufferpos = 0;
|
||||
_RXbufferSize--;
|
||||
return v;
|
||||
} else return -1;
|
||||
}*/
|
||||
|
||||
void WebSocket_Server::handle()
|
||||
{
|
||||
if (_TXbufferSize > 0) {
|
||||
if ((_TXbufferSize>=TXBUFFERSIZE) || ((millis()- _lastflush) > FLUSHTIMEOUT)) {
|
||||
log_esp3d("[SOCKET]need flush, buffer size %d",_TXbufferSize);
|
||||
flush();
|
||||
Hal::wait(0);
|
||||
if (_started) {
|
||||
if (_TXbufferSize > 0) {
|
||||
if ((_TXbufferSize>=TXBUFFERSIZE) || ((millis()- _lastTXflush) > FLUSHTIMEOUT)) {
|
||||
flushTXbuffer();
|
||||
}
|
||||
}
|
||||
if (_RXbufferSize > 0) {
|
||||
if ((_RXbufferSize>=RXBUFFERSIZE) || ((millis()- _lastRXflush) > FLUSHTIMEOUT)) {
|
||||
flushRXbuffer();
|
||||
}
|
||||
}
|
||||
if (_websocket_server) {
|
||||
_websocket_server->loop();
|
||||
}
|
||||
}
|
||||
if (_websocket_server) {
|
||||
_websocket_server->loop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WebSocket_Server::flush(void)
|
||||
{
|
||||
if (_TXbufferSize > 0) {
|
||||
log_esp3d("[SOCKET]flush data, buffer size %d",_TXbufferSize);
|
||||
if (_websocket_server) {
|
||||
_websocket_server->broadcastBIN
|
||||
(_TXbuffer,_TXbufferSize);
|
||||
flushTXbuffer();
|
||||
flushRXbuffer();
|
||||
}
|
||||
|
||||
void WebSocket_Server::flushTXbuffer(void)
|
||||
{
|
||||
if (_started) {
|
||||
if ((_TXbufferSize > 0) && (_websocket_server->connectedClients() > 0 )) {
|
||||
//if(!_isdebug) {
|
||||
// log_esp3d("[SOCKET]flush data, buffer size %d",_TXbufferSize);
|
||||
//}
|
||||
if (_websocket_server) {
|
||||
_websocket_server->broadcastBIN(_TXbuffer,_TXbufferSize);
|
||||
log_esp3d("WS Broadcast bin port %d", port());
|
||||
}
|
||||
//refresh timout
|
||||
_lastTXflush = millis();
|
||||
|
||||
}
|
||||
//refresh timout
|
||||
_lastflush = millis();
|
||||
//reset buffer
|
||||
_TXbufferSize = 0;
|
||||
}
|
||||
//reset buffer
|
||||
_TXbufferSize = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include "Print.h"
|
||||
#define TXBUFFERSIZE 1200
|
||||
//#define RXBUFFERSIZE 128
|
||||
#define RXBUFFERSIZE 256
|
||||
#define FLUSHTIMEOUT 500
|
||||
class WebSocketsServer;
|
||||
class WebSocket_Server: public Print
|
||||
@ -55,15 +55,14 @@ public:
|
||||
{
|
||||
return write((uint8_t) n);
|
||||
}
|
||||
bool begin(uint16_t port=0);
|
||||
bool begin(uint16_t port=0, bool debug=false);
|
||||
uint16_t port()
|
||||
{
|
||||
return _port;
|
||||
}
|
||||
void end();
|
||||
//int available();
|
||||
//int peek(void);
|
||||
//int read(void);
|
||||
int available();
|
||||
uint availableForWrite();
|
||||
void pushMSG (const char * data);
|
||||
void pushMSG (uint num, const char * data);
|
||||
void flush(void);
|
||||
@ -71,18 +70,31 @@ public:
|
||||
operator bool() const;
|
||||
void set_currentID(uint8_t current_id);
|
||||
uint8_t get_currentID();
|
||||
void closeClients();
|
||||
bool started()
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
void push2RXbuffer(uint8_t * sbuf, size_t len);
|
||||
private:
|
||||
bool _started;
|
||||
uint16_t _port;
|
||||
uint32_t _lastflush;
|
||||
bool _isdebug;
|
||||
uint32_t _lastTXflush;
|
||||
uint32_t _lastRXflush;
|
||||
WebSocketsServer * _websocket_server;
|
||||
uint8_t _TXbuffer[TXBUFFERSIZE];
|
||||
uint16_t _TXbufferSize;
|
||||
uint8_t _current_id;
|
||||
//uint8_t _RXbuffer[RXBUFFERSIZE];
|
||||
//uint16_t _RXbufferSize;
|
||||
//uint16_t _RXbufferpos;
|
||||
void flushTXbuffer();
|
||||
void flushRXbuffer();
|
||||
uint8_t *_RXbuffer;
|
||||
uint16_t _RXbufferSize;
|
||||
};
|
||||
|
||||
extern WebSocket_Server websocket_terminal_server;
|
||||
|
||||
#if defined(WS_DATA_FEATURE)
|
||||
extern WebSocket_Server websocket_data_server;
|
||||
#endif //WS_DATA_FEATURE
|
||||
#endif //_WEBSOCKET_SERVER_H_
|
||||
|
131
tools/wsterm.html
Normal file
131
tools/wsterm.html
Normal file
@ -0,0 +1,131 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>WSocket monitor</TITLE>
|
||||
<style>
|
||||
pre {
|
||||
display: inline;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<table>
|
||||
<tr>
|
||||
<td><span id="isconnected"></span></td>
|
||||
<td><input type="TEXT" ID="ADDRESS" placeholder="Address"/></td>
|
||||
<td><input type="TEXT" ID="PORT" placeholder="port"/></td>
|
||||
<td><button ID="CONNECT" onclick="connect();">Connect</button></td>
|
||||
<td><button ID="DISCONNECT" style="display:none;" onclick="disconnect();">Disconnect</button></td>
|
||||
<td><button ID="CLEAR" onclick="clearmonitor();">Clear</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=6>
|
||||
<div id="MONITOR" style="min-height: 350px; max-height: 350px;min-width: 450px; width:100%; border-width:1px;border-style: solid;overflow-y:auto" ></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type="TEXT" style="display:none;" onkeyup="checkcode(event)" ID="CMD" placeholder="command"/></td>
|
||||
<td><button ID="SEND" style="display:none;" onclick="Send();">send</button></td>
|
||||
</tr>
|
||||
</table>
|
||||
<SCRIPT>
|
||||
var msg ="";
|
||||
var logoff=false;
|
||||
function checkcode(event){
|
||||
if (event.keyCode == 13) {
|
||||
Send();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function connect(){
|
||||
logoff=false;
|
||||
var address = document.getElementById('ADDRESS').value;
|
||||
var port = document.getElementById('PORT').value;
|
||||
if (address.length == 0){
|
||||
address = document.location.hostname;
|
||||
document.getElementById('ADDRESS').value = document.location.hostname;
|
||||
port = "8181";
|
||||
document.getElementById('PORT').value = "8181";
|
||||
}
|
||||
if (typeof ws_source !='undefined'){
|
||||
ws_source.close();
|
||||
}
|
||||
try {
|
||||
ws_source = new WebSocket('ws://'+address+':' + port,['arduino']);
|
||||
ws_source.binaryType = "arraybuffer";
|
||||
ws_source.onopen = function(e){
|
||||
document.getElementById('isconnected').innerHTML = "Connected";
|
||||
document.getElementById('CONNECT').style.display="none";
|
||||
document.getElementById('DISCONNECT').style.display="block";
|
||||
document.getElementById('CMD').style.display="block";
|
||||
document.getElementById('SEND').style.display="block";
|
||||
console.log("Connected");
|
||||
};
|
||||
ws_source.onclose = function(e){
|
||||
console.log("Disconnected");
|
||||
document.getElementById('isconnected').innerHTML = "";
|
||||
document.getElementById('CONNECT').style.display="block";
|
||||
document.getElementById('DISCONNECT').style.display="none";
|
||||
document.getElementById('CMD').style.display="none";
|
||||
document.getElementById('SEND').style.display="none";
|
||||
//auto reconnect
|
||||
if (!logoff)setTimeout(connect, 3000);
|
||||
};
|
||||
ws_source.onerror = function(e){
|
||||
console.log("ws error", e);
|
||||
disconnect();
|
||||
alert(e);
|
||||
};
|
||||
ws_source.onmessage = function(e){
|
||||
var tmpmsg="";
|
||||
if(e.data instanceof ArrayBuffer){
|
||||
tmpmsg +="<span style='color:blue'>[Received BIN data]</span><br><pre>";
|
||||
var bytes = new Uint8Array(e.data);
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
if (bytes[i] == 13){
|
||||
tmpmsg += "</pre><br><pre>";
|
||||
} else {
|
||||
if (bytes[i] != 10) {
|
||||
tmpmsg += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
tmpmsg+="</pre><br>";
|
||||
msg+= tmpmsg.replace("<br><pre></pre>","");
|
||||
document.getElementById('MONITOR').innerHTML = msg
|
||||
} else {
|
||||
tmpmsg += "<span style='color:blue'>[Received TXT data]</span><br><pre>" + e.data.replace("\n", "</pre><br><pre>") ;
|
||||
tmpmsg+="</pre>";
|
||||
msg+=tmpmsg;
|
||||
document.getElementById('MONITOR').innerHTML = msg ;
|
||||
}
|
||||
document.getElementById('MONITOR').scrollTop = document.getElementById('MONITOR').scrollHeight;
|
||||
};
|
||||
}
|
||||
catch(error){
|
||||
alert(error);
|
||||
}
|
||||
}
|
||||
function clearmonitor(){
|
||||
msg = "";
|
||||
document.getElementById('MONITOR').innerHTML = "";
|
||||
}
|
||||
function Send(){
|
||||
var cmd= document.getElementById('CMD').value;
|
||||
var tmpmsg ="";
|
||||
if(cmd.length > 0) {
|
||||
cmd+="\n";
|
||||
tmpmsg+="<span style='color:green'>[Send]</span><br><pre>"+cmd + "</pre>";
|
||||
msg+=tmpmsg;
|
||||
document.getElementById('MONITOR').innerHTML = msg ;
|
||||
ws_source.send(cmd);
|
||||
}
|
||||
document.getElementById('CMD').value = "";
|
||||
}
|
||||
function disconnect(){
|
||||
logoff=true;
|
||||
ws_source.close();
|
||||
}
|
||||
</SCRIPT>
|
||||
</BODY>
|
||||
</HTML>
|
Loading…
x
Reference in New Issue
Block a user