# Emoncms cannot connect to mqtt server

**URL:** <https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229>\
**Category:** Emoncms\
**Created:** [10 December 2021 09:39 UTC](https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229 "2021-12-10T09:39:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariusl](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@mariusl](https://community.openenergymonitor.org/u/mariusl)\
**Post date:** [10 December 2021 09:39 UTC](https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229/1 "2021-12-10T09:39:38Z")

</div>

Hi  
I installed Emoncms on a VPS using the Debian install script. The following error is shown in the log  
2021-12-10 09:30:48.038|ERROR|emoncms\_mqtt.php|unexpected connection problem mqtt server:Connection Refused: not authorised.  
I used all the default usernames and passwords as the system installed. Any suggestions please?

From the terminal I do this  
sudo mosquitto\_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘emon/#’  
It sits and waits so I assume that it connected

Then with this  
sudo mosquitto\_sub -v -u ‘emoncms’ -P ‘emoncmsmqtt2016’ -t ‘emon/#’  
Connection Refused: not authorised.

---

<div class="post-metadata">

**Author:** ![TrystanLea](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/trystanlea/32/31_2.png) [@TrystanLea](https://community.openenergymonitor.org/u/TrystanLea)\
**Post date:** [11 December 2021 21:35 UTC](https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229/2 "2021-12-11T21:35:52Z")

</div>

Hello @mariusl I assume mosquitto is running ok?

This is the script that installs mosquitto and sets mosquitto.conf, might be worth checking that these steps applied ok…

> <https://github.com/openenergymonitor/EmonScripts/blob/master/install/mosquitto.sh>

---

<div class="post-metadata">

**Author:** ![mariusl](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@mariusl](https://community.openenergymonitor.org/u/mariusl)\
**Post date:** [13 December 2021 15:09 UTC](https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229/3 "2021-12-13T15:09:09Z")

</div>

I used the script that is supplied for Debian installation. I think Mosquitto is running fine but I will go through the steps that you suggested.

---

<div class="post-metadata">

**Author:** ![Vster](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/v/258eb7/32.png) [@Vster](https://community.openenergymonitor.org/u/Vster)\
**Post date:** [14 December 2021 11:31 UTC](https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229/4 "2021-12-14T11:31:14Z")

</div>

> [@mariusl](#):
>
> From the terminal I do this  
> sudo mosquitto\_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘emon/#’  
> It sits and waits so I assume that it connected

This is the terminal on the VPS?  
Is the log error is generated by that first mosquitto\_sub command? Or the second \_sub?

If it’s the second, then it’s probably correct.

The first line sitting and waiting it correct, it’s waiting for some incoming messages.  
If you log in to a second terminal (or use screen), then publish some data to mosquitto, it should show up in the first command.

---

<div class="post-metadata">

**Author:** ![mariusl](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@mariusl](https://community.openenergymonitor.org/u/mariusl)\
**Post date:** [14 December 2021 20:33 UTC](https://community.openenergymonitor.org/t/emoncms-cannot-connect-to-mqtt-server/19229/5 "2021-12-14T20:33:28Z")

</div>

I ended up re-installing the system. Maybe it was not required but I needed to know that I did everything correct.  
I do not know why the emoncms connection with the mqtt server failed as I used the automated install script. After the reinstall that problem went away.  
Then I think there might be some confusion on my part with regards to topic definitions.  
On the emonesp I defined the topic to be emon/# and the same on emoncms. This failed. Then looking at the debug output from the emonesp I saw another piece that was required.  
I changed the topic to emon/emonesp/# and that seemed to work.  
I also managed to connect emoncms with emonesp by using the device API-KEY.  
I am now connecting to the VPS using emonesp
