import random
import time
import mosquitto

timestamp = int(time.time())

broker = '127.0.0.1'
port = 1883
element = 'home'
areas = ['front', 'back', 'kitchen', 'basement', 'living']
entrances = ['door', 'window']
states = ['true', 'false']

print 'Messages are published on topic %s/#... -> CTRL + C to shutdown' \
    % element

while True:
    area = random.choice(areas)
    if (area in ['basement', 'living']):
        topic = element + '/' + area + '/temp'
        message = random.randrange(0, 30, 1)
    else:
        topic = element + '/' + area + '/' + random.choice(entrances)
        message = random.choice(states)

    client = mosquitto.Mosquitto("mqtt-panel-test")
    client.connect(broker)
    client.publish(topic, message)
    time.sleep(2)

import random
import time
import paho.mqtt.client as mqtt

timestamp = int(time.time())

broker = '127.0.0.1'
port = 1883
element = 'home'
areas = ['front', 'back', 'kitchen', 'basement', 'living']
entrances = ['door', 'window']
states = ['true', 'false']

print('Messages are published on topic %s/#... -> CTRL + C to shutdown' \
    % element)

while True:
    area = random.choice(areas)
    if (area in ['basement', 'living']):
        topic = element + '/' + area + '/temp'
        message = random.randrange(0, 30, 1)
    else:
        topic = element + '/' + area + '/' + random.choice(entrances)
        message = random.choice(states)

    mqttclient = mqtt.Client("mqtt-panel-test")
    mqttclient.connect(broker, port=int(port))
    mqttclient.publish(topic, message)
    time.sleep(2)


Switch to paho-mqtt and make ready for py3
Switch to paho-mqtt and make ready for py3

  import random
  import time
- import mosquitto
+ import paho.mqtt.client as mqtt
  
  timestamp = int(time.time())
  
  broker = '127.0.0.1'
  port = 1883
  element = 'home'
  areas = ['front', 'back', 'kitchen', 'basement', 'living']
  entrances = ['door', 'window']
  states = ['true', 'false']
  
- print 'Messages are published on topic %s/#... -> CTRL + C to shutdown' \
+ print('Messages are published on topic %s/#... -> CTRL + C to shutdown' \
-     % element
+     % element)
  
  while True:
      area = random.choice(areas)
      if (area in ['basement', 'living']):
          topic = element + '/' + area + '/temp'
          message = random.randrange(0, 30, 1)
      else:
          topic = element + '/' + area + '/' + random.choice(entrances)
          message = random.choice(states)
  
-     client = mosquitto.Mosquitto("mqtt-panel-test")
+     mqttclient = mqtt.Client("mqtt-panel-test")
-     client.connect(broker)
+     mqttclient.connect(broker, port=int(port))
-     client.publish(topic, message)
+     mqttclient.publish(topic, message)
      time.sleep(2)
  
+ 
Switch to paho-mqtt and make ready for py3
## Code Before:
import random
import time
import mosquitto

timestamp = int(time.time())

broker = '127.0.0.1'
port = 1883
element = 'home'
areas = ['front', 'back', 'kitchen', 'basement', 'living']
entrances = ['door', 'window']
states = ['true', 'false']

print 'Messages are published on topic %s/#... -> CTRL + C to shutdown' \
    % element

while True:
    area = random.choice(areas)
    if (area in ['basement', 'living']):
        topic = element + '/' + area + '/temp'
        message = random.randrange(0, 30, 1)
    else:
        topic = element + '/' + area + '/' + random.choice(entrances)
        message = random.choice(states)

    client = mosquitto.Mosquitto("mqtt-panel-test")
    client.connect(broker)
    client.publish(topic, message)
    time.sleep(2)

## Instruction:
Switch to paho-mqtt and make ready for py3
## Code After:
import random
import time
import paho.mqtt.client as mqtt

timestamp = int(time.time())

broker = '127.0.0.1'
port = 1883
element = 'home'
areas = ['front', 'back', 'kitchen', 'basement', 'living']
entrances = ['door', 'window']
states = ['true', 'false']

print('Messages are published on topic %s/#... -> CTRL + C to shutdown' \
    % element)

while True:
    area = random.choice(areas)
    if (area in ['basement', 'living']):
        topic = element + '/' + area + '/temp'
        message = random.randrange(0, 30, 1)
    else:
        topic = element + '/' + area + '/' + random.choice(entrances)
        message = random.choice(states)

    mqttclient = mqtt.Client("mqtt-panel-test")
    mqttclient.connect(broker, port=int(port))
    mqttclient.publish(topic, message)
    time.sleep(2)

