MQTT lost connecection after a few days and

Hi, I have 3 Nodemcu esp8266 all connecting to my wifi and pc via mqtt.
OS: ubuntu 16.04
openhab2

I installed binding-mqtt - 2.5.11
and misc-mqttbroker - 2.5.11
and I add in things.

all the things work for a few days and suddenly they stop working. after restarting openhab every things will back to normal.
by the way, my esp8266 units resets electrically every hour. I am pretty sure that something in my configuration causes the problem or maybe a bug.
in old days I dont have any problem when installing mosquitto and mosquitto-clients and mqtt binding but now …
thanks in advance and sorry for my bad english

one thing that i am struggling about is client id that I put in mqtt.cfg, that im not using it anywhere now but it is in esp8266 code, i don’t know it is problematic or not

Use mosquitto as your broker

the client id’s should be unique / different for each 8266 and openHAB

1 Like

Thanks just another question, I have in my esp code two parts, one is client-id which is unique for every esp’s and one named device-id which are same across esp’s. Like this:

#define CLIENT_ID "client-1temhu00sd25101"         // 

const char* mqttDeviceID = "My1";

The first line named client Id is different in each esp
But device id is same, will this be a problem?
And as you said, I have to create mqtt broker in things section with empty client Id (in more setting section)?
And then create 3 generic mqtt and connect them to mqtt broker for my 3 esp’s

Right?
Thanks

It depends I would make both unique.

As I don’t know the rest of your program and what libraries you are using it is had to know what mqttDeviceID actually means

Maybe change your code to

const char* mqttDeviceID = CLIENT_ID;

Are you using Mosquitto or the system broker?

1 Like

Changing my esp codes are difficult!! They are in another city!
I removed mqtt system broker from misc.
Install mosquito and mosquito-clients.
Add mqtt broker from paper ui, it is online.
Add generic mqtt and bridge to that broker.
It is online
But my esp’s can not connect to mqtt.
In system broker I didn’t have this problem. Should I change any file or configuration when using mosquito?
And am I correct to use one mqtt broker and bridge it to couple of esp’s? Thanks

So just to be sure you have Mosquitto installed and no other Broker software like the embedded broker?

Can you use another client like http://mqtt-explorer.com/ to look at the $SYS topic to see what clients are connected?

1 Like

I did as follows:
first, uninstall embedded broker and mqtt binding at first and delete all things related to mqtt.
then, install mosquitto and mosquitto-clients
restart openhab and install mqtt binding
go to the things and add mqtt broker with localhost and then add generic one that says online but esp’s can not connect!
but I try to change mqtt broker ip address to my server ip address which should be same as localhost I imagine!
but when i put 192.168.1.100 which is my server local ip, it shows broker is offline
I think the problem is here but don’t know what it is.
and I install that software that you linked in my pc but can not connect to 192.168.1.100!
also here is mosquitto log:

1615208074: mosquitto version 1.4.8 (build date Fri, 19 Feb 2016 12:03:16 +0100) starting
1615208074: Config loaded from /etc/mosquitto/mosquitto.conf.
1615208074: Opening ipv4 listen socket on port 1883.
1615208074: Error: Address already in use
1615834384: mosquitto version 2.0.9 starting
1615834384: Config loaded from /etc/mosquitto/mosquitto.conf.
1615834384: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615834384: Create a configuration file which defines a listener to allow remote access.
1615834384: Opening ipv4 listen socket on port 1883.
1615834384: Opening ipv6 listen socket on port 1883.
1615834384: mosquitto version 2.0.9 running
1615834403: New connection from 127.0.0.1:54476 on port 1883.
1615834403: New client connected from 127.0.0.1:54476 as cf92810c-efae-4ec6-ac2e-cb5f3a4b6ec6 (p2, c1, k60).
1615834663: New connection from 127.0.0.1:54496 on port 1883.
1615834663: New client connected from 127.0.0.1:54496 as 390cd5e1-58d9-48ff-816c-c5c30dd0726e (p2, c1, k60).
1615836185: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615837986: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615839787: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615841588: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615843389: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615845190: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615846991: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615848792: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615850593: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615852394: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615854195: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615855996: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615857797: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615859598: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615861399: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615863200: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615865001: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615866802: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615868603: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615870404: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615872205: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615874006: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615875807: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615877608: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615879409: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615881210: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615883011: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615884812: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615886613: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615888414: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615890215: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615892016: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615893817: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615895618: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615897419: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615899220: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615901021: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615902822: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615904623: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615906424: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615908225: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615910026: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615911827: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615913628: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615915429: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615917228: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615919029: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615920831: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615922633: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615924434: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615925840: Client 390cd5e1-58d9-48ff-816c-c5c30dd0726e disconnected.
1615926235: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615926347: mosquitto version 2.0.9 terminating
1615926347: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615926390: mosquitto version 2.0.9 starting
1615926390: Config loaded from /etc/mosquitto/mosquitto.conf.
1615926390: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615926390: Create a configuration file which defines a listener to allow remote access.
1615926390: Opening ipv4 listen socket on port 1883.
1615926390: Opening ipv6 listen socket on port 1883.
1615926390: mosquitto version 2.0.9 running
1615926508: New connection from 127.0.0.1:35464 on port 1883.
1615926508: New client connected from 127.0.0.1:35464 as 7edea2dc-698f-450e-80ef-25aeef3c11da (p2, c1, k60).
1615926891: Client 7edea2dc-698f-450e-80ef-25aeef3c11da disconnected.
1615926912: mosquitto version 2.0.9 terminating
1615926912: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615926912: mosquitto version 2.0.9 starting
1615926912: Config loaded from /etc/mosquitto/mosquitto.conf.
1615926912: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615926912: Create a configuration file which defines a listener to allow remote access.
1615926912: Opening ipv4 listen socket on port 1883.
1615926912: Opening ipv6 listen socket on port 1883.
1615926912: mosquitto version 2.0.9 running
1615926983: New connection from 127.0.0.1:35506 on port 1883.
1615926983: New client connected from 127.0.0.1:35506 as 00a93608-f1b9-40f9-8a34-52b7444806c8 (p2, c1, k60).
1615928713: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615928856: mosquitto version 2.0.9 terminating
1615928856: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1615928884: mosquitto version 2.0.9 starting
1615928884: Config loaded from /etc/mosquitto/mosquitto.conf.
1615928884: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615928884: Create a configuration file which defines a listener to allow remote access.
1615928884: Opening ipv4 listen socket on port 1883.
1615928884: Opening ipv6 listen socket on port 1883.
1615928884: mosquitto version 2.0.9 running

just for testing, i remove mosquitto and mosquitto clients, install mics mqtt broker…it worked! frustrating!

1 Like