• This repository has been archived on 09/Apr/2020
  • Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Objective-C
  • Created almost 9 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MQTT Client native module for react-native

npm

Please use paho.mqtt.javascript for your application, this repository not use for production

Description

react-native mqtt client module

MQTT Features (inherit from native MQTT framework)

Warning

This library in progress developing, api may change, SSL/TLS non verify

Getting started

Manual install

iOS

  • npm install react-native-mqtt@latest --save
  • In XCode, in the project navigator, right click Libraries âžœ Add Files to [your project's name]
  • Go to node_modules âžœ react-native-mqtt and add RCTMqtt.xcodeproj
  • In XCode, in the project navigator, select your project. Add libRCTmqtt.a to your project's Build Phases âžœ Link Binary With Libraries
  • Click RCTMqtt.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). In the Search Paths section, look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React - mark as recursive.
  • Run your project (Cmd+R)

Android

  • npm install react-native-mqtt@latest --save
  • Modify the ReactInstanceManager.builder() calls chain in android/app/main/java/.../MainActivity.java to include:
import com.tuanpm.RCTMqtt.*; // import


.addPackage(new RCTMqttPackage()) //for older version

new RCTMqttPackage()           // for newest version of react-native
  • Append the following lines to android/settings.gradle before include ':app':
include ':react-native-mqtt'
project(':react-native-mqtt').projectDir = new File(rootProject.projectDir,  '../node_modules/react-native-mqtt/android')

  • Insert the following lines inside the dependencies block in android/app/build.gradle, don't missing apply plugin:'java' on top:
compile project(':react-native-mqtt')

Notes:

dependencies {
  compile project(':react-native-mqtt')
}

Usage

var mqtt    = require('react-native-mqtt');

/* create mqtt client */
mqtt.createClient({
  uri: 'mqtt://test.mosquitto.org:1883', 
  clientId: 'your_client_id'
}).then(function(client) {

  client.on('closed', function() {
    console.log('mqtt.event.closed');
    
  });
  
  client.on('error', function(msg) {
    console.log('mqtt.event.error', msg);
    
  });

  client.on('message', function(msg) {
    console.log('mqtt.event.message', msg);
  });

  client.on('connect', function() {
    console.log('connected');
    client.subscribe('/data', 0);
    client.publish('/data', "test", 0, false);
  });

  client.connect();
}).catch(function(err){
  console.log(err);
});

API

  • mqtt.createClient(options) create new client instance with options, async operation

    • uri: protocol://host:port, protocol is [mqtt | mqtts]
    • host: ipaddress or host name (override by uri if set)
    • port: port number (override by uri if set)
    • tls: true/false (override by uri if set to mqtts or wss)
    • user: string username
    • pass: string password
    • auth: true/false - override = true if user or pass exist
    • clientId: string client id
    • keepalive
  • client

    • on(event, callback): add event listener for
      • event: connect - client connected
      • event: closed - client disconnected
      • event: error - error
      • event: message - message object
    • connect: begin connection
    • disconnect: disconnect
    • subscribe(topic, qos)
    • publish(topic, payload, qos, retain)
  • message

    • retain: boolean false
    • qos: number 2
    • data: string "test message"
    • topic: string "/data"

Todo

  • todo

LICENSE

INHERIT FROM MQTT LIBRARY (progress)

More Repositories

1

esp_mqtt

MQTT client library for ESP8266
C
1,135
star
2

espduino

ESP8266 network client (mqtt, restful) for Arduino
C++
381
star
3

esp32-mqtt

ESP32 MQTT sample project for
C
176
star
4

react-native-smartconfig

A React Native module for ESP8266 Smartconfig
Objective-C
127
star
5

esp_bridge

ESP8266 firmware SLIP Command, support mqtt, restful client
C
81
star
6

ESP8266MQTTClient

C
80
star
7

esp-request

This project is no longer supported, please use
C
62
star
8

esp-audio-player

ESP8266 Mp3 player and display spectrum on OLED
C
36
star
9

react-native-mqttjs

Pure javascript Websocket MQTT client library for react-native
JavaScript
27
star
10

esp32-fota

ESP32 Firmware update over the air
C
22
star
11

BluFi

BluFi Swift library - The protocol used to set up WiFi via Bluetooth for ESP32
Swift
19
star
12

esp_rpi_flasher

ESP32 batch programming tool
Python
18
star
13

iot-for-beginners-book

Ruby
17
star
14

lua-async

Async utilities for lua
Lua
14
star
15

esp-bootloader

ESP8266 bootloader
C++
10
star
16

esp-adf-sam

C
10
star
17

fullstack-engineer

Work environment, tools, knowledge, background required of a full stack R&D engineer genuine (Electronics, IT, IoTs)
JavaScript
8
star
18

STM32F10x_DSP_Lib

STM32F10x_DSP_Lib
Assembly
8
star
19

react-native-blufi

Java
5
star
20

html5-audio-fft

html5-audio-fft
HTML
5
star
21

esp-request-app

Sample http client for esp32
C
3
star
22

led-rgb-audio-spectrum

led-rgb-audio-spectrum
C
3
star
23

luat-dac-khu

2
star
24

CMSIS

CMSIS
C
2
star
25

piio

High performance GPIO library for raspberry pi
C++
2
star
26

BluFiAndroid

Java
1
star
27

STM32F10x_StdPeriph_Driver

STM32F10x_StdPeriph_Driver
C
1
star
28

esp-fibonacci-dualcore-test

JavaScript
1
star
29

indoor-loc-web

JavaScript
1
star