diff --git a/autorun.lua b/autorun.lua index d7d0d30..4981d92 100644 --- a/autorun.lua +++ b/autorun.lua @@ -5,12 +5,6 @@ dofile("main.lua") -- affiche la température du CPU printTemp() --- affiche le résultat du dé sur le neopixel --- dice() - --- lance l'hotspot wifi et le serveur web --- dofile("web.lua") - -- connection au brooker mqtt dofile("mqtt.lua") diff --git a/js-app/.gitignore b/js-app/.gitignore new file mode 100644 index 0000000..458b3e7 --- /dev/null +++ b/js-app/.gitignore @@ -0,0 +1,2 @@ +deno.lock + diff --git a/js-app/main.ts b/js-app/main.ts index 3479fa6..1f6c93c 100644 --- a/js-app/main.ts +++ b/js-app/main.ts @@ -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}`) + } } }) diff --git a/js-app/main_test.ts b/js-app/main_test.ts deleted file mode 100644 index 3d981e9..0000000 --- a/js-app/main_test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { assertEquals } from "@std/assert"; -import { add } from "./main.ts"; - -Deno.test(function addTest() { - assertEquals(add(2, 3), 5); -}); diff --git a/mqtt.lua b/mqtt.lua index bc22c53..dfe17b3 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -1,6 +1,10 @@ client = mqtt.client("ESP32", "192.168.0.11", 1883, false) client:connect("","") +nb = 0 +net.service.http.start() +console(net.stat(true)[0]["ip"]) + function printMaster(length, msg) console("[MASTER]"..msg) end @@ -15,7 +19,7 @@ max_place = "" min_place = "" function printBuildingTemp(length, msg) - local temp_str, place = pack.unpack(msg) + local temp_str, place = split(msg, ":") local temp = tonumber(temp_str) if temp > max_temp then max_temp = temp @@ -25,15 +29,13 @@ function printBuildingTemp(length, msg) min_temp = temp min_place = place end - console("Max : ["..max_place.."] "..max_temp) - console("Min : ["..min_place.."] "..min_temp) end function sendTemp() s = sensor.attach("DHT22", pio.GPIO21) tmr.delayms(500) while true do - client:publish("Building/temp", pack.pack(s:read("temperature"), "Salon"), mqtt.QOS0) + client:publish("Building/temp", s:read("temperature")..":Salon", mqtt.QOS0) tmr.delayms(5000) end end diff --git a/web.lua b/web.lua deleted file mode 100644 index 56f809a..0000000 --- a/web.lua +++ /dev/null @@ -1,9 +0,0 @@ -dofile("buzz.lua") --- s = sensor.attach("DHT22", pio.GPIO21) --- tmr.delayms(500) -nets = net.wf.scan(true) -nb = 0 -net.wf.setup(net.wf.mode.AP, "ESP32 Pierre", "sandwich134") -net.wf.start() -net.service.http.start() - diff --git a/www/buzz.lua b/www/buzz.lua deleted file mode 100644 index e448c71..0000000 --- a/www/buzz.lua +++ /dev/null @@ -1,8 +0,0 @@ - -
- - - - diff --git a/www/index.lua b/www/index.lua index c624e38..db1119c 100644 --- a/www/index.lua +++ b/www/index.lua @@ -1,3 +1,4 @@ +