IPAddress local_ip(100.64.75.173); // [Interface] VPN Address
char private_key[] = "8CRo9QpWNsdQoMjFtrKVPqP72ULvHJK32YpmcP5Tr1U="; // [Interface] PrivateKey of esp
char public_key[] = "oeqDhAeoxw1g/6cKq/fo4ubgssbwhO3K2Nkmn6JVhg8="; // [Peer] PublicKey of peer
char endpoint_address[] = "man-126-wg.whiskergalaxy.com"; // [Peer] Endpoint
int endpoint_port = 443; // [Peer] Endpoint
static WireGuard wg;
static const inline void beginWireGuard(){
// Must set the correct time
configTime(9 * 60 * 60, 0, "ntp.jst.mfeed.ad.jp", "ntp.nict.jp", "time.google.com");
wg.begin(
local_ip, // IP address of the local interface
private_key, // Private key of the local interface
endpoint_address, // Address of the endpoint peer.
public_key, // Public key of the endpoint peer.
endpoint_port); // Port pf the endpoint peer.
}
Something like this should work. There are comments after the variables.
You should call beginWireGuard();
after you connected to a wifi network.
Something like this:
#include "WiFi.h"
const char* ssid = "yourNetworkName";
const char* password = "yourNetworkPass";
IPAddress local_ip(100.64.75.173); // [Interface] VPN Address
char private_key[] = "8CRo9QpWNsdQoMjFtrKVPqP72ULvHJK32YpmcP5Tr1U="; // [Interface] PrivateKey of esp
char public_key[] = "oeqDhAeoxw1g/6cKq/fo4ubgssbwhO3K2Nkmn6JVhg8="; // [Peer] PublicKey of peer
char endpoint_address[] = "man-126-wg.whiskergalaxy.com"; // [Peer] Endpoint
int endpoint_port = 443; // [Peer] Endpoint
static WireGuard wg;
static const inline void beginWireGuard(){
// Must set the correct time
configTime(9 * 60 * 60, 0, "ntp.jst.mfeed.ad.jp", "ntp.nict.jp", "time.google.com");
wg.begin(
local_ip, // IP address of the local interface
private_key, // Private key of the local interface
endpoint_address, // Address of the endpoint peer.
public_key, // Public key of the endpoint peer.
endpoint_port); // Port pf the endpoint peer.
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
beginWireGuard();
}
void loop() {}