Current Lua downloadable firmware will be posted here
User avatar
By Deniz Y
#74563 I have very little information about how to coding, all i want is a wifi-relay controlled power strip , i tried to make this code but i couldnt get it working. I have NodeMcu v3.

Code: Select allwifi.setmode(wifi.SOFTAP)
 cfg={}
 cfg.ssid="myssid"
 cfg.pwd="mypassword"
wifi.ap.config(cfg)
afg =
{
    ip="192.168.1.1",
    netmask="255.255.255.0",
    gateway="192.168.1.1"
}
wifi.ap.setip(afg)
GPIO14 = 5
GPIO12 = 6
GPIO13 = 7
GPIO15 = 8
gpio.mode(5, gpio.OUTPUT)
gpio.mode(6, gpio.OUTPUT)
gpio.mode(7, gpio.OUTPUT)
gpio.mode(8, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
local srv=net.createServer(net.TCP)
local function receiver(sck,numbers)
  local p={}
  for v,n in (numbers or ''):gmatch("([x-z])=(%d+)") do
    print (("%s=%s"):format(v,n))
    p[v]=n+0
  end
 
 
end
 
if svr then
  srv:listen(80,function(conn) conn:on("receive",receiver) end)
end
        html_buffer = html_buffer.."<head><meta name='viewport' content='width=200px, initial-scale=1.0'/>"
        html_buffer = html_buffer.."<style>body  { background-image: url('https://i.hizliresim.com/5dxJbL.png');background-repeat: no-repeat;background-position: 0px 150px;}</style>"
        html_buffer = html_buffer.."<font face='verdana'><h1> ESP8266 Wifi PowerSwitch by CBILAB</h1>";
        html_buffer = html_buffer.."<h2><p>Left Side<a href=\"?pin=ON1\">&nbsp;<button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
        html_buffer1 = html_buffer1.."<p>Right<br>(Mosquito) <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p></font></head>";
        html_buffer1 = html_buffer1.."<h2><p>Left Side<a href=\"?pin=ON3\">&nbsp;<button>ON</button></a>&nbsp;<a href=\"?pin=OFF3\"><button>OFF</button></a></p>";
        html_buffer1 = html_buffer1.."<p>Right<br>(Mosquito) <a href=\"?pin=ON4\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF4\"><button>OFF</button></a></p></font></head>";
       
        local _on,_off = "",""
        if(_GET.pin == "ON1")then
              gpio.write(GPIO14, gpio.HIGH);
        elseif(_GET.pin == "OFF1")then
              gpio.write(GPIO14, gpio.LOW);
        elseif(_GET.pin == "ON2")then
              gpio.write(GPIO12, gpio.HIGH);
        elseif(_GET.pin == "OFF2")then
              gpio.write(GPIO12, gpio.LOW);
        elseif(_GET.pin == "ON3")then
              gpio.write(GPIO13, gpio.HIGH);
        elseif(_GET.pin == "OFF3")then
              gpio.write(GPIO13, gpio.HIGH);
        elseif(_GET.pin == "ON4")then
              gpio.write(GPIO15, gpio.HIGH);
        elseif(_GET.pin == "OFF4")then
              gpio.write(GPIO15, gpio.HIGH);
        end
        print(collectgarbage("count")*1024)
        collectgarbage("collect")
        receive:close()
    end)
end)
]
In the link above .lua contents exist. My problem is that it gives "init.lua:32: out of memory" error in ESPlorer.

Also i am never sure which GPIO pin is which number in lua file, if someone has a proper pinout map with numbers would really :?: :?: appreciate.
User avatar
By marcelstoer
#74587
Deniz Y wrote:Also i am never sure which GPIO pin is which number in lua file, if someone has a proper pinout map with numbers would really appreciate.


https://nodemcu.readthedocs.io/en/lates ... ules/gpio/
User avatar
By TerryE
#74649 If you are using a current dev or master build from Marcel's cloud builder service then doing a =node,heap() should return around 43Kb. If not then you are using the wrong version or adding too many modules that you arren't using.