def publish_platform_info(client,
                          attr_file_dir=default_cfg_dir,
                          attr_file_name="attributes.cfg"):
    """
    Function to publish information about the current platform (device) to the
    cloud as attributes.
    """
    client.log(iot.LOGINFO, "Publishing platform Info")

    try:
        hdc_version = pkg_resources.get_distribution("device_cloud").version
    except pkg_resources.DistributionNotFound:
        hdc_version = "RC-17.00.00"

    client.attribute_publish("os_name", osal.os_name())
    client.attribute_publish("os_version", osal.os_version())
    client.attribute_publish("architecture", platform.machine())
    client.attribute_publish("hostname", platform.node())
    client.attribute_publish("kernel", osal.os_kernel())
    client.attribute_publish("hdc_version", hdc_version)
    client.attribute_publish("mac_address", get_adapter_mac())

    try:
        with open(os.path.join(attr_file_dir, attr_file_name),
                  'r') as attr_file:
            attribute_data = json.load(attr_file)
        attr_list = attribute_data["publish_attribute"]

        for key, value in attr_list.items():
            if key == "hdc_version":
                client.log(iot.LOGERROR, "Cannot set hdc_version")
            else:
                client.attribute_publish(key, value)
    except:
        pass
Exemple #2
0
def publish_platform_info(client):
    """
    Function to publish information about the current platform (device) to the
    cloud as attributes.
    """
    client.log(iot.LOGINFO, "Publishing platform Info")

    try:
        hdc_version = pkg_resources.get_distribution("device_cloud").version
    except pkg_resources.DistributionNotFound:
        hdc_version = "Unknown"

    client.attribute_publish("os_name", osal.os_name())
    client.attribute_publish("os_version", osal.os_version())
    client.attribute_publish("architecture", platform.machine())
    client.attribute_publish("hostname", platform.node())
    client.attribute_publish("kernel", osal.os_kernel())
    client.attribute_publish("hdc_version", hdc_version)
    client.attribute_publish("mac_address", get_adapter_mac())