Esempio n. 1
0
    def __init__(self, config, logHandlers=None):
        self._config = DeviceClientConfig(**config)

        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            port=self._config.port,
            transport=self._config.transport,
            cleanStart=self._config.cleanStart,
            sessionExpiry=self._config.sessionExpiry,
            keepAlive=self._config.keepAlive,
            caFile=self._config.caFile,
            logLevel=self._config.logLevel,
            logHandlers=logHandlers,
        )

        # Add handler for commands if not connected to QuickStart
        if not self._config.isQuickstart():
            self.client.message_callback_add("iot-2/cmd/+/fmt/+", self._onCommand)

        # Initialize user supplied callback
        self.commandCallback = None

        # Register startup subscription list (only for non-Quickstart)
        if not self._config.isQuickstart():
            self._subscriptions[self._COMMAND_TOPIC] = 1
Esempio n. 2
0
    def __init__(self, config, logHandlers=None):
        self._config = ApplicationClientConfig(**config)
        # Call parent constructor
        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            logHandlers=logHandlers,
            cleanStart=self._config.cleanStart,
            port=self._config.port,
            transport=self._config.transport,
            caFile=self._config.caFile,
            logLevel=self._config.logLevel,
            sessionExpiry=self._config.sessionExpiry,
            keepAlive=self._config.keepAlive,
        )

        # Add handlers for events and status
        self.client.message_callback_add("iot-2/type/+/id/+/evt/+/fmt/+", self._onDeviceEvent)
        self.client.message_callback_add("iot-2/type/+/id/+/mon", self._onDeviceStatus)
        self.client.message_callback_add("iot-2/app/+/mon", self._onAppStatus)
        self.client.message_callback_add("iot-2/type/+/id/+/intf/+/evt/state", self._onDeviceState)
        self.client.message_callback_add("iot-2/thing/type/+/id/+/intf/+/evt/state", self._onThingState)
        self.client.message_callback_add("iot-2/type/+/id/+/err/data", self._onErrorTopic)
        self.client.message_callback_add("iot-2/thing/type/+/id/+/err/data", self._onThingError)

        # Add handler for commands if not connected to QuickStart
        if not self._config.isQuickstart():
            self.client.message_callback_add("iot-2/type/+/id/+/cmd/+/fmt/+", self._onDeviceCommand)

        # Attach fallback handler
        self.client.on_message = self._onUnsupportedMessage

        # Initialize user supplied callbacks
        self.deviceEventCallback = None
        self.deviceCommandCallback = None
        self.deviceStateCallback = None
        self.deviceStatusCallback = None
        self.thingStateCallback = None
        self.errorTopicCallback = None
        self.appStatusCallback = None

        # Create an api client if not connected in QuickStart mode
        if not self._config.isQuickstart():
            apiClient = ApiClient(self._config, self.logger)
            self.registry = Registry(apiClient)
            self.usage = Usage(apiClient)
            self.dsc = DSC(apiClient)
            self.lec = LEC(apiClient)
            self.mgmt = Mgmt(apiClient)
            self.serviceBindings = ServiceBindings(apiClient)
            self.actions = Actions(apiClient)
            self.state = StateMgr(apiClient)

            # We directly expose the get() method via self.serviceStatus()
            self._serviceStatus = ServiceStatus(apiClient)
Esempio n. 3
0
    def __init__(self, config, logHandlers=None):
        self._config = ApplicationClientConfig(**config)
        # Call parent constructor
        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            logHandlers=logHandlers,
            cleanStart=self._config.cleanStart,
            port=self._config.port,
            transport=self._config.transport,
        )

        # Add handlers for events and status
        self.client.message_callback_add("iot-2/type/+/id/+/evt/+/fmt/+",
                                         self._onDeviceEvent)
        self.client.message_callback_add("iot-2/type/+/id/+/mon",
                                         self._onDeviceStatus)
        self.client.message_callback_add("iot-2/app/+/mon", self._onAppStatus)

        # Add handler for commands if not connected to QuickStart
        if not self._config.isQuickstart():
            self.client.message_callback_add("iot-2/type/+/id/+/cmd/+/fmt/+",
                                             self._onDeviceCommand)

        # Attach fallback handler
        self.client.on_message = self._onUnsupportedMessage

        # Initialize user supplied callbacks
        self.deviceEventCallback = None
        self.deviceCommandCallback = None
        self.deviceStatusCallback = None
        self.appStatusCallback = None

        # Create an api client if not connected in QuickStart mode
        if not self._config.isQuickstart():
            apiClient = ApiClient(self._config, self.logger)
            self.registry = Registry(apiClient)
            self.status = Status(apiClient)
            self.usage = Usage(apiClient)
            self.dsc = DSC(apiClient)
            self.lec = LEC(apiClient)
            self.mgmt = Mgmt(apiClient)
            self.serviceBindings = ServiceBindings(apiClient)
            self.actions = Actions(apiClient)
            self.state = StateMgr(apiClient)
Esempio n. 4
0
    def __init__(self, config, logHandlers=None):
        self._config = ApplicationClientConfig(**config)
        # Call parent constructor
        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            logHandlers=logHandlers,
            cleanStart=self._config.cleanStart,
            port=self._config.port,
            transport=self._config.transport,
        )

        # Add handlers for events and status
        self.client.message_callback_add("iot-2/type/+/id/+/evt/+/fmt/+", self._onDeviceEvent)
        self.client.message_callback_add("iot-2/type/+/id/+/mon", self._onDeviceStatus)
        self.client.message_callback_add("iot-2/app/+/mon", self._onAppStatus)

        # Add handler for commands if not connected to QuickStart
        if not self._config.isQuickstart():
            self.client.message_callback_add("iot-2/type/+/id/+/cmd/+/fmt/+", self._onDeviceCommand)

        # Attach fallback handler
        self.client.on_message = self._onUnsupportedMessage

        # Initialize user supplied callbacks
        self.deviceEventCallback = None
        self.deviceCommandCallback = None
        self.deviceStatusCallback = None
        self.appStatusCallback = None

        # Create an api client if not connected in QuickStart mode
        if not self._config.isQuickstart():
            apiClient = ApiClient(self._config, self.logger)
            self.registry = Registry(apiClient)
            self.status = Status(apiClient)
            self.usage = Usage(apiClient)
            self.dsc = DSC(apiClient)
            self.lec = LEC(apiClient)
            self.mgmt = Mgmt(apiClient)
            self.serviceBindings = ServiceBindings(apiClient)
Esempio n. 5
0
    def __init__(self, config, logHandlers=None):
        """
        Override the constructor
        """
        self._config = GatewayClientConfig(**config)

        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            port=self._config.port,
            transport=self._config.transport,
            cleanStart=self._config.cleanStart,
            sessionExpiry=self._config.sessionExpiry,
            keepAlive=self._config.keepAlive,
            caFile=self._config.caFile,
            logLevel=self._config.logLevel,
            logHandlers=logHandlers,
        )

        self.COMMAND_TOPIC = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/+"

        gatewayCommandTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/json"
        deviceCommandTopic = "iot-2/type/+/id/+/cmd/+/fmt/+"
        messageNotificationTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/notify"

        self.client.message_callback_add(gatewayCommandTopic, self._onCommand)
        self.client.message_callback_add(deviceCommandTopic,
                                         self._onDeviceCommand)
        self.client.message_callback_add(messageNotificationTopic,
                                         self._onMessageNotification)

        # Initialize user supplied callback
        self.commandCallback = None
        self.deviceCommandCallback = None
        self.notificationCallback = None
        self.client.on_connect = self._onConnect
        self.client.on_disconnect = self._onDisconnect
Esempio n. 6
0
    def __init__(self, config, logHandlers=None):
        """
        Override the constructor
        """
        self._config = GatewayClientConfig(**config)

        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            port=self._config.port,
            transport=self._config.transport,
            cleanStart=self._config.cleanStart,
            sessionExpiry=self._config.sessionExpiry,
            keepAlive=self._config.keepAlive,
            caFile=self._config.caFile,
            logLevel=self._config.logLevel,
            logHandlers=logHandlers,
        )

        self.COMMAND_TOPIC = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/+"

        gatewayCommandTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/json"
        deviceCommandTopic = "iot-2/type/+/id/+/cmd/+/fmt/+"
        messageNotificationTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/notify"

        self.client.message_callback_add(gatewayCommandTopic, self._onCommand)
        self.client.message_callback_add(deviceCommandTopic, self._onDeviceCommand)
        self.client.message_callback_add(messageNotificationTopic, self._onMessageNotification)

        # Initialize user supplied callback
        self.commandCallback = None
        self.deviceCommandCallback = None
        self.notificationCallback = None
        self.client.on_connect = self._onConnect
        self.client.on_disconnect = self._onDisconnect
Esempio n. 7
0
    def __init__(self, config, logHandlers=None, deviceInfo=None):
        """
        Override the constructor
        """
        if config["identity"]["orgId"] == "quickstart":
            raise ConfigurationException(
                "QuickStart does not support device management")

        self._config = GatewayClientConfig(**config)

        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            port=self._config.port,
            transport=self._config.transport,
            cleanStart=self._config.cleanStart,
            sessionExpiry=self._config.sessionExpiry,
            keepAlive=self._config.keepAlive,
            caFile=self._config.caFile,
            logLevel=self._config.logLevel,
            logHandlers=logHandlers,
        )

        self.COMMAND_TOPIC = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/+"

        gatewayCommandTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/json"
        deviceCommandTopic = "iot-2/type/+/id/+/cmd/+/fmt/+"
        messageNotificationTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/notify"

        self.client.message_callback_add(gatewayCommandTopic, self._onCommand)
        self.client.message_callback_add(deviceCommandTopic,
                                         self._onDeviceCommand)
        self.client.message_callback_add(messageNotificationTopic,
                                         self._onMessageNotification)

        # Initialize user supplied callback
        self.deviceCommandCallback = None
        self.notificationCallback = None

        # ---------------------------------------------------------------------
        # Device Management Specific code starts here
        # ---------------------------------------------------------------------
        self.readyForDeviceMgmt = threading.Event()

        # Add handler for supported device management commands
        self.client.message_callback_add("iotdm-1/#",
                                         self.__onDeviceMgmtResponse)

        # List of DM requests that have not received a response yet
        self._deviceMgmtRequestsPendingLock = threading.Lock()
        self._deviceMgmtRequestsPending = {}

        # List of DM notify hook
        self._deviceMgmtObservationsLock = threading.Lock()
        self._deviceMgmtObservations = []

        # Initialize local device data model
        self.metadata = {}
        if deviceInfo is not None:
            self._deviceInfo = deviceInfo
        else:
            self._deviceInfo = DeviceInfo()

        self._location = None
        self._errorCode = None

        # Initialize subscription list
        self._subscriptions[self.DM_RESPONSE_TOPIC_TEMPLATE %
                            (self._config.typeId, self._config.deviceId)] = 1
        self._subscriptions[self.DM_OBSERVE_TOPIC_TEMPLATE %
                            (self._config.typeId, self._config.deviceId)] = 1
        self._subscriptions[self.COMMAND_TOPIC] = 1
Esempio n. 8
0
    def __init__(self, config, logHandlers=None, deviceInfo=None):
        """
        Override the constructor
        """
        if config["identity"]["orgId"] == "quickstart":
            raise ConfigurationException("QuickStart does not support device management")

        self._config = GatewayClientConfig(**config)

        AbstractClient.__init__(
            self,
            domain=self._config.domain,
            organization=self._config.orgId,
            clientId=self._config.clientId,
            username=self._config.username,
            password=self._config.password,
            port=self._config.port,
            transport=self._config.transport,
            cleanStart=self._config.cleanStart,
            sessionExpiry=self._config.sessionExpiry,
            keepAlive=self._config.keepAlive,
            caFile=self._config.caFile,
            logLevel=self._config.logLevel,
            logHandlers=logHandlers,
        )

        self.COMMAND_TOPIC = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/+"

        gatewayCommandTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/cmd/+/fmt/json"
        deviceCommandTopic = "iot-2/type/+/id/+/cmd/+/fmt/+"
        messageNotificationTopic = "iot-2/type/" + self._config.typeId + "/id/" + self._config.deviceId + "/notify"

        self.client.message_callback_add(gatewayCommandTopic, self._onCommand)
        self.client.message_callback_add(deviceCommandTopic, self._onDeviceCommand)
        self.client.message_callback_add(messageNotificationTopic, self._onMessageNotification)

        # Initialize user supplied callback
        self.deviceCommandCallback = None
        self.notificationCallback = None

        # ---------------------------------------------------------------------
        # Device Management Specific code starts here
        # ---------------------------------------------------------------------
        self.readyForDeviceMgmt = threading.Event()

        # Add handler for supported device management commands
        self.client.message_callback_add("iotdm-1/#", self.__onDeviceMgmtResponse)

        # List of DM requests that have not received a response yet
        self._deviceMgmtRequestsPendingLock = threading.Lock()
        self._deviceMgmtRequestsPending = {}

        # List of DM notify hook
        self._deviceMgmtObservationsLock = threading.Lock()
        self._deviceMgmtObservations = []

        # Initialize local device data model
        self.metadata = {}
        if deviceInfo is not None:
            self._deviceInfo = deviceInfo
        else:
            self._deviceInfo = DeviceInfo()

        self._location = None
        self._errorCode = None

        # Initialize subscription list
        self._subscriptions[self.DM_RESPONSE_TOPIC_TEMPLATE % (self._config.typeId, self._config.deviceId)] = 1
        self._subscriptions[self.DM_OBSERVE_TOPIC_TEMPLATE % (self._config.typeId, self._config.deviceId)] = 1
        self._subscriptions[self.COMMAND_TOPIC] = 1