Skip to content

argandas/SerialCommand

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino CI License: MIT GitHub release

SerialCommand

Arduino library for Serial Commands over a serial port


Introduction

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.

Types of AT Commands and responses

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.

Examples

For examples please check the "examples" folder inside this library.

Or open examples directly from Arduino: File->Examples->SerialCommand

Usage

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.

Commands with no parameters:

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

Commands with parameters:

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

Serial Interfaces

This library is intended to work with any Stream child class like "HardwareSerial" (Most commonly used serial interface), "SoftwareSerial", and "Serial_" (USB CDC Serial).

Debug

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.

About

Arduino library for Serial Commands over a serial port.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%