In my last Blog, I was showing how we can process html forms with the Arduino TinyHttp library. In the examples we were embedding the html into the source code.

Sometimes however it is more convenient to store the html as files on a dedicated server: In the following examples we use Github for this.

Forwarding

In this example we just forward to an external URL.

static Url forward_url("https://pschatzmann.github.io/TinyHttp/app/webservice-example.html");
server.on("/",GET, forward_url);

This external html page contains logical names (with the serive_url = ‘http://esp32-service/service’) to address the webervice.

Therefore we just needed to add some additional DNS logic into the sketch.

// register the service name
if (!MDNS.begin("esp32-service")) {
    Serial.println("Could not set up DNS");
    return; 
}

Github is using a https connection, but the webservice just uses http. This is insecure and we need to change the browser settings to allow this.

Tunnelling

In the next example we use tunnelling to an external URL: the forwarding is hidden to the end user.

// forward address
static HttpTunnel tunnel_url("https://pschatzmann.github.io/TinyHttp/app/webservice-example-local.html");
server.on("/",GET, tunnel_url);

This is a little bit less efficient then a simple forwarding, but it has the advantage that we do not have to worry about authentication or CORS, and the external html page can use local addressing (with the serive_url = ‘/service’) to specify the services!

Categories: Arduino

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *