Saataa andagii !
This commit is contained in:
parent
48b0b4047e
commit
ddc46bdd2a
9 changed files with 40 additions and 64 deletions
2
js-app/.gitignore
vendored
Normal file
2
js-app/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
deno.lock
|
||||
|
|
@ -4,7 +4,7 @@ import mqtt from "npm:mqtt"
|
|||
const app = express()
|
||||
const client = mqtt.connect("mqtt://localhost")
|
||||
|
||||
var temp = {
|
||||
var vals = {
|
||||
"min": {
|
||||
"temp": 100,
|
||||
"place": ""
|
||||
|
@ -16,22 +16,29 @@ var temp = {
|
|||
}
|
||||
|
||||
app.get("/temp", (req, res) => {
|
||||
res.status(200).send({
|
||||
"min": {
|
||||
"temp": 12,
|
||||
"place": "Salon"
|
||||
},
|
||||
"max": {
|
||||
"temp": 50,
|
||||
"place": 'Four'
|
||||
}
|
||||
})
|
||||
res.status(200).send(vals)
|
||||
})
|
||||
|
||||
client.on("connect", () => {
|
||||
client.subscribe("Building/temp", (err) => {
|
||||
console.log("Subscribed to Building/temp topic.")
|
||||
});
|
||||
});
|
||||
|
||||
client.on("message", (topic, message) => {
|
||||
console.log(topic, message.toString())
|
||||
if (topic == "temp") {
|
||||
console.log(message.split(":"))
|
||||
if (topic == "Building/temp") {
|
||||
const [ temp_str, place ] = message.toString().split(":")
|
||||
const temp = parseFloat(temp_str)
|
||||
if (temp < vals.min.temp) {
|
||||
vals.min.temp = temp
|
||||
vals.min.place = place
|
||||
console.log(`Updated min temp to : [${place}] : ${temp}`)
|
||||
}
|
||||
if (temp > vals.max.temp) {
|
||||
vals.max.temp = temp
|
||||
vals.max.place = place
|
||||
console.log(`Updated max temp to : [${place}] : ${temp}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
import { assertEquals } from "@std/assert";
|
||||
import { add } from "./main.ts";
|
||||
|
||||
Deno.test(function addTest() {
|
||||
assertEquals(add(2, 3), 5);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue