mirror of
https://github.com/esphome/esphome.git
synced 2024-12-29 08:51:43 +01:00
Merge branch 'udp' into nrf52_core
This commit is contained in:
commit
4a83efceac
2 changed files with 10 additions and 5 deletions
|
@ -262,7 +262,8 @@ void UDPComponent::setup() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
|
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||||
// 8266 and RP2040 `Duino
|
// 8266 and RP2040 `Duino
|
||||||
for (const auto &address : this->addresses_) {
|
for (const auto &address : this->addresses_) {
|
||||||
auto ipaddr = IPAddress();
|
auto ipaddr = IPAddress();
|
||||||
|
@ -371,7 +372,8 @@ void UDPComponent::loop() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||||
auto len = this->listen_socket_->read(buf, sizeof(buf));
|
auto len = this->listen_socket_->read(buf, sizeof(buf));
|
||||||
#else
|
#endif
|
||||||
|
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||||
auto len = this->udp_client_.parsePacket();
|
auto len = this->udp_client_.parsePacket();
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
len = this->udp_client_.read(buf, sizeof(buf));
|
len = this->udp_client_.read(buf, sizeof(buf));
|
||||||
|
@ -588,7 +590,8 @@ void UDPComponent::send_packet_(void *data, size_t len) {
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
ESP_LOGW(TAG, "sendto() error %d", errno);
|
ESP_LOGW(TAG, "sendto() error %d", errno);
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
|
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||||
auto iface = IPAddress(0, 0, 0, 0);
|
auto iface = IPAddress(0, 0, 0, 0);
|
||||||
for (const auto &saddr : this->ipaddrs_) {
|
for (const auto &saddr : this->ipaddrs_) {
|
||||||
if (this->udp_client_.beginPacketMulticast(saddr, this->port_, iface, 128) != 0) {
|
if (this->udp_client_.beginPacketMulticast(saddr, this->port_, iface, 128) != 0) {
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
#endif
|
#endif
|
||||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||||
#include "esphome/components/socket/socket.h"
|
#include "esphome/components/socket/socket.h"
|
||||||
#else
|
#endif
|
||||||
|
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#endif
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -126,7 +127,8 @@ class UDPComponent : public PollingComponent {
|
||||||
std::unique_ptr<socket::Socket> broadcast_socket_ = nullptr;
|
std::unique_ptr<socket::Socket> broadcast_socket_ = nullptr;
|
||||||
std::unique_ptr<socket::Socket> listen_socket_ = nullptr;
|
std::unique_ptr<socket::Socket> listen_socket_ = nullptr;
|
||||||
std::vector<struct sockaddr> sockaddrs_{};
|
std::vector<struct sockaddr> sockaddrs_{};
|
||||||
#else
|
#endif
|
||||||
|
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||||
std::vector<IPAddress> ipaddrs_{};
|
std::vector<IPAddress> ipaddrs_{};
|
||||||
WiFiUDP udp_client_{};
|
WiFiUDP udp_client_{};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue