Commencé à tester le petit WEB IDE de Matthieu Borgognon ;-)

This commit is contained in:
Christian Zufferey
2019-10-20 12:32:30 +02:00
parent d1ffbc522c
commit 32dc293415
10 changed files with 250 additions and 14 deletions

View File

@@ -0,0 +1,17 @@
f= "web_ide.lc" if file.exists(f)==false then
print("no exist")
end
--[[
f= "web_ide.lua" if file.exists(f) then dofile(f) end
node.compile("hello.lua")
f= "web_ide.lc" if file.exists(f) then dofile(f) end
]]

View File

@@ -0,0 +1,15 @@
-- Scripts à charger après le boot pour démarrer le core system
print("\n boot.lua zf191020.1150 \n")
-- charge ses propres secrets
f= "secrets_energy.lua" if file.exists(f) then dofile(f) end
--f= "led_rgb.lua" if file.exists(f) then dofile(f) end
--f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) 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
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

View File

@@ -0,0 +1,22 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n boot2.lua zf191020.1151 \n")
second_chance=nil
function heartbeat()
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
flash_led_xfois()
boottimer1=tmr.create()
boottimer1:alarm(1*1000, tmr.ALARM_AUTO, function()
xfois =2
blink_LED ()
end)
end
--f= "0_get_data.lua" if file.exists(f) then dofile(f) end
--f= "0_send_data.lua" if file.exists(f) then dofile(f) end
--f= "0_cron.lua" if file.exists(f) then dofile(f) end
f=nil
--heartbeat=nil
heartbeat()

View File

@@ -0,0 +1,39 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
function flash_led_xfois()
print("\n flash_led_xfois.lua zf190601.1618 \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)
ztmr_Flash_LED:alarm(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)
ztmr_Flash_LED:alarm(zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
end
end
-- xfois =2
-- blink_LED ()
end

View File

@@ -0,0 +1,63 @@
--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 zf190917.0001 \n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
function hvbouton()
gpio.trig(zswitch, "none")
initalarme:unregister() initalarme2:unregister()
f= "boot.lua" if file.exists(f) then dofile(f) end
f= "boot2.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()
initalarme:alarm(4*1000, tmr.ALARM_SINGLE, function()
f= "boot.lua" if file.exists(f) then dofile(f) end
end)
initalarme2=tmr.create()
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
gpio.trig(zswitch)
hvbouton=nil
zswitch=nil
reset_reason=nil
f= "boot2.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")
gpio.trig(zswitch)
hvbouton=nil
second_chance=nil
zswitch=nil
reset_reason=nil
f= "boot.lua" if file.exists(f) then dofile(f) end
f= "boot2.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
f= "boot2.lua" if file.exists(f) then dofile(f) end
elseif reset_reason == 6 then
print("external reset")
second_chance()
else
print("autre raison")
second_chance()
end

View File

@@ -1,3 +1,9 @@
-- Petit WEB_IDE assez génial
-- Source: https://github.com/matbgn/NodeMCU/tree/master/lib/web-ide
print("\n web_ide.lua zf191020.1211 \n")
local mPort = 88
local function editor(aceEnabled) -- feel free to disable the shiny Ajax.org Cloud Editor
@@ -121,10 +127,12 @@ local function editor(aceEnabled) -- feel free to disable the shiny Ajax.org Clo
node.output(s_output, 0) -- re-direct output to function s_output.
local st, result = pcall(dofile, url)
-- delay the output capture by 1000 milliseconds to give some time to the user routine in pcall()
tmr.alarm(0, 1000, tmr.ALARM_SINGLE, function()
node.output(nil)
-- tmr.alarm(0, 1000, tmr.ALARM_SINGLE, function()
local ztmr_web_ide1 = tmr.create()
ztmr_web_ide1:alarm(1000, tmr.ALARM_SINGLE, function()
ztmr_web_ide1=nil node.output(nil)
if result then
local outp = tostring(result):sub(1,1300) -- to fit in one send() packet
result = nil
@@ -217,14 +225,12 @@ local function editor(aceEnabled) -- feel free to disable the shiny Ajax.org Clo
end)
end
local t = tmr.create()
t:alarm(500, tmr.ALARM_AUTO, function()
if (wifi.sta.status() == wifi.STA_GOTIP) then
t:unregister()
t=nil
print("\n--- Web server started ---")
print("NodeMCU Web IDE running at http://"..wifi.sta.getip()..":"..mPort.."/")
editor()
end
end)
local ztmr_web_ide2 = tmr.create()
ztmr_web_ide2:alarm(500, tmr.ALARM_AUTO, function()
if (wifi.sta.status() == wifi.STA_GOTIP) then
ztmr_web_ide2:unregister() ztmr_web_ide2=nil
print("\n--- Web server started ---")
print("NodeMCU Web IDE running at http://"..wifi.sta.getip()..":"..mPort.."/")
editor()
end
end)

View File

@@ -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é")

View File

@@ -0,0 +1,11 @@
-- Petit script pour configurer le client WIFI du NodeMCU
function wifi_cli_conf()
print("\n wifi_cli_conf.lua zf190726.1912 \n")
-- les secrets sont maintenant initialisés par boot.lua !
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true}
end
wifi_cli_conf()
wifi_cli_conf=nil

View File

@@ -0,0 +1,20 @@
-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM
function wifi_cli_start()
print("\n wifi_cli_start.lua zf190310.1519 \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
end
wifi_cli_start()
wifi_cli_start=nil

View File

@@ -0,0 +1,33 @@
-- Petit script pour afficher les infos actuel du WIFI
print("\n wifi_info.lua zf190727.1220 \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())
local sta_config=wifi.sta.getconfig(true)
print("Current client config:")
print("\tssid:", sta_config.ssid)
print("\tpassword:", sta_config.pwd)
print("\tbssid:", sta_config.bssid)
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())
local sta_config=wifi.sta.getconfig(true)
print("Current client config:")
print("\tssid:", sta_config.ssid)
print("\tpassword:", sta_config.pwd)
print("\tbssid:", sta_config.bssid)
print("AP MAC: ", wifi.ap.getmac())
print("AP IP: ", wifi.ap.getip())
end