ESPLib
This project started as a fork of luatool with collection of Lua snippets and wrappers collected from teh internetz, then evolved to a standaloned project. It now contains number of examples, wrappers to make your life easier and bunch of finished applications.
Overview
On ESP MCU start-up, NodeMCU loads init.lua which
- sets-up a few shortcuts
- reads and applies configuration from config.lua
- reads pin layout from pins.lua
- and finally loads main.lua file after a small delay
Usage
To load required library files and empty application use:
git clone https://github.com/hackerspace/esplib/
cd luatool
make all
Proceed with editing config.lua, pins.lua and main.lua file.
To load one of the pre-made applications use make APPNAME, for example to load telnetsrv application use
make telnetsrv
This will load main_telnetsrv.lua to ESP as main.lua. When loaded restart ESP or use
d('main')
# shortcut for dofile('main.lua')
to load this file while running.
Loading one file
For example, after altering main, you can flash only this file by running
make main.luac
Newly created library files has to be added to the FULL_FILE_LIST in the Makefile.
Adding applications
When your prototype is ready, you can fork your main.lua, pins.lua and any other required files by copying these files and adding a suffix with your application name. For example to create troll app you need to create (or copy) main.lua to main_troll.lua and create appropriate section in the Makefile. Look at the bottom of the Makefile for examples of already defined applications. Don't forget to list all the dependencies of your application. Also make sure you load main_APP.lua to the MCU as main.lua (-t parameter).
Shortcuts
Provided shortcuts:
out(PIN) # gpio.mode(pin, gpio.OUTPUT)
lo(PIN) # gpio.write(pin, gpio.LOW)
hi(PIN) # gpio.write(pin, gpio.HIGH)
d('...') # dofile('...')
ip() # show IP when connected to an access point
apip() # show access point IP
res() # node.restart(), restart MCU
a() or abort() # abort loading main.lua, when main.lua is borken and causes reboot loop
whoami() # show hostname
ping() # reply with pong
ls() # list files
safecall(CODE) # try loading CODE in safe manner and report errors if any
rpc(CODE) # safecall followed by '!ok_rpc' reply