Coder Social home page Coder Social logo

mqtt.js's Issues

Close event is getting fired continuously

Hi @taoqf , when i try connecting to any any stream with any protocol. The connection close callback gets called regularly. Even the below snippet doesn't work. Is it a bug ?.
var mqtt = require('@taoqf/react-native-mqtt')
var client = mqtt.connect('mqtt://test.mosquitto.org')
client.addListener('connect', () => {
console.log('connected');
});
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})

Always close event called when connected using mqtt protocol

Whenever tires to connect to a server by mqtt protocol, close event is emitted before getting connected. But works fine with ws/wss protocol.

const mqtt = require('@taoqf/react-native-mqtt')
const client = mqtt.connect('mqtt://XXX.XXX.XXX.XXX:1883);

Example: const client = mqtt.connect('mqtt://test.mosquitto.org:1883');

Unable to connect - MQTT protocol URL (plugin@taoqf/react-native-mqtt)

Here, I have integrated this plugin in my react native project and trying to connect URL with protocol mqtt. Referred doc
https://github.com/taoqf/MQTT.js/blob/react-native/README.md
Am unable to detect either connected or not. Below is my snippet
let mUrl = "mqtt://xxxx.xxxx.in";
let mOptions = {
username: server_user, password: server_pass,
protocol: 'mqtt',
clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
rejectUnauthorized: false,
protocolId: 'mqtt',
defaultProtocol:"mqtt",
protocolVersion: 4,
clean:false
}
var client = mqtt.connect(mUrl,mOptions);
client.on('connect', function () {
console.log("connected");
})
})
client.on('error', function ( err) {
console.log("client err : " + err)
})

Can anyone help ?

Thanks

Unable to connect / React native MQTT

Hey! I'm trying to connect and get the data from topic sent by sensor. Unfortunately the connection not working.
Any help is appreciated.

import init from 'react_native_mqtt'
import AsyncStorage from '@react-native-async-storage/async-storage'

 init({
  size: 10000,
  storageBackend: AsyncStorage,
  defaultExpires: 1000 * 3600 * 24,
  enableCache: true,
  reconnect: true,
  sync : {
  }
});

const host = '52.11.11.11'
const port = '8883'
const connectUrl = `mqtt://${host}:${port}`
clientID = "clientID-" + parseInt(Math.random() * 100);
export default class TestScreen extends Component {

  constructor(){
    super();
    this.onConnectionLost = this.onConnectionLost.bind(this)
    this.onConnect = this.onConnect.bind(this)
    const client = new Paho.MQTT.Client(host, Number(port), clientID);
    client.onConnectionLost = this.onConnectionLost;
    client.connect({ 
      onSuccess: this.onConnect,
      useSSL: true,
      userName: 'admin',
      password: 'admin',
      onFailure: (e) => {console.log("here is the error" , e); }

    });

    this.state = {
      message: [''],
      client,
      messageToSend:'',
      isConnected: false,
    };
  }
  onConnect = () => {
   // const { client } = this.state;
    console.log("Connected!!!!");
    //client.subscribe('hello/world');
    this.setState({isConnected: true, error: ''})
  };

It log :
here is the error Object {
"errorCode": 7,
"errorMessage": "AMQJS0007E Socket error:undefined.",
"invocationContext": undefined,
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.