Created
April 27, 2018 10:54
-
-
Save cbh6/707bc906ed22c060a4f3c1bc2b8aa506 to your computer and use it in GitHub Desktop.
This file contains 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 express = require("express"); | |
var bodyParser = require("body-parser"); | |
var app = express(); | |
var mqttHandler = require('./mqtt_handler'); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })) | |
var mqttClient = new mqttHandler(); | |
mqttClient.connect(); | |
// Routes | |
app.post("/send-mqtt", function(req, res) { | |
mqttClient.sendMessage(req.body.message); | |
res.status(200).send("Message sent to mqtt"); | |
}); | |
var server = app.listen(3000, function () { | |
console.log("app running on port.", server.address().port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment