O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Device ID

The Internet contains a huge number of devices. To be able to distinguish our device from the rest, we must make sure to create a persistent Device ID for it, and make sure it's unique:

private string deviceId;

After having started the Arduino initiation, we need to check whether we have a deviceId created. We use our runtime settings library for this:

this.deviceId = await RuntimeSettings.GetAsync( 
   "DeviceId", string.Empty); 

If you haven't created one yet, let's do so. A simple way to generate a globally unique deviceId is to create a Guid. We also remove any hyphens:

if (string.IsNullOrEmpty(this.deviceId)) { this.deviceId = Guid.NewGuid().ToString(). Replace("-", string.Empty); await RuntimeSettings.SetAsync("DeviceId", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required