TheThingsNetwork / arduino-device-lib

Arduino Library for TTN Devices
MIT License
207 stars 96 forks source link

sleep function - overflow #220

Closed savnik closed 6 years ago

savnik commented 6 years ago

I'm working on an ATmega1284p with the RN2483A. When putting the device to sleep using the library the module does not go to sleep. I'm using ttn.sleep(4294967295); where 4294967295 is the maximum value defined in the documentation. The result "sys sleep -1" is send to the RN2483, which results in nothing. If I use 2147483647 or less it works and sends "sys sleep 2147483647" and i can see the power usage go down. I guess somewhere there is a overflow in the library but I have not been able to spot where.

johanstokking commented 6 years ago

So basically https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/src/TheThingsNetwork.cpp#L957 results in -1 when specifying 0xFFFFFFFF ?

Maybe this check is wrong then? https://github.com/TheThingsNetwork/arduino-device-lib/blob/master/src/TheThingsNetwork.cpp#L948. I wonder why it should check whether it's larger than the max value anyway...

Can you file a PR?

alexbn71 commented 6 years ago

an uint32_t has a maximum value of 4,294,967,295 so the "if" has no very sense. It should be only:

if (mseconds < 100)

but the issue that prints "-1" is the printf... you must use "%lu" inestead of "%ld" to print an uint32_t correctly

johanstokking commented 6 years ago

Released in https://github.com/TheThingsNetwork/arduino-device-lib/releases/tag/v2.5.4