LUA scripts for MQTT clients are uploaded to esp8266 with luatool.py

python ./path/to/script/luatool.py -p /dev/ttyS0 -f /path/to/LUA-script/init.lua -t init.lua

Below are lua scripts for MQTT clients.

init.lua is base background operation – connects to WiFi network.

Remember to change NETMASK and IP for AP and clients (aaa.bbb.ccc.ddd) according to your network settings!

 init.lua – almost the same for all chips 
wifi.setmode(wifi.STATION)
wifi.sta.config("yourwifi","yourpasswd")

cfg =
{
    ip="aaa.bbb.ccc.ddd",
    netmask="eee.fff.ggg.hhh",
    gateway="aaa.bbb.ccc.xxx"
}
wifi.sta.setip(cfg)

cfg=nil

wifi.sta.connect()
wifi.sta.autoconnect(0)

tmr.alarm(0,5000,1, function()
    if wifi.sta.getip()~=nil then
        print('\r\n  IP:',wifi.sta.getip())
        print('BRDC:',wifi.sta.getbroadcast())
        print(' MAC:',wifi.sta.getmac())
            if wifi.sta.status()==5 then
                print('MODE:','Station')
            else
                print('MODE:','connect to AP')
            end
        print('CHIP:',node.chipid())
        print('HEAP:',node.heap())
        print('FLSH:',node.flashid())
        tmr.stop(0)
        cfg=nil
        dofile("mqtt.lua")
    end
end