RouterClient¶
This module imports the Kortex Router, which is in turn used to instantiate service clients for Kortex API RPC calls.
- class RouterClient(transport: Optional[ITransportClient] = None, errorCallback=None, mqttBrokerHost: str = '192.168.1.10', mqttBrokerPort: int = 1883)¶
Leverages a Kortex Transport to properly route inbound and outbound Kortex frames to and from the proper Kortex Services.
Creating a RouterClient is necessary in order to issue RPC calls to a Kortex device. It needs to be supplied a valid
ITransportClient
at construction, and then Kortex Service Clients (see kortex_api.autogen.client_stubs) can be created using the RouterClient.If no transport is provided to the constructor, it will create a
MqttTransport
and try to connect it to a Kortex device.Before disconnecting the transport,
SetActivationStatus()
must be called to cleanly destroy the RouterClient.Usage :
from kortex_api.autogen.client_stubs.BaseClientRpc import BaseClient transport = MqttTransport() router = RouterClient(transport) transport.connect("192.168.1.10") # The router can be used to create a Service Client as such : base_client = BaseClient(router) # The Service Client can then be used to call RPCs and subscribe to notifications router.SetActivationStatus(False) transport.disconnect()
Constructor for the RouterClient.
Passing it no argument will make it create a
MqttTransport
on its own, and try to connect it to a Kortex device. If a transport is supplied, it must be connected after the construction of the RouterClient for it to work properly.- Parameters
transport (
ITransportClient
, optional) – Kortex Transport this Router will use. Defaults to None.errorCallback (function, optional) – Custom error callback to call when something goes awry. Defaults to None.
mqttBrokerHost (str, optional) – If no transport is provided, this address will be used to connect the default transport. Defaults to DEFAULT_CONTROLLER_ADDRESS.
mqttBrokerPort (int, optional) – If no transport is provided, this port will be used to connect the default transport. Defaults to DEFAULT_MQTT_BROKER_PORT.
- GetConnectionId() int ¶
Returns the router’s session ID.
If the router does not have a valid session, 0 is returned.
- SetActivationStatus(isActive: bool)¶
Sets the activation status of the RouterClient.
Needs to be called before disconnecting the transport.
- Parameters
isActive (bool) – Activation status.