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

Is it possible to add ethernet support ? #11

Open
kboeckx opened this issue Feb 11, 2023 · 10 comments
Open

Is it possible to add ethernet support ? #11

kboeckx opened this issue Feb 11, 2023 · 10 comments

Comments

@kboeckx
Copy link

kboeckx commented Feb 11, 2023

Hi, I have an ESP32 bord that is connected via Ethernet instead of WIFI. So NO WIFI is configured, only Ehternet.

First part of my esphome config is:

esphome:
  name: kc-868-a64
  platform: ESP32
  board: esp32dev

logger:
  level: VERBOSE
  
syslog:
  ip_address: "192.168.255.X"
  port: 514
  min_level: VERY_VERBOSE

api:
  encryption:
    key: <mykey>

ota:
  password: <mypassword>

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0

  manual_ip:
    static_ip: 192.168.255.X
    gateway: 192.168.255.1
    subnet: 255.255.255.0  

I was troubleshooting this because I did not get any syslog message on my syslog server. I used "tcpdump" to see if any syslog packet was received by the syslog server -> the answer was NO :-( (I'm an IT specialist so I know what I"m doing)

Then I added the action "syslog.log" to send explicit a syslog message. Then I received this:

[syslog:058]: Tried to send "custom_action"@"My log message" with level 7 but Wifi isn't connected yet

So my question is: as I'm not using WIFI to connect the ESP32, would it be possible to add support for Ethernet ?
Thanks for reponse and support !

@TheStaticTurtle
Copy link
Owner

I don't have an ESP32 on me to test this right now, nor do I have an Ethernet module for it. But if you feel up to it, you can try to add a condition to check Ethernet connectivity in this file: https://github.com/TheStaticTurtle/esphome_syslog/blob/main/syslog_component.cpp#L57

I'm not certain how it would work on the esp32 idf platform, though, maybe it's as simple as including the Ethernet.h header and getting the link status.

As an ugly patch just to test that syslog/udp even works (because I'm using WiFiUDP) you could try to remove the check completely

Samuel

@kboeckx
Copy link
Author

kboeckx commented Feb 11, 2023

Thanks for a quick repply !

After looking at the source code on https://github.com/arcao/Syslog, I think this your code is not going to work because it uses the WIFI components.

I don't have time today to look into this and read the code and understand it :-)
So please give me some time, I will look into this next week.

Greetings !

@TheStaticTurtle
Copy link
Owner

After looking at the source code on https://github.com/arcao/Syslog, I think this your code is not going to work because it uses the WIFI components.

Actually, no it doesn't, while you can give it an instance of WiFiUDP you can also do it for EthernetUDP see their SimpleLogging example. The only thing that I'm not sure about is how to detect that it's using Ethernet.

Samuel

@kboeckx
Copy link
Author

kboeckx commented Feb 13, 2023

Hi Samuel,

I did some testing and found out that it works with your code. I removed the "if(WiFi.status() != WL_CONNECTED)" part of your code and it works.

I was reading the source code and searching the internet but I can't find out how to check if ethernet is connected.
For me it works, I receive syslog messages. If you ever find out how to check for etherenet connectivity, please let me know.

Thanks for support !

@bucovaina
Copy link

I can confirm on my ESP32 WT32-ETH01 this hack works. I commented out the WiFi connection check and now I get rsyslog messages on my server.

Nice to have if this were implemented in a way so that both Ethernet and WiFi work without having to modify the code and pull it locally :)

But nevertheless, great work, love it!!

@TheStaticTurtle
Copy link
Owner

Hi,

Nice to know 😀!
Currently, I don't have a working esp32 board with Ethernet as I don't really have any project that needs it, so I can't actually test it.
As you saw, it's easy-ish to switch to Ethernet, almost all the code is already compatible thanks to WifiUDP and EthernetUDP using the same UDP class.

I basically need to do two things:

  • Check is esphome is using Ethernet or Wi-Fi, if I'm not mistaken, recreating a WifiUdp instance for every log line caused some issue for me in the past. So it needs to change only when the esp switched connection methods.
  • Check if the Ethernet driver has been initialized and that a link is detected.

The tricky thing is using both Wi-Fi and Ethernet since, especially since the esp32 ip stack is apparently not always stable 😅

Would you mind describing how the module behaves if there is no cable plugged in or if the driver didn't initialize for some reason? My experience with WifiUDP is that it will probably fail silently.

One thing, I'm not clear about the docs is that it states that The Ethernet component and the Wi-Fi component may not be used simultaneously, even if both are physically available.
Does that mean it won't let you compile with both modules, or just not running simultaneously?

But it's of course doable. The thing is, as I said, I don't have the capabilities to do it right now. One thing that could work in the meantime is a secondary branch (or even PR) and users could use the experimental branch/pr-id on the external_components import.

Thanks for the update!

@TheStaticTurtle
Copy link
Owner

On a side note, esphome evolved a lot since I last looked at how it works internally, I'm amazed that this module still works "fine" after going through so many updates 😀! If I get my hands on an Ethernet board, I'll probably redo of most of the module.

Syslog isn't complicated and ditching the *UDP class entirely and instead using a socket is possible as suggested by esphome docs https://esphome.io/cookbook/lambda_magic.html#send-udp-commands. This would not only reduce overhead (Especially if I also ditch the Syslog library), but would also solve compatibility with esp-idf since it would use anything from the Arduino framework 🤔.

I need to tinker with the esp32 and sendto because if there is no connection it will most likely just do nothing intentionally, and I would prefer to write a warning in the log if there is an issue sending something.

@TheStaticTurtle
Copy link
Owner

TheStaticTurtle commented Oct 3, 2023

You know what, I'll order a board of AliExpress so that I will at least have it, and I'll work on it when I'll have a bit more time (my month is about to get crazy 😪).
Any recommendations?

@bucovaina
Copy link

Yeah no worries, it's not urgent for me since it works :)

I just tested it, but only OTA since otherwise, I have to solder again and no time for that :).

While I was connected with "esp logs" it worked. Then I pulled the cable, it said "Connection reset by pear", replugged the cable, it didn't work again. Then I CTRL-C, then re-issued the command esphome logs, but still it didn't connect OTA. I had to unplug the power from the ESP32 before it restarted.

I guess more info will be visible if I connect via serial, but as I said, I'm having a hard time finding time for the project I'm using your custom module in.

With regards to recommendations? I don't know, I just bought an ESP32 WT32-eth01 for around 15$/15eur. I guess most of them are the same but not sure :)

[09:26:25][C][mqtt.light:079]:   Command Topic: '12channel-dimmer/light/flow_heater_l1/command'
[09:26:25][C][mqtt.light:078]: MQTT Light 'Flow heater L2':
[09:26:25][C][mqtt.light:079]:   State Topic: '12channel-dimmer/light/flow_heater_l2/state'
[09:26:25][C][mqtt.light:079]:   Command Topic: '12channel-dimmer/light/flow_heater_l2/command'
[09:26:25][C][mqtt.light:078]: MQTT Light 'Flow heater L3':
[09:26:25][C][mqtt.light:079]:   State Topic: '12channel-dimmer/light/flow_heater_l3/state'
[09:26:25][C][mqtt.light:079]:   Command Topic: '12channel-dimmer/light/flow_heater_l3/command'
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for 12channel-dimmer.local
WARNING Disconnected from API
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
WARNING Can't connect to ESPHome API for 12channel-dimmer.local: Read failed (ReadFailedAPIError)
INFO Trying to connect to 12channel-dimmer.local in the background

WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer

WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
^C(esphome) userwa@macbookuser:~/Documents/smarthome/esphome/tmp$ esphome logs dimpack-controller.yml 
INFO ESPHome 2023.8.3
INFO Reading configuration dimpack-controller.yml...
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
Found multiple options for logging, please choose one:
  [1] Over The Air (12channel-dimmer.local)
  [2] MQTT (10.10.10.19)
(number): 1
INFO Starting log output from 12channel-dimmer.local using esphome API
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
WARNING Can't connect to ESPHome API for 12channel-dimmer.local: Read failed (ReadFailedAPIError)
INFO Trying to connect to 12channel-dimmer.local in the background
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer
WARNING 12channel-dimmer.local: Connection error occurred: [Errno 104] Connection reset by peer

@dwmw2
Copy link

dwmw2 commented Aug 5, 2024

This should now work (for Ethernet, esp-idf, IPv6) with #17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants