You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
694 B
JavaScript
30 lines
694 B
JavaScript
require("dotenv").config();
|
|
const mqtt = require("mqtt");
|
|
const express = require("express");
|
|
|
|
// const db = require("./db");
|
|
|
|
const app = express();
|
|
|
|
app.use(require("./routes"))
|
|
|
|
app.use(express.static("public"));
|
|
|
|
app.listen(process.env.PORT || 8080, () => {
|
|
console.log(`Listening on port ${process.env.PORT || 8080}`);
|
|
});
|
|
|
|
const mqttClient = mqtt.connect(process.env.MQTT);
|
|
|
|
mqttClient.on("connect", (a) => {
|
|
console.log(`Connected to ${process.env.MQTT}`);
|
|
});
|
|
|
|
mqttClient.subscribe("motion");
|
|
mqttClient.subscribe("sound");
|
|
mqttClient.subscribe("temperature");
|
|
mqttClient.subscribe("light");
|
|
|
|
mqttClient.on("message", (topic, message) => {
|
|
console.log(topic, message.toString());
|
|
}); |