BLE: cannot convert std::string to String

  • ESP32 core 3.x

You may see

error: conversion from 'String' to non-scalar type 'std::string' {aka 'std::__cxx11::basic_string<char>'} requested

Why it happens

  • In ESP32 core 3.x, BLE functions use Arduino String instead of std::string.

How to fix it

  1. Change std::string value = p->getValue(); to String value = p->getValue();.
  2. Or install ESP32 core 2.0.17.

It worked if: Verify passes.

Seen in a real run (some lines are close variants of it). Produced with Arduino CLI 1.5.1 and ESP32 core 3.1.3. Sources: Arduino ESP32: moving from 2.x to 3.0.

Didn't help? Search another error or ask us.