WIFIO is a dual Arduino WIFI module (ESP8266+ATMEGA328P) FCC approve-able with transferable licence. Can use the 328P for I/O expansion also...

Moderator: igrr

User avatar
By ESPevan
#44649 Hi,

Firstly, don't know if I'm posting in the right place. If not, please direct me to the correct thread.

My problem is that I'm trying to send the ESP into deep sleep, but when verifying my code, I get the following error:

bikeLock:130: error: 'ESP' does not name a type
ESP.deepSleep(6000000, WAKE_RF_DEFAULT);

The code runs fine without the deep sleep line, but I need it to go to sleep to maximize battery life.

My code (deep sleep is very last line):

#include <SPI.h>
#include <ESP8266WiFi.h>

char ssid[] = ""; // your network SSID (name)
char pass[] = ""; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);
}
server.begin();
// you're connected now, so print out the status:
printWifiStatus();
}


void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

int sensorReading = analogRead(4);
client.print("analog input ");
client.print(4);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");

if(sensorReading > 0) {
client.print("bike is locked and secure");
//client.println("br />");
}
else{
client.print("bike is stolen");
//client.println("br />");
}

client.println("</html>");
break;
}

if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}

}
// give the web browser time to receive the data
delay(2);

// close the connection:
client.stop();
Serial.println("client disonnected");
}
}

//system_deep_sleep_set_option(0);
//system.deepSleep(60000000); //sleep for 6 seconds
ESP.deepSleep(6000000, WAKE_RF_DEFAULT);



Any help is appreciated.
User avatar
By eduperez
#44914 Is that ESP.deepSleep() outside loop()?

In an Arduino sketch, there is a setup(), that is executed once after boot-up, and there is a loop(), that is executed continuously; and there is nothing else, that ESP would never be executed.