ESP32 faulty?

Hi all,

I’v got a few ESP32 devices plus ESP8266’s on the WiFi, last week I added an ESP32 NFC tag reader and have been testing the setup before deploying.

It keep dropping WiFi, random times, usually ok for 9-10 hours but then drops out with NaN shown in my HA front-end for WiFi signal strength and the status signal shows disconnected.

A reboot always gets it going again but for an NFC reader thats no good at all as I want to use it for entry/exit control.

I’ve assigned it as a static IP address in the router.

No other WiFi devices seem affected, would this point to a duff ESP32???

(Serial) logs should tell you/us the exact reason :page_with_curl:

Thanks but how?

When it goes offline the logs are unavailable and when rebooted the logs are wiped??

You can use serial logging via USB.
Do you have any evidence that just wifi drops? Not whole esp crashing?

It still responds to tags, so i presume the program is still running, obviously no data is sent to HA though.

We are assuming you are using esphome. If so show your yaml.

Of course…

esphome:
  name: esp-nfc
  friendly_name: ESP_NFC

esp32:
  variant: esp32
  framework:
    type: esp-idf

logger:

api:
  encryption:
    key: "xxxx"

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  ap:
    ssid: "ESP_NFC Fallback Hotspot"
    password: "xxxx"

captive_portal:


# --------------------------------------------------
# ONBOARD LED
# --------------------------------------------------

output:

  - platform: gpio
    pin: GPIO2
    id: onboard_led

  - platform: gpio
    pin: GPIO4
    id: nfc_buzzer


# --------------------------------------------------
# BUZZER SWITCH
# --------------------------------------------------
#
# This exposes GPIO4 directly to Home Assistant.
#
# ON  = GPIO4 ON
# OFF = GPIO4 OFF
#
# There is NO script or automation associated
# with this switch.
#
# --------------------------------------------------

switch:

  - platform: output
    name: "NFC Buzzer"
    id: nfc_buzzer_switch
    output: nfc_buzzer

    # Always start with the switch OFF after boot
    restore_mode: ALWAYS_OFF


# --------------------------------------------------
# SPI BUS
# --------------------------------------------------

spi:
  clk_pin: 18
  miso_pin: 19
  mosi_pin: 23
  id: spi_1


# --------------------------------------------------
# PN532 - SPI
# --------------------------------------------------

pn532_spi:

  id: nfc_reader

  cs_pin: 5
  spi_id: spi_1

  update_interval: 1s

  on_tag:

    then:

      # --------------------------------------------
      # Blink onboard LED
      # --------------------------------------------

      - output.turn_on: onboard_led

      - delay: 300ms

      - output.turn_off: onboard_led


      # --------------------------------------------
      # NFC Buzzer beep
      # --------------------------------------------

      - output.turn_on: nfc_buzzer

      - delay: 600ms

      - output.turn_off: nfc_buzzer


      # --------------------------------------------
      # Send UID to Home Assistant
      # --------------------------------------------

      - homeassistant.tag_scanned: !lambda |

          auto uid = tag.get_uid();
          std::string result;

          for (size_t i = 0; i < uid.size(); i++) {

            if (i > 0) {
              result += "-";
            }

            char buf[3];

            snprintf(
              buf,
              sizeof(buf),
              "%02X",
              uid[i]
            );

            result += buf;
          }

          return result;


# --------------------------------------------------
# WIFI SIGNAL
# --------------------------------------------------

sensor:

  - platform: wifi_signal
    name: "NFC Reader WiFi Signal"
    update_interval: 60s

binary_sensor:
  - platform: status
    name: NFC Status
    id: binary_sensor_status_1
    update_interval: 30s

Yaml does not look obviously bad. You don’t appear to be overtaxing the ESP32

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  manual_ip:
    static_ip: 192.168.0.2
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 192.168.0.3
    dns2: 192.168.0.4

I remember in the early days that I would get devices that would drop and reconnect every few minutes. Over a long period of time this has stopped happening. I can’t say for sure exactly what I did but I do tend to set the wifi as above.
You can get faulty ESP32 so if you have a spare one you could swap that in.
I have seen power supplies that don’t just seem to work with some ESPs.
I have some ESP that I use an automation to restart under certain states e.g.

triggers:
  - trigger: state
    entity_id:
      - climate.2nd_floor_bathroom
    to: unavailable
    for:
      hours: 0
      minutes: 11
      seconds: 0

actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.2ndfloorproxy_restart

It’s frustrating but I try to be practical about things and along the way learn things.
Again as Karosm said get a serial connection to the device and see what logs shows.

If your buzzer beeps, your esp is alive.
If disconnection is really random, it points to wifi problem. But if it’s always around 9-10 hours it points to some other direction.
Try to catch it on esphome logs.

Exactly which esp32 (there are probably 20 different choices now) from where (there are thousands of choices, when you include the various copies of varying quality)?

Many people have had poor results with many different esp32 boards. Some boards are especially bad. These tend to be the cheaper ones from AliExpress.

The red chip antenna is often the vital clue. I recommend you avoid those if WiFi connectivity is critical for your end use.

Check the ESPHome WiFi options for other settings that may improve uptime, such as turning off power saving mode. See:

Set your ESPHome error logging settings to VERY VERBOSE , restart and post some run logs may help narrow down the problem. Please use </> forum formatting for these for readability. Don’t forget to put the logging settings back after you have finished troubleshooting.

It was from Amazon but does look identical to one that i saw in a thread mentioning poor wifi earlier. I have temporarily disconnected the UART and as they saw, it gives a 5-10dbm boost in wifi signal, very odd.

I do have a spare so i can spin that up and try it very easily.

Doesn’t really narrow it down much. Amazon has hundreds listed.

Cheap, good, fast. Pick one or possibly two, because getting all three is impossible. I have many cheap ones that I bought years ago. They mostly work, but when they don’t they are a waste of time figuring out what is wrong. I tend to buy better quality ones now.

There is a thread about which ones people have had good luck with.

There are few infamous board designs that affect wifi. One is early version of common unbranded wroom32 devkit board with usb-c.
You still haven’t answered what you have, but I wouldn’t be surprised if that’s the case here.

But that is not explaining drop after 9-10 hours.

That would be consistent with your wiring connection acting as an antenna, or reorientation of your ESP32 to bring the antenna into a more favorable position in respect of what it was connected to.
5-10dBm is a huge change - 3dBm is double - 10dBm is is in the order of hundred times - it’s logarithmic.

You sure you have a good connection for power?

No bad solder joints? This can often be if the device was hand soldered with leaded solder on a late night kitchen bench by child slave labor and poor lighting, using substitute parts that were discarded factory seconds, just so you could save a few cents and get the cheapest one on Amazon. Please continue to buy these, as the child working 18 hours each day to support the sick grandparents needs the money. Just bin the device and support the charity donation by buying more. Get the picture?

No ESPHome debug log? No clear close-up photo of both sides of the board? We’re guessing.

It is and it isn’t.
A 10dB change in power (which is what we are talking about here) is a 10X change. A 20 dB change is 100X the power. A 3dB change requires twice the power.

But, that is somewhat misleading, as in hearing a 10dB louder signal sounds about twice as loud. Now, that might be the difference in understanding or not.

In my admittedly limited experience, I’ve discovered that sometimes the only issue is the power supply for the ESP32. If you are using old cellphone charges that happen to have the micro USB connector that some variants of the ESP32 use, I’d try swapping with another well-behaved ESP32 and see if the problem moves (it is the charger) or remains (ESP32).

WiFi is the most power-hungry bit of an ESP32 so everything else can work fine but the signal just isn’t strong enough all the time for the link to remain up. Remember that simple things like just walking by a device or opening a door (especially a metal-clad exterior door) can change the whole RF path in mysterious ways.

You can also generally find a specification on the back of a wall-wart for the voltage (usually 5.0V DC) and maximum current - I’ve seen some as low as 0.7A which doesn’t really cut it. I prefer at least 1.5A although a few 1.0A work in my setup.

Ok, here’s the board, the back is flat and plain so i didn’t think it worth a picture.

Very interesting re the dBm figures, thanks. The PSU is a generic phone charger, 5v 1.5A output (labelled) and I do have others so can try a swap if it drops out again.

At present it’s still running ok since the last mod yesterday.

The wiring is still in ‘dev mode’ - push-on wires to the PN532 and it’s still sitting on my coffee table.

I will look for the recommended device thread, i certainly didn’t search out the cheapest offering on purpose but yes there was a massive range out there. I never use AliExpress but do know that Amazon also carries junk too.

Thanks for all the advice and info so far.

There are all sorts of things which can affect wi-fi signal, and most of them are not visible. I suggest it is well worth doing a search in this forum and then spending the couple of hours to read them.
Note also that a few months back ESPHome developers put effort into refactoring and improving the ESPHome Wi-fi code, so some of the threads will no longer be relevant.

So any particular reason for not capturing serial logs that…