Open ghost opened 11 years ago
Hi Florian,
Apologies for the delay. I've just tested it, and it appears to connect.
Can you set debug = True in mqtt-republisher.cfg, and try again as root. Attach the output of /var/log/mqtt-republisher.log as well please. With debug = True it should say "Looping" repeatedly in the log.
Can you also copy and paste all the output from running sudo ./mqtt-republisher.py please?
Regards
Kyle
Hello Kyle, thank you for your answer. When I ran your code 'out of the box' with mosquitto installed, it was throwing the following:
Traceback (most recent call last):
File "/Users/florianpuget/my_code/MQTT_tests/mqtt-republisher.py", line 137, in
I have fixed that by removing the 'True' in result = mqttc.connect(MQTT_HOST, MQTT_PORT, 60, True) line 60.
Then I was facing another error:
Traceback (most recent call last):
File "/Users/florianpuget/my_code/MQTT_tests/mqtt-republisher.py", line 138, in
That I have fixed adding 2 more parameters to the methods on_connect(), on_disconnect() and on_message()
I am now questioning if we are using the same library.. :) Or I might simply be missing something..
Obviously I changed the map.csv file to match some test topics i could control but didn't get it to work..
But I still have to say a big thank you, because I am in the process of learning MQTT and python and your code was a great starting point for me, I especially like how you keep it neat linking to external files (.csv and .cfg).
If I can take advantage of your experience a little more and ask you another question :) I would like to set some logic for mqtt in python and publish it on a google app engine website, so it will do the parsing job from this server rather than from a locally hosted one. Any idea how I could get to run such a thing ? I am missing knowledge on how I can run a python script on a distant server basically.. I had a look on internet but was pretty unsuccessful this time. Any suggestion ?
Thanks a lot,
Florian
Update: I have found what was wrong eventually (once the two issues described above were resolved). My map.csv file was containing spaces, therefore it was publishing with a slightly wrong topic name ... :) Easy one, but it took me a while to find out..
..I am runninginto the same exact problem. Can you kindly share the script you've used or the changes you've made?
Here is the error I get
Connecting... /dev/ttyACM0
Traceback (most recent call last):
File "./serilScrape.py", line 71, in
Here is the script Used
import serial import mosquitto import os
serialdev = '/dev/ttyUSB0' broker = "127.0.0.1" port = 1883
def on_connect(rc): if rc == 0:
print "Connected" else: raise Exception
def on_publish(val): print "Published ", val
def cleanup(): print "Ending and cleaning up" ser.close() mqttc.disconnect()
try: print "Connecting... ", serialdev
ser = serial.Serial(serialdev, 9600, timeout=20) except: print "Failed to connect serial"
raise SystemExit
try: ser.flushInput()
mypid = os.getpid() client_uniq = "arduinopub"+str(mypid) mqttc = mosquitto.Mosquitto(client_uniq)
mqttc.on_connect = on_connect mqttc.on_publish = on_publish
mqttc.connect(broker, port, 60, True)
while mqttc.loop() == 0: line = ser.readline()
list = line.split(",")
temp = list[1].rstrip() mqttc.publish("arduino/temp", temp) pass
except (IndexError): print "No data received within serial timeout period" cleanup()
except (KeyboardInterrupt): print "Interrupt received" cleanup() except (RuntimeError): print "uh-oh! time to die" cleanup()
link to the script
hello, it has been quite a while i looked into this and unfortunately didn't have much time to maintain this homework.. so i really can't tell you off the hook. but if by any chance i come across the code i used then I'll take a look. cheers, flo On 2 Jul 2014 22:33, "antex22" notifications@github.com wrote:
link to the script
http://mqtt.org/wiki/doku.php/python_examples
— Reply to this email directly or view it on GitHub https://github.com/kylegordon/mqtt-republisher/issues/4#issuecomment-47839844 .
Hey,
That one seems vaguely familiar. Are you using the stock Mosquitto libs from your distribution repository? If so, try using the repos from http://mosquitto.org/download/
It seems familiar, as I originally wrote it on Debian, and then got bitten by their out of date mosquitto libraries!
Kyle
...You stated that "That I have fixed adding 2 more parameters to the methods on_connect(), on_disconnect() and on_message()"....can you elaborate on that. I think this is purely a python script issue.
I didn't state that - @flopupuj stated it, but is also short of time.
Did you do what I suggested, and use an up to date version of the Mosquitto libraries? What version are you on?
readserial.py by Andy Piper is coming up for 3 years old, and there have been significant changes since then. Specifically, the documentation at http://mosquitto.org/documentation/python/ states that 3 parameters can be passed to on_connect(), yet your library is reporting that only 1 can be passed.
I experienced this and fixed it with commit https://github.com/kylegordon/mqtt-republisher/commit/bb03171196e4190d4a2d7fb0e0c986f30128cad1 as it was indicative of an out of date library on my system.
Thanks for your prompt response! So I used the 'sudo apt-get install python-mosquitto' lib. I am using python 2.7. on Ubuntu. And I went to mosquitto.org/download page and add the mosquitto-dev PPA repsoitory, and did the apt-get update, and still getting the same error.
Thanks Kyle. You were right. The library is outdated. Installed the phao-mqtt lib
"Pip install paho-mqtt"
Used the paho lib instead of the "import osquitto"
"Import paho.mqtt.client as mqtt"
Edited the python script script some, and it works!
Matt
On Jul 3, 2014, at 5:55 AM, Kyle Gordon notifications@github.com wrote:
I didn't state that - @flopupuj stated it, but is also short of time.
Did you do what I suggested, and use an up to date version of the Mosquitto libraries? What version are you on?
readserial.py by Andy Piper is coming up for 3 years old, and there have been significant changes since then. Specifically, the documentation at http://mosquitto.org/documentation/python/ states that 3 parameters can be passed to on_connect(), yet your library is reporting that only 1 can be passed.
I experienced this and fixed it with commit bb03171 as it was indicative of an out of date library on my system.
— Reply to this email directly or view it on GitHub.
Hello, So I had a quick look but i am not sure if the file i found is the one error free.. I got the following headers (with arguments): on_message(self, topic, msg) on_connect(self, topic,result_code) on_disconnect(self, topic, result_code) hope this helps, i could try having a better look later ;)
Glad to hear you got it sorted!
For what it's worth, after you add a PPA in Ubuntu, you need to not only do an apt-get update, but also an apt-get upgrade. The update just updates your local list of available packages - the upgrade (or dist-upgrade) will actually install or upgrade things for you.
Nonetheless, you're working now :-)
Kyle
Hi Kyle, when using this code on my machine, with mosquitto installed (MAC OS X), it seems to connect with you test IP address 10.8.0.1, but when I try to connect to test.mosquitto.org (85.119.83.194) it simply fails to connect and throws me an error message from on_connect method. Any idea why ? Florian