Gast
#5837667
Hallo ich habe hier im LAN einen Arduino (Mega) mit Ethernet-Lan W5100, der seine Zeit von einem Zeitserver der auf einem Raspberry im gleichen lan installiert ist, bekommen soll hängen im 192.168.2.0 LAN alle h Auf dem Raspberry sieht die ntp.con so aus # /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help driftfile /var/lib/ntp/ntp.drift # Enable this if you want statistics to be logged. #statsdir /var/log/ntpstats/ statistics loopstats peerstats clockstats filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable # You do need to talk to an NTP server or two (or three). #server ntp.your-provider.example # pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will # pick a different set every time it starts up. Please consider joining the # pool: <http://www.pool.ntp.org/join.html> pool ntp1.hetzner.de iburst pool ntp2.hetzner.com iburst pool 0.de.pool.ntp.org iburst pool 1.de.pool.ntp.org iburst # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for # details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions> # might also be helpful. # # Note that "restrict" applies to both servers and clients, so a configuration # that might be intended to block requests from certain clients could also end # up blocking replies from your own upstream servers. # By default, exchange time with everybody, but don't allow configuration. restrict -4 default kod notrap nomodify nopeer noquery limited restrict -6 default kod notrap nomodify nopeer noquery limited # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 # Needed for adding pool entries restrict source notrap nomodify noquery # Clients from this (example!) subnet have unlimited access, but only if # cryptographically authenticated. restrict 192.168.2.0 mask 255.255.255.0 notrust # If you want to provide time to your local subnet, change the next line. # (Again, the address is an example only.) broadcast 192.168.2.255 # If you want to listen to time broadcasts on your local subnet, de-comment the # next lines. Please do this only if you trust everybody on the network! #disable auth #broadcastclient mit tcpdump erhalte ich folgendes sudo tcpdump -vvveni any udp port 123 tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes 16:42:54.783503 In de:ad:be:ef:fe:ed ethertype IPv4 (0x0800), length 92: (tos 0x0, ttl 128, id 10574, offset 0, flags [DF], proto UDP (17), length 76) 192.168.2.9.8888 > 192.168.2.10.123: [udp sum ok] NTPv4, length 48 Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -20 Root Delay: 0.000000, Root dispersion: 0.000000, Reference-ID: (unspec) Reference Timestamp: 0.000000000 Originator Timestamp: 0.000000000 Receive Timestamp: 0.000000000 Transmit Timestamp: 0.000000000 Originator - Receive Timestamp: 0.000000000 Originator - Transmit Timestamp: 0.000000000 16:43:05.844961 In de:ad:be:ef:fe:ed ethertype IPv4 (0x0800), length 92: (tos 0x0, ttl 128, id 10576, offset 0, flags [DF], proto UDP (17), length 76) 192.168.2.9.8888 > 192.168.2.10.123: [udp sum ok] NTPv4, length 48 Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -20 Root Delay: 0.000000, Root dispersion: 0.000000, Reference-ID: (unspec) Reference Timestamp: 0.000000000 Originator Timestamp: 0.000000000 Receive Timestamp: 0.000000000 Transmit Timestamp: 0.000000000 Originator - Receive Timestamp: 0.000000000 Originator - Transmit Timestamp: 0.000000000 16:43:08.558536 Out b8:27:eb:67:ec:f4 ethertype IPv4 (0x0800), length 92: (tos 0xb8, ttl 64, id 37665, offset 0, flags [DF], proto UDP (17), length 76) 192.168.2.10.123 > 192.168.2.255.123: [bad udp cksum 0x86a3 -> 0xf154!] NTPv4, length 48 Broadcast, Leap indicator: (0), Stratum 3 (secondary reference), poll 6 (64s), precision -18 Root Delay: 0.021270, Root dispersion: 0.056213, Reference-ID: 94.16.115.123 Reference Timestamp: 3766487654.572646037 (2019/05/10 16:34:14) Originator Timestamp: 0.000000000 Receive Timestamp: 0.000000000 Transmit Timestamp: 3766488188.558358062 (2019/05/10 16:43:08) Originator - Receive Timestamp: 0.000000000 Originator - Transmit Timestamp: 3766488188.558358062 (2019/05/10 16:43:08) 16:43:16.906417 In de:ad:be:ef:fe:ed ethertype IPv4 (0x0800), length 92: (tos 0x0, ttl 128, id 10578, offset 0, flags [DF], proto UDP (17), length 76) 192.168.2.9.8888 > 192.168.2.10.123: [udp sum ok] NTPv4, length 48 Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -20 Root Delay: 0.000000, Root dispersion: 0.000000, Reference-ID: (unspec) Reference Timestamp: 0.000000000 Originator Timestamp: 0.000000000 Receive Timestamp: 0.000000000 Transmit Timestamp: 0.000000000 Originator - Receive Timestamp: 0.000000000 Originator - Transmit Timestamp: 0.000000000 der Code auf dem arduino sieht so aus /* Udp NTP Client Get the time from a Network Time Protocol (NTP) time server Demonstrates use of UDP sendPacket and ReceivePacket For more on NTP time servers and the messages needed to communicate with them, see http://en.wikipedia.org/wiki/Network_Time_Protocol created 4 Sep 2010 by Michael Margolis modified 9 Apr 2012 by Tom Igoe modified 02 Sept 2015 by Arturo Guadalupi This code is in the public domain. */ #include <SPI.h> #include <Ethernet.h> #include <EthernetUdp.h> // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 2, 9); IPAddress gateway(192,168,2, 1); IPAddress subnet(255, 255, 255, 0); IPAddress dnsServer(192,168,2, 1); EthernetClient client; unsigned int localPort = 8888; // local port to listen for UDP packets const char timeServer[] = "printer2"; // time.nist.gov NTP server const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets // A UDP instance to let us send and receive packets over UDP EthernetUDP Udp; void setup() { // You can use Ethernet.init(pin) to configure the CS pin Ethernet.init(10); // Most Arduino shields //Ethernet.init(5); // MKR ETH shield //Ethernet.init(0); // Teensy 2.0 //Ethernet.init(20); // Teensy++ 2.0 //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // start Ethernet and UDP Ethernet.begin(mac, ip, dnsServer, gateway, subnet); Udp.begin(localPort); } void loop() { sendNTPpacket(timeServer); // send an NTP packet to a time server // wait to see if a reply is available delay(1000); if (Udp.parsePacket()) { // We've received a packet, read the data from it Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer // the timestamp starts at byte 40 of the received packet and is four bytes, // or two words, long. First, extract the two words: unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); // combine the four bytes (two words) into a long integer // this is NTP time (seconds since Jan 1 1900): unsigned long secsSince1900 = highWord << 16 | lowWord; Serial.print("Seconds since Jan 1 1900 = "); Serial.println(secsSince1900); // now convert NTP time into everyday time: Serial.print("Unix time = "); // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: const unsigned long seventyYears = 2208988800UL; // subtract seventy years: unsigned long epoch = secsSince1900 - seventyYears; // print Unix time: Serial.println(epoch); // print the hour, minute and second: Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) Serial.print(':'); if (((epoch % 3600) / 60) < 10) { // In the first 10 minutes of each hour, we'll want a leading '0' Serial.print('0'); } Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) Serial.print(':'); if ((epoch % 60) < 10) { // In the first 10 seconds of each minute, we'll want a leading '0' Serial.print('0'); } Serial.println(epoch % 60); // print the second } // wait ten seconds before asking for the time again delay(10000); Ethernet.maintain(); } // send an NTP request to the time server at the given address void sendNTPpacket(const char * address) { // set all bytes in the buffer to 0 memset(packetBuffer, 0, NTP_PACKET_SIZE); // Initialize values needed to form NTP request // (see URL above for details on the packets) packetBuffer[0] = 0b11100011; // LI, Version, Mode packetBuffer[1] = 0; // Stratum, or type of clock packetBuffer[2] = 6; // Polling Interval packetBuffer[3] = 0xEC; // Peer Clock Precision // 8 bytes of zero for Root Delay & Root Dispersion packetBuffer[12] = 49; packetBuffer[13] = 0x4E; packetBuffer[14] = 49; packetBuffer[15] = 52; // all NTP fields have been given values, now // you can send a packet requesting a timestamp: Udp.beginPacket(address, 123); // NTP requests are to port 123 Udp.write(packetBuffer, NTP_PACKET_SIZE); Udp.endPacket(); } im Terminal erhalte ich jedoch keine Ausgabe. Er bekommt also irgendwie die Zeit nicht korrekt sieht da jemand den Fehler den ich machte? Grüße Jürgen