Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Latest commit

 

History

History
38 lines (25 loc) · 789 Bytes

README.md

File metadata and controls

38 lines (25 loc) · 789 Bytes

MQTT Client

MQTT Client for the browser & React Native

This is an export of the MQTT.js library, but exported with Webpack as a CommonJS module for ease of use.

Installation

$ npm i --save wt-mqtt

Usage (ES6)

import mqtt from 'wt-mqtt'

...

var client = mqtt.connect('ws://localhost:3000')

client.subscribe('mqtt/demo')

client.on('connect', () => {
  console.log('mqtt connected')
})

client.on('message', (topic, payload) => {
  console.log([topic, payload].join(': '))
  client.end()
})

client.publish('mqtt/demo', 'hello world!')

Server

We use Mosca as our MQTT broker. Read this wiki for a guide of setting up Mosca over WebSockets.