Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UDP_RoundTripDelay_OS6_H743ZI advancedIO_1wifiMessing_copy advancedIO_Assignment_Program UDP_RoundTripDelay_OS6_K64F
NTPClient.h@0:d4145a1a189a, 2020-09-10 (annotated)
- Committer:
- nzvandan
- Date:
- Thu Sep 10 00:31:53 2020 +0000
- Revision:
- 0:d4145a1a189a
2020 NTP Server Communication
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nzvandan | 0:d4145a1a189a | 1 | /* Copyright (c) 2019 ARM, Arm Limited and affiliates. |
| nzvandan | 0:d4145a1a189a | 2 | * SPDX-License-Identifier: Apache-2.0 |
| nzvandan | 0:d4145a1a189a | 3 | * |
| nzvandan | 0:d4145a1a189a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| nzvandan | 0:d4145a1a189a | 5 | * you may not use this file except in compliance with the License. |
| nzvandan | 0:d4145a1a189a | 6 | * You may obtain a copy of the License at |
| nzvandan | 0:d4145a1a189a | 7 | * |
| nzvandan | 0:d4145a1a189a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| nzvandan | 0:d4145a1a189a | 9 | * |
| nzvandan | 0:d4145a1a189a | 10 | * Unless required by applicable law or agreed to in writing, software |
| nzvandan | 0:d4145a1a189a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| nzvandan | 0:d4145a1a189a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| nzvandan | 0:d4145a1a189a | 13 | * See the License for the specific language governing permissions and |
| nzvandan | 0:d4145a1a189a | 14 | * limitations under the License. |
| nzvandan | 0:d4145a1a189a | 15 | */ |
| nzvandan | 0:d4145a1a189a | 16 | |
| nzvandan | 0:d4145a1a189a | 17 | #include "mbed.h" |
| nzvandan | 0:d4145a1a189a | 18 | |
| nzvandan | 0:d4145a1a189a | 19 | #define NTP_DEFULT_NIST_SERVER_ADDRESS "2.pool.ntp.org" |
| nzvandan | 0:d4145a1a189a | 20 | #define NTP_DEFULT_NIST_SERVER_PORT 123 |
| nzvandan | 0:d4145a1a189a | 21 | |
| nzvandan | 0:d4145a1a189a | 22 | class NTPClient { |
| nzvandan | 0:d4145a1a189a | 23 | public: |
| nzvandan | 0:d4145a1a189a | 24 | explicit NTPClient(NetworkInterface *interface = NULL); |
| nzvandan | 0:d4145a1a189a | 25 | void set_server(const char* server, int port); |
| nzvandan | 0:d4145a1a189a | 26 | time_t get_timestamp(int timeout = 15000); |
| nzvandan | 0:d4145a1a189a | 27 | void network(NetworkInterface *interface); |
| nzvandan | 0:d4145a1a189a | 28 | |
| nzvandan | 0:d4145a1a189a | 29 | private: |
| nzvandan | 0:d4145a1a189a | 30 | NetworkInterface *iface; |
| nzvandan | 0:d4145a1a189a | 31 | const char* nist_server_address; |
| nzvandan | 0:d4145a1a189a | 32 | int nist_server_port; |
| nzvandan | 0:d4145a1a189a | 33 | |
| nzvandan | 0:d4145a1a189a | 34 | uint32_t ntohl(uint32_t num); |
| nzvandan | 0:d4145a1a189a | 35 | }; |