I am using the library SerialCommands
and I am just trying to print the first text message in the Serial Monitor. But this code does not work for some reason.
The expected result is that the Serial monitor prints a message ("Hello world !!") when I write "hello" and press "enter" as input. Is there something wrong or is this not working like I was expecting? Is there another way to check if these commands work? Is there anythin that I am missing?
#include <SerialCommands.h>
char serial_command_buffer_[32];
SerialCommands serial_commands_(&Serial, serial_command_buffer_, sizeof(serial_command_buffer_), "\r\n", ",");
void cmd_hello(SerialCommands* sender) {
sender->GetSerial()->println("Hello world !!");
}
SerialCommand cmd_hello_("hello", cmd_hello);
void cmd_unrecognized(SerialCommands* sender, const char* cmd) {
sender->GetSerial()->print("ERROR: Unrecognized command [");
sender->GetSerial()->print(cmd);
sender->GetSerial()->println("]");
}
void setup() {
Serial.begin(9600); // Serial comm begin at 9600bps
serial_commands_.AddCommand(&cmd_hello_);
serial_commands_.SetDefaultHandler(&cmd_unrecognized);
Serial.println("Ready");
}
void loop() {
serial_commands_.ReadSerial();
}