cleaned up commands

This commit is contained in:
proddy
2018-10-06 14:58:35 +02:00
parent 7629a6ecb0
commit f1a3960da8
2 changed files with 41 additions and 41 deletions

View File

@@ -663,14 +663,11 @@ void ESPHelper::consoleHandle() {
} }
} }
// Set help for commands over telnet
void ESPHelper::consoleSetHelpProjectsCmds(String help) {
_helpProjectCmds = help;
}
// Set callback of sketch function to process project messages // Set callback of sketch function to process project messages
void ESPHelper::consoleSetCallBackProjectCmds(void (*callback)()) { void ESPHelper::consoleSetCallBackProjectCmds(command_t * cmds, uint8_t count, void (*callback)()) {
_consoleCallbackProjectCmds = callback; _helpProjectCmds = cmds; // command list
_helpProjectCmds_count = count; // numiber of commands
_consoleCallbackProjectCmds = callback; // external function to handle commands
} }
// Set bootime received as a string from HA // Set bootime received as a string from HA
@@ -745,32 +742,31 @@ size_t ESPHelper::write(uint8_t character) {
// Show help of commands // Show help of commands
void ESPHelper::consoleShowHelp() { void ESPHelper::consoleShowHelp() {
// Show the initial message String help = "********************************\n\r* Remote Telnet Command Center "
String help = ""; "*\n\r********************************\n\r";
help += "* Device hostname: " + WiFi.hostname() + "\tIP: " + WiFi.localIP().toString()
help.concat("*\n\r* Remote Debug for ESP8266/ESP32\n\r"); + "\tMAC address: " + WiFi.macAddress() + "\n\r";
help.concat("* Device hostname: "); help += "* Connected to WiFi AP: " + WiFi.SSID() + "\n\r";
help.concat(WiFi.hostname()); help += "* Boot time: ";
help.concat(", IP: ");
help.concat(WiFi.localIP().toString());
help.concat(", MAC address: ");
help.concat(WiFi.macAddress());
help.concat("\n\r* Connected to WiFi AP: ");
help.concat(WiFi.SSID());
help.concat("\n\r* Boot time: ");
help.concat(_boottime); help.concat(_boottime);
help.concat("\n\r* Free Heap RAM: "); help += "\n\r* Free Heap RAM: ";
help.concat(ESP.getFreeHeap()); help.concat(ESP.getFreeHeap());
help.concat(" bytes\n\r"); help += " bytes\n\r";
help.concat("*\n\r* Commands:\n\r* ?=help, *=quit, $=memory, !=reboot, " help += "*\n\r* Commands:\n\r* ?=this help, q=quit telnet, $=show used memory, !=reboot, &=suspend all "
"&=toggle verbose messages"); "notifications\n\r";
if (_helpProjectCmds != "" && (_consoleCallbackProjectCmds)) { // print custom commands if available
help.concat("\n\r"); if (_consoleCallbackProjectCmds) {
help.concat(_helpProjectCmds); for (uint8_t i = 0; i < _helpProjectCmds_count; i++) {
//for (uint8_t i = 0; i < 5; i++) {
help += FPSTR("* ");
help += FPSTR(_helpProjectCmds[i].key);
help += FPSTR(" ");
help += FPSTR(_helpProjectCmds[i].description);
help += FPSTR("\n\r");
} }
help.concat("\n\r"); }
telnetClient.print(help); telnetClient.print(help);
#ifdef USE_SERIAL #ifdef USE_SERIAL
@@ -806,13 +802,13 @@ void ESPHelper::consoleProcessCommand() {
uint8_t cmd = _command[0]; uint8_t cmd = _command[0];
if (!_verboseMessages) { if (!_verboseMessages) {
telnetClient.println("Warning, verbose messaging is off. Use v to toggle."); telnetClient.println("Warning, all messages are supsended. Use & to enable.");
} }
// Process the command // Process the command
if (cmd == '?') { if (cmd == '?') {
consoleShowHelp(); // Show help consoleShowHelp(); // Show help
} else if (cmd == '*') { // quit } else if (cmd == 'q') { // quit
telnetClient.println("* Closing telnet connection..."); telnetClient.println("* Closing telnet connection...");
telnetClient.stop(); telnetClient.stop();
} else if (cmd == '$') { } else if (cmd == '$') {
@@ -822,7 +818,7 @@ void ESPHelper::consoleProcessCommand() {
resetESP(); resetESP();
} else if (cmd == '&') { } else if (cmd == '&') {
_verboseMessages = !_verboseMessages; // toggle _verboseMessages = !_verboseMessages; // toggle
telnetClient.printf("Verbose messaging is %s\n\r", _verboseMessages ? "on" : "off"); telnetClient.printf("Suspend all messages is %s\n\r", _verboseMessages ? "disabled" : "enabled");
} else { } else {
// custom Project commands // custom Project commands
if (_consoleCallbackProjectCmds) { if (_consoleCallbackProjectCmds) {

View File

@@ -27,6 +27,7 @@
#include <PubSubClient.h> #include <PubSubClient.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <pgmspace.h>
// MQTT stuff // MQTT stuff
#define DEFAULT_QOS 1 //at least once - devices are guarantee to get a message. #define DEFAULT_QOS 1 //at least once - devices are guarantee to get a message.
@@ -58,27 +59,29 @@ typedef enum { LOG_NONE, LOG_CONSOLE, LOG_HA } log_level_t;
enum connStatus { NO_CONNECTION, BROADCAST, WIFI_ONLY, FULL_CONNECTION }; enum connStatus { NO_CONNECTION, BROADCAST, WIFI_ONLY, FULL_CONNECTION };
struct netInfo { typedef struct {
const char * mqttHost; const char * mqttHost;
const char * mqttUser; const char * mqttUser;
const char * mqttPass; const char * mqttPass;
uint16_t mqttPort; uint16_t mqttPort;
const char * ssid; const char * ssid;
const char * pass; const char * pass;
}; } netInfo;
typedef struct netInfo netInfo;
struct subscription { typedef struct {
bool isUsed = false; bool isUsed = false;
const char * topic; const char * topic;
}; } subscription;
typedef struct subscription subscription;
typedef struct {
char key[5];
char description[400];
} command_t;
// class ESPHelper { // class ESPHelper {
class ESPHelper : public Print { class ESPHelper : public Print {
public: public:
void consoleSetHelpProjectsCmds(String help); void consoleSetCallBackProjectCmds(command_t * cmds, uint8_t count, void (*callback)());
void consoleSetCallBackProjectCmds(void (*callback)());
char * consoleGetLastCommand(); char * consoleGetLastCommand();
void resetESP(); void resetESP();
void logger(log_level_t level, const char * message); void logger(log_level_t level, const char * message);
@@ -198,7 +201,8 @@ class ESPHelper : public Print {
char _command[COMMAND_LENGTH]; // Command received, includes options seperated by a space char _command[COMMAND_LENGTH]; // Command received, includes options seperated by a space
uint32_t _lastTimeCommand = millis(); // Last time command received uint32_t _lastTimeCommand = millis(); // Last time command received
String _helpProjectCmds = ""; // Help of commands setted by project command_t * _helpProjectCmds; // Help of commands setted by project
uint8_t _helpProjectCmds_count; // # available commands
void (*_consoleCallbackProjectCmds)(); // Callable for projects commands void (*_consoleCallbackProjectCmds)(); // Callable for projects commands
void consoleShowHelp(); void consoleShowHelp();