IOT Projects

  • LUA webserver

    LUA a new programming language, easy and simple so similar to Python but with little difference.
    today we learn how to programming the chip with ESPlorer IDE,but first we need to install java it's important for the IDE.
    Installing Java
    after installing Java we install ESPlorer which is IDE can communicate with the esp8266 by LUA programming language or python or the AT command.
    Download ESPlorer
    we extract the files "you don't need to install it",open ESPlorer.jar icon to start the program and it looks like this.

    Post
    Set the baud rate to 9600 and choose the right com port then click open, like in the picture below.

    Post
    for me I use the esp8266 mini or Wemos to connect it directly to the USB port which I recommend it.
    hit the button send to ESP to test the code,by this choice, the esp8266 only execute the command we send but if you make a restart the program will be gone.
    If you want to save the program in the esp8266 memory you must press "upload", after that make a file name init.lua and write inside of it.
    dofile("name of your program.lua")
    Then also upload this file after that the module will execute your program automatically.
    LUA code
    wifi.setmode(wifi.STATION)// wifi mode 
    wifi.sta.config("your router","your password")// connect to router
    print("connecting...")
    wifi.sta.connect()
    ip = wifi.sta.getip()// get the device ip 
    print("IP: ",ip)// print it 
    
    srv = net.createServer(net.TCP)// create a web page
    srv:listen(80, function(conn)
      conn:on("receive",function(conn,payload)
        print(payload)
        conn:send("HTTP/1.1 200/OK\r\nServer: NodeMCU\r\nContent-Type: text/html\r\n\r\n")    
        conn:send("<html><head><title>NodeMCU</title></head><body><p>Hello, NodeMcu.<p></body></html>")    
      end)
      conn:on("sent",function(conn) conn:close() end)
    end)