ESPAsyncWebServer + Husarnet

Hi.

I’m trying to use ESPAsyncWebServer library using this simple web server example.

This is the resulting code:

#include "Arduino.h"
#include <WiFi.h>
#include <Husarnet.h>
//#include <WebServer.h>
#include "AsyncTCP.h"
#include "ESPAsyncWebServer.h"

// WiFi credentials
const char* ssid     = "------";
const char* password = "----------------";

// Husarnet credentials
const char* hostName = "----------------";
const char* husarnetJoinCode = "------------------------------";
const char* dashboardURL = "default";

// Setup http server
AsyncWebServer server(8000);



void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi
  Serial.printf("Connecting to %s", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.printf("done!\r\nLocal IP: %s\r\n", WiFi.localIP().toString().c_str());

  // Start Husarnet
  Husarnet.selfHostedSetup(dashboardURL);
  Husarnet.join(husarnetJoinCode, hostName);
  Husarnet.start();

  // Configure http server
server.on("/index.html", HTTP_GET, [] (AsyncWebServerRequest * request) {
    AsyncWebServerResponse *response = request->beginResponse(200, "text/html", "<html><head></head><body>Hello World!</body></html>");
    request->send(response);
  });

  server.begin();
}

void loop() {
}

app.husarnet.com shows the connected device and all its parameters:
name - status - address - info
but never shows an available web server under “info” column

The code works well when accessing inside the local network: 192.168.1.X:8000 but not when using https://-----------------------------------------------8000.husarnetusers.com/index.html
Firefox allways shows: 502 Bad Gateway

Today, it works and i don’t know why

Hi, basically https://................../husarnetuser.com/index.html is not the perfect way of accessing a web user interface of your ESP32 board. In this case you don’t use peer-to-peer to access you ESP32 but a proxy server instead.

The better way is to connect ESP32 and your laptop to the same Husarnet network.

If you do so, you ESP32 web UI will be available from a level of your web browser under the hostname or Husarnet IPv6 address of your ESP32 board, eg. :

http://my-esp32-hostname:8000 (in firefox)

of

http://[fc94:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:d395]:8000

You will have a peer-to-peer connection with no proxy server in between.

Best,
Dominik