Testing scenarios
The following testing scenarios give detailed instructions for testing specific use cases. They list the required AT commands and the expected responses.
Some scenarios are generic and should work out of the box, while others require you to set up a server that you can test against.
See Building and running for instructions on how to build and run the Serial Modem application. Testing describes how to turn on the modem and conduct the tests.
Generic AT commands
Complete the following steps to test the functionality provided by the Generic AT commands:
Retrieve the version of the Serial Modem application.
AT#XSMVER #XSMVER: "v1.99.0-67-ga9e396bc3d58","3.3.99" OK
Retrieve a list of all supported proprietary AT commands.
AT#XCLAC AT#XSMVER AT#XSLEEP AT#XCLAC AT#XSOCKET AT#XSOCKETOPT AT#XBIND [...] OK
Check the supported values for the sleep command, then put the kit in sleep mode.
AT#XSLEEP=? #XSLEEP: (1,2) OK
TCP/UDP AT commands
The following sections show how to test the functionalities provided by the Socket AT commands.
Network connection is required for these tests, so insert a SIM card and connect to the network:
AT+CFUN=1 OK
TCP connection
The following steps assume that you have a TCP echo server available. You can connect to public HTTP servers (port 80), but you cannot send and receive data.
Test the TCP connection with a TCP socket:
Check the available values for the AT#XSOCKET command.
AT#XSOCKET=? #XSOCKET: <handle>,(1,2),(1,2,3),(0,1),<cid> OK
Open a TCP socket, read the information (handle, family, role, type and cid) about the open socket, and set the receive timeout of the open socket to 30 seconds.
AT#XSOCKET=1,1,0 #XSOCKET: 0,1,6 OK AT#XSOCKET? #XSOCKET: 0,1,0,1,0 OK AT#XSOCKETOPT=0,1,20,30 OK
Replace example.com with the hostname or IPv4 address of the TCP echo server, and 1234 with the corresponding port.
1indicates that the connection is established.AT#XCONNECT=0,"example.com",1234 #XCONNECT: 0,1 OK
Send plaintext data to the TCP server and retrieve the response.
AT#XSEND=0,0,0,"Test TCP" #XSEND: 0,0,8 OK AT#XRECV=0,0,0,0 #XRECV: 0,0,8 Test TCP OK
Close the socket and confirm its state.
AT#XCLOSE=0 #XCLOSE: 0,0 OK AT#XSOCKET? OK
UDP connection
The following steps assume that you have a UDP echo server available.
Test the UDP connection with a UDP socket using
AT#XSENDTO:Open a UDP socket and read the information (handle, family, role, type and cid) about the open socket.
AT#XSOCKET=1,2,0 #XSOCKET: 0,2,17 OK AT#XSOCKET? #XSOCKET: 0,1,0,2,0 OK
Send plaintext data to a UDP echo server on a specified port. Replace example.com with the hostname or IPv4 address of a UDP server, and 1234 with the corresponding port. Then retrieve the response.
AT#XSENDTO=0,0,0,"example.com",1234,"Test UDP" #XSENDTO: 0,0,8 OK AT#XRECVFROM=0,0,0,0 #XRECVFROM: 0,0,8,"<IP address>",<port> Test UDP OK
Close the socket.
AT#XCLOSE=0 #XCLOSE: 0,0 OK
Test the UDP connection with a UDP socket, using
AT#XCONNECT:Open a UDP socket and set connection to UDP server. Replace example.com with the hostname or IPv4 address of a UDP server, and 1234 with the corresponding port.
AT#XSOCKET=1,2,0 #XSOCKET: 0,2,17 OK AT#XCONNECT=0,"example.com",1234 #XCONNECT: 0,1 OK
Send plaintext data to the UDP server and retrieve the response.
AT#XSEND=0,0,0,"Test UDP" #XSEND: 0,0,8 OK AT#XRECV=0,0,0,0 #XRECV: 0,0,8 Test UDP OK
Close the socket.
AT#XCLOSE=0 #XCLOSE: 0,0 OK
TLS connection
The following steps assume that you have a TLS echo server available. You can connect to public HTTPS servers (port 443), but you cannot send and receive the data.
A TLS connection requires a valid certificate for the TLS server.
Update your TLS (root) certificate in PEM format with your selected security tag (in this example, 1000), and start the modem:
Note
Sending multi-line text to Serial Modem requires the terminal to be configured to use
<CR><LF>as the line ending.AT+CFUN=0 OK AT%CMNG=0,1000,0,"-----BEGIN CERTIFICATE----- MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcN AQELBQAwTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNl Y3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3Qg WDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYD VQQGEwJVUzEpMCcGA1UEChMgSW50ZX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/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNz ktHCgKQ5ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdN bOhdjsnvzqvHu7UrTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIu vtd7u+Nxe5AW0wdeRlN8NwdCjNPElpzVmbUq4JUagEiuTDkHzsxHpFKV K7q4+63SM1N95R1NbdWhscdCb+ZAJzVcoyi3B43njTOQ5yOf+1CceWxG 1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq4RgqsahDYVvTH9w7 jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPAmRGunUHB cnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5i ItreGCc= -----END CERTIFICATE-----" OK AT+CFUN=1 OK
Test the TLS connection with a TLS socket:
Open a TLS socket that uses the security tag 1000 and connect to a TLS server on a specified port. Replace example.com with the hostname or IPv4 address of a TLS server and 1234 with the corresponding port.
AT#XSSOCKET=1,1,0,1000 #XSSOCKET: 0,1,258 OK AT#XCONNECT=0,"example.com",1234 #XCONNECT: 0,1 OK
Send plaintext data to the TLS server and retrieve the response.
AT#XSEND=0,0,0,"Test TLS" #XSEND: 0,0,8 OK AT#XRECV=0,0,0,0 #XRECV: 0,0,8 Test TLS OK
Close the socket.
AT#XCLOSE=0 #XCLOSE: 0,0 OK
DTLS connection
The following steps assume that you have a DTLS echo server available with pre-shared key (PSK) authentication.
Update your hex-encoded PSK and the PSK identity to be used for the DTLS connection in the modem, with your selected security tag (in this example, 1001):
AT+CFUN=0 OK AT%CMNG=0,1001,3,"6e7266393174657374" OK AT%CMNG=0,1001,4,"nrf91test" OK AT+CFUN=1 OK
Test the DTLS connection with a DTLS socket:
Open a DTLS socket that uses the security tag 1001 and connect to a DTLS server on a specified port. Replace example.com with the hostname or IPv4 address of a DTLS server and 1234 with the corresponding port.
AT#XSSOCKET=1,2,0,1001 #XSSOCKET: 0,2,273 OK AT#XCONNECT=0,"example.com",1234 #XCONNECT: 0,1 OK
Send plaintext data to the DTLS server and retrieve the returned data.
AT#XSEND=0,0,0,"Test DTLS" #XSEND: 0,0,9 OK AT#XRECV=0,0,0,0 #XRECV: 0,0,9 Test DTLS OK
Close the socket.
AT#XCLOSE=0 #XCLOSE: 0,0 OK
UDP server
To act as a UDP server, the nRF91 Series DK must have a public IP address and the radio network must be configured to route incoming IP packets to the nRF91 Series DK. These depend on the network and SIM card used.
To check your current setup, use the AT+CGDCONT? command to check if the IP address allocated by the network is a reserved IPv4 private address of class A, B, or C (see Private addresses).
If it is, the device is not reachable from the public network with this IPv4 address and you should try with an IPv6 address instead.
Generally, IPv6 addresses are more likely to be reachable from the public network.
To test the UDP server functionality, complete the following steps:
Create a Python script
client_udp.pythat acts as a UDP client. See the following sample code (make sure to use the correct IP addresses and port):import socket import time host_addr = '000.000.000.00' host_port = 1234 host = (host_addr, host_port) local_addr = '9.999.999.99' local_port = 1234 local = (local_addr, local_port) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(local) print("Sending: 'Hello, UDP#1!") s.sendto(b"Hello, UDP#1!", host) time.sleep(1) print("Sending: 'Hello, UDP#2!") s.sendto(b"Hello, UDP#2!", host) data, address = s.recvfrom(1024) print(data) print(address) print("Sending: 'Hello, UDP#3!") s.sendto(b"Hello, UDP#3!", host) time.sleep(1) print("Sending: 'Hello, UDP#4!") s.sendto(b"Hello, UDP#4!", host) time.sleep(1) print("Sending: 'Hello, UDP#5!") s.sendto(b"Hello, UDP#5!", host) data, address = s.recvfrom(1024) print(data) print(address) print("Closing connection") s.close()
Establish and test a UDP connection:
Open a UDP socket and bind it to the UDP port that you want to use. Replace 1234 with the correct port number.
AT#XSOCKET=1,2,1 #XSOCKET: 0,2,17 OK AT#XBIND=0,1234 OK
Run the
client_udp.pyscript to start sending data to the server.Start receiving and acknowledging the data. Replace example.com with the hostname or IPv4 address of the UDP client and 1234 with the corresponding port. A more complete example would use
AT#XAPOLLto see when data has arrived and then read it withAT#XRECVFROM.AT#XRECVFROM=0,0,0,0 #XRECVFROM: 0,0,13,"<IP address>",<port> Hello, UDP#1! OK AT#XRECVFROM=0,0,0,0 #XRECVFROM: 0,0,13,"<IP address>",<port> Hello, UDP#2! OK AT#XSENDTO=0,0,0,"example.com",1234,"UDP1/2 received" #XSENDTO: 0,0,15 OK AT#XRECVFROM=0,0,0,0 #XRECVFROM: 0,0,13,"<IP address>",<port> Hello, UDP#3! OK AT#XRECVFROM=0,0,0,0 #XRECVFROM: 0,0,13,"<IP address>",<port> Hello, UDP#4! OK AT#XRECVFROM=0,0,0,0 #XRECVFROM: 0,0,13,"<IP address>",<port> Hello, UDP#5! OK AT#XSENDTO=0,0,0,"example.com",1234,"UDP3/4/5 received" #XSENDTO: 0,0,17 OK
Observe the output of the Python script:
$ python client_udp.py Sending: 'Hello, UDP#1! Sending: 'Hello, UDP#2! b'UDP1/2 received' ('000.000.000.00', 1234, 0, 0) Sending: 'Hello, UDP#3! Sending: 'Hello, UDP#4! Sending: 'Hello, UDP#5! b'UDP3/4/5 received' ('000.000.000.00', 1234, 0, 0) Closing connectionClose the socket.
AT#XCLOSE=0 #XCLOSE: 0,0 OK
DNS lookup
Look up the IP address for a hostname.
AT#XGETADDRINFO="www.google.com" #XGETADDRINFO: "172.217.174.100" OK AT#XGETADDRINFO="ipv6.google.com" #XGETADDRINFO: "2404:6800:4006:80e::200e" OK AT#XGETADDRINFO="172.217.174.100" #XGETADDRINFO: "172.217.174.100" OK AT#XGETADDRINFO="2404:6800:4006:80e::200e" #XGETADDRINFO: "2404:6800:4006:80e::200e" OK
Socket options
After opening a client-role socket, you can configure various options.
Check the available values for the XSOCKETOPT command.
AT#XSOCKETOPT=? #XSOCKETOPT: <handle>,(0,1),<name>,<value> OK
Open a client socket.
AT#XSOCKET=1,1,0 #XSOCKET: 0,1,6 OK
Test to set and get socket options. Note that not all options are supported.
AT#XSOCKETOPT=0,1,20,30 OK
ICMP AT commands
Complete the following steps to test the functionality provided by the ICMP AT commands:
Ping a remote host, for example, www.google.com.
AT#XPING="www.google.com",45,5000,5,1000 OK #XPING: 0.637 seconds #XPING: 0.585 seconds #XPING: 0.598 seconds #XPING: 0.598 seconds #XPING: 0.599 seconds #XPING: average 0.603 seconds AT#XPING="ipv6.google.com",45,5000,5,1000 OK #XPING: 0.140 seconds #XPING: 0.109 seconds #XPING: 0.113 seconds #XPING: 0.118 seconds #XPING: 0.112 seconds #XPING: average 0.118 seconds
Ping a remote IP address, for example, 172.217.174.100.
AT#XPING="172.217.174.100",45,5000,5,1000 OK #XPING: 0.873 seconds #XPING: 0.576 seconds #XPING: 0.599 seconds #XPING: 0.623 seconds #XPING: 0.577 seconds #XPING: average 0.650 seconds