Nabto Edge Service Invocation Example

This quick start guide shows how to setup a ready-made Nabto Edge device to invoke a webservice through the Nabto Edge Basestation.

This example requires a webservice that the Nabto Basestation can invoke on behalf of the device. For quick testing and prototyping, you can use webhook.site - no signup required. The site generates a unique URL for you - this will be needed later.

The webservice should respond with a properly formatted JSON object, such as:

{"message": "aGVsbG8td29ybGQ="}

If you use webhook.site, press Edit, set the Content Type to application/json, and set the Response Body to the document above. The Service Invocation intro describes ways to format the response message.

The Default status code can have any valid HTTP status code.

Nabto Cloud Configuration

To use any Nabto Edge example, you must have an account on the Nabto Cloud Console with a Product and a Device configured as described in this guide.

Additionally, this example requires a Service assosiated with the Product.

In the Nabto Cloud Console, navigate to the Services page and create a new Service. On the created Service, put the webhook.site URL as the HTTP URL and save the Service. The service ID will be needed later. Add the service to your product by picking your product in the drop down, and clicking “Add to product”.

Embedded Device Application

Follow the general build instructions on the Embedded SDK intro page to build the simple_service_invocation_device application.

To run the application, use the Product ID, Device ID, and Service ID configured above and execute the following command:

$./bin/simple_service_invocation <PRODUCT ID> <DEVICE ID> <SERVICE ID> hello-world
Nabto Embedded SDK Version v5.7.1
Device: pr-abcdefg.de-hijklmno with fingerprint: [73e53042551c128a492cfd910b9ba67fffd2cab6c023b50c10992289f4c23d54]
2022-02-07 07:52:58.091 ...sdk/src/core/nc_device.c(361)[_INFO] Starting Nabto Device
2022-02-07 07:52:58.305 ...k/src/core/nc_attacher.c(736)[_INFO] Device attached to basestation
Attached to the basestation
Invoking the service se-pqrstuvx
Service invocation ok. StatusCode: 200, MessageLength: 11, Message hello-world

The output public key fingerprint (73e53...d54) must be set through the Nabto Cloud Console: Go to the device configuration page - first click the product, then click the device in question.

Beyond examples

To start integrating Nabto Service Invocation in an embedded device, the source code for the example above is available at the Nabto Embedded SDK repository. For details on the Nabto Embedded SDK service invocation functions see the API reference.

For details on the requirements for the webservice, and a general overview of the system, check out the Nabto Edge Service Invocation section.