nrf9160dk How to add custom at command

I want to add a custom at command in the SLM example . I follow the https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/libraries/modem/at_cmd_custom.html, enable  CONFIG_AT_CMD_CUSTOM in prj.conf, add at_cmd_custom.h to the main.c, and the following code was added

AT_CMD_CUSTOM(my_command_filter, "AT+MYCOMMAND", my_command_callback);

int my_command_callback(char *buf, size_t len, char *at_cmd);
{
    printf("Callback for %s", at_cmd);
    return at_cmd_custom_respond(buf, len, "OK\r\n");
}


I found slm_at_cmdulist in slm_at_commends.c, And try to change my_command_filter to slm_at_cmdulist,It also has no effect
Apart from the at command supported by the SLM example itself, the MYCOMMEND command I added did not take effect. Did I make a mistake in which step? Or which step was missed?

gratitude
Parents
  • Hi Illy,

    I did a quick check by modifying SLM application in NCS v2.6.1. It works as expected.

    Here are the project and hex file. You can check the difference compared with your modification.

    ncs261_slm_customATcommands.zip

    ncs261_slm_customATcommands.hex

    I suggest you refer to this page if you want Extending the application — nRF Connect SDK 2.6.99 documentation (nordicsemi.com) in SLM application.

    Best regards,

    Charlie

  • hi Charlie,

    thank you for your help. I have successfully added custom commands to SLM and they are working properly. I compared my SLM with the SLM you sent me, and the custom command section is consistent. The current issue is that custom commands added using the same method in other sample level projects will only return normally when the first command is entered, and will return an error when entered again later, as shown in the above figure

  • Hi Illy,

    Try to set CONFIG_CR_LF_TERMINATION=y.

    Best regards,

    Charlie

  • Thank you so much,It is indeed a problem with CR and LF at the end of commands. The default setting is to end with a CR. But now there are two other small issues.

    One is that in the at client, the end needs to be set to CR and LF to recognize commands properly, but in SLM, keeping the default CR end can recognize commands properly.

    Another issue is that custom commands in SLM can be case insensitive, and even mixed case is fine. However, in at client, commands can only be executed in all uppercase, otherwise an error will be returned (custom commands in both projects are all uppercase).

    Can you help me check again what caused these two problems? Thank you again

  • Hi Illy,

    llly said:
    One is that in the at client, the end needs to be set to CR and LF to recognize commands properly, but in SLM, keeping the default CR end can recognize commands properly.

    I think this is not an issue. SLM and AT Client use CONFIG_CR_LF_TERMINATION=y and CONFIG_CR_TERMINATION=y by default respectively, you can just change to what you want at building time. The Serial Terminal also has Line Ending option allows you to set up the termination method.

    llly said:
    Another issue is that custom commands in SLM can be case insensitive, and even mixed case is fine. However, in at client, commands can only be executed in all uppercase, otherwise an error will be returned (custom commands in both projects are all uppercase).

    It seems AT Client support case-insensitive for modem AT commands but not custom commands. I think this depends on the at commands processing in MFW. For a custom AT command, it will match exactly what you provide.

    *** Booting nRF Connect SDK v3.5.99-ncs1-1-4-ga681edb8d456 ***
    The AT host sample started
    Ready
    > at+CFUN?
    +CFUN: 0
    OK
    > at+cfun?
    +CFUN: 0
    OK
    > at+mycommand=?
    at+mycommand=?
    > AT+MYCOMMAND=?
    +MYCOMMAND: (0, 1)
    OK

    Best regards,

    Charlie

  • Hi Illy,

    llly said:
    One is that in the at client, the end needs to be set to CR and LF to recognize commands properly, but in SLM, keeping the default CR end can recognize commands properly.

    I think this is not an issue. SLM and AT Client use CONFIG_CR_LF_TERMINATION=y and CONFIG_CR_TERMINATION=y by default respectively, you can just change to what you want at building time. The Serial Terminal also has Line Ending option allows you to set up the termination method.

    llly said:
    Another issue is that custom commands in SLM can be case insensitive, and even mixed case is fine. However, in at client, commands can only be executed in all uppercase, otherwise an error will be returned (custom commands in both projects are all uppercase).

    It seems AT Client support case-insensitive for modem AT commands but not custom commands. I think this depends on the at commands processing in MFW. For a custom AT command, it will match exactly what you provide.

    *** Booting nRF Connect SDK v3.5.99-ncs1-1-4-ga681edb8d456 ***
    The AT host sample started
    Ready
    > at+CFUN?
    +CFUN: 0
    OK
    > at+cfun?
    +CFUN: 0
    OK
    > at+mycommand=?
    at+mycommand=?
    > AT+MYCOMMAND=?
    +MYCOMMAND: (0, 1)
    OK

    Best regards,

    Charlie

Reply Children
No Data
Related