ESP8266 - Serial output abruptly stops working

Hi all,

Need some help understanding and fixing the serial output.

I'm running code on an ESP8266 using Arduino IDE.
Code is reading some sensors and then going into deep-sleep for limited time (for troubleshooting, every 5sec).

Using the terminal I attempt to debug my code, however I encounter issues with the serial output.
My terminal displays the output of 1 or 2 cycles... then I see the start of the 3rd cycle, but no more output from my code.
I know my code is running fine, because I do get the sensor readings over MQTT!

I use a NodeMCU as TTL interface:
PC <-> NodeMCU <-> ESP8266

Can someone explain me why my serial output suddenly stops working?

Baud rate is set to 74880 to ensure reduction of the gibberish on ESP startup.

Example output given below:


 ets Jan  8 2013,rst cause:2, boot mode:(3,0)

load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
Serial is Ready
Entering Setup function
Disabling radio
Defining MQTT parameters
Prevent flash read of Wif confi⸮HU(V⸮⸮⸮().b⸮⸮W,B$⸮K9⸮..⸮⸮*Te#⸮raw battery:744.10
Battery: 3.68
Waking up radio
Verifing known WiFi parameters from RTC memory
Initiate connection to Wifi 
Titi-2.4
No RTC data found, fallback to normal connection
Verifying WiFi state
..........................................................
Wifi properly connected
Initiating reading temp/hum
Turning on sensor
Reading values
Temperature: 22.40
Humidity: 50.90
Turning off sensor
Initiating reading lum
Turning on LDR sensor
Luminosity: nan
Turning off sensor
Verifying WiFi state

Wifi properly connected

Reconnecting to MQTT...
CONNECTED
Publishing values to MQTT server
Entering Deep-Sleep mode
Elapsed time: 9005

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
Serial is Ready
Enteringt⸮@u+⸮7#(1V⸮RkAW⸮e⸮Defining MQTT parameters
Prevent flash read of Wificoni⸮*Vu⸮⸮⸮W,.b⸮)-%9⸮K)⸮=.*⸮:*TE⸮raw battery:744.10
Battery: 3.68
Waking up radio
Verifing known WiFi parameters from RTC memory
Initiate connection to Wifi 
Titi-2.4
Found RTC data for quick connection
Initiating reading temp/hum
Turning on sensor
Reading values
Temperature: 22.40
Humidity: 50.40
Turning off sensor
Initiating reading lum
Turning on LDR sensor
Luminosity: nan
Turning off sensor
Verifying WiFi state

Wifi properly connected

Reconnecting to MQTT...
CONNECTED
Publishing values to MQTT server
Entering Deep-Sleep mode
Elapsed time: 5352

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

This forum section ( Gigs and Collaborations) is really meant for looking for paid help with a project. Do you want to pay for help or do you want this topic moved to the Programming section ?

As you have a node-mcu as the ttl to USB-converter
did you check if the nodeMCU is working properly?

Do you have another TTL-to-USB-adapter you could use?
What about connecting your ESP8266 just for testing directly to your PC?

How about buying a $10 logic analyser
24 MHz 8 Channel Logic analyser

These analysers work together with the freeware pulseView which is able to decode a lot of serial protocols

And then of course your code can contain a lot of kind of bugs that only occur over time. Using String-variables for example
best regards Stefan

NodeMCU seems to be working fine, as I do receive the first one or two occurences of reboot.
So I know that connectivity wise, everything is good (otherwise I would get nothing).

I'm attaching my complete code in case anyone would find a bug in it...

Sequence is the following:

  • Read battery
  • Read Temperature & Humidity from DHT sensor
  • Read Illuminance from LDR (via ADC0)
  • Send values over MQTT

a lot is split off into dedicated methods for ease of maintenance.

DHT-LDR.ino (9.9 KB)

So did you really test the continuous receiving?

using the node-MCU in this way:
without any deepsleeping repeat sending the same data
in the same time-intervalls from your ESP8266 to your nodeMCU?

You have to narrow down the problem through narrowing down the involved hardware.

And as a second test sending the serial data to the USB-serial connecting your ESP8266 directly to your PC and let it to the deepsleep-cycles in this way?

best regards Stefan

The NodeMCU is actually not really used...
I leverage the USB-Serial from the NodeMCU only.
On the NodeMCU I connect the EN pin to GND so that the onboard chip is disabled.
This leaves the TX/RX pins available directly to the USB-Serial...

I ordered a new USB-Serial adapter (without any other chip on it) to remove dependency on the NodeMCU. I hope it would offer some improvement.

I tested your recommendations:

  • Remove deep sleep and try serial with very simple code in loop() function --> SUCCESS (no issue with serial)
  • Attempt very simple code with deep-sleep --> FAILURE (serial fails at second iteration)

failing code:

#define SLEEPTIME 1000000
int i = 0;

void setup() {

 Serial.begin(74880);
 delay(50);
 i++;
 Serial.print("Itteration: ");
 Serial.print(i);
 Serial.println("\t Going to sleep now");

 ESP.deepSleep(SLEEPTIME);
}

void loop() {
}

Console output:

11:29:39.262 -> 
11:29:39.262 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
11:29:39.262 -> 
11:29:39.262 -> load 0x4010f000, len 3584, room 16 
11:29:39.262 -> tail 0
11:29:39.262 -> chksum 0xb0
11:29:39.262 -> csum 0xb0
11:29:39.262 -> v2843a5ac
11:29:39.262 -> ~ld
11:29:39.400 -> Itteration: 1	 Going to sleep now
11:29:40.509 -> 
11:29:40.509 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
11:29:40.509 -> 
11:29:40.509 -> load 0x4010f000, len 3584, room 16 
11:29:40.509 -> tail 0
11:29:40.509 -> chksum 0xb0
11:29:40.509 -> csum 0xb0
11:29:40.509 -> v2843a5ac
11:29:40.509 -> ~ld

Update:

I swapped my NodeMCU for an ARduino Mega board (from a starter kit).
Serial works like a charm... no bugs at all after deep sleep.
Hence problem solved. :slight_smile:

Seems that the NodeMCU USB-Serial does not handle well if your board goes into deep sleep.
(note: I also have much less gibberish I expereinced sometimes in my logs. With the arduino, all serial output is clean/clear).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.