# SNTP

This module includes functions that control SNTP communication.

## Summary

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-sntp#group__api-sntp_1gad8b03f5d57ff303014063b5b74bd1388` | typedef `struct https://openthread.io/reference/struct/ot-sntp-query` Implements SNTP Query parameters. |
| `https://openthread.io/reference/group/api-sntp#group__api-sntp_1ga68222f1a08921ba7a1f85ae7a2bf0a8d)(void *aContext, uint64_t aTime, otError aResult)` | typedef `void(*` Pointer is called when a SNTP response is received. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-sntp#group__api-sntp_1gaf59b2e17e5cfaa943f6550fed45720cf(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, const https://openthread.io/reference/struct/ot-sntp-query *aQuery, https://openthread.io/reference/group/api-sntp#group__api-sntp_1ga68222f1a08921ba7a1f85ae7a2bf0a8d aHandler, void *aContext)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a SNTP query. |
| `https://openthread.io/reference/group/api-sntp#group__api-sntp_1ga60816054c21e1fb3b6fb315a9dca435d(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, uint32_t aUnixEra)` | `void` Sets the unix era number. |

| ### Macros ||
|---|---|
| `https://openthread.io/reference/group/api-sntp#group__api-sntp_1ga7b68dc817871f8f73d3654e47deaf487 "2001:4860:4806:8::"` | Defines default SNTP Server address - Google NTP Server. |
| `https://openthread.io/reference/group/api-sntp#group__api-sntp_1gaf9b46234541eabaa5846d5327e70d910 123` | Defines default SNTP Server port. |

| ### Structs ||
|---|---|
| [otSntpQuery](https://openthread.io/reference/struct/ot-sntp-query) | Implements SNTP Query parameters. |

## Typedefs

### otSntpQuery

```
struct otSntpQuery otSntpQuery
```
Implements SNTP Query parameters.

### otSntpResponseHandler

```
void(* otSntpResponseHandler)(void *aContext, uint64_t aTime, otError aResult)
```
Pointer is called when a SNTP response is received.

<br />

Details Parameters `[in] aContext` A pointer to application-specific context. `[in] aTime` Specifies the time at the server when the response left for the client, in UNIX time. `[in] aResult` A result of the SNTP transaction. Return Values `OT_ERROR_NONE` A response was received successfully and time is provided in `aTime`. `OT_ERROR_ABORT` A SNTP transaction was aborted by stack. `OT_ERROR_BUSY` The Kiss-o'-death packet has been received. `OT_ERROR_RESPONSE_TIMEOUT` No SNTP response has been received within timeout. `OT_ERROR_FAILED` A response was received but contains incorrect data.

## Functions

### otSntpClientQuery

```
otError otSntpClientQuery(
  otInstance *aInstance,
  const otSntpQuery *aQuery,
  otSntpResponseHandler aHandler,
  void *aContext
)
```
Sends a SNTP query.

Is available only if feature `OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE` is enabled.

<br />

Details Parameters `[in] aInstance` A pointer to an OpenThread instance. `[in] aQuery` A pointer to specify SNTP query parameters. `[in] aHandler` A function pointer that shall be called on response reception or time-out. `[in] aContext` A pointer to arbitrary context information.

### otSntpClientSetUnixEra

```
void otSntpClientSetUnixEra(
  otInstance *aInstance,
  uint32_t aUnixEra
)
```
Sets the unix era number.

The default value of unix era is set to 0. The subsequent eras start after year 2106.

<br />

Details Parameters `[in] aInstance` A pointer to an OpenThread instance. `[in] aUnixEra` Unix era number.

## Macros

### OT_SNTP_DEFAULT_SERVER_IP

```
 OT_SNTP_DEFAULT_SERVER_IP "2001:4860:4806:8::"
```
Defines default SNTP Server address - Google NTP Server.

### OT_SNTP_DEFAULT_SERVER_PORT

```
 OT_SNTP_DEFAULT_SERVER_PORT 123
```
Defines default SNTP Server port.

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).