top of page

Lua with METAS

What is Lua?

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode with a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

Lua is free

Lua is free open-source software, distributed under a very liberal license (the well-known MIT license). It may be used for any purpose, including commercial purposes, at absolutely no cost. Just download it and use it.

METAS and Lua

You can impot Lua via lualoader to METAS NodeOne.
Make sure is connect with USB port.

Lua Tutorial:

1. Connect to the wireless network
print(wifi.sta.getip())
–nil
wifi.setmode(wifi.STATION)
wifi.sta.config(“SSID”,”password”)
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip() == nil then
print(“Connecting…”)
else
tmr.stop(1)
print(“Connected, IP is “..wifi.sta.getip())
end
end)

2. HTTP Server
— a simple http server
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on(“receive”, function(sck, payload)
print(payload)
sck:send(“HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>”)
end)
conn:on(“sent”, function(sck) sck:close() end)
end)

3. DISPLAY
function prepare()
disp = u8g.ssd1306_128x64_i2c(0x3c)
disp:setFont(u8g.font_chikita)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
disp:setScale2x2()
end

function init_display()
disp:firstPage()
repeat
disp:drawStr(9,0,”METAS IOT”)
disp:drawStr(8,20,”Please Wait”)
until disp:nextPage() == false
end

i2c.setup(0,7,6,i2c.SLOW)
prepare()
init_display()

4. Control
–Control D1–
gpio.mode(1,gpio.OUTPUT)
gpio.write(1,gpio.HIGH)

–Control D2 —
gpio.mode(1,gpio.OUTPUT)
gpio.write(1,gpio.LOW)

–Read A0–
gpio.mode(8,gpio.OUTPUT)
gpio.write(8,gpio.HIGH)
A0 = adc.read(0)

–Read A1–
gpio.mode(8,gpio.OUTPUT)
gpio.write(8,gpio.LOW)
A1 = adc.read(0)

How to write and copy your own program?

Currently the firmware and tutorial of METAS company are mainly achieved by virtual machine with NodeMCU LUA language. For more details about NodeMCU virtual machine, please visit www.nodemcu.com/index_cn.html. In the next software update, METAS company will provide more examples of Mirco Pyton virtual machine.

Office Hour

 

 

Mon - Fri 9:00am-06:00pm

Tel: (852) 3707 4719

 

 

  • YouTube - Black Circle
  • Facebook - Black Circle
  • Instagram - Black Circle

Address

 

Suite 19, 5/F, Hung To Centre,

94-96 How Ming Street,

Kwun Tong, Hong Kong

bottom of page