Try this... Be sure to connect WAKE to RST on the Oak. Also pin 5 is set pinMode(5, INPUT_PULLUP) as way to control whether you want it to sleep or not.
Hopefully the code comments are sufficient to explain. This is the essence of the code I created for sketches that deep sleep.
/*
Digistump Oak deep sleep example
Requires:
* Particle.io account
* Digistump Oak with current firmware and active on particle.io
Does:
* Support sleep and non-sleep modes
* Publishes events and data to particle.io
* Enters deep sleep when Sleep_pin = HIGH (set INPUT_PULLUP)
* Watches Sleep_pin to determine whether or not to go into deep sleep.
HIGH = sleep, At wakeup resets and runs setup() again and does not enter loop()
LOW = enters Loop() and non sleep mode
NOTE: Non sleep mode will allow for new sketch uploads
*/
/*
* WARNING: Pin 10 (WAKE) must be connected to the reset pin (RST) for wakeup to occur
*/
int Sleep_pin = 5; // (Configure as INPUT_PULLUP to default HIGH)
int OakLEDpin = 1; // Oak onboard LED pin 1
int sleepTimeS = 30; // 30 seconds - adjust a needed
void setup(void) {
pinMode(Sleep_pin, INPUT_PULLUP); // Use pullup mode to default HIGH
pinMode(OakLEDpin, OUTPUT);
digitalWrite(OakLEDpin,HIGH); // Turn on onboard LED
Particle.publish("Oak Setup", "Started", 60, PRIVATE);
// Put your code here to do work like read a value or set a pin
Particle.publish("Oak Setup", "Working", 60, PRIVATE);
Particle.publish("Oak Setup", "Complete", 60, PRIVATE);
delay(2000); // Long pluse stretch onboard LED for visual effect
digitalWrite(OakLEDpin,LOW);
// Check to see if sleep mode selected
if (digitalRead(Sleep_pin) == HIGH) {
Particle.publish("Oak Setup", "Entering Deep Sleep", 60, PRIVATE);
ESP.deepSleep(sleepTimeS*1000000, WAKE_RF_DEFAULT); // Sleep
}
else {
Particle.publish("Oak Setup","Entering Non Sleep Mode",60,PRIVATE);
}
} //END setup()
void loop(void) {
// We are here because Non Sleep Mode has been selected.
// Will remain in loop() until reset or power cycle occurs.
digitalWrite(OakLEDpin,HIGH); // Turn on onboard LED
Particle.publish("Oak Loop", "Working", 60, PRIVATE);
// Put your code here to do work like read a value or set a pin
delay(500); // Short pluse stretch onboard LED for visual effect
digitalWrite(OakLEDpin,LOW); // Turn off onboard LED
// Delay - don't flood Particle.io
for(int i=0; i<sleepTimeS; i++) {
delay(1000); // This delay * sleepTimeS slows updates to particle.io log
}
} //END loop()