MQTT configuration

Hello every one.
i am new here.
I have installed mosquitto on my raspberry and mqtt binding addon.

directory of /etc/openhab2/services/mqtt-eventbus.cfg
broker=mqtt (istead of i wrote mqtt , actually i dont know what is it)
commandPublishTopic=openhab/out/${item}/command

drectory of /etc/openhab2/services/mqtt.cfg
mqtt.url=tcp://localhost:1883
mqtt.clienId=openhab
mqtt.user=openhab
mqtt.pwd=qwerty

i don’t know is it true configuration

I also have esp8266 .
flashing with arduino
when i wrote
#define mqtt_server “localhost”
#define mqtt_port 1883
#define mqtt_user “openhab”
#define mqtt_key “qwerty”

it fails to connect mqtt

when i wrote
#define mqtt_server “192.168.0.107” //ip address of raspberry
#define mqtt_port 1883
#define mqtt_user “openhab”
#define mqtt_key “key”

it is successfully connected

i have tried
#define mqtt_server “192.168.0.107” //ip address of raspberry
#define mqtt_port 1883
#define mqtt_user “anyuser”
#define mqtt_key "anypassword"
it is successfully connected .

i don’t know wether mqtt.cfg works or not.

how can i list mqtt users ? or add mqtt user ?

Usually the only thing you need to define in your mqtt.cfg is the broker and port.
What you write/define in your arduino/esp8266 is up to the library you are using and how you are using that.
‘localhost’ does not work in your arduino/esp8266 (as you saw) because they then try to publish to their own ip number.

Supposing you have a raspberry for openhab that is still called ‘raspberry’ then you could use ‘raspberry.local’ but the working of that may depend on settings in your router.
provided your raspberry always uses the same ip address, using that is the easiest

You do not need to define the user or the key as I presume your mqtt broker is not protected with a log in code.
Should you for instance use adafruit as broker, you would need those entry codes.

I am not really sure how to list your mqtt users, I doubt if it is useful and if you really need that to test your mqtt.cfg works or not. Adding mqtt users is what you do everytime you have an arduino or esp or other device, connect as a client and you usually define that in the program on that client, but if not, then it is assigned random

I get the impression that you are just staring at this on the worng presumption that you need to ‘add users’ in order to connect to openhab/mqtt.
That is not necessary. Unless you have mqtt broker protected with a login, any client can connect.

As regarding the mqtt.cfg working or not… if it receives commands it is working, so just try and again, the only thing you need to adapt in your mqtt.cfg is the broker

Thank you very much i understand it!

My pleasure

then what is the purpose of mqtt.user=openhab
mqtt.pwd=qwerty
on esp8266 is wrote different username . it works anyway

i think when i am using localhost does not matter what is username or password .
username is used using adafruit .

to secure my mqtt should i use io.adafruit or eclipse web site ?

Well I am not entirely sure about what you define in your program but I presume those are the log on credentials for an mqtt broker and if you use your own mosquitto broker you do not need a log in

I am getting a bit confused about what you trying to achieve.
if you are using openhab then I presume you are using mosquitto on your own raspberry as broker and you do not need any logon credentials

and yes, adafruit who i only mentioned as an example, wants logon credentials.

I am not sure what you mean by ‘secure your mqtt’ and why you want adafruit or eclipse for that.
The most secure is to use your own broker and even if there is no pw on it, as long as your LAN is unreachable from outside you are safe

EDIT: this was a reply to a now withdrawn post

Thank you very much! sorry for bothering)))