Skip to content

Commit 5e0dc2f

Browse files
Improve SNTP start/restart (#2919)
***NO_CI***
1 parent f47a79b commit 5e0dc2f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/PAL/Lwip/lwIP_Sockets.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C"
1717
#include "lwip/sockets.h"
1818
#include "lwip/dhcp.h"
1919
#include "lwip/netif.h"
20+
#include <lwip/apps/sntp.h>
2021
}
2122

2223
int errorCode;
@@ -188,6 +189,12 @@ void LWIP_SOCKETS_Driver::Status_callback(struct netif *netif)
188189
PostAddressChangedContinuation.Enqueue();
189190
}
190191

192+
// need to restart SNTP client
193+
#if SNTP_SERVER_DNS
194+
sntp_stop();
195+
sntp_init();
196+
#endif
197+
191198
#if !defined(BUILD_RTM)
192199
// lcd_printf("\f\n\n\n\n\n\nLink Update: %s\n", (netif_is_up(netif) ? "UP " : "DOWN"));
193200
// lcd_printf(" IP: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF,

targets/ChibiOS/_lwIP/nf_lwipthread.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ void lwipDefaultLinkUpCB(void *p)
256256
#endif
257257

258258
#if SNTP_SERVER_DNS
259-
sntp_init();
259+
// if not using DHCP then start SNTP
260+
// otherwise SNTP will be started when DHCP request succeeds
261+
if (addressMode != NET_ADDRESS_DHCP)
262+
{
263+
sntp_init();
264+
}
260265
#endif
261266
}
262267

0 commit comments

Comments
 (0)