Hello,
I need to send and receive UDP packets using nRF9160DK via NB-IoT network. I'm able to achieve this using Serial LTE modem. However I need to write my own application to use SPI, LED, etc... I tried to modify UDP example to be able to not only send UDP packets but also receive them.
The only modification to original UDP example code is in main.c in function server_transmission_work_fn:
static void server_transmission_work_fn(struct k_work *work) {
int err;
char buffer[CONFIG_UDP_DATA_UPLOAD_SIZE_BYTES] = {valve_state};
printk("Transmitting UDP/IP payload of %d bytes to the ",
CONFIG_UDP_DATA_UPLOAD_SIZE_BYTES + UDP_IP_HEADER_SIZE);
printk("IP address %s, port number %d\n",
CONFIG_UDP_SERVER_ADDRESS_STATIC,
CONFIG_UDP_SERVER_PORT);
err = send(client_fd, buffer, sizeof(buffer), 0);
if (err < 0) {
printk("Failed to transmit UDP packet, %d\n", errno);
return;
}
printk("Start receive\n");
int max_len = 25;
char data[576];
err = recvfrom(client_fd, data, max_len, 0, NULL, NULL);
if (err < 0)
printk("Receive unsuccessful: %d \n", err);
printk("First byte is: %d\n", data[1]);
k_delayed_work_submit(&server_transmission_work, K_SECONDS(CONFIG_UDP_DATA_UPLOAD_FREQUENCY_SECONDS));
}
I basically added just function recvfrom. I'm using newest sdk version 1.5.1.
After restart nRF9160 successfully connect to network, send UDP packet and start waiting for downlink packet. But after I send packet from server application doesn't receive anything and continues waiting forever.
As I said, the receive worked fine when I used Serial modem LTE and from what I looked to the source code the sequence of commands to modem was the same. Can anybody explain this behaviour or help solve my problem?
Thanks for any help