Need help for SRAM

Hi guys. I am currently trying to figure out how to use SRAM so I can actually use sleep mode.
So I wrote a small program to test it.
Here is my code:
https://go.particle.io/shared_apps/5ab97cc14e4c27dc5000067c

I expect 0 and 5, but I get all the 0s.

Can someone explain to me where do I get it wrong?

There’s nothing wrong with the way you’re using the retained int. The problem is your test code. When I try it, I only get 0 once, then it never publishes again. If I put in a delay of 5000 instead of 1000, then it works as expected. Also, your second publish statement will never run. When you put the device into deep sleep, it resets when it starts back up (that is, it runs setup() again, it doesn’t go to the next line after the sleep command).

3 Likes

Thanks for the help. Can you also take a look on this code as well? I think I should receive 3, but it never publishes.
https://go.particle.io/shared_apps/5abad382920c455c9900082c

I think the problem is that you have semicolons after your if statements, which should be removed. Do that, and see if that fixes the problem.

1 Like

Use proper indentation then you might better grasp the structure of your code too (including seeing the implication of the erronous semicolons).

1 Like