1

I'm trying to connect and get the data from topic sent by sensor. Unfortunately the connection not working. in the console doesn't show no msg

Ps: I'm using react_native_mqtt lib and a port : 80

Any help is appreciated.

constructor(){
        super();
        this.onMessageArrived = this.onMessageArrived.bind(this)
        this.onConnectionLost = this.onConnectionLost.bind(this)
        this.onConnect = this.onConnect.bind(this)
        const client = new Paho.MQTT.Client(host, Number(port), clientID);
        client.onMessageArrived = this.onMessageArrived;
        client.onConnectionLost = this.onConnectionLost;
        client.connect({ 
          onSuccess: this.onConnect,
          useSSL: false,
          userName: "user",
          password: "pass",
          onFailure: this.onConnectionLost
    
        });
    
        this.state = {
          message: [''],
          client,
          messageToSend:'',
          isConnected: false,
        };
    
      }
      onConnect = () => {
        const { client } = this.state.client;
        console.log("Connected!!!!");
        client.subscribe(topic, () => {
          console.log('subscribe success topic1');
        });
        this.setState({isConnected: true, error: ''})
      };

After a few minute:

Android Running app on Android SDK built for x86
onConnectionLost:AMQJS0007E Socket error:undefined.
  • 2
    Adding an `onFailure` handler might help identify the issue (see [this answer](https://stackoverflow.com/a/42993205/11810946), [this question](https://stackoverflow.com/questions/60895132/app-works-in-android-and-ios-simulator-but-not-after-release) may be useful). Note that your question says "I'm using react_native_mqtt lib" but it appears you are actually using the [paho](https://github.com/eclipse/paho.mqtt.javascript) library? If the above does not help please add extra info (e.g. what broker are you connecting to, what platform are you running the code on etc). – Brits Nov 27 '21 at 03:51
  • Paho javascript lib required a WebSocket listener port. share the details about the MQTT broker. – mukeshmandiwal Oct 06 '22 at 18:03

0 Answers0