I have been unable to find a clear concise description of how to send an AT command from within main.c in the application space. I am using the AT_CLIENT sample, and I have it running and responding from both the LTE Link Monitor and from my terminal (I am on a Mac using OSX). All I want to do is make sure that the modem is turned on and active. I’m never sure if the modem is turned on by default in the AT_CLIENT sample or if when using nRF LTE Link Monitor, by reading CFUN (AT+CFUN?) it is actually turning the modem on. In order to turn the modem on from main.c is it as simple as setting:

CONFIG_AT_CMD=y
CONFIG_AT_NOTIF=y

in proj.conf and then invoking

#include <modem/at_cmd.h>
#include <modem/at_notif.h>

at_cmd_write("AT+CFUN=21", NULL, 0, NULL)

in main.c?

I’ve looked through many posts in the Nordic forums and the online documentation but haven’t found anything this fundamentally basic.

Thanks!
Joe

    Hey joebambino

    Yea this is tricky. I pretty much learned it by looking at Nordic examples.

    Here’s an example of how I use it on the test firmware:

     /* Send SIM related AT commands */
            err = at_cmd_write("AT+CFUN=4", NULL, 0, NULL);
            if (err)
            {
                LOG_INF("Unable to set offline mode.");
                const uint8_t resp[] = {2, SimTest, 'f'};
                uart_send(resp, sizeof(resp));
                goto finish;
            }
    
            /* Send SIM related AT commands */
            err = at_cmd_write("AT+CFUN=41", NULL, 0, NULL);
            if (err)
            {
                LOG_INF("Unable to power with SIM mode.");
                const uint8_t resp[] = {2, SimTest, 'f'};
                uart_send(resp, sizeof(resp));
                goto finish;
            }
    
            k_sleep(K_SECONDS(1));
    
            err = at_cmd_write("AT%XSIM?", buf, sizeof(buf), NULL);
            if (err || (strstr(buf, "%XSIM: 1") == NULL))
            {
                LOG_INF("SIM is not active/present.");
                const uint8_t resp[] = {2, SimTest, 'f'};
                uart_send(resp, sizeof(resp));
                goto finish;
            }

    In some cases the return value is fine but in other cases you need to parse the output like I did with strstr.

    Here’s the documentation for NCS. It breaks down the API a bit better. I was just using it so it’s fresh in my mind!

    I’m sure you know already but here’s a link to all the AT commands.

      Thanks jaredwolff
      I appreciate the super quick response. I was looking through all the samples in the Nordic forums and there’s a lot out there. Nothing clear and concise. I’m trying to keep it as simple as humanly possible. I don’t even care about the response. I just want to make sure that the modem is on and active so that a LTE testing callbox can connect to it (with a matching test SIM, of course). It looks like if at a minimum I have

      /* Send AT commands */
              err = at_cmd_write("AT+CFUN=21", NULL, 0, NULL);
              if (err)
              {
                  printk("AT Command BARFED.");
                  goto finish;
              }

      then I should be mostly good to go.

        joebambino yea if you want it to simply power on and start connecting AT+CFUN=1 should do the trick. You can play around with nRF Connect Desktop and use the automatic requests. That should give you an idea of what does what as well.

        Upon further review, it seems all I need to do in proj.conf is:

        # LTE link control
        CONFIG_LTE_LINK_CONTROL=y
        CONFIG_LTE_AUTO_INIT_AND_CONNECT=y

        and the modem should turn on and attempt to connect using CONFIG_LTE_AUTO_INIT_AND_CONNECT . Am I misreading this? I guess the drawback to this option is that if a connection is not established, you would never enter main(). I guess another way to simplify would be to use the LTE Link Control Driver and the modem_configure() function as described here: https://devzone.nordicsemi.com/f/nordic-q-a/53064/what-should-be-magpio-command-sequence-for-connecting-to-nbiot-network/215237#215237

          joebambino LTE link control simplifies creating a connection. (Essentially running the AT+CFUN=1 etc for you). I use it but it depends on how “automated” you want establishing a connection to be.

          Terms and Conditions | Privacy Policy