Node-Red MQTT AND a Python MQTT script?

Does anyone know if it's possible to have Node-Red listening out for MQTT commands on a Raspberry Pi that's ALSO trying to use Mosquitto to PUBLISH MQTT messages?

Basically I've got a Raspberry Pi which is happily and successfully waiting for certain MQTT messages to come in and acting on them.

I'm now trying to debug why a Python script on the same Pi never seems to even attempt an MQTT broker connection and wondering if it's because Node-Red is already there, tying up the line?! Just a theory and possibly a wrong headed one!

Thanks

Doesn't matter where the MQTT broker is. Installing MQTT on the same Pi that runs NR is something that many people (including myself) do.

A program can both publish and subscribe to MQTT topics. It does so by attachng to a MQTT Broker.

As long as they both use the same broker, there shouldn't be a problem

Also two applications (node red and a python program) both connecting to the same instance of mosquitto should not be a problem.

...but they do NEED to have unique client id's, otherwise they will be kicked in and out, in and out,,,,etc etc.

So in your python script, I would recommend to do the mqtt client connection so that you will get a randomized id

1 Like

Thank you all, you've been really helpful and unbelievably quick about it too. Wow.

OK, so back to my problem, I think you've roundly and comprehensively confirmed that I'm going to have to look elsewhere on my setup for the cause of my woes. I had hoped I might have found the start of unravelling it!

The problem is this particular python script seemingly can't be called directly (just results in a load of errors) and seems only to be able to be called from another script, as it then has all the arguments it needs and it gets its config file passed correctly.

The script is this one - I figure if I could call it directly I could read its output directly and see what's amiss.

Thanks for all help :slight_smile:

That script belongs in an Asterisk setup. AFIK, Asterisk is a service for running your own PBX (phone system). It isn't meant to be called stand-alone.