0

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_connect
  client.on_message = on_message
  client.on_publish = on_publish
  client.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 respond
    at 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.

Jensen
  • 43
  • 1
  • 3
  • 11
  • Do you get any error messages, either on the client end or in the logs of the hivemq instance? – hardillb Nov 25 '15 at 16:14
  • Please edit the original question to include updates as things don't format well in comments. But that error implies that the broker can not find HTTP server so have you configured a http auth not file based auth? – hardillb Nov 26 '15 at 09:57
  • @hardillb sorry. ive updated the question with the server and client outputs! – Jensen Nov 26 '15 at 10:05
  • @hardillb also yes it is http auth. sorry or the late reply did not notice the question. – Jensen Nov 26 '15 at 10:25
  • What HiveMQ plugin is used for authentication? Where did you download the plugin? Did you download it from http://www.hivemq.com/plugins/ ? – Dominik Obermaier Nov 26 '15 at 13:22
  • No, it is one developed partly by me for a company i work for! @DominikObermaier – Jensen Nov 27 '15 at 12:11
  • I think the problem i am having is the way the paho client library formats the connect request. i can send a cURL request and other devices connect. just cant connect with a raspberry pi and python @DominikObermaier – Jensen Nov 27 '15 at 12:13

1 Answers1

0

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.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • the thing is i have other devices that connect using the same information that my raspberry pi is using! so i dont think its the details. the cURL did return an "unautorized" message though... – Jensen Nov 26 '15 at 11:29