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", this.deviceId); 
} 

Log the deviceId to the log. This will allow us to see it in the user interface:

Log.Informational("Device ID: " + this.deviceId); 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset