This example shows how to use the 51Degrees Cloud service to lookup
the details of a device based on a given 'TAC'.
More background information on TACs can be found through various online
sources such as Wikipedia.
This example requires a subscription to 51Degrees Device Data, a subscription can be acquired from the 51Degrees pricing page.
Make sure to include the Profiles, HardwareVendor and HardwareModel properties as they are used by this example.
const pipelineCore = require('fiftyone.pipeline.core');
const CloudRequestEngine =
require('fiftyone.pipeline.cloudrequestengine').CloudRequestEngine;
require((process.env.directory || __dirname) +
'/../../hardwareProfileCloudEngine');
let localResourceKey = process.env.RESOURCE_KEY || "!!YOUR_RESOURCE_KEY!!";
let localLicenseKey = "!!YOUR_LICENSE_KEY!!";
if (localResourceKey === "!!YOUR_RESOURCE_KEY!!" ||
localLicenseKey === "!!YOUR_LICENSE_KEY!!") {
console.log('You need to create a resource key at ' +
'https://configure.51degrees.com and paste it into the code, ' +
'replacing !!YOUR_RESOURCE_KEY!!.');
console.log('You also need a subscription which can be acquired ' +
'from https://51degrees.com/pricing. Paste the license key into the ' +
'code, replacing !!YOUR_LICENSE_KEY!!.');
console.log('Make sure to include the Profiles, HardwareVendor, ' +
'HardwareName and HardwareModel properties as they are used by this ' +
'example.');
} else {
console.log(`This example shows the details of devices associated with a given 'Type Allocation Code' or 'TAC'.
More background information on TACs can be found through various online sources such as Wikipedia: https:
----------------------------------------`);
const requestEngineInstance = new CloudRequestEngine({
resourceKey: localResourceKey,
licenseKey: localLicenseKey
});
const pipelineBuilder = pipelineCore.PipelineBuilder;
const pipeline = new pipelineBuilder()
.add(requestEngineInstance)
.add(hardwareProfileCloudEngineInstance)
.build();
pipeline.on('error', console.error);
const outputDetails = async function (tac) {
let message = `Which devices are associated with the TAC '${tac}'?`;
const flowData = pipeline.createFlowData();
flowData.evidence.add('query.tac', tac);
await flowData.process();
flowData.hardware.profiles.forEach(profile => {
const hardwareVendor = profile.hardwarevendor;
const hardwareName = profile.hardwarename;
const hardwareModel = profile.hardwaremodel;
if (hardwareVendor.hasValue &&
hardwareName.hasValue &&
hardwareModel.hasValue) {
message += `\r\n\t${hardwareVendor.value} ${hardwareName.value.join(',')} (${hardwareModel.value})`;
} else {
message += `\r\n\t${hardwareVendor.noValueMessage}`;
}
});
console.log(message);
};
const tac1 = '35925406';
const tac2 = '86386802';
outputDetails(tac1);
outputDetails(tac2);
}