Post your best Lua script examples here

User avatar
By lucashayes
#7739
gwizz wrote:Awesome work, thanks for sharing!! Even to my inexperienced eyes your code looks very clean, smells good too! :)

I'm sure Peter Scargill will be interested in this as well, he is very concerned with timekeeping with his projects.

If you can share any other details of your project I'd like to read about it?

Keep on hacking :D


Thanks for your kind words! I'm a developer by trade so clean code is something I pride myself on :).

It's really something just to get my feet wet with the ESP8266.
My fiancee and I are planning to get a hedgehog as a pet. They need to be kept above 72°F and need 12 hours of dedicated light a day.

So my project controls 2 relays, one to power an infrared heat emitter, and the other a standard light bulb. The heater is controlled by the temp read from a DS18b20, and the light is controlled by the time from a DS3231. A web interface will allow me to see and change the temp and adjust the hours the light is active (as well as forcefully turn the heater or light on).

The hardware is done and 90% of the code is done (web interface part is really all that's left). The biggest issue I'm facing at the moment is running out of heap. If I try to add too much into the web interface code I end up randomly running out of heap when I try to load the web page and the module reboots. I've stripped the unneeded LUA modules and I'm trying to slim down the code as much as possible.

When I get it all working and finished up I'll do a full write up of both the hardware and code :)
User avatar
By gwizz
#7741
lucashayes wrote:Thanks for your kind words! I'm a developer by trade so clean code is something I pride myself on :).
Well I'm not surprised to hear that, but still, plenty of folks out there writing bad code and getting paid for it. :)

lucashayes wrote:The biggest issue I'm facing at the moment is running out of heap. If I try to add too much into the web interface code I end up randomly running out of heap when I try to load the web page and the module reboots. I've stripped the unneeded LUA modules and I'm trying to slim down the code as much as possible.

Ah, well now, is this post http://www.esp8266.com/viewtopic.php?f=24&t=1135&p=7519&hilit=heap#p7519 (or the subsequent replies) useful? And, perhaps I can ask, as a professional, can you explain to someone that isn't, why and how to use such an approach, spelling it out maybe with a few lines of example code?

lucashayes wrote:When I get it all working and finished up I'll do a full write up of both the hardware and code :)

Wow, sounds like a great project, open source to boot! I'm sure it will be also interesting to people because hedgehogs can be amazingly cute :D

Image
User avatar
By alonewolfx2
#9417 i am trying to use this module with ds1307 but it seems something different. firstly ds1307 is 5v device so i am using level converter. i have this return value. but right answer is 23:48:40 10/2/15. have you any idea?
> dofile("ds3231-example.lua")
init done
Time & Date: 24.875:48.125:43.25 10/3.25/18.125
User avatar
By lucashayes
#9514 Looks like this needs to be updated to work with floats enabled. I haven't upgraded the project using this code to the new float enabled nodeMCU so I didn't know it was broken.

Will update and create pull request when I have the time. However I just got a 3D printer so that might be a while :lol:

alonewolfx2 wrote:i am trying to use this module with ds1307 but it seems something different. firstly ds1307 is 5v device so i am using level converter. i have this return value. but right answer is 23:48:40 10/2/15. have you any idea?
> dofile("ds3231-example.lua")
init done
Time & Date: 24.875:48.125:43.25 10/3.25/18.125