[SOLVED] Mosquitto MQTT cannot get service to run

Not sure if you have a special case and this is in purpose, but right now you have two MQTT brokers configured, which will be rather challenging to configure.
Remember, the basic information flow is device <–> MQTT broker <–> OH2

In the best case you have now:
device1 <–> MQTT embedded <–> OH2
device2 <–> MQTT Mosquitto <-------^

While OH2 can likely handle two brokers, it will be challenging to remember who does what (unless you have a special case and this is on purpose). OH2 provides an embedded broker for convenience and hence, maybe you want to delete the Mosquitto broker you had set up (or vice versa if this is your preference).
A few more things to remember:

  • 127.0.0.1 always points to the local machine (whichever that is); if you are unsure, just use the real IP address in all cases.
  • Clear the Cache can be your friend if you work on configs a lot and get weird results
  • in any case, do it step-wise: first check if you device connects to the broker, than check if OH2 connects to the broker; and if both, check then you get to content and items, etc. You can use a separate program to connect to your broker with your computer and see what is happening: MQTT Exploration App (as well as read incoming commands or post MQTT messages)

I’ve made the change to 2.5.0.M3, removed and reinstalled the embedded broker and binding. I did not install the auto-generated thing and am configuring it in a thing file. As of today my device (TH16 with SI7021 sensor) is at least partially working; I can control the switch (super happy about that!) but cannot pull the sensor data out. The current entries in the .things files are:

Bridge mqtt:broker:mqttbroker "MQTT Broker" [ host="127.0.0.1", secure=false, port=1883, qos=0, retain=false, clientid="openhab", keep_alive_time=30000, reconnect_time=60000 ]
{
     Thing topic Sonoff_Coop "Sonoff Coop" @ "openhab" {
    Channels:
        Type switch : power "Power" [ stateTopic="stat/Sonoff_Coop/POWER", commandTopic="cmnd/Sonoff_Coop/POWER" ]
    }
}

and a .item as:

Switch Sonoff_Coop_Power "Coop Switch" <switch> { channel="mqtt:topic:mqttbroker:Sonoff_Coop:power"}

I can control the switch remotely any all is happy. When I begin to attempt to create a Channel to pull out the temperature, any configuration I try either does nothing or messes up the operation of the switch.
The Sonoff TH is sending out the following string from its sensor, seen from the Sonoff console:

06:45:32 MQT: tele/Sonoff_Coop/SENSOR = {"Time":"2019-10-06T06:45:32","SI7021":{"Temperature":77.0,"Humidity":53.6},"TempUnit":"F"}

I’ve tried the following channel configurations (separately of course) without luck (I have the JSON transformation installed):

Type number : Temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR:SI7021:Temperature"]
Type number : temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]

I’ve found some variations out there in the community pages but none work to pull the temperature number over.

Have you installed the JSONPATH transformation service?

Yes, and uninstalled/reinstalled JSONPath after the 2.5.0.M3 update to be sure the latest was there

The second version should work. I have it working like that with the AM2301 sensor.

I agree, I think it should! But it immediately breaks the switch and still doesn’t transmit the temperature! I’d actually be ok without the switch working and in fact tried leaving the temperature channel and removed the switch channel, and it still doesn’t transmit…
Could the JSON transform be malfunctioning somehow?

You have to define your Thing like this:

    //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"]
    }

and the corresponding items look like:

//**********************************************************************************************************************************************************************************************************************
//Gruppe TH10/16 Sensoren
//**********************************************************************************************************************************************************************************************************************
//192.168.x.y                            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" }          
//Number    Sonoff_PowerStrip_01_VCC      "Steckdosenleiste 1 VCC[%.2f V]"                  <energy>                (gSonoffs)    // doesn't work any longer
//**********************************************************************************************************************************************************************************************************************

Thanks, Peter. Your input was the basis for most of my testing but still not functioning.
I did discover one potential conflict: Within my .thing file in defining my thing topic I used Sonoff_Coop but also used this in the Sonoff configuration file and in the .item. I changed the topic line to

Thing topic Sonoff_Coop_Thing "Sonoff Coop" @ "openhab" {

…changing the thing name to include _Thing at the end. It now fixes the conflicts I had with the switch being disabled but am still not getting the temperature feed… :o(

I should mention I correspondingly changed the .items:

Switch Sonoff_Coop_Power "Coop Switch" <switch> { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:power"}
Number Sonoff_Coop_Temperature "Coop Temperature [%.1f °F]" <temperature> { mqtt="<[mqttbroker:Sonoff_Coop_Thing:SENSOR:JSONPATH($.SI7021.Temperature)]"}

This is a configuration for use with MQTT binding version 2

This is a configuration for use with MQTT binding version 1 (it could never work with Things and channels)

That line needs to be added to the thing definition you posted earlier!

One more try:

.items:

Switch Sonoff_Coop_Power "Coop Switch" <switch>                            { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:power"}
Number Sonoff_Coop_Temperature "Coop Temperature [%.1f °F]" <temperature>  { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:temperature"}

.things:

    Thing topic Sonoff_Coop_Thing  "Sonoff Coop" @ "openhab" {
    Channels:
        Type switch : power "Power"               [ stateTopic="stat/Sonoff_Coop/POWER", commandTopic="cmnd/Sonoff_Coop/POWER" ]
        Type number : temperature "Temperature"   [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]
    }

After you made this changes, pls. restart openhab as I think there is still a bug, when changing your text-files, that changes are not loaded.

your switch:#

Well that worked! I have a temperature coming through!
At least it worked for a few minutes, now my embedded broker is broken, for some unknown reason. Grrr. I don’t think this could get any more ridiculous. Commented out all of my changes, three restarts and still "OFFLINE - COMMUNICATION_ERROR

As the broker attempts to connect, I’m getting these entries in the logs:

2019-10-06 19:45:38.717 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid paho69680369956 and file store '/var/lib/openhab2/mqtt/127.0.0.1'
2019-10-06 19:45:39.554 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to '127.0.0.1'. Next attempt in 10000ms

I don’t somehow have a permissions issue on that folder that I never had before?

Don’t know if it helps or if you already changed it, but I saw that your clientID in the Bridge is written as clientid, but I think it should be clientID.

I updated the clientID tag but there was no change; not a surprise, it was working perfectly well before.
Recap on where I am:

  • Recently updated to 2.5.0.M3
  • The “MQTT Broker Moquette 2.5.0.M3” is installed
  • The “MQTT Binding 2.5.0.M3” is installed
  • I did not install the suggested MQTT thing; I have a bridge, thing and channels in a .things file as:
Bridge mqtt:broker:mqttbroker "MQTT Broker" [ host="127.0.0.1", secure=false, port=1883, qos=0, retain=false, clientID="openhab", keep_alive_time=30000, reconnect_time=60000 ]
{
    Thing topic Sonoff_Coop_Thing "Sonoff Coop" @ "openhab" {
    Channels: 
        Type switch : power "Power" [ stateTopic="stat/Sonoff_Coop/POWER", commandTopic="cmnd/Sonoff_Coop/POWER" ]
        Type number : temperature "Temperature" [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Temperature"]
        Type number : humidity "Humidity"       [ stateTopic="tele/Sonoff_Coop/SENSOR", transformationPattern="JSONPATH:$.SI7021.Humidity"]
    }
}

My .items file contains:

Switch Sonoff_Coop_Power "Coop Switch" <switch> { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:power"}
Number Sonoff_Coop_Temperature "Coop Temperature [%.1f °F]" <temperature>  { channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:temperature"}
Number Sonoff_Coop_Humidity "Coop Humidity [%s %%]" <humidity> {channel="mqtt:topic:mqttbroker:Sonoff_Coop_Thing:humidity"}

The broker was working right up to the time that the Temperature data started displaying from my Sonoff TH16 on my sitemap, then suddenly the broker just stopped working.
My openhab.log file is continuously displaying the following entries:

2019-10-08 20:20:18.172 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to '127.0.0.1'. Next attempt in 10000ms
2019-10-08 20:20:18.173 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid openhab and file store '/var/lib/openhab2/mqtt/127.0.0.1'

And the events.log repeats:

2019-10-08 20:21:48.192 [hingStatusInfoChangedEvent] - 'mqtt:broker:mqttbroker' changed from OFFLINE (COMMUNICATION_ERROR): Unable to connect to server to OFFLINE
2019-10-08 20:21:48.197 [hingStatusInfoChangedEvent] - 'mqtt:broker:mqttbroker' changed from OFFLINE to OFFLINE (COMMUNICATION_ERROR): Unable to connect to server

I’ve uninstalled the broker and binding and rebooted, no change.
In defining the thing, a file “127.0.0.1” is created that includes a lot of characters in addition to my .things file entries. Could this file be corrupt? What if I deleted the file and restarted?

No extra .things File with the above parameters. Of course I have the Bridge and Things in one file too. (it’s just the Thing-Part which I posted)
I don’t quite understand

Who and where a file “127.0.0.1” was created and what’s the content? :thinking:

My .things-File looks similar to yours(Just a snippet of mine):

Bridge mqtt:broker:hans "Mosquitto" [ host="localhost", port=1883, secure=false, clientID="OH2_hans" ]  
{
    // Sonoff Basic
    Thing topic basic03 "Sonoff Basic 03 Schreibtischlampe" @ "MQTT2" {
    Channels:
        Type switch : power     "Power "                 [ stateTopic="stat/basic_03/POWER", commandTopic="cmnd/basic_03/POWER" ]
        Type number : rssi      "WiFi Signal Strength"   [ stateTopic="tele/basic_03/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type string : version   "Firmware Version    "   [ stateTopic="stat/basic_03/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
        Type switch : reachable "Reachable"              [ stateTopic="tele/basic_03/LWT",transformationPattern="MAP:reachable.map" ]
//        Trigger String : powerx     "Power x Trigger Test "                 [ stateTopic="stat/basic_03/POWER" ]   // seems not to work with this syntax
//        Type switch : powerx     "Power X"                 [ stateTopic="stat/basic_03/POWER", trigger=true ]  // Trigger Channel; no need to define an item // Test with Channel Event Trigger - test_mqtt.rules
    }
    Thing topic basic04 "Sonoff Basic 04 Kugellampe"       @ "MQTT2" {
    Channels:
        Type switch : power     "Power "                 [ stateTopic="stat/basic_04/POWER", commandTopic="cmnd/basic_04/POWER" ]
        Type number : rssi      "WiFi Signal Strength"   [ stateTopic="tele/basic_04/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type string : version   "Firmware Version    "   [ stateTopic="stat/basic_04/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
        Type switch : reachable "Reachable"              [ stateTopic="tele/basic_04/LWT",transformationPattern="MAP:reachable.map" ]
    }
    // Sonoff Touch Wall Switches (T1, Touch)
    Thing topic T101 "Sonoff T1 01 DeckenLampe York" @ "MQTT2" {
    Channels:
        Type switch : power     "Power "                 [ stateTopic="stat/T1_01/POWER", commandTopic="cmnd/T1_01/POWER" ]
        Type number : rssi      "WiFi Signal Strength"   [ stateTopic="tele/T1_01/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type string : version   "Firmware Version    "   [ stateTopic="stat/T1_01/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
        Type switch : reachable "Reachable"              [ stateTopic="tele/T1_01/LWT",transformationPattern="MAP:reachable.map" ]
    }
.......
}

but I haven’t installed an embedded or a system broker, as I’m already use my former installed Mosquitto-Broker.

When starting/restarting openHAB the INFO

2019-10-08 08:29:16.452 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid OH2_hans and file store '/var/lib/openhab2/mqtt/localhost'

is normal, as you can see. I got it too. But the second information I’d never seen. Maybe it comes from the additional parameters in your Bridge-Configuration, which is a bit different to mine.