Skip to main content

Husarnet library API

Husarnet Library API

Husarnet on ESP32 (similar to non-embedded platforms) runs in the background and creates a virtual network interface on the LwIP layer.

C++ API

C++ API consists of a simple wrapper class HusarnetClient that provides an interface for joining Husarnet network and performing basic operations on the Husarnet network.

class HusarnetClient {
// Joins Husarnet network with given hostname and join code.
// Network communication is available after a successful join.
void join(const char* hostname, const char* joinCode);

// Sets the FQDN of the Husarnet Dashboard. Used for the self-hosted setup.
void setDashboardFqdn(const char* fqdn);

// Returns a list of peers connected to the device in Husarnet network.
std::vector<HusarnetPeer> listPeers();

// Returns true if the device is connected to Husarnet network.
bool isJoined();

// Returns the IP address of the device in Husarnet network.
std::string getIpAddress();

// Returns the internal HusarnetManager instance for advanced usage.
HusarnetManager* getManager();
};

C API

C API wraps around the C++ API and exposes the same functionality. husarnet_init() function creates a new Husarnet client instance, which can be used to join the Husarnet network and perform basic operations.

HusarnetClient* husarnet_init();
void husarnet_join(HusarnetClient* client, const char* hostname, const char* joinCode);
void husarnet_set_dashboard_fqdn(HusarnetClient* client, const char* fqdn);
uint8_t husarnet_is_joined(HusarnetClient* client);
uint8_t husarnet_get_ip_address(HusarnetClient* client, char* ip, size_t size);