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

  • You may want to switch to CoAP and use NEBRASKA for the purpose of getting your data in your AWS IoT Core account.

    To get a working CoAP stack, just use IOWA Evaluation Version.

    Best Regards,

    Olivier

  • 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

     

  • It looks like the documentation for the #XRECVFROM command has not been updated together with the code.

    Could you try "AT#XRECV" (this should let you receive data from any source) or "AT#XRECVFROM=<url>,<port>" instead?

    We are also working on fixing the documentation to avoid more confusion in the future.

    You can track the progress here: https://github.com/nrfconnect/sdk-nrf/pull/3596

  • Hi,

    Thanks for the answer and Good New Year!

    I redownload the code from "Open nRF Connect SDK Project..." cleaning build directory.

    I have just tried and the outputs are:

    -First try:

    AT#XRECV

    ERROR

    [00:05:20.988,220] ESC  [1;31m<err> tcpip: Not connected yet ESC  [0m

    (I think) It is used for a TCP message (so it needs a TCP "connection") instead of a UDP message.

    -Second try:

    AT#XRECVFROM="x.x.x.x",20080

    ERROR

    It returns me an error but it doesn't block the code as before tries (it seems a good thing).

    -Third try:

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

    +CME: 0

    In this case the code stops working and I have to press the button RESET to restart. I see this command (AT#UDPRECVFROM) in the link you shared.

    Do I have to add something more or something different in command "AT#XRECVFROM="x.x.x.x",20080" that seems the best result for UDP message?

    Best regards

Related