mqtt_instrument

Classes

MQTTInstrument(*args, **kwargs)

MQTTInstrument

class icicle.mqtt_instrument.MQTTInstrument(*args, **kwargs)

Bases: Instrument

__init__(resource, **kwargs)

must be explicitly specified - failing to do so will result in an error since the Multiton metaclass on VisaInstrument masks this default value for resource.

Parameters:
  • resource – VISA Resource address. See VISA docs for more info.

  • **username – username for the mqtt server (default=””)

  • **password – password for the mqtt server (default=””)

  • **init – whether to initialize the coldbox (default=False)

  • **sim – whether to simulate the instrument (default=False)

  • **ssl – whether to use ssl (default=False)

  • **clientID – mqtt clientID (default=”ICICLE::MQTTInstrument”)

TIMEOUT = 10

MQTT maximum waiting time for query

connect() None

Connects the client to a broker. Does nothing if simulating

connected() bool

Returns if the connection to MQTTInstrument is active.

disconnect() None

Disconnects the client from a broker.

execute(topic, msg) None

Sends a message from the client to the broker.

Parameters:
  • topic – A string specifying the topic the message should be published on.

  • msg – A string specifying the message to send. Passing an int or float will result in the message being converted to a string.

loop_forever() None

Loop client forever. Handles reconnecting automatically. Loop will not return until client calls disconnect()`.

loop_start() None

Start client loop. Handles reconnecting automatically.

loop_stop() None

Stop client loop.

simulate(topic, msg) None

Simulates sending a message from the client to the broker. Needs defined simulation entry point for class.

Parameters:
  • topic – A string specifying the topic the message should be published on.

  • msg – A string specifying the message to send. Passing an int or float will result in the message being converted to a string.

subscribe(topic) None

Subscribes the client to a topic.

Parameters:

topic – A string specifying the topic to subscribe to.

update(msg)

Handle to be called by on_connect. Supposed to be overwritten by child classes accordingly.

Parameters:

msg – A string specifying the message received.