Saataa andagii !

This commit is contained in:
Lukian 2024-12-20 13:51:47 +01:00
parent 48b0b4047e
commit ddc46bdd2a
9 changed files with 40 additions and 64 deletions

View file

@ -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")

2
js-app/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
deno.lock

View file

@ -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}`)
}
}
})

View file

@ -1,6 +0,0 @@
import { assertEquals } from "@std/assert";
import { add } from "./main.ts";
Deno.test(function addTest() {
assertEquals(add(2, 3), 5);
});

View file

@ -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

View file

@ -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()

View file

@ -1,8 +0,0 @@
<html>
<body>
<?lua
buzz(pio.GPIO21, 1000)
?>
</body>
</html>

View file

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>ESP 32 web page</title>
@ -7,13 +8,8 @@
<h1>Hello, world!</h1>
<?lua
nb = nb + 1
console(nb.." Chargements")
print(nb.." Chargements")
?>
<h1>DHT22</h1>
<?lua
-- print("Temp: "..s:read("temperature").." Humi: "..s:read("humidity"))
?>
<h1>Led</h1>
<iframe name="fd" style="display:none"></iframe>
<form action="ledon.lua" target="fd">
@ -22,17 +18,10 @@
<form action="ledoff.lua" target="fd">
<button type="submit">Off</button>
</form>
<h1>Buzzer</h1>
<form action="buzz.lua" target="fd">
<button type="submit">Buzz</button>
</form>
<h1>Networks</h1>
<ul>
<h1>Building temp</h>
<?lua
for i=0,#nets do
print("<li>"..nets[i].ssid.."</li>")
end
print("Max : ["..max_place.."] "..max_temp)
print("Min : ["..min_place.."] "..min_temp)
?>
</ul>
</body>
</html>

View file

@ -0,0 +1,5 @@
body {
background-color: black;
text-align: center;
color: white;
}