I would like to receive UDP messages sent from a server to nRF9160. Is it possible? If so, how can you do that?
I would like to receive UDP messages sent from a server to nRF9160. Is it possible? If so, how can you do that?
Hi.
You can receive data from a UDP socket (or any type of socket) using the recv or recvfrom functions.
One of my colleagues made a sample a while ago that fetches the current time from an NTP server: https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/ntp
As the sample is not actively maintained, it might need some modifications to work on the latest version of NCS, but it should be a good starting point.
One important detail though is that most cellular network uses some form of NAT. This means that you might not be able to reach a device from your server unless the device was the one to initiate the communication.
Best regards,
Didrik
Hi, Didrik. Sorry for a late response.
I'm thinking of applying a public static IP address to a SIM card and receiving a UDP message during eDRX mode. Is this possible?
As long as I learned about UDP sever, a following step to receive a message as a server should be taken.
1. create a socket
2. bind the socket to a specific port
3. poll until data is received or timeout
4. recvfrom when data is received.
During eDRX, nRF9160 server decreases power consumption so it can receive a message saving battery power..
I'm not familiar with network. Thank you for advising me!
Hi, Didrik. Sorry for a late response.
I'm thinking of applying a public static IP address to a SIM card and receiving a UDP message during eDRX mode. Is this possible?
As long as I learned about UDP sever, a following step to receive a message as a server should be taken.
1. create a socket
2. bind the socket to a specific port
3. poll until data is received or timeout
4. recvfrom when data is received.
During eDRX, nRF9160 server decreases power consumption so it can receive a message saving battery power..
I'm not familiar with network. Thank you for advising me!
Hi, and sorry for the late response, but I was away on vacation.
One problem with your suggestion is that on most networks the device is behind NAT, and the network will close the connection after 10-75 seconds (in most cases).
You can therefore not expect your device to keep it's IP address, or be reachable from the outside.
These problems can probably be worked around by employing your own APN, but that is not a trivial thing to do (from both a technical and business perspective).
Instead, the common approach is to have the device initiate all communication.
A modification of that solution is to have the server send an SMS to the device when the server wants to initiate communication. SMS-es has more guarantees regarding delivery than (UDP) IP packets, so the server can be quite confident that the SMS will reach the device. The device can then contact the server over IP (UDP or TCP) to receive the data.
Best regards,
Didrik