-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Rene K. Mueller edited this page Jan 4, 2018
·
4 revisions
The main idea is to have a shell which operates like in UNIX with NodeMCU (ESP8266).
The filesystem layout looks like this, each application or app has its own directory, with main.lua
as entry point:
-
shell/main.lua
- main shell, opens tcp at port 2323 and one can telnet to it and has a shell
-
shell/ls.lua
- the
ls
command, will be executed by shell/main.lua when the user typesls
- the
-
mycmd/main.lua
- extra command e.g.
mycmd
, themain.lua
is called when users requestsmycmd
- extra command e.g.
command skeleton (shell or user command):
return function(arg)
-- arg[1] contains command (e.g. 'ls')
-- arg[2] first argument
-- etc.
end
example:
% telnet 192.168.2.199 2323
Trying 192.168.2.119...
Connected to 192.168.2.119.
Escape character is '^]'.
== Welcome to NodeMCU Shell 0.0.2
% help
available commands:
blink
cat
compile_all
cp
date
df
echo
help
hostname
ls
mv
rm
sysinfo
telnet
time
touch
uptime
% uptime
0d 00h 20m 59s
% cat startup.lua
dofile("wifi/main.lua")
% cat wifi/main.lua
conf = dofile("wifi/wifi.conf")
if(conf.mode=='client') then
wifi.setmode(wifi.STATION)
--wifi.setphymode(conf.signal_mode)
wifi.sta.config({ssid=conf.client.ssid, pwd = conf.client.password})
wifi.sta.connect()
wifi.sta.sethostname("ESP-"..node.chipid())
if conf.ip then
wifi.sta.setip({ip=conf.ip,netmask=conf.netmask,gateway=conf.gateway})
end
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP,function(args)
print("wifi: ",conf.client.ssid,wifi.sta.getip())
dofile("net.up.lua")
wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED,function(args)
print("wifi: lost connectivity, reconnecting ...")
dofile("net.down.lua")
end)
end)
else
wifi.setmode(wifi.SOFTAP)
wifi.ap.config(conf.ap.config)
wifi.ap.setip(conf.ap.net)
print("wifi: "..conf.ap.config.ssid.." access point ("..wifi.sta.getmac()..")")
dofile("net.up.lua")
end