| 1 |
sntp_lwip |
| 2 |
================= |
| 3 |
|
| 4 |
## Overview |
| 5 |
|
| 6 |
**sntp_lwip** implements Azure IoT C Shared Utility `sntp` adapter on devices running lwIP. |
| 7 |
The `sntp` adapter is intentionally lightweight |
| 8 |
and aimed at small devices because NTP's time setting function is taken care of by the OS on larger machines. |
| 9 |
|
| 10 |
## References |
| 11 |
|
| 12 |
[lwIP](http://savannah.nongnu.org/projects/lwip/) |
| 13 |
|
| 14 |
### Exposed API |
| 15 |
|
| 16 |
**SRS_SNTP_LWIP_30_001: [** The ntp_lwip shall implement the methods defined in `sntp.h`. |
| 17 |
```c |
| 18 |
int SNTP_SetServerName(const char* serverName); |
| 19 |
int SNTP_Init(); |
| 20 |
void SNTP_Deinit(); |
| 21 |
``` |
| 22 |
**]** |
| 23 |
|
| 24 |
|
| 25 |
### SNTP_SetServerName |
| 26 |
`SNTP_SetServerName` must be called before `SNTP_Init`. The character array pointed to by `serverName` parameter must persist between calls to `SNTP_SetServerName` and `SNTP_Deinit` because the char* is stored and no copy of the string is made. |
| 27 |
|
| 28 |
`SNTP_SetServerName` is a wrapper for the lwIP call `sntp_setservername` and defers parameter validation to the lwIP library. |
| 29 |
|
| 30 |
Future implementations of this adapter may allow multiple calls to `SNTP_SetServerName` in order to support multiple servers. |
| 31 |
|
| 32 |
```c |
| 33 |
int SNTP_SetServerName(const char* serverName); |
| 34 |
``` |
| 35 |
|
| 36 |
**SRS_SNTP_LWIP_30_002: [** The `serverName` parameter shall be an NTP server URL which shall not be validated. (Validation is deferred to the underlying library.) **]** |
| 37 |
|
| 38 |
**SRS_SNTP_LWIP_30_003: [** The `SNTP_SetServerName` shall set the NTP server |
| 39 |
to be used by ntp_lwip and return 0 to indicate success. (lwIP has no failure path.) **]** |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
### SNTP_Init |
| 44 |
|
| 45 |
`SNTP_Init` initializes the SNTP client and begins the process of contacting the NTP server. It blocks until NTP time has been successfully received. |
| 46 |
|
| 47 |
```c |
| 48 |
int SNTP_Init(); |
| 49 |
``` |
| 50 |
**SRS_SNTP_LWIP_30_004: [** `SNTP_Init` shall initialize the SNTP client, contact the NTP server to set system time, then return 0 to indicate success (lwIP has no failure path). **]** |
| 51 |
|
| 52 |
|
| 53 |
### SNTP_Denit |
| 54 |
|
| 55 |
`SNTP_Denit` deinitializes the SNTP client. |
| 56 |
|
| 57 |
```c |
| 58 |
void SNTP_Denit(); |
| 59 |
``` |
| 60 |
|
| 61 |
**SRS_SNTP_LWIP_30_005: [** `SNTP_Denit` shall deinitialize the SNTP client. **]** |