A short tutorial on how a floating cloud license works, and how it can be incorporated into your C++ project.
Working with Custom Fields and Device Variables
Custom fields are a component of the LicenseSpring SDK that allow users to send data from LicenseSpring to your application at the license level. Device variables operate in the other direction, allowing the transfer of data back into the platform from the device level. In this tutorial, we will learn the basics of custom fields and device variables using the LicenseSpring SDK.
Follow the linked video for an overview on LicenseSpring’s Custom Fields and Device Variables:
This guide will walk you through implementing custom fields and device variables within the LicenseSpring SDK. By the end of this tutorial, you should understand how to send data from LicenseSpring to a device and from a device back to the platform. We will also examine useful scenarios for these tools, the interactions between local license files and custom fields, caching and sending device variables periodically, and device variable caveats when using offline licensing. We will create a basic program that lists current custom fields, creates device variables, and lists existing device variables. To see this C++ console program, click here.
In order to set up custom fields to follow this tutorial, follow the guide given at the link below:
In this tutorial, we will discuss:
- Useful Scenarios
- Local License Files and Custom Field Interactions
- Pushing Device Variables
- Caching/Sending Device Variables Periodically
- Accessing Device Variables within the Program
- Device Variables Caveats When Using Offline
Defining a License/Product type:
You can have a custom field, for multiple products, all with the same custom field key, but with different values to differentiate between products. Thus, you only require very minimal code changes between product types (product code + maybe key + user info depending on how it is implemented). Furthermore, if you ever decide to change the name of the product, it can be changed by simply creating a custom field for your product name, and updating it on the LicenseSpring platform.
You can create a Custom Field object where the key is ‘Notification’ and the value can be your notification message. Then, if you want to change your message, you can simply go into your product’s custom fields, find the key: ‘Notification’ and update the value with your new message. When the user updates their license (by performing an online license check), then the new notification message will be updated as well.
- Wanting to send/keep track of user registration data (name, user info) on the LicenseSpring platform using Device Variables
- Using the value of a custom field to configure the edition that should be available to the end-user without needing to distribute separate binaries. For example, a field called “LicenseType” could have a value of “lite”, “standard” or “pro”. A different edition of the application can be made available for the end user, depending on which value is used for the custom field for a given license.
Behavior of the Local License File with Custom Fields
A custom field is just a key-value pair. The local license will hold all the custom field data. You can access this data using:
When you activate your license (online or offline) and create a local license file, all the custom fields will be found on the local license file. However, since custom fields can be added, removed or updated after a license has already been issued and activated, the other way to update your local license file with any newly added, removed or updated custom fields is to perform an online check using:
Or, in the case of an offline license, use the offline refresh response file, see our Offline Tutorial for more information.
Creating and Pushing Device Variables to LicenseSpring
Device variables are a way to transfer data from the end-user’s machine, at the device level, to the LicenseSpring platform. We can send these key-value pairs to the LicenseSpring server, which will display our data. Unlike custom fields, any device variables present on the LicenseSpring server will not be transferred to your local license file when you run an online check or activate your license.
Note: To update a device variable, you can simply add the device variable with the same name, and it’s updated value.
Caching and Sending Device Variables Periodically
In the C++ SDK, it is possible to store device variables locally on the device's local license file. Since these device variables are not restricted to memory, they can be accessed at any time. So, to send device variables periodically, in your code, you just need to set up the code to send the device variables to the LicenseSpring server on some sort of interval.
Accessing Device Variables within the Program
The C++ SDK also has the capabilities to retrieve these device variables from within the program. As stated earlier, running online checks will not bring any device variables onto your local license file. You will need to use:
It is important to note that you can pull device variables from the LicenseSpring servers, or from your local license file. If these two files are out of sync, then you may need to pull device variables from both ends to get a full list.
If the device variable is on your local license file, you can retrieve it with the following:
Device Variable Caveats with Offline Licensing
For offline licensing, we can still add device variables, although they will require a bit more work. First, it is important to note that you can only add device variables after creating a local license on your device. That will require you to submit and obtain your offline activation request and response file respectively, see our Offline Tutorial for more details. As of August 12, 2022, offline deactivation will not upload your device variables to the LicenseSpring server, so it is recommended to save the device variables to your local license, and upload them when the device has access to the internet.
Note: As of August 15, 2022, offline deactivation for the C++ SDK ver. 7.17.0 will now transfer device variables back to the LicenseSpring servers upon uploading their deactivation request file.
You should now have a thorough understanding of what custom fields and device variables are. You should also have an idea of what they can be used for, and how they can be implemented into your projects.
Q: Does changing my custom fields on the platform change the values for all my license?
Yes and no. Custom fields are created on the product level. Here you can create key-value pairs. Every license you create under this product will share this same key and value when created. These key value pairs cannot be deleted on the license level, and the keys cannot be altered. The values however can be altered on the license level, changing this will not affect any other licenses issued under the same products. On the product level, you can also alter the custom fields. Adding, deleting, or changing a key will reflect on every license under this product. However, changing the value of a key-value pair has slightly different effects. If that value has been altered on the license level, then it will not be affected if altered on the product level. If that value has not been altered on a license, then that license will reflect whatever value changes are made on the product level.
Q: Are there any other ways to retrieve device variables outside of the C++ SDK?
Yes. You can retrieve device variables from the LicenseSpring backend by using our license API, which is documented here.