Sming - Open Source framework for high efficiency native ESP8266 development

User avatar
By helpme
#36364 I have set up the UART to receive and process commands using the CommandProcessing library by using the Telnet_TCPServer_TCPClient example.

Here are the relevant code;

Code: Select allvoid init()
{
   Serial.begin(SERIAL_BAUD_RATE);
        Serial.commandProcessing(true);
   commandHandler.registerCommand(CommandDelegate("appheap","Usage appheap on/off/now for     
                                                                                         heapdisplay\r\n","testGroup", appheapCommand));
   memoryTimer.initializeMs(250,checkHeap).start();
}

void appheapCommand(String commandLine  ,CommandOutput* commandOutput)
{
   Vector<String> commandToken;
   int numToken = splitString(commandLine, ',' , commandToken);
        //The rest are same as inside sample code.
}


When I send this string `appheap ,off` to the UART, the command is parsed properly.

However, when I send this string `appheap,off` to the UART, the command is not parsed properly. The message returned is `Command not found, cmd = 'appheap,off'`.

If things are going fine, both strings `appheap ,off` and `appheap,off`should work fine.
User avatar
By hreintke
#36366 The commandprocessor "detects" the command to be processed based on the occurrence if the first space or end-of line and comparing that withe the commandlist created by the (CommandDelegate("appheap","Usage ..... commands.

in your example "appheap" in the list "appheap,off" on the command line -> unknown command

If you enter "appheap off" the appheapCommand function will be called.
User avatar
By helpme
#36368 Thanks for your reply. Things are clearer now.

In my command handler,
Code: Select allvoid appheapCommand(String commandLine  ,CommandOutput* commandOutput)
{
   Vector<String> commandToken;
   int numToken = splitString(commandLine, ',' , commandToken);
        //The rest are same as inside sample code.
}

The string `commandLine` is for the string after `appheap`, right? In other words, if the command received is `appheap on,1`, then `commandLine` string will be `on,1` , correct?
User avatar
By hreintke
#36385 No, the commandLine is the full inputline. Thus in your example will be `appheap on,1`
This is to make it possible that multiple commands can be handled by one delegate.

So you could have f.e.
CommandDelegate("appheap",.....,appheapCommand)
and
CommandDelegate("appheapMax",.....,appheapCommand)