Arduino library for Serial Commands over a serial port
This library is a fork from scogswell's library.
The main intention of this library was to implement a device able to respond to AT Commands, for example "AT", "AT+RST", that kind of commands you see a lot on modems or SoCs like the ESP8266 or the SIM900.
Type | Example | Description |
---|---|---|
Test Command | AT+=? | Test the existence of a command and checks it's range of subparameter(s). |
Read Command | AT+? | This command returns the currently set value of the parameters(s). |
Write Command | AT+=<...> | This command sets the user-definable parameter value(s). |
Execution Command | AT+ | This command execute a function. |
For examples please check the "examples" folder inside this library.
Or open examples directly from Arduino: File->Examples->SerialCommand
NOTE: Every command used should end with a carriage return (, ASCII '\r', HEX 0xD). Be careful since not all serial port consoles send it as default.
Adding a new command requires 2 things, a string and a pointer to void function. The string is used to compare user input against available commands. The function will be called when the command is received correctly.
mySerialCMD.addCommand("AT", ping);
Valid user input:
AT<CR>
This is well explained on: examples/ping/ping.pde
The declaration for parametric commands is the same as one without parameters
mySerialCMD.addCommand("AT+LED", ledHandler);
When used these commands should include a '=' char for the first parameter and ',' for trailing parameters.
Valid user input:
AT+LED=1<CR>
In order to get the parameters we use the method "next" which return a pointer to the next parameter. NOTE: To know if the parameter is valid you should always check if is NULL.
param = mySerialCMD.next();
if (param != NULL) // Do something
This is well explained on: examples/LedHandler/LedHandler.pde
This library is intended to work with any Stream child class like "HardwareSerial" (Most commonly used serial interface), "SoftwareSerial", and "Serial_" (USB CDC Serial).
If you are experimenting issues with the commands and don't know why, you may want to debug this library, to do that just set "SERIAL_CMD_DBG_EN" on "SerialCommand.h" to 1.