Programming device store
Neuko provides an abstract class of DeviceIdentifierStore to make it flexible for developer to choose on how some parameters is generated.
DeviceIdentifierStore is a class that defines on how the Neuko SDK module retrieves the following parameters:
- Account identifier (account_id)
- Project identifier (project_id)
- Telemetry state schema identifier (schema_id)
- Device unique identifier (device_id)
Device identifier
The first 3 identifiers can be retrieve from this procedure and hardcoded into the extension of the DeviceIdentifierStore class.
However device_id may need a generic method to retrieve it from the device. As an example to illustrate this, let’s use OS native UUID/GUID to act as the device identifier.
import { DeviceIdentifierStore } from "@neukolabs/device-sdk-js"; // the following package is for example import { machineIdSync } from "node-machine-id"; class deviceIdentifier extends DeviceIdentifierStore { constructor() { super(); } public getAccountId(): string { return "acc_someid"; } public getProjectId(): string { return "prj_someid"; } public getDeviceSchemaId(): string { return "sch_someid"; } /* The usage of machine ID is an example to retrieve a UUID from machine */ public getDeviceId(): string { return machineIdSync(); } }
from neuko.device.identifierStore import DeviceIdentifierStore class EdgeGatewayDeviceIdentifierStore(DeviceIdentifierStore): def getAccountId(self) -> str: return 'acc_someid' def getProjectId(self) -> str: return 'prj_someid' def getDeviceSchemaId(self) -> str: return 'sch_someid' def getDeviceId(self) -> str: serialNumber = subprocess.check_output(["cat", "/var/lib/dbus/machine-id"]).decode().strip() return serialNumber