Example #1
0
    def __init__(self, options):
        self.__options = options

        if 'org' not in self.__options or self.__options['org'] == None:
            raise ibmiotf.ConfigurationException(
                "Missing required property: org")
        if 'id' not in self.__options or self.__options['id'] == None:
            raise ibmiotf.ConfigurationException(
                "Missing required property: type")
        if 'auth-method' not in self.__options:
            raise ibmiotf.ConfigurationException(
                "Missing required property: auth-method")

        if (self.__options['auth-method'] == "apikey"):
            # Check for required API Key and authentication token
            if 'auth-key' not in self.__options or self.__options[
                    'auth-key'] == None:
                raise ibmiotf.ConfigurationException(
                    "Missing required property for API key based authentication: auth-key"
                )
            if 'auth-token' not in self.__options or self.__options[
                    'auth-token'] == None:
                raise ibmiotf.ConfigurationException(
                    "Missing required property for API key based authentication: auth-token"
                )

            self.credentials = (self.__options['auth-key'],
                                self.__options['auth-token'])
        elif self.__options['auth-method'] is not None:
            raise ibmiotf.UnsupportedAuthenticationMethod(
                options['authMethod'])
Example #2
0
	def __init__(self, options):
		self.__options = options

		username = None
		password = None

		if 'org' not in self.__options or self.__options['org'] == None:
			raise ibmiotf.ConfigurationException("Missing required property: org")
		if 'id' not in self.__options or self.__options['id'] == None: 
			raise ibmiotf.ConfigurationException("Missing required property: type")

		# Auth method is optional.  e.g. in QuickStart there is no authentication
		if 'auth-method' not in self.__options:
			self.__options['auth-method'] = None
			
		if (self.__options['auth-method'] == "apikey"):
			# Check for required API Key and authentication token
			if 'auth-key' not in self.__options or self.__options['auth-key'] == None: 
				raise ibmiotf.ConfigurationException("Missing required property for API key based authentication: auth-key")
			if 'auth-token' not in self.__options or self.__options['auth-token'] == None: 
				raise ibmiotf.ConfigurationException("Missing required property for API key based authentication: auth-token")
			
			username = self.__options['auth-key']
			password = self.__options['auth-token']
			
		elif self.__options['auth-method'] is not None:
			raise ibmiotf.UnsupportedAuthenticationMethod(options['authMethod'])

		# Call parent constructor
		ibmiotf.AbstractClient.__init__(
			self, options['org'], "a:" + options['org'] + ":" + options['id'], username, password
		)
		
		# 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 self.__options['org'] != "quickstart":
			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 (devices)
		self.deviceEventCallback = None
		self.deviceCommandCallback = None
		self.deviceStatusCallback = None
		
		# Initialize user supplied callbacks (applcations)
		self.appStatusCallback = None
		
		self.client.on_connect = self.on_connect

		# Create an api client if not connected in QuickStart mode
		if self.__options['org'] != "quickstart":
			self.api = ibmiotf.api.ApiClient(options)
Example #3
0
    def __init__(self, options):
        self.__options = options

        if self.__options['org'] == None:
            raise ibmiotf.ConfigurationException(
                "Missing required property: org")
        if self.__options['type'] == None:
            raise ibmiotf.ConfigurationException(
                "Missing required property: type")
        if self.__options['id'] == None:
            raise ibmiotf.ConfigurationException(
                "Missing required property: id")

        if self.__options['org'] != "quickstart":
            if self.__options['auth-method'] == None:
                raise ibmiotf.ConfigurationException(
                    "Missing required property: auth-method")

            if (self.__options['auth-method'] == "token"):
                if self.__options['auth-token'] == None:
                    raise ibmiotf.ConfigurationException(
                        "Missing required property for token based authentication: auth-token"
                    )
            else:
                raise ibmiotf.UnsupportedAuthenticationMethod(
                    options['authMethod'])

        ibmiotf.AbstractClient.__init__(
            self,
            organization=options['org'],
            clientId="d:" + options['org'] + ":" + options['type'] + ":" +
            options['id'],
            username="******" if
            (options['auth-method'] == "token") else None,
            password=options['auth-token'])

        # Add handler for commands if not connected to QuickStart
        if self.__options['org'] != "quickstart":
            self.client.message_callback_add("iot-2/cmd/+/fmt/+",
                                             self.__onCommand)

        # Initialize user supplied callback
        self.commandCallback = None

        self.client.on_connect = self.on_connect
Example #4
0
	def __init__(self, options):
		self.__options = options

		# Configure logging
		self.logger = logging.getLogger(self.__module__+"."+self.__class__.__name__)
		self.logger.setLevel(logging.INFO)

		if 'org' not in self.__options or self.__options['org'] == None:
			raise ibmiotf.ConfigurationException("Missing required property: org")
		if 'id' not in self.__options or self.__options['id'] == None: 
			raise ibmiotf.ConfigurationException("Missing required property: type")
		if 'auth-method' not in self.__options:
			raise ibmiotf.ConfigurationException("Missing required property: auth-method")
			
		if (self.__options['auth-method'] == "apikey"):
			# Check for required API Key and authentication token
			if 'auth-key' not in self.__options or self.__options['auth-key'] == None: 
				raise ibmiotf.ConfigurationException("Missing required property for API key based authentication: auth-key")
			if 'auth-token' not in self.__options or self.__options['auth-token'] == None: 
				raise ibmiotf.ConfigurationException("Missing required property for API key based authentication: auth-token")
			
			self.credentials = (self.__options['auth-key'], self.__options['auth-token'])
		elif self.__options['auth-method'] is not None:
			raise ibmiotf.UnsupportedAuthenticationMethod(options['authMethod'])