title: MQTT IoT smart plug in Python
body: <p>I am totally new in IoT and I have a code exercise for my university. I don't know how to connect this script in order to connect to MQTT and run without errors.</p>
  <p>How can I connect with MQTT? The script is the following:</p>
  <pre><code>import paho.mqtt.client as mqtt
  import ssl
  import os
  import sys
  
  import matplotlib.pyplot as plt
  from matplotlib.widgets import Button
  from threading import Timer
  from datetime import datetime
  
  class IoTExample:
      def __init__(self):
          self._establish_mqtt_connection()
  
      def start(self):
          self.client.loop_forever() 
      
      def disconnect(self, args=None):
          self.client.disconnect()
  
      def _establish_mqtt_connection(self):
          self.client = mqtt.Client
          self.client.on_log = self._on_log
          client.username_pw_set('iotlesson', 'YGK0tx5pbtkK2WkCBvJlJWCg')
          self.client.connect('phoenix.medialab.ntua.gr', 8883)
          client.subscribe('hscnl/hscnl02/state/ZWaveNode005_Switch/state')
          self.client.publish('hscnl/hscnl02/sendcommand/ZWaveNode005_Switch', 'ON')
          self.client.loop_forever()
  
      def _on_connect(self, client, userdata, flags, rc):
          self.client.on_connect = self._on_connect
  
      def _on_message(self, client, userdata, msg):
          self.client.on_message = self.on_message
          print(msg.topic+' '+str(msg.payload))
  
      def _on_log(self, client, userdata, level, buf):
          self.client.on_log = self._on_log
          print('log: ', buf)
  
  try:
      iot_example = IoTExample()
      iot_example.start()
  except KeyboardInterrupt:
      print('Interrupted')
      try:
          iot_example.disconnect()
          sys.exit(0)
      except SystemExit:
          os._exit(0)
  </code></pre>
  <p>I got the following errors:</p>
  <pre><code>python /home/mina/paho.mqtt.python/iot_example.py
  Traceback (most recent call last):
    File &quot;/home/mina/paho.mqtt.python/iot_example.py&quot;, line 41, in &lt;module&gt;
      iot_example = IoTExample()
    File &quot;/home/mina/paho.mqtt.python/iot_example.py&quot;, line 13, in __init__
      self._establish_mqtt_connection()
    File &quot;/home/mina/paho.mqtt.python/iot_example.py&quot;, line 24, in _establish_mqtt_connection
      self.client.connect('phoenix.medialab.ntua.gr', 8883)
  TypeError: unbound method connect() must be called with Client instance as first argument (got str instance instead)
  </code></pre>