Click here to Skip to main content
14,355,618 members

ProxyLayer Between MQTT Broker (Any MQTT Broker) and AWS IoT Broker

Rate this:
5.00 (2 votes)
Please Sign up or sign in to vote.
5.00 (2 votes)
10 Feb 2016CPOL
ProxyLayer Between MQTT Broker (Any MQTT Broker) and AWS IoT Broker

This article is an entry in our Microsoft Azure IoT Contest. Articles in this section are not required to be full articles so care should be taken when voting.

AWS IoT Broker currently supports only X.509 certificate Authorization. If your device does not support X.509, use this ProxyLayer to fill the Gap.

It listens to MQTT broker (Setup any broker, e.g., Mosquitto, HiveMQ) and publish that message to AWS IoT broker.

Create proxylayer.js file and paste the following code into it:

var mqtt = require('mqtt'), url = require('url');
var client = mqtt.connect('mqtt://127.0.0.1:1883',
{
username: '<mqtt username>',
password: '<mqtt password>'
});

var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({

keyPath: ‘&lt;Certificate key file path&gt;’,
certPath:‘&lt;Certificate file path&gt;’,
caPath: '‘&lt;Certificate root file path&gt;’,
clientId: ‘&lt;AWS Thing Name&gt;’,
region: ‘&lt;AWS IoT Broker region&gt;’
});

device.on('connect', function ()
{
//Write logging to check connection done or not
});

client.on('connect', function()
{
//subscribe to a topic (#)
client.subscribe('#', function ()
{
client.on('message', function (topic, message, packet) {
console.log("Received :-" + message + " on " + topic);
device.publish(topic, message);
console.log("Sent :-" + message + " on " + topic);
});
});
});

Run this into nodejs server by running the following command:

  • to run it from console: node proxylayer.js
  • to run it as background service: forever proxylayer.js (first installed forever by using npm -g install forever)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

aj_ankurjain
Chief Technology Officer CoreValue Technologies
India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
Technical Blog
Posted 10 Feb 2016

Stats

6.7K views
2 bookmarked