Coder Social home page Coder Social logo

react-native-mqttjs's Introduction

react-native-mqttjs

Features

This is 100% Pure javascript Websocket MQTT client library without any dependencies for react-native, use original react-native Websocket, port from: MQTT client library for Contiki - Prefer for any IoT Mobile applications using react-native

Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).

Sampe as esp_mqtt for ESP8266 chip and should replace for react-native-mqtt

Install

npm i react-native-mqttjs --save

Basic usage

import { MqttClient } from 'react-native-mqttjs';

var mqtt = new MqttClient();
mqtt.connect('ws://test.mosquitto.org:8080');

mqtt.subscribe({'/topic1': 0}, () => {
  console.log('subscribe success topic1 with qos 0');
});
mqtt.subscribe([{'/topic2': 1}, {'/topic3': 2}], () => {
  console.log('subscribe success topic2 with qos 1, topic3 with qos 2');
});

mqtt.publish('/topic1', 'test', {qos: 0, retain: 0}, () => {
  console.log('publish success');
});

mqtt.addListener('message', (topic, data) => {
  console.log('data arrived, topic: ' + topic + ' - data: ' + data);
});

mqtt.addListener('connect', () => {
  console.log('mqtt connected');
});

API

  • Options:
    • keepalive: 120 seconds
    • reschedulePings: reschedule ping messages after sending packets (default true)
    • clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8)
    • protocolId: 'MQTT' or 'MQIsdp'
    • clean: true, set to false to receive QoS 1 and 2 messages while offline
    • reconnectPeriod: 1000 milliseconds, interval between two reconnections
    • connectTimeout: 30 * 1000 milliseconds, time to wait before a CONNACK is received
    • username: the username required by your broker, if any
    • password: the password required by your broker, if any
    • will: a message that will sent by the broker automatically when the client disconnect badly. The format is:
      • topic: the topic to publish
      • payload: the message to publish
      • qos: the QoS
      • retain: the retain flag

License

MIT

react-native-mqttjs's People

Contributors

hd1001 avatar tuanpmt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-mqttjs's Issues

Not available on NPM?

Please make it available on NPM

bash-3.2$ npm i react-native-mqttjs --save
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/5.2.0/bin/node" "/usr/local/Cellar/node/5.2.0/bin/npm" "i" "react-native-mqttjs" "--save"
npm ERR! node v5.2.0
npm ERR! npm v4.0.3
npm ERR! code E404

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/react-native-mqttjs
npm ERR! 404
npm ERR! 404 'react-native-mqttjs' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/gp/Bikeninja/projects/workspace/gp/NavigatorSample/npm-debug.log

Doesn't work on React-Native 0.26.2

Hey I came here from the README at https://github.com/tuanpmt/react-native-mqtt which has now changed saying to use https://github.com/eclipse/paho.mqtt.javascript

I tried playing around with react-native-mqttjs and paho.mqtt.javascript but can't get either working.

react-native-mqttjs doesn't work due to EventEmitter module.exports I think and paho.mqtt.javascript due to it not being a node module.

Do you have any examples of getting either of these to work?

EventEmitter module doesn't exist in the module map

I added this library using yarn add tuanpmt/react-native-mqttjs.

I had error EventEmitter module does not exist in the module map or in these directories: some path/react-native-mqttjs/mqtt.js when I'd run app.

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.