OpenEnergyMonitor Community

MQTT Server Issue - Connection Refused not authorized


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

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= 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 =

    Type = EmonHubJeeInterfacer
        com_port = /dev/ttyAMA0
        com_baud = 38400                      # 9600 for old RFM12Pi modules
        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)


    Type = EmonHubMqttInterfacer
        #mqtt_host =
        #mqtt_port = 1883
        mqtt_host =
        mqtt_port = 81
        mqtt_user = 'pi'
        mqtt_passwd = '********'

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)


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

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

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?


Type = EmonHubMqttInterfacer
    mqtt_host = localhost
    mqtt_port = 1883
    mqtt_user = emonpi
    mqtt_passwd = emonpi2016

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.

That sounds good did you set the mqtt password?

sudo mosquitto_passwd -c /etc/mosquitto/passwd emonpi

Enter password emonpimqtt2016 (default)

Are your running the 03-May16 pre-built emonSD image? emonSD pre built SD card Download & Change Log · openenergymonitor/emonpi Wiki · GitHub

Or is it a DIY build?

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

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:
2016-10-11 18:11:25,309 WARNING emoncmsorg emoncmsorg couldn’t send to server, URLError: [Errno 113] No route to host

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

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 :slight_smile:

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.

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

To post to you will need to create an account on then paste the rw api key into emonhub config. See
3. Log Remotely - Guide | OpenEnergyMonitor

  • sent from my mobile device

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?

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)

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?

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
Frequency (433 / noRF): 433Mhz
Node ID: 8 (default)
emonTx Enclosure: Fully Assembled
Temperature Sensor: 1 x RJ45 to Terminal
Block Breakout for DS18B20

1 Like

“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

1 Like

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:

So the command should look like:

mosquitto_pub -h -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