- testé le mode deep sleep avec dsleep.lua
- fait un petit ping avec ping.lua pour tester si une machine est présente
This commit is contained in:
@@ -2,16 +2,22 @@
|
||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
||||
|
||||
print("\n just_test_3x.lua zf181105.1428 \n")
|
||||
print("\n just_test_3x.lua zf181106.0940 \n")
|
||||
|
||||
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
ws2812_effects.stop()
|
||||
strip_buffer = ws2812.newBuffer(3, 3)
|
||||
ws2812.write(string.char(0, 255, 0, 255, 0, 0, 0, 0, 255))
|
||||
ws2812.write(string.char(255, 0, 255, 0, 255, 255, 255, 255, 0))
|
||||
ws2812.write(string.char(128, 255, 64, 255, 200, 200, 200, 200, 255))
|
||||
ws2812.write(string.char(255, 255, 255, 40, 40, 40, 5, 5, 5))
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB natural
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0)) -- GBR WS2813
|
||||
ws2812.write(string.char(0, 255, 0, 255, 0, 0, 0, 0, 255)) -- GRB WS2812
|
||||
|
||||
ws2812.write(string.char(255, 0, 255, 255, 255, 0, 0, 255, 255)) -- CMY en GBR WS2813!
|
||||
ws2812.write(string.char(255, 0, 255, 0, 255, 255, 255, 255, 0)) -- CMY en GRB WS2812!
|
||||
|
||||
ws2812.write(string.char(128, 255, 64, 255, 200, 200, 200, 200, 255))
|
||||
ws2812.write(string.char(255, 255, 255, 40, 40, 40, 5, 5, 5))
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
|
||||
|
||||
21
LED_WS2812/Alex/PoC/just_test_6x.lua
Normal file
21
LED_WS2812/Alex/PoC/just_test_6x.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
-- Scripts juste pour tester 6x LED RGB
|
||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
||||
|
||||
print("\n just_test_3x.lua zf181106.1458 \n")
|
||||
|
||||
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
ws2812_effects.stop()
|
||||
strip_buffer = ws2812.newBuffer(6, 3)
|
||||
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB positionnement naturel
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255/3, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- vert compensé GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(128, 255, 128, 200, 200, 255, 255, 200, 200, 255, 255, 255, 40, 40, 40, 5, 5, 5)) -- White RGB & White 100/50/10%
|
||||
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) -- LED OFF
|
||||
|
||||
@@ -7,7 +7,7 @@ dofile('wifiap.lua')
|
||||
-- LED init (strip with 72 leds)
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
strip_buffer = ws2812.newBuffer(3, 3)
|
||||
strip_buffer = ws2812.newBuffer(6, 3)
|
||||
ws2812_effects.init(strip_buffer)
|
||||
-- initially all leds off
|
||||
ws2812_effects.set_speed(200)
|
||||
|
||||
BIN
LED_WS2812/Alex2/PoC.tar
Normal file
BIN
LED_WS2812/Alex2/PoC.tar
Normal file
Binary file not shown.
17
LED_WS2812/Alex2/PoC/cat.lua
Normal file
17
LED_WS2812/Alex2/PoC/cat.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
|
||||
print("\n cat.lua zf180826.1109 \n")
|
||||
|
||||
function cat(zfile)
|
||||
print("\n"..zfile.."\n-------------------------------")
|
||||
|
||||
zfilei = file.open(zfile, "r")
|
||||
i=1
|
||||
zline=file.readline()
|
||||
repeat
|
||||
print(i..": "..string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
until zline== nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
15
LED_WS2812/Alex2/PoC/dir.lua
Normal file
15
LED_WS2812/Alex2/PoC/dir.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- fonction dir() pour afficher les fichiers dans la flash
|
||||
print("\n dir.lua zf180826.1019 \n")
|
||||
|
||||
function dir()
|
||||
print("\n-------------------------------")
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes")
|
||||
end
|
||||
print("-------------------------------")
|
||||
print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
|
||||
end
|
||||
|
||||
dir()
|
||||
15
LED_WS2812/Alex2/PoC/dossier sans titre/initz.lua
Normal file
15
LED_WS2812/Alex2/PoC/dossier sans titre/initz.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
print()
|
||||
print("starting init.lua...")
|
||||
print()
|
||||
print("local files:")
|
||||
l=file.list()
|
||||
for k,v in pairs(l) do
|
||||
print(k.." "..v)
|
||||
end
|
||||
print()
|
||||
|
||||
print("starting webleds...")
|
||||
print()
|
||||
dofile('webleds.lua')
|
||||
|
||||
60
LED_WS2812/Alex2/PoC/index.html
Normal file
60
LED_WS2812/Alex2/PoC/index.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>LED Strip Control</title>
|
||||
<style>
|
||||
|
||||
body {
|
||||
font-family: Bitstream Vera Sans, Verdana, Helvetica, Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
background-color: #dddddd;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
/* this matches 'retina' displays */
|
||||
@media screen and (-webkit-min-device-pixel-ratio: 2) {
|
||||
body {
|
||||
font-size: 24px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 64px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 48px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>LED strip control page</h1>
|
||||
|
||||
<h2>Choose an effect:</h2>
|
||||
<ul>
|
||||
<li><a href="/?set=effect&effect=rainbow_cycle">Rainbow Cycle</a></li>
|
||||
<li><a href="/?set=effect&effect=larson_scanner">Larson Scanner</a></li>
|
||||
<li><a href="/?set=effect&effect=fire">Fire</a></li>
|
||||
<li><a href="/?set=effect&effect=blink">Blink</a></li>
|
||||
<li><a href="/?set=effect&effect=circus_combustus">Circus Combustus</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>Pick a color:</h2>
|
||||
<ul>
|
||||
<li><a href="/?set=color&r=255&g=0&b=0">Red</a></li>
|
||||
<li><a href="/?set=color&r=0&g=255&b=0">Green</a></li>
|
||||
<li><a href="/?set=color&r=0&g=0&b=255">Blue</a></li>
|
||||
<li><a href="/?set=color&r=255&g=255&b=255">White</a></li>
|
||||
<li><a href="/?set=color&r=0&g=0&b=0">Black</a></li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
23
LED_WS2812/Alex2/PoC/initz.lua
Normal file
23
LED_WS2812/Alex2/PoC/initz.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
|
||||
-- autrement en attendant 8 secondes cela démarre start_boot
|
||||
|
||||
print("\n init.lua zf181017.1026\n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
initalarme=tmr.create()
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
tmr.unregister(initalarme)
|
||||
dofile("start_boot.lua")
|
||||
-- dofile("start_job.lua")
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
tmr.alarm(initalarme, 8000, tmr.ALARM_SINGLE, function()
|
||||
print("\nStart\n")
|
||||
dofile("start_boot.lua")
|
||||
-- dofile("start_job.lua")
|
||||
end)
|
||||
23
LED_WS2812/Alex2/PoC/just_test_3x.lua
Normal file
23
LED_WS2812/Alex2/PoC/just_test_3x.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- Scripts juste pour tester 3x LED RGB
|
||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
||||
|
||||
print("\n just_test_3x.lua zf181106.0940 \n")
|
||||
|
||||
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
ws2812_effects.stop()
|
||||
strip_buffer = ws2812.newBuffer(3, 3)
|
||||
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB natural
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0)) -- GBR WS2813
|
||||
ws2812.write(string.char(0, 255, 0, 255, 0, 0, 0, 0, 255)) -- GRB WS2812
|
||||
|
||||
ws2812.write(string.char(255, 0, 255, 255, 255, 0, 0, 255, 255)) -- CMY en GBR WS2813!
|
||||
ws2812.write(string.char(255, 0, 255, 0, 255, 255, 255, 255, 0)) -- CMY en GRB WS2812!
|
||||
|
||||
ws2812.write(string.char(128, 255, 64, 255, 200, 200, 200, 200, 255))
|
||||
ws2812.write(string.char(255, 255, 255, 40, 40, 40, 5, 5, 5))
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
|
||||
21
LED_WS2812/Alex2/PoC/just_test_6x.lua
Normal file
21
LED_WS2812/Alex2/PoC/just_test_6x.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
-- Scripts juste pour tester 6x LED RGB
|
||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
||||
|
||||
print("\n just_test_3x.lua zf181106.1458 \n")
|
||||
|
||||
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
ws2812_effects.stop()
|
||||
strip_buffer = ws2812.newBuffer(6, 3)
|
||||
ws2812.write(string.char(255, 0, 0, 0, 255, 0, 0, 0, 255)) -- RGB positionnement naturel
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(0, 255, 0, 0, 0, 255/3, 255, 0, 0, 255, 0, 255, 255, 255, 0, 0, 255, 255)) -- vert compensé GBR and CMY en GBR WS2813!
|
||||
|
||||
ws2812.write(string.char(128, 255, 128, 200, 200, 255, 255, 200, 200, 255, 255, 255, 40, 40, 40, 5, 5, 5)) -- White RGB & White 100/50/10%
|
||||
|
||||
ws2812.write(string.char(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) -- LED OFF
|
||||
|
||||
12
LED_WS2812/Alex2/PoC/rm_files.lua
Normal file
12
LED_WS2812/Alex2/PoC/rm_files.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU
|
||||
|
||||
print("\n rm_files.lua zf180907.1511 \n")
|
||||
|
||||
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
file.remove(k)
|
||||
end
|
||||
print("-------------------------------")
|
||||
print("\nC'est tout effaced :-) \n")
|
||||
8
LED_WS2812/Alex2/PoC/start_boot.lua
Normal file
8
LED_WS2812/Alex2/PoC/start_boot.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
-- Scripts à charger au moment du boot
|
||||
|
||||
print("\n start_boot.lua zf181105.1122 \n")
|
||||
|
||||
print("starting webleds...")
|
||||
print()
|
||||
dofile('webleds.lua')
|
||||
|
||||
63
LED_WS2812/Alex2/PoC/webleds.lua
Normal file
63
LED_WS2812/Alex2/PoC/webleds.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
-- initially based on https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/webap_toggle_pin.lua
|
||||
|
||||
-- start wifi client or AP mode
|
||||
--dofile('wificlient.lua')
|
||||
dofile('wifiap.lua')
|
||||
|
||||
-- LED init (strip with 72 leds)
|
||||
print("Initializing LED strip...")
|
||||
ws2812.init()
|
||||
strip_buffer = ws2812.newBuffer(6, 3)
|
||||
ws2812_effects.init(strip_buffer)
|
||||
-- initially all leds off
|
||||
ws2812_effects.set_speed(200)
|
||||
ws2812_effects.set_brightness(0)
|
||||
ws2812_effects.set_color(0,0,0)
|
||||
ws2812_effects.start()
|
||||
print("done.")
|
||||
print()
|
||||
|
||||
-- helper functions
|
||||
-- send a file from memory to the client; max. line length = 1024 bytes!
|
||||
function send_file(client, filename)
|
||||
if file.open(filename, "r") then
|
||||
repeat
|
||||
local line=file.read('\n')
|
||||
if line then
|
||||
client:send(line)
|
||||
end
|
||||
until not line
|
||||
file.close()
|
||||
end
|
||||
end
|
||||
|
||||
-- web server
|
||||
srv = net.createServer(net.TCP)
|
||||
srv:listen(80, function(conn)
|
||||
conn:on("receive", function(client, request)
|
||||
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
||||
if (method == nil) then
|
||||
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
|
||||
end
|
||||
local _GET = {}
|
||||
if (vars ~= nil) then
|
||||
for k, v in string.gmatch(vars, "(%w+)=([a-z0-9_]+)&*") do
|
||||
_GET[k] = v
|
||||
end
|
||||
end
|
||||
if (_GET.set == "effect") then
|
||||
print("setting effect", _GET.effect)
|
||||
ws2812_effects.set_mode(_GET.effect)
|
||||
ws2812_effects.set_speed(200)
|
||||
ws2812_effects.set_brightness(50)
|
||||
ws2812_effects.start()
|
||||
end
|
||||
if (_GET.set == "color") then
|
||||
print("setting color (RGB)", _GET.r, _GET.g, _GET.b)
|
||||
ws2812_effects.set_color(_GET.g, _GET.r, _GET.b) -- obviously our strip is GRB and not RGB
|
||||
end
|
||||
send_file(client, 'index.html')
|
||||
end)
|
||||
conn:on("sent", function(c) c:close() end)
|
||||
end)
|
||||
|
||||
18
LED_WS2812/Alex2/PoC/wifiap.lua
Normal file
18
LED_WS2812/Alex2/PoC/wifiap.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
-- set AP mode
|
||||
wifi.setmode(wifi.SOFTAP)
|
||||
wifi.ap.config({ ssid = "webleds", pwd = "12345678" })
|
||||
print("Started AP mode")
|
||||
|
||||
-- get and display our IP addr.
|
||||
tmr.alarm(0, 1000, 1, function()
|
||||
if wifi.ap.getip() == nil then
|
||||
print("Getting AP info...")
|
||||
else
|
||||
print('IP: ', wifi.ap.getip())
|
||||
tmr.stop(0)
|
||||
end
|
||||
end)
|
||||
|
||||
print()
|
||||
|
||||
18
Wifi/dsleep.lua
Normal file
18
Wifi/dsleep.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Teste le deep sleep !
|
||||
-- s'endore pendant 3 secondes après 8 secondes
|
||||
-- à mettre à la place du init.lua
|
||||
-- ATTENTION: il faut connecter la pin 0 à la pin RESET !
|
||||
|
||||
print("\n dsleep.lua zf181113.2040 \n")
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason: ",reset_reason)
|
||||
if reset_reason == 4 then print("Coucou, soft reset...") end
|
||||
if reset_reason == 5 then print("Coucou, je suis réveillé...") end
|
||||
if reset_reason == 6 then print("Coucou, hard reset...") end
|
||||
|
||||
ztmr_SLEEP = tmr.create()
|
||||
tmr.alarm(ztmr_SLEEP, 8000, tmr.ALARM_SINGLE, function ()
|
||||
print("Je dors...")
|
||||
node.dsleep(3000000)
|
||||
end)
|
||||
29
Wifi/ping.lua
Normal file
29
Wifi/ping.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
-- Permet de tester si une adresse IP est active
|
||||
-- ATTENTION, ne fonctionne seulement s'il y a du réseau !
|
||||
|
||||
print("\n ping.lua zf181113.1937 \n")
|
||||
|
||||
function Ping(mIP)
|
||||
t1=tmr.now()
|
||||
conn=net.createConnection(net.TCP, 0)
|
||||
conn:connect(1,mIP)
|
||||
conn:on("disconnection", function(sck, c)
|
||||
-- on disconnection
|
||||
t2 = tmr.now()
|
||||
t3=(t2-t1)/1000/1000
|
||||
print(t3)
|
||||
if ((t3)<5) then
|
||||
--IPCount=IPCount+1
|
||||
print(mIP.." is active.")
|
||||
else
|
||||
print(mIP.." is not active.")
|
||||
end
|
||||
t1, t2, t3 = nil
|
||||
end)
|
||||
sck, c, conn = nil
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
Ping("192.168.0.102")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- Petit script pour configurer le client WIFI du NodeMCU
|
||||
print("\n wifi_cli_conf.lua zf180824.2000 \n")
|
||||
|
||||
wifi.sta.config{ssid="Hugo", pwd="tototutu", save=true}
|
||||
wifi.sta.config{ssid="apzuzu6", pwd="12234567", save=true}
|
||||
|
||||
20
make_ping.lua
Normal file
20
make_ping.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
-- programme pour faire des ping en permanence
|
||||
|
||||
print("\n make_ping.lua zf181113.1947 \n")
|
||||
|
||||
zLED=0
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
ztmr_LED = tmr.create()
|
||||
value = true
|
||||
|
||||
dofile("ping.lua")
|
||||
|
||||
tmr.alarm(ztmr_LED, 500, tmr.ALARM_AUTO, function ()
|
||||
if value then
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
else
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
Ping("192.168.0.102")
|
||||
end
|
||||
value = not value
|
||||
end)
|
||||
Reference in New Issue
Block a user