Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect error #6

Open
ghost opened this issue Apr 7, 2020 · 10 comments
Open

Connect error #6

ghost opened this issue Apr 7, 2020 · 10 comments

Comments

@ghost
Copy link

ghost commented Apr 7, 2020

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"
@basilbai
Copy link

same question

@jackdewhurst
Copy link

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

@panchal-krunal
Copy link

Any solution on this ?

@kvaghas
Copy link

kvaghas commented Jun 25, 2020

Works well on iOS, nothing at all on Android.

@songzuyun
Copy link

same question

@songzuyun
Copy link

Works well on iOS, nothing at all on Android.

Any solution on this now?

@imetric
Copy link

imetric commented Jul 17, 2020

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

@llaneiro
Copy link

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

@clvs7-gh
Copy link

clvs7-gh commented Feb 20, 2021

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.

@SarathKannan
Copy link

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants