From ecfe06aafafe4b02537c20d0b7fafd2ed8e1c822 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Thu, 28 Feb 2019 12:28:26 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=C3=A9=20le=20projet=20Timetable=20=C3=A0?= =?UTF-8?q?=20Alexandre=20et=20des=20scripts=20pour=20g=C3=A9rer=20le=20bo?= =?UTF-8?q?uton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Btn/btn_flipflop.lua | 28 +++++ Btn/btn_timeout.lua | 34 ++++++ Timetable/JLEB/README.md | 1 + Timetable/JLEB/boot.lua | 32 ++++++ Timetable/JLEB/diff_time.lua | 24 +++++ Timetable/JLEB/flash_led_xfois.lua | 33 ++++++ Timetable/JLEB/initz.lua | 47 +++++++++ Timetable/JLEB/jflash_2rgb.lua | 69 +++++++++++++ Timetable/JLEB/jled_rgb.lua | 38 +++++++ Timetable/JLEB/restart.lua | 12 +++ Timetable/JLEB/rm_files.lua | 12 +++ Timetable/JLEB/set_time.lua | 29 ++++++ Timetable/JLEB/web_cli.lua | 37 +++++++ Timetable/JLEB/web_ide2.lua | 159 +++++++++++++++++++++++++++++ Timetable/JLEB/wifi_ap_start.lua | 14 +++ Timetable/JLEB/wifi_cli_conf.lua | 13 +++ Timetable/JLEB/wifi_cli_start.lua | 14 +++ Timetable/JLEB/wifi_info.lua | 31 ++++++ 18 files changed, 627 insertions(+) create mode 100644 Btn/btn_flipflop.lua create mode 100644 Btn/btn_timeout.lua create mode 100644 Timetable/JLEB/README.md create mode 100644 Timetable/JLEB/boot.lua create mode 100644 Timetable/JLEB/diff_time.lua create mode 100644 Timetable/JLEB/flash_led_xfois.lua create mode 100644 Timetable/JLEB/initz.lua create mode 100644 Timetable/JLEB/jflash_2rgb.lua create mode 100644 Timetable/JLEB/jled_rgb.lua create mode 100644 Timetable/JLEB/restart.lua create mode 100644 Timetable/JLEB/rm_files.lua create mode 100644 Timetable/JLEB/set_time.lua create mode 100644 Timetable/JLEB/web_cli.lua create mode 100644 Timetable/JLEB/web_ide2.lua create mode 100644 Timetable/JLEB/wifi_ap_start.lua create mode 100644 Timetable/JLEB/wifi_cli_conf.lua create mode 100644 Timetable/JLEB/wifi_cli_start.lua create mode 100644 Timetable/JLEB/wifi_info.lua diff --git a/Btn/btn_flipflop.lua b/Btn/btn_flipflop.lua new file mode 100644 index 0000000..f026f61 --- /dev/null +++ b/Btn/btn_flipflop.lua @@ -0,0 +1,28 @@ +-- Petit scripts pour faire un flip flop avec le bouton et la led du nodemcu +-- Très intéressant la techno utilisée ici pour enlever les rebonds du micro switch +-- dans la variable b se trouve l'heure à laquelle l'interruption est arrivée, il suffit juste alors de lui mettre un petit délai de 300mS + +print("\n btn_flipflop.lua zf190228.0935 \n") + +gpio.write(0,1) +gpio.mode(0,gpio.OUTPUT) +gpio.mode(3,gpio.INT) + +d=tmr.now() + +function zled (a,b,c) + print("a: "..a..",b: "..b..",c: "..c) + if b-d > 300*1000 then + if gpio.read(0) == 0 then + gpio.write(0,1) + else + gpio.write(0,0) + end + print(gpio.read(0)) + d=b + end +end + +gpio.trig(3, "down", zled) + +print("tutu") diff --git a/Btn/btn_timeout.lua b/Btn/btn_timeout.lua new file mode 100644 index 0000000..d55f92f --- /dev/null +++ b/Btn/btn_timeout.lua @@ -0,0 +1,34 @@ +-- Petit scripts pour faire un timeout avec le bouton et la led du nodemcu +-- C'est seulement après 3 secondes de pression sur le bouton que l'on allume la led + +print("\n btn_timeout.lua zf190228.0935 \n") + +gpio.write(0,1) +gpio.mode(0,gpio.OUTPUT) +gpio.mode(3,gpio.INT) + +d=tmr.now() + +jTimer1 = tmr.create() + + +function jButton (a,b,c) + if b-d > 300*1000 then + if gpio.read(3) == 0 then + tmr.alarm(jTimer1, 3*1000, tmr.ALARM_SINGLE, jLed) + else + tmr.unregister(jTimer1) + gpio.write(0,1) + end + d=b + end +end + +function jLed() + gpio.write(0,0) +end + +gpio.trig(3, "both", jButton) + +print("tutu") + diff --git a/Timetable/JLEB/README.md b/Timetable/JLEB/README.md new file mode 100644 index 0000000..88dad5d --- /dev/null +++ b/Timetable/JLEB/README.md @@ -0,0 +1 @@ +# Affiche l'horaire du train Cheseaux à Lausanne sur un ruban de LED's RGB diff --git a/Timetable/JLEB/boot.lua b/Timetable/JLEB/boot.lua new file mode 100644 index 0000000..d4e58d6 --- /dev/null +++ b/Timetable/JLEB/boot.lua @@ -0,0 +1,32 @@ +-- Scripts à charger après le boot pour démarrer son appli + +print("\n boot.lua zf190227.1836 \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_start.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end +--f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end +f= "web_ide2.lua" if file.exists(f) then dofile(f) end +--f= "web_srv2.lua" if file.exists(f) then dofile(f) end +f= "set_time.lua" if file.exists(f) then dofile(f) end +--f= "dsleep.lua" if file.exists(f) then dofile(f) end +--f= "b.lua" if file.exists(f) then dofile(f) end +f= "jled_rgb.lua" if file.exists(f) then dofile(f) end +f= "diff_time.lua" if file.exists(f) then dofile(f) end + + + +--heartbeat() + + + + diff --git a/Timetable/JLEB/diff_time.lua b/Timetable/JLEB/diff_time.lua new file mode 100644 index 0000000..3b6dcc2 --- /dev/null +++ b/Timetable/JLEB/diff_time.lua @@ -0,0 +1,24 @@ +-- Scripts pour calculer une différence entre deux heures + +print("\n diff_time.lua zf190227.1842 \n") + +function time2sec(jtime) + jsecondes = 3600 * tonumber(string.sub(jtime,1,2)) + jsecondes = jsecondes + 60 * tonumber(string.sub(jtime,4,5)) + jsecondes = jsecondes + tonumber(string.sub(jtime,7,8)) + return jsecondes +end + +function diff_time(jtime1, jtime2) + diff_secondes = time2sec(jtime1) - time2sec(jtime2) + return diff_secondes +end + +function zround(num, dec) + local mult = 10^(dec or 0) + return math.floor(num * mult + 0.5) / mult +end + +--[[ +print(diff_time("18:42:00", "18:40:00")) +]] \ No newline at end of file diff --git a/Timetable/JLEB/flash_led_xfois.lua b/Timetable/JLEB/flash_led_xfois.lua new file mode 100644 index 0000000..c50e5ab --- /dev/null +++ b/Timetable/JLEB/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 zf181208.1521 \n") + +--zLED=0 --NodeMCU +zLED=4 --EPS-M3 +zTm_On_LED = 50 --> en ms +zTm_Off_LED = 100 --> en ms +nbfois = 0 +gpio.write(zLED, gpio.HIGH) +gpio.mode(zLED, gpio.OUTPUT) +ztmr_Flash_LED = tmr.create() + +function blink_LED () + if nbfois >= xfois then +-- print(nbfois) + nbfois = 0 + else + if gpio.read(zLED)==gpio.HIGH then + gpio.write(zLED, gpio.LOW) + tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 + tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end +end + +xfois =2 +blink_LED () + + + diff --git a/Timetable/JLEB/initz.lua b/Timetable/JLEB/initz.lua new file mode 100644 index 0000000..49a45bb --- /dev/null +++ b/Timetable/JLEB/initz.lua @@ -0,0 +1,47 @@ +--Script de bootstrap, test au moment du boot qui a été la cause de boot. +-- Si la cause est un power on ou une connexion depuis l'IDE, alors +-- le script repair.lua pendant xx secondes avant de continuer +--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason + +print("\n init.lua zf190217.1231 \n") + +zswitch=3 --switch flash +gpio.mode(zswitch, gpio.INT, gpio.PULLUP) + +function hvbouton() +-- gpio.trig(zswitch, "none") + tmr.unregister(initalarme) + f= "boot.lua" if file.exists(f) then dofile(f) end +end + +gpio.trig(zswitch, "both", hvbouton) + +function second_chance() + print("seconde chance...") + f= "repair.lua" if file.exists(f) then dofile(f) end + initalarme=tmr.create() + tmr.alarm(initalarme, 4*1000, tmr.ALARM_SINGLE, function() + f= "boot.lua" if file.exists(f) then dofile(f) end + end) +end + +_, reset_reason = node.bootreason() +print("reset_reason:",reset_reason) +if reset_reason == 0 then + print("power on") + second_chance() +elseif reset_reason == 4 then + print("node.restart") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 5 then + print("dsleep wake up") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 6 then + print("external reset") + second_chance() +-- f= "boot.lua" if file.exists(f) then dofile(f) end +else + print("autre raison") + second_chance() +end + diff --git a/Timetable/JLEB/jflash_2rgb.lua b/Timetable/JLEB/jflash_2rgb.lua new file mode 100644 index 0000000..175f8f7 --- /dev/null +++ b/Timetable/JLEB/jflash_2rgb.lua @@ -0,0 +1,69 @@ +-- Scripts juste pour flasher deux LED's sur un ruban RGB +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n jflash_2rgb.lua jv190227.1628 \n") + +dofile("jled_rgb.lua") + +zLED1=1 zLED2=6 +nbfois1 = 0 nbfois2 = 0 +zLED_state1 = 0 zLED_state2 = 0 + +R1 = 255 G1 = 0 B1 = 0 +R2 = 0 G2 = 255 B2 = 0 + +zTm_On_LED = 200 zTm_Off_LED = 400 zTm_Pause = 2000 --> en ms + +ztmr_Flash_LED1 = tmr.create() ztmr_Flash_LED2 = tmr.create() + +function flash_LED1 () + if nbfois1 >= xfois1 then + print(nbfois1) + nbfois1 = 0 + jled_rgb(zLED1,R1,G1,B1,0) + tmr.alarm(ztmr_Flash_LED1, zTm_Pause, tmr.ALARM_SINGLE, flash_LED1) + else + if zLED_state1 == 0 then + jled_rgb(zLED1,R1,G1,B1,1) + zLED_state1 = 1 + tmr.alarm(ztmr_Flash_LED1, zTm_On_LED, tmr.ALARM_SINGLE, flash_LED1) + nbfois1 = nbfois1 + 1 + else + jled_rgb(zLED1,R1,G1,B1,0) + zLED_state1 = 0 + tmr.alarm(ztmr_Flash_LED1, zTm_Off_LED, tmr.ALARM_SINGLE, flash_LED1) + end + end +end + +function flash_LED2 () + if nbfois2 >= xfois2 then + print(nbfois2) + nbfois2 = 0 + jled_rgb(zLED2,R2,G2,B2,0) + tmr.alarm(ztmr_Flash_LED2, zTm_Pause, tmr.ALARM_SINGLE, flash_LED2) + else + if zLED_state2 == 0 then + jled_rgb(zLED2,R2,G2,B2,1) + zLED_state2 = 1 + tmr.alarm(ztmr_Flash_LED2, zTm_On_LED, tmr.ALARM_SINGLE, flash_LED2) + nbfois2 = nbfois2 + 1 + else + jled_rgb(zLED2,R2,G2,B2,0) + zLED_state2 = 0 + tmr.alarm(ztmr_Flash_LED2, zTm_Off_LED, tmr.ALARM_SINGLE, flash_LED2) + end + end +end + +xfois1 =5 +flash_LED1 () +xfois2 =2 +flash_LED2 () + + +--[[ + +]] + diff --git a/Timetable/JLEB/jled_rgb.lua b/Timetable/JLEB/jled_rgb.lua new file mode 100644 index 0000000..ba6ed4d --- /dev/null +++ b/Timetable/JLEB/jled_rgb.lua @@ -0,0 +1,38 @@ +-- Scripts juste pour allumer ou éteindre une LED sur un ruban RGB +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n jled_rgb.lua jv190227.1626 \n") + +nbleds=6 +ws2812.init() +myLedStrip = ws2812.newBuffer(nbleds, 3) + +function RGB_clear() + myLedStrip:fill(0, 0, 0) ws2812.write(myLedStrip) +end + +function RGB_reform(R1, G1, B1) --RGB to GRB + rR1=G1 rG1=R1 rB1=B1 +end + +function jled_rgb(num_led, R1, G1, B1, jpower) + RGB_reform(R1, G1, B1) + myLedStrip:set(num_led, rR1*jpower, rG1*jpower, rB1*jpower) + ws2812.write(myLedStrip) +end + +function jled_write() + ws2812.write(myLedStrip) +end + + +RGB_clear() + +--[[ +jled_rgb(1,255,0,0,1) +jled_rgb(4,0,0,255,1) +jled_rgb(4,0,0,255,0.05) +jled_rgb(6,0,255,0,1) + +]] diff --git a/Timetable/JLEB/restart.lua b/Timetable/JLEB/restart.lua new file mode 100644 index 0000000..85f28eb --- /dev/null +++ b/Timetable/JLEB/restart.lua @@ -0,0 +1,12 @@ +-- Scripts pour faire un soft reset + +print("\n restart.lua zf181209.1753 \n") + +restarttimer1=tmr.create() +tmr.alarm(restarttimer1, 2*1000, tmr.ALARM_SINGLE, function() + node.restart() +end) + +print("hello zuzu") + + diff --git a/Timetable/JLEB/rm_files.lua b/Timetable/JLEB/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/Timetable/JLEB/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/Timetable/JLEB/set_time.lua b/Timetable/JLEB/set_time.lua new file mode 100644 index 0000000..748cc95 --- /dev/null +++ b/Timetable/JLEB/set_time.lua @@ -0,0 +1,29 @@ +-- Scripts pour régler l'horloge quand on est connecté en WIFI +-- Permet aussi de 'compresser' le unix time afin de prendre moins de place dans les strings + +print("\n set_time.lua zf190217.1426 \n") + +--source: https://www.freeformatter.com/epoch-timestamp-to-date-converter.html + +ztime2019 = 1546300800 -- Unix time pour le 1.1.2019 + +function set_time() + sntp.sync(nil, nil, nil, 1) +end + +function ztime_compress(ztime_long) + return ztime_long - ztime2019 +end + +function ztime_uncompress(ztime_short) + return ztime_short + ztime2019 +end + +function ztime_format(ztime) + tm = rtctime.epoch2cal(ztime + 3600) + return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])) +end + +set_time() +print(ztime_format(rtctime.get())) + diff --git a/Timetable/JLEB/web_cli.lua b/Timetable/JLEB/web_cli.lua new file mode 100644 index 0000000..dc1cd6d --- /dev/null +++ b/Timetable/JLEB/web_cli.lua @@ -0,0 +1,37 @@ +-- Petit script pour envoyer quelque chose sur un serveur WEB +print("\n web_cli.lua zf190227.1838 \n") + + +function disp_send() +-- http.get("http://192.168.4.1/?line1="..zlength.."m", nil, function(code, data) + print("web_cli: ") + http.get("http://transport.opendata.ch/v1/connections?from=Cheseaux&to=Lausanne-Flon&fields[]=connections/from/departure", nil, function(code, data) + if (code < 0) then + print("HTTP request failed") + else + print(code, data) + jp= 50 h1=string.sub (data,jp,jp+7) + jp= 100 h2=string.sub (data,jp,jp+7) + jp= 150 h3=string.sub (data,jp,jp+7) + jp= 200 h4=string.sub (data,jp,jp+7) + print(h1,h2,h3,h4) + tm = rtctime.epoch2cal(rtctime.get() + 3600) + h0 = string.format("%02d:%02d:%02d", tm["hour"], tm["min"], tm["sec"]) + d1=zround((diff_time(h2, h0)/180),0) + d2=zround((diff_time(h3, h0)/180),0) + print(d1,d2) + xfois1 = d2 xfois2 =d1 + end + end) +end + +disp_send() + + +--[[ +tm = rtctime.epoch2cal(ztime + 3600) +h0 = string.format("%02d:%02d:%02d", tm["hour"], tm["min"], tm["sec"]) +print(h0) + + +]] \ No newline at end of file diff --git a/Timetable/JLEB/web_ide2.lua b/Timetable/JLEB/web_ide2.lua new file mode 100644 index 0000000..1a7c3ab --- /dev/null +++ b/Timetable/JLEB/web_ide2.lua @@ -0,0 +1,159 @@ +-- Petit WEB IDE tout simple autonome +-- ATTENTION: tourne sur le port 88 ! + +print("\n _web_ide2.lua zf190227.1739 \n") + +--[[ +XChip's NodeMCU IDE + +Create, Edit and run NodeMCU files using your webbrowser. +Examples: +http:/// will list all the files in the MCU +http:///newfile.lua displays the file on your browser +http:///newfile.lua?edit allows to creates or edits the specified script in your browser +http:///newfile.lua?run it will run the specified script and will show the returned value +]]-- + +srv=net.createServer(net.TCP) +srv:listen(88,function(conn) + + local rnrn=0 + local Status = 0 + local DataToGet = 0 + local method="" + local url="" + local vars="" + + conn:on("receive",function(conn,payload) + + if Status==0 then + _, _, method, url, vars = string.find(payload, "([A-Z]+) /([^?]*)%??(.*) HTTP") + print(method, url, vars) + end + + if method=="POST" then + + if Status==0 then + --print("status", Status) + _,_,DataToGet, payload = string.find(payload, "Content%-Length: (%d+)(.+)") + if DataToGet~=nil then + DataToGet = tonumber(DataToGet) + --print(DataToGet) + rnrn=1 + Status = 1 + else + print("bad length") + end + end + + -- find /r/n/r/n + if Status==1 then + --print("status", Status) + local payloadlen = string.len(payload) + local mark = "\r\n\r\n" + local i + for i=1, payloadlen do + if string.byte(mark, rnrn) == string.byte(payload, i) then + rnrn=rnrn+1 + if rnrn==5 then + payload = string.sub(payload, i+1,payloadlen) + file.open(url, "w") + file.close() + Status=2 + break + end + else + rnrn=1 + end + end + if Status==1 then + return + end + end + + if Status==2 then + --print("status", Status) + if payload~=nil then + DataToGet=DataToGet-string.len(payload) + --print("DataToGet:", DataToGet, "payload len:", string.len(payload)) + file.open(url, "a+") + file.write(payload) + file.close() + else + conn:send("HTTP/1.1 200 OK\r\n\r\nERROR") + Status=0 + end + + if DataToGet==0 then + conn:send("HTTP/1.1 200 OK\r\n\r\nOK") + Status=0 + end + end + + return + end + + DataToGet = -1 + + if url == "favicon.ico" then + conn:send("HTTP/1.1 404 file not found") + return + end + + conn:send("HTTP/1.1 200 OK\r\n\r\n") + + -- it wants a file in particular + if url~="" and vars=="" then + DataToGet = 0 + return + end + + conn:send("

NodeMCU IDE

".."Connected IP: "..wifi.sta.getip().."

") + + if vars=="edit" then + conn:send("") + conn:send("

Back to file list\n") + conn:send("

run") + conn:send("



") + end + + if vars=="run" then + conn:send("") + local st, result=pcall(dofile, url) + conn:send(tostring(result)) + conn:send("") + end + + if url=="" then + local l = file.list(); + for k,v in pairs(l) do + conn:send(""..k..", size:"..v.."
") + end + end + + conn:send("") + + end) + conn:on("sent",function(conn) + if DataToGet>=0 and method=="GET" then + if file.open(url, "r") then + file.seek("set", DataToGet) + local line=file.read(512) + file.close() + if line then + conn:send(line) + DataToGet = DataToGet + 512 + + if (string.len(line)==512) then + return + end + end + end + end + + conn:close() + end) +end) +print("listening, free:", node.heap()) + diff --git a/Timetable/JLEB/wifi_ap_start.lua b/Timetable/JLEB/wifi_ap_start.lua new file mode 100644 index 0000000..1e3bd93 --- /dev/null +++ b/Timetable/JLEB/wifi_ap_start.lua @@ -0,0 +1,14 @@ +-- Démarre le WIFI en mode AP + +print("\n wifi_ap_start.lua zf190227.1727 \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 jLEB "..wifi.ap.getmac(), pwd = "12345678" }) +f= "wifi_info.lua" if file.exists(f) then dofile(f) end diff --git a/Timetable/JLEB/wifi_cli_conf.lua b/Timetable/JLEB/wifi_cli_conf.lua new file mode 100644 index 0000000..05d052a --- /dev/null +++ b/Timetable/JLEB/wifi_cli_conf.lua @@ -0,0 +1,13 @@ +-- Petit script pour configurer le client WIFI du NodeMCU + +print("\n wifi_cli_conf.lua zf190227.1723 \n") + +--credentials par défaut +--cli_ssid="3g-s7" +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/Timetable/JLEB/wifi_cli_start.lua b/Timetable/JLEB/wifi_cli_start.lua new file mode 100644 index 0000000..f1091ac --- /dev/null +++ b/Timetable/JLEB/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/Timetable/JLEB/wifi_info.lua b/Timetable/JLEB/wifi_info.lua new file mode 100644 index 0000000..5062fcf --- /dev/null +++ b/Timetable/JLEB/wifi_info.lua @@ -0,0 +1,31 @@ +-- Petit script pour afficher les infos actuel du WIFI +print("\n wifi_info.lua zf181119.0014 \n") + +local zmodewifi=wifi.getmode() + +--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP + +if zmodewifi == wifi.NULLMODE then + print("WIFI OFF") +elseif zmodewifi == wifi.STATION then + print("WIFI mode CLI") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP") + print("AP MAC:\n",wifi.ap.getmac()) + print("AP IP:\n",wifi.ap.getip()) + print("AP Connect:\n",wifi.ap.getconfig()) +elseif zmodewifi == wifi.STATIONAP then + print("WIFI mode CLI+AP") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end + print("AP MAC: "..wifi.ap.getmac()) + print("AP IP: "..wifi.ap.getip()) +end