node package manager


Cordova Plugin Nabto - 2.0

Nabto ApS client plugin for Cordova.

Nabto provides a full communication infrastructure to allow direct, encrypted communication between clients and IoT devices - the Nabto communication platform. The platform supports direct peer-to-peer connectivity through NAT traversal with fallback through central relay.

The Cordova plugin allows hybrid client apps to use Nabto RPC to invoke uNabto devices, i.e. to retrieve data or control the device.

For an example of such a hybrid app, see Ionic Starter for Nabto / AppMyProduct.


  1. Download Nabto libraries and assets to cordova-plugin-nabto/src/nabto/ (See "Source File Structure" section). This step can be skipped if installing directly from npm.
  2. Install cordova plugin: cordova plugin add cordova-plugin-nabto.
  3. For iOS projects replace linker flag -ObjC with -force_load $(BUILT_PRODUCTS_DIR)/libCordova.a -lstdc++ (in platforms/ios/cordova/build.xcconfig)
  4. Start using as described in the Example and API section.


A simple example using the Cordova Nabto plugin:

// Wait for cordova to fully load 
document.addEventListener('deviceready', function() {
  // Start Nabto and login as guest 
  nabto.startupAndOpenProfile(function() {
    // set the device interface definition to use 
    nabto.rpcSetDefaultInterface("<unabto_queries><query name='my_wind_speed.json' id='2'><request></request><response format='json'><parameter name='speed' type='uint32'/></response></query></unabto_queries>", function() {
      // prepare invocation - note: may show a full screen ad if device is associated a free tier AMP product 
      nabto.prepareInvoke([''], function() {
        // invoke a function on the device 
        nabto.rpcInvoke('nabto://', function(error, result) {
          if (error) {
          } else {
            if (result.response) {
}, false);

Nabto API

See www/nabto.js for API implementation details.

All callbacks are invoked with an error object as the first argument if something went wrong, otherwise the first argument is set to undefined.


Start Nabto and open a session with optional username and password.

nabto.startup([username, password, ]callback)


Shuts down Nabto.



Makes a Nabto RPC request to a uNabto device:

nabto.invokeRpc(url, callback)

For example:

nabto.invokeRpc('nabto://', function(err, res) {

Prior to invoking, the following must have been done (after startup):

  • RPC interface must have been set with nabto.rpcSetInterface(host, unabto_queries_xml) or nabto.rpcSetDefaultInterface(unabto_queries_xml). The interface file is the file formerly distributed centrally through HTML DD bundles in the nabto subdir.
  • The function nabto.prepareInvoke(hosts) where hosts is an array of hostnames.

nabto.invokeRpc() is equivalent to nabto.fetchUrl() on JSON URLs in earlier versions of the SDK; devices invoked earlier with nabto.fetchUrl() can be invoked in exactly the same way and the resulting response objects are identical. It is only a matter of simpler management, cf. the description above.


Set Nabto RPC interface for specific host. See section 6.2 in TEN024 for format (note that the key HTML DD concept in that document is deprecated, the mentioned section will soon be available in a new location).

nabto.rpcSetInterface(host, unabto_queries_xml, callback)


Set default Nabto RPC interface to use if not overriden with host specific version (rpcSetInterface). See section 6.2 in TEN024 for format (note that the key HTML DD concept in that document is deprecated, the mentioned section will soon be available in a new location).

nabto.rpcSetDefaultInterface(host, unabto_queries_xml, callback)


Mandatory to invoke prior to nabto.invokeRpc after each nabto.startup invocation. This function may show a fullscreen ad if hosts contains a device associated with an AMP free tier product. An ad may also be shown if a previous invocation since last nabto.startup contained such free tier device.

nabto.prepareInvoke(hosts, callback)


Get local Nabto devices. Callback is invoked with an array of device strings.



Get Nabto client version. Callback is invoked with a string.



Create selfsigned keypair to be used for RSA fingerprint based authentication in uNabto devices.

nabto.createKeyPair(name, private_key_encryption_password, callback)


Get RSA fingerprint for public key in specified keypair.

nabto.getFingerprint(name, callback)

Source File Structure

Install from npm to get all necessary libraries and resources installed in the right location.

├── android
│   └── *
├── ios
│   └── *
└── nabto
    └── ios
        ├── include
        │   └── nabto_client_api.h
        ├── lib
        │   ├── libnabto_client_api_static.a
        │   └── libnabto_static_external.a
        └── share
            └── nabto
                ├── configuration
                ├── roots
                ├── schemas
                ├── skins
                └── users

Run Tests

  1. Create a new Cordova project and install cordova-plugin-nabto as described above
  2. Also install the /tests subproject (cordova plugin add
  3. Install the Cordova test framework plugin: cordova plugin add
  4. Install the Cordova device plugin: cordova plugin add cordova-plugin-device
  5. Add <content src="cdvtests/index.html" /> to the projects config.xml
  6. Run on the platform you wish to test