Tunneling Mozilla WebThings Gateway through NKN client

Mozilla webthings banner

NKN client can be used to transparently tunnel any TCP based application in a purely decentralized way, and the application itself does not need any modification. Such tunnel does not require any side to have public IP address or port forwarding, and no centralized server is needed at all. Below is an instruction for Mozilla WebThings Gateway.

Both the client (user) and server (gateway) side needs to run nkn-tunnel. On the gateway device (or any device in the same local network), we start nkn-tunnel in server mode:

./nkn-tunnel -from nkn -to 127.0.0.1:8080 -s <seed>

Where 127.0.0.1:8080 is the WebThings Gateway web server address, and <seed> is the secret seed (similar to private key) used to create NKN client. The seed should be a 64-char hex string. If seed is omitted, a random seed will be used.

After nkn-tunnel is started, it will print out the listening address:

Listening at <server-listening-address>

where <server-listening-address> is the NKN address of the tunnel.

Then on the user side, we start nkn-tunnel in client mode:

./nkn-tunnel -from 127.0.0.1:8081 -to <server-listening-address>

Now user can access the gateway interface by visiting http://127.0.0.1:8081

Embed nkn-tunnel in iOS/Android application

nkn-tunnel is written in Go and can be compiled to a native iOS/Android library using Go mobile.

Below is a simple iOS application that use nkn-tunnel + WebView as a minimal WebThings Gateway mobile client.

ezgif-7-471decb53bfc

Using NKN client as p2p communication layer

nkn-tunnel is the easiest way to integrate with existing application, but might not be the most friendly way to users because it requires client side to run nkn-tunnel also. If you are able and willing to modify the server side application, you can use NKN client as the p2p communication layer and integrate NKN client to both the client and server side of your application. NKN client is currently available in Go, JavaScript, Java.

About Mozilla WebThings

The Web of Things connects real-world objects to the World Wide Web.

The idea of the Web of Things is to create a decentralized Internet of Things by giving things URLs on the web to make them linkable and discoverable, and defining a standard data model and APIs to make them interoperable.

Mozilla WebThings is Mozilla’s open source implementation of the Web of Things, including the WebThings Gateway and the WebThings framework. For more information please check out:

3 Likes

Since Mozilla plans to decommission the tunneling service for WebThings Gateways, and the project will soon be independently run by the community (at a new url, webthings.io), this will be a nice alternative for remote access to a home gateway. Would be nice to see the NKN installation process implemented as an add-on, with the seed as a configuration variable or automatically generated one. I will ask a community add-on expert if it is something that he could implement. Might even be worth creating a separate mobile app for remote gateway access.

Great idea! I just tried the 1.0.0 version of webthings gateway, and did not get the my-gw.webthings.io working. So the new tunneling service might be still in the works.

We can definitely help with NKN’s nConnect solution, which is tested and working for such secure remote access. And even better, it will not expose your webthings gateway to anyone else other than you since there will be no public DDNS name for your gateway.

If you can help us, we can reach out to the right engineers and community forums for webthings gateway.

1 Like