issues icon indicating copy to clipboard operation
issues copied to clipboard

Could not allocate memory for JSON document!

Open sajikur opened this issue 2 years ago • 53 comments

The problem

Hi, someone could help me for this error?

[19:04:29][E][json:034]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 38872 bytes [19:04:29][D][sensor:125]: 'RSSI sensore 12': Sending state -48.00000 dB with 0 decimals of accuracy [19:04:29][E][json:034]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 38872 bytes [19:04:30][D][esp32_ble_tracker:723]: Found device 00:7C:2D:F4:D6:2F RSSI=-92 [19:04:30][D][esp32_ble_tracker:744]: Address Type: PUBLIC [19:04:31][D][xiaomi_ble:314]: Got Xiaomi HHCCJCY01 (C4:7C:8D:67:38:6B): [19:04:31][D][xiaomi_ble:326]: Conductivity: 1674µS/cm [19:04:31][D][sensor:125]: 'Fertilizzazione sensore 5': Sending state 1674.00000 µS/cm with 0 decimals of accuracy INFO 192.168.0.151: Ping timed out! INFO Disconnected from ESPHome API for 192.168.0.151 WARNING Disconnected from API INFO 192.168.0.151: Error while reading incoming messages: Error while reading data: 0 bytes read on a total of 1 expected bytes WARNING Can't connect to ESPHome API for 192.168.0.151: Error while reading data: 0 bytes read on a total of 1 expected bytes INFO Trying to reconnect to 192.168.0.151 in the background INFO 192.168.0.151: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer INFO Successfully connected to 192.168.0.151 [19:05:38][D][sensor:125]: 'Segnale WIFI ESP piante': Sending state -81.00000 dBm with 0 decimals of accuracy [19:06:38][D][sensor:125]: 'Segnale WIFI ESP piante': Sending state -81.00000 dBm with 0 decimals of accuracy [19:07:38][D][sensor:125]: 'Segnale WIFI ESP piante': Sending state -80.00000 dBm with 0 decimals of accuracy [19:08:38][D][sensor:125]: 'Segnale WIFI ESP piante': Sending state -82.00000 dBm with 0 decimals of accuracy [19:08:49][I][ota:105]: Boot seems successful, resetting boot loop counter.

My esp32 mini D1 goes offline and reconnect many times in a day. I'm on the latest update, Wifi signal is strong but rssi goes between -50 to -87. Any ideas to solve? THX

Which version of ESPHome has the issue?

Current version: 2022.3.1

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

mini d1 with esternal antenna

Component causing the issue

No response

Example YAML snippet

  name: piante_interno
  platform: ESP32
  board: wemos_d1_mini32

wifi:
  ssid: "xxxxxxxxxxxxxxx"
  password: "xxxxxxxxxxxxxxxx"

  manual_ip:
    static_ip: 192.168.0.124
    gateway: 192.168.0.1
    subnet: 255.255.255.0  
  
# Enable logging
logger:

web_server:



# Enable Home Assistant API

api:

ota:


binary_sensor:
  - platform: status
    name: "ESP Piante interno"
    
switch:
  - platform: restart
    name: "ESP piante interno Restart"  
    
esp32_ble_tracker:

sensor:
  - platform: xiaomi_hhccjcy01
    mac_address: C4:7C:8D:6A:BC:62
    temperature:
      name: "Temperatura sensore 1a"
    moisture:
      name: "Acqua sensore 1a"
    illuminance:
      name: "Intensità luminosa sensore 1a"
    conductivity:
      name: "Fertilizzazione sensore 1a"
      
  - platform: ble_rssi
    mac_address: C4:7C:8D:6A:BC:62
    name: "RSSI sensore 1a"      


  - platform: xiaomi_hhccjcy01
    mac_address: C4:7C:8D:61:B6:06
    temperature:
      name: "Temperatura sensore 2a"
    moisture:
      name: "Acqua sensore 2a"
    illuminance:
      name: "Intensità luminosa sensore 2a"
    conductivity:
      name: "Fertilizzazione sensore 2a"
      
  - platform: ble_rssi
    mac_address: C4:7C:8D:61:B6:06
    name: "RSSI sensore 2a"  ```   


sajikur avatar Mar 28 '22 17:03 sajikur

Exactly the same problem on a Sonoff Dual R3:

imagen

On Sonoff Basic I had to go back to 2022.2.5 due to a problem with JSON too. A lot of lines in log like these:

[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:17][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     
[18:14:18][W][json:079]: Increasing memory allocation.                                                     

This occurs when I switch the relay through Home Assistant.

skarcha avatar Mar 28 '22 18:03 skarcha

I've the same issue on esphome esp32 d1 mini. Bug on last update?

In data 28 marzo 2022 20:27:24 Antonio Pérez @.***> ha scritto:

Exactly the same problem on a Sonoff Dual R3:

On Sonoff Basic I had to go back to 2022.2.5 due to a problem with JSON too. A lot of lines in log like these: [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:17][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. [18:14:18][W][json:079]: Increasing memory allocation. This occurs when I switch the relay through Home Assistant. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

sajikur avatar Mar 28 '22 19:03 sajikur

Same issue here with NSPanel, boots up and starts throwing below error.

07][W][json:079]: Increasing memory allocation.

Will then reboot again and again. Started couple of days ago with the v2022.3.1 release.

mivano avatar Mar 28 '22 20:03 mivano

I do see this PR https://github.com/esphome/esphome/pull/3289 as part of the latest release. I m not clever enough to see if it is indeed related but maybe @jesserockz knows?

mivano avatar Mar 28 '22 20:03 mivano

I don't know. Hope in a short time solution ;)

sajikur avatar Mar 29 '22 09:03 sajikur

Workaround to avoid restarts:

logger:
    level: NONE
    baud_rate: 0

zdzichu6969 avatar Mar 29 '22 14:03 zdzichu6969

compiling with your workaround hide the log. with only "logger: " I see a new warning

/data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c: In function 'spiTransferBytesNL': /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c:922:39: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types] uint8_t * last_out8 = &result[c_longs-1]; ^ /data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c:923:40: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types] uint8_t * last_data8 = &last_data;

sajikur avatar Mar 29 '22 16:03 sajikur

last update, with change of the version, solve "could not allocate..." problem. Remain last problem and this

"pio system prune"

what is that and how can I solve?

THANX

sajikur avatar Mar 30 '22 08:03 sajikur

The 2022.3.2 fixed the issue for me (sonoff NSpanel). No longer crashing and normal log output. Thanks.

mivano avatar Mar 30 '22 18:03 mivano

Landed here due to I have this issue now on a just update ESP32: 2022.3.2

11:31:26 | [D] | [atc_mithermometer:121] | Battery Level: 50 %
11:31:26 | [D] | [atc_mithermometer:124] | Battery Voltage: 2.679 V
11:31:26 | [D] | [sensor:125] | 'Temperature': Sending state 19.10000 °C with 1 decimals of accuracy
11:31:26 | [D] | [sensor:125] | 'Humidity': Sending state 51.00000 % with 0 decimals of accuracy
11:31:26 | [E] | [json:034] | Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 38388 bytes
11:31:26 | [D] | [sensor:125] | 'Battery-Level': Sending state 50.00000 % with 0 decimals of accuracy
11:31:26 | [E] | [json:034] | Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 38388 bytes
11:31:26 | [D] | [sensor:125] | 'Battery-Voltage': Sending state 2.67900 V with 3 decimals of accuracy
11:31:26 | [E] | [json:034] | Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 38388 bytes
11:31:27 | [D] | [esp32_ble_tracker:723] | Found device E7:74:2E:CC:0C:9F RSSI=-83
11:31:27 | [D] | [esp32_ble_tracker:744] | Address Type: RANDOM
11:31:32 | [I] | [ota:105] | Boot seems successful, resetting boot loop counter.
11:31:32 | [D] | [esp32.preferences:114] | Saving preferences to flash...
11:31:33 | [D] | [esp32_ble_tracker:217] | Starting scan...
11:31:33 | [D] | [binary_sensor:036] | 'Flower Bluetooth': Sending state OFF

sanderlv avatar Mar 31 '22 09:03 sanderlv

Landed here due to I have this issue now on a just update

same here

sajikur avatar Mar 31 '22 09:03 sajikur

it seems that last update doesn't solve. Reflashed boards but in the logs there are same errors. Uninstall and reinstall ESPHOME, same errors (plus others) any ideas to solve? Thanx

sajikur avatar Apr 02 '22 05:04 sajikur

Same issue, but with P1 DSMR , ESP8266 based. If I disable the integration in Home Assistant however, the error isn't logged and the ESPhome devices don't reboot (unless after 15minutes because no client is connecting)

statte avatar Apr 05 '22 15:04 statte

Hi, no ideas to solve?

sajikur avatar Apr 07 '22 05:04 sajikur

One of the possible solutions in my case would be to disable the API component and use MQTT , but I've yet to test this(!). I Don't know how relevant it would be in your case.

statte avatar Apr 07 '22 09:04 statte

I don't use MQTT and the error persists from the penultimate version and there is no way around it. I hope everything will work again with the next update

sajikur avatar Apr 07 '22 10:04 sajikur

I am getting the same error with ESPHome version 2022.3.1:

[E][json:034]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 37660 bytes

on this board:

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

paulius2k avatar Apr 07 '22 15:04 paulius2k

same error with ESPHome 2022.3.2 on HA 2022.4

not seeing any restarts, i'm also seeing it intermittently when reading my airthings BLE sensors. when i say intermittently sometimes it reads fine but most time it errors out on at least one of the sensors its reading, most of the times the error comes up on the last sensor value read (tvoc) as in the log sample below.

with two boards:

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

and

esp32:
  board: esp32dev
  framework:
    type: arduino

here is the code running on both boards:

esphome:
  name: keeyees

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "XXXXXXXXXXXXX"

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

sensor:
  - platform: airthings_wave_mini
    ble_client_id: airthingsmini1
    update_interval: 5min # default
    temperature:
      name: "B1 WaveMini Temperature"
    pressure:
      name: "B1 WaveMini Pressure"
    humidity:
      name: "B1 WaveMini Humidity"
    tvoc:
      name: "B1 WaveMini VOC"

ble_client:
  - mac_address: F4:60:77:75:19:91
    id: airthingsmini1
    
esp32_ble_tracker:

web_server:
  port: 80

log snipet

[12:07:25][D][ble_client:047]: Found device at MAC address [F4:60:77:75:19:91]
[12:07:25][I][ble_client:085]: Attempting BLE connection to f4:60:77:75:19:91
[12:07:39][I][airthings_wave_mini:015]: Connected successfully!
[12:07:43][I][ble_client:161]: Service UUID: 0x1800
[12:07:43][I][ble_client:162]:   start_handle: 0x1  end_handle: 0x7
[12:07:43][I][ble_client:347]:  characteristic 0x2A00, handle 0x3, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A01, handle 0x5, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A04, handle 0x7, properties 0x2
[12:07:43][I][ble_client:161]: Service UUID: 0x1801
[12:07:43][I][ble_client:162]:   start_handle: 0x8  end_handle: 0xb
[12:07:43][I][ble_client:347]:  characteristic 0x2A05, handle 0xa, properties 0x20
[12:07:43][I][ble_client:161]: Service UUID: B42E3882-ADE7-11E4-89D3-123B93F75CBA
[12:07:43][I][ble_client:162]:   start_handle: 0xc  end_handle: 0x18
[12:07:43][I][ble_client:347]:  characteristic B42E3B98-ADE7-11E4-89D3-123B93F75CBA, handle 0xe, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic B42E3EF4-ADE7-11E4-89D3-123B93F75CBA, handle 0x12, properties 0x2c
[12:07:43][I][ble_client:347]:  characteristic B42E41C4-ADE7-11E4-89D3-123B93F75CBA, handle 0x16, properties 0x10
[12:07:43][I][ble_client:161]: Service UUID: F000FFC0-0451-4000-B000-000000000000
[12:07:43][I][ble_client:162]:   start_handle: 0x19  end_handle: 0x25
[12:07:43][I][ble_client:347]:  characteristic F000FFC1-0451-4000-B000-000000000000, handle 0x1b, properties 0x1c
[12:07:43][I][ble_client:347]:  characteristic F000FFC2-0451-4000-B000-000000000000, handle 0x1f, properties 0x1c
[12:07:43][I][ble_client:347]:  characteristic F000FFC5-0451-4000-B000-000000000000, handle 0x23, properties 0x14
[12:07:43][I][ble_client:161]: Service UUID: 0x180A
[12:07:43][I][ble_client:162]:   start_handle: 0x26  end_handle: 0xffff
[12:07:43][I][ble_client:347]:  characteristic 0x2A23, handle 0x28, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A24, handle 0x2a, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A25, handle 0x2c, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A26, handle 0x2e, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A27, handle 0x30, properties 0x2
[12:07:43][I][ble_client:347]:  characteristic 0x2A29, handle 0x32, properties 0x2
[12:07:43][D][esp32_ble_tracker:217]: Starting scan...
[12:07:43][D][sensor:125]: 'B1 WaveMini Humidity': Sending state 31.67000 % with 2 decimals of accuracy
[12:07:43][D][sensor:125]: 'B1 WaveMini Pressure': Sending state 896.23999 hPa with 2 decimals of accuracy
[12:07:43][D][sensor:125]: 'B1 WaveMini Temperature': Sending state 20.23001 °C with 2 decimals of accuracy
[12:07:43][D][sensor:125]: 'B1 WaveMini VOC': Sending state 72.00000 ppb with 0 decimals of accuracy
[12:07:43][E][json:034]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 38872 bytes
[12:07:43][I][ble_client:075]: [f4:60:77:75:19:91] Disabling BLE client.
[12:07:43][W][airthings_wave_mini:021]: Disconnected!

briodan avatar Apr 07 '22 18:04 briodan

Best if I provide some more additional info and to point out that I'm using ESP8266 not ESP32

esphome:
  platform: ESP8266
  board: d1_mini

And HomeAssistant

Version	core-2022.3.8
Installation Type	Home Assistant Container

running config

substitutions:
  device_name: slimmelezer-1sagXXXXXXXXXXXX
  device_description: "DIY P1 module to read your smart meter"
     
esphome:
  name: ${device_name}
  comment: "${device_description}"
  platform: ESP8266
  esp8266_restore_from_flash: true
  board: d1_mini
  name_add_mac_suffix: false
  project:
    name: zuidwijk.slimmelezer
    version: "1.0"
  on_boot:
    then:
      - if:
          condition:
            lambda: return id(has_key);
          then:
            - lambda: |-
                std::string key(id(stored_decryption_key), 32);
                id(dsmr_instance).set_decryption_key(key);
          else:
            - logger.log:
                level: info
                format: "Not using decryption key. If you need to set a key use Home Assistant service 'ESPHome:  ${device_name}_set_dsmr_key'"
 
wifi:
  networks:
    ssid: !secret wifi_ssid
    password: !secret wifi_password
  domain: ".somedomain.here"
 
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${device_name}-AP"
    password: XXXXXXXXXX
    ap_timeout: 15s
 
captive_portal:
 
# Enable logging
logger:
  baud_rate: 0
 
# Enable Home Assistant API
api:
  services:
    service: set_dsmr_key
    variables:
      private_key: string
    then:
      - logger.log:
          format: Setting private key %s. Set to empty string to disable
          args: [private_key.c_str()]
      - globals.set:
          id: has_key
          value: !lambda "return private_key.length() == 32;"
      - lambda: |-
          if (private_key.length() == 32)
            private_key.copy(id(stored_decryption_key), 32);
          id(dsmr_instance).set_decryption_key(private_key);
 
ota:
  password: "passwordhere"

web_server:
  port: 80
 
uart:
  baud_rate: 115200
  rx_pin: D7
 
globals:
  - id: has_key
    type: bool
    restore_value: yes
    initial_value: "false"
  - id: stored_decryption_key
    type: char[32]
    restore_value: yes
 
dsmr:
  id: dsmr_instance
  # For Luxembourg users set here your decryption key. 
  # Enable this when using decryption for Luxembourg;
  # key looks like '00112233445566778899AABBCCDDEEFF'
  #decryption_key: !secret decryption_key 
 
sensor:
  - platform: dsmr
    energy_delivered_lux:
      name: "${device_name} Energy Consumed Luxembourg"
      state_class: total_increasing
    energy_delivered_tariff1:
      name: "${device_name} Energy Consumed Tariff 1"
      state_class: total_increasing
    energy_delivered_tariff2:
      name: "${device_name} Energy Consumed Tariff 2"
      state_class: total_increasing
    energy_returned_lux:
      name: "${device_name} Energy Produced Luxembourg"
      state_class: total_increasing
    energy_returned_tariff1:
      name: "${device_name} Energy Produced Tariff 1"
      state_class: total_increasing
    energy_returned_tariff2:
      name: "${device_name} Energy Produced Tariff 2"
      state_class: total_increasing
    power_delivered:
      name: "${device_name} Power Consumed"
      accuracy_decimals: 3
    power_returned:
      name: "${device_name} Power Produced"
      accuracy_decimals: 3
    electricity_failures:
      name: "${device_name} Electricity Failures"
      icon: mdi:alert
    electricity_long_failures:
      name: "${device_name} Long Electricity Failures"
      icon: mdi:alert
    voltage_l1:
      name: "${device_name} Voltage Phase 1"
    voltage_l2:
      name: "${device_name} Voltage Phase 2"
    voltage_l3:
      name: "${device_name} Voltage Phase 3"
    current_l1:
      name: "${device_name} Current Phase 1"
    current_l2:
      name: "${device_name} Current Phase 2"
    current_l3:
      name: "${device_name} Current Phase 3"
    power_delivered_l1:
      name: "${device_name} Power Consumed Phase 1"
      accuracy_decimals: 3
    power_delivered_l2:
      name: "${device_name} Power Consumed Phase 2"
      accuracy_decimals: 3
    power_delivered_l3:
      name: "${device_name} Power Consumed Phase 3"
      accuracy_decimals: 3
    power_returned_l1:
      name: "${device_name} Power Produced Phase 1"
      accuracy_decimals: 3
    power_returned_l2:
      name: "${device_name} Power Produced Phase 2"
      accuracy_decimals: 3
    power_returned_l3:
      name: "${device_name} Power Produced Phase 3"
      accuracy_decimals: 3
    gas_delivered:
      name: "${device_name} Gas Consumed"
      state_class: total_increasing
    gas_delivered_be:
      name: "${device_name} Gas Consumed Belgium"
      state_class: total_increasing
  - platform: uptime
    name: "${device_name} SlimmeLezer Uptime"
  - platform: wifi_signal
    name: "${device_name} SlimmeLezer Wi-Fi Signal"
    update_interval: 60s
 
text_sensor:
  - platform: dsmr
    identification:
      name: "${device_name} DSMR Identification"
    p1_version:
      name: "${device_name} DSMR Version"
    p1_version_be:
      name: "${device_name} DSMR Version Belgium"
  - platform: wifi_info
    ip_address:
      name: "${device_name} SlimmeLezer IP Address"
    ssid:
      name: "${device_name} SlimmeLezer Wi-Fi SSID"
    bssid:
      name: "${device_name} SlimmeLezer Wi-Fi BSSID"
  - platform: version
    name: "${device_name} ESPHome Version"
    hide_timestamp: true

Log snip snip

21:55:41][D][sensor:124]: 'devicenamehere SlimmeLezer Wi-Fi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy
[21:55:41][D][sensor:124]: 'devicenamehere Energy Consumed Tariff 1': Sending state 5081.72217 kWh with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1816 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Energy Consumed Tariff 2': Sending state 4618.21387 kWh with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Energy Produced Tariff 1': Sending state 0.00000 kWh with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Energy Produced Tariff 2': Sending state 0.16900 kWh with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Power Consumed': Sending state 0.44200 kW with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Power Produced': Sending state 0.00000 kW with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Voltage Phase 1': Sending state 229.50000 V with 1 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Voltage Phase 2': Sending state 0.00000 V with 1 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Voltage Phase 3': Sending state 227.39999 V with 1 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Current Phase 1': Sending state 1.91000 A with 1 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Current Phase 2': Sending state 0.68000 A with 1 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Current Phase 3': Sending state 2.14000 A with 1 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Power Consumed Phase 1': Sending state 0.34400 kW with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Power Consumed Phase 2': Sending state 0.00000 kW with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes
[21:55:41][D][sensor:124]: 'devicenamehere Power Consumed Phase 3': Sending state 0.09700 kW with 3 decimals of accuracy
[21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes


Then reboot happens and works again for like 1 to 2 minutes

statte avatar Apr 07 '22 20:04 statte

Same errors here with esp32, esp32 mini d1, esp8266

In data 7 aprile 2022 22:17:13 statte @.***> ha scritto:

Best if I provide some more additional info and to point out that I'm using ESP8266 not ESP32 esphome: platform: ESP8266 board: d1_mini

And HomeAssistant Version core-2022.3.8 Installation Type Home Assistant Container

running config substitutions: device_name: slimmelezer-1sagXXXXXXXXXXXX device_description: "DIY P1 module to read your smart meter" esphome: name: ${device_name} comment: "${device_description}" platform: ESP8266 esp8266_restore_from_flash: true board: d1_mini name_add_mac_suffix: false project: name: zuidwijk.slimmelezer version: "1.0" on_boot: then: - if: condition: lambda: return id(has_key); then: - lambda: |- std::string key(id(stored_decryption_key), 32); id(dsmr_instance).set_decryption_key(key); else: - logger.log: level: info format: "Not using decryption key. If you need to set a key use Home Assistant service 'ESPHome: ${device_name}_set_dsmr_key'" wifi: networks: ssid: !secret wifi_ssid password: !secret wifi_password domain: ".somedomain.here" # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "${device_name}-AP" password: XXXXXXXXXX ap_timeout: 15s captive_portal: # Enable logging logger: baud_rate: 0 # Enable Home Assistant API api: services: service: set_dsmr_key variables: private_key: string then: - logger.log: format: Setting private key %s. Set to empty string to disable args: [private_key.c_str()] - globals.set: id: has_key value: !lambda "return private_key.length() == 32;" - lambda: |- if (private_key.length() == 32) private_key.copy(id(stored_decryption_key), 32); id(dsmr_instance).set_decryption_key(private_key); ota: password: "passwordhere" web_server: port: 80 uart: baud_rate: 115200 rx_pin: D7 globals: - id: has_key type: bool restore_value: yes initial_value: "false"

  • id: stored_decryption_key type: char[32] restore_value: yes dsmr: id: dsmr_instance # For Luxembourg users set here your decryption key. # Enable this when using decryption for Luxembourg; # key looks like '00112233445566778899AABBCCDDEEFF' #decryption_key: !secret decryption_key sensor: - platform: dsmr energy_delivered_lux: name: "${device_name} Energy Consumed Luxembourg" state_class: total_increasing energy_delivered_tariff1: name: "${device_name} Energy Consumed Tariff 1" state_class: total_increasing energy_delivered_tariff2: name: "${device_name} Energy Consumed Tariff 2" state_class: total_increasing energy_returned_lux: name: "${device_name} Energy Produced Luxembourg" state_class: total_increasing energy_returned_tariff1: name: "${device_name} Energy Produced Tariff 1" state_class: total_increasing energy_returned_tariff2: name: "${device_name} Energy Produced Tariff 2" state_class: total_increasing power_delivered: name: "${device_name} Power Consumed" accuracy_decimals: 3 power_returned: name: "${device_name} Power Produced" accuracy_decimals: 3 electricity_failures: name: "${device_name} Electricity Failures" icon: mdi:alert electricity_long_failures: name: "${device_name} Long Electricity Failures" icon: mdi:alert voltage_l1: name: "${device_name} Voltage Phase 1" voltage_l2: name: "${device_name} Voltage Phase 2" voltage_l3: name: "${device_name} Voltage Phase 3" current_l1: name: "${device_name} Current Phase 1" current_l2: name: "${device_name} Current Phase 2" current_l3: name: "${device_name} Current Phase 3" power_delivered_l1: name: "${device_name} Power Consumed Phase 1" accuracy_decimals: 3 power_delivered_l2: name: "${device_name} Power Consumed Phase 2" accuracy_decimals: 3 power_delivered_l3: name: "${device_name} Power Consumed Phase 3" accuracy_decimals: 3 power_returned_l1: name: "${device_name} Power Produced Phase 1" accuracy_decimals: 3 power_returned_l2: name: "${device_name} Power Produced Phase 2" accuracy_decimals: 3 power_returned_l3: name: "${device_name} Power Produced Phase 3" accuracy_decimals: 3 gas_delivered: name: "${device_name} Gas Consumed" state_class: total_increasing gas_delivered_be: name: "${device_name} Gas Consumed Belgium" state_class: total_increasing - platform: uptime name: "${device_name} SlimmeLezer Uptime" - platform: wifi_signal name: "${device_name} SlimmeLezer Wi-Fi Signal" update_interval: 60s text_sensor: - platform: dsmr identification: name: "${device_name} DSMR Identification" p1_version: name: "${device_name} DSMR Version" p1_version_be: name: "${device_name} DSMR Version Belgium" - platform: wifi_info ip_address: name: "${device_name} SlimmeLezer IP Address" ssid: name: "${device_name} SlimmeLezer Wi-Fi SSID" bssid: name: "${device_name} SlimmeLezer Wi-Fi BSSID" - platform: version name: "${device_name} ESPHome Version" hide_timestamp: true Log snip snip 21:55:41][D][sensor:124]: 'devicenamehere SlimmeLezer Wi-Fi Signal': Sending state -50.00000 dBm with 0 decimals of accuracy [21:55:41][D][sensor:124]: 'devicenamehere Energy Consumed Tariff 1': Sending state 5081.72217 kWh with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1816 bytes [21:55:41][D][sensor:124]: 'devicenamehere Energy Consumed Tariff 2': Sending state 4618.21387 kWh with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Energy Produced Tariff 1': Sending state 0.00000 kWh with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Energy Produced Tariff 2': Sending state 0.16900 kWh with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Power Consumed': Sending state 0.44200 kW with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Power Produced': Sending state 0.00000 kW with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Voltage Phase 1': Sending state 229.50000 V with 1 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Voltage Phase 2': Sending state 0.00000 V with 1 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Voltage Phase 3': Sending state 227.39999 V with 1 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Current Phase 1': Sending state 1.91000 A with 1 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Current Phase 2': Sending state 0.68000 A with 1 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Current Phase 3': Sending state 2.14000 A with 1 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Power Consumed Phase 1': Sending state 0.34400 kW with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Power Consumed Phase 2': Sending state 0.00000 kW with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes [21:55:41][D][sensor:124]: 'devicenamehere Power Consumed Phase 3': Sending state 0.09700 kW with 3 decimals of accuracy [21:55:41][E][json:033]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 1144 bytes Then reboot happens and works again for like 1 to 2 minutes — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

sajikur avatar Apr 08 '22 04:04 sajikur

Just came here as this hit me:

[E][json:034]: Could not allocate memory for JSON document! Requested 5120 bytes, largest free heap block: 47092 bytes v2022.3.2 on featheresp32

lux4rd0 avatar Apr 08 '22 17:04 lux4rd0

I also have this problem on my ESP32 with home assistant 2022.4.1 and esphome 2022.3.2 Looks like there is a fix in the make: esphome/esphome#3377 but this is only for the esp32 not the esp8266

DJJo14 avatar Apr 13 '22 07:04 DJJo14

No way for me. Ask for downgrade or update. My esp32 has many sensors miflora and temp/hum to control so workaround doesn't solve

In data 13 aprile 2022 09:26:16 DJJo14 @.***> ha scritto:

I also have this problem on my ESP32 with home assistant 2022.4.1 and esphome 2022.3.2 Looks like there is a fix in the make: esphome/esphome#3377 but this is only for the esp32 not the esp8266 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

sajikur avatar Apr 13 '22 07:04 sajikur

No way for me. Ask for downgrade or update. My esp32 has many sensors miflora and temp/hum to control so workaround doesn't solve In data 13 aprile 2022 09:26:16 DJJo14 @.> ha scritto: I also have this problem on my ESP32 with home assistant 2022.4.1 and esphome 2022.3.2 Looks like there is a fix in the make: esphome/esphome#3377 but this is only for the esp32 not the esp8266 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.>

The fix is for both families of devices. If you want to test it out, add the following to the "yaml".

Structure:

external_components:
  - source: github://pr#3384
    components: [ json ]
logger:
  level: VERBOSE

I might also point out, that the BLE stack is very memory hungry, in my testing the allocation failures happened when BLE was in use/being initialized...

dz0ny avatar Apr 13 '22 09:04 dz0ny

Thank you but I prefer wait for update. I'm Not sure to be able to do it in the right mode.

In data 13 aprile 2022 11:24:57 Janez Troha @.***> ha scritto:

No way for me. Ask for downgrade or update. My esp32 has many sensors miflora and temp/hum to control so workaround doesn't solve In data 13 aprile 2022 09:26:16 DJJo14 @.> ha scritto: … I also have this problem on my ESP32 with home assistant 2022.4.1 and esphome 2022.3.2 Looks like there is a fix in the make: esphome/esphome#3377 but this is only for the esp32 not the esp8266 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.> The fix is for both families of devices. If you want to test it out, create components directory and then copy just the folder https://github.com/dz0ny/esphome/tree/fix/json-malloc/esphome/components/json. Structure: one.yaml two.yaml components json

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

sajikur avatar Apr 13 '22 09:04 sajikur

Thank you but I prefer wait for update

@sajikur If you cannot test the fix and verify that it actually works, how do I know to merge the PR?

jesserockz avatar Apr 13 '22 20:04 jesserockz

I'm not so skilled like you to handle code

In data 13 aprile 2022 22:37:32 Jesse Hills @.***> ha scritto:

Thank you but I prefer wait for update @sajikur If you cannot test the fix and verify that it actually works, how do I know to merge the PR? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

sajikur avatar Apr 13 '22 20:04 sajikur

The YAML was given to you above:

external_components:
  - source: github://pr#3384
    components: [ json ]
logger:
  level: VERBOSE

You dont need to know code, you just need to add that to your device yaml and you can test the PR code.

jesserockz avatar Apr 13 '22 20:04 jesserockz

I've tested on my setup on ESP8266 with the DSMR

23:00:23 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:23 | [V] | [sensor:074] | 'namehere Energy Consumed Tariff 2': Received new state 10143.069336
23:00:23 | [D] | [sensor:124] | 'namehere Energy Consumed Tariff 2': Sending state 10143.06934 kWh with 3 decimals of accuracy
23:00:23 | [V] | [json:040] | Size after shrink 124 bytes
23:00:23 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:23 | [V] | [dsmr:105] | Start reading data from P1 port
23:00:23 | [V] | [dsmr:142] | Header of telegram found
23:00:23 | [V] | [dsmr:176] | Footer of telegram found
23:00:23 | [V] | [dsmr:257] | Trying to parse telegram
23:00:23 | [V] | [dsmr:118] | Stop reading data from P1 port
23:00:23 | [V] | [sensor:074] | 'namehere Energy Consumed Tariff 1': Received new state 34.446999
23:00:23 | [D] | [sensor:124] | 'namehere Energy Consumed Tariff 1': Sending state 34.44700 kWh with 3 decimals of accuracy
23:00:23 | [V] | [json:040] | Size after shrink 120 bytes
23:00:23 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:23 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:24 | [V] | [sensor:074] | 'namehere Energy Consumed Tariff 2': Received new state 10143.069336
23:00:24 | [D] | [sensor:124] | 'namehere Energy Consumed Tariff 2': Sending state 10143.06934 kWh with 3 decimals of accuracy
23:00:24 | [V] | [json:040] | Size after shrink 124 bytes
23:00:24 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:24 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:24 | [V] | [sensor:074] | 'namehere Energy Produced Tariff 1': Received new state 0.032000
23:00:24 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space
23:00:24 | [V] | [dsmr:142] | Header of telegram found
23:00:24 | [V] | [dsmr:176] | Footer of telegram found
23:00:24 | [V] | [dsmr:257] | Trying to parse telegram
23:00:24 | [V] | [dsmr:118] | Stop reading data from P1 port

So I am getting a different error message, but the reboot still happens.

also interesting to note that without the PR included (YAML) the error

23:00:24 | [V] | [api.connection:893] | Cannot send message because of TCP buffer space

doesn't occur , verbose logging is enabled in both cases

statte avatar Apr 13 '22 21:04 statte

Thanks, @statte. In your case, I think reboot happens because the node runs out of memory. The "Cannot send message because of TCP buffer space" is saying "hey I'm supposed to write something, but my buffer is empty, maybe i was not able to reserve memory". The memory error would be dumped to your UART when in happens, so you don't see it here. You can maybe try removing some non-essential service(OTA, captive portal) to see if that gives you more room.

dz0ny avatar Apr 13 '22 21:04 dz0ny