I tried pinMode(WATER_SENSOR, INPUT_PULLUP) but it did not help. I am not sure what is causing this not to work. When I reset the device it works fine for the first time but after that it goes back again to water_alarm which is not true.
@ScruffR – Hi Scruff ! I even bought a new water sensor which supports 3.3 V but I got the same result. I also want to try the retained variable but I do not like the idea of saving the values here.
WiFi.selectAntenna() is a "sticky" setting. You'd only set it once and it'll stay set even when you remove the instruction.
In order to set a specific antenna, you'd need to select that one explicitly at least once.
About your other issue, could you try calling pins_init() again after the sleep call?
@ScruffR, Thanks ! It is working now. I am also working on electron for GPS module and I would like to apply the same sleep function over there. Though electron has its own battery gauge , these fundamentals will over there too.
(you could forget the #if ... #endif since that extra parameter will be ignored on WiFi devices, but just to show-off )
This avoids the need to always introduce yourself to the cell tower after wake-up which might use a few KB per wake.
@ScruffR, Thanks for advice. I have another question here:
Is there any way that we can find out whether the photon wakes up through button clicked or through time interval is up for sleep.
System.sleep(Button, FALLING, 30);
When i click the button (D2=HIGH, I am using D2 pin for wakeup) , it wakes up the photon but after that D2=LOW. Is there any way to capture or maintain D2=HIGH.
This question has been asked before, and the usual answers are, you either need to build a sample and hold circuit to keep the button state long enough to read it via your code, or you store away the current time before you go to sleep and then check the time after wake. If you are far enough away from your timeout you know it was a button press, if not it could be either reason.
Hah, I’m just catching up on this. In the initial question about going super deep sleep on the Button: yes, the WKP is already committed… to the interrupt pin for the accelerometer! So you can turn the micro off completely and let the crazy low power ADXL362 wake it up when it’s bumped or tapped above a threshold. I’m pretty sure it’ll actually pick up the button click but via acceleration rather than direct 'lectrons.
@ScruffR: Hi ! Thanks for helping me on this ! I have another Question regarding this topic.
I wanted to have 3 buttons in deep sleep mode for my device.
1st Button: Wake up the device which can be pressed on demand by users.
2nd Button: Device Set which can be pressed for 1st time by OR when the user will move the device to other wifi location.
I would actually use interrupts for 2 & 3.
This way your application code does not need to take any care for reading the buttons often enough in order to not miss a button press.
But both actions will not be able to wake the device or do their jobs while the device is asleep.