Difference between revisions of "ESPLib"

From base48
Jump to: navigation, search
(initial)
 
(fixup! initial)
 
Line 7: Line 7:
 
}}
 
}}
  
This repository started as a fork of luatool with collection of Lua snippets and wrappers collected from teh internetz,
+
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.
 
then evolved to a standaloned project. It now contains number of examples, wrappers to make your life easier and bunch of finished applications.
  
 
== Overview ==
 
== Overview ==
  
On ESP MCU start-up, NodeMCU loads '''init.lua''' which
+
On ESP MCU start-up, NodeMCU loads ''init.lua'' which
 
* sets-up a few shortcuts
 
* sets-up a few shortcuts
* reads and applies configuration from '''config.lua'''  
+
* reads and applies configuration from ''config.lua''  
* reads pin layout from '''pins.lua'''
+
* reads pin layout from ''pins.lua''
* and finally loads '''main.lua''' file after a small delay
+
* and finally loads ''main.lua'' file after a small delay
  
 
== Usage ==
 
== Usage ==
  
 
To load required library files and empty application use:
 
To load required library files and empty application use:
 
 
{{cmd|code=
 
{{cmd|code=
 
git clone https://github.com/hackerspace/esplib/
 
git clone https://github.com/hackerspace/esplib/
Line 28: Line 27:
 
}}
 
}}
  
Proceed with editing '''config.lua''', '''pins.lua''' and '''main.lua''' file.
+
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
+
To load one of the pre-made applications use ''make APPNAME'', for example to load
'''telnetsrv''' application use
+
''telnetsrv'' application use
 
{{cmd|code=
 
{{cmd|code=
 
make telnetsrv
 
make telnetsrv
 
}}
 
}}
  
This will load '''main_telnetsrv.lua''' to ESP as '''main.lua'''. When loaded restart ESP or use
+
This will load ''main_telnetsrv.lua'' to ESP as ''main.lua''. When loaded restart ESP or use
 
{{cmd|code=
 
{{cmd|code=
 
d('main')
 
d('main')
Line 51: Line 50:
 
}}
 
}}
  
Newly created library files has to be added to the '''FULL_FILE_LIST''' in the Makefile.
+
Newly created library files has to be added to the ''FULL_FILE_LIST'' in the ''Makefile''.
  
 
== Adding applications ==
 
== Adding applications ==
  
 
When your prototype is ready, you can fork your main.lua, pins.lua and any other required files
 
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'''
+
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.
+
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
+
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).
+
dependencies of your application. Also make sure you load ''main_APP.lua'' to the MCU as ''main.lua'' (''-t'' parameter).
  
  

Latest revision as of 13:05, 22 June 2017


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