def __init__(self, edge_system_name=None, pub_topic=None, sub_topic=None, pub_qos=1, sub_qos=1, pub_retain=False, sub_callback=None): """ :param edge_system_name: Name of the EdgeSystem :param pub_topic: Publish topic of EdgeSystem or RegisteredMetric :param sub_topic: Subscribe topic of EdgeSystem or RegisteredMetric :param pub_qos: Publish QoS :param sub_qos: Subscribe QoS :param pub_retain: Publish Retain Flag :param sub_callback: Subscribe Callback """ if edge_system_name: # For Project ICE and Non-Project ICE, topics will be auto-generated if edge_system_name is not None self.pub_topic = 'liota/' + systemUUID().get_uuid(edge_system_name) + '/request' self.sub_topic = 'liota/' + systemUUID().get_uuid(edge_system_name) + '/response' else: # When edge_system_name is None, pub_topic or sub_topic must be provided self.pub_topic = pub_topic self.sub_topic = sub_topic # General validation if pub_qos not in range(0, 3) or sub_qos not in range(0, 3): raise ValueError("QoS should either be 0 or 1 or 2") if not isinstance(pub_retain, bool): raise ValueError("pub_retain must be a boolean") if sub_callback is not None: if not callable(sub_callback): raise ValueError("sub_callback should either be None or callable") log.info("Pub Topic is:{0}".format(self.pub_topic)) log.info("Sub Topic is:{0}".format(self.sub_topic)) self.pub_qos = pub_qos self.sub_qos = sub_qos self.pub_retain = pub_retain self.sub_callback = sub_callback
def __init__(self, edge_system_name=None, pub_topic=None, sub_topic=None, pub_qos=1, sub_qos=1, pub_retain=False, sub_callback=None): """ :param edge_system_name: Name of the EdgeSystem :param pub_topic: Publish topic of EdgeSystem or RegisteredMetric :param sub_topic: Subscribe topic of EdgeSystem or RegisteredMetric :param pub_qos: Publish QoS :param sub_qos: Subscribe QoS :param pub_retain: Publish Retain Flag :param sub_callback: Subscribe Callback """ if edge_system_name: # For Project ICE and Non-Project ICE, topics will be auto-generated if edge_system_name is not None self.pub_topic = 'liota/' + systemUUID().get_uuid( edge_system_name) + '/request' self.sub_topic = 'liota/' + systemUUID().get_uuid( edge_system_name) + '/response' else: # When edge_system_name is None, pub_topic or sub_topic must be provided self.pub_topic = pub_topic self.sub_topic = sub_topic # This validation is when MqttMessagingAttributes is initialized for registered_metric # Client can assign topics for each metrics at metric level # It will be used either for publishing or subscribing but not both. if self.pub_topic is None and (self.sub_topic is None or sub_callback is None): log.error( "Either (pub_topic can be None) or (sub_topic and sub_callback) can be None. But not both" ) raise ValueError( "Either (pub_topic can be None) or (sub_topic and sub_callback) can be None. But not both" ) # General validation if pub_qos not in range(0, 3) or sub_qos not in range(0, 3): log.error("QoS should either be 0 or 1 or 2") raise ValueError("QoS should either be 0 or 1 or 2") if not isinstance(pub_retain, bool): log.error("pub_retain must be a boolean") raise ValueError("pub_retain must be a boolean") if sub_callback is not None: if not callable(sub_callback): log.error("sub_callback should either be None or callable") raise ValueError( "sub_callback should either be None or callable") log.info("Pub Topic is:{0}".format(self.pub_topic)) log.info("Sub Topic is:{0}".format(self.sub_topic)) self.pub_qos = pub_qos self.sub_qos = sub_qos self.pub_retain = pub_retain self.sub_callback = sub_callback
def __init__(self, name): """ Init method for Dk300EdgeSystem. :param name: Dk300EdgeSystem name """ super(Dk300EdgeSystem, self).__init__(name=name, entity_id=systemUUID().get_uuid(name))
def __init__(self, name, modelRule): super(windmillSimulated, self).__init__( name=name, entity_id=systemUUID().get_uuid(name), entity_type="windmillSimulated" ) self.modelRule = modelRule
def reg_device_graphite(self, name, dev_type, prop_dict): from liota.entities.devices.device import Device from liota.lib.utilities.utility import systemUUID # Get values from configuration file config_path = self._config['package_path'] config = {} execfile(config_path + '/sampleProp.conf', config) # Acquire resources from registry if not self.pkg_registry.has("graphite"): log.warning("graphite package is not running, please load it first!") return None, None graphite = self.pkg_registry.get("graphite") tmp = systemUUID().get_uuid(name) dev = Device(name, tmp, dev_type) # Register device try: with self.discovery_lock: reg_dev = graphite.register(dev) graphite.set_properties(reg_dev, prop_dict) except: return None, None return dev, reg_dev
def reg_device(self, dcc_pkg, edge_system_pkg, name, dev_type, prop_dict): from liota.entities.devices.device import Device from liota.lib.utilities.utility import systemUUID # Acquire resources from registry if not self.pkg_registry.has(dcc_pkg): log.warning("%s package is not running" % dcc_pkg) return None, None dcc = self.pkg_registry.get(dcc_pkg) dev = Device(name, systemUUID().get_uuid(name), dev_type) # Register device try: with self.discovery_lock: reg_dev = dcc.register(dev) dcc.set_properties(reg_dev, prop_dict) except: return None, None # TBM: temporarily assume devices will be attached to the only edge system if self.pkg_registry.has(edge_system_pkg): edge_system = self.pkg_registry.get(edge_system_pkg) dcc.create_relationship(edge_system, reg_dev) else: log.warning("%s package is not loaded, please load it!" % edge_system_pkg) return dev, reg_dev
def reg_device_iotcc(self, name, dev_type, prop_dict): from liota.entities.devices.device import Device from liota.lib.utilities.utility import systemUUID # Get values from configuration file config_path = self._config['package_path'] config = {} execfile(config_path + '/sampleProp.conf', config) # Acquire resources from registry if not self.pkg_registry.has("iotcc"): log.warning("iotcc package is not running, please load it first!") return None, None iotcc = self.pkg_registry.get("iotcc") dev = Device(name, systemUUID().get_uuid(name), dev_type) prop_dict = self.add_organization_properties(iotcc, prop_dict) # Register device try: with self.discovery_lock: reg_dev = iotcc.register(dev) iotcc.set_properties(reg_dev, prop_dict) except: return None, None # TBM: temporarily assume devices will be attached to the only edge system if self.pkg_registry.has("iotcc_edge_system"): iotcc_edge_system = self.pkg_registry.get("iotcc_edge_system") iotcc.create_relationship(iotcc_edge_system, reg_dev) else: log.warning("iotcc_edge_system package is not loaded, please load it!") return dev, reg_dev
def reg_device_graphite(self, name, dev_type, prop_dict): from liota.entities.devices.device import Device from liota.lib.utilities.utility import systemUUID # Get values from configuration file config_path = self._config['package_path'] config = {} execfile(config_path + '/sampleProp.conf', config) # Acquire resources from registry if not self.pkg_registry.has("graphite"): log.warning("graphite package is not running, please load it first!") return None, None graphite = self.pkg_registry.get("graphite") tmp = systemUUID().get_uuid(name) dev = Device(name, tmp, dev_type) # Register device try: with self.discovery_lock: reg_dev = graphite.register(dev) #graphite.set_properties(reg_dev, prop_dict) except: return None, None return dev, reg_dev
def auto_generate_jabber_id(edge_system_name, server_name): """ :param edge_system_name: :return: return auto generated jabberID """ return systemUUID().get_uuid(edge_system_name) + "@" + server_name
def __init__(self, name, entity_type="Metric", unit=None, interval=60, aggregation_size=1, sampling_function=None ): """ Create a local metric object. :param name: metric name :param entity_type: entity type (by default, is "Metric") :param unit: Metric unit :param interval: Metric sampling interval :param aggregation_size: How many sampling results will be aggregated before publishing :param sampling_function: Metric sampling function :return: """ if not (unit is None or isinstance(unit, pint.unit._Unit)) \ or not ( isinstance(interval, int) or isinstance(interval, float) ) \ or not isinstance(aggregation_size, int): raise TypeError() super(Metric, self).__init__( name=name, entity_id=systemUUID().get_uuid(name), entity_type=entity_type ) self.unit = unit self.interval = interval self.aggregation_size = aggregation_size self.sampling_function = sampling_function
def __init__(self, name, wheel=26, m_bike=20, m_rider=80, m_load=0, interval=5, ureg=None): super(BikeSimulated, self).__init__(name=name, entity_id=systemUUID().get_uuid(name), entity_type="BikeSimulated") self.slope = 0.0 # rad self.radius_wheel = wheel # inch self.weight_bike = m_bike # kg self.weight_rider = m_rider # kg self.weight_load = m_load # kg self.revolution = 0.0 # rpm self.area = 1.0 # m ** 2 self.interval = interval self.ureg = None if isinstance(ureg, pint.UnitRegistry): self.ureg = ureg else: self.ureg = pint.UnitRegistry() self.time_last = None self.run()
def __init__(self, edge_system_name=None, pub_topic=None, sub_topic=None, pub_qos=1, sub_qos=1, pub_retain=False, sub_callback=None): """ :param edge_system_name: Name of the EdgeSystem :param pub_topic: Publish topic of EdgeSystem or RegisteredMetric :param sub_topic: Subscribe topic of EdgeSystem or RegisteredMetric :param pub_qos: Publish QoS :param sub_qos: Subscribe QoS :param pub_retain: Publish Retain Flag :param sub_callback: Subscribe Callback """ if edge_system_name: # For ProjectICE and Non-ProjectICE, topics will be auto-generated if gw_name is not None self.pub_topic = 'liota/' + systemUUID().get_uuid(edge_system_name) self.sub_topic = 'liota-resp/' + systemUUID().get_uuid(edge_system_name) else: # When gw_name is None, pub_topic or sub_topic must be provided self.pub_topic = pub_topic self.sub_topic = sub_topic # This validation is when MqttMessagingAttributes is initialized for reg_metric # Client can assign topics for each metrics at metric level # It will be used either for publishing or subscribing but not both. if self.pub_topic is None and (self.sub_topic is None or sub_callback is None): log.error("Either (pub_topic can be None) or (sub_topic and sub_callback) can be None. But not both") raise ValueError("Either (pub_topic can be None) or (sub_topic and sub_callback) can be None. But not both") # General validation if pub_qos not in range(0, 3) or sub_qos not in range(0, 3): log.error("QoS should either be 0 or 1 or 2") raise ValueError("QoS should either be 0 or 1 or 2") if not isinstance(pub_retain, bool): log.error("pub_retain must be a boolean") raise ValueError("pub_retain must be a boolean") if sub_callback is not None: if not callable(sub_callback): log.error("sub_callback should either be None or callable") raise ValueError("sub_callback should either be None or callable") log.info("Pub Topic is:{0}".format(self.pub_topic)) log.info("Sub Topic is:{0}".format(self.sub_topic)) self.pub_qos = pub_qos self.sub_qos = sub_qos self.pub_retain = pub_retain self.sub_callback = sub_callback
def run(self, registry): import copy from liota.dccs.wavefront import Wavefront from liota.dcc_comms.mqtt_dcc_comms import MqttDccComms from liota.lib.transports.mqtt import MqttMessagingAttributes from liota.lib.transports.mqtt import QoSDetails from liota.lib.utilities.identity import Identity from liota.lib.utilities.tls_conf import TLSConf from liota.lib.utilities.offline_buffering import BufferingParams from liota.lib.utilities.utility import systemUUID # Acquire resources from registry # Creating a copy of system object to keep original object "clean" edge_system = copy.copy(registry.get("edge_system")) # Get values from configuration file config_path = registry.get("package_conf") config = read_user_config(config_path + '/sampleProp.conf') # Initialize DCC object with transport offline_buffering = BufferingParams(persistent_storage=True, queue_size=-1, data_drain_size=10, draining_frequency=1) identity = Identity(root_ca_cert=config['broker_root_ca_cert'], username=config['broker_username'], password=['broker_password'], cert_file=None, key_file=None) # Encapsulate TLS parameters tls_conf = TLSConf(config['cert_required'], config['tls_version'], config['cipher']) # Encapsulate QoS related parameters qos_details = QoSDetails(config['in_flight'], config['queue_size'], config['retry']) # Connecting to emqtt broker client_id = systemUUID().get_uuid(edge_system.name) self.wavefront = Wavefront(MqttDccComms( edge_system_name=edge_system.name, url=config['BrokerIP'], port=config['BrokerPort'], identity=identity, tls_conf=tls_conf, qos_details=qos_details, client_id=client_id, clean_session=True, protocol=config['protocol'], transport=['transport'], conn_disconn_timeout=config['ConnectDisconnectTimeout']), buffering_params=offline_buffering) # Register gateway system wavefront_edge_system = self.wavefront.register(edge_system) registry.register("wavefront", self.wavefront) registry.register("wavefront_edge_system", wavefront_edge_system)
def __init__(self, name): """ Init method for GeneralEdgeSystem :param name: GeneralEdgeSystem name """ super(GeneralEdgeSystem, self).__init__( name=name, entity_id=systemUUID().get_uuid(name) )
def __init__(self, name): """ Init method for Dell5KEdgeSystem. :param name: Dell5KEdgeSystem name """ super(Dell5KEdgeSystem, self).__init__( name=name, entity_id=systemUUID().get_uuid(name) )
def __init__(self, name): """ Init method for SimulatedEdgeSystem. :param name: SimulatedEdgeSystem name """ super(SimulatedEdgeSystem, self).__init__( name=name, entity_id=systemUUID().get_uuid(name) )
def __init__(self, remote_system_identity, edge_system_identity, tls_details, qos_details, url, port, client_id="", clean_session=False, userdata=None, protocol="MQTTv311", transport="tcp", keep_alive=60, enable_authentication=False, conn_disconn_timeout=10): """ :param remote_system_identity: remote_system_identity object :param edge_system_identity: EdgeSystemIdentity object :param tls_details: TLSDetails object :param qos_details: QoSDetails object :param url: MQTT Broker URL or IP :param port: MQTT Broker Port :param client_id: Client ID :param clean_session: Connect with Clean session or not :param userdata: userdata is user defined data of any type that is passed as the "userdata" parameter to callbacks. :param protocol: allows explicit setting of the MQTT version to use for this client :param transport: Set transport to "websockets" to use WebSockets as the transport mechanism. Set to "tcp" to use raw TCP, which is the default. :param keep_alive: KeepAliveInterval :param enable_authentication: Enable user-name password authentication or not :param conn_disconn_timeout: Connect-Disconnect-Timeout """ self.remote_system_identity = remote_system_identity self.edge_system_identity = edge_system_identity self.tls_details = tls_details self.url = url self.port = port self.keep_alive = keep_alive self.qos_details = qos_details self.enable_authentication = enable_authentication self._conn_disconn_timeout = conn_disconn_timeout if clean_session: # If user passes client_id, it'll be used. Otherwise, it is left to the underlying paho # to generate random client_id self._paho_client = paho.Client(client_id, clean_session=True, userdata=userdata, protocol=getattr(paho, protocol), transport=transport) else: # client_id given by user if client_id is not None and (client_id != ""): self._paho_client = paho.Client(client_id, clean_session=False) else: # local-uuid of the gateway will be the client name self._paho_client = paho.Client(client_id=systemUUID().get_uuid(edge_system_identity.edge_system_name), clean_session=False, userdata=userdata, protocol=getattr(paho, protocol), transport=transport) self._connect_result_code = sys.maxsize self._disconnect_result_code = sys.maxsize self._paho_client.on_message = self.on_message self._paho_client.on_publish = self.on_publish self._paho_client.on_subscribe = self.on_subscribe self._paho_client.on_connect = self.on_connect self._paho_client.on_disconnect = self.on_disconnect self.connect_soc()
class PackageClass(LiotaPackage): def run(self, registry): """ The execution function of a liota package. Acquires "iotcc_mqtt" and "iotcc_mqtt_edge_system" from registry then register five devices and publishes device metrics to the DCC :param registry: the instance of ResourceRegistryPerPackage of the package :return: """ from liota.entities.devices.device import Device from liota.entities.metrics.metric import Metric import copy log.info("-----------beging register device with:" + device_name + "--" +device_metric_name) # Acquire resources from registry self.iotcc = registry.get("iotcc_mqtt") # Creating a copy of edge_system object to keep original object "clean" self.iotcc_edge_system = copy.copy(registry.get("iotcc_mqtt_edge_system")) self.reg_devices = [] self.metrics = [] try: # Register device device = Device(device_name,systemUUID().get_uuid(device_name),"edgexfoundry") log.info("Registration Started for Device".format(device.name)) # Device Registration reg_device = self.iotcc.register(device) self.reg_devices.append(reg_device) self.iotcc.create_relationship(self.iotcc_edge_system, reg_device) # Use the device name as identifier in the registry to easily refer the device in other packages device_registry_name = device_name registry.register(device_registry_name, reg_device) log.info("----------------relation success:"+str(device_name)+"----------------------") self.iotcc.set_properties(reg_device, {"Country": "USA-G", "State": "California", "City": "Palo Alto", "Location": "VMware HQ", "Building": "Promontory H Lab", "Floor": "First Floor"}) try: # Registering Metric for Device metric_name = device_metric_name + "_metrics" metric_simulated_received = Metric(name=metric_name, unit=None, interval=5, aggregation_size=1, sampling_function=device_metric) reg_metric_simulated_received = self.iotcc.register(metric_simulated_received) self.iotcc.create_relationship(reg_device, reg_metric_simulated_received) reg_metric_simulated_received.start_collecting() log.info("--------------relation metics:"+device_metric_name+"----------------------") self.metrics.append(reg_metric_simulated_received)
def __init__(self, name, entity_type="SimulatedDevice"): """ Init method for SimulatedDevice. :param name: SimulatedDevice name :param entity_type: Entity type which is "SimulatedDevice" """ super(SimulatedDevice, self).__init__(name=name, entity_type=entity_type, entity_id=systemUUID().get_uuid(name))
def __init__(self, name, entity_type="SimulatedDevice"): """ Init method for SimulatedDevice. :param name: SimulatedDevice name :param entity_type: Entity type which is "SimulatedDevice" """ super(SimulatedDevice, self).__init__( name=name, entity_type=entity_type, entity_id=systemUUID().get_uuid(name) )
def __init__(self, name, interval=1): super(SimulatedDevice, self).__init__(name=name, entity_id=systemUUID().get_uuid(name), entity_type="SimulatedDevice") self.mqtt = MqttDeviceComms(url="test.mosquitto.org", port=1883, clean_session=True, conn_disconn_timeout=1000) print('Connection to broker established...') self.interval = interval self.randomVar = 0 self.run()
def __init__(self, name, u=5.0, r0=3000, interval=5, ureg=None): super(ThermistorSimulated, self).__init__( name=name, entity_id=systemUUID().get_uuid(name), entity_type="ThermistorSimulated" ) self.u = u # Total voltage self.r0 = r0 # Reference resistor self.ux = self.u / 2 # Initial voltage on thermistor self.c1 = 1.40e-3 self.c2 = 2.37e-4 self.c3 = 9.90e-8 self.interval = interval self.ureg = None if isinstance(ureg, pint.UnitRegistry): self.ureg = ureg else: self.ureg = pint.UnitRegistry()
def test_init_implementation_without_msg_attr( self, mocked_init, mocked_declare_publish_exchange): """ Test AmqpDccComms implementation without publish messaging attributes. :param mocked_init: Mocked init from Amqp class :param mocked_init: Mocked declare_publish_exchange from Amqp class :return: None """ # Mocked init method mocked_init.return_value = None # Instantiate client for DCC communication self.amqp_client = AmqpDccComms( edge_system_name=self.edge_system.name, url=self.url, port=self.port, enable_authentication=self.enable_authentication, tls_conf=self.tls_conf, identity=self.identity, connection_timeout_sec=self.connection_disconnect_timeout_sec) # Read uuid.ini self.config.read(self.uuid_file) edge_system_name = self.config.get('GATEWAY', 'name') local_uuid = self.config.get('GATEWAY', 'local-uuid') # Compare stored edge system name self.assertEquals(edge_system_name, self.edge_system.name) # Compare stored client-id self.assertEquals(local_uuid, systemUUID().get_uuid(self.edge_system.name)) # Check Amqp init called method call has been made mocked_init.assert_called_with(self.url, self.port, self.identity, self.tls_conf, self.enable_authentication, self.connection_disconnect_timeout_sec) # Check declare publish exchange has been called mocked_declare_publish_exchange.assert_called_with( self.amqp_client.pub_msg_attr)
def __init__(self, name, entity_type="Metric", unit=None, interval=60, aggregation_size=1, sampling_function=None): if not (unit is None or isinstance(unit, pint.unit._Unit)) \ or not ( isinstance(interval, int) or isinstance(interval, float) ) \ or not isinstance(aggregation_size, int): raise TypeError() super(Metric, self).__init__(name=name, entity_id=systemUUID().get_uuid(name), entity_type=entity_type) self.unit = unit self.interval = interval self.aggregation_size = aggregation_size self.sampling_function = sampling_function
def __init__(self, name, entity_type="Metric", unit=None, interval=60, aggregation_size=1, sampling_function=None ): if not (unit is None or isinstance(unit, pint.unit._Unit)) \ or not ( isinstance(interval, int) or isinstance(interval, float) ) \ or not isinstance(aggregation_size, int): raise TypeError() super(Metric, self).__init__( name=name, entity_id=systemUUID().get_uuid(name), entity_type=entity_type ) self.unit = unit self.interval = interval self.aggregation_size = aggregation_size self.sampling_function = sampling_function
def __init__(self, name, wheel=26, m_bike=20, m_rider=80, m_load=0, interval=5, ureg=None): super(BikeSimulated, self).__init__( name=name, entity_id=systemUUID().get_uuid(name), entity_type="BikeSimulated" ) self.slope = 0.0 # rad self.radius_wheel = wheel # inch self.weight_bike = m_bike # kg self.weight_rider = m_rider # kg self.weight_load = m_load # kg self.revolution = 0.0 # rpm self.area = 1.0 # m ** 2 self.interval = interval self.ureg = None if isinstance(ureg, pint.UnitRegistry): self.ureg = ureg else: self.ureg = pint.UnitRegistry() self.time_last = None self.run()
def __init__(self, name, device_mac, entity_type="Device"): Device.__init__(self, name=name, entity_type=entity_type, entity_id=systemUUID().get_uuid(name)) SensorTag.__init__(self, addr=device_mac)
def __init__(self, edge_system_name, url, port, identity=None, tls_conf=None, qos_details=None, client_id="", clean_session=False, protocol="MQTTv311", transport="tcp", keep_alive=60, mqtt_msg_attr=None, enable_authentication=False, conn_disconn_timeout=10): """ :param edge_system_name: EdgeSystem's name for auto-generation of topic :param url: MQTT Broker URL or IP :param port: MQTT Broker Port :param tls_conf: TLSConf object :param identity: Identity object :param qos_details: QoSDetails object :param client_id: Client ID :param clean_session: Connect with Clean session or not :param userdata: userdata is user defined data of any type that is passed as the "userdata" parameter to callbacks. :param protocol: allows explicit setting of the MQTT version to use for this client :param transport: Set transport to "websockets" to use WebSockets as the transport mechanism. Set to "tcp" to use raw TCP, which is the default. :param keep_alive: KeepAliveInterval :param mqtt_msg_attr: MqttMessagingAttributes object or None. In case of None, topics will be auto-generated. User provided topic will be used otherwise. :param enable_authentication: Enable user-name password authentication or not :param conn_disconn_timeout: Connect-Disconnect-Timeout """ self.client_id = client_id if mqtt_msg_attr is None: # pub-topic and sub-topic will be auto-generated log.info("pub-topic and sub-topic is auto-generated") self.msg_attr = MqttMessagingAttributes(edge_system_name) if self.client_id is None or self.client_id == "": # local_uuid generated will be the client ID self.client_id = systemUUID().get_uuid(edge_system_name) log.info("generated local uuid will be the client ID") else: log.info("Client ID is provided by user") # Storing edge_system name and generated local_uuid which will be used in auto-generation of pub-sub topic store_edge_system_uuid(entity_name=edge_system_name, entity_id=self.client_id, reg_entity_id=None) elif isinstance(mqtt_msg_attr, MqttMessagingAttributes): log.info("User configured pub-topic and sub-topic") self.msg_attr = mqtt_msg_attr else: log.error("mqtt_mess_attr should either be None or of type MqttMessagingAttributes") raise TypeError("mqtt_mess_attr should either be None or of type MqttMessagingAttributes") self.url = url self.port = port self.identity = identity self.tls_conf = tls_conf self.qos_details = qos_details self.clean_session = clean_session self.userdata = Queue.Queue() self.protocol = protocol self.transport = transport self.keep_alive = keep_alive self.enable_authentication = enable_authentication self.conn_disconn_timeout = conn_disconn_timeout self._connect()
def __init__(self, name, entity_type="SimulatedDevice"): super(SimulatedDevice, self).__init__( name=name, entity_type=entity_type, entity_id=systemUUID().get_uuid(name) )
def __init__(self, name): super(Dell5KEdgeSystem, self).__init__( name=name, entity_id=systemUUID().get_uuid(name) )
def __init__(self, name): super(Dell5KEdgeSystem, self).__init__(name=name, entity_id=systemUUID().get_uuid(name))
def __init__(self, edge_system_name, url, port, identity=None, tls_conf=None, qos_details=None, client_id="", clean_session=False, protocol="MQTTv311", transport="tcp", keep_alive=60, mqtt_msg_attr=None, enable_authentication=False, conn_disconn_timeout=10): """ :param edge_system_name: EdgeSystem's name for auto-generation of topic :param url: MQTT Broker URL or IP :param port: MQTT Broker Port :param tls_conf: TLSConf object :param identity: Identity object :param qos_details: QoSDetails object :param client_id: Client ID :param clean_session: Connect with Clean session or not :param userdata: userdata is user defined data of any type that is passed as the "userdata" parameter to callbacks. :param protocol: allows explicit setting of the MQTT version to use for this client :param transport: Set transport to "websockets" to use WebSockets as the transport mechanism. Set to "tcp" to use raw TCP, which is the default. :param keep_alive: KeepAliveInterval :param mqtt_msg_attr: MqttMessagingAttributes object or None. In case of None, topics will be auto-generated. User provided topic will be used otherwise. :param enable_authentication: Enable user-name password authentication or not :param conn_disconn_timeout: Connect-Disconnect-Timeout """ self.client_id = client_id if mqtt_msg_attr is None: # pub-topic and sub-topic will be auto-generated log.info("pub-topic and sub-topic is auto-generated") self.msg_attr = MqttMessagingAttributes(edge_system_name) if self.client_id is None or self.client_id == "": # local_uuid generated will be the client ID self.client_id = systemUUID().get_uuid(edge_system_name) log.info("generated local uuid will be the client ID") else: log.info("Client ID is provided by user") # Storing edge_system name and generated local_uuid which will be used in auto-generation of pub-sub topic store_edge_system_uuid(entity_name=edge_system_name, entity_id=self.client_id, reg_entity_id=None) elif isinstance(mqtt_msg_attr, MqttMessagingAttributes): log.info("User configured pub-topic and sub-topic") self.msg_attr = mqtt_msg_attr else: log.error( "mqtt_mess_attr should either be None or of type MqttMessagingAttributes" ) raise TypeError( "mqtt_mess_attr should either be None or of type MqttMessagingAttributes" ) self.url = url self.port = port self.identity = identity self.tls_conf = tls_conf self.qos_details = qos_details self.clean_session = clean_session self.userdata = Queue.Queue() self.protocol = protocol self.transport = transport self.keep_alive = keep_alive self.enable_authentication = enable_authentication self.conn_disconn_timeout = conn_disconn_timeout self._connect()
def __init__(self, name): super(SierraWirelessEdgeSystem, self).__init__(name=name, entity_id=systemUUID().get_uuid(name))