Hello everyone,
I received my nRF7002-DK board and I wanted to get the time using sntp client.
I wrote a small code (which is mostly a fusion between this code and the sntp_client sample) that connects to my network, setup a sntp context and sends a query to get the time but I keep getting this error : <err> net_sntp: Failed to send over UDP socket -1.
I suspect that something is wrong in my prj.conf but as I am just discovering Zephyr OS, I can't figure out what I am missing...
Any piece of help or advice would be greatly appreciated.
The SNTP part of my code :
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//SNTP Test
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(SNTP_PORT);
zsock_inet_pton(AF_INET, SNTP_SERVER, &addr.sin_addr);
sntp_status = sntp_init(&ctx, (struct sockaddr *) &addr, sizeof(addr));
if(sntp_status < 0){
printk("Init SNTP socket : Failure - Error %d\n", sntp_status);
}
else{
printk("Init SNTP socket : Success\n");
sntp_status = sntp_query(&ctx, 4*MSEC_PER_SEC, &s_time);
if(sntp_status < 0){
printk("Send SNTP query : Failure - Error %d\n", sntp_status);
}
else{
printk("Send SNTP query : Success %d\n");
}
}
sntp_close(&ctx);
My complete code :
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <zephyr/kernel.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/wifi_mgmt.h>
#include <zephyr/net/net_event.h>
#include <errno.h>
#include <zephyr/net/sntp.h>
#include <arpa/inet.h>
#define SSID MYSSID
#define PSK MYPSK
#define SNTP_SERVER "ntp.midway.ovh"
#define SNTP_PORT 123
static K_SEM_DEFINE(wifi_connected, 0, 1);
static K_SEM_DEFINE(ipv4_address_obtained, 0, 1);
static struct net_mgmt_event_callback wifi_cb;
static struct net_mgmt_event_callback ipv4_cb;
And my prj.conf file :
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
# WPA supplicant
CONFIG_WPA_SUPP=y
CONFIG_NET_L2_WIFI_SHELL=y
# System settings
CONFIG_NEWLIB_LIBC=y
#CONFIG_NEWLIB_LIBC_NANO=n
# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_POSIX_API=y
CONFIG_NET_LOG=y
Thanks