-
Notifications
You must be signed in to change notification settings - Fork 28
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
WireGuard Support for ESP32 #1444
Comments
I've already tried to add the library by putting this in my ESPHome yaml config:
Any help / hint is much appreciated! |
@davey Very cool solution. It is potentially will add ability to communicate with I know one of embedded developer. Will try to consult with him. Also, will try to google problem to help you. |
Faced with same issue. I've even created fresh project to test. Same result. It tries to execute Here my test project and config: What I found and tried, options:
Summary: It is necessary to understand, how configure Hope it helps somehow.
...
; Removes paramaters from ASFLAGS
build_unflags =
-Wa,-x
-Wa,assembler-with-cpp
-Wa,-mlongcalls
... Error from assembler after remove unsupported flags: ...
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:14: Error: unknown pseudo-op: `.cpu'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:15: Error: unknown pseudo-op: `.fpu'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:16: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:17: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:18: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:19: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:20: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:21: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:22: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:23: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:24: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_mpy121666.S:25: Error: unknown pseudo-op: `.code'
cortex_m0_reduce25519.S:33: Error: unknown pseudo-op: `.code'
cortex_m0_reduce25519.S:34: Error: unknown pseudo-op: `.thumb_func'
cortex_m0_reduce25519.S:38: Error: unknown opcode or format name 'push'
cortex_m0_reduce25519.S:39: Error: unknown opcode or format name 'ldr'
cortex_m0_reduce25519.S:40: Error: extra comma
cortex_m0_reduce25519.S:40: Error: syntax error
cortex_m0_reduce25519.S:41: Error: extra comma
cortex_m0_reduce25519.S:41: Error: syntax error
cortex_m0_reduce25519.S:42: Error: extra comma
cortex_m0_reduce25519.S:42: Error: syntax error
cortex_m0_reduce25519.S:43: Error: extra comma
cortex_m0_reduce25519.S:43: Error: syntax error
cortex_m0_reduce25519.S:44: Error: unknown opcode or format name 'uxth'
cortex_m0_reduce25519.S:45: Error: unknown opcode or format name 'mul'
cortex_m0_reduce25519.S:46: Error: unknown opcode or format name 'mul'
cortex_m0_reduce25519.S:47: Error: bad register name: r5
cortex_m0_reduce25519.S:47: Error: junk at end of line, first unrecognized character is `r'
cortex_m0_reduce25519.S:47: Internal error!
Assertion failure in ignore_rest_of_line at /builds/idf/crosstool-NG/.build/src/binutils-2.25.1/gas/read.c line 3694.
Please report this bug.
*** [.pio/build/esp-wrover-kit/libca3/WireGuard-ESP32/crypto/cortex/cortex_m0_mpy121666.S.o] Error 1
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S: Assembler messages:
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:11: Error: unknown pseudo-op: `.cpu'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:12: Error: unknown pseudo-op: `.fpu'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:13: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:14: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:15: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:16: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:17: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:18: Error: unknown pseudo-op: `.eabi_attribute'
-ardui.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:19: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:20: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:21: Error: unknown pseudo-op: `.eabi_attribute'
.pio/libdeps/esp-wrover-kit/WireGuard-ESP32/src/crypto/cortex/cortex_m0_reduce25519.S:22: Error: unknown pseudo-op: `.code'
ncortex_m0_reduce25519.S:30: Error: unknown pseudo-op: `.code'
oespressif32/tools/sdk/include/coap -I/cortex_m0_reduce25519.S:31: Error: unknown pseudo-op: `.thumb_func'
home/petr/.platformio/cortex_m0_reduce25519.S:35: Error: unknown opcode or format name 'push'
cortex_m0_reduce25519.S:36: Error: extra comma
cortex_m0_reduce25519.S:36: Error: syntax error
cortex_m0_reduce25519.S:37: Error: extra comma
cortex_m0_reduce25519.S:37: Error: syntax error
cortex_m0_reduce25519.S:38: Error: unknown opcode or format name 'uxth'
cortex_m0_reduce25519.S:39: Error: extra comma
cortex_m0_reduce25519.S:39: Error: syntax error
cortex_m0_reduce25519.S:40: Error: unknown opcode or format name 'mul'
cortex_m0_reduce25519.S:41: Error: unknown opcode or format name 'mul'
cortex_m0_reduce25519.S:42: Error: extra comma
cortex_m0_reduce25519.S:42: Error: syntax error
cortex_m0_reduce25519.S:43: Error: extra comma
cortex_m0_reduce25519.S:43: Error: syntax error
cortex_m0_reduce25519.S:44: Error: extra comma
cortex_m0_reduce25519.S:44: Error: syntax error
cortex_m0_reduce25519.S:45: Error: extra comma
cortex_m0_reduce25519.S:45: Error: syntax error
cortex_m0_reduce25519.S:46: Error: bad register name: r4
cortex_m0_reduce25519.S:46: Error: junk at end of line, first unrecognized character is `r'
cortex_m0_reduce25519.S:46: Internal error!
Assertion failure in ignore_rest_of_line at /builds/idf/crosstool-NG/.build/src/binutils-2.25.1/gas/read.c line 3694.
Please report this bug.
... |
Solved. By exclude files in In the end reveals that So it can safety exclude from build. One thing, I don't find easy way to exclude some lib files from build via So you can use lib_deps = https://github.com/mrkeuz/WireGuard-ESP32-Arduino#a788ab8 Or fork you own repo (just delete |
Hi, will it be added to esphome code? I want to connect esphome sensors from external network to home assistant api. Thanks EDIT: I added libs_deps: If I flash it how and what commands can I configure it on project yaml? Thanks |
I finally got a basic example setup working and would like to share that. 🚀 Thanks a lot for all those who contributed to this - this is great! This is the content of my ESPhome config yaml (
This is the content of my Wireguard config (
This is all that is needed on the ESP / EPShome side. For completeness of this example, this is the essential part on the VPN/Wireguard server side (
I am sure there a a lot things that still need to be improved, e.g. properly waiting for the Wifi being established, making sure we reconnect in case the connection is lost and so on - I just wanted to share the earliest success to everyone waiting for it :-) Next steps in my opinion would be to make the config more dynamic, e.g. being able to change the settings (server host, port, public and private keys and so on) or even generate a private key on the ESP itself, only showing/providing it's publickey part somewhere... |
Thanks for the great work! You can also make it run upon time sync, which simplifies things: wireguard-test.yaml esphome:
name: wireguard-test
platform: ESP32
board: esp32dev
libraries: ciniml/WireGuard-ESP32
includes: wg-settings.h
wifi:
networks:
- { ssid: "wifi-ssid-1", password: "xxxxxxxxxxxx" }
ap: { ssid: "wgtest-SETUP", password: "secretsetup" }
ota:
logger: { level: DEBUG, baud_rate: 115200}
web_server: { port: 80 }
time:
- platform: sntp
on_time_sync:
then:
- logger.log: "Starting wireguard..."
- lambda: |
wg.begin(local_ip,private_key,endpoint_address,public_key,endpoint_port); wg-settings.h #include <WireGuard-ESP32.h>
static WireGuard wg;
char private_key[] = "XXXXXXXXXXXXXXX="; // private key of the client (ESP)
char public_key[] = "YYYYYYYYYYYYYYYY="; // public key of the server (remote linux VPN server)
IPAddress local_ip(192,168,99,123); // VPN IP for this VPN client
char endpoint_address[] = "vpn.example.com"; // VPN/Wireguard server hostname
int endpoint_port = 51820; // VPN/Wireguard server port The web server works, it's pretty amazing to have Wireguard running finally thanks a lot :D However, I haven't been able to connect via OTA nor ESPHome API (adding |
OK, got it to work with Home Assistant & OTA! 😄 We were missing an IP route from the Home Assistant network to the Wireguard network (i.e. packets sent from HASS to the ESPHome node IP were being forwarded to the router, which dropped them). So neither HASS nor OTA could reach the nodes.
sensor:
- platform: command_line
name: Wireguard addon internal IP # Creates the IP route to support ESPHome devices on Wireguard
command: host_result=$(host a0d7b954-wireguard); addon_ip=${host_result##* }; ip route replace 172.27.66.0/24 via $addon_ip; echo $addon_ip
A bit tacky but at least we know it can work! Thanks @davey, @mrkeuz and @ciniml for making this possible! 🎉 |
@CarlosGS fantastic news! I'm curious, did you try test connections exactly from Honestly, exposed API via |
Haven't tried MQTT yet, but it should work. Setup order shouldn't really matter as the Wireguard implementation overrides the default routing interface.
Indeed! And ESP8266 is also based on lwip - do you think it could be possible to port it, or does it depend on internal cipher functions of ESP32? |
Actually, I'm not "core" I think it needs just try. The missing functions can be added and replaced via some Ah. Finally, found next discussion (see last comment). Seem it already worked on |
The other item that wasn't working "out of the box" was the API logger. Connecting with the remote logger would make the ESP32 fall into some sort of loop and stop responding. Also, for a complete official component we should consider enabling Wireguard in "OTA safe mode", this way remote nodes would be accessible even in the event of a reboot loop :) 🤔 It would be great if someone could get ESPHome+Wireguard running on ESP8266, that would really shape an official method to have remote ESPHome nodes. Any news or testing, make sure to post here! |
Just FYI. Found easy instruction how link Maybe it might be useful for somebody. |
Hello everyone, first of all, thanks a lot for your work, it's awesome!
I hope this information will be useful and save someone a few nights of debugging :) |
i did confirm that esp8266 works fine with the original implementation. |
This feature will be added to esphome? |
Hi, I tried to build that with platformIO but I get error, How did you do it? Thanks.
|
as I don't use platformio, I don't know. |
@CarlosGS thank you (gracias!). I'm very close to make work oracle cloud+home assistant+wireguard+esphome. Only have and issue (the last?). I've made your magic with the command sensor. With those line wireguard works, but home assistant loses internet connection. any idea? |
Hmm, do you mean your Home assistant is running in an external server?
Mine runs in LAN, sorry, I'm not sure what would be needed to make it work
like that 🤔
|
yes, it's working on an oracle cloud+wireguard (i think it's great). I'd to enable ip forward to make it work (see my previous post). thank you! |
Hi, can anyone make a little guide in one document, how novice users like me can get wiregurd working with esp32? Thanks :) I think it can help more people that me ;) |
A quick and ugly guide. enjoy |
PSA this attachment is a virus. |
Why do you think it's a virus? It's a document describing how to setup wireguard on an esphome device. |
Hi @snechiporenko, I'm aware of that inconvenient behaviour, the same will happen if the device looses wifi connection and then reconnect, but currently I don't know how to fix it, probably it is something related to lower levels of network stack. That is why I introduced the A possible workaround could be to hook the wifi connection drop in order to refresh the wireguard interface but I didn't find a way to hook such event... |
Please @snechiporenko see comment on droscy/esphome#11 |
Code updated, these are the changes:
|
Hey there love it, I can't understand where the issue might be. Any help welcome Thanks |
Hello @y1ann1s, could you please provide your configuration and logs of the esp when it is connected to the remote wifi? |
Hello. When will the release be scheduled? I have one more suggestion. If the device changes its point of connection (it can be either within a home network or outside), depending on its location, it should determine whether to use a VPN or not. wifi:
networks:
- ssid: FirstNetworkToConnectTo
password: VerySafePassword
- ssid: SecondNetworkToConnectTo
password: VerySafePassword I use a VPN for a wearable device, like a watch :-) |
I would leave this logic to triggers/actions/scripts rather than a built in feature. |
@droscy ignore it, my bad F@#$ up firewall, working perfect now |
Thank you very much for this great extension! I added a node locally with a configured wireguard block. Then I put the node to a remote location. I tried adding the remote ip (172.27.66.3) to ESPHome but it said "already exists". Everything works fine and it is connected. The only thing wich does not work ist the online/offline state and viewing logs. It searches for "wireguard-watermeter.local" and cannot resolv the IP: Is there any option to fix this? Or did I do something wrong? Greetings :-) |
The addresses |
@droscy Thank you very much! The |
A quick question. I'm trying to establish a connection but i receive the following message:
The vpn server is operational because my phone can connect without issues. I use the following configuration:
Does someone have an idea what the issue could be? |
This worked perfectly, thank you! One tiny suggestion, to add the |
I @remcom, I think I've never tested with an IP as endpoint so that could be the issue (and, in that case, also a bug). But currently I cannot do any test. Could you test with a hostname? Or, could anyone else here test with IP? I'll test myself as soon as I can.
The entry |
@droscy I tried this morning with a hostname and had the same results. Does "handshake timestamp not available" mean something specific? Or is it just a message that the vpn server isn't available? |
Could you please enable debug logs and post here the output for wireguard component?
It simply means that no handshake has ever succeded, otherwise it reports the timestamp of the latest handshake. |
It loops the following data:
|
Please, post every log related to wireguard, not only the last repeated lines. I need to track any step from config lines till the loop. Thanks |
There is not a lot more: 21:26:50 | [V] | [wireguard:290] | wdt resumed |
You omitted many lines (including config log lines), I need them all in order to help you. If you don't want to paste everything here send them directly to me, just hide endpoint IP and port (keys are already partly masked). I suspect misconfiguration or firewall issue.
|
@droscy I found the issue. A restart of the dreammachine resolved the issue. So it probably was router/vpn-server related. Thnx for your time and making this integration possible |
Hi, Thanks for the great work, this looks like a very very promising feature for remote i/o. I'm trying to get this up and running, and thanks to your hard work it was very easy up to this point. The API does not seem to be accepting connections on the wireguard IP. And, also, the node does not connect to my MQTT server. I've followed the configuration from the latest comment #1444 (comment). The esp is connected to a remote wifi network, and I have homeassistant (hassio) on a local network with the wireguard addon. Things I know:
So there are two things I don't understand:
[EDIT]:
|
Hi @victorclaessen could you please post your full configuration and the config log output? Hide sensitive data. If you want to hide your IPs please change them to be consistent, do not mix them or use always x.y.z.w.
6053 is closed or unreachable? I mean, the connection timeouts if you test with telnet?
Are you receiving a timeout?
This should be a timeout from mqtt client. |
I am closing this as esphome/esphome#4256 has been merged and will be in the next release. |
Describe the problem you have/What new integration you would like
Please help me adding support for WireGuard to ESPHome on ESP32 boards.
WireGuard is an extremely simple yet fast and modern VP.
There already seems to be an Arduino library in Platformio for the ESP32.
Please describe your use case for this integration and alternatives you've tried:
I need to have a bidirectional, secure channel between multiple ESPHome/ESP32s at multiple locations and some remote backend server.
From these backend servers I want to be able to push e.g. OTA updates centrally to many different NATed locations (where a site2site VPN is not an option).
Also I'd like to reach all those different locations from one central HomeAssistant instance.
On the ESP side, only traffic to a specific remote subnet (the backend) needs be routed through Wireguard, all remaining network traffic should use the default gateway.
AFAIK there are no VPN alternatives available for ESPhome yet.
Additional context
Basically this is all about being able to directly reach (on IP level) multiple ESPHome boards at different locations/networks behind their NAT routers from some central place / VPN server / backend.
The text was updated successfully, but these errors were encountered: