Paho Python Client with HiveMQ

2024/10/14 21:18:05

i am developing a module in python that will allow me to connect my raspberry pi to a version of hivemq hosted on my pc.

it connects normally but when i add hivemq's file auth plugin it doesnt seem to work

im using the username_pw_set to set my username and password

here is what my code currently looks like:

import paho.mqtt.client as mqtt
client = mqtt.Client()#The callback for when the client recieves a CONNACK response from the server
def on_connect(client, userdata, flags, rc):print("connected with the result code "+str(rc))#Define any topics you would like the pi to
#automatically subscribe to here#The callback for when this client publishes to the server.
def on_publish(client, userdata, mid):print("message published")#The callback for when a PUBLISH message is recieve from the server.
def on_message(client, userdata, msg):print(msg.topic+" "+str(msg.payload))def on_log(client, userdata, level, buf):print(str(level)+" "+str(buf))#set callbacks
def setup():client.on_connect = on_connectclient.on_message = on_messageclient.on_publish = on_publishclient.on_log = on_log#setup connection to broker
def connect(username, password):client.username_pw_set(username, password)client.connect("10.19.109.152")def publish(topic, message):client.publish(topic, message)def loop():client.loop()

could it be something to do with the way the python client formats the connect request?

Edit:

Server gives me error message:

2015-11-26 09:50:53,723 ERROR - Could not get valid results from the webservice
org.apache.http.NoHttpResponseException: The target server failed to respondat org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(Default
HttpResponseParser.java:143)

and my client(on_connect function) outputs a connack message with code 5 which is for refused connection as its not authorised.

Answer

The error from hivemq states that the http server you have pointed it at to do the authentication has not responded.

You should check that those details are correct and that it responds as expected when you use something like curl to test it.

https://en.xdnf.cn/q/117907.html

Related Q&A

Comparison of value items in a dictionary and counting matches

Im using Python 2.7. Im trying to compare the value items in a dictionary.I have two problems. First is the iteration of values in a dictionary with a length of 1. I always get an error, because python…

how to send cookies inside post request

trying to send Post request with the cookies on my pc from get request #! /usr/bin/python import re #regex import urllib import urllib2 #get request x = urllib2.urlopen("http://www.example.com) #…

Flask-Uploads gives AttributeError?

from flask import Flask from flask.ext.uploads import UploadSet, configure_uploads, IMAGESapp = Flask(__name__)app.config[UPLOADED_PHOTOS_DEST] = /home/kevin photos = UploadSet(photos, IMAGES)configure…

Python: Alternate way to covert from base64 string to opencv

Im trying to convert this string in base64 (http://pastebin.com/uz4ta0RL) to something usable by OpenCV. Currently I am using this code (img_temp is the string) to use the OpenCV functions by convertin…

Move 3D plot to avoid clipping by margins

Im trying to figure out how I can get the 3D matplotlib images below to plot higher on the canvas so it doesnt get clipped. Here is the code Im using to create the plot. I couldnt find a way to attach …

HTML Link parsing using BeautifulSoup

here is my Python code which Im using to extract the Specific HTML from the Page links Im sending as parameter. Im using BeautifulSoup. This code works fine for sometimes and sometimes it is getting st…

XML format change using XSL file in a Python code

Have written a Python code to transform a XML file to a particular format using XSL stylesheet. Python code below:#!/usr/bin/env python # -*- coding:utf-8 -*- from lxml import etree def transform(xmlP…

How to extract a specific value from a dictionary in python

I want to extract distance from google distance matrix API in Python. The objet it returned is a python dictionary.{destination_addresses: [Mumbai, Maharashtra, India ],origin_addresses: [Powai, Mumbai…

label on top of image in python

I am trying to display text on top of an image. Right now the text is below the image or if I put a row=0 in the grid disappears. I am assuming it is behind the image. I cant seem to get it to work. My…

plot multiple graphs from multiple files gnuplot

I have a set of files named like this:qd-dPZ-z1-1nn.dat qd-dPZ-z2-1nn.dat qd-dPZ-z4-1nn.dat qd-dPZ-z8-1nn.dat qd-dPZ-z16-1nn.dat qd-dPZ-z32-1nn.dat qd-dPZ-z1-2nn.dat qd-dPZ-z2-2nn.dat qd-dPZ-z4…