This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

receive UDP on nRF9160-dk SLM application

Hi,

I want to receive UPD message on my nRF9160-DK.

I can send UDP messages from my Nordic device to a server and from that messages I get the public IP address of my module. But when I try to receive messages, I don't receive anything.  

I use the serial LTE modem application.

I see the following links to send messages:

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/doc/TCPIP_AT_commands.html#udp-receive-data-xrecvfrom

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/doc/slm_description.html

First try:

AT#XSOCKET=1,2,0


#XSOCKET: 1, 2, 0, 17


OK
AT#XSENDTO="x.x.x.x",20080,1,"Test UDP"


#XSENDTO: 8


OK
AT#XSOCKET=0


#XSOCKET: 0, closed


OK
AT#XSOCKET=1,2,1


#XSOCKET: 1, 2, 1, 17
OK


AT#XBIND=3442


OK


AT#XRECVFROM

and after this I get: "Error: 'AT#XRECVFROM' timed out"  and I cannot send AT command to LTE Link Monitor.

-------------------------------------------------------------------------

Second try:

AT#XSOCKET=1,2,0


#XSOCKET: 1, 2, 0, 17


OK





AT#XSENDTO="x.x.x.x",20080,1,"Test UDP"


#XSENDTO: 8


OK





AT#XSOCKET=0


#XSOCKET: 0, closed


OK


AT#XSOCKET=1,2,1


#XSOCKET: 1, 2, 1, 17


OK


AT#UDPRECVFROM="x.x.x.x",3442


+CME: 0

Here I don't know how to solve this error.


-------------------------------------------------------------------------




Third try:

I set the UDP proxy to use the command AT#XUDPSVR;
So in "Configure nRF Connect SDK Project" I select "Stateful connection-oriented UDP client/server <SLM_UDP_PROXY>"

AT#XUDPCLI=1,"x.x.x.x",20080


#XUDPCLI: 1 connected


OK


%CESQ: 32,1,19,2


%CESQ: 29,1,24,3


AT#XUDPSEND=1,"Test UDP"


#XUDPSEND: 8


OK





AT#XUDPCLI=0


#XUDPCLI: disconnected


OK


AT#XUDPSVR=1,3442 or AT#XUDPSVR=2,3442



#XUDPSVR: 1 started


OK

Here it seems to work but I don't receive anything and retrying I get sometimes: "Error: 'AT#XUDPSVR=1,3442 ' timed out"

I try using the IP that I get in the receiving messages and also with the IP that I get with the command "AT+CGDCONT?"

I try also using the example script "client_udp.py" but nothing.

I try many times with all possible combinations.

What can I do? The nRF9160-DK receives messages but doesn't print them on the LTE Link Monitor or I'm using wrong AT command? Is there an error in the client code? Is the IP that I use the error? Is it possible that my server doesn't know how to reach my APN even if I specify the correct public IP address?


Please, help me to receive a simple "hello".
Thank you in advance.

Best regards

Parents
  • Hi,

    You should not close the socket after sending data, for so to open a new socket that you listen on.

    Instead, you should listen on the same socket that you sent data from.

    Also, be aware that due to Christmas vacations, response times might be slower than normal.

    Best regards,

    Didrik

  • Hi,
    Thanks for the answer.
    I tried without closing the socket but the recvfrom returns always this error: "Error: 'AT#XRECVFROM ' timed out" and always from here I can't send AT command through the LTE Link Monitor.
    In the following I put the command used:

    First try:

    AT#XSOCKET=1,2,1
    #XSOCKET: 1, 2, 1, 17
    OK

    AT#XBIND=3442
    OK

    AT#XSENDTO="x.x.x.x",20080,1,"Test UDP"
    #XSENDTO: 8
    OK

    AT#XRECVFROM (here stops)

    -----------------------------------------------------------


    Second try:

    AT#XSOCKET=1,2,0
    #XSOCKET: 1, 2, 0, 17
    OK

    AT#XSENDTO="x.x.x.x",20080,1,"Test UDP"
    #XSENDTO: 8
    OK

    AT#XRECVFROM (here stops)

    I have to change something in the project file?

    I closed socket in previous tries because I thought that I have to set the socket in client mode (AT#XSOCKET=1,2,0) to send messages and in server mode (AT#XSOCKET=1,2,1) to receive messages.

    Best regards

     

  • AndMar8 said:
    AT#UDPRECVFROM="x.x.x.x",20080

     This command does not exist anymore, so that not working is expected.

     

    AndMar8 said:
    AT#XRECVFROM="x.x.x.x",20080

     Based on the discussion in the PR to fix the documentation, it seems I was wrong in my guess for what form of the command was right. So with that knowledge, this is also expected not to work.

    Instead, the correct syntax for the command is the one in the documentation, and which you were originally using:

    #XRECVFROM[=<size>]

    What server do you send data to, and expect data in return from?

    Are you certain that it does send a reply?

    Can you take a modem trace?

    That will let us see if the modem receives the response, and it is the application that is the problem, or if the response never arrives at the device.

  • Hi,

    I'm sending data using NODE-RED udp-out block. I tested it with different devices and it works.
    Regarding the modem trace I'm working on it.

    I tried this AT command but I get an error:

    first try:

    AT#XRECVFROM=[4]
    ERROR
    [00:02:19.316,406] ESC [1;31M<err> tcpip: F

    [1;31m<err> tcpip: Failed to parse AT command -11

    [0m

    second try:

    AT#XRECVFROM

    Here the code stops and it returns me an error in the window of log output under the terminal.

    I'm wondering what is the correct procedure to send and receive data using UDP.

    Are these steps right?
    1)Opening a Socket
    2) Sending data
    3)Waiting for a response

    Is the UDP data sent from the server buffered somehow or do I need to put the modem into receveing mode before sending the UDP data?

    Best regards

  • AndMar8 said:
    I'm sending data using NODE-RED udp-out block. I tested it with different devices and it works.

     Were do you host it? Did you test with devices outside the local (to the server) network?

     

    AndMar8 said:
    AT#XRECVFROM=[4]

     The "[ ]" in the syntax means that it is an optional parameter. You should either use AT#XRECVFROM, or AT#XRECVFROM=<size>, where <size> is the number of bytes you expect to receive. You should not use "[ ]" in the command.

     

    AndMar8 said:
    Are these steps right?

     Yes. Assuming the device is already connected to the network.

    These commands worked for me:

    at#xsocket=1,2,0
    #XSOCKET: 1, 2, 0, 17
    OK
    at#xsendto="x.x.x.x",7,1,"test"
    #XSENDTO: 4
    OK
    at#xrecvfrom
    test
    #XRECVFROM: 1, 4
    OK

  • Hi,

    Thanks for the answer.

    Yes I tested it with a device outside our local network and the udp packet is correctly received.

    I have tried to replcate your steps but at#xrecvfrom command is not recognized and after that the modem stops answer me and i have to reboot the board.

    To be clear as much as possible, these are the steps that I do:

    1. at+cfun=1
    2. at+cfun?
    3. after that command start automatic command due to the "automatic requests"
    4. after this command:
      at+cgact?
      +cgact: 0,1
      ok
      I send the AT commands that you use
    5. at#xsocket=1,2,0
      #XSOCKET: 1, 2, 0, 17
      OK
    6. at#xsendto="x.x.x.x",20080,1,"test"
      #XSENDTO: 4
      OK
    7. at#xrecvfrom

    Here the code stops working and under the terminal in the Log window immediately appears:

    09:47:24.974       Error: 'at#xrecvfrom' timed out

    From here all AT commands (also a simple AT) returns me this same error (Error: 'at' timed out).

    Which's your modem version? What about the firmware? Are you using the slm application?

    Thank you very much for the help.
    Best regards

  • AndMar8 said:

    Which's your modem version? What about the firmware? Are you using the slm application?

     mfw v1.2.2, SLM from NCS v1.4.0.

     

    AndMar8 said:

    09:47:24.974       Error: 'at#xrecvfrom' timed out

     I assume you are using the LTE link monitor?

    It is note really meant for this kind of use case, but to communicate with the modem "directly". As such, almost all the AT commands it is "meant" to send returns a reply immediately. It therefore has a fairly short timeout. However, it should not be a problem that a command times out, as long as there is a response eventually.

     

    AndMar8 said:
    From here all AT commands (also a simple AT) returns me this same error (Error: 'at' timed out).

     The SLM implementation of #RECVFROM is blocking, so this is not surprising.

    Can you take a modem trace, so we can analyze the IP traffic?

    Also, if you could capture an IP trace from your server, that could also help.

Reply
  • AndMar8 said:

    Which's your modem version? What about the firmware? Are you using the slm application?

     mfw v1.2.2, SLM from NCS v1.4.0.

     

    AndMar8 said:

    09:47:24.974       Error: 'at#xrecvfrom' timed out

     I assume you are using the LTE link monitor?

    It is note really meant for this kind of use case, but to communicate with the modem "directly". As such, almost all the AT commands it is "meant" to send returns a reply immediately. It therefore has a fairly short timeout. However, it should not be a problem that a command times out, as long as there is a response eventually.

     

    AndMar8 said:
    From here all AT commands (also a simple AT) returns me this same error (Error: 'at' timed out).

     The SLM implementation of #RECVFROM is blocking, so this is not surprising.

    Can you take a modem trace, so we can analyze the IP traffic?

    Also, if you could capture an IP trace from your server, that could also help.

Children
  • > The SLM implementation of #RECVFROM is blocking, so this is not surprising.

    Sorry to write that, surprising is indeed not the behavior, it's more, that it is implemented in that way. Doesn't this block the modem for new AT-commands until it receives something? If the sent data is lost, you will not be able to even resend it. For me this implementation is very close to "useless"?

  • Hi, Sorry for the delay. I were able to collected the modem Trace. 
    Please find attached the zip file containing two modem traces. 

    I have also tested the receive mode using a different terminal. I use Termite as both putty and were not able to communicate with the SIP:

    Just for knowledge I have tested the sim card with a different modem from Quectel and I was able to receive the data coming from the node-red UDP node.

    I have also tested the UDP functionality with a desktop packet receiver and it works as well. 

    Here a screen shot from node-red showing the message I am receiving from the SIP. OFC I use the same address and port to send data back to the SIP.

    I am starting being clueless about why I am not able to receive the UDP packet using the nrf9160 SIP.

    I do not know if it can be useful but, can you please share your firmware HEX files just to test it.

    Thank you for your kind help.

    nRF9160_recvfrom_trace.zip

  • Hi,

    I've had a quick look at your traces so far, and I have noticed two things:

    1. Neither the IP address or the source port (from the device) matches your screenshot from the server. Are you sure the screenshot is from the nRF9160?

    2. The modem never receives an recvfrom RPC call from the application core.

    To debug 2 further, could you enable debug logging in the SLM (by setting CONFIG_SLM_LOG_LEVEL=y), and capture the debug log which will be sent over RTT (as well as the UART log and a modem trace)?

    But, the device never receives the reply from the server, so even if the recvfrom call had been there, you still wouldn't have seen any response.

  • Hi,

    1. I believe that the messages are sent by my device because when I send messages from nRF9160 they appear on the node-red debug messages window (as in the screeshot). However to be sure is there an at command to get the IP address of my nRF9160?

    2. Debug:

    I didn't find CONFIG_SLM_LOG_LEVEL=y so I guess you mean CONFIG_SLM_LOG_LEVEL_DBG=y (I hope it's correct).

    For the debugging I also set in the prj.config file:


    CONFIG_USE_SEGGER_RTT=n
    CONFIG_RTT_CONSOLE=n
    CONFIG_UART_CONSOLE=y
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_LOG_BACKEND_UART=y

    I attached the zip with modem trace bin, terminal of Termite, logfile of LTE Link Monitor and the prj.config file

    nRF9160 log.rar

  • Usually, neither the local ip-address your nRF9160 nor the local port you use will be visible at the server. The mobile provider mostly use a NAT, which exchanges that address and port. And because of that NAT, you must respond "in time". I would try to start with less than 30s. 

Related