Struggling to build ESP-32D

I’m a complete novice at this but I’m struggling to build an ESP-32D. I do have some other boards working so this one is a bit mysterious, especially as I had it working once but I can’t remember how!

Ideally I would like to build it using ESP Builder in Home Assistant but that fails. Attaching the board to my PC, and choosing ESP32 as the board, near the start of the install it fails, and I couldn’t find a log. Restarting it, and skipping ends up with with “InvalidJSONFile: Could not load broken JSON: /data/cache/platformio/packages/[email protected]+2021r2-patch5/.piopm” . I have no idea where to start with this - I’ve read threads which talk about deleting the platformio cache etc etc but I don’t think I have one! This is the generated yaml.

esphome:
  name: test
  friendly_name: test

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "x="

ota:
  - platform: esphome
    password: "x"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test Fallback Hotspot"
    password: "x"

captive_portal:

I also tried with esphome.io using the ready made project called empty ESPhome device which goes through erasing then installing then adding WiFiand that fails too.

Is it just that this board is not supported in those tools? If so, how can I build it?

I just tried renaming the device in Home Assistant and this is the full log.

INFO ESPHome 2025.5.1
INFO Reading configuration /config/esphome/lounge-e.yaml...
Updating /config/esphome/lounge-e.yaml to /config/esphome/oldlounge.yaml

INFO ESPHome 2025.5.1
INFO Reading configuration /config/esphome/oldlounge.yaml...
esphome:
  name: oldlounge
  friendly_name: Lounge ESP BT and BLE
  min_version: 2025.5.1
  build_path: build/oldlounge
  area: ''
  platformio_options: {}
  includes: []
  libraries: []
  name_add_mac_suffix: false
  debug_scheduler: false
esp32:
  board: esp32dev
  framework:
    version: 5.1.6
    sdkconfig_options: {}
    advanced:
      ignore_efuse_custom_mac: false
    components: []
    platform_version: https://github.com/pioarduino/platform-espressif32.git#51.03.07
    source: pioarduino/framework-espidf@https://github.com/pioarduino/esp-idf/releases/download/v5.1.6/esp-idf-v5.1.6.zip
    type: esp-idf
  flash_size: 4MB
  variant: ESP32
  cpu_frequency: 160MHZ
logger:
  baud_rate: 115200
  tx_buffer_size: 512
  deassert_rts_dtr: false
  task_log_buffer_size: 768
  hardware_uart: UART0
  level: DEBUG
  logs: {}
api:
  encryption:
    key: [redacted]
  port: 6053
  password: [redacted]
  reboot_timeout: 15min
ota:
- platform: esphome
  password: [redacted]
  version: 2
  port: 3232
wifi:
  ap:
    ssid: [redacted]
    password: [redacted]
    ap_timeout: 1min
  domain: .local
  reboot_timeout: 15min
  power_save_mode: LIGHT
  fast_connect: false
  enable_btm: false
  enable_rrm: false
  passive_scan: false
  enable_on_boot: true
  networks:
  - ssid: [redacted]
    password: [redacted]
    priority: 0.0
  use_address: oldlounge.local
bluetooth_proxy:
  active: true
  cache_services: true
  connection_slots: 3
  connections:
  - {}
  - {}
  - {}
esp32_ble_tracker:
  max_connections: 3
  scan_parameters:
    duration: 5min
    interval: 320ms
    window: 30ms
    active: true
    continuous: true
  software_coexistence: true
sensor:
- platform: ble_rssi
  mac_address: xx
  name: Geoffs BLE strength
  disabled_by_default: false
  force_update: false
  unit_of_measurement: dBm
  accuracy_decimals: 0
  device_class: signal_strength
  state_class: measurement
- platform: ble_rssi
  mac_address: xx
  name: Jans BLE strength
  disabled_by_default: false
  force_update: false
  unit_of_measurement: dBm
  accuracy_decimals: 0
  device_class: signal_strength
  state_class: measurement
binary_sensor:
- platform: ble_presence
  mac_address: xx
  name: Geoffs BLE proximity
  id: Geoffs_BLE_proximity
  on_state:
  - then:
    - if:
        condition:
          binary_sensor.is_on:
            id: Geoffs_BLE_proximity
        then:
        - logger.log:
            format: Device is nearby
            tag: main
            level: DEBUG
            args: []
        else:
        - logger.log:
            format: Device is not nearby
            tag: main
            level: DEBUG
            args: []
  disabled_by_default: false
  timeout: 5min
- platform: ble_presence
  mac_address: xx
  name: Jans BLE proximity
  id: Jans_BLE_proximity
  on_state:
  - then:
    - if:
        condition:
          binary_sensor.is_on:
            id: Jans_BLE_proximity
        then:
        - logger.log:
            format: Device is nearby
            tag: main
            level: DEBUG
            args: []
        else:
        - logger.log:
            format: Device is not nearby
            tag: main
            level: DEBUG
            args: []
  disabled_by_default: false
  timeout: 5min
captive_portal: {}

INFO Configuration is valid!
INFO ESPHome 2025.5.1
INFO Reading configuration /config/esphome/oldlounge.yaml...
INFO Generating C++ source...
INFO Updating https://github.com/espressif/[email protected]
INFO Compiling app...
Processing oldlounge (board: esp32dev; framework: espidf; platform: https://github.com/pioarduino/platform-espressif32.git#51.03.07)
--------------------------------------------------------------------------------
InvalidJSONFile: Could not load broken JSON: /data/cache/platformio/packages/[email protected]+2021r2-patch5/.piopm:`

It made no difference whether framework was set to arduino or esp-idf

It looks to me that a JSON file that has been cached in ESPHone is corrupt. Try cleaning the build files. Click the 3 dots and select Clean Build Files in the popup menu.

Thanks, that sounded really promising to me but that didn’t work. However you may be on the right track because along the way I have attached a new board , using another board I’ve bought (unused I believe) - a C6. Just for testing I skipped the step where you tell it where the board is connected and went to the menu and selected ESP32-C6, which is what it is. I get the message that the config is created with the encryption key. I choose manual install to “install it myself using ESPHome Web”, the log shows it starting then

INFO Reading configuration /config/esphome/lounge-new.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing lounge-new (board: esp32-c6-devkitc-1; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
UnknownBoard: Unknown board ID 'esp32-c6-devkitc-1'``

which is not the same error but makes me think something somewhere is broken, probably local to me. I’m not sure what I should delete though.

Or, I suppose, for some reason it’s not reaching the bit of the internet it needs. I have nothing in the way though, and a fast connection etc.

UPDATED TO ADD YAML

This defaults to framework type arduino which gives the error above. If I change that to esp-idf I get the same error as before

InvalidJSONFile: Could not load broken JSON: /data/cache/platformio/packages/[email protected]+2021r2-patch5/.piopm

Here’s the YAML

esphome:
  name: lounge-new
  friendly_name: Lounge new

esp32:
  board: esp32-c6-devkitc-1
  framework:
    type: esp-idf
    

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxx/zz+2gKY="

ota:
  - platform: esphome
    password: "zz"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lounge-New Fallback Hotspot"
    password: "zz"

captive_portal:

And after deleting and reinstalling ESP Home Builder…

INFO ESPHome 2025.5.1
INFO Reading configuration /config/esphome/lounge2.yaml...
INFO Generating C++ source...
INFO Core config, version or integrations changed, cleaning build files...
INFO Compiling app...
Processing lounge2 (board: esp32-c6-devkitc-1; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
Platform Manager: Installing platformio/espressif32 @ 5.4.0
INFO Installing platformio/espressif32 @ 5.4.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Platform Manager: [email protected] has been installed!
INFO [email protected] has been installed!
UnknownBoard: Unknown board ID 'esp32-c6-devkitc-1'

However if I change the platform to esp-idf it compiles correctly.

I don’t think this has solved my original problem but more testing to follow. I need to get on with some other stuff first though.

I was about the write that Arduino is the default platform in ESPHome and it’s a bit old and don’t support newer chips. Changing to esp-idf usually fixes that.

However, I think we’re dealing with two different issues. Are you still gettting the

InvalidJSONFile: Could not load broken JSON: /data/cache/platformio/packages/[email protected]+2021r2-patch5/.piopm

Error message with the ESP32D?

Yes, hence the move to try a different board

EDIT: Which I have now managed to get built but the log stops at “Starting scheduler on CPU0”… that was with a minimal yaml.

2nd Edit - yes Zenzay , quite likely two different problems but I mention all the facts in case they may be relevant (which rather clogs up the discussion). Btw the link you posted was where I found the arduino/esp framework idea - but thanks :slight_smile:

I’ve done a lot of poking and prodding but the only significant thing I think was changing the cable and I now have a (nearly) successful build on the ESP 32D

I have changed the cable back and it doesn’t fail, even if I rerase the card, which might mean something else fixed it. I did reboot my PC at some point but I’ve had this problem for days so that can’t be it. Other than that I’m not sure what changed.

I’m just left with some non fatal messages in the log

[17:52:15][I][wifi:313]: WiFi Connecting to 'Geoffs WiFi'...
[17:52:15][W][wifi:674]: WiFi Unknown connection status 0
[17:52:15][I][wifi:313]: WiFi Connecting to 'Geoffs WiFi'...
[17:52:15][W][wifi_esp32:569][arduino_events]: Event: Disconnected ssid='Geoffs WiFi' bssid=[redacted] reason='Association Leave'
[17:52:17][I][wifi:617]: WiFi Connected! 

and later

[17:52:18][W][component:167]: Component api set Warning flag: unspecified

then every minute

[17:52:26][W][api.connection:135]: : Socket operation failed: BAD_INDICATOR errno=11
[17:52:26][W][component:182]: Component api cleared Warning flag
[17:52:26][W][component:167]: Component api set Warning flag: unspecified1

But it seems to be reporting what I need it to, so I will look at these “in the fullness of time!!”

I hate not knowing or being able to say what fixed it but thanks for your help and tips

Why can’t that be it? The first question Help Desk asks you to do is reboot your computer.

You neglected to include the part of the log that shows all the networks the device can see and how strong they are. Many weird connectivity problems are caused by bad Wi-Fi. There are many reasons this could be.

As I implied, the computer has been rebooted many times during this investigation.

I chose to not include the whole log, it wasn’t neglect. I understand WiFi quality and had concluded that wasn’t the problem, so I chose to include the things I didn’t really understand that I thought might be helpful to troubleshooting. The logs are, as you probably know, massive and I felt the thread was already overblown in size.

So assume the WiFi is OK. Can you help please with the more likely of the many reasons which may cause this? Just the top five please, for the time being.

Since you are sure it isn’t the Wi-Fi connection look here:

Thanks. I usually do try reboots and having read that I will bear it in mind for future issues. However in this case it’s not solved the problem but, as I said above, the board seems to be doing what I want it to so I’m moving on for a bit.

Rebooting the host Pi did however resolve another issue with rebuilding a C6, although that now also has a different error which doesn’t seem to impact but I will investigate.

Just fyi, it kind of helps that I have two Home Assistants on my network, in that I can go to each and see if they are logging the same errors. This is a temporary move really, brought about because to build OTA with ESP Home Builder I need an SSL connection, which my regular HA doesn’t have - I use Cloudflare.

Anyway, thanks for the link & suggestion, I’ll bear it in mind in future.