Skip to main content

Using Husarnet under Arduino IDE

info

Migration process from the legacy codebase has been completed 🎉 - the Husarnet library for ESP32 is now available as a proper standalone ESP-IDF component.

The Husarnet embedded library is available for all Espressif Wi-Fi microcontrollers. It allows for a tunneled (simmilar to a classic VPN) or a peer-to-peer connection between your ESP32 devices and other hosts running Husarnet.

Quickstart

info

Due to required upstream changes in the Arduino core the Husarnet library is only available for the ESP32 platform versions 3.0.3 and newer. Please make sure you're using a latest version of the ESP32 platform in your Arduino IDE or follow our guide in the FAQ section to update it.

Install the Husarnet library using the Library Manager. Select library icon from the sidebar, search for Husarnet and grab the latest version.

Arduino Library Manager

Select simple-webserver example from the File -> Examples menu. Scroll down to the Examples from custom libraries section and open it.

Set your Husarnet join code and Wi-Fi credentials by editing following lines in the simple-webserver.ino file:

// WiFi credentials
#define WIFI_SSID "wifi-network"
#define WIFI_PASS "wifi-password"

// Husarnet credentials
#define HOSTNAME "esp32-arduino-webserver"
#define JOIN_CODE "xxxxxxxxxxxxxxxxxxxx"

Join code is obtained from the dashboard. You can use the same code multiple times for different devices as long as you don't generate a new one in the dashboard. If you do all previous ones will be invalidated.

Finally, build and flash the project using the Upload button.

After a few seconds your first HTTP webserver on ESP32 should be available on every device in your Husarnet network under the provided hostname URL: http://esp32-arduino-webserver.

danger

URL used above won't work on Chrome and Chromium-based browsers as they ignore the hosts file. Husarnet uses it to allow resolution of device names to Husarnet IPv6 addresses. You will need to type the IPv6 address enclosed with square brackets directly in the browser (eg. http://[fc94:b01d:1803:8dd8:b293:5c7d:7639:932a]).

Under Firefox everything should work ok.

a simple webserver hosted by ESP32

info

API reference can be found here. In case of any issues, refer to the Husarnet ESP32 troubleshooting guide and the Husarnet Community Forum.