Constant MQTT devices disconnections (socket error)

Yes but I’ve found to be a lot easier to use terminal and a Windows PC to manage all projects using templates, substitutions and anchors, editing the code with Visual Code Studio. I’ve compiled and updated to version 1.12 all of my 39 devices in a matter os minutes using that method. Compiling a firmware with an i7 with 8 cores takes only a few seconds.

I don’t see the point. Tasmota is far more flexible and I don’t need to reflash firmware everytime I want to make a change. I was only trying esphome because it was so damn unstable but now that’s fixed I see no reason to change.

1 Like

Latest release for Tasmota is 6.5.0 with 2.3.0 being the default core.

1 Like

Yes I’m aware of that. I’m on 6.5.0.1 dev release. I had a lot of correspondence with Adrian @ tasmota and was pleased they reverted to core 2.3.0 as default again.

1 Like

Very helpfull discussion, I ask if someone can help me through the steps required: I have a Blitzwolf SPH2 with tasmota 6.4.1 core 2.4.2 flashed Ota with tuya convert (works well) and another Shp2 flashed soldering wires, using firmware 2.5 core 2.3. This one give me problems of connection to the broker, it became unavailable. I want to check my setup before flashing a new firmware, I ask the steps to follow when I will have to do it. I must flash first a minimal firmware to make room for the final firmware? I never used tasmoadmin, can I install it on a windows PC? The precompiled firmware with change keep alive and other parameter is still valid? (don’t know how to compie a firmware)

I have this disconnecting MQTT problem and I don’t know how to solve it… This is the Mosquitto log:

[INFO] found pi on local database
1560605925: New client connected from 192.168.2.7 as RfBridge01 (c1, k15, u’pi’).
[INFO] found pi on local database
1560605926: New client connected from 172.30.32.1 as mqtt_98cb4147.4d6cd (c1, k60, u’pi’).
[INFO] found pi on local database
1560605927: New client connected from 192.168.2.131 as lucibagnoinf (c1, k30, u’pi’).
[INFO] found pi on local database
1560605928: New client connected from 192.168.2.129 as lucucpri (c1, k30, u’pi’).
[INFO] found pi on local database
1560605929: New client connected from 192.168.2.116 as lusala1 (c1, k30, u’pi’).
[INFO] found pi on local database
1560605930: New client connected from 192.168.2.128 as lutersala (c1, k30, u’pi’).
[INFO] found pi on local database
1560605932: New client connected from 192.168.2.118 as luter23 (c1, k15, u’pi’).
[INFO] found pi on local database
1560605933: New client connected from 192.168.2.130 as lusalaled (c1, k30, u’pi’).
[INFO] found pi on local database
1560605934: New client connected from 192.168.2.115 as lucam2 (c1, k15, u’pi’).
[INFO] found pi on local database
1560605935: New client connected from 192.168.2.117 as luspebasup (c1, k30, u’pi’).
[INFO] found pi on local database
1560605936: New client connected from 192.168.2.120 as lusala2 (c1, k30, u’pi’).
[INFO] found pi on local database
1560605937: New client connected from 2.192.102.68 as mqtt_434800e3.8471d (c1, k60, u’pi’).
[INFO] found pi on local database
1560605938: New client connected from 192.168.2.122 as luter1 (c1, k30, u’pi’).
[INFO] found pi on local database
1560605939: New client connected from 192.168.2.126 as lutercuc (c1, k30, u’pi’).
[INFO] found pi on local database
1560605940: New client connected from 192.168.2.21 as luscainf (c1, k30, u’pi’).
1560605940: New connection from 192.168.2.130 on port 1883.
1560605940: New connection from 192.168.2.117 on port 1883.
1560605940: New connection from 192.168.2.118 on port 1883.
1560605940: New connection from 192.168.2.115 on port 1883.
1560605940: New connection from 192.168.2.120 on port 1883.
1560605940: New connection from 192.168.2.122 on port 1883.
1560605940: New connection from 192.168.2.126 on port 1883.
1560605940: New connection from 192.168.2.21 on port 1883.
1560605940: New connection from 192.168.2.125 on port 1883.
1560605940: New connection from 192.168.2.124 on port 1883.
1560605940: New connection from 192.168.2.121 on port 1883.
1560605940: New connection from 192.168.2.9 on port 1883.
1560605940: New connection from 192.168.2.23 on port 1883.
1560605940: New connection from 192.168.2.127 on port 1883.
1560605940: New connection from 192.168.2.24 on port 1883.
1560605940: New connection from 192.168.2.22 on port 1883.
1560605940: New connection from 192.168.2.20 on port 1883.
1560605940: New connection from 192.168.2.119 on port 1883.
1560605940: New connection from 192.168.2.7 on port 1883.
1560605940: New connection from 172.30.32.1 on port 1883.
1560605940: New connection from 192.168.2.131 on port 1883.
1560605940: Socket error on client RfBridge01, disconnecting.
1560605940: Socket error on client mqtt_98cb4147.4d6cd, disconnecting.
1560605940: Socket error on client lucibagnoinf, disconnecting.
1560605940: Socket error on client lucucpri, disconnecting.
1560605940: Socket error on client lusala1, disconnecting.
1560605940: Socket error on client lutersala, disconnecting.
1560605940: Socket error on client luter23, disconnecting.
1560605940: Socket error on client lusalaled, disconnecting.
1560605940: Socket error on client lucam2, disconnecting.
1560605940: Socket error on client luspebasup, disconnecting.
1560605940: Socket error on client lusala2, disconnecting.
1560605940: Socket error on client mqtt_434800e3.8471d, disconnecting.
1560605940: Socket error on client luter1, disconnecting.
1560605940: Socket error on client lutercuc, disconnecting.
1560605940: Socket error on client luscainf, disconnecting.

And the devices is always offline.
The device is all sonoffs with 6.5.0 firmware core 2.5.2 I have a total of 29 devices.
All the devices is reachable via url, why the mqtt doesn’t work??

Hello,
I had a lot of trouble with HASSIO where all my Tasmota devices are getting socket errors and disconnecting-reconnecting all the time. I tried almost everything. Changed settings in the firmware, upgraded my wifi, got real headaches out of it.
Then I tried a second HA instance based on HASSBIAN with MOSQITTO running as a seperate service.
The funny thing I noticed: everything is working like a charm, without changing any settings on my 30+ tasmota (6.5.0 and core 2.3.0) devices.
So My conclusion is that these socket-errors are HASSIO related, not Tasmota or HA.
I now have a 2nd Raspberry Pi ZeroW running RASPBIAN and just the MOSQUITTO broker and connect HASSIO (with no broker) to this MQTT broker. No more issues!

I have almost the exact same setup but with Socker Errors :frowning: Rpi3 B+ running raspbian (without) broker and pi zerow running mosquitto. I even temporarily changed brokers completely for testing and still got the socket errors. I tracked it down to the Wemo emulation and since i turned that off, no alexa :frowning: but 90% less socket errors.

@Narfel (And anyone else struggling) This is how I made my RASPBIAN-Pi ZeroW MQTT broker, perhaps it solves your issues too:

I downloaded Raspian Lite and flashed it to an SD-card (mine is 16GB) with Balena Etcher.
After flashing is complete I removed the SD and put it in my computer again so I can get to the ‘root’ directory of the SD. There I put 2 files:

  • a empty file with named ‘ssh’ with no extension
  • a file named ‘wpa_supplicant.conf’ with the following content:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=NL
network={
ssid=“[your wifi SSID]”
psk=“[your WPA password]”
key_mgmt=WPA-PSK

}

You have to change the country-code, in my case it’s NL.

Now I put the Sd in the Pi and let it boot, so you can SSH into it:

ssh [email protected]

with the IP-adress of the Pi at the xxx.xxx.xxx.xxx.
Enter password ‘raspberry’ to gain access to the Pi.
I immediately change the standard password for security reasons:

passwd

You’ll be asked again to fill in the old password ‘raspberry’ and then have to enter 2 the new password 2 times.

It is advised to enhance the swapfile-size on a Pi-Zero, to give it some ‘air’ and prevent lock-ups due to insufficient swap-file size:

sudo nano /etc/dphys-swapfile

Now uncomment (remove the ‘#’) on the se two lines:

CONF_SWAPFILE=/var/swap
CONF_SWAPFACTOR=2

And comment (put a ‘#’ before) the line:

#CONF_SWAPSIZE=100

Save the file with [crtl+o] and close the editor with [crtl+x]
Then make the new settings work with:

sudo dphys-swapfile setup
sudo dphys-swapfile swapon
sudo reboot

After rebooting and SSH into the Pi again, I updated the OS:

sudo apt-get update
sudo apt-get upgrade -y

After this is done, I expand the filesystem on de SD, so all of the memory on the SD is usable:

sudo raspi-config

In the menu go to option ‘7 Advanced Options’ and then ‘A1 Expand Filesystem’ and reboot again.
Now it’s finally time to install Mosquito with:

sudo apt install -y mosquitto mosquitto-clients

After this is finished, I make Mosquito auto-start on boot:

sudo systemctl enable mosquitto.service

And your done!

After I upgraded from HA+Mosquitto to Hassio+Mosquitto Addon, I was able to get sensor data from one of my sensors but cannot get any reading from other 2 sensors which none of them use Tasmota, so in my case it is not related with Tasmota. There were lots of socket error logs. Then I upgraded official Mosquitto broker addon to 5.0 version but the logs remain same. I installed MQTT Server & Web client 1.1.0 and stopped Mosquitto addon, now I can get all my sensor data and no more socket error so far.
Give it a try before any hard work.

1 Like

Thanks, will try it!

i tried the MQTT Server & Web 1.1.0 but with my setup the error remains. perhaps i had the wrong integration setup - it is setup with my local ip and the user & pass on hass.io 0.99.2 supervisor 188, tried to add it with a0d7b954-mqtt but doesn’t worked after reboot… dunno what im doing wrong here - does anyone has the same problem and got a solution?

I have a similar issue but i have Openhab running along with Hassio and openhab doesn´t have the conectivity issues, when I arrive home most of the times I reach Hassio to turn the lights and none of them are available, and then I open the Openhab app and they work flawlessly there, that´s why I don´t think it has anything to do with the tasmotized switches.

but when I restart hassio they work again…

that´s really weird don´t you think?

Hi guys.
I have the same connection problem, identical to you. What changes is that I use the Arduino Mega with an ENC28j60 ethernet board. I actually use two Arduino Mega boards each with the ENC28j60 ethernet. The two have practically the same Scheduler, carrying one of them after a few touches on the switches or using the HA for some command disconnects, the other card is stable and working perfectly. I have already changed the plates, I have rewritten the codes, I have left only one connection on the network, I have done the cabling inspection, replaced the number of IPs and there is no way to be revolved. Follow my schedule, if anyone can help me. And I use a different name for each board

#include <PubSubClient.h>
#include <UIPEthernet.h>

byte mac[] = {0x80, 0x7D, 0x3A, 0x69, 0x20, 0xC8 }; //physical mac address
byte ip[] = {192, 168, 0, 202 }; // ip in lan

int botao[] =                    {      11,              12,                10,                 9,              8,                7,            6,                 5,             4,              3,              27,               14,              17,              16,              15,             18,           22,              21,                20,            19,             23,               26,               25,           24        };//PORTAS DOS INTERRUPTORES
int rele[] =                     {      A11,             A10,               A12,               A13,            A14,              A15,           A6,               A5,             A4,             A3,             49,               48,              45,              46,              47,             44,           40,              41,                42,            43,             39,               36,               37,           38        }; //PORTAS DOS RELES
const char* TOPIC_PUBLISH [] =   {"ha/v_principal","ha/v_cabeceira",  "ha/v_acessoria", "ha/c_principal", "ha/c_acessoria", "ha/c_parede", "ha/q_principal", "ha/q_parede", "ha/q_entrada", "ha/q_esquerda", "ha/q_direita", "ha/q_arandela", "ha/m_principal", "ha/m_acessoria", "ha/m_parede", "ha/m_sacada", "ha/lustre", "ha/jantar_indireta", "ha/s_indireta", "ha/mezanino", "ha/v_sacada", "ha/porta_arandela", "ha/calcada", "ha/j_frente"  };
String strTopic []=              {"ha/v_principal","ha/v_cabeceira",  "ha/v_acessoria", "ha/c_principal", "ha/c_acessoria", "ha/c_parede", "ha/q_principal", "ha/q_parede", "ha/q_entrada", "ha/q_esquerda", "ha/q_direita", "ha/q_arandela", "ha/m_principal", "ha/m_acessoria", "ha/m_parede", "ha/m_sacada", "ha/lustre", "ha/jantar_indireta", "ha/s_indireta", "ha/mezanino", "ha/v_sacada", "ha/porta_arandela", "ha/calcada", "ha/j_frente"  };
String Switch[] =                {  "v_principal" ,  "v_cabeceira" ,   "v_acessoria"  ,  "c_principal"  ,   "c_acessoria" ,   "c_parede" ,  "q_principal"  ,  "q_parede"  ,   "q_entrada" ,   "q_esquerda" ,  "q_direita"  ,   "q_arandela" ,   "m_principal" ,   "m_acessoria" ,   "m_parede" ,   "m_sacada" ,   "lustre" ,   "j_indireta"      ,   "s_indireta" ,   "mezanino" ,  "v_sacada"  ,   "porta_arandela" ,  "calcada"  ,   "j_frente"   };
boolean statusrele[] =           {        1,              2,                3,                  4,              5,                 6,            7,                8,             9,              10,             11,                12,              13,              14,             15,              16,          17,              18,                 19,            20,             21,              22,               23,           24,       };
static unsigned long debounceInterruptor[]={1,            2,                3,                  4,              5,                 6,            7,                8,             9,              10,             11,                12,              13,              14,             15,              16,          17,              18,                 19,            20,             21,              22,               23,           24,       };
  
int relecont = 24; // NR DE PORTAS USADAS RELES OU INTERRUPETORES PARA O INDICE (i)
int i;

const char* mqtt_server = "192.168.xxx.xxx";
const char* mqttUser = "mqttUser";
const char* mqttPassword = "xxxxx";

EthernetClient espClient;
PubSubClient client(espClient);

String strTopic1;
String strPayload;



void interruptor(int i)  // FUNCAO PARA LIGAR/DESLIGAR LAMPADAS
{
   for (int i = 0; i < relecont; i++){
   if (  (millis() - debounceInterruptor[i]) > 30 ) {
    if((digitalRead(botao[i]) == HIGH))
    {
      while(digitalRead(botao[i]) == HIGH){};
        digitalWrite(rele[i],!statusrele[i]);
        statusrele[i] = !statusrele[i];
        if (statusrele[i]==false){
        client.publish(TOPIC_PUBLISH[i], "OFF");}
         if (statusrele[i]==true){
        client.publish(TOPIC_PUBLISH[i], "ON");}
       delay(350);
    }
   }
   }
   
   }


void setup_inicio() {

 
 Serial.begin(115200);
  delay(100);
 
   Ethernet.begin(mac,ip);
}

void callback(char* topic, byte* payload, unsigned int length) {
  payload[length] = '\0';
  strTopic1 = String((char*)topic);

  for (int i = 0; i < relecont; i++) 
{
  if(strTopic1 == strTopic[i])
    {
    Switch[i] = String((char*)payload);
    if(Switch[i] == "ON")
      {statusrele[i] = true;
        Serial.println("ON");
        digitalWrite(rele[i], HIGH);
        delay(350);
      }
    else
      {statusrele[i] = false;
        Serial.println("OFF");
        digitalWrite(rele[i], LOW);
        delay(350);
      }
    }
}
}
 
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("arduinoClientSuperior",mqttUser, mqttPassword)) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.subscribe("ha/#");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      
      delay(5000);
    }
    
  }
  
}
 
void setup()
{
Serial.begin(115200);
for (int i = 0; i < relecont; i++) 
{
  pinMode(rele[i],OUTPUT); //DEFINI PORTAS RELE COMO PORTA DE SAIDA
  pinMode(botao[i],INPUT); //DEFINE PORTAS DE INTERRUPTORES COMO PORTA DE ENTRADA
  digitalWrite(rele[i],HIGH); // DEFINIE ESTADO HIGH PARA PORTAS DE RELE
  statusrele[i] = true; // DEFINE O STATUS RELE COMO TRUE  
 }



 
  setup_inicio(); 
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  


}
 
void loop()
{
  if (!client.connected()) {
 
    reconnect();
  }
  
  interruptor(i);
  client.loop();


      
}