Usage Guideline + Authenticati...
DeviceHub
20min
the devicehub module covers all functionality related to the devicehub service in litmus edge it is divided into 5 sub modules asset discovery automatic devicehub asset discovery devices create, update, delete, and list operations on devices drivers listing of drivers and driver properties general general information of the devicehub service, also directly accessible under the devicehub module tags create, update, delete, and list operations on tags important before using devices or tags modules run generate driver templates in your command line to generate templates used during validation general dashboard prometheus metrics return unformatted string of prometheus metric information version return dictionary of devicehub version and git commit id schema introspection return gql schema of devicehub endpoint entries many of the operations in the devicehub service require a key value pair object represented by an entry object these can be created directly or via python dict objects manually creating entry from litmussdk devicehub import general plant location = general entry(name="plant", value="toronto") line num = general entry(name="line", value=3) creating entry list from dictionary from litmussdk devicehub import general metadata = { "plant" "toronto", "line" 3, } metadata entries = general create entry list(metadata) devices device model most operations in the devices module use the device object as an abstraction of device instances in litmus edge it is a self validating pydantic model with the following fields id optional\[str] when specified represents a real device instance in litmus edge should never be set manually by the user will be set by create/list operations name str display name of device driver id str id of corresponding driver of the device drivers will be used to validate the properties of the device description optional\[str] description of the device metadata list\[general entry] meta data of the device as key value pairs properties list\[general entry] properties of the device as key value pairs supported and required properties will depend on the underlying driver ( driver properties to see properties) dh params list\[general entry] devicehub specific parameters worker params list\[general entry] devicehub worker specific parameters alias topics boolean whether to enable alias topics for this device debug boolean whether to enable debug for this device functions list devices get a list of all devices in edge as a list of device objects list device by id get a device object with id if one exists create device takes a device object with no id and creates it in litmus edge, returning a device object with an id update device takes a device object with a set id and updates corresponding device in litmus edge with the properties will fail if not device with matching id exists start devices takes a list of device object with ids and starts all corresponding devices in litmus edge will fail if any of the devices are already running stop device takes a list of device objects with ids and stops all corresponding devices in litmus edge will fail if any of the devices are already stopped delete devices takes a list of device objects with ids and deletes the corresponding devices in litmus edge delete device takes a device object with an id and deletes the corresponding device in litmus edge drivers each device instance has a corresponding driver which are represented by the driver object in the sdk because drivers deviate between versions, run generate driver templates in your command line to load drivers supported by your edge instance once the sdk is installed and configured driver a driver object has the following properties name str name of the driver (e g siemens s7) id str id of the driver, used to specify drivers of devices properties list\[property] supported properties of the driver supported registers list\[supportedregister] registers/tags of the driver and the following methods get register gets a register by name if it exists get property gets a property by name if it exists validate properties takes a dictionary of property names and values and returns an error if fails to validate get default properties get a list of default property values for generating device with this driver the driver module also gives the function list all drivers() returns a list of all supported drivers in the edge device property all drivers and registers have properties which are configuration parameters (e g ip address, tls enabled, etc ) this is represented by a property object with the following properties name str name of the property description str description of the property string format str required format of a string property default value any default value of the property if not specified num min int inclusive minimum of numeric fields num max int inclusive maximum of numeric fields required bool whether the property is required list values list\[any] enum values of field if set linked fields list\[linkedfield] preconditions for being required users should not interact with properties directly, they are self validating in drivers and registers properties are set with a list of general entry objects supported registers represent the supported register/tags for drivers have the following fields properties list\[property] supported properties for the register name str name of the register description str description of register read only bool whether this tag is read only or write enabled and the following methods get property gets a property by name if it exists validate properties takes a dictionary of property names and values and returns an error if fails to validate get default properties get a list of default property values for generating tag with this register driver templates generate via generate driver templates , this is a module accessible from litmussdk devicehub drivers driver templates drivers are accessible as objects, e g driver templates siemens s7 tags tag model like devices, most tag functions use a pydantic model abstraction it has the following fields id optional\[str] when specified indicates a particular tag in litmus edge device str either a device id or device object with a non none id specifies the device this is a tag of name str specifies tag type tag name str display name of register description str description of tag value type str value type of tag, e g int16 properties list\[entry] key value pairs of property values topics list\[topic] topics where data is published or written to for this tag publish cov bool whether this tag only publishes on change of value metadata list\[entry] optional key value metadata value tag formula str optional formula for tag values topic model a topic is an i/o address for tag values it has the following fields direction str either input or output encoding str encoding format for values format str expected format of string values interval ms int tick interval in milliseconds topic str topic name functions list all tags get all tags in an edge instance up to a maximum of 1000 list registers from single device get all tags for a specified device create tags create a list of tag objects and return tag objects with set ids update tags update a tag object with a set id delete tag delete a specified tag delete tags delete a list of tags tag status get the status for a list of tags for a particular device (e g status 'ok') download csv download a csv file of all tags for a set device browse tags browse tags for device which supports it upload csv upload a csv file of tags to a device, creating or updating tags as neccessary asset discovery devicehub network interfaces list network interfaces configured for the devicehub service (e g 'eth0') assets on network get a list of assets on the network scan for devices on eth get cip scan result scan nd nodes get nd nodes if they exist enable disable device discovery enable or disable device discovery service examples for more thorough examples see the examples directory in the repo listing all devices and tags from litmussdk devicehub import devices, tags ds = devices list devices() ts = \[] for dev in devs ts extend(tags list registers from single device(dev)) creating default device from driver template first, generate the driver templates in your command line with generate driver templates this only needs to be once for any installation from litmussdk devicehub import drivers, devices simulator driver = drivers driver templates simulator gen1 my device = devices device( name="my device", driverid=simulator driver id, properties=simulator driver get default properties() ) my device = devices create device(my device)