Saataa andagii !
This commit is contained in:
parent
48b0b4047e
commit
ddc46bdd2a
9 changed files with 40 additions and 64 deletions
|
@ -5,12 +5,6 @@ dofile("main.lua")
|
||||||
-- affiche la température du CPU
|
-- affiche la température du CPU
|
||||||
printTemp()
|
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
|
-- connection au brooker mqtt
|
||||||
dofile("mqtt.lua")
|
dofile("mqtt.lua")
|
||||||
|
|
||||||
|
|
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 app = express()
|
||||||
const client = mqtt.connect("mqtt://localhost")
|
const client = mqtt.connect("mqtt://localhost")
|
||||||
|
|
||||||
var temp = {
|
var vals = {
|
||||||
"min": {
|
"min": {
|
||||||
"temp": 100,
|
"temp": 100,
|
||||||
"place": ""
|
"place": ""
|
||||||
|
@ -16,22 +16,29 @@ var temp = {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get("/temp", (req, res) => {
|
app.get("/temp", (req, res) => {
|
||||||
res.status(200).send({
|
res.status(200).send(vals)
|
||||||
"min": {
|
|
||||||
"temp": 12,
|
|
||||||
"place": "Salon"
|
|
||||||
},
|
|
||||||
"max": {
|
|
||||||
"temp": 50,
|
|
||||||
"place": 'Four'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
client.on("connect", () => {
|
||||||
|
client.subscribe("Building/temp", (err) => {
|
||||||
|
console.log("Subscribed to Building/temp topic.")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
client.on("message", (topic, message) => {
|
client.on("message", (topic, message) => {
|
||||||
console.log(topic, message.toString())
|
if (topic == "Building/temp") {
|
||||||
if (topic == "temp") {
|
const [ temp_str, place ] = message.toString().split(":")
|
||||||
console.log(message.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);
|
|
||||||
});
|
|
10
mqtt.lua
10
mqtt.lua
|
@ -1,6 +1,10 @@
|
||||||
client = mqtt.client("ESP32", "192.168.0.11", 1883, false)
|
client = mqtt.client("ESP32", "192.168.0.11", 1883, false)
|
||||||
client:connect("","")
|
client:connect("","")
|
||||||
|
|
||||||
|
nb = 0
|
||||||
|
net.service.http.start()
|
||||||
|
console(net.stat(true)[0]["ip"])
|
||||||
|
|
||||||
function printMaster(length, msg)
|
function printMaster(length, msg)
|
||||||
console("[MASTER]"..msg)
|
console("[MASTER]"..msg)
|
||||||
end
|
end
|
||||||
|
@ -15,7 +19,7 @@ max_place = ""
|
||||||
min_place = ""
|
min_place = ""
|
||||||
|
|
||||||
function printBuildingTemp(length, msg)
|
function printBuildingTemp(length, msg)
|
||||||
local temp_str, place = pack.unpack(msg)
|
local temp_str, place = split(msg, ":")
|
||||||
local temp = tonumber(temp_str)
|
local temp = tonumber(temp_str)
|
||||||
if temp > max_temp then
|
if temp > max_temp then
|
||||||
max_temp = temp
|
max_temp = temp
|
||||||
|
@ -25,15 +29,13 @@ function printBuildingTemp(length, msg)
|
||||||
min_temp = temp
|
min_temp = temp
|
||||||
min_place = place
|
min_place = place
|
||||||
end
|
end
|
||||||
console("Max : ["..max_place.."] "..max_temp)
|
|
||||||
console("Min : ["..min_place.."] "..min_temp)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function sendTemp()
|
function sendTemp()
|
||||||
s = sensor.attach("DHT22", pio.GPIO21)
|
s = sensor.attach("DHT22", pio.GPIO21)
|
||||||
tmr.delayms(500)
|
tmr.delayms(500)
|
||||||
while true do
|
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)
|
tmr.delayms(5000)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
9
web.lua
9
web.lua
|
@ -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()
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<?lua
|
|
||||||
buzz(pio.GPIO21, 1000)
|
|
||||||
?>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>ESP 32 web page</title>
|
<title>ESP 32 web page</title>
|
||||||
|
@ -7,13 +8,8 @@
|
||||||
<h1>Hello, world!</h1>
|
<h1>Hello, world!</h1>
|
||||||
<?lua
|
<?lua
|
||||||
nb = nb + 1
|
nb = nb + 1
|
||||||
console(nb.." Chargements")
|
|
||||||
print(nb.." Chargements")
|
print(nb.." Chargements")
|
||||||
?>
|
?>
|
||||||
<h1>DHT22</h1>
|
|
||||||
<?lua
|
|
||||||
-- print("Temp: "..s:read("temperature").." Humi: "..s:read("humidity"))
|
|
||||||
?>
|
|
||||||
<h1>Led</h1>
|
<h1>Led</h1>
|
||||||
<iframe name="fd" style="display:none"></iframe>
|
<iframe name="fd" style="display:none"></iframe>
|
||||||
<form action="ledon.lua" target="fd">
|
<form action="ledon.lua" target="fd">
|
||||||
|
@ -22,17 +18,10 @@
|
||||||
<form action="ledoff.lua" target="fd">
|
<form action="ledoff.lua" target="fd">
|
||||||
<button type="submit">Off</button>
|
<button type="submit">Off</button>
|
||||||
</form>
|
</form>
|
||||||
<h1>Buzzer</h1>
|
<h1>Building temp</h>
|
||||||
<form action="buzz.lua" target="fd">
|
<?lua
|
||||||
<button type="submit">Buzz</button>
|
print("Max : ["..max_place.."] "..max_temp)
|
||||||
</form>
|
print("Min : ["..min_place.."] "..min_temp)
|
||||||
<h1>Networks</h1>
|
?>
|
||||||
<ul>
|
|
||||||
<?lua
|
|
||||||
for i=0,#nets do
|
|
||||||
print("<li>"..nets[i].ssid.."</li>")
|
|
||||||
end
|
|
||||||
?>
|
|
||||||
</ul>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
text-align: center;
|
||||||
|
color: white;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue