Using nrf_modem_at_cmd() for AT% commands

Hi, 

Using nRF9160 - NCS 3.1.0

I am trying to implement the AT%XBANDLOCK at command into my Firmware, and I am struggling to set it with the nrf_modem_at_cmd() function. I have used this function for "AT+" commands with no issues, but I think "AT%" commands have to work a little differently

Using a AT Command passthrough firmware, I have verified that the functions definitely work. I make sure that CFUN=0 before hand, and then, as an initial test, just clear any bitmask that may be there using 

AT%XBANDLOCK=0
However, this always returns ERROR when using the nrf_modem_at_cmd() function.
sprintf(at_command, "AT%%XBANDLOCK=0");
err = nrf_modem_at_cmd(str, strlen(at_command)-1, at_command, NULL);
I have tried multiple variations of this;
With and without NULL 
sizeof(at_command) rather than strlen()
#define at_command "AT%XBANDLOCK=0" rather than sprintf
I looked in the coneval.c to see how that deals with the %, and that does a definition of  "AT%CONEVAL" (only one %)

I don't know how this would work with setting an AT% command though, because the function uses a printf-style variadic argument, so if I were to only use 1 '%', the first variadic argument would be %X (from AT%XBAND...), which would be fixed with a double % character

I tried doing AT%CONEVAL with this method and it also failed, so I am sure it it something to do with that %.

I can't find a wrapper function for XBANDLOCK, so I presume nrf_modem_at_cmd() is the way I should be doing it?
I may be missing something blatantly obvious but I cannot see it. 
Thanks, 
Damien 
  • Hello Damien, 

    Have you had a look at nrfxlib\nrf_modem\include\nrf_modem_at.h ?  And included in your project? Could you please provide more details for how you are trying to implement this? I would like to try on my side to replicate.

    Kind regards,
    Øyvind

  • Hi Øyvind, 

    I can confirm it is included in my project. 

    I will be using a 32 bit mask to enable/disable certain bands. So I have written a bitstring builder for the AT Command, to convert my bitmask into the bitstring style that the AT Command accepts. 

    I actually found that if I use nrf_modem_at_printf() rather than nrf_modem_at_cmd(), it seems to work, err = 0. With nrf_modem_at_cmd(), err = 65536 and the reply is "ERROR".

    The following bit of code does include some of my own functions, mainly just print functions you can replace with printk()

    if(freq_band_update)
    {
    	if((config_registers.band_bitmask_S9 == 0) || (config_registers.band_bitmask_S9 == 0xFFFF))
    	{
    		sprintf(at_command, "AT%%XBANDLOCK=0");
    	}
    	else
    	{
    		build_band_string(config_registers.band_bitmask_S9, str);
    		sprintf(at_command, "AT%%XBANDLOCK=1,\"%s\"", str);
    	}
    	print_to_com(uart, "[D] BANDLOCK AT COMMAND - %s", ALWAYS_PRINT, at_command);
    	err = nrf_modem_at_printf("%s", at_command);        //THIS WORKS nfr_modem_at_cmd() doesn't
    	if (err)
    	{
    		print_to_com(uart, "[E] Could not set bandlock", ALWAYS_PRINT);
    	}
    	else
    	{
    		print_to_com(uart, "[D] BANDLOCK SET - %08X", ALWAYS_PRINT, config_registers.band_bitmask_S9);
    	}
    }

    Thanks, 

    Damien

  • Ah, I think I see the problem. Knew it would be simple. 

    Because it's a variadic function the *fmt parameter has to be string literal ("")

    So 

    err = nrf_modem_at_cmd(str, strlen(at_command)-1,  at_command);            - ERROR
    err = nrf_modem_at_cmd(str, strlen(at_command)-1,  ,"%s", at_command);  - OK

    Coneval wrapper works because the AT command is not part of the *fmt, as it uses scanf to read the response, so the one '%' character makes sense there. 
Related