first commit

This commit is contained in:
Christian Zufferey
2018-07-22 12:43:16 +02:00
parent 0fa4e7727e
commit 3149e7ecc8
54 changed files with 3043 additions and 0 deletions
View File
+12
View File
@@ -0,0 +1,12 @@
-- get_ip.lua
-- affiche l'adresse IP
-- zf180715.2347
tmr.alarm(0, 1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
print("Connected! IP: ",wifi.sta.getip())
tmr.stop(0)
end
end)
+94
View File
@@ -0,0 +1,94 @@
-- init.lua
-- test si clic sur le bouton
-- clic <2s goto start.lua
-- clic >2s goto config wifi
print("\ninit.lua zf180717.1125 \n")
zBTN = 3 -- GPIO0 button
--zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLED = 0 -- SonOff: 7 GPIO13 PWM1, NodeMCU: 0, (active low)
zFlag_LED = 0
function blink_LED ()
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)
end
gpio.write(zLED, zFlag_LED)
end
gpio.mode(zLED, gpio.OUTPUT)
ztmr_LED = tmr.create()
--pwm.setup(zLED, 1, 500)
--pwm.start(zLED)
zTm_On_LED = 500 --> en ms
zTm_Off_LED = 500 --> en ms
blink_LED ()
function btn_test()
print("test")
t2=tmr.now()
t3=(t2-t1)/1000000
print("t3: "..t3)
if gpio.read(zBTN)==1 then
tmr.stop(0)
gpio.trig(zBTN)
--pwm.stop(zLED)
tmr.stop(ztmr_LED)
gpio.write(zLED,1)
print("start.lua")
dofile("start.lua")
end
if t3>2 then
tmr.stop(0)
gpio.trig(zBTN)
--pwm.setup(zLED, 10, 500)
--pwm.start(zLED)
zTm_On_LED = 100 --> en ms
zTm_Off_LED = 100 --> en ms
blink_LED ()
wifi.sta.disconnect()
wifi.sta.clearconfig()
print("\nwifi config http://192.168.4.1\n")
tmr.alarm(0, 1000, tmr.ALARM_AUTO , get_ip)
enduser_setup.start()
end
end
function btn_clic()
print("clic")
t1=tmr.now()
--pwm.stop(zLED)
tmr.stop(ztmr_LED)
gpio.write(zLED,0)
tmr.alarm(0,100,tmr.ALARM_AUTO, btn_test)
end
function get_ip()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
tmr.stop(0)
print("Connected! IP: ",wifi.sta.getip())
tmr.alarm(0,3000,tmr.ALARM_SINGLE, function() node.restart() end)
end
end
function dir()
l=file.list()
for k,v in pairs(l) do
print(k.." "..v)
end
print('\nusage: dofile("file.lua")\n')
end
gpio.mode(zBTN,gpio.INT)
gpio.trig(zBTN, "down", btn_clic)
wifi.sta.connect()
dofile("telnet_srv.lua")
+34
View File
@@ -0,0 +1,34 @@
zBTN = 3 -- GPIO0 button
zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLED = 7 -- GPIO13 PWM1 GREEN LED (active low)
--pwm.setup(zLED, 1, 500)
--pwm.start(zLED)
gpio.mode(zBTN,gpio.INT)
pwm.stop(zLED)
gpio.write(zLED,1)
gpio.trig(zBTN, "both",function()
if gpio.read(zBTN)==0 then
pwm.stop(zLED)
gpio.write(zLED,0)
t1=tmr.now()
else
gpio.write(zLED,1)
t2=tmr.now()
t3=(t2-t1)/1000000
print(t3)
if t3<2 then
gpio.write(zLED,1)
print("start")
pwm.setup(zLED, 1, 500)
pwm.start(zLED)
else
print("config")
pwm.setup(zLED, 10, 500)
pwm.start(zLED)
end
end
end)
+11
View File
@@ -0,0 +1,11 @@
-- start.lua
-- programme de start
-- zf180715.2359
zBTN = 3 -- GPIO0 button
zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLED = 7 -- GPIO13 PWM1 GREEN LED (active low)
gpio.mode(zLED,gpio.OUTPUT)
pwm.setup(zLED, 2, 900)
pwm.start(zLED)
+13
View File
@@ -0,0 +1,13 @@
-- stop.lua
-- programme de stop
-- zf180716.0010
zBTN = 3 -- GPIO0 button
zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLED = 7 -- GPIO13 PWM1 GREEN LED (active low)
gpio.mode(zLED,gpio.OUTPUT)
pwm.stop(zLED)
gpio.write(zLED,1)
+42
View File
@@ -0,0 +1,42 @@
-- a simple telnet server
-- restart server if needed
if telnet_srv ~= nil then
telnet_srv:close()
end
telnet_srv = net.createServer(net.TCP, 180)
telnet_srv:listen(23, function(socket)
local fifo = {}
local fifo_drained = true
local function sender(c)
if #fifo > 0 then
c:send(table.remove(fifo, 1))
else
fifo_drained = true
end
end
local function s_output(str)
table.insert(fifo, str)
if socket ~= nil and fifo_drained then
fifo_drained = false
sender(socket)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.
socket:on("receive", function(c, l)
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
end)
socket:on("disconnection", function(c)
node.output(nil) -- un-regist the redirect output function, output goes to serial
end)
socket:on("sent", sender)
print("Welcome to NodeMCU world.")
end)
print("Telnet server running...")