Saataa andagii !
This commit is contained in:
parent
7a9860a3bb
commit
48b0b4047e
4 changed files with 685 additions and 0 deletions
39
js-app/main.ts
Normal file
39
js-app/main.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
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)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue