MQTT works in the pi terminal but not with Mycodo

I have an ESP32 sending sensor readings over MQTT to my raspberry pi that I have hosting my Mycodo server as well as being my MQTT broker. I can successfully get readings by subscribing to the topic on my pi’s terminal, but can’t get Mycodo to get readings from MQTT. I’m using the same IP and port that works for my ESP32 to connect to MQTT, but they have unique clientIDs. Can anyone offer some advice on this?

I’m using a pi 4 with all hardware on my LAN

These are my Mycodo logs:

2024-10-16 19:14:14,571 - INFO - mycodo.controllers.controller_input_0c01eb9d - Deactivated in 583.4 ms
2024-10-16 19:19:00,797 - DEBUG - mycodo.inputs.mqtt_paho_0c01eb9d - Client created with ID Mycodo
2024-10-16 19:19:00,798 - DEBUG - mycodo.controllers.controller_input_0c01eb9d - get_measurement() not found
2024-10-16 19:19:00,799 - DEBUG - mycodo.controllers.controller_input_0c01eb9d - listener() found
2024-10-16 19:19:00,800 - DEBUG - mycodo.controllers.controller_input_0c01eb9d - Starting listener() thread.
2024-10-16 19:19:00,800 - DEBUG - mycodo.inputs.mqtt_paho_0c01eb9d - Connecting MQTT callback functions
2024-10-16 19:19:00,801 - INFO - mycodo.controllers.controller_input_0c01eb9d - Activated in 178.0 ms
2024-10-16 19:19:00,801 - DEBUG - mycodo.inputs.mqtt_paho_0c01eb9d - MQTT callback functions connected
2024-10-16 19:19:00,802 - ERROR - mycodo.inputs.mqtt_paho_0c01eb9d - Could not connect to mqtt host: XXX.XXX.XX.XXX:XXXX

I can’t think of any other info that would be necessary and relevant, please let me know if I should be including anything else.

What is the firmware that you are using on the ESP32? Is it Tasmota?

Please post a screenshot of the MQTT Input settings you are using on Mycodo.
Most likely you’ve incorrectly entered the JMESPATH or Subscription Topic of the remote device you are trying to pull telemetry from… or you didn’t enter the user/password for your broker in the Mycodo settings?

Are you using an MQTT GUI diagnostic app like MQTT Explorer to view the raw message data that is being received by your broker? https://mqtt-explorer.com/

You didn’t mention if you redacted this or you actually have Xs for the IP and port. If you don’t have the proper IP/port specified, that’s the issue. Not sure why you would react a LAN IP.

I believe I’m using nodeMCU-32S, this is what I select in my IDE for the board. I’m using this board with the default firmware. My apologies, I’m unsure of how to check my firmware and I couldn’t find a definite answer researching it, this is also my first MQTT project but I had my friend that’s a very skilled software engineer help me and he’s stumped as well.
Out of curiosity, why does my ESP firmware matter at this point? I can already get my pi to subscribe to the ESP topics in the terminal with the correct numerical readout, wouldn’t that mean that the issue is something with the pi and/or the Mycodo server?

I will post screenshots at the bottom. The IP I’m using is the IPv4 IP address on the pi, which is what I’m using to access the Mycodo webserver, connect the ESP32 to MQTT (works), connect Mycodo to MQTT (doesn’t work) and is the internal IP address for my pi listed on my router admin page.

I was not using an MQTT GUI tool. I just tried the one you linked and I cannot connect to my broker with it.

Thanks for the help!

ESP32 topics:

const char* temp_topic = "sensor/temperature";

const char* leaf_temp_topic = "sensor/leaf_temperature";

const char* humidity_topic = "sensor/humidity";

const char* dewpoint_topic = "sensor/dewpoint";

const char* vpd_topic = "sensor/vpd";

const char* co2_topic = "sensor/co2";

const char* luminosity_topic = "sensor/luminosity";

My apologies, I did redact my IP. I thought I was using it to access externally but I’m not. Sorry, I’m not too well versed in networking.

From my reply to Lucid3y3:

The IP I’m using is the IPv4 IP address on the pi, which is what I’m using to access the Mycodo webserver locally, connect the ESP32 to MQTT (works), connect Mycodo to MQTT (doesn’t work) and is the internal IP address for my pi listed on my router admin page.

Thanks for the help!

The reason I asked about the ESP32 firmware is because most of the time they only come with a very minimally functional firmware installed which isn’t useful for much except to show that the unit is working. There are far more functional and easier to use firmware options out there like ESPHome and Tasmota… I recommend Tasmota because it has a GUI interface that’s fairly easy to use and program for most use cases without having to edit the actual firmware in Arduino IDE or Visual Studio Code… but because it is such a powerful and feature rich firmware, there is a bit of a learning curve.

For now, since you say you have the ESP and all of the sensors you have attached to it successfully sending messages to your mqtt broker, we’ll focus on the Mycodo settings.

Are you using Mosquitto Broker?
When you setup the MQTT broker, did you setup a user and password? It’s not necessary unless you plan on sending data to another network or across the internet, but if you did setup a password, you’ll need to enter that info into the Mycodo Input settings to access the MQTT server even though it’s running on the same Pi as Mycodo.

Any reason why you have the “Use Websockets” box checked? Did you specifically setup the broker to use the websockets protocol? If not, uncheck that Use Websockets box and try to see if your measurements show up in Mycodo.

If you can not connect to your mqtt broker using MQTT Explorer, that suggests that you may have an access problem to the broker (like a password). What happens when you try to connect to your broker with mqtt explorer? Are there any error messages that may indicate what the problem is?
Just to clarify, you are running the MQTT Explorer app on your desktop computer, not the Pi, right?
You should also be accessing the Mycodo interface from a browser on your desktop computer, not locally from a browser on the Pi… if you are running the desktop version of the Pi OS, you really shouldn’t be… the Pi that is running Mycodo should be running the LITE OS version (no desktop).

Here is a quick guide I use when setting up Mosquito, so you can compare to how you set it up.

1 Like

Wow it was the websockets :man_facepalming:. Very good to know about the different firmwares, I’ll keep that in mind and do some research. Everything I know on coding are from a couple college classes that used arduino very lightly to explore electrical phenomena that they were teaching us, and everything I’ve learned on my own with my own projects. Might be time to move away from Arduino IDE and just using the default settings.

I did not know that I had to specifically configure my broker for websockets, that was it. I see in MQTT explorer, I can switch between mqtt:// and ws:// when setting up to connect to a broker, I’m guessing that means websockets.

I’m still unsure of why I couldn’t connect MQTT explorer before. I just now retyped my IP back into it, exactly how I had it as far as I could tell, and now it works. Didn’t change any settings or anything, just retyped the IP.

And I was doing everything remotely, ssh to the pi to write to the terminal on the pi from my computer, access Mycodo from my pc and phone(off my home network), etc.

I knew it was something ridiculously simple sitting right in front of my face. I thought I had tried changing each of those settings 1 by 1 to see if they fixed the issue, but I guess I hadn’t.

Thank you so much for the help, I really appreciate all of it and will certainly be coming back to this thread for further research!

1 Like

Gotcha thank you! It was actually having websockets on when I shouldn’t have.

I appreciate all the help! And thank you for such an amazing platform and developing and staying active within the community!