I have an ESP-01 that I want to measure pool temperature with. It will send the data over MQTT to the broker.

I have connected RST to GPIO16 so I can use the deep sleep functionality. Currently I am testing sending a "hello world" to the MQTT broker, and everything works fine when booting up the first time, but it seems like the ESP never wakes up correctly after the first deep sleep.

My script looks like this:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Set ADC mode

// WiFi settings
const char* ssid = "Network";
const char* password = "Password";
IPAddress ip(192, 168, 0, 100);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

// MQTT settings
const char* mqtt_server = "";
const int mqtt_port = 1883;
const char* mqtt_user = "User";
const char* mqtt_pass = "Password";
const char* mqtt_client_name = "poolsensor";
const char* mqtt_topic = "pool";

// Data wire plugged into D1 on the ESP8266 ESP-01 - GPIO 5
#define ONE_WIRE_BUS 5

// Setup OneWire instance to communicate with any device
OneWire oneWire(ONE_WIRE_BUS);

// Pass our OneWire reference to Dallas Temperature
DallasTemperature DS18B20(&oneWire);

WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {

  // Annuonce connection
  Serial.print("Connecting to ");

  // Setup WiFi config and connect
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("Connected, IP address: ");

void reconnect() {
  // Loop until we're connected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");

    // Attempt to connect
    if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass)) {
      // Success
    } else {
      // Fail
      Serial.print("failed, rc=");
      Serial.println(" try again in 5 seconds");

      // Wait 5 seconds before retrying

void setup() {

  // Start WiFi setup

  // Set MQTT server
  client.setServer(mqtt_server, mqtt_port);

  // Set resolution to 0.25

  // Start sensor

void loop() {
  if (!client.connected()) {
  } else {
    // Get temperature
    float temp = DS18B20.getTempCByIndex(0);

    if ((temp > -20) && (temp < 60)) {
      client.publish("pool/temperature", String(temp).c_str(), true);

    client.publish("pool/temperature", "hello world");
    Serial.println("published temperature");


    // Sleep
    ESP.deepSleep(60 * 1000000);


Everything looks good in the serial monitor when compiling and uploading code, as the code runs the first time:

Connecting to Network
Connected, IP address:
Attempting MQTT connection...connected
published temperature

And I can see in my MQTT debugger that it receives hello world. After around 60 seconds, the following is shown in the serial monitor (lots of gibberish):


This is the last message I ever receive from the ESP, so I assume it never deep sleeps again and runs over the code again.

Anyone experienced the same, or see a bug in my code?

  • you have io 0 LOW?
    – Juraj
    Commented Feb 19, 2019 at 10:50
  • 1
    How did you connect anything to GPIO16 on an ESP01? Other than very carefully of course - and D1??? that's wemos/nodemcu garbage (plus the ESP01 doesn't break out gpio 5 either Commented Feb 19, 2019 at 10:53
  • if you set your serial monitor to 74880 baud, then you may be able to read the gibberish Commented Feb 19, 2019 at 11:06
  • @JaromandaX Actually the temp. sensor is not connected yet, so I commented out the code. I ran a thin copper wire from RST to the correct pin on the chip. Baud 74880 worked, and it reads the following: ets Jan 8 2013,rst cause:5, boot mode:(1,6) ets_main.c but only once, and never more. @Juraj no, should I use pinMode(0, LOW); ?
    – rebellion
    Commented Feb 19, 2019 at 11:32
  • 2
    @dandavis, he answered that " I ran a thin copper wire from RST to the correct pin on the chip"
    – Juraj
    Commented Feb 20, 2019 at 6:52

3 Answers 3


Pretty sure you will need gpio 16 connected to reset in order for this to ever work, it’s tricky but not impossible. Have a read here:


  • 1
    I did that. Small copper wire from RST to GPIO16 on the chip.
    – rebellion
    Commented Feb 20, 2019 at 9:19
  • Sorry, missed that one. From your code above it should be waking as expected. As others have said pulling GPIO 0 high is required for normal boot, GPIO 2 is not required but it is good practice to ensure stability. What you are most likely seeing and what I have seen in the past, if you have GPIO 0 grounded, i.e. to program with the arduino IDE, immediately after programming is complete, the chip will reboot normally and run with GPIO 0 grounded, but only once. If you leave GPIO 0 grounded and reboot again (or the chip wakes from sleep) it will not boot. Take GPIO 0 high and it should work.
    – user54057
    Commented Feb 21, 2019 at 22:18

You left io 0 floating. With io 0 not HIGH at boot, the esp8266 goes into flashing mode.

The wake-up from deep-sleep is boot startup. So your code doesn't start if io 0 is not pulled high. Add a pull-up for io 0.

If you set Serial Monitor to 74880 baud, you will see the boot-log readable. It will print 1 as first value in "boot mode". This value is set from state of io 15, 2 and 0. 15 should be LOW and io 2 and io 0 HIGH for normal boot. 1 indicates that only 2 is HIGH.

  • Thanks for your reply. I'm not quite sure if I understand. No guides I've read says I have to pull 0 high. I use a programmer for programming, but I still have the same initial issue when I disconnect the programmer and just connect VCC and GND to a power source.
    – rebellion
    Commented Feb 19, 2019 at 14:37
  • every good esp-01 tutorial connects EN and io 0 to VCC. I would use a pull-up resistor
    – Juraj
    Commented Feb 19, 2019 at 15:15
  • do you understand that io 0 state at boot determines if the board boots to application or to bootloader?
    – Juraj
    Commented Feb 19, 2019 at 15:20
  • Of course, but previously I never have to do this. I've used ESP-01 in several projects, but never with deep sleep, so this is new to me.
    – rebellion
    Commented Feb 19, 2019 at 17:01
  • after upload it start without reboot
    – Juraj
    Commented Feb 19, 2019 at 17:25

I had the same problem and i found out, my CH_PD pin and RST pin were shorted together, when i was connecting wire from RST to GPIO_16. On the chip, the CH_PD pin is next to GPIO_16, so when you short them, the RST pin is always high, so esp cannot reboot anymore without external grounding. I fixed it and now deep sleep is working again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.