diff --git a/Workshop/181015/btn_led_remote/btn/flash_led_xfois.lua b/Workshop/181015/btn_led_remote/btn/flash_led_xfois.lua new file mode 100644 index 0000000..a9682d2 --- /dev/null +++ b/Workshop/181015/btn_led_remote/btn/flash_led_xfois.lua @@ -0,0 +1,33 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off +print("\n flash_led_xfois.lua zf181015.1641 \n") + + +zLED=0 +zTm_On_LED = 100 --> en ms +zTm_Off_LED = 100 --> en ms +zFlag_LED = 0 +zxfois = 0 +zxfois_max =2 + +function blink_LED () + if zxfois > zxfois_max-1 then + print(zxfois) + tmr.stop(ztmr_LED) + zFlag_LED=gpio.HIGH + else + if zFlag_LED==gpio.LOW then + zFlag_LED=gpio.HIGH + tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + zFlag_LED=gpio.LOW + tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + zxfois = zxfois+1 + end + end + gpio.write(zLED, zFlag_LED) + +end + +gpio.mode(zLED, gpio.OUTPUT) +ztmr_LED = tmr.create() +blink_LED () diff --git a/Workshop/181015/btn_led_remote/btn/start_boot.lua b/Workshop/181015/btn_led_remote/btn/start_boot.lua index 29bddab..b4754ac 100644 --- a/Workshop/181015/btn_led_remote/btn/start_boot.lua +++ b/Workshop/181015/btn_led_remote/btn/start_boot.lua @@ -1,8 +1,10 @@ -- Scripts à charger au moment du boot afin de pouvoir travailler avec le robot à distance -print("\n start_boot.lua zf181011.2342 \n") +print("\n start_boot.lua zf181015.1642 \n") +dofile("wifi_ap_stop.lua") dofile("wifi_cli_conf.lua") dofile("wifi_cli_start.lua") dofile("web_cli.lua") dofile("btn_led.lua") +dofile("flash_led_xfois.lua") diff --git a/Workshop/181015/btn_led_remote/btn/web_cli.lua b/Workshop/181015/btn_led_remote/btn/web_cli.lua index c8c66e2..84bbb6d 100644 --- a/Workshop/181015/btn_led_remote/btn/web_cli.lua +++ b/Workshop/181015/btn_led_remote/btn/web_cli.lua @@ -1,10 +1,10 @@ -- Petit script pour envoyer quelque chose sur un serveur WEB -print("\n web_cli.lua zf181011.2352 \n") +print("\n web_cli.lua zf181015.1625 \n") function disp_send() -- http.get("http://192.168.4.1/?line1="..zlength.."m", nil, function(code, data) print("web_cli: "..zled_state) - http.get("http://192.168.0.122/?pin="..zled_state, nil, function(code, data) + http.get("http://192.168.4.1/?pin="..zled_state, nil, function(code, data) if (code < 0) then print("HTTP request failed") else diff --git a/Workshop/181015/btn_led_remote/btn/wifi_ap_stop.lua b/Workshop/181015/btn_led_remote/btn/wifi_ap_stop.lua new file mode 100644 index 0000000..2738627 --- /dev/null +++ b/Workshop/181015/btn_led_remote/btn/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/Workshop/181015/btn_led_remote/btn/wifi_cli_conf.lua b/Workshop/181015/btn_led_remote/btn/wifi_cli_conf.lua index 2f54e32..73d2688 100644 --- a/Workshop/181015/btn_led_remote/btn/wifi_cli_conf.lua +++ b/Workshop/181015/btn_led_remote/btn/wifi_cli_conf.lua @@ -1,4 +1,5 @@ -- Petit script pour configurer le client WIFI du NodeMCU -print("\n wifi_cli_conf.lua zf181011.2338 \n") +print("\n wifi_cli_conf.lua zf181015.1624 \n") + +wifi.sta.config{ssid="NodeMCU btn 3a:2b:78:04:2d:2d", pwd="12345678", save=true} -wifi.sta.config{ssid="apzuzu6", pwd="12234567", save=true} diff --git a/Workshop/181015/btn_led_remote/led/flash_led_xfois.lua b/Workshop/181015/btn_led_remote/led/flash_led_xfois.lua new file mode 100644 index 0000000..a9682d2 --- /dev/null +++ b/Workshop/181015/btn_led_remote/led/flash_led_xfois.lua @@ -0,0 +1,33 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off +print("\n flash_led_xfois.lua zf181015.1641 \n") + + +zLED=0 +zTm_On_LED = 100 --> en ms +zTm_Off_LED = 100 --> en ms +zFlag_LED = 0 +zxfois = 0 +zxfois_max =2 + +function blink_LED () + if zxfois > zxfois_max-1 then + print(zxfois) + tmr.stop(ztmr_LED) + zFlag_LED=gpio.HIGH + else + if zFlag_LED==gpio.LOW then + zFlag_LED=gpio.HIGH + tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + zFlag_LED=gpio.LOW + tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + zxfois = zxfois+1 + end + end + gpio.write(zLED, zFlag_LED) + +end + +gpio.mode(zLED, gpio.OUTPUT) +ztmr_LED = tmr.create() +blink_LED () diff --git a/Workshop/181015/btn_led_remote/led/rm_files.lua b/Workshop/181015/btn_led_remote/led/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/Workshop/181015/btn_led_remote/led/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/Workshop/181015/btn_led_remote/led/start_boot.lua b/Workshop/181015/btn_led_remote/led/start_boot.lua index a2f3e4e..f696f1c 100644 --- a/Workshop/181015/btn_led_remote/led/start_boot.lua +++ b/Workshop/181015/btn_led_remote/led/start_boot.lua @@ -1,7 +1,9 @@ -- Scripts à charger au moment du boot afin de pouvoir travailler avec le robot à distance -print("\n start_boot.lua zf181011.2338 \n") +print("\n start_boot.lua zf181015.1643 \n") -dofile("wifi_cli_conf.lua") -dofile("wifi_cli_start.lua") +dofile("wifi_cli_stop.lua") +dofile("wifi_ap_start.lua") dofile("web_led_onoff.lua") +dofile("flash_led_xfois.lua") + diff --git a/Workshop/181015/btn_led_remote/led/web_led_onoff.lua b/Workshop/181015/btn_led_remote/led/web_led_onoff.lua index 7ff2709..041c760 100644 --- a/Workshop/181015/btn_led_remote/led/web_led_onoff.lua +++ b/Workshop/181015/btn_led_remote/led/web_led_onoff.lua @@ -1,5 +1,6 @@ --Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI ---hv20180711.1606 + +print("\n web_led_onoff.lua zf181015.1622 \n") print("Démarrage") --wifi.sta.disconnect() @@ -7,7 +8,7 @@ print("Démarrage") --print("set mode=STATION (mode="..wifi.getmode()..")") --wifi.sta.config{ssid="Hugo", pwd="tototutu"} -wifi.sta.connect() +--[[wifi.sta.connect() tmr.alarm(0, 1000, tmr.ALARM_AUTO , function() if wifi.sta.getip() == nil then @@ -17,6 +18,7 @@ tmr.alarm(0, 1000, tmr.ALARM_AUTO , function() tmr.stop(0) end end) +]] zLED=0 gpio.mode(zLED, gpio.OUTPUT) @@ -38,13 +40,13 @@ srv:listen(80, function(conn) buf = buf .. "

Hello, this is NodeMCU.

Turn PIN
" + buf = buf .. "OFFON" client:send(buf) end) conn:on("sent", function(c) c:close() end) diff --git a/Workshop/181015/btn_led_remote/led/wifi_ap_start.lua b/Workshop/181015/btn_led_remote/led/wifi_ap_start.lua new file mode 100644 index 0000000..2a971dc --- /dev/null +++ b/Workshop/181015/btn_led_remote/led/wifi_ap_start.lua @@ -0,0 +1,13 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_ap_start.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.NULLMODE then + print("WIFI mode AP only") + wifi.setmode(wifi.SOFTAP) +elseif zmodewifi == wifi.STATION then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) +end +wifi.ap.config({ ssid = "NodeMCU ".."btn "..wifi.ap.getmac(), pwd = "12345678" }) +dofile("wifi_info.lua") diff --git a/Workshop/181015/btn_led_remote/led/wifi_cli_conf.lua b/Workshop/181015/btn_led_remote/led/wifi_cli_conf.lua deleted file mode 100644 index 2f54e32..0000000 --- a/Workshop/181015/btn_led_remote/led/wifi_cli_conf.lua +++ /dev/null @@ -1,4 +0,0 @@ --- Petit script pour configurer le client WIFI du NodeMCU -print("\n wifi_cli_conf.lua zf181011.2338 \n") - -wifi.sta.config{ssid="apzuzu6", pwd="12234567", save=true} diff --git a/Workshop/181015/btn_led_remote/led/wifi_cli_start.lua b/Workshop/181015/btn_led_remote/led/wifi_cli_start.lua deleted file mode 100644 index aac8bea..0000000 --- a/Workshop/181015/btn_led_remote/led/wifi_cli_start.lua +++ /dev/null @@ -1,14 +0,0 @@ --- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM -print("\n wifi_cli_start.lua zf180824.2000 \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() -dofile("wifi_get_ip.lua") diff --git a/Workshop/181015/btn_led_remote/led/wifi_cli_stop.lua b/Workshop/181015/btn_led_remote/led/wifi_cli_stop.lua new file mode 100644 index 0000000..9429aa5 --- /dev/null +++ b/Workshop/181015/btn_led_remote/led/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/Workshop/181015/btn_led_remote/script1.lua b/Workshop/181015/btn_led_remote/script1.lua new file mode 100644 index 0000000..ff5afc3 --- /dev/null +++ b/Workshop/181015/btn_led_remote/script1.lua @@ -0,0 +1,3 @@ +a=3 +b=77 +print(a*b)