rn-native-mqtt icon indicating copy to clipboard operation
rn-native-mqtt copied to clipboard

Connect error

Open ghost opened this issue 5 years ago • 10 comments

Hi, i'm trying to get simple test of this and i'm get error when trying to connect to server, i test my own mqtt server and free public server like mosquitto, but the result its same.

Im testing this on android

I'm start my project with npx react-native init MqttSample --template react-native-template-typescript

then i'm install the lib with: npm install react-native-native-mqtt --save

then i run react-native link react-native-native-mqtt

And my simple code is:

import * as Mqtt from 'react-native-native-mqtt';

const client = new Mqtt.Client('mqtt://test.mosquitto.org:1883');

client.connect(
      {
            clientId: 'miclienteyujuwao',
            cleanSession: true,
            keepAlive: 10,
            timeout: 30000,
            autoReconnect: true,
      },
      err => {
            alert('One error :(');
            console.warn(err); // Error: mqtt://test.mosquitto.org:1883
      },
);

Simply, i'm test with and without typescript templates and the result its same.

System:
    OS: Windows 10 Home, 1909, x64
    CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 16.0 GB
Packages:
    "react": "16.11.0",
    "react-native": "0.62.1",
    "react-native-native-mqtt": "^0.1.5"

ghost avatar Apr 07 '20 21:04 ghost

same question

basilbai avatar May 11 '20 06:05 basilbai

Same, nothing happens on client.connect(...), no error, logs or anything, doesn't matter what options I try

jackdewhurst avatar Jun 24 '20 13:06 jackdewhurst

Any solution on this ?

panchal-krunal avatar Jun 25 '20 04:06 panchal-krunal

Works well on iOS, nothing at all on Android.

kvaghas avatar Jun 25 '20 14:06 kvaghas

same question

songzuyun avatar Jun 30 '20 06:06 songzuyun

Works well on iOS, nothing at all on Android.

Any solution on this now?

songzuyun avatar Jun 30 '20 06:06 songzuyun

Change the the with tcp protocal const client = new Mqtt.Client('tcp://test.mosquitto.org:1883');

imetric avatar Jul 17 '20 03:07 imetric

Change the the with tcp protocal const client = new Mqtt.Client('tcp://test.mosquitto.org:1883');

did not work for me, when using 'tcp' it returns undefined error

in the image the first log is using the 'mqtt' and in the second the 'tcp' image

llaneiro avatar Jan 13 '21 13:01 llaneiro

I had same issue.

From Eclipse Paho's document ( https://www.eclipse.org/paho/files/javadoc/org/eclipse/paho/client/mqttv3/MqttConnectOptions.html#setUserName-java.lang.String- ) :

public void setUserName(java.lang.String userName) Sets the user name to use for the connection. Throws: java.lang.IllegalArgumentException - if the user name is blank or only contains whitespace characters.

So, I think below implementation of this library is a bit wrong:

https://github.com/davesters/rn-native-mqtt/blob/master/android/src/main/java/com/davesters/reactnative/mqtt/MqttClient.java#L66 https://github.com/davesters/rn-native-mqtt/blob/master/src/index.ts#L24

username must be specified. Can't be omitted.

clvs7-gh avatar Feb 20 '21 08:02 clvs7-gh

i changed the protocal and added the usename and is worked. const client = new Mqtt.Client('tcp://test.mosquitto.org:1883'); and client.connect({clientId: 'CLIENT_ID_0012656562645', username: 'USERNAME_0012656562645'}, err => {console.log(err)});

@imetric @clvs7-gh thanks a lot..

SarathKannan avatar Sep 25 '21 15:09 SarathKannan