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

1 Like

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

Hi, I know it’s too late
But I have a question
Do you know the reason for working the code well?
Is it possible to access WEBUI of Husarnet with the ESPAsyncWebServer library at all?

Hi, yes, it is possible: https://github.com/husarnet/esp32-internet-ota :slight_smile: . Details of this project are presented in this blog post

AsyncTCP and ESPAsyncWebServer are great projects, and yes - they work with Husarnet as well :slight_smile:

I have even a few more examples using that library on my GitHub profile, like:

Best,
Dominik

Hello Domink
Thanks for your quick reply.
I have problems to run this code.
what does these lines of code means?
extern const char index_html_start asm(“_binary_src_index_html_start”);
const String index_html = String((const char*)index_html_start);

can you explain above lines?
I get compiling error in here.

Hi, the project is made for VSC + platformio, not for Arduino IDE.

String((const char*)index_html_start); will not work in Arduino IDE, because this part is handled by platformio. This is very handy feature to deal with HTML files in embedded projects.

Best,
Dominik

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.