nodemcu-tool upload *.lua && nodemcu-tool terminal
This commit is contained in:
24
lua/init.lua
24
lua/init.lua
@ -8,5 +8,27 @@ end
|
||||
tryfile('display.lua')
|
||||
tryfile('wifi.lua')
|
||||
|
||||
function ls() print(sjson.encode(file.list())) end
|
||||
function reload() tryfile('init.lua') end
|
||||
function ls() for k,v in pairs(file.list()) do print(k.."\t\tsize: "..v) end end
|
||||
|
||||
function rpt_iter(f)
|
||||
return function ()
|
||||
return f()
|
||||
end
|
||||
end
|
||||
|
||||
function cat(f)
|
||||
if file.open(f) then
|
||||
local f = file.read()
|
||||
while f do
|
||||
print(f)
|
||||
f = file.read()
|
||||
end
|
||||
file.close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function help() print("heh") end
|
||||
|
||||
|
||||
37
lua/mqtt.lua
Normal file
37
lua/mqtt.lua
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
m = mqtt.Client(hostname, 120)
|
||||
|
||||
m:lwt("/lwt", "offline", 0, 0)
|
||||
|
||||
m:on("connect", function(client) print ("connected") end)
|
||||
m:on("offline", function(client) print ("offline") end)
|
||||
|
||||
|
||||
m:on("message", function(client, topic, data)
|
||||
print("MQTT: msg recieved: "..topic)
|
||||
if data ~= nil then
|
||||
print(data)
|
||||
end
|
||||
end)
|
||||
|
||||
-- for TLS: m:connect("192.168.11.118", secure-port, 1)
|
||||
m:connect("departmentofinter.net", 1883, 0, function(client)
|
||||
print("connected")
|
||||
-- Calling subscribe/publish only makes sense once the connection
|
||||
-- was successfully established. You can do that either here in the
|
||||
-- 'connect' callback or you need to otherwise make sure the
|
||||
-- connection was established (e.g. tracking connection status or in
|
||||
-- m:on("connect", function)).
|
||||
|
||||
-- subscribe topic with qos = 0
|
||||
client:subscribe("/topic", 0, function(client) print("subscribe success") end)
|
||||
-- publish a message with data = hello, QoS = 0, retain = 0
|
||||
client:publish("/topic", "hello", 0, 0, function(client) print("sent") end)
|
||||
end,
|
||||
function(client, reason)
|
||||
print("failed reason: " .. reason)
|
||||
end)
|
||||
|
||||
m:close();
|
||||
-- you can call m:connect again
|
||||
39
lua/wifi.lua
39
lua/wifi.lua
@ -1,14 +1,13 @@
|
||||
--local M, module = {}, ...
|
||||
--_G[module] = M
|
||||
|
||||
|
||||
hostname="doi-kontrol-m5core1"
|
||||
|
||||
--function M.init()
|
||||
function sta_init()
|
||||
--wifi.mode(wifi.STATION, true)
|
||||
sta_list = {
|
||||
{ssid="departmentofinter.net", pwd="baguette2175bagel", auto=true}
|
||||
}
|
||||
sta_list_idx = 1
|
||||
function sta_init(hostname)
|
||||
wifi.mode(wifi.STATION, true)
|
||||
wifi.sta.on("start", function(ev, a) print("NodeMCU WiFi Start") end)
|
||||
wifi.sta.on("start", function(ev, a) print("NodeMCU WiFi Stop") end)
|
||||
wifi.sta.on("stop", function(ev, a) print("NodeMCU WiFi Stop") end)
|
||||
wifi.sta.on("connected", function(ev, a) print("NodeMCU wifi connected! ssid:", a.ssid, "bssid:", a.bssid,
|
||||
"channel:", a.channel, "auth:", a.auth) end)
|
||||
wifi.sta.on("disconnected", function(ev, a) print("NodeMCU wifi disconnected! ssid:", a.ssid, "bssid:", a.bssid,
|
||||
@ -16,33 +15,23 @@ function sta_init()
|
||||
wifi.sta.on("authmode_changed", function(ev, a) print("NodeMCU authmode_changed! old_mode:", a.old_mode,
|
||||
"new_mode:", new_mode) end)
|
||||
wifi.sta.on("got_ip", function(ev, info)
|
||||
dofile('telnet.lua') -- TKTK TODO XXX security risk lol
|
||||
print("NodeMCU got_ip! ip:", info.ip, "netmask", info.netmask,
|
||||
"gw", info.gw) end)
|
||||
tryfile('telnet.lua') -- TKTK TODO XXX
|
||||
print("NodeMCU got_ip! ip:", info.ip, "netmask", info.netmask, "gw", info.gw)
|
||||
end)
|
||||
wifi.start()
|
||||
wifi.sta.sethostname("doi-kontrol-m5core1")
|
||||
wifi.sta.config({ssid="departmentofinter.net", pwd="baguette2175bagel", auto=true}, true)
|
||||
wifi.sta.sethostname(hostname)
|
||||
wifi.sta.config(sta_list[sta_list_idx], true)
|
||||
print("wifi_init done")
|
||||
end
|
||||
|
||||
sta_list = [
|
||||
{ssid="departmentofinter.net", pwd="baguette2175bagel", auto=true}
|
||||
]
|
||||
|
||||
function staionap_init()
|
||||
wifi.mode(wifi.STATIONAP, true)
|
||||
wifi.sta.config({ssid="departmentofinter.net", pwd="baguette2175bagel", auto=true})
|
||||
|
||||
wifi.ap.config({ssid="cyberkontrol", pwd="baguette2175bagel", auth=wifi.AUTH_WPA2_PSK,
|
||||
channel=11, hidden=false, max=4, becaon=100}, true)
|
||||
|
||||
wifi.ap.setip({ip=192.168.0.1, netmask=255.255.255.0, gateway=192.168.0.1, dns=1.1.1.1})
|
||||
wifi.ap.setip({ip="192.168.0.1", netmask="255.255.255.0", gateway="192.168.0.2", dns="1.1.1.1"})
|
||||
wifi.ap.sethostname(hostname)
|
||||
end
|
||||
|
||||
|
||||
init()
|
||||
|
||||
return init
|
||||
|
||||
|
||||
sta_init("doi-kontrol-m5core1")
|
||||
|
||||
Reference in New Issue
Block a user