Example Embedded Applications
All examples prefixed with
simple_ are minimal examples of the specific subject, omitting all access control and other complexities. For a thorough example demonstrating access control, see the thermostat example or the full Nabto Edge Tunnel app.
Corresponding example clients for all of the above examples are available in the nabto-client-sdk-examples github repo. The embedded tunnel application can be used with the Nabto Edge Tunnel CLI client tool.
Configuration of Example Projects
To allow remote access, all examples need configuration through the Nabto Cloud Console where you must sign up for a free account (no credit card required). The configuration of a device through the console is simple - you just need to obtain two ids (device and product ids) and set a value (public key fingerprint).
The configuration process is outlined below with screenshots for the “Hello, World” example. It is the same process for all examples - all devices just need this simple configuration for remote access, regardless of the use case: The actual application is only running on the client and device - so from a Nabto Basestation configuration point of view, they are all similar.
If you just want to test local only access to your example from a client application, you do not need to do any configuration at all through the Nabto Cloud Console, it will just work without further ado.
Hello, World! CoAP Service
This example is a simple Hello, World! style Nabto Edge Embedded SDK application. It is located in examples/simple_coap in the SDK repo. The other
simple_ examples are built an run in a similar way.
The application is a simple CoAP service, that
GET request at the path
/hello-world. It replies with a string payload that says
“Hello, world!” back to the client.
The unique device configuration values are supplied on the command line. Obtain these from the Nabto Cloud Console - start by signing up for a free developer account if not already done.
If you have not yet created an organization and an initial product and device, just follow the “Get started” wizard:
After completing the wizard, you have an organization, a product and a device. Your “Products” page will then look something as follows - click the “devices” link:
On the devices page click on an available device, ie one with no fingerprint set yet (you will have one such device after following the wizard):
For now note the product id (
pr-v3hg947i in the screenshots) and device id (
de-ukmuqfkq). The two ids have been shown in several places on your way here - on this page they may be handy to copy from the text on the right:
Remember that the
de- prefixes are parts of the ids and must be included!
Keep this page in your browser as you will return shortly to register the device’s generated public key fingerprint.
Building and running
Follow the general build instructions on the Embedded SDK intro page to build the Hello, World CoAP service.
Run the embedded application where you specify the two ids noted above from the console:
$ ./examples/simple_coap/simple_coap_device pr-v3hg947i de-ukmuqfkq
When the device starts, it generates a unique private key and tries to register with the Nabto basestation using this. This will initially fail as the corresponding public key is not yet registered:
$ ./examples/simple_coap/simple_coap_device pr-v3hg947i de-ukmuqfkq Nabto Embedded SDK Version 0.0.0-branch.master.commits.2539+201f1e87 Nabto Embedded SDK Version 0.0.0-branch.master.commits.2539+201f1e87 Device: pr-v3hg947i.de-ukmuqfkq with fingerprint: [83a6cb6803ad7c812e962c1acc35f9985dd800b8d559aea8b7766b4a94696a45] 2023-01-08 14:56:34.712 ...emb/src/core/nc_device.c(391)[_INFO] Starting Nabto Device 2023-01-08 14:56:35.049 ..._attacher_attach_start.c(102)[ERROR] The server does not recognize the fingerprint of the device. Check that the fingerprint is in sync with the server The device fingerprint is not known by the basestation
Just leave the device running, it will work in a moment after the last configuration step is done:
The final configuration step is to register the device’s fingerprint through the Nabto Cloud Console. The public key fingerprint is the long string output in the 4th line of the above console output (
83a6...a45), just copy this and paste it into the fingerprint field in the Nabto Cloud console:
When the fingerprint is saved, the device comes online:
$ ./examples/simple_coap/simple_coap_device pr-v3hg947i de-ukmuqfkq Nabto Embedded SDK Version 0.0.0-branch.master.commits.2539+201f1e87 Nabto Embedded SDK Version 0.0.0-branch.master.commits.2539+201f1e87 Device: pr-v3hg947i.de-ukmuqfkq with fingerprint: [83a6cb6803ad7c812e962c1acc35f9985dd800b8d559aea8b7766b4a94696a45] 2023-01-08 14:56:34.712 ...emb/src/core/nc_device.c(391)[_INFO] Starting Nabto Device 2023-01-08 14:56:35.049 ..._attacher_attach_start.c(102)[ERROR] The server does not recognize the fingerprint of the device. Check that the fingerprint is in sync with the server The device fingerprint is not known by the basestation 2023-01-08 14:56:57.854 ...b/src/core/nc_attacher.c(747)[_INFO] Device attached to basestation Attached to the basestation
Now the device is “Attached” - this means it is registered with the Nabto basestation and ready to be invoked from a remote client!
Invoking CoAP service from a Nabto Edge client
To invoke the simple “Hello, World!” CoAP service, use the corresponding CoAP commandline client.
Invoke the client as follows:
./simple_coap_client -p pr-v3hg947i -d de-ukmuqfkq -r /hello-world --force-remote Nabto Client SDK Version: 5.12.0 connecting to pr-v3hg947i.de-ukmuqfkq Connected to device with fingerprint: 83a6cb6803ad7c812e962c1acc35f998 Received CoAP get response data: Hello world
--force-remote option makes sure you test connecting using P2P (or relay) mediated by the Nabto basestation instead of using a local connection to the device. You could invoke the target device locally even if it was not correctly configured through the Nabto Cloud Console.
For more information about connecting and invoking devices, read the client development introduction.