API reference Introduction HubClient is a class containing the main functions you will use in applications to communicate between your device and the cloud. HubClient is a singleton meaning that you don’t have to create an HubClient object, there is a unique instance of the class that will be used by the static functions. CallbackParameters CallbackParameters class CallbackParameters Creates a callback "package" (function name, parameters, ...) that can be registered using HubClient.register_function. Usage # Setup a callback function in case of a device parameter change callback_param = CallbackParameters() # Use "|" if you want your callback to be set on several parameters callback_param.set_parameter_callback("onParamChange", "camera_resolution|camera_fps|camera_image_flip", CALLBACK_TYPE.ON_PARAMETER_UPDATE) # Register your function HubClient.register_function(on_init_param_update, callback_param) CallbackParameters static function set_configuration_callback ( string function_name , string setting_key , CALLBACK_TYPE callback_type , list<FunctionParameterDescription> function_parameters ) Generates configuration callback parameters (for device twin update). function_name string The name of the function callback. setting_key string The device twin key that will activates the callback on update. callback_type CALLBACK_TYPE optional allowed callback_type for this function is CALLBACK_TYPE.ON_CONFIGURATION_UPDATE function_parameters list<FunctionParameterDescription> optional List of function parameters. Usage # Setup a callback function in case of a device twin configuration change callback_param = CallbackParameters() callback_param.set_configuration_callback("onHostSoftwareUpdate", "host.software", CALLBACK_TYPE.ON_CONFIGURATION_UPDATE) # Register your function HubClient.register_function(on_host_software_update, callback_param) CallbackParameters static function set_remote_callback ( string function_name , CALLBACK_TYPE callback_type , list<FunctionParameterDescription> function_parameters ) Generates remote function callback parameters (for remote function calls). function_name string The name of the function callback. callback_type CALLBACK_TYPE optional allowed callback_type for this function is CALLBACK_TYPE.ON_REMOTE_CALL function_parameters list<FunctionParameterDescription> optional List of function parameters. Usage # Set a remote callback for the function "functionCall" callback_param = CallbackParameters() HubClient.set_remote_callback("functionCall", CALLBACK_TYPE.ON_REMOTE_CALL) # Register your function HubClient.register_function(on_function_call, callback_param) CallbackParameters static function set_parameter_callback ( string function_name , CALLBACK_TYPE callback_type , CALLBACK_TYPE parameter_type , list<FunctionParameterDescription> function_parameters ) Generates remote function callback parameters (for remote function calls). function_name string The name of the function callback. callback_type CALLBACK_TYPE optional allowed callback_type for this function is CALLBACK_TYPE.ON_PARAMETER_UPDATE parameter_type CALLBACK_TYPE optional The requested parameter type that can be PARAMETER_TYPE.APPLICATION or PARAMETER_TYPE.DEVICE (default: DEVICE). function_parameters list<FunctionParameterDescription> optional List of function parameters. Usage # Set a remote callback for the function "functionCall" callback_param = CallbackParameters() HubClient.set_parameter_callback("onParamChange", "first_param|second_param", CALLBACK_TYPE.ON_PARAMETER_UPDATE, PARAMETER_TYPE.APPLICATION) # Register your function HubClient.register_function(on_parameter_update, callback_param) CallbackParameters static function reset ( ) Resets the CallbackParameters structure to reuse it. Usage # Setup a callback function in case of an application parameter change callback_param = CallbackParameters() HubClient.set_parameter_callback("onFirstParamChange", "first_param", CALLBACK_TYPE.ON_PARAMETER_UPDATE, PARAMETER_TYPE.APPLICATION) # Register your function HubClient.register_function(on_parameter_update, callback_param) # Reset the CallbackParameters structure callback_param.reset() HubClient.set_parameter_callback("onSecondParamChange", "second_param", CALLBACK_TYPE.ON_PARAMETER_UPDATE, PARAMETER_TYPE.APPLICATION) # Register your function HubClient.register_function(on_parameter_update, callback_param) DataParameters DataParameters struct UpdateParameters A structure that defines parameters used in the HubClient::update function. enable_recording bool Enable the recordings (default: true). enable_zed_sdk_streaming bool Enable the SDK streaming (default: false). enable_rtsp_streaming bool Enable the RTSP streaming (default: false). recording_bitrate int Bitrate of the recordings in Kbit/s (default: 2200). streaming_width int With of the streaming in pixel (default: 1280). streaming_height int Height of the streaming in pixel (default: 720). Usagef update_params = UpdateParameters() update_params.enable_rtsp_streaming = true HubClient.update(update_params) HubClient.register(p_zed, update_params) DataParameters struct LogParameters A structure that defines parameters for logs that can be used in the HubClient.send_log function. timestamp unsigned long long Defines the timestamp of the log in milliseconds. 0 gives the current timestamp when the log is sent. retention int Retention of the log in days. 0 gives the default retention for logs. reference string Gives a specific id to the log to be used to send data to this log. reference_to string The log will be incremented to the log that was sent with this value as reference. Usage log_params = LogParameters() log_params.retention = 2 # 2 days HubClient.send_log("Info log sent, will be deleted in 6 hours", LOG_LEVEL.INFO, "label", log_params) DataParameters struct TelemetryParameters A structure that defines parameters for telemetry that can be used in the HubClient.send_telemetry function. timestamp unsigned long long Defines the timestamp of the log in milliseconds. 0 gives the current timestamp when the telemetry is sent. retention int Retention for telemetry in days. 0 gives the default retention for telemetry. tags std::string optional Tags to add to the telemetry. Usage ts_start = get_current_timestamp() telemetry_data = {} # Do some stuff with telemetry_data during a certain amount of time telemetry_params = TelemetryParameters() telemetry_params.timestamp = ts_start # Send the telemetry with the right timestamp HubClient.send_telemetry("telem", telemetry_data, telemetry_params) DataParameters struct EventParameters A structure that defines parameters for events that can be used in the HubClient.start_video_event function. timestamp unsigned long long Defines the timestamp of the event in milliseconds. 0 gives the current timestamp when the event is sent. reference std::string Gives a specific id to the event to be used to send data to this event and update it. reference_to std::string The data of this event will be incremented to the event that was sent with this value as reference. The duration attribute will be added by the cloud to the event data calculated from the new timestamp. retention int Retention of the event in days. 0 gives the default retention for events. Usage # Create a ZED Object zed = sl.Camera() # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) exit(1) # Open the ZED Camera errZed = zed.open() if errZed != ERROR_CODE.SUCCESS: HubClient.send_log("Camera initialization error: " + str(errZed)), LOG_LEVEL.ERROR) exit(1) # Register the ZED Camera status_iot = HubClient.register_camera(zed) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) exit(1) # Enable Object Detection zed.enable_object_detection() # Main Loop depth_image = sl.Mat() objects = sl.Objects() same_event = false curr_event = "" curr_ts = 0 last_ts = 0 while True: if zed.grab() == sl.ERROR_CODE.SUCCESS: # Use zed results curr_ts = get_current_timestamp() zed.retrieve_objects(objects) # If object list size is >= 5 send an event if not same_event and len(objects.object_list) >= 5: value = {} value["nb_persons"] = len(objects.object_list) event_params = EventParameters() # Give a unique id to the event curr_event = random_string() event_params.reference = curr_event HubClient.start_video_event("crowd", value, event_params) same_event = true last_ts = get_current_timestamp() # If object list size is still >= 5 after the event, update the event if same_event and curr_ts > last_ts + 5000 and len(objects.object_list) >= 5: value = {} value["nb_persons"] = len(objects.object_list) # Give the current event id event_params = EventParameters() event_params.reference_to = curr_event HubClient.start_video_event("crowd", value, event_params) same_event = true last_ts = get_current_timestamp() # If object list size is not >= 5 anymore after 5 seconds, finish the event if same_event and curr_ts > last_ts + 5000 and len(objects.object_list) < 5: same_event = false curr_event = "" HubClient.update() # Live/Playback view will be the depth image. } } Enumerates Enumerates enum LOG_LEVEL Represents the available level of logs. DEBUG log level for debugging INFO log level for an info STATUS log level for a status WARNING log level for a warning ERROR log level for an error SUCCESS log level for a success DISABLED level where no log will be sent Usage HubClient.send_log("Sample log", LOG_LEVEL.INFO) Enumerates enum STATUS_CODE Represent the status codes that can be returned by functions. A successful function will return SUCCESS. INVALID_SYSTEM_CLOCK The device as an invalid clock, which can mess with SSL certificates. INVALID_TARGET A publish or a subscribe was called with an invalid \ref TARGET NO_RECORDINGS_FOUND No recordings were found on the device. CANNOT_LOAD_CONFIGURATION Cannot get the local device configuration. CANNOT_CONNECT Cannot connect to ZED Hub. FAILURE A function has failed. INVALID_FUNCTION_CALL A function was called with invalid parameters. INVALID_TOPIC A publish on an invalid topic was requested. REST_REQUESTS_DISABLED A REST Request was called but the feature is disabled. REQUEST_FAILED A REST Request has failed. EMPTY_KEY A device configuration read or write was called with an empty key. EMPTY_JSON A publish on a mqtt topic with an empty json is called. NOT_INITIALIZED A function was used before HubClient.connect has been successfully called. UNEXPECTED_INIT_TOKEN HubClient was initialized with a wrong token (application token for applications or device token for Edge Agent) CANNOT_OPEN_FILE Error while opening a file. SUCCESS No Error, Success. Usage STATUS_CODE status = HubClient.is_initialized() print(status) Enumerates enum REST_REQUEST_TYPE Specify the REST request to perform. GET Defines a GET request. POST Defines a POST request. PUT Defines a PUT request. DELETE Defines a DELETE request. Usage # Get the device information through a REST request workspace_url = HubClient.get_workspace_url() device_id = HubClient.get_device_id() endpoint = workspace_url + "/devices/" + device_id result = HubClient.perform_REST_request(REST_REQUEST_TYPE.GET, endpoint) == STATUS_CODE.SUCCESS) if result[0] == STATUS_CODE.SUCCESS: print("Device Information as REST response: ", result[1].dumps()) Enumerates enum TARGET Specify the communication target. This is used in the function publish_on_topic and subscribe_to_topic to specify the target recipient of the messages. TARGET.LOCAL_DEVICE refers to localhost, TARGET.WORKSPACE refers to any device on the same local network. LOCAL_DEVICE Target recipients are all applications that run on the current device. WORKSPACE Target recipients are all devices in the current workspace. Usage # Subscribe to the "myLocalData" topic on local device only HubClient.subscribe_to_topic("myLocalData", onNewMessage, TARGET.LOCAL_DEVICE) Enumerates enum CALLBACK_TYPE Defines the callback type for CallbackParameters. ON_CONFIGURATION_UPDATE Callback type for a configuration setting update. ON_REMOTE_CALL Callback type for a remote function call. ON_RESTART_CALL Callback type for a restart request. ON_PARAMETER_UPDATE Callback type for a parameter update. Usage # Set a remote callback HubClient.set_remote_callback("functionCall", CALLBACK_TYPE.ON_REMOTE_CALL) Enumerates enum PARAMETER_TYPE Defines the parameter type for CALLBACK_TYPE.ON_PARAMETER_UPDATE CallbackParameters. DEVICE The parameters is a device parameter (in device twin). ON_REMOTE_CALL The parameter is an application parameter (in application twin). Usage # Set a remote callback for the application parameter "alarm" HubClient.setParameterCallback("alarmUpdate", "alarm", CALLBACK_TYPE.ON_PARAMETER_UPDATE, PARAMETER_TYPE.APPLICATION) FunctionEvent FunctionEvent class FunctionEvent This is used in the callback function as parameter. status int Status of the event result json Result sent from the cloud. Can be emtpy. Usage # Define a callback with a FunctionEvent as parameter def remote_callback(event): # Perform action on event ... FunctionEvent function string function_name ( ) Get function name registered. On Success string function name as string Usage # Define a callback with a FunctionEvent as parameter def remote_callback(event): function_name = event.function_name() FunctionEvent function json parameters ( ) get event parameters as json of the function event. On Success json event parameters as json Usage # Define a callback with a FunctionEvent as parameter def remote_callback(event): function_name = event.parameters() FunctionEvent struct FunctionParameterDescription Defines a function parameter as a name and a default value. name string Name of the parameter. default_value string Default value of the parameter as string. Usage param = FunctionParameterDescription("unit", "meters") FunctionEvent static function json generate_parameters_description ( list<FunctionParameterDescription> parameters ) Generate a parameter description parameters list<FunctionParameterDescription> List of function parameters On Success json A json description of provided parameters Usage parameters = [] parameters.append(FunctionParameterDescription("unit", "meters")) result = generate_parameters_description(parameters) print(json.dumps(result)) HubClient HubClient class HubClient Provides the main interface to connect your program to the cloud. This class can be used program-wide with the static functions it provides. An initial configuration is required using the connect function. This initialization is available in two ways: Without a previously defined sl.Camera object: No video-related functions will be available, but Telemetry/Logs/Callbacks will still be available. With a previously defined sl.Camera object: All video-related functions will be available. This class is implemented as a singleton, it means that the constructor isn't available and only the static functions should be used. HubClient static function STATUS_CODE connect ( string app_id , bool verbose ) Init function for an application that doesn't use the ZED Camera. This function does not require a sl.Camera object. Some functions (related to video) will not be available if this function is used without registering a camera with register_camera. app_id string An identifier for your application verbose bool optional Set to False by default, whether the HubClient object will print verbose info in the console On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) HubClient static function STATUS_CODE is_initialized ( ) returns the status of HubClient's initialization. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Init sl_iot status_iot = HubClient.connect(app_name) if HubClient.is_initialized() != STATUS_CODE.SUCCESS: exit(1) HubClient static function STATUS_CODE disconnect ( ) Stop function that properly closes HubClient threads and connection. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) status_iot = HubClient.disconnect() HubClient static function STATUS_CODE register_camera ( sl.Camera zed ) ZED camera registration function for an application. zed sl.Camera ZED camera object. ZED SDK feature. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Create a ZED Object zed = sl.Camera() # Init sl_iot STATUS_CODE status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) exit(1) HubClient.register_camera(zed) # Open the ZED Camera errZed = zed.open() if errZed != ERROR_CODE.SUCCESS: HubClient.send_log("Camera initialization error: " + str(errZed)), LOG_LEVEL.ERROR) exit(1) # Register the ZED Camera update_params = UpdateParameters(); status_iot = HubClient.register_camera(zed, update_params); if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) exit(1) HubClient static function STATUS_CODE update ( sl.Camera camera , sl.Mat image ) Function called in the main loop that updates the video features, live stream and recording, of the sl_iot library. Commonly called after each zed.grab. This function is mandatory for video module: if it is not called, the live stream and SVO/MP4 recording won't be available. HubClient.connect must be called before using this function. camera sl.Camera optional ZED camera to update features from. ZED SDK feature. If not filled, the update will loop on all registered ZED camera and use the left RGB image. image sl.Mat optional Image from the SDK to update features. If not filled, the update will use the left RGB image. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Create a ZED Object zed = sl.Camera() depth = sl.Mat() # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) exit(1) # Open the ZED Camera errZed = zed.open() if errZed != ERROR_CODE.SUCCESS: HubClient.send_log("Camera initialization error: " + str(errZed)), LOG_LEVEL.ERROR) exit(1) # Register the ZED Camera status_iot = HubClient.register_camera(zed) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) exit(1) # Main Loop while True: if (zed.grab() == sl.ERROR_CODE.SUCCESS): # Use ZED results # An empty update will use the left image of the registered ZED camera # HubClient.update() # Otherwise, you can retrieve a matrix, play with it, and send it to Hub Client zed.retrieve_image(depth, sl.VIEW.DEPTH) HubClient.update(depth) HubClient static function STATUS_CODE send_log ( string or json message , LOG_LEVEL lvl , string label , LogParameters log_parameters ) Sends a log message (cloud and terminal, depending on LOG_LEVEL chosen). HubClient.connect must be called before using this function. message string or json Message to be sent in a string or json format. lvl LOG_LEVEL LOG_LEVEL of the message. Will be filtered (displayed or not) according to Log level threshold set by setLogLevelThreshold. label string optional Label of the message (can be filtered). log_parameters LogParameters optional Defines a log parameter for this message. See LogParameters for more details. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage HubClient.send_log("An error happened", LOG_LEVEL.ERROR) HubClient static function set_log_level_threshold ( LOG_LEVEL local_terminal_log_level , LOG_LEVEL cloud_log_level ) Sets the log level limit to be displayed. Every log with LOG_LEVEL below the limit will not be printed. HubClient.connect must be called before using this function. local_terminal_log_level LOG_LEVEL Log limit for terminal display. cloud_log_level LOG_LEVEL Log limit for cloud display. Usage # set threshold to error for terminal and info for cloud HubClient.set_log_level_threshold(LOG_LEVEL.ERROR, LOG_LEVEL.INFO) # this log will be printed in terminal but not sent to the cloud HubClient.send_log(log_msg, LOG_LEVEL.ERROR) HubClient static function LOG_LEVEL get_log_level_threshold ( ) Gets the current log level limit. HubClient.connect must be called before using this function. On Success LOG_LEVEL the terminal log level. Usage # get threshold terminal_log, cloud_log = HubClient.get_log_level_threshold() print("Terminal Log", terminal_log) print("Cloud Log", cloud_log) HubClient static function STATUS_CODE send_telemetry ( string label , json value , TelemetryParameters telemetry_parameters ) Sends a telemetry to the cloud. The telemetry will be stored on the cloud and can then be queried. Telemetry are data produced or calculated that meant to be reported to the cloud for further process. Combination of a label (i.e. key), a format-free json value and internal metadata. HubClient.connect must be called before using this function. label string Label that defines the telemetry. This label can be queried on the cloud for data filtering for example. value json Format-free json that contains the telemetry metadata values. telemetry_parameters TelemetryParameters optional Parameters for events. See TelemetryParameters for more details. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Create a ZED Object zed = sl.Camera() # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) # Open the ZED Camera errZed = zed.open() if errZed != ERROR_CODE.SUCCESS: HubClient.send_log("Camera initialization error: " + str(errZed)), LOG_LEVEL.ERROR) exit(1) # Register the ZED Camera status_iot = HubClient.register_camera(zed) if status_iot != STATUS_CODE.SUCCESS: print("Registration: ", sc) label= "environment" value = {} value["temperature"] = 21.0 # °C value["humidity"] = 91 # % HubClient.send_telemetry(label, value) HubClient static function STATUS_CODE publish_on_topic ( str topic , json value , TARGET target ) Publishes a message (json format) on the specified topic. HubClient.connect must be called before using this function. topic str Defines the topic name. value json Message to be sent in a json format. target TARGET optional Defines the recipient of the message. If TARGET.LOCAL_DEVICE is used, only the applications on the device that subscribed to this topic will receive the message. If TARGET.WORKSPACE is used, all the applications on the devices of the workspace that are running and that subscribed to this topic will receive the message. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", str(sc)) # To only my device val_device = {} val_device["message"] = "Hello myself" HubClient.publish_on_topic("myLocalData", val_device, TARGET.LOCAL_DEVICE) # To all devices in the workspace val_lan = {} val_lan["message"] = "Hello all" HubClient.publish_on_topic("myLocalData", val_device, TARGET.WORKSPACE) HubClient static function STATUS_CODE subscribe_to_topic ( string topic , callback callback , TARGET target ) Subscribes to a specified topic with a callback function. HubClient.connect must be called before using this function. topic string Defines the topic name. callback callback Callback function that will be called when a message is received on the subscribed topic. The function must have the following signature: def callback(topic: string, message: string, target: TARGET) string topic that defines the topic name. string message that defines the message (generally json but to be parsed). TARGET target that defines the recipient of the message. target TARGET optional Defines the recipient of the message. If TARGET.LOCAL_DEVICE is used, will receive messages only from applications on the device that send to this topic. If TARGET.WORKSPACE is used, will receive messages only from applications on devices of the workspace that send to this topic. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage def on_new_message(topic, message, target): print("Message Received: ", message) def main(): # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) HubClient.subscribe_to_topic("myLocalData", on_new_message, TARGET.LOCAL_DEVICE) HubClient static function STATUS_CODE unsubscribe_from_topic ( string topic , TARGET target ) Unsubscribes to a specified topic with a callback function. HubClient.connect must be called before using this function. topic string Defines the topic name. target TARGET optional Defines the recipient of the message. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage def on_new_message(topic, message, target): print("Message Received: ", message) def main(): # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) HubClient.subscribe_to_topic("myLocalData", on_new_message, TARGET.LOCAL_DEVICE) # Do stuff HubClient.unsubscribe_from_topic("myLocalData", TARGET.LOCAL_DEVICE) HubClient static function STATUS_CODE start_video_event ( sl.Camera target_camera , string label , json value , EventParameters event_params ) Starts a video event. The video event data will be stored on the cloud and can then be queried alongside the associated video if it's available on the device. It's a combination of a label (i.e. a key), a format-free json value, a recorded video and internal metadata. HubClient.connect must be called before using this function. target_camera sl.Camera Target ZED camera object . ZED SDK feature. label string .abel that defines the event. This label can be queried on the cloud for data filtering for example. value json Format-free json that contains the event metadata value. event_params EventParameters optional Parameters for events. See EventParameters for more details. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Create a ZED Object zed = sl.Camera() # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) # Open the ZED Camera errZed = zed.open() if errZed != ERROR_CODE.SUCCESS: HubClient.send_log("Camera initialization error: " + str(errZed)), LOG_LEVEL.ERROR) exit(1) # Register the ZED Camera status_iot = HubClient.register_camera(zed) if status_iot != STATUS_CODE.SUCCESS: print("Registration: ", sc) # Enable Object Detection zed.enable_object_detection() # Main Loop depth_image = sl.Mat() objects = sl.Objects() while True: if zed.grab() == sl.ERROR_CODE.SUCCESS: # Use zed results zed.retrieve_objects(objects) if len(objects.object_list) >= 5: value = {} value["nb_persons"] = len(objects.object_list) HubClient.start_video_event("crowd", value) HubClient.update() HubClient static function STATUS_CODE update_video_event ( sl.Camera target_camera , string label , json value , EventParameters event_params ) Update a video event. HubClient.start_video_event must be called before using this function. target_camera sl.Camera Target ZED camera object. ZED SDK feature. label string Label that defines the event. This label can later be queried on the cloud for data filtering for example. value json Format-free json that contains the event metadata value. event_params EventParameters optional Parameters for events. See EventParameters for more details. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Create a ZED Object zed = sl.Camera() # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) # Open the ZED Camera errZed = zed.open() if errZed != ERROR_CODE.SUCCESS: HubClient.send_log("Camera initialization error: " + str(errZed)), LOG_LEVEL.ERROR) exit(1) # Register the ZED Camera status_iot = HubClient.register_camera(zed) if status_iot != STATUS_CODE.SUCCESS: print("Registration: ", sc) # Enable Object Detection zed.enable_object_detection() # Main Loop depth_image = sl.Mat() objects = sl.Objects() event_started = false while True: if zed.grab() == sl.ERROR_CODE.SUCCESS: # Use zed results zed.retrieve_objects(objects) if len(objects.object_list) >= 5: value = {} value["nb_persons"] = len(objects.object_list) if event_started: HubClient.update_video_event("crowd", value) else: HubClient.start_video_event("crowd", value) event_started = true else: event_started = false HubClient.update() HubClient static function STATUS_CODE purge_video_stream ( ) Purge the HLS (streaming protocol) live playlist and remove any remaining segment. This can be used when changing camera settings of ZED camera (brightness, contrast, ...). HubClient.connect must be called before using this function. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage HubClient.purge_video_stream() HubClient.update() HubClient static function STATUS_CODE register_function ( Callable callback , CallbackParameters callback_parameters ) Registers a function callback associated with a function name. HubClient.connect must be called before using this function. callback Callable Function callback that will be called. The function must have these arguments: FunctionEvent# event: A FunctionEvent containing data to be used in the callback. See FunctionEvent for more infos. callback_parameters CallbackParameters Parameters containing information about the callback function, name, type etc. See CallbackParameters for more infos. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Callback function def on_init_param_update(event: FunctionEvent): event.status = 0 HubClient.send_log("Init Parameters Update. Re-opening the camera.", LOG_LEVEL.INFO) zed.close() init_parameters = sl.InitParameters() reso_str = sliot.HubClient.get_parameter_string( "camera_resolution", sliot.PARAMETER_TYPE.APPLICATION) if reso_str == "HD2K": init_parameters.camera_resolution = sl.RESOLUTION.HD2K elif reso_str == "HD720": init_parameters.camera_resolution = sl.RESOLUTION.HD720 elif reso_str == "HD1080": init_parameters.camera_resolution = sl.RESOLUTION.HD1080 elif reso_str == "VGA": init_parameters.camera_resolution = sl.RESOLUTION.VGA init_parameters.camera_image_flip = sl.FLIP_MODE(HubClient.get_parameter_int("camera_image_flip", PARAMETER_TYPE.APPLICATION)) init_parameters.camera_fps = HubClient.get_parameter_int("camera_fps", sliot.PARAMETER_TYPE.APPLICATION) zed.open(init_parameters) def main(): # Create camera object zed = sl.Camera() # Init sl_iot STATUS_CODE status_iot = HubClient.connect("app name") if status_iot != STATUS_CODE.SUCCESS: print("HubClient ", status_iot) exit(1) status_iot = HubClient.register_camera(zed) if status_iot != STATUS_CODE.SUCCESS: print("Registration ", status_iot) exit(1) # Setup a callback function in case of an application parameter change callback_param = sl.CallbackParameters() # Use "|" if you want your callback to be set on several parameters callback_param.set_parameter_callback("onParamChange", "camera_resolution|camera_fps|camera_image_flip", CALLBACK_TYPE.ON_PARAMETER_UPDATE) # Register your function HubClient.register_function(on_init_param_update, callback_param) HubClient static function STATUS_CODE unregister_function ( string function_name ) Unregisters callback associated with the function name. HubClient.connect must be called before using this function. function_name string The function name of the function to be unregistered. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Setup a callback function in case of an application parameter change callback_param = CallbackParameters() # Use "|" if you want your callback to be set on several parameters callback_param.set_parameter_callback("onParamChange", "camera_resolution|camera_fps|camera_image_flip", CALLBACK_TYPE.ON_PARAMETER_UPDATE) # Register your function HubClient.register_function(on_init_param_update, callback_param) # Unregister your function HubClient.unregister_function("onParamChange") HubClient static function STATUS_CODE get_device_id ( ) Gets the device unique id that is stored on the cloud. This is the device id parameter that needs to be used in a REST request. See the REST API doc for more details. HubClient.connect must be called before using this function. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage status, device_id = HubClient.get_device_id() print("Device Id: ", device_id) HubClient static function STATUS_CODE get_device_type ( ) Gets the device type from the device twin. HubClient.connect must be called before using this function. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage status, device_type = HubClient.get_device_type() print("Device Type: ", device_type) HubClient static function STATUS_CODE get_device_name ( ) Gets the device name from the device twin. HubClient.connect must be called before using this function. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage status, device_name = HubClient.get_device_name() print("Device Name: ", device_name) HubClient static function STATUS_CODE get_workspace_id ( ) Gets the workspace unique id that is stored on the cloud. This is the workspace id parameter that needs to be used in a REST request. See the REST API doc for more details. HubClient.connect must be called before using this function. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage status, workspace_id = HubClient.get_workspace_id() print("Workspace Id: ", workspace_id) HubClient static function STATUS_CODE get_workspace_url ( ) Gets the workspace URL of the current workspace. This is the workspace URL parameter that needs to be used in a REST request. See the REST API doc for more details. HubClient.connect must be called before using this function. On Success STATUS_CODE the SUCCESS status. On Success string The workspace URL as a string. On Error STATUS_CODE Any other status code != SUCCESS. Usage status, workspace_url = HubClient.get_workspace_url() print("Workspace URL: ", workspace_url) HubClient static function STATUS_CODE get_cloud_url ( ) Gets the cloud URL. This is the cloud URL parameter that needs to be used in a REST request. See the REST API doc for more details. HubClient.connect must be called before using this function. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage status, cloud_url = HubClient.get_cloud_url() print("Cloud URL: ", cloud_url) HubClient static function list get_headers ( ) Returns base headers for REST Request to the cloud with "Authorization" containing access token. HubClient.connect must be called before using this function. On Success list List containing the base "Authorization" header containing access token. On Error list Empty list. Usage headers = HubClient.get_headers() HubClient static function STATUS_CODE perform_rest_request ( REST_REQUEST_TYPE type , string url , json payload , list headers ) Generic function to perform a REST request. See the REST API doc for more details. HubClient.connect must be called before using this function. type REST_REQUEST_TYPE Defines the request type: GET, PUT, POST or DELETE as an enum for simplicity. url string Defines the end point of the request. payload json optional json payload to add to the request. Not used in "GET" request. headers list optional Headers to add to the REST Request, default is the result of HubClient.getHeader containing "Authorization" header with access token. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage # Init sl_iot status_iot = HubClient.connect(app_name) if status_iot != STATUS_CODE.SUCCESS: print("Status: ", sc) # Get the device information through a REST request workspace_url = HubClient.get_workspace_url() device_id = HubClient.get_device_id() endpoint = workspace_url + "/devices/" + device_id status, result = HubClient.perform_rest_request(REST_REQUEST_TYPE.GET, endpoint) if status = STATUS_CODE.SUCCESS print("Device Information as REST response: ", json.dumps(result)) HubClient static function STATUS_CODE get_configuration ( string key ) Gets the content of a section of the device twin. HubClient.connect must be called before using this function. key string The name of the section of the device twin, subsections are separated by dots. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage content = {} # Get host software description from the device twin. status, result = HubClient.get_configuration("host.software") print(json.dumps(result)) HubClient static function STATUS_CODE update_configuration ( string key , json new_conf ) Updates the content of a section of the device twin. HubClient.connect must be called before using this function. key string The key of the section of the device twin, subsection are separated by dots. new_conf json The new value of the device twin section to update. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage content = {} # Get user_data from the device twin. status, content = HubClient.get_configuration("user_data") print("Before: ", json.dumps(content)) content["data"] = 3 # Update user_data HubClient.update_configuration("user_data", content) status, content = HubClient.get_configuration("user_data") print("After: ", json.dumps(content)) HubClient static function T& get_parameter<output-type> ( string parameter_name , PARAMETER_TYPE parameter_type , T& default_value ) Gets the requested device/application parameter defined by its name (parameters.requested in device/application twin). HubClient.connect must be called before using this function. parameter_name string Defines the parameter name that is stored on the cloud.` parameter_type PARAMETER_TYPE The type of the parameter PARAMETER_TYPE.DEVICE for device parameters PARAMETER_TYPE.APPLICATION` for application parameters. default_value T& The default value to return if no parameter is found. On Success T# The value of the parameter. Usage param_str = HubClient.get_parameter_string("first_param", PARAMETER_TYPE.APPLICATION, "default_value") HubClient static function STATUS_CODE set_parameter ( string parameter_name , PARAMETER_TYPE parameter_type , T& value ) Sets the requested device/application parameter defined by its name (parameters.requested in device/application twin). HubClient.connect must be called before using this function. parameter_name string Defines the parameter name that is stored on the cloud. parameter_type PARAMETER_TYPE The type of the parameter PARAMETER_TYPE.DEVICE for device parameters PARAMETER_TYPE.APPLICATION for application parameters. value T& The value to to set. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage HubClient.set_parameter("first_param", PARAMETER_TYPE:.APPLICATION, "value") HubClient static function STATUS_CODE report_parameter ( string parameter_name , PARAMETER_TYPE parameter_type , T& value ) Reports the device/application parameter defined by its name (parameters.reported in device/application twin). HubClient.connect must be called before using this function. parameter_name string Defines the parameter name that is stored on the cloud. parameter_type PARAMETER_TYPE The type of the parameter PARAMETER_TYPE.DEVICE for device parameters PARAMETER_TYPE.APPLICATION for application parameters. value T& The value to to set. On Success STATUS_CODE The SUCCESS status code. On Error STATUS_CODE Any other status code != SUCCESS. Usage HubClient.report_parameter("first_param", PARAMETER_TYPE.APPLICATION, "value")