Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Conversation

dwmw2
Copy link

@dwmw2 dwmw2 commented Aug 5, 2024

It turns out to be fairly simple to just send the UDP packets directly, and the UDP socket handling can then be a whole lot more generic.

…ibrary

It turns out to be fairly simple to just send the UDP packets directly,
and the UDP socket handling can then be a whole lot more generic.
Using a Legacy IP syslog server in an IPv6-enabled build fails due to a
socket::set_sockaddr() bug. Work around it in older versions of esphome.
@chatziko
Copy link

Thanks for this PR, it works great with esp-idf!

However with arduino I get the following error:

src/esphome/components/syslog/syslog_component.cpp: In member function 'virtual void esphome::syslog::SyslogComponent::setup()':
src/esphome/components/syslog/syslog_component.cpp:65:72: error: 'IPPROTO_UDP' was not declared in this scope; did you mean 'IPPROTO_TCP'?
   65 |     this->socket_ = socket::socket(this->server.ss_family, SOCK_DGRAM, IPPROTO_UDP);
      |                                                                        ^~~~~~~~~~~
      |                                                                        IPPROTO_TCP

I'm using esphome 2024.9.0 with the following config:

external_components:
  - source: github://dwmw2/esphome_syslog@esp-ipv6-support
    components: [syslog]

syslog:
    ip_address: <redacted>
    port: 514

Any chance of making the code compatible with both arduino and esp-idf?

@dwmw2
Copy link
Author

dwmw2 commented Sep 26, 2024

Hm, which platform is that on? I thought I'd tested it with Arduino for ESP32. I think there are some platforms where UDP isn't available directly in LwIP and we have to use the Arduino UDP as before, as I mentioned above. I'll have a look at making the change conditional.

@chatziko
Copy link

Oh, just realized that this was on a esp8266 device (not esp32). But there are still plenty of those out there :D

ESP_LOGW(TAG, "Failed to parse server IP address '%s'", this->settings_.address.c_str());
return;
}
this->socket_ = socket::socket(this->server.ss_family, SOCK_DGRAM, IPPROTO_UDP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPPROTO_UDP is not defined on arduino for esp8266.
I managed to fix this by adding

#ifndef IPPROTO_UDP
#include <lwip/ip.h>
#define IPPROTO_UDP IP_PROTO_UDP
#endif

Maybe there is a better way but this works for me. (Also tested with esp-idf.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it #ifdef USE_SOCKET_IMPL_LWIP_TCP; does that work for you?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also, does that make it work or just make it build? The comment at esphome/esphome#4969 (comment) seems to suggest that it'll still just use TCP? Is it actually connecting to the syslog server over TCP?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so as it is right now esp8266 doesn't work, also verified that

#ifdef USE_SOCKET_IMPL_LWIP_TCP
#include <lwip/ip.h>
#define IPPROTO_UDP IP_PROTO_UDP
#endif

is in the source file

@barcar
Copy link

barcar commented Feb 22, 2025

Thanks for this PR, it works great with esp-idf!

However with arduino I get the following error:

src/esphome/components/syslog/syslog_component.cpp: In member function 'virtual void esphome::syslog::SyslogComponent::setup()':
src/esphome/components/syslog/syslog_component.cpp:65:72: error: 'IPPROTO_UDP' was not declared in this scope; did you mean 'IPPROTO_TCP'?
   65 |     this->socket_ = socket::socket(this->server.ss_family, SOCK_DGRAM, IPPROTO_UDP);
      |                                                                        ^~~~~~~~~~~
      |                                                                        IPPROTO_TCP

I'm also seeing this on my older ESP8266 devices. Is there a fix for this?

@dwmw2 dwmw2 requested a review from DjordjeMandic February 24, 2025 20:08
@KrX3D
Copy link

KrX3D commented Mar 8, 2025

works good with idf and arduino for me. thanks ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants