Running Lua on your FlashAir!

Latest update: March 2015

In this tutorial, we will go over how to execute a basic script.

There are three ways to run your Lua scripts on your FlashAir: on boot, on a write event, or with an HTTP request. Lets put together a quick “Hello World” program to demonstrate.

print("Hello World!")
local file = io.open("Hello.txt", "a")
file:write("Hello There!\n")
file:close()

All this script does is print “Hello World!”, and appends “Hello There!” to a Hello.txt file.

Execute on Boot

To execute it on boot, edit SD_WLAN/CONFIG and add the following line.

LUA_RUN_SCRIPT=/HelloWorld.lua

Unmount the Sdcard, the remove and re-insert it. Your script should run immediately!

Execute on Write

To execute it every time a file is written, use LUA_SD_EVENT instead.

LUA_SD_EVENT=/HelloWorld.lua

Using LUA_RUN_SCRIPT and LUA_SD_EVENT together

LUA_RUN_SCRIPT and LUA_SD_EVENT can be used together. LUA_SD_EVENT is ignored until the operation of LUA_RUN_SCRIPT is completed. LUA_SD_EVENT becomes executable after the execution of LUA_RUN_SCRIPT is finished.

Execute with HTTP Request

You can also execute your script with an HTTP request, for example opening http://flashair/HelloWorld.lua will display Hello World!.

All sample code on this page is licensed under BSD 2-Clause License