Exemple #1
0
def main():
    client = TBDeviceMqttClient(THINGSBOARD_HOST, DEVICE_ACCESS_TOKEN)
    client.connect()
    rc = client.claim(secret_key=SECRET_KEY, duration=DURATION).get()
    if rc == 0:
        print("Claiming request was sent.")
    client.stop()
    config["host"] = host if host else "thingsboard.cloud"
    token = ""
    while not token:
        token = input("Please write accessToken for device: ")
        if not token:
            print("Access token is required!")
    config["token"] = token
    config["secret_key"] = input(
        "Please write secret key for claiming request: ")
    if not config["secret_key"]:
        print(
            "Please make sure that you have claimData in server attributes for device to use this feature without device secret in the claiming request."
        )
    duration_ms = input(
        "Please write duration in milliseconds for claiming request or leave it blank to use default (30000): "
    )
    config["duration_ms"] = int(duration_ms) if duration_ms else 30000
    print("\n", "=" * 80, "\n", sep="")
    return config


if __name__ == '__main__':
    config = collect_required_data()
    client = TBDeviceMqttClient(host=config["host"], token=config["token"])
    client.connect()
    client.claim(secret_key=config["secret_key"],
                 duration=config["duration_ms"]).get()
    print(
        "Claiming request was sent, now you should use claiming device widget to finish the claiming process."
    )