Skip to main content

Husarnet Library for ESP32

The Husarnet embedded library is currently available only for ESP32 Wi-Fi microcontrollers. It allows a peer-to-peer connection of your ESP32 devices with other hosts running the Husarnet Client app.

Husarnet Library API

Husarnet on ESP32 (similar to no-embedded hosts) runs in the background and creates a virtual network interface on the Lwip layer. This is why there are only a few C++ methods:

Husarnet.h
#ifndef Husarnet_h
#define Husarnet_h

#include "Arduino.h"
#include "HusarnetServer.h"
#include "IPv6Address.h"
#include "WString.h"
#include <vector>
#include <utility>
#include <string>

struct _Husarnet
{
// Sets up Husarnet to use self-hosted base server
void selfHostedSetup(const char *hostname);

// Starts the Husarnet
void start();

// Provides join code. Use before Husarnet.start().
void join(const char *joinCode, const char *hostname = "");

// Get list of peers' hostnames and addresses
std::vector<std::pair<IPv6Address, String>> listPeers();

// Get hostname you're currently known at
String getHostname();
};

extern _Husarnet Husarnet;

#endif

For writing a UDP/TCP client or server code, use regular libraries for ESP32.

warning

The current version of Husarnet for ESP32 works with a forked version of Arduino Core for ESP32. There are some modifications related to IPv6 support.

Also to work with some networking libraries, like AsyncTCP, an IPv6 related customization is needed. If you need AsyncTCP in your project use our fork

A project template

The Husarnet API for ESP32 is very short and self-describing, however to work in Husarnet you need to use a forked version of Arduino Core.

To make the environment configuration as straightforward as possible we recommend using Husarnet with PlatformIO.

The fastest way to start is making a new project based on this GitHub template.