Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of using with Arduino Ethernet Shield (#111) #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/ArduinoEthernetShield/ArduinoEthernetShield.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <EthernetUdp.h>
#include <NTPClient.h>

#define ethernetShieldPin 10 // Most Arduino shields
// #define ethernetShieldPin 5 // MKR ETH shield
// #define ethernetShieldPin 0 // Teensy 2.0
// #define ethernetShieldPin 20 // Teensy++ 2.0
// #define ethernetShieldPin 15 // ESP8266 with Adafruit Featherwing Ethernet
// #define ethernetShieldPin 33 // ESP32 with Adafruit Featherwing Ethernet

byte localMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
unsigned int localUdpPort = 8888;
EthernetUDP udp;

NTPClient timeClient(udp);

void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Ethernet.init(ethernetShieldPin);
Serial.println("Initialize Ethernet with DHCP");
if (Ethernet.begin(localMac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found.");
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
while (true) {
delay(1);
}
}
udp.begin(localUdpPort);
}

void loop() {
if(timeClient.update()) {
Serial.print("Updated current time: ");
Serial.println(timeClient.getFormattedTime());
}
}