- Queue Mechanism: This service implements a command queue to ensure that only one AT command runs at a time, avoiding concurrent errors in the modem's ATD service
- Multiple Invocation Methods: The service can be called by other services on the router via ubus, or by HTTP services via rpcd, making it suitable for both modem management and WebUI development
- Better Stability: Compared to the modem's built-in ATD service, this service provides more stable and reliable performance across different vendor modems
Add rpcd permissions for at-daemon (for demonstration purposes, the following configuration is unauthenticated - please configure appropriate authentication for production environments)
echo << EOF > /usr/share/rpcd/acl.d/unauthenticated.json
{
"unauthenticated": {
"description": "Access controls for unauthenticated requests",
"read": {
"ubus": {
"session": [
"access",
"login"
],
"at-daemon" : ["list","open","sendat","close"]
}
}
}
}
EOFUse curl to access rpcd and send commands:
curl -s -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc":"2.0",
"id":1,
"method":"call",
"params":["00000000000000000000000000000000","at-daemon","sendat",{"at_port":"/dev/ttyUSB0","at_cmd":"at+cgmm"}]
}
' http://192.168.1.1/ubusResponse example:
{
"jsonrpc": "2.0",
"id": 1,
"result": [
0,
{
"port": "/dev/ttyUSB0",
"command": "at+cgmm",
"is_raw": 0,
"sendonly": 0,
"timeout": 5,
"end_flag": "default",
"end_flags_used": [
"OK",
"ERROR",
"+CMS ERROR:",
"+CME ERROR:",
"NO CARRIER"
],
"status": "success",
"response": "\r\nMH5000-82M\r\n\r\nOK\r\n",
"response_length": 20,
"end_flag_matched": "OK",
"response_time_ms": 79
}
]
}You can also use ubus commands directly on the router:
ubus call at-daemon sendat '{"at_port":"/dev/ttyUSB0","at_cmd":"at+cgmm"}'ubus -v list at-daemon
'at-daemon' @de5d6d53
"open":{"at_port":"String","baudrate":"Integer","databits":"Integer","parity":"Integer","stopbits":"Integer","timeout":"Integer"}
"sendat":{"at_port":"String","timeout":"Integer","end_flag":"String","at_cmd":"String","raw_at_content":"String","sendonly":"Boolean"}
"list":{}
"close":{"at_port":"String"}Opens the specified serial port device (usually called automatically when using sendat)
Parameters:
at_port(String, required): Serial port device path, e.g.,/dev/ttyUSB0baudrate(Integer, optional): Baud rate, default 115200databits(Integer, optional): Data bits, default 8parity(Integer, optional): Parity bit, 0=none, 1=odd, 2=evenstopbits(Integer, optional): Stop bits, 1 or 2timeout(Integer, optional): Timeout in seconds, default 5
Sends an AT command to the specified serial port and receives the response
Parameters:
at_port(String, required): Serial port device pathat_cmd(String, optional): AT command content, e.g.,at+cgmmraw_at_content(String, optional): Raw content in hexadecimal format, choose one between this andat_cmdtimeout(Integer, optional): Timeout in seconds, default 5sendonly(Boolean, optional): Whether to send only without receiving response, default falseend_flag(String, optional): Custom termination character, truncates when this character is detected in response
Default Termination Characters: OK, ERROR, +CMS ERROR:, +CME ERROR:, NO CARRIER
Lists all opened serial port connections
Parameters: None
Closes the specified serial port connection
Parameters:
at_port(String, required): Serial port device path to close
If you want to share the serial port with QModem, you need to enable ubus at mode in QModem configuration. Otherwise, ubus at will monopolize the serial port buffer after startup, preventing QModem from receiving information.
Configuration method:
uci set qmodem.1_1_2.use_ubus='1'
uci commit qmodemWhen calling ubus-at-daemon in your project, ensure that AT commands return one of the following termination characters:
OKERROR+CMS ERROR:+CME ERROR:NO CARRIER
Or manually specify a termination character via the end_flag parameter. Otherwise, the request will wait until timeout and status will return an error.
Unauthenticated rpcd configuration is not recommended for production environments. Please configure appropriate authentication mechanisms based on your security requirements.
ubus call at-daemon sendat '{"at_port":"/dev/ttyUSB0","at_cmd":"at+cgmm"}'ubus call at-daemon sendat '{"at_port":"/dev/ttyUSB0","at_cmd":"at+csq"}'ubus call at-daemon sendat '{"at_port":"/dev/ttyUSB0","at_cmd":"at+cfun=1,1","sendonly":true}'ubus call at-daemon sendat '{"at_port":"/dev/ttyUSB0","at_cmd":"at+cgmm","timeout":10}'