0

Lua 5.1.4 on SDK 3.0.1-dev(fce080e) Trying to use node.dsleepMax() and it is returning a really smaller number (147324921). Then I tried to manually set the sleep time in node.dsleep to the 32-bit max value (4294967295) and it only remained sleeping for around 30 min or so.

Tried the following:

    sleeptime = 4294967295
    > 
    =print(sleeptime)

2147483647

which is 2^31 -1.

Also did a loop adding to a variable, and it becomes negatve when it reaches 2^31.

Questions:

  1. Why is the variable wrapping at 2^31?
  2. Isn't node.dsleep supposed to accept a 64-bit value with SDK 2.1 and above?

Regards,

Cesar

cmaciel
  • 3
  • 1
  • It is very likely that you are using firmware int version (32bit) instead of of float (32bit with 23bit precision). This limitation is in lua and not in SDK. – Darius Aug 19 '20 at 23:30
  • Darius, I thought about it, but wanted to verify before building another firmware. I am using the integer firmware. So, it is a signed integer, therefore 31 bit plus sign info, is that correct? – cmaciel Aug 20 '20 at 01:12
  • Max positive signed int is exactly 2^31-1. In lua source code file `node.c` function `node_deepsleep` internally uses uint64 with `system_deep_sleep`. But if you use float firmware you loses precision in calculating sleep time i.e. float number 2^23 == 2^23+1 – Darius Aug 20 '20 at 08:18
  • Thank you, appreciate the explanation! – cmaciel Aug 20 '20 at 17:00

1 Answers1

0

You already got some feedback regarding int vs. float. As for dsleep the documentation doesn't explicitly state that it accepts 64bit values but that's indeed what's happening as per https://github.com/nodemcu/nodemcu-firmware/pull/2358 (since April 2018).

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
  • Thank you Marcel! I saw the info on the 64-bit from the link provided in the documentation that points to your article on Thingpulse. I just didn't thing that I would need the float firmware for that, since it is an integer number. I have just flashed a float firmware and it works fine :-) – cmaciel Aug 20 '20 at 17:19
  • Sorry about the missing hint. We at NodeMCU also accept PRs that improve the documentation ;-) – Marcel Stör Aug 21 '20 at 05:37