[SOLVED] Having trouble with ESP8266 and MQTT binding

I’ve managed to set up Mosquitto on my RPI3 and it appears to be working. I also installed ESPEasy on a ESP-01 with a DHT11 sensor. The sensor reads both Temp and Humidity correctly:

I have openhab.cfg set to:

mqtt:broker.url=tcp://localhost:1883
mqtt:broker.clientId=openhab

and it looks like it’s being loaded:

2016-08-16 19:49:09.812 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-08-16 19:49:09.815 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'broker'

I can see that the ESP8266 is sending data and it is being received on the RPI3:

Cpi@raspberrypi:~ $ mosquitto_sub -d -t /# -v
Client mosqsub/2052-raspberryp sending CONNECT
Client mosqsub/2052-raspberryp received CONNACK
Client mosqsub/2052-raspberryp sending SUBSCRIBE (Mid: 1, Topic: /#, QoS: 0)
Client mosqsub/2052-raspberryp received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/2052-raspberryp received PUBLISH (d0, q0, r0, m0, '/ESPTEMP1/DHTTest/Temperature', ... (4 bytes))
/ESPTEMP1/DHTTest/Temperature 80.6
Client mosqsub/2052-raspberryp received PUBLISH (d0, q0, r0, m0, '/ESPTEMP1/DHTTest/Humidity', ... (4 bytes))
/ESPTEMP1/DHTTest/Humidity 28.0
Client mosqsub/2052-raspberryp received PUBLISH (d0, q0, r0, m0, '/ESPTEMP1/DHTTest/Temperature', ... (4 bytes))
/ESPTEMP1/DHTTest/Temperature 80.6
Client mosqsub/2052-raspberryp received PUBLISH (d0, q0, r0, m0, '/ESPTEMP1/DHTTest/Humidity', ... (4 bytes))
/ESPTEMP1/DHTTest/Humidity 37.0

Despite all this, I am not getting these messages translated and populate my variables. My items file looks like this:

Number 	esp_outdoor_fr_temp 		"Front Porch Temperature[%.0f °F]" 	<temp_icon> 	(esp) {mqtt="<[broker:/ESPTEMP1/DHTTest/Temperature:state:default]"}
Number 	esp_outdoor_fr_hum 			"Front Porch Humidity[%.0f %%]" 	<hum_icon> 		(esp) 	{mqtt="<[broker:/ESPTEMP1/DHTTest/Humidity:state:default]"}}

Can anyone spot what I’m doing wrong?

When you say your variables are not being populated, do you mean you cannot see the value in your sitemap/UI or the actual items are not being updated?

Can you check the openhab event.log to see if those items are being updated?

Do you have any ACLs configured which might restrict openhab for subscribing to those topics?

Last thing, I am not sure if you need a space between the item description and the value formatting, e.g. Humidity[%0.f %%]. You might want to try Humidity [%.0f %%].

At least you got ESPeasy to show values! I ended up throwing a sketch on with Arduino IDE after updating firmware with ESPeasy. Here is my sketch:

https://codebender.cc/sketch:316691

Just copy into the Arduino IDE, modify your client name, wifi settings, and topic name.

have you set the Protocol etc in ESPEasy? these are my settings…

BTW. I have had this combo running for a while no dramas. ESPEasy can be a bit of dog to get going hint: try resetting the board when things don’t work :wink:

Also I haven’t set a client id in the config file.

… and don’t forget to set the unit nr under config tab to a different value than zero (and if you have more than one esp8266 to a different nr than your other devices). This applies also to the IDX/Variable nr under the devices tab: they must not be zero and different from other sensors (I see that you have already set it to “1”).

BUT: because you already are able to see your data in your shell by subscribing to the topic, this can’t actually be the problem.
So maybe you should post your rules where your are setting up your variables to see it there is a problem.
Otherwise a simple

Text item=esp_outdoor_fr_temp
Text item=esp_outdoor_fr_hum

in your sitemap should already show you the temp and hum data …

Not seeing anything in event.log pertaining to these devices. I don’t know what ACLs are so unclear on this.

Here’s my settings:

The variables are not showing that they are updating so the sensor values are not being assigned to them. I changed my items definition to ‘String’ just to make sure but still nothing. You can see my items definition in the OP. I am not using any rules but I’m guessing you’re asking about the items definition.

It’s odd because I can see the messages on the RPI but it’s like the MQTT binding isn’t picking them up. I’m not sure if I have something misconfigured. I started in debug mode and this is what I get from openhab.log when grepping for ‘-i mqtt’:

08:13:54.779 [DEBUG] [.io.transport.mqtt.MqttService:123  ] - Starting MQTT Service...
08:13:54.831 [INFO ] [.io.transport.mqtt.MqttService:108  ] - MQTT Service initialization completed.
08:13:54.834 [INFO ] [o.i.t.m.i.MqttBrokerConnection:114  ] - Starting MQTT broker connection 'broker'
08:13:54.849 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:294  ] - Creating new client for 'tcp://localhost:1883' using id 'openhab' and file store '/tmp/broker'
08:14:52.311 [DEBUG] [.a.mqtt.internal.MqttActivator:34   ] - Mqtt action has been started.
08:15:04.196 [DEBUG] [riptExtensionClassNameProvider:63   ] - Script actions have changed: ExecActionService, PingActionService, MqttActionService, AudioActionService, TransformationActionService, HTTPActionService, 
08:15:11.297 [DEBUG] [riptExtensionClassNameProvider:63   ] - Script actions have changed: ExecActionService, PingActionService, MqttActionService, AudioActionService, TransformationActionService, HTTPActionService, MyOpenHABServiceImpl, 
08:15:11.815 [DEBUG] [riptExtensionClassNameProvider:63   ] - Script actions have changed: ExecActionService, PingActionService, MqttActionService, AudioActionService, TransformationActionService, imperiHabActionService, AstroActionService, HTTPActionService, MyOpenHABServiceImpl, 
08:15:14.467 [DEBUG] [riptExtensionClassNameProvider:63   ] - Script actions have changed: ExecActionService, PingActionService, MqttActionService, AudioActionService, TransformationActionService, MailActionService, imperiHabActionService, AstroActionService, HTTPActionService, MyOpenHABServiceImpl, 

Also, checking /var/log/mosquitto/mosquitto.log shows:

1471439823: mosquitto version 1.4.9 (build date Fri, 03 Jun 2016 09:02:12 +0100) starting
1471439823: Config loaded from /etc/mosquitto/mosquitto.conf.
1471439823: Opening ipv4 listen socket on port 1883.
1471439823: Opening ipv6 listen socket on port 1883.
1471439834: New connection from 192.168.0.12 on port 1883.
1471439834: New client connected from 192.168.0.12 as ESPClient1 (c1, k15).
1471440871: New connection from 127.0.0.1 on port 1883.

So it appears that my ESP8266 is broadcasting correctly because I can see the messages on the RPI and I’ve also seen them with MQTTfx tool. The messages are definitely coming from:

/ESPTEMP1/DHTTest/Temperature

These messages have valid values in them. I’m guessing it’s probably something small that I’m missing.

Can someone tell me how to test OH MQTT binding by creating a simple device and how to send it a simple message just to try and isolate things to a problem with OH? Something like a switch controlled by MQTT and how to send a message from command line. Is this possible and/or worthwhile test?

Thanks to you all for responding!

As you can see the MQTT message, the problem is not your ESP8266…

I verified your item definition and saw some small difference to mine. This is one of my definition for an MQTT temperature sensor:

Number ARDUINO_01_01_TEMP "Außen Temp [%.1f °C]" (Arduino) {mqtt="<phc:/phc/FromArduino/BOARD/01/SENSOR/01/01/TEMP:state:REGEX((.*))]"}

You should try to change “state:default” to “state:REGEX((.*))” and try again.

Andreas

In your item declarations, it looks like you have an extra closing } on your humidity sensor, although I wouldn’t think that would keep both of them from working.

Here’s one of my outlets if you want to try testing a virtual switch.

Item File

Switch outlet1 "Lamp" (lights,lamp,bedroom) ["Lighting"] {mqtt=">[broker:/ol1/gpio/15:command:ON:1],>[broker:/ol1/gpio/15:command:OFF:0],<[broker:/ol1/state:state:default"}

Sitemap

Switch item=outlet1 label="Lamp"

You should be able to control it by passing 1 for ON and 0 for OFF

mosquitto_pub -d -t /ol1/gpio/15 -m 1

Here is a switch that gets the status of my dryer. It is running Homie rather than ESPEasy so the topic format is a little different.

Switch dryer "Dryer Status" {mqtt="<[broker:devices/laundry-sensor/Dryer/status:state:default]"}

I don’t have any sensors with ESPEasy, so I’m not sure what the correct syntax should be. Andreas may be on to something with "state:REGEX((.*))

Thanks for this. I changed it to:

String esp_outdoor_fr_temp "Front Porch Temperature[%.0f °F]" <temp_icon> (esp) {mqtt="<[broker:/ESPTEMP1/DHTTest/Temperature:state:REGEX((.*))]"}

Still not getting anything. [quote=“PointandClick, post:8, topic:13330, full:true”]
In your item declarations, it looks like you have an extra closing } on your humidity sensor, although I wouldn’t think that would keep both of them from working.

Here’s one of my outlets if you want to try testing a virtual switch.

Item File

Switch outlet1 “Lamp” (lights,lamp,bedroom) [“Lighting”] {mqtt=">[broker:/ol1/gpio/15:command:ON:1],>[broker:/ol1/gpio/15:command:OFF:0],<[broker:/ol1/state:state:default"}

Sitemap

Switch item=outlet1 label=“Lamp”

You should be able to control it by passing 1 for ON and 0 for OFF

mosquitto_pub -d -t /ol1/gpio/15 -m 1

Here is a switch that gets the status of my dryer. It is running Homie rather than ESPEasy so the topic format is a little different.

Switch dryer “Dryer Status” {mqtt="<[broker:devices/laundry-sensor/Dryer/status:state:default]"}

I don’t have any sensors with ESPEasy, so I’m not sure what the correct syntax should be. Andreas may be on to something with "state:REGEX((.*))
[/quote]

Fixed the closing brace on that line but doesn’t seem to matter. I also tried adding your item and passing the control to it:

pi@raspberrypi:~ $ mosquitto_pub -d -t /ol1/gpio/15 -m 1
Client mosqpub/2491-raspberryp sending CONNECT
Client mosqpub/2491-raspberryp received CONNACK
Client mosqpub/2491-raspberryp sending PUBLISH (d0, q0, r0, m1, '/ol1/gpio/15', ... (1 bytes))
Client mosqpub/2491-raspberryp sending DISCONNECT

Unfortunately, nothing happened.

It really looks like Mosquitto is running fine as I see messages from the ESP8266 coming through as well as the one I manually sent above:

I’m really stumped. Can the MQTT binding be set into some sort of debug mode like Zwave? Can it write out it’s own log file? Is there any way to see what OH is actually receiving? Thanks again guys

Did you get it working? I see it’s now marked as solved.

I found the problem and I’ve also wasted all of your time. Seems that I fat fingered the copy when I copied the addons jar file. I only had the action and didn’t have the binding. All is well. Again, apologies to all who helped.

No problem. It can be frustrating when you know it just has to be one little thing, but feel like you’ve gone over everything a million times. Glad you go it working.