- totalement remanié la structure de mon dépôt, cela commençait à être trop le foutoire ;-(
This commit is contained in:
20
Net_utils/make_ping.lua
Normal file
20
Net_utils/make_ping.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
-- programme pour faire des ping en permanence
|
||||
|
||||
print("\n make_ping.lua zf181113.1947 \n")
|
||||
|
||||
zLED=0
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
ztmr_LED = tmr.create()
|
||||
value = true
|
||||
|
||||
dofile("ping.lua")
|
||||
|
||||
tmr.alarm(ztmr_LED, 500, tmr.ALARM_AUTO, function ()
|
||||
if value then
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
else
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
Ping("192.168.0.102")
|
||||
end
|
||||
value = not value
|
||||
end)
|
||||
29
Net_utils/ping.lua
Normal file
29
Net_utils/ping.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
-- Permet de tester si une adresse IP est active
|
||||
-- ATTENTION, ne fonctionne seulement s'il y a du réseau !
|
||||
|
||||
print("\n ping.lua zf181113.1937 \n")
|
||||
|
||||
function Ping(mIP)
|
||||
t1=tmr.now()
|
||||
conn=net.createConnection(net.TCP, 0)
|
||||
conn:connect(1,mIP)
|
||||
conn:on("disconnection", function(sck, c)
|
||||
-- on disconnection
|
||||
t2 = tmr.now()
|
||||
t3=(t2-t1)/1000/1000
|
||||
print(t3)
|
||||
if ((t3)<5) then
|
||||
--IPCount=IPCount+1
|
||||
print(mIP.." is active.")
|
||||
else
|
||||
print(mIP.." is not active.")
|
||||
end
|
||||
t1, t2, t3 = nil
|
||||
end)
|
||||
sck, c, conn = nil
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
Ping("192.168.0.102")
|
||||
|
||||
|
||||
11
Net_utils/show_ip.lua
Normal file
11
Net_utils/show_ip.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
--Affiche l'adresse IP
|
||||
--zf20180712.1110
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user