diff --git a/LED_WS2812/Alex/PoC/just_test_3x.lua b/LED_WS2812/Alex/PoC/just_test_3x.lua index c04c64a..8059019 100644 --- a/LED_WS2812/Alex/PoC/just_test_3x.lua +++ b/LED_WS2812/Alex/PoC/just_test_3x.lua @@ -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)) diff --git a/LED_WS2812/Alex/PoC/just_test_6x.lua b/LED_WS2812/Alex/PoC/just_test_6x.lua new file mode 100644 index 0000000..9c8abe0 --- /dev/null +++ b/LED_WS2812/Alex/PoC/just_test_6x.lua @@ -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 + diff --git a/LED_WS2812/Alex/PoC/webleds.lua b/LED_WS2812/Alex/PoC/webleds.lua index 6ef5da6..81bd992 100644 --- a/LED_WS2812/Alex/PoC/webleds.lua +++ b/LED_WS2812/Alex/PoC/webleds.lua @@ -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) diff --git a/LED_WS2812/Alex2/PoC.tar b/LED_WS2812/Alex2/PoC.tar new file mode 100644 index 0000000..c782384 Binary files /dev/null and b/LED_WS2812/Alex2/PoC.tar differ diff --git a/LED_WS2812/Alex2/PoC/cat.lua b/LED_WS2812/Alex2/PoC/cat.lua new file mode 100644 index 0000000..7c309b9 --- /dev/null +++ b/LED_WS2812/Alex2/PoC/cat.lua @@ -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 diff --git a/LED_WS2812/Alex2/PoC/dir.lua b/LED_WS2812/Alex2/PoC/dir.lua new file mode 100644 index 0000000..8bf9414 --- /dev/null +++ b/LED_WS2812/Alex2/PoC/dir.lua @@ -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() diff --git a/LED_WS2812/Alex2/PoC/dossier sans titre/initz.lua b/LED_WS2812/Alex2/PoC/dossier sans titre/initz.lua new file mode 100644 index 0000000..17beb40 --- /dev/null +++ b/LED_WS2812/Alex2/PoC/dossier sans titre/initz.lua @@ -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') + diff --git a/LED_WS2812/Alex2/PoC/index.html b/LED_WS2812/Alex2/PoC/index.html new file mode 100644 index 0000000..62283da --- /dev/null +++ b/LED_WS2812/Alex2/PoC/index.html @@ -0,0 +1,60 @@ + + + +LED Strip Control + + + + +

LED strip control page

+ +

Choose an effect:

+ + +

Pick a color:

+ + + + + diff --git a/LED_WS2812/Alex2/PoC/initz.lua b/LED_WS2812/Alex2/PoC/initz.lua new file mode 100644 index 0000000..97951ca --- /dev/null +++ b/LED_WS2812/Alex2/PoC/initz.lua @@ -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) diff --git a/LED_WS2812/Alex2/PoC/just_test_3x.lua b/LED_WS2812/Alex2/PoC/just_test_3x.lua new file mode 100644 index 0000000..8059019 --- /dev/null +++ b/LED_WS2812/Alex2/PoC/just_test_3x.lua @@ -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)) + diff --git a/LED_WS2812/Alex2/PoC/just_test_6x.lua b/LED_WS2812/Alex2/PoC/just_test_6x.lua new file mode 100644 index 0000000..9c8abe0 --- /dev/null +++ b/LED_WS2812/Alex2/PoC/just_test_6x.lua @@ -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 + diff --git a/LED_WS2812/Alex2/PoC/rm_files.lua b/LED_WS2812/Alex2/PoC/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/LED_WS2812/Alex2/PoC/rm_files.lua @@ -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") diff --git a/LED_WS2812/Alex2/PoC/start_boot.lua b/LED_WS2812/Alex2/PoC/start_boot.lua new file mode 100644 index 0000000..c651d1d --- /dev/null +++ b/LED_WS2812/Alex2/PoC/start_boot.lua @@ -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') + diff --git a/LED_WS2812/Alex2/PoC/webleds.lua b/LED_WS2812/Alex2/PoC/webleds.lua new file mode 100644 index 0000000..81bd992 --- /dev/null +++ b/LED_WS2812/Alex2/PoC/webleds.lua @@ -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) + diff --git a/LED_WS2812/Alex2/PoC/wifiap.lua b/LED_WS2812/Alex2/PoC/wifiap.lua new file mode 100644 index 0000000..13f559a --- /dev/null +++ b/LED_WS2812/Alex2/PoC/wifiap.lua @@ -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() + diff --git a/Wifi/dsleep.lua b/Wifi/dsleep.lua new file mode 100644 index 0000000..799d3c5 --- /dev/null +++ b/Wifi/dsleep.lua @@ -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) diff --git a/Wifi/ping.lua b/Wifi/ping.lua new file mode 100644 index 0000000..76c13b4 --- /dev/null +++ b/Wifi/ping.lua @@ -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") + + diff --git a/Wifi/wifi_cli_conf.lua b/Wifi/wifi_cli_conf.lua index d3cd11e..2ed3fe9 100644 --- a/Wifi/wifi_cli_conf.lua +++ b/Wifi/wifi_cli_conf.lua @@ -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} diff --git a/make_ping.lua b/make_ping.lua new file mode 100644 index 0000000..e11c200 --- /dev/null +++ b/make_ping.lua @@ -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)