Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

394
Visualizações
Reconnection in MQTT using javascript

I'm trying to reconnect in MQTT. I have many pages every page received data from different sensor. I tried to use reconnect: true and keepaliveIInterval: 30, but thats made my app crashed after few minutes and it doesnt let me the navigate to another page so I tried another solution which is to invoked the connect function after every lost of conn (because when I navigate to another page the connection is lost) but that's not working. It returns the last data after I swich to another page so it doesn't resend subscribe. Any help is appreciated.

constructor(){
    super();
    this.onMessageArrived = this.onMessageArrived.bind(this)
    this.onConnectionLost = this.onConnectionLost.bind(this)
   
    this.onConnect = this.onConnect.bind(this)
    this.onFailure = this.onFailure.bind(this)
    const client = new Paho.MQTT.Client(host, Number(port), clientID);
    client.onMessageArrived = this.onMessageArrived;
    client.onFailure = this.onFailure;
    client.MQTTconnect = this.MQTTconnect;
    client.connect({ 
                
                onSuccess : this.onConnect, 
                userName: "admin",
                password: "admin",
                onFailure : this.onFailure, 
          
  
              
    });
componentDidMount() {
    this.onConnect = this.onConnect.bind(this);
  }
  onFailure(responseObject) {
    if (responseObject.errorCode !== 0) {
    console.log("Connection Attempt to host"+ host +" Failed");
  
  }
  }
  MQTTconnect() {
    const client = new Paho.MQTT.Client(host, Number(port), clientID);
    client.onMessageArrived = this.onMessageArrived;
    client.connect({ 
      
                onSuccess : this.onConnect,
              
                userName: "admin",
                password: "admin",
                onFailure : this.onFailure, 
  
              
    });
  }
  onConnectionLost(responseObject) {
    if (responseObject.errorCode !== 0) {
      console.log("onConnectionLost : "+responseObject.errorMessage);
      this.setState({error: 'Lost Connection', isConnected: false});
      this.MQTTconnect();
   
    }
  }
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda