Help Center> Huawei HiLens> Developer Guide> Initialization> Initializing the HiLens Framework
Updated on 2022-02-22 GMT+08:00

Initializing the HiLens Framework

This API is used to initialize the HiLens Framework. Before calling other APIs of the HiLens Framework, you need to perform global initialization.

  • API calling

    hilens.init(verify)

  • Parameter description
    Table 1 Parameters

    Parameter

    Mandatory

    Type

    Description

    verify

    Yes

    Character string

    The value is a string of 0 to 128 characters.

    The value must be the same as the verification value in the basic information entered when you create a skill on the Huawei HiLens management console. If they are different, the HiLens Framework forcibly stops the skill.

  • Return value

    The value 0 indicates that the HiLens Framework is initialized successfully. Other values indicate that the HiLens Framework fails to be initialized.

    This method can also be used to verify whether the skill is corrupted or tampered with. To use this function, the verify parameter must be the return value of a function compiled by the developer. The return value is the hash value of the file to be verified in real time. After developing a skill, the developer uses the same hash method to calculate the hash value and enters the verification value when creating the skill on the console. The following is an example:

    #! /usr/bin/python3.7
    
    import hilens
    def verify():   
        # You need to implement a method to verify the program identity (to prevent the program from being damaged or tampered with).
        # For example, if the hash value of an important file in a skill package can be calculated, verify must return a string of 1 to 128 bytes.
        # On the HiLens platform, enter the hash value during skill development. After the init method is invoked, the skill automatically sends the hash value to the platform for comparison and verifies the skill license.
    
        # During debugging, you can use a fixed character string for verification to facilitate code modification.
        # The source code of Python scripts is easy to be tampered with when being delivered to devices. For commercial skills, you are advised to use C++ for development.
        # Note: Do not use hard-coded character strings to verify skills that are officially released.
        return "hello"
    
    def main():
         # Initialize HiLens.
        rc = hilens.init(verify())
    # If you do not want to use this function in skill development and debugging phase, enter a static character string.
        # Example: hilens.init("hello")
        if rc != 0: 
           hilens.error("Failed to initialize HiLens")
           return 
    
       # Business code
        pass
    
        # Clear resources.
        hilens.terminate()
    
    if __name__ == '__main__':
        main()