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

Added compatibility for WT32-ETH01 - ESP32 Board with Ethernet Socket #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Adds NTP capabilities to the ESPHome platform.

** Fixed duplicate sources in "NTP Server info"

** Fixed Ethernet/Wifi compatibility

## Basic Usage

Host an NTP server from an ESP device. Works with any time source in the ESPHome ecosystem.
Expand Down
9 changes: 9 additions & 0 deletions components/ntp_server/ntp_server.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "esphome.h"
#ifdef USE_WIFI
#include "esphome/components/wifi/wifi_component.h"
#else
#include "esphome/components/ethernet/ethernet_component.h"
#endif

#include <WiFiUdp.h>

WiFiUDP Udp;
Expand Down Expand Up @@ -105,7 +110,11 @@ void processNTP() {
tempval = timestamp;

// Set refid to IP address if not locked
#ifdef USE_WIFI
IPAddress myIP = wifi::global_wifi_component->get_ip_addresses()[0];
#else
IPAddress myIP = ethernet::global_eth_component->get_ip_addresses()[0];
#endif
packetBuffer[12] = myIP[0];
packetBuffer[13] = myIP[1];
packetBuffer[14] = myIP[2];
Expand Down