[SOLVED] Mosquitto MQTT cannot get service to run

Hardware: Intel Q9650 on Dell 0G261D motherboard
OS: Ubuntu 18.04.1 LTS
JRE: OpenJDK 1.8.0_192
OpenHAB 2.4

This isn’t really an Openhab question directly, as it’s with mosquitto configuration but I know there are a lot of users here. I am struggling to get it to even run. I’ve been all over the web looking for install/troubleshooting help and now fear I have conflicting information in files across my system.
My latest, when checking the service status is a return of:

Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: failed (result:exit-code) since Sun 2019-08-04 14:49:31 CDT; 32min ago
Process: 2287 ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=203/EXEC)
Main PID:2287 (code=exited, status=203/EXEC)

Aug 04 14:49:31 ubuntu_server systemd[1]: mosquitto.service: Service hold-off time over, scheduling restart
Aug 04 14:49:31 ubuntu_server systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Aug 04 14:49:31 ubuntu_server systemd[1]: Stopped Mosquitto MQTT Broker.
Aug 04 14:49:31 ubuntu_server systemd[1]: mosquitto.service: Start request repeated too quickly.
Aug 04 14:49:31 ubuntu_server systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Aug 04 14:49:31 ubuntu_server systemd[1]: Failed to start Mosquitto MQTT Broker.

Can someone point me in the right direction?

Hi David
Probably know this but if you just want a mqtt broker for OpenHAB, now OpenHAB has a mqtt broker embeded you can install in the Paper user interface

If this is a fresh install of Mosquitto and it has never run, uninstall reinstall?
of course you rebooted the computer?

Some thoughts:

  • did you configure ssl and are the key/cert files readable for the user running mosquitto?
  • did you start mosquitto as root and it probably created files that can‘t be accessed if run as a service (probably other user)?
  • is it working if you run it in the foreground?
  • what is written in the log?

Hi Andrew.
I’m looking at the MQTT binding documentation I’m reading I need a broker; I’m not reading anything about an imbedded OpenHAB broker??? I have no other need on this computer for an external MQTT broker (just need it for WiFi devices) so an embedded solution would be ideal.
I’ve uninstalled and purged Mosquitto (and of course rebooted several times!) but when I reinstall keep getting similar messages. I’m convinced there’s something amiss with the .conf file but can’t find a solution.

Hi Jan.
No, I’ve not done any of that. I can’t get to the point where Mosquitto even runs stably.
When I first installed it I checked its operation and it was working, but when I went to enable it to start on boot it went south.
Are there specific Mosquitto logs? Log files are something I’m not adept at interpreting (or even finding…).

This is the whole point of the embedded broker, no certs, easy to get going

So do I install both the MQTT Broker, and MQTT embedded Broker? I would guess just the later…

correct

I have not been able to work on this but with winter pending, I need to get a few temperature devices up and running.
I’ve installed MQTT Embedded Broker service and beyond setting the Embedded user brokername (MQTT temporarily during testing) and password I haven’t made any setting changes.
I also have the MQTT system broker connection service and as far as I can tell, don’t need to make any setting changes.
My test device is a Sonoff TH16 with Si7021 temperature sensor that’s been reprogrammed with Tasmota firmware. The Sonoff seems to be working just fine, I can log into it via my web browser, screen shot of the MQTT configuration below.
The Sonoff isn’t connecting to the MQTT broker; the blue indicator light continues to flash and the log reading:
“19:48:55 MQT: Connect failed to 127.0.0.1:1883, rc -2. Retry in 10 sec”
continues to log.
Question: Is 127.0.0.0 the correct connection address? I don’t see this setting in the MQTT broker.

You need to set the Host to the IP of the system where the broker is running. Setting it to 127.0.0.1 means localhost, in your case that would be the Sonoff-Device!!

1 Like

127.0.0.1 = loclhost = the network card you are using right now…
ifconfig will show your IP(you need the IP of your broker , the same machine runing MQTT)

try to watch some basic networking youtubes, its the basic for home auto…

Ok, great news. Entering the appropriate IP address of my host computer did the trick. I can see the Sonoff is connected by using MQTT.fx. One step down!

Now, onto the .things and .items configuration. The youtube videos are little help as I can’t see what they’re entering and their web sites have no good info (at least the videos I’ve seen). I’ve been following this guide:


but am unsure of what terms all need to match, between the Sonoff configuration, the myMQTTBroker thing properties and the .things and .items entries. Does anyone have a good example I can follow?
I’m also using a TH16 with an Si7021 sensor, and am not quite sure those values are right (I can find no examples that use this particular temp/humidity sensor).
Thanks again,

Read Here to find an example of the file setup.
For the setup via PaperUI take the settings found in the files-example.

what is the “clientID” within the thing file? No matter what I put in there I get a log error "Session does not exist. CId=“whatever I put in there”

Here is an example from my own Setup:

.items:

//192.xxx.xxx.xx                            Steckdosenleiste/Power Strip  TH16

Switch    Sonoff_PowerStrip_01          "Steckdosenleiste 1 [MAP(de.map):%s]"             <poweroutlet>           (EG_Kind1,gPlugSwitch,gSonoff)  { channel="mqtt:topic:hans:TH1601:power"}               
Number    Sonoff_PowerStrip_01_RSSI     "Steckdosenleiste 1 RSSI [%s]"                    <qualityofservice>      (EG_Kind1,gRSSI)                { channel="mqtt:topic:hans:TH1601:rssi" }               
String    Sonoff_PowerStrip_01_Version  "Steckdosenleiste 1 Version [%s]"                 <sonoff_pow>            (gSonoffs,gVer)                 { channel="mqtt:topic:hans:TH1601:version" }            
Switch    Sonoff_PowerStrip_01_Unreach  "Steckdosenleiste 1 Erreichbarkeit [%s]"          <siren1>                (EG_Kind1,gLWT)                 { channel="mqtt:topic:hans:TH1601:reachable" }          
//        For Fun and Test                                                                                                                                  
Number    Sonoff_PowerStrip_01_Temp     "Steckdosenleiste 1 Temperatur[%.1f °C]"          <temperature>           (gSonoffs,EG_Kind1,gRtIstI)     { channel="mqtt:topic:hans:TH1601:temperature"}               
Number    Sonoff_PowerStrip_01_Hum      "Steckdosenleiste 1 Luftfeuchtigkeit[%.2f %%]"    <humidity>              (gSonoffs,EG_Kind1)             { channel="mqtt:topic:hans:TH1601:humidity" }               
String    Sonoff_PowerStrip_01_SSID     "Steckdosenleiste 1 Wlan [%s]"                    <chart>                 (gSonoffs)                      { channel="mqtt:topic:hans:TH1601:ssid" }            
DateTime  Sonoff_PowerStrip_01_Date     "Steckdosenleiste 1 Refresh [ %1$tH:%1$tM]"       <time>                  (gSonoffs)                      { channel="mqtt:topic:hans:TH1601:time" }          

.things (including a Bridge)

Bridge mqtt:broker:hans "Mosquitto" [ host="localhost", port=1883, secure=false, clientID="OH2_Client" ]  
{
    //Gruppe TH10/16 Monitoring WiFi Smart Switch
    Thing topic TH1601 "Sonoff TH16 01" @ "MQTT2" {
    Channels:
        Type switch : power       "Power "               [ stateTopic="stat/th16_01/POWER", commandTopic="cmnd/th16_01/POWER" ]
        Type number : rssi        "WiFi Signal Strength" [ stateTopic="tele/th16_01/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type string : version     "Firmware Version"     [ stateTopic="stat/th16_01/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
        Type switch : reachable   "Reachable"            [ stateTopic="tele/th16_01/LWT", transformationPattern="MAP:reachable.map" ]
        Type number : temperature "Temperature"          [ stateTopic="tele/th16_01/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
        Type number : humidity    "Humidity"             [ stateTopic="tele/th16_01/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
        Type string : ssid        "WiFi"                 [ stateTopic="tele/th16_01/STATE", transformationPattern="JSONPATH:$.Wifi.SSId"]
        Type datetime : time      "Time"                 [ stateTopic="tele/th16_01/STATE", transformationPattern="JSONPATH:$.Time"]
    }
}

Hope this helps.

1 Like

Thanks, Peter. I am seeing some other details that will help me later but it is not helping my current problem.
I am thinking it is something to do with the Client ID (or at least that is one problem). I’ve seen a number of different names used in .items files but I continue to get an error with any entry I provide:
Session does not exist. CId=openhab
for example when I list clientID=“openhab”
Is this client ID entered somewhere else? The only other place I see it listed is in the MQTT broker configurations, but it’s not allowing me to enter a value there. Also does this correspond to a setting on the Sonoff?
Thanks again,

Each device has to have its own ClientID, in other words the same ClientID must not be used by two devices.

1 Like

As Jürgen said

I think the clientID is not mandatory in the Bridge/Thing so omit it.

1 Like

Within the MQTT Broker thing, some text beneath the Client ID setting states:“Use a fixed client ID. Defaults to empty which means a user ID is generated for this connection.” So that must be hapening because when deleting the clientID within the Bridge statement of the .things file, I get the following error:

Session does not exist. CId=paho51621326352350

!!!
So now I have to believe something else is holding this up. Perhaps something in the “MQTT Embedded Broker” service or the “MQTT system broker connection” service? There aren’t much for settings in those services however…

I’m going through everything I have installed and verifying their settings:

  1. Under Services/MQTT I have MQTT Embedded Broker and MQTT system broker connections installed. The only field filled under the embedded broker is the name of the persistence file (mqttembedded.bin).

  2. The following things are installed:
    image
    The first is a thing that I tried installing via PaperUI, but am now unable to install (when I try I get Error: 409 - Conflict).
    The MQTT Broker configuration settings are:

  • Broker Hostname/IP: 127.0.0.1
  • Broker Port: 1883
  • Client ID: paho51621326352350 (system generated)

And that’s all that I can see. I was “hoping” to find some conflict but I can’t find any differences from online guides.