Skip to content

Commit

Permalink
Using ESP sleep mode
Browse files Browse the repository at this point in the history
  • Loading branch information
brbrr committed Mar 26, 2016
1 parent 822b49c commit 74eb33c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.pioenvs
.clang_complete
.gcc-flags.json
*tags*
55 changes: 34 additions & 21 deletions src/weather_cli.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void clearBuffer(void);
char* createJson(char* buff, int len);
void doResets(void);
void connectAndSend(void);
void goSleep(long time);

#define ARD_RX 10
#define ARD_TX 11
Expand All @@ -33,7 +34,6 @@ void connectAndSend(void);
// #define PORT 80 // 80 = HTTP default port
#define HOST "192.168.0.50" // Host to contact
#define PORT 3000 // 80 = HTTP default port

// https://weather-api-brbrr.herokuapp.com/

//#define esp Serial1 // If using Leonardo board
Expand Down Expand Up @@ -67,22 +67,45 @@ void setup() {

wifi.setBootMarker(F("ready"));
// wifi.setTimeouts(20000, 20000, 30000, 20000);
doResets();
connectAndSend();

// // doResets();
//
// debug.print(F("Checking firmware version..."));
// wifi.println(F("AT+GMR"));
// char buffer[50];
// if (wifi.readLine(buffer, sizeof(buffer))) {
// debug.println(buffer);
// wifi.find(F("OK.")); // Discard the 'OK' that follows
// } else {
// debug.println(F("error"));
// }

// connectAndSend();
}

void loop() {
delay(100);
unsigned long beforeMilis = millis();
doResets();
connectAndSend();
unsigned long sleepTime = 120000L - (millis() - beforeMilis);
goSleep(beforeMilis);
}

void goSleep(long beforeMilis) {
long sleepTime = 120000L - (millis() - beforeMilis);
debug.print(F("Going to sleep for: "));
debug.println(sleepTime);
delay(100); //delay to allow serial to fully print before sleep

wifi.println(String("AT+GSLP=") + String(sleepTime-100));
delay(100); //delay to allow serial to fully print before sleep
wifi.find(F("OK")); // Discard the 'OK' that follows


delay(100); //delay to allow serial to fully print before sleep
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(sleepTime); //sleep for: sleepTime
debug.println(F("After SleepD"));

}

void connectAndSend() {
Expand Down Expand Up @@ -187,27 +210,17 @@ void doResets() {
debug.print(F("Hard reset..."));
if (!wifi.hardReset()) {
debug.println(F("no response from module."));
for (;; ) ;
for (;; );
}
debug.println(F("OK."));
delay(100);
debug.print(F("Soft reset..."));
if (!wifi.softReset()) {
debug.println(F("failed, one more try.."));
if (!wifi.softReset()) {
debug.println(F("no response from module."));
for (;; ) ;
}
debug.println(F("failed, one more try.."));
if (!wifi.softReset()) {
debug.println(F("no response from module."));
for (;; ) ;
}
}
debug.println(F("OK."));

debug.print(F("Checking firmware version..."));
wifi.println(F("AT+GMR"));
char buffer[50];
if (wifi.readLine(buffer, sizeof(buffer))) {
debug.println(buffer);
wifi.find(F("OK.")); // Discard the 'OK' that follows
} else {
debug.println(F("error"));
}
}

0 comments on commit 74eb33c

Please sign in to comment.