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: ‘<Certificate key file path>’,
certPath:‘<Certificate file path>’,
caPath: '‘<Certificate root file path>’,
clientId: ‘<AWS Thing Name>’,
region: ‘<AWS IoT Broker region>’
});
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)CodeProject