Advertisement
mikroavr

ntp_basic_ethernet

Aug 3rd, 2021
1,405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <HTTPClient.h>
  4. #include <NTPClient.h>
  5. #include <EthernetUdp.h>
  6.  
  7. EthernetUDP Udp_eth;
  8. NTPClient timeClient(Udp_eth, "pool.ntp.org", 25200, 60000);
  9.  
  10. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  11. byte ip[] = {192, 168, 1, 20};
  12. byte dns[] = {255, 255, 255, 0};
  13.  
  14. void setup(){
  15.   pinMode(13, OUTPUT);
  16.   digitalWrite(13, HIGH);
  17.   delay(5000);
  18.   Serial.begin(115200);
  19.   Serial.println("mulai membaca ntp");
  20.  
  21.   Ethernet.init(5);
  22.   Ethernet.begin(mac, ip);
  23.   timeClient.begin();
  24. }
  25.  
  26. void loop() {
  27.   timeClient.update();
  28.   Serial.println(timeClient.getFullFormattedTime());
  29.  
  30.   delay(1000);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement