# MQTT Server Issue - Connection Refused not authorized

**URL:** <https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828>\
**Category:** emonPi\
**Created:** [9 October 2016 12:16 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828 "2016-10-09T12:16:47Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [9 October 2016 12:16 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/1 "2016-10-09T12:16:47Z")

</div>

Hello,

I have the following error in the emoncms.log.

> 2016-10-09 12:09:39.002 |WARN| phpmqtt\_input.php| Connecting to MQTT server: Connection Refused: not authorised.: code: 5

And the following in the emonhub.log

```auto
2016-10-09 11:46:53,502 INFO MQTT Could not connect...
2016-10-09 11:46:54,294 INFO MainThread Deleting interfacer 'MQTT' 
2016-10-09 11:46:54,295 INFO MainThread Creating EmonHubJeeInterfacer 'RFM2Pi' 
2016-10-09 11:46:54,297 ERROR MainThread could not open port /dev/ttyAMA0: [Errno 2] No such file or directory: '/dev/ttyAMA0'
2016-10-09 11:46:54,297 ERROR MainThread Unable to create 'RFM2Pi' interfacer: global name 'EmonHubInterfacerInitError' is not defined
2016-10-09 11:46:54,298 INFO MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2016-10-09 11:46:54,299 INFO MainThread MQTT Init mqtt_host=192.168.0.41 mqtt_port=21 mqtt_user=pi
2016-10-09 11:46:54,302 DEBUG MainThread MQTT Subscribed to channel' : ToEmonCMS
2016-10-09 11:46:54,304 DEBUG MainThread emoncmsorg Subscribed to channel' : ToEmonCMS
2016-10-09 11:46:54,404 INFO MQTT Connecting to MQTT Server
2016-10-09 11:46:54,406 INFO MQTT Could not connect...

```

I tried serveral user id’s and passwords.

The config file is as follows (baseid = 8, mqtt\_host = 192.168.0.41):

```auto
[[RFM2Pi]]
    Type = EmonHubJeeInterfacer
    [[[init_settings]]]
        com_port = /dev/ttyAMA0
        com_baud = 38400 # 9600 for old RFM12Pi modules
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        subchannels = ToRFM12,

        group = 210
        frequency = 433
        baseid = 8 # emonPi / emonBase nodeID
        quiet = true # Report incomplete RF packets (no implemented on emonPi)
        calibration = 230V # (UK/EU: 230V, US: 110V)
        # interval = 0 # Interval to transmit time to emonGLCD (seconds)

[[MQTT]]

    Type = EmonHubMqttInterfacer
    [[[init_settings]]]
        #mqtt_host = 127.0.0.1
        #mqtt_port = 1883
        mqtt_host = 192.168.0.41
        mqtt_port = 81
        mqtt_user = 'pi'
        mqtt_passwd = ' ********'

```

---

<div class="post-metadata">

**Author:** ![Paul\_Cardelli](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/paul_cardelli/32/1501_2.png) [@Paul\_Cardelli](https://community.openenergymonitor.org/u/Paul_Cardelli)\
**Post date:** [10 October 2016 04:30 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/2 "2016-10-10T04:30:34Z")

</div>

I had the same issue, for me it was because I had not updated the location of the password file in the mqtt config, Check step 5 in the SD build. If you are installing manually I recommend reviewing the SD image build instructions. There are a few steps here that I think are missing on the other build instructions.

> Turn off Mosquitto persistence and enable authentication:

> sudo nano /etc/mosquitto/mosquitto.conf  
> Set persistence false and add the lines:

> allow\_anonymous false  
> password\_file /etc/mosquitto/passwd

> Create a password file for MQTT user emonpi with:

> sudo mosquitto\_passwd -c /etc/mosquitto/passwd emonpi  
> Enter password emonpimqtt2016 (default)

> Test MQTT

> Open another shell window to subscribe to a test topic:

> mosquitto\_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘test/topic’  
> Publish to the test topic :

> mosquitto\_pub -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘test/topic’ -m ‘helloWorld’

[SD Build](https://github.com/openenergymonitor/emonpi/blob/master/docs/SD-card-build.md)

---

<div class="post-metadata">

**Author:** ![glyn.hudson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/glyn.hudson/32/35003_2.png) [@glyn.hudson](https://community.openenergymonitor.org/u/glyn.hudson)\
**Post date:** [10 October 2016 07:57 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/3 "2016-10-10T07:57:24Z")

</div>

The `emonhub.conf` settings are for emonhub to connect to mqtt.

The php input script (which is giving you an error) gets its credentials  
from `/var/www/emoncms/settings.php`

Check the mqtt details in settings.php are correct, the default username:password is ‘emonpi:emonpi2016’

- sent from my mobile device

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [10 October 2016 17:28 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/4 "2016-10-10T17:28:05Z")

</div>

In settings.php the user/password is emonpi, emonpimqtt2016  
I used this in the config file.

This results in  
2016-10-10 17:12:54,996 DEBUG MQTT CONACK =\> Return code: 5  
2016-10-10 17:12:54,998 INFO MQTT Unexpected disconnection  
2016-10-10 17:12:55,099 INFO MQTT Connecting to MQTT Server  
2016-10-10 17:12:55,104 WARNING MQTT Connection refused - not authorised  
2016-10-10 17:12:55,105 DEBUG MQTT CONACK =\> Return code: 5

Afterwards I used user = emonpi and passwd = emonpi2016  
But this returns the same error.

Does the text here below requires a comma and/or quotes?  
Or is this all right written down?

[[MQTT]]

```
Type = EmonHubMqttInterfacer
[[[init_settings]]]
    mqtt_host = localhost
    mqtt_port = 1883
    mqtt_user = emonpi
    mqtt_passwd = emonpi2016
```

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [10 October 2016 17:32 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/5 "2016-10-10T17:32:29Z")

</div>

I didn’t have to add the two lines. They were already written in de moquitto.conf file.

The command “mosquitto\_sub -v -u ‘emonpi’ -P ‘emonpimqtt2016’ -t ‘test/topic’” results in multiple lines  
**"Connection Refused: not autorised."**  
And had to stop this with CTRL-C.

---

<div class="post-metadata">

**Author:** ![Paul\_Cardelli](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/paul_cardelli/32/1501_2.png) [@Paul\_Cardelli](https://community.openenergymonitor.org/u/Paul_Cardelli)\
**Post date:** [10 October 2016 22:38 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/6 "2016-10-10T22:38:49Z")

</div>

That sounds good did you set the mqtt password?

> sudo mosquitto\_passwd -c /etc/mosquitto/passwd emonpi

Enter password emonpimqtt2016 (default)

---

<div class="post-metadata">

**Author:** ![glyn.hudson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/glyn.hudson/32/35003_2.png) [@glyn.hudson](https://community.openenergymonitor.org/u/glyn.hudson)\
**Post date:** [11 October 2016 09:07 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/7 "2016-10-11T09:07:41Z")

</div>

Are your running the 03-May16 pre-built emonSD image? [emonSD pre built SD card Download & Change Log · openenergymonitor/emonpi Wiki · GitHub](https://github.com/openenergymonitor/emonpi/wiki/emonSD-pre-built-SD-card-Download-&-Change-Log#emonsd-03may16--release)

Or is it a DIY build?

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [11 October 2016 18:06 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/8 "2016-10-11T18:06:49Z")

</div>

I recently bought the emontx and raspberry pi including the 8GB Prebuilt SD card.  
Invoice 13184 and invoice 13140.

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [11 October 2016 18:14 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/9 "2016-10-11T18:14:17Z")

</div>

By the way, the errors today are different than yesterday, perhaps due to restart/reboot(?):

2016-10-11 18:11:22,309 WARNING emoncmsorg emoncmsorg couldn’t send to server, URLError: [Errno 113] No route to host  
2016-10-11 18:11:22,310 WARNING emoncmsorg send failure: wanted ‘ok’ but got ‘’  
2016-10-11 18:11:22,311 INFO emoncmsorg sending: [http://192.168.1.41/emoncms/myip/set.json?apikey=E-M-O-N-C-M-S-A-P-I-K-E-Y](http://192.168.1.41/emoncms/myip/set.json?apikey=E-M-O-N-C-M-S-A-P-I-K-E-Y)  
2016-10-11 18:11:25,309 WARNING emoncmsorg emoncmsorg couldn’t send to server, URLError: [Errno 113] No route to host

---

<div class="post-metadata">

**Author:** ![glyn.hudson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/glyn.hudson/32/35003_2.png) [@glyn.hudson](https://community.openenergymonitor.org/u/glyn.hudson)\
**Post date:** [11 October 2016 21:06 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/10 "2016-10-11T21:06:05Z")

</div>

Oh dear, have you had this issue from day 1? Has anything been changed on  
the sd card image setup? Mqtt on the latest sd card image has been  
extensively tested and proven to be reliable.

- sent from my mobile device

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [11 October 2016 21:25 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/11 "2016-10-11T21:25:56Z")

</div>

Yes, it is not functioning since the first day.  
I do not know how I have to change the sd card image and think this how I received it.

Since more than a year I have an emontx V3.  
Because the temperature sensor is not working I recently bought another one.  
But the temperature sensor is also not working on this new delivery.

A lot of trouble for this hobby 🙂

---

<div class="post-metadata">

**Author:** ![glyn.hudson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/glyn.hudson/32/35003_2.png) [@glyn.hudson](https://community.openenergymonitor.org/u/glyn.hudson)\
**Post date:** [12 October 2016 06:31 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/12 "2016-10-12T06:31:57Z")

</div>

Very sorry to hear, I’m not sure what has gone wrong. Would you like us to send you a replacement sd card with a fresh image? Or would you be happy to download a fresh image and flash yourself? Do you have a spare SD card onto which you could flash the fresh image to test?

Download link is above.

---

<div class="post-metadata">

**Author:** ![glyn.hudson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/glyn.hudson/32/35003_2.png) [@glyn.hudson](https://community.openenergymonitor.org/u/glyn.hudson)\
**Post date:** [12 October 2016 12:10 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/13 "2016-10-12T12:10:24Z")

</div>

Ah great, I think that looks like mqtt is functional. Can you see data  
coming into local emoncms inputs? See

> **[2. Log Locally](https://guide.openenergymonitor.org/setup/local/)**
>
> Log data locally to emonPi

To post to [emoncms.org](http://emoncms.org) you will need to create an account on  
[https://emoncms.org](https://emoncms.org) then paste the rw api key into emonhub config. See  
[3. Log Remotely - Guide | OpenEnergyMonitor](https://guide.openenergymonitor.org/setup/remote)

- sent from my mobile device

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [13 October 2016 21:19 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/14 "2016-10-13T21:19:25Z")

</div>

The errors are gone after reinstalling the SD card.  
But the inputs are not showing in menu setup \> inputs .  
What more can be wrong in the setup?

```auto
2016-10-13 21:11:49,506 DEBUG RFM2Pi acknowledged command: > 8i
2016-10-13 21:11:49,608 DEBUG RFM2Pi device settings updated: H i8 g210 @ 433 MHz
2016-10-13 21:11:49,713 DEBUG RFM2Pi Discarding RX frame 'unreliable content'? 44 121 128 129 130 114 57 224 59 7 75 254 58 61 134 137 134 242 156 95 229 (-81)
2016-10-13 21:11:49,815 DEBUG RFM2Pi acknowledged command: > 1p
2016-10-13 21:11:50,120 DEBUG RFM2Pi acknowledged command: i - set node ID (standard node ids are 1..30)
2016-10-13 21:11:50,224 DEBUG RFM2Pi acknowledged command: b - set MHz band (4 = 433, 8 = 868, 9 = 915)
2016-10-13 21:11:50,329 DEBUG RFM2Pi acknowledged command: o - change frequency offset within the band (default 1600)
2016-10-13 21:11:50,536 DEBUG RFM2Pi acknowledged command: g - set network group (RFM12 only allows 212, 0 = any)
2016-10-13 21:11:50,640 DEBUG RFM2Pi acknowledged command: c - set collect mode (advanced, normally 0)
2016-10-13 21:11:50,847 DEBUG RFM2Pi acknowledged command: ..., a - send data packet to node , request ack
2016-10-13 21:11:50,951 DEBUG RFM2Pi acknowledged command: ..., s - send data packet to node , no ack
2016-10-13 21:11:51,055 DEBUG RFM2Pi acknowledged command: q - set quiet mode (1 = don't report bad packets)
2016-10-13 21:11:51,159 DEBUG RFM2Pi acknowledged command: x - set reporting format (0: decimal, 1: hex, 2: hex+ascii)
2016-10-13 21:11:51,470 DEBUG RFM2Pi acknowledged command: ,,, f - FS20 command (868 MHz)
2016-10-13 21:11:51,574 DEBUG RFM2Pi acknowledged command: ,, k - KAKU command (433 MHz)
2016-10-13 21:11:51,778 DEBUG RFM2Pi device settings updated: H i8 g210 @ 433 MHz
2016-10-13 21:11:51,884 DEBUG RFM2Pi Discarding RX frame 'unreliable content'? 42 237 229 174 255 127 171 200 116 189 225 196 250 11 119 61 233 170 179 241 177 (-79)
2016-10-13 21:11:51,990 DEBUG RFM2Pi Discarding RX frame 'unreliable content'? 30 108 57 31 222 151 144 119 164 41 125 115 250 200 131 255 126 190 123 9 (-80)
2016-10-13 21:11:52,095 DEBUG RFM2Pi Discarding RX frame 'unreliable content'? 28 183 252 42 157 227 82 118 221 228 235 60 145 48 154 12 15 124 149 95 21 (-87)
2016-10-13 21:11:53,204 DEBUG RFM2Pi Discarding RX frame 'unreliable content'? 21 55 224 164 109 40 75 225 92 38 100 46 253 254 204 190 127 92 244 110 17 (-85)

```

---

<div class="post-metadata">

**Author:** ![glyn.hudson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/glyn.hudson/32/35003_2.png) [@glyn.hudson](https://community.openenergymonitor.org/u/glyn.hudson)\
**Post date:** [14 October 2016 14:09 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/15 "2016-10-14T14:09:59Z")

</div>

> [@emontxv3](#):
>
> Discarding RX frame ‘unreliable content’? 44 121 128 129 130

Ah OK, that’s good. It seems the base station part is working fine now, it’s just receiving data if cannot decode. Each RF needs needs a corresponding node decoder in emonhub.conf. The default node decoder s should work fine with all our standard units.

What are you using as the transmitter node? Has the firmware on this node been modified? When was the transmitter node purchased? Do you have your order number so I can check the unit config?

---

<div class="post-metadata">

**Author:** ![emontxv3](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/e/439d5e/32.png) [@emontxv3](https://community.openenergymonitor.org/u/emontxv3)\
**Post date:** [14 October 2016 18:57 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/16 "2016-10-14T18:57:52Z")

</div>

Everything is working now after changing the node in 10 instead of 8 that is mentioned on the invoice (number 9630).  
thx for the all assistance.

1 emonTx V3 Electricity  
Monitoring Transmitter  
Unit 433MHz  
[emonTxV3]  
Frequency (433 / noRF): 433Mhz  
Node ID: 8 (default)  
emonTx Enclosure: Fully Assembled  
Temperature Sensor: 1 x RJ45 to Terminal  
Block Breakout for DS18B20

---

<div class="post-metadata">

**Author:** ![pb66](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/pb66/32/27_2.png) [@pb66](https://community.openenergymonitor.org/u/pb66)\
**Post date:** [15 October 2016 12:40 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/17 "2016-10-15T12:40:14Z")

</div>

> [@glyn.hudson](#):
>
> Discarding RX frame ‘unreliable content’? 44 121 128 129 130
> 
> Ah OK, that’s good. It seems the base station part is working fine now, it’s just receiving data if cannot decode. Each RF needs needs a corresponding node decoder in emonhub.conf. The default node decoder s should work fine with all our standard units.

“unreliable content” is actually anything recieved via the RFM2Pi interfacer prefixed with a question mark, ie packets that the rfm2pi has “discarded” due to failing the CRC checks. It’s not related to the node decoding in emonhub.

Those “unreliable contect” messages can be suppressed by setting `quiet = true` in the [[RFM2Pi]] settings in emonhub.conf, it is only useful to set to `false` for debugging if you are experiencing missing RF packets etc

---

<div class="post-metadata">

**Author:** ![Amelia\_Wilson](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@Amelia\_Wilson](https://community.openenergymonitor.org/u/Amelia_Wilson)\
**Post date:** [22 September 2017 08:23 UTC](https://community.openenergymonitor.org/t/mqtt-server-issue-connection-refused-not-authorized/1828/18 "2017-09-22T08:23:07Z")

</div>

The mosquito command is complete, you need to specify the port 8883, and the connection is secure by default and you need to specify the server certificate that can be downloaded from below:

[https://github.com/ibm-watson-iot/iot-python/blob/master/src/ibmiotf/messaging.pem](https://github.com/ibm-watson-iot/iot-python/blob/master/src/ibmiotf/messaging.pem)

So the command should look like:

mosquitto\_pub -h [xwc8vm.messaging.internetofthings.ibmcloud.com](http://xwc8vm.messaging.internetofthings.ibmcloud.com) -p 8883 -u “use-token-auth” -P “xxxxxxxxx” -i “d:xwc8vm:device-type:my-device” -t “iot-2/evt/x/fmt/json” -m {“d”:“hello”} --cafile messaging.pem -d

Note: Please mind the topic format:

“iot-2/evt/x/fmt/json” \>\>\>\>\> iot-2/evt/event/fmt/event\_format
