Last active
December 14, 2015 19:18
-
-
Save adamvr/5135589 to your computer and use it in GitHub Desktop.
Quick and dirty http mqtt publisher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mqtt = require('mqtt') | |
, express = require('express'); | |
var app = express(); | |
var publish = function(topic, payload, cb) { | |
var client = mqtt.createClient(1883, 'test.mosquitto.org'); | |
client.on('connect', function() { | |
client.publish(topic, payload, cb); | |
client.end(); | |
}); | |
}; | |
app.use(express.bodyParser()); | |
app.get('/', function (req, res) { | |
res.send('Test thing!'); | |
}); | |
app.post('/:param', function (req, res) { | |
publish(req.param, req.body, function () { | |
res.send(200); | |
}); | |
}); | |
var port = process.env.PORT || 3000; | |
app.listen(port, function () { | |
console.log('Listening on port ' + 3000); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mqtt-http", | |
"version": "0.0.0", | |
"description": "mqtt-http bridge", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": "", | |
"keywords": [ | |
"mqtt", | |
"http", | |
"publish", | |
"subscribe", | |
"pubsub" | |
], | |
"author": "Adam Rudd", | |
"license": "BSD", | |
"dependencies": { | |
"mqtt": ">=0.2.0", | |
"express": "~3.1.0" | |
}, | |
"engines": { | |
"node": ">=0.6.0", | |
"npm": ">=1.1.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: node . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment