Post your best Lua script examples here

User avatar
By sfinx
#9050
tuanpm wrote:
sfinx wrote:Any news on this publish queue? Or has anyone made a working queue implementation in lua?

Please try this: https://github.com/tuanpmt/lua-async ,
I've written this lib to make async process easier, now only waterfall function, you can publish another msg by callback after send msg.
Queue need a lot of RAM, not comfortable for LUA module

Thanks, I will have a look at that! I'm not sure however if this would solve the problem where 1 publish is triggered by a timer and another one by an interrupt..
User avatar
By iHaveESP
#9219 @BySuxsem

I wanted a simple mqtt solution so I tried lua. I have since switched to C, with this toolchain https://github.com/pfalcon/esp-open-sdk

...and with https://github.com/tuanpmt/esp_mqtt where a proper queue is in place. It works great. I haven't seen any of the problems with lua mqtt (sending in...)

It's cool to turn wifi OFF, watch the queue build,(I imagine it's FIFO), turn wifi back on and watch the publishes blow the queue. The buffer is 2048 by default.

...it's worth setting up the SDK , if you use Windows http://www.esp8266.com/viewtopic.php?f=9&t=820 (never tried).

With this setup you can compile your own lua and not wait for pre-builds, like I used to. Additionally, there so much more C builds you can try. It's worth it!

Cheers!
User avatar
By Lawrence_jeff
#9222 Thanks all for the great info. I have been struggling to figure out how to integrate an ESP8266 with an OpenHAB instance. After pulling my hair out with the OpenHAB docs, I finally have an example working with the demo OpenHAB instance (using the 1/24/15 nodeMCU image.)

The 3 main steps are:
1) Build a lua file that publishes to mqtt upon state change (initiated from the device), as well as receives state change commands from mqtt (sent by OpenHAB user interaction on the website)
2) You need to configure a mqtt service bus in OpenHAB
3) You need to tweak the switch configuration so it doesn't autoupdate but waits until it gets a response from the ESP

With a standard mosquitto install and the OpenHAB demo instance running you can have a device talking in only a few minutes.
I have example lua file and OpenHAB modifications documented here
http://lawrencejeff.blogspot.com/
User avatar
By quantalume
#9267
Lawrence_jeff wrote:With a standard mosquitto install and the OpenHAB demo instance running you can have a device talking in only a few minutes.
I have example lua file and OpenHAB modifications documented here
http://lawrencejeff.blogspot.com/


Thanks for posting your code and writeup. I somehow hadn't heard of OpenHAB before. Looks like it would be a better way to integrate everything together than the collection of Python scripts I'm using currently.