• DIY
  • ESP8266 MQTT Connection Lost

By connecting to this broker (tcp://mqtt.flespi.io:1883) via ESP8266 a new session is created on the site. it would be all right, I would be happy because I only need a message transfer intermediary, but after a certain period of time, the connection will disconnect:
close_code : -6
event_code : 503
503: mqtt session connection was closed (connection lost)

This is true primarily for ESP, device lost connection constantly, in case of my JAVA app (based on org.eclipse.pro.client.mqttv3 API), connection lost is rarely, but only when session is inactive - it's okay.

From my side: ESP sends message once a minute, the image below shows how the connection is randomly terminated right after sending some messages. This obviously shouldn't be the case.

I tried to connect via channel item with tcp (tcp://[CHANNEL].flespi.gw:[PORT] of test protocol id) and mqtt protocol: it can be seen through mqtt that there is a receive and send activity, but ESP still disconnects; test protocol, in turn, cannot be used - it immediately interrupts the connection due, as I know, to an incorrect chip response (it passes in answer mqtt local params instead of selecting a number). The device item also displays activity of specified topic, but the connection is unstable again.

The quality of the documentation is terrible, there is nothing to explain the correct way to connect to the broker with mqtt.

EDIT:
Okay it's esp problem: with another brokers has same issue: Socket error

    Hello. Please contact us via chat on flespi.io. We will look into your problem.

    At this point, it looks like you have configured a short keepalive interval and are not sending ping packets.
    Also maybe you can publish your code for esp?

    You can't use the test protocol to connect the ESP. The test protocol was created to check the operation of the channel using telnet.

      dexif Thank you for the reply. I have already solved the problem, it was a conflict between two ESPs with the same local IP address - I left one switched on and forgot about it.

      Write a Reply...