Formating serial command

I'm having a bit of a go around trying to format a serial command in the serial monitor to be sent to Command Handler.

The response from the sketch indicates: "I don't understand" in the serial monitor, so I am not formatting correctly.

!ListAll with both NL and CR on yields a good result

!SetOnTime 40 returns: "I don't understand"

Can anyone come up with a good command?

#include "CommandHandler.h" 
CommandHandler<> SerialCommandHandler;
long LastBlink = 0; // Time we last blinked the LED
int OnTime = 10; // Amount of time the LED remains on [milliseconds]
int OffTime = 100; // Amount of time the LED remains off [milliseconds]
const int LEDPin = 13; // Pin the LED is attached to 
void setup() 
  Serial.println(F("Blink 2.0"));
  // Setup the serial commands we can repond to
  SerialCommandHandler.AddCommand(F("OnTime"), Cmd_SetOnTime);
  SerialCommandHandler.AddCommand(F("OffTime"), Cmd_SetOffTime);
  SerialCommandHandler.AddCommand(F("ListAll"), Cmd_ListAll);
  pinMode(LEDPin, OUTPUT);
void loop() 

  // Check for serial commands and dispatch them.
  // Update the LED
  uint32_t uNow = millis();
  if (uNow - LastBlink < OnTime) 
    digitalWrite(LEDPin, HIGH); 
    digitalWrite(LEDPin, LOW); 
  if (uNow - LastBlink > OnTime + OffTime)
    LastBlink = uNow;
void Cmd_ListAll(CommandParameter &Parameters)
  Serial.print(F("OnTime [ms]="));
  Serial.print(F("OffTime [ms]="));
void Cmd_SetOnTime(CommandParameter &Parameters)
  OnTime = Parameters.NextParameterAsInteger(OnTime);
void Cmd_SetOffTime(CommandParameter &Parameters)
  OffTime = Parameters.NextParameterAsInteger(OffTime);
void Cmd_Unknown()
  Serial.println(F("I don't understand"));

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

You don't have SetOnTime defined. The text in the " " is the command string.
SerialCommandHandler.AddCommand(F("OnTime"), Cmd_SetOnTime);
The second parameter is the routine to call. Try !OnTime as the command.

I believe I knew that but may have added the tag incorrectly. Sorry!
Is it right now?

I stared at their example (!SetOnTime 40\r\n) for so long that I believed it.


1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.