#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Client paho-mqtt MqttServer
# main.py
import paho.mqtt.publish as publish
from json import dumps
from ssl import PROTOCOL_TLSv1
import urllib2
class MqttClient():
host = 'mqtt.xyz.com'
port = '1883'
auth = {}
topic = '%s/streams'
tls = None
def __init__(self, auth, tls=None):
self.auth = auth
self.topic = '%s/streams' % auth['username']
if tls:
self.tls = tls
self.port = '8883'
def publish(self, msg):
try:
publish.single (topic=self.topic,payload=msg,hostname=self.host,
tls=self.tls,port=self.port)
except Exception, ex:
print ex
if __name__ == '__main__':
auth = {'username': 'your username', 'password': ''}
#tls_dict = {'ca_certs': 'ca_certs.crt', 'tls_version': PROTOCOL_TLSv1} # sslvers.
msg_dict={'protocol':'v2','device':'Development Device','at':'now','data':{'temp':21,'hum':58}}
client_mqtt =MqttClient(auth=auth) # non ssl version
#client_mqtt =MqttClient(auth=auth, tls=tls_dict) # ssl version
client_mqtt.publish(dumps(msg_dict))
I guess my organization's proxy settings are blocking the request, so please guide me in including the proxy settings in the above code.
For instance if address is 'proxy.xyz.com' and port number is '0000' and my network username is 'xyz' and password is 'abc'