Post your best Lua script examples here

User avatar
By blavery
#47161 An 8266 datalogger platform with webserver, true time, event logging, virtual memory, oled, telnet.

https://github.com/BLavery/ESP8266_LG3

LG3 is a small suite of lua files that forms an IoT logger platform, operating via local Access Point. (It's “LG3” simply because there were two earlier versions.) It works easily on the devkit 1.0 boards and the variant clones based on ESP-12, but there is little reason that ESP-01 should not support many of the features. On this standard datalogger platform, you then add your specific “project”.

Environment:
    esp-12 based board (although esp-01 should be usable)
    NodeMCU lua. Lua 5.1.4 was used for testing, on SDK 1.5.1
    ESPlorer, at least for setting up & testing

Lua binary:
Your lua bin build should support at least these modules: Adc, file, gpio, I2C, net, node, pwm, RTC-time, SNTP, timer, U8g with font_6x10, wifi. At this time (Apr 2016) the dev build supports deregistering wifi events more flexibly than master build, and so is recommended. (It runs 115200 baud native, too.)


“LG3” suite includes these features:
- 2 second startup delay, for “panic/crash” escape.
- Login to first available of up to 5 preset AP stations.
- Auto wifi reconnection if wifi fails.
- Read true time from any selected SMTP timeserver, and preserving that at RTC.
- Auto sensing of a connected OLED 0.96” I2C (4 pin) display.
- A small suitable library of oled layout styles.
- A primitive virtual memory system for “freezing” selected functions to flash file, and recalling at required runtime moments.
- A “datalogger” function to log events to flash file.
- Timestamp stored with every event.
- A self-contained webserver process for simple button-based web page.
- Multi-packet TCP sending.
- Framework for handling responses (eg GPIO write) to each button.
- Options to have web page auto-refresh.
- Easy support for event logger display and erase buttons at web page.
- Support for optional simple “telnet” function where browser can have a text input field, to be sent to the lua interpreter.
- On completion of all LG3 logger platform setup, transfer to whatever custom “project” lua file is to be run.

Possibly your “project” code requirements are now quite minimal, as the LG3 platform has supplied a comprehensive base of functions.
In addition, LG3 is designed to leave plenty of heap space remaining for your project code.


Several sample “project” files are supplied, to run on LG3 platform:
1. The “ubiquitous” 2 gpio out simple control from web page
2. WebIO-esp – control over each gpio, ala the defunct WebIO-pi
3. Scheduled hourly (or whatever) logging of all GPIO data
4. Simple demo of all supplied oled display styles
5. HC04 sonar logging/control – not yet
6. PIR logging – not yet
7. TNET – a minimal “telnet” access
8. Battery voltage (or LDR) level monitor – not yet
9. Capture/logging of multiple button/switch events – not yet

Brian