From cb81ed2a221783f4ce22c4791cfa54cfe664b990 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Wed, 5 Dec 2018 20:51:10 +0100 Subject: [PATCH] =?UTF-8?q?Super=20bien=20avanc=C3=A9=20sur=20la=20d=C3=A9?= =?UTF-8?q?mo=20du=20chapeau,=20good=20job=20*=20il=20y=20a=20maintenant?= =?UTF-8?q?=20un=20petit=20serveur=20WEB=20qui=20permet=20de=20modifier=20?= =?UTF-8?q?certains=20param=C3=A8tres=20de=20l'effet=20lumineux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LED_RGB_WS2812/chapeau_led/a_train3.lua | 10 +- LED_RGB_WS2812/chapeau_led/boot.lua | 21 ++-- LED_RGB_WS2812/chapeau_led/credentials.lua | 9 ++ LED_RGB_WS2812/chapeau_led/goodies/index.html | 60 --------- .../chapeau_led/goodies/webleds.lua | 63 ---------- .../chapeau_led/goodies/wifi_ap_stop.lua | 10 ++ .../chapeau_led/goodies/wifi_cli_stop.lua | 10 ++ LED_RGB_WS2812/chapeau_led/index.html | 68 +++++++++++ LED_RGB_WS2812/chapeau_led/webleds.lua | 111 +++++++++++++++++ LED_RGB_WS2812/chapeau_led/wifi_cli_conf.lua | 12 ++ LED_RGB_WS2812/chapeau_led/wifi_cli_start.lua | 14 +++ .../chapeau_led/{goodies => }/wifi_get_ip.lua | 0 .../chapeau_led/{goodies => }/wifi_info.lua | 0 .../train effect/effect3/a_train3.lua | 115 +++++++++--------- 14 files changed, 309 insertions(+), 194 deletions(-) create mode 100644 LED_RGB_WS2812/chapeau_led/credentials.lua delete mode 100644 LED_RGB_WS2812/chapeau_led/goodies/index.html delete mode 100644 LED_RGB_WS2812/chapeau_led/goodies/webleds.lua create mode 100644 LED_RGB_WS2812/chapeau_led/goodies/wifi_ap_stop.lua create mode 100644 LED_RGB_WS2812/chapeau_led/goodies/wifi_cli_stop.lua create mode 100644 LED_RGB_WS2812/chapeau_led/index.html create mode 100644 LED_RGB_WS2812/chapeau_led/webleds.lua create mode 100644 LED_RGB_WS2812/chapeau_led/wifi_cli_conf.lua create mode 100644 LED_RGB_WS2812/chapeau_led/wifi_cli_start.lua rename LED_RGB_WS2812/chapeau_led/{goodies => }/wifi_get_ip.lua (100%) rename LED_RGB_WS2812/chapeau_led/{goodies => }/wifi_info.lua (100%) diff --git a/LED_RGB_WS2812/chapeau_led/a_train3.lua b/LED_RGB_WS2812/chapeau_led/a_train3.lua index 7015d13..a3cf167 100644 --- a/LED_RGB_WS2812/chapeau_led/a_train3.lua +++ b/LED_RGB_WS2812/chapeau_led/a_train3.lua @@ -2,12 +2,12 @@ -- tout sur la couleur: https://www.w3schools.com/colors/default.asp -- roue des couleurs: https://iro.js.org/?ref=oldsite -print("\n a_train3.lua zf181205.1903 \n") +print("\n a_train3.lua zf181205.1919 \n") nbleds=36 -fade1=0.05 ; fade2=0.2 ; fade3=0.4 ; fade4=1 -R1=255 ; G1=0 ; B1=0 -R2=255 ; G2=0 ; B2=0 +fade1=0.05 fade2=0.2 fade3=0.4 fade4=1 +R1=255 G1=0 B1=0 +R2=255 G2=0 B2=0 train_speed=50 ws2812.init() myLedStrip = ws2812.newBuffer(nbleds, 3) @@ -15,7 +15,7 @@ myLedStrip1 = ws2812.newBuffer(nbleds, 3) myLedStrip2 = ws2812.newBuffer(nbleds, 3) function RGB_clear() - myLedStrip:fill(0, 0, 0) ; ws2812.write(myLedStrip) + myLedStrip:fill(0, 0, 0) ws2812.write(myLedStrip) end function train1_fill() diff --git a/LED_RGB_WS2812/chapeau_led/boot.lua b/LED_RGB_WS2812/chapeau_led/boot.lua index c98546e..96a4082 100644 --- a/LED_RGB_WS2812/chapeau_led/boot.lua +++ b/LED_RGB_WS2812/chapeau_led/boot.lua @@ -1,6 +1,15 @@ -- Scripts à charger après le boot pour démarrer son appli -print("\n boot.lua zf181204.2059 \n") +print("\n boot.lua zf181205.2048 \n") + +function heartbeat() + f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + boottimer1=tmr.create() + tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function() + xfois =2 + blink_LED () + end) +end --f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end --f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end @@ -8,16 +17,12 @@ print("\n boot.lua zf181204.2059 \n") --f= "telnet_srv.lua" if file.exists(f) then dofile(f) end --f= "web_ide2.lua" if file.exists(f) then dofile(f) end f= "az_init_led.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end +f= "webleds.lua" if file.exists(f) then dofile(f) end f= "a_train3.lua" if file.exists(f) then dofile(f) end +heartbeat() -f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end -boottimer1=tmr.create() -tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function() - xfois =2 - blink_LED () -end) - diff --git a/LED_RGB_WS2812/chapeau_led/credentials.lua b/LED_RGB_WS2812/chapeau_led/credentials.lua new file mode 100644 index 0000000..0efde32 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/credentials.lua @@ -0,0 +1,9 @@ +-- Petit script pour configurer les choses secrètes que l'on n'aimerait +-- pas être exportées sur Internet (github) +-- faut donc le mettre ailleurs que dans le dépôt ! + +print("\n credential.lua zf181205.1910 \n") + +cli_ssid="3g-s7" +cli_pwd="12234567" + diff --git a/LED_RGB_WS2812/chapeau_led/goodies/index.html b/LED_RGB_WS2812/chapeau_led/goodies/index.html deleted file mode 100644 index 62283da..0000000 --- a/LED_RGB_WS2812/chapeau_led/goodies/index.html +++ /dev/null @@ -1,60 +0,0 @@ - - - -LED Strip Control - - - - -

LED strip control page

- -

Choose an effect:

- - -

Pick a color:

- - - - - diff --git a/LED_RGB_WS2812/chapeau_led/goodies/webleds.lua b/LED_RGB_WS2812/chapeau_led/goodies/webleds.lua deleted file mode 100644 index 81bd992..0000000 --- a/LED_RGB_WS2812/chapeau_led/goodies/webleds.lua +++ /dev/null @@ -1,63 +0,0 @@ --- 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_RGB_WS2812/chapeau_led/goodies/wifi_ap_stop.lua b/LED_RGB_WS2812/chapeau_led/goodies/wifi_ap_stop.lua new file mode 100644 index 0000000..2738627 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/wifi_ap_stop.lua @@ -0,0 +1,10 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_ap_stop.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.SOFTAP then + wifi.setmode(wifi.NULLMODE) +elseif zmodewifi == wifi.STATIONAP then + wifi.setmode(wifi.STATION) +end +print("WIFI AP arrêté") diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_cli_stop.lua b/LED_RGB_WS2812/chapeau_led/goodies/wifi_cli_stop.lua new file mode 100644 index 0000000..9429aa5 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/goodies/wifi_cli_stop.lua @@ -0,0 +1,10 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_cli_stop.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.STATION then + wifi.setmode(wifi.NULLMODE) +elseif zmodewifi == wifi.STATIONAP then + wifi.setmode(wifi.SOFTAP) +end +print("WIFI CLI arrêté") diff --git a/LED_RGB_WS2812/chapeau_led/index.html b/LED_RGB_WS2812/chapeau_led/index.html new file mode 100644 index 0000000..59cf3db --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/index.html @@ -0,0 +1,68 @@ + + + + + +LED RGB zf181205.2048 + + + + +

Contrôle des effets des LED's RGB du chapeau

+ +Home + +

Start & Stop:

+ + +

Vitesse de l'effet:

+ + +

Couleurs des trains:

+ + +Restart + + + + diff --git a/LED_RGB_WS2812/chapeau_led/webleds.lua b/LED_RGB_WS2812/chapeau_led/webleds.lua new file mode 100644 index 0000000..9a43d38 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/webleds.lua @@ -0,0 +1,111 @@ +-- Petit script de serveur WEB pour piloter les effets des LED RGB +-- source: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/webap_toggle_pin.lua + +print("\n webleds.lua zf181205.2048 \n") + + +-- 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 not string.find(request, "/favicon.ico") then + --print("coucou") + if (method == nil) then + _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP") + end + _GET = {} + if (vars ~= nil) then + for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do + _GET[k] = v + print(k..": "..v) + end + end + + if (_GET.fonction == "start") then + train_start() + end + + if (_GET.fonction == "stop") then + train_stop() + end + + if (_GET.set == "speed") then + train_stop() + if (_GET.speed == "inc") then + train_speed=train_speed*0.8 + else + train_speed=train_speed*1.2 + end + train_start() + end + + if (_GET.set == "color") then + print("setting color (RGB)", _GET.R1, _GET.G1, _GET.B1) + train_stop() + R1=_GET.R1 G1=_GET.G1 B1=_GET.B1 + R2=_GET.R2 G2=_GET.G2 B2=_GET.B2 + train1_fill() + train2_fill() + train_start() + end + + if (_GET.restart == "1") then + restarttimer1=tmr.create() + tmr.alarm(restarttimer1, 2*1000, tmr.ALARM_SINGLE, function() + node.restart() + end) + end + + + print("send html...") + send_file(client, 'index.html') + end + + + +--[[ + 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_RGB_WS2812/chapeau_led/wifi_cli_conf.lua b/LED_RGB_WS2812/chapeau_led/wifi_cli_conf.lua new file mode 100644 index 0000000..6726313 --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/wifi_cli_conf.lua @@ -0,0 +1,12 @@ +-- Petit script pour configurer le client WIFI du NodeMCU + +print("\n wifi_cli_conf.lua zf181205.1931 \n") + +--credentials par défaut +cli_ssid="3g-s7" +cli_pwd="12234567" + +--ses propre credentials +f= "credentials.lua" if file.exists(f) then dofile(f) end + +wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true} diff --git a/LED_RGB_WS2812/chapeau_led/wifi_cli_start.lua b/LED_RGB_WS2812/chapeau_led/wifi_cli_start.lua new file mode 100644 index 0000000..f1091ac --- /dev/null +++ b/LED_RGB_WS2812/chapeau_led/wifi_cli_start.lua @@ -0,0 +1,14 @@ +-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM +print("\n wifi_cli_start.lua zf181119.2359 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.NULLMODE then + print("WIFI mode CLI only") + wifi.setmode(wifi.STATION) +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) +end +wifi.sta.autoconnect(1) +wifi.sta.connect() +f= "wifi_get_ip.lua" if file.exists(f) then dofile(f) end diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_get_ip.lua b/LED_RGB_WS2812/chapeau_led/wifi_get_ip.lua similarity index 100% rename from LED_RGB_WS2812/chapeau_led/goodies/wifi_get_ip.lua rename to LED_RGB_WS2812/chapeau_led/wifi_get_ip.lua diff --git a/LED_RGB_WS2812/chapeau_led/goodies/wifi_info.lua b/LED_RGB_WS2812/chapeau_led/wifi_info.lua similarity index 100% rename from LED_RGB_WS2812/chapeau_led/goodies/wifi_info.lua rename to LED_RGB_WS2812/chapeau_led/wifi_info.lua diff --git a/LED_RGB_WS2812/train effect/effect3/a_train3.lua b/LED_RGB_WS2812/train effect/effect3/a_train3.lua index 258aab1..7015d13 100644 --- a/LED_RGB_WS2812/train effect/effect3/a_train3.lua +++ b/LED_RGB_WS2812/train effect/effect3/a_train3.lua @@ -2,68 +2,67 @@ -- tout sur la couleur: https://www.w3schools.com/colors/default.asp -- roue des couleurs: https://iro.js.org/?ref=oldsite -print("\n a_chapeau_z.lua zf181204.2057 \n") +print("\n a_train3.lua zf181205.1903 \n") -znbled=36 +nbleds=36 +fade1=0.05 ; fade2=0.2 ; fade3=0.4 ; fade4=1 +R1=255 ; G1=0 ; B1=0 +R2=255 ; G2=0 ; B2=0 +train_speed=50 +ws2812.init() +myLedStrip = ws2812.newBuffer(nbleds, 3) +myLedStrip1 = ws2812.newBuffer(nbleds, 3) +myLedStrip2 = ws2812.newBuffer(nbleds, 3) function RGB_clear() - ws2812.init() - buffer = ws2812.newBuffer(znbled, 3) - buffer:fill(0, 0, 0) - ws2812.write(buffer) + myLedStrip:fill(0, 0, 0) ; ws2812.write(myLedStrip) +end + +function train1_fill() + myLedStrip1:fill(0,0,0) + myLedStrip1:set(1, G1*fade1, R1*fade1, B1*fade1) + myLedStrip1:set(2, G1*fade2, R1*fade2, B1*fade2) + myLedStrip1:set(3, G1*fade3, R1*fade3, B1*fade3) + myLedStrip1:set(4, G1*fade4, R1*fade4, B1*fade4) +end + +function train2_fill() + myLedStrip2:fill(0,0,0) + myLedStrip2:set(nbleds, G2*fade1, R2*fade1, B2*fade1) + myLedStrip2:set(nbleds-1, G2*fade2, R2*fade2, B2*fade2) + myLedStrip2:set(nbleds-2, G2*fade3, R2*fade3, B2*fade3) + myLedStrip2:set(nbleds-3, G2*fade4, R2*fade4, B2*fade4) +end + +function train_mix() + myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2) +end + +function train_shift() + myLedStrip1:shift(1, ws2812.SHIFT_CIRCULAR) + myLedStrip2:shift(-1, ws2812.SHIFT_CIRCULAR) +end + +function train_write() + ws2812.write(myLedStrip) +end + +function train_start() + train3timer1=tmr.create() + tmr.alarm(train3timer1, train_speed, tmr.ALARM_AUTO, function() + train_shift() + train_mix() + train_write() + end) +end + +function train_stop() + tmr.unregister(train3timer1) + RGB_clear() end RGB_clear() +train1_fill() +train2_fill() +train_start() - -fadeLevel=3 - -train1_R=255 -train1_G=0 -train1_B=0 - -train2_R=255 -train2_G=0 -train2_B=0 - --- Buffer Train 1 -myLedStrip1 = ws2812.newBuffer(znbled, 3) -myLedStrip1:fill(0,0,0) -myLedStrip1:set(1, train1_G, train1_R, train1_B) -myLedStrip1:fade(fadeLevel) -myLedStrip1:set(2, train1_G, train1_R, train1_B) -myLedStrip1:fade(fadeLevel) -myLedStrip1:set(3, train1_G, train1_R, train1_B) -myLedStrip1:fade(fadeLevel) -myLedStrip1:set(4, train1_G, train1_R, train1_B) -ws2812.write(myLedStrip1) - --- Buffer Train 2 -myLedStrip2 = ws2812.newBuffer(znbled, 3) -myLedStrip2:fill(0,0,0) -myLedStrip2:set(znbled, train2_G, train2_R, train2_B) -myLedStrip2:fade(fadeLevel) -myLedStrip2:set(znbled-1, train2_G, train2_R, train2_B) -myLedStrip2:fade(fadeLevel) -myLedStrip2:set(znbled-2, train2_G, train2_R, train2_B) -myLedStrip2:fade(fadeLevel) -myLedStrip2:set(znbled-3, train2_G, train2_R, train2_B) -ws2812.write(myLedStrip2) - --- Buffer Train Total -myLedStrip = ws2812.newBuffer(znbled, 3) -myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2) -ws2812.write(myLedStrip) - --- Train move -zspeed=25 -train2timer1=tmr.create() -tmr.alarm(train2timer1, zspeed, tmr.ALARM_AUTO, function() - - myLedStrip1:shift(1, ws2812.SHIFT_CIRCULAR) -- direction → - myLedStrip2:shift(-1, ws2812.SHIFT_CIRCULAR) -- direction ← - - myLedStrip:mix(255, myLedStrip1, 255, myLedStrip2) -- mix both train - ws2812.write(myLedStrip) - -end)