Pour le doublon le soucis c'est que je n'arrive pas à le supprimer ^^'
Actuellement, mon professeur m'a dit que je devais essayer de me concentrer que sur l'exemple Udp Ntp Client, je n'ai utilisé que ce code que je n'ai pas modifié, ou quasiment pas du tout si ce n'est que faire +2 à l'heure pour dire être à l'heure française. Voici tout de même le code :
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x22, 0x5D};
unsigned int localPort = 8888;
char timeServer[] = "time.nist.gov";
const int NTP_PACKET_SIZE = 48;
byte packetBuffer[ NTP_PACKET_SIZE];
EthernetUDP Udp;
void setup() {
Serial.begin(9600);
while (!Serial) {;}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
;
}
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()) {
Udp.read(packetBuffer, NTP_PACKET_SIZE);
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
Serial.print(((epoch % 86400L) / 3600)+2);
Serial.print(':');
if (((epoch % 3600) / 60) < 10) {
Serial.print('0');
}
Serial.print((epoch % 3600) / 60);
Serial.print(':');
if ((epoch % 60) < 10) {
Serial.print('0');
}
Serial.println(epoch % 60);
}
delay(300000);
Ethernet.maintain();
}
// send an NTP request to the time server at the given address
void sendNTPpacket(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();
}
Et qu'est ce qui ne va pas dans le post ? ^^'