Post your best Lua script examples here

User avatar
By JohnPap70
#4305 Hi all!

I was trying to make some sensor drivers in Lua in order to connect them with the ESP8266. It seems that the floating point values are not supported by the Lua running on the ESP. Is this correct?

Are we going to have this feature soon or it is totally unsupported by the hardware?
User avatar
By JohnPap70
#4787 Thank you for your answer! I am new to Lua and I was trying to write a few sensor drivers.

How I will define that a variable of mine is a float in the Lua running on the ESP chip?
User avatar
By sancho
#4931
JohnPap70 wrote:Thank you for your answer! I am new to Lua and I was trying to write a few sensor drivers.

How I will define that a variable of mine is a float in the Lua running on the ESP chip?

I would suggest to take a look into the example for DS1820 - you can see the temperature calculation, which should be done by multiplication of resulting integer by 0.0625 to get degrees Celsius.
However, instead of this, the number is multiplied by 625, resulting in 4 decimal places.
Than, you can display the number as
Code: Select allprint(resultValue/10000 .. "." .. string.format("%04d", resultValue%10000))

Does it help?