Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE and WiFi together #61

Closed
captain324 opened this issue Aug 9, 2024 · 4 comments
Closed

BLE and WiFi together #61

captain324 opened this issue Aug 9, 2024 · 4 comments

Comments

@captain324
Copy link

Using the victron-ble.yaml code as a start, I have been able to connect to a Victron Orion Tr DC-DC Charger. With BLE and WiFi both enabled the ESP32 dev board is unstable, rebooting over and over with errors that BLE is unable to start and that it can not find the WiFi AP. I'm using an Ideaspark (Amazon) ESP32 dev board with an integrated LCD screen. With the WiFi code disabled, it works.

I read there is a coexistence module in the ESP32 code, but it is not working for me. Any suggestions?

Here is my code, still a bit rough but working ...

# WIP adding display stuff
# ili9xxx vs ST7789V - which driver is bettter?
# no binary sensors found
# stable? not stable with both ble and wifi

esphome:
  name: victron-ble-r2
  friendly_name: victron-ble-r2

esp32:
  board: esp32dev
  flash_size: 16MB
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
#api:
#  encryption:
#    key: "JqNKvthRY/fmdq92ESQIys/buKruo1oqUQQOr+aXcCA="

#ota:
#  - platform: esphome
#    password: "7bd2ddffda653538a1a1147ef1ca521e"

#wifi:
#  ssid: !secret wifi_ssid
#  password: !secret wifi_password
#  manual_ip: 
#    static_ip: 192.168.8.100
#    gateway: 192.168.8.1
#    subnet: 255.255.255.0
#    dns1: 1.1.1.1

  # Enable fallback hotspot (captive portal) in case wifi connection fails
#  ap:
#    ssid: "Victron-Ble Fallback Hotspot"
#    password: "ptpdJHm2APPK"

esp32_ble_tracker:

external_components:
  - source: github://Fabian-Schmidt/esphome-victron_ble

victron_ble:
  - id: AuxBatteryCharger
    mac_address: "D9:1A:2E:DC:B1:40"    
    bindkey: "55bf7a059d157eeb4679ba9c1db31c4a"
    on_dcdc_converter_message:
      - logger.log: "Message from DC/DC Converter."

sensor:
  # DC-DC Charger
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Error Report"
    type: CHARGER_ERROR
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Device State"
    type: DEVICE_STATE
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "House Battery"
    type: INPUT_VOLTAGE
    id: input_voltage
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Off Reason"
    type: OFF_REASON
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Aux Battery"
    type: OUTPUT_VOLTAGE
    id: output_voltage

binary_sensor:
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Charger Error"
    type: CHARGER_ERROR

  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "DEVICE_STATE_OFF"
    type: DEVICE_STATE_OFF

  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "DEVICE_STATE_FAULT"   
    type: DEVICE_STATE_FAULT
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "DEVICE_STATE_BULK"
    type: DEVICE_STATE_BULK
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "DEVICE_STATE_ABSORPTION"
    type: DEVICE_STATE_ABSORPTION
    
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "DEVICE_STATE_FLOAT"
    type: DEVICE_STATE_FLOAT
    
text_sensor:
  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Charger Error"
    type: CHARGER_ERROR
    id: charger_error

  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Charger state"
    type: DEVICE_STATE
    id: charger_state

  - platform: victron_ble
    victron_ble_id: AuxBatteryCharger
    name: "Off Reason"
    type: OFF_REASON
    id: off_reason

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23

display:
  - platform: ili9xxx
    model: ST7789V
    transform:
      swap_xy: true
      mirror_x: false
      mirror_y: true
    dimensions:
      height: 170
      width: 320
      offset_height: 35
      offset_width: 0
    cs_pin: GPIO15
    dc_pin: GPIO02
    reset_pin: GPIO04
    invert_colors: true

    lambda: |-
      auto black = Color(0, 0, 0);
      auto red = Color(255, 0, 0);
      auto green = Color(0, 255, 0);
      auto blue = Color(0, 0, 255);
      auto white = Color(255, 255, 255);
      it.print(0, 0, id(font20), "Valiant DC-DC Charger");
      it.line(0, 20, 320, 20);
      it.printf(0, 40, id(font15), "Charger Error:   %s", id(charger_error).state.c_str());
      it.printf(0, 60, id(font15), "Charger State:   %s", id(charger_state).state.c_str());
      it.printf(0, 80, id(font15), "Off Reason: %s", id(off_reason).state.c_str());
      it.printf(0, 100, id(font15), "House Battery Voltage: %5.2f", id(input_voltage).state);
      it.printf(0, 120, id(font15), "Aux Battery Voltage: %5.2f", id(output_voltage).state);

font:
  - file: "gfonts://Roboto"
    id: font20
    size: 20
  - file: "gfonts://Roboto"
    id: font15
    size: 15
  - file: "gfonts://Roboto"
    id: font10
    size: 10
    
#captive_portal:
@Fabian-Schmidt
Copy link
Owner

Hi,
This is a tricky problem. I don't think this issue is related to the victron integration as it uses a common pattern used by ESPHome and nobody has reported this issue.

Without a dump of the error it is hard to identify the cause. Possible root causes (outside of a software bug) are:

  • Running out of memory. Happens very easily when using a display.
  • Processor too busy. Happens sometimes when display is used.
  • Hardware bug. Seen some ESP devices which are just tired.

You can try the following:

  • Disable logging by setting level: None. Logging is blocking operation in ESPHome and I have seen it causing unusual behavior. Especially on high volume levels like debug or verbose.
  • Disable the display. If it causes issues you might need to decrease the refresh rate and increase the data rate.

If you connect and flash the ESP device via USB then it should be possible to collect more details when it crashes to identify the root cause.

Cheers,
Fabian

@captain324
Copy link
Author

Thanks for your comments, I'll give it another try ...

FWIW, I remember having issues with wifi stability before I added any code to enable the display. I'll go back to that and capture some of the log reports.

The board that I'm using has 16M of RAM, I did not think I was running out of memory from the errors I saw. I also tried several delayed start of BLE schemes without success such as those suggested here ... esphome/issues#2941 (comment)

Using Arduino IDE and the example from https://github.com/hoberman/Victron_BLE_Advertising_example plus some wifiseriallite code, BLE and wifi was rock solid. This didn't get my Victron data into HA but did point a finger at ESPHome.

@Fabian-Schmidt
Copy link
Owner

Fabian-Schmidt commented Aug 17, 2024

All ESP32 have 384kb ram. You have additional 16mb PSRam. This additional psram is slow and can only be used for some things. Its not like a normal x86 computer. To use this psram you must add psram to the esphome yaml. Or else it will not use it.
See https://esphome.io/components/psram.html

Edit: I don't think you have 16MB psram. The classic ESP32 only supports 4MB psram maximum. You have 16MB Flash!

@captain324
Copy link
Author

To close this out, my board has 16MB of Flash ...

Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 8c:4b:14:x:x:x
Auto-detected Flash size: 16MB

WiFi became stable when I removed the display code. There was no need to disable logging.

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants