1
0
mirror of https://github.com/balkian/mqtt-poc.git synced 2024-12-22 04:48:12 +00:00
mqtt-poc/python-clients/mqtt-producer.py
J. Fernando Sánchez a1e0d0b4b0 First commit
2018-02-22 17:38:21 +01:00

20 lines
402 B
Python

import paho.mqtt.publish as publish
import os
import time
import socket
HOSTNAME = socket.gethostname()
HOST = os.environ.get('MQTT_HOST', 'localhost')
print('Connecting to %s' %HOST)
topic = "/gsi/test/multiple"
i = 0
while True:
print('%s pushing msg %s' %(HOSTNAME, i))
publish.single(topic=topic, payload='%s says %s' %(HOSTNAME, i), qos=1, hostname=HOST)
i += 1
time.sleep(2)