first commit
This commit is contained in:
27
src/index.js
Normal file
27
src/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const app = express();
|
||||
const SocketIO = require("socket.io");
|
||||
var mqtt = require('mqtt')
|
||||
var client = mqtt.connect('mqtt://192.168.1.105',{username:'mdchaparror',password:'un80187452'})
|
||||
|
||||
app.set("port", 6000);
|
||||
app.use(express.static(path.join(__dirname, "public")));
|
||||
console.log(__dirname);
|
||||
|
||||
const server = app.listen(app.get("port"), () => {
|
||||
console.log("Servidor iniciado puerto: ", app.get("port"));
|
||||
});
|
||||
|
||||
const io = SocketIO(server);
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
console.log("Cliente conectado");
|
||||
socket.emit('OK',{mensaje:'Bienvenido'})
|
||||
socket.on("mensaje", (mensaje) => {
|
||||
client.publish('matrix/mensaje',mensaje.message);
|
||||
client.publish('matrix/rgb',mensaje.color_rgb);
|
||||
console.log("mensaje MQTT =>",mensaje)
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user