code-lua-iot/js-app/main.ts
2024-12-20 11:51:59 +01:00

39 lines
603 B
TypeScript

import express from "npm:express"
import mqtt from "npm:mqtt"
const app = express()
const client = mqtt.connect("mqtt://localhost")
var temp = {
"min": {
"temp": 100,
"place": ""
},
"max": {
"temp": 0,
"place": ''
}
}
app.get("/temp", (req, res) => {
res.status(200).send({
"min": {
"temp": 12,
"place": "Salon"
},
"max": {
"temp": 50,
"place": 'Four'
}
})
})
client.on("message", (topic, message) => {
console.log(topic, message.toString())
if (topic == "temp") {
console.log(message.split(":"))
}
})
app.listen(3000)