AT socketΒΆ


The socket-based AT interface is deprecated since version v1.3.0. Use the AT interface instead.

You can use the AT socket to send AT commands to the LTE modem and to receive the responses.

To do so, create a socket with the proprietary address family NRF_AF_LTE and the protocol family NRF_PROTO_AT. You can then write AT command strings to that socket using nrf_send() and nrf_write(), and they are sent to the modem. The responses are available when you read from the socket using nrf_read() and nrf_recv(). Received AT messages are not truncated; to read the full response, provide a sufficiently large buffer or fetch the full response in several read operations.

See the AT Commands Reference Guide for detailed information on the available AT commands.

The following BSD socket functions are available for the NRF_PROTO_AT protocol family:

By default, read and write functions are blocking. To make them non-blocking, use nrf_fcntl() to set the NRF_O_NONBLOCK flag, or pass NRF_MSG_DONTWAIT as flag to the function call.

The following code example shows how to send an AT command and receive the response:

#include "nrf_socket.h" // socket(), NRF_AF_LTE family type, NRF_PROTO_AT protocol.
#include <string.h>     // strncmp()

int func(void)
    // Create a socket for AT commands.
    int fd = nrf_socket(NRF_AF_LTE, 0, NRF_PROTO_AT);

    // Write the AT command.
    nrf_write(fd, "AT+CEREG=2", 10);

    // Allocate a response buffer.
    char ok_buffer[10];

    // Read an AT message (read 10 bytes to ensure that the
    // entire message is consumed).
    int num_of_bytes_recvd = nrf_read(fd, ok_buffer, 10);

    // Compare buffer content against expected return value.
    if (strncmp("OK", ok_buffer, 2) != 0)
        // Return in case of failure.
        return -1;

    // Return on success.
    return 0;