Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mqtt-agent

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mqtt-agent

This is a MQTT Agent

  • 1.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

This is a MQTT Agent

It is a simplification of MQTT in NodeJS. All functions return a native-promise that you can use Asynchronously.

Installation

$ npm install --save mqtt-agent

Usage

const mqttAgent = require('mqtt-agent');

// const agent = new MQTTAgent('mqtt://yourmqttserver:8883'); // Default message callback
const agent = new MQTTAgent('mqtt://your-mqtt-server:8883', (topic, msg) => {
  // Do something with your Topic and Message.
}); // Custom message callback

agent.connect() // Return a promise when it is connected to your server
  .then((connected) => {
    console.log('Connected:', connected); // Do something with the connected status
    // You can now subscribe, publish and all with native promises!
    return agent.subscribe('your_topic/your_device/something'); // Returns a promise
  })
  .then((subscribedTopic) => {
    console.log('Topic subscribed to:', subscribedTopic);
    // You can send options as last parameter
    return agent.publish('yourTopic', 'yourMessage can be a JS Object or string'); 
  })
  .then((published) => {
    console.log('Published (boolean):', published); // Then if you are subscribed to the topic, you will receive the message in your message callback
    return agent.end(); // Disconnect
  })
  .then((disconnected) => {
    console.log('Disconnected:', disconnected);
  })
  .catch((error) => {
    console.log('Error:', error);
  });

License

© Javier Cañadilla

Keywords

FAQs

Package last updated on 17 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc