RaspberryPi Zero+esp8266(esp_easy)

Hello! I have some difficulties with my project. I am new to Openhab to i wanted to do something simple to just learn how it works. I want to just turn on and off LED connected to esp8266. I configured Openhab and espeasy however something is not working. I got this kind of error in log

2018-08-31 20:59:00.456 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'komar'
2018-08-31 20:59:02.330 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttSecurityException: Not authorized to connect
	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28) [202:org.openhab.io.transport.mqtt:1.12.0]
	at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:990) [202:org.openhab.io.transport.mqtt:1.12.0]
	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118) [202:org.openhab.io.transport.mqtt:1.12.0]
	at java.lang.Thread.run(Thread.java:748) [?:?]

And I have tested if mosquitto is working using mqttfx. So I quess there must be some mistake in openhabian configuration or in esp easy, but I have no idea where.
This is ma mqtt.cfg, rest of it is unchanged.

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
komar.url=tcp://192.168.8.114:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
komar.clientId=openhab2

Also I am attaching screenshot from esp easy !
2018-08-31%20(1)|690x388

Thank you in advance for your help!

what does your item file look like?

I have Esp8266 but currently only using only for temp and humidity readings. This is what the items file looks like:

Number ESP_Easy_Temp "Esp8266 Temp [%.1f °F]" <temperature> 
	{ mqtt="<[pibroker:/Esp/DS/Temp:state:default]" }

Your turning on an LED so the item will be a little different like:

Switch ESP_Easy_Led "Esp8266" <light>
	{ mqtt=">[pibroker:/Esp/GPIO/13:command:ON:1],>[pibroker:/Esp/GPIO/13:command:OFF:0],
	<[pibroker:Esp/Led/State:state:default],<[pibroker:/Esp/Led/State:state:default]" }

This is what the ESP EASY looks like for a switch. Devices tab, GPIO 13

Config Tab Unit Name is ESP.

Hopefully this will help with how to set up your item in OH relating Esp Easy.

One more note, for testing comment out

from your mqqt.cfg file. I can’t see your controllers set up in Esp Easy so I will assume that you have selected OpenHab MQTT and have the correct IP.

The error is connection not authorized.
You need to put the username and password in the mqtt.conf file

That is an optional setting and I’m assuming that he has not changed it else it would be in the OP.

Edit: The documents say the user name and password is required but in the mqtt.cfg file it looks like this for both:

# Optional. User id to authenticate with the broker.

I’ve never tried a set up without using these setting, so ???

I know but the error he has is not authorized to connect
So I assume that his broker is setup for basic auth

Switch MQTTLED "ESP_LED"  {mqtt=">[komar:/esp8266/gpio/0:command:ON:1],>[komar:/esp8266/gpio/0:command:OFF:0]"}

If the Unit Name in Config tab is esp8266 and your using the GPIO pin 0 it looks ok. I would try capitalizing the gpio and there is some who will say that the leading / is not needed but I have used with and without and no issue.

@vzorglub made a good point about the user name and password. Looking at the doc’s and how the mqtt cfg file has it as optional is a bit confusing. That being said, if you are not using a user name and password you should add it (both in OH and Esp Easy). ClientId is optional and for now comment it out.

sooo… I added user and password both in OH and ESP, capitalized gpio, commented out clientid and still getting same error. Any other ideas? Maybe something with Controller Subscribe and Publish in ESP Easy? What should I put there?

Do you have the MQTT Action installed?
If yes, remove it

Also add:

pid:org.openhab.mqtt
At the very top (first line) of the mqqt.cfg file. That will force OH to ignore any previous config that may remain in the cache config

I don’t have MQTT Action and after I added the line, this appeared in log:

2018-09-01 22:41:21.641 [WARN ] [g.dispatch.internal.ConfigDispatcher] - Could not parse line 'pid:org.openhab.mqtt'

Remove the pid:org.openhab.mqtt from mqtt.cfg, make sure the user name and password looks like: komar.user=your user name and komar.pwd=your password. Then from terminal type the following, all on one line, even the grey part.

sudo service openhab2 stop && sudo rm -rf /var/lib/openhab2/cache/* && sudo rm -rf /var/lib/openhab2/tmp/* && sudo reboot

This should clear out any previous configs your no longer using.

In the Esp Easy UI, controller tab, verify your using the same user name and password thats in the mqtt.cfg file. See below for example I have user as openhabian.

ok so quick update. I started everything from scratch. Reinstalled software on pi and esp and everything works now. I have no idea what was wrong previously. Anyway thank you for your help. And btw everything works fine without putting user and password in mqtt.conf.

I recommend that you set up mosquitto with authorisation