dmamontov / esphome-blekeyboard

ESPHome BLE Keyboard
https://community.home-assistant.io/t/esphome-ble-keyboard/
84 stars 16 forks source link

ESP32-C3 doesn't compile #8

Closed gekberlin closed 2 years ago

gekberlin commented 2 years ago

Hi, with my M5Stack C3U ESP32-CE it does not compile ordaniery. It fails all the time with the following output:

INFO Reading configuration /config/esphome/test.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing c3u (board: esp32doit-devkit-v1; framework: espidf; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32C3 240MHz, 320KB RAM, 4MB Flash
 - framework-arduinoespressif32 @ 0.0.0+sha.caef400 
 - framework-espidf @ 3.40302.0 (4.3.2) 
 - tool-cmake @ 3.16.4 
 - tool-ninja @ 1.7.1 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch2 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch2
Reading CMake configuration...
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- noise-c @ 0.1.4
|   |-- libsodium @ 1.10018.1
Compiling /data/c3u/.pioenvs/c3u/src/esphome/components/ble_keyboard/ble_keyboard.o
Compiling /data/c3u/.pioenvs/c3u/src/esphome/components/ble_keyboard/button.o
Compiling /data/c3u/.pioenvs/c3u/src/esphome/components/ble_keyboard/number.o
Compiling /data/c3u/.pioenvs/c3u/src/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.o
In file included from src/esphome/components/ble_keyboard/button.h:7,
                 from src/esphome/components/ble_keyboard/button.cpp:3:
src/esphome/components/ble_keyboard/ble_keyboard.h:28:14: error: 'MediaKeyReport' has not been declared
   void press(MediaKeyReport key, bool with_timer = true);
              ^~~~~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.h:38:3: error: 'BleKeyboard' does not name a type; did you mean 'ble_keyboard'?
   BleKeyboard bleKeyboard;
   ^~~~~~~~~~~
   ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.h: In constructor 'esphome::ble_keyboard::Esp32BleKeyboard::Esp32BleKeyboard(std::__cxx11::string, std::__cxx11::string, uint8_t)':
src/esphome/components/ble_keyboard/ble_keyboard.h:15:33: error: class 'esphome::ble_keyboard::Esp32BleKeyboard' does not have any field named 'bleKeyboard'
       : PollingComponent(1000), bleKeyboard(name, manufacturer_id, battery_level) {}
                                 ^~~~~~~~~~~
src/esphome/components/ble_keyboard/button.cpp: In member function 'virtual void esphome::ble_keyboard::Esp32BleKeyboardButton::press_action()':
src/esphome/components/ble_keyboard/button.cpp:15:5: error: 'MediaKeyReport' was not declared in this scope
     MediaKeyReport mediaKey = {(uint8_t) first_value_, (uint8_t) second_value_};
     ^~~~~~~~~~~~~~
src/esphome/components/ble_keyboard/button.cpp:17:20: error: 'mediaKey' was not declared in this scope
     parent_->press(mediaKey);
                    ^~~~~~~~
*** [/data/c3u/.pioenvs/c3u/src/esphome/components/ble_keyboard/button.o] Error 1
In file included from src/esphome/components/ble_keyboard/number.h:8,
                 from src/esphome/components/ble_keyboard/number.cpp:3:
src/esphome/components/ble_keyboard/ble_keyboard.h:28:14: error: 'MediaKeyReport' has not been declared
   void press(MediaKeyReport key, bool with_timer = true);
              ^~~~~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.h:38:3: error: 'BleKeyboard' does not name a type; did you mean 'ble_keyboard'?
   BleKeyboard bleKeyboard;
   ^~~~~~~~~~~
   ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.h: In constructor 'esphome::ble_keyboard::Esp32BleKeyboard::Esp32BleKeyboard(std::__cxx11::string, std::__cxx11::string, uint8_t)':
src/esphome/components/ble_keyboard/ble_keyboard.h:15:33: error: class 'esphome::ble_keyboard::Esp32BleKeyboard' does not have any field named 'bleKeyboard'
       : PollingComponent(1000), bleKeyboard(name, manufacturer_id, battery_level) {}
                                 ^~~~~~~~~~~
In file included from src/esphome/components/ble_keyboard/ble_keyboard.cpp:3:
src/esphome/components/ble_keyboard/ble_keyboard.h:28:14: error: 'MediaKeyReport' has not been declared
   void press(MediaKeyReport key, bool with_timer = true);
              ^~~~~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.h:38:3: error: 'BleKeyboard' does not name a type; did you mean 'ble_keyboard'?
   BleKeyboard bleKeyboard;
   ^~~~~~~~~~~
   ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.h: In constructor 'esphome::ble_keyboard::Esp32BleKeyboard::Esp32BleKeyboard(std::__cxx11::string, std::__cxx11::string, uint8_t)':
src/esphome/components/ble_keyboard/ble_keyboard.h:15:33: error: class 'esphome::ble_keyboard::Esp32BleKeyboard' does not have any field named 'bleKeyboard'
       : PollingComponent(1000), bleKeyboard(name, manufacturer_id, battery_level) {}
                                 ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'virtual void esphome::ble_keyboard::Esp32BleKeyboard::setup()':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:14:3: error: 'bleKeyboard' was not declared in this scope
   bleKeyboard.begin();
   ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:14:3: note: suggested alternative: 'ble_keyboard'
   bleKeyboard.begin();
   ^~~~~~~~~~~
   ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'virtual void esphome::ble_keyboard::Esp32BleKeyboard::update()':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:18:64: error: 'bleKeyboard' was not declared in this scope
 void Esp32BleKeyboard::update() { state_sensor_->publish_state(bleKeyboard.isConnected()); }
                                                                ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:18:64: note: suggested alternative: 'ble_keyboard'
 void Esp32BleKeyboard::update() { state_sensor_->publish_state(bleKeyboard.isConnected()); }
                                                                ^~~~~~~~~~~
                                                                ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'bool esphome::ble_keyboard::Esp32BleKeyboard::is_connected()':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:21:8: error: 'bleKeyboard' was not declared in this scope
   if (!bleKeyboard.isConnected()) {
        ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:21:8: note: suggested alternative: 'ble_keyboard'
   if (!bleKeyboard.isConnected()) {
        ^~~~~~~~~~~
        ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'void esphome::ble_keyboard::Esp32BleKeyboard::set_delay(uint32_t)':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:35:59: error: 'bleKeyboard' was not declared in this scope
 void Esp32BleKeyboard::set_delay(uint32_t delay_ms = 8) { bleKeyboard.setDelay(delay_ms); }
                                                           ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:35:59: note: suggested alternative: 'ble_keyboard'
 void Esp32BleKeyboard::set_delay(uint32_t delay_ms = 8) { bleKeyboard.setDelay(delay_ms); }
                                                           ^~~~~~~~~~~
                                                           ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'void esphome::ble_keyboard::Esp32BleKeyboard::press(std::__cxx11::string)':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:41:9: error: 'bleKeyboard' was not declared in this scope
         bleKeyboard.print(message.substr(i, 5).c_str());
         ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:41:9: note: suggested alternative: 'ble_keyboard'
         bleKeyboard.print(message.substr(i, 5).c_str());
         ^~~~~~~~~~~
         ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp:43:9: error: 'delay' was not declared in this scope
         delay(default_delay_);
         ^~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:49:5: error: 'bleKeyboard' was not declared in this scope
     bleKeyboard.print(message.c_str());
     ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:49:5: note: suggested alternative: 'ble_keyboard'
     bleKeyboard.print(message.c_str());
     ^~~~~~~~~~~
     ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'void esphome::ble_keyboard::Esp32BleKeyboard::press(uint8_t, bool)':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:59:5: error: 'bleKeyboard' was not declared in this scope
     bleKeyboard.press(key);
     ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:59:5: note: suggested alternative: 'ble_keyboard'
     bleKeyboard.press(key);
     ^~~~~~~~~~~
     ble_keyboard
src/esphome/components/ble_keyboard/ble_keyboard.cpp: At global scope:
src/esphome/components/ble_keyboard/ble_keyboard.cpp:63:30: error: variable or field 'press' declared void
 void Esp32BleKeyboard::press(MediaKeyReport key, bool with_timer) {
                              ^~~~~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:63:30: error: 'MediaKeyReport' was not declared in this scope
src/esphome/components/ble_keyboard/ble_keyboard.cpp:63:50: error: expected primary-expression before 'bool'
 void Esp32BleKeyboard::press(MediaKeyReport key, bool with_timer) {
                                                  ^~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp: In member function 'void esphome::ble_keyboard::Esp32BleKeyboard::release()':
src/esphome/components/ble_keyboard/ble_keyboard.cpp:75:5: error: 'bleKeyboard' was not declared in this scope
     bleKeyboard.releaseAll();
     ^~~~~~~~~~~
src/esphome/components/ble_keyboard/ble_keyboard.cpp:75:5: note: suggested alternative: 'ble_keyboard'
     bleKeyboard.releaseAll();
     ^~~~~~~~~~~
     ble_keyboard
*** [/data/c3u/.pioenvs/c3u/src/esphome/components/ble_keyboard/number.o] Error 1
*** [/data/c3u/.pioenvs/c3u/src/esphome/components/ble_keyboard/ble_keyboard.o] Error 1
========================= [FAILED] Took 48.78 seconds =========================

My yaml:

# BLE Keyboard project
# https://github.com/dmamontov/esphome-blekeyboard

############# User configuration #############

substitutions:

  mdns_name: blekeyboard

  # Wifi credentials
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on

########### End user configuration ###########

############# Base configuration #############

esphome:
  name: c3u
  platformio_options:
    board_build.flash_mode: dio
    board_build.mcu: esp32c3
    platform_packages:
      - platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.2

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_COMPILER_CXX_EXCEPTIONS: y
    advanced:
      ignore_efuse_mac_crc: true

# Enable logging
logger:

# Enable OTA
ota:
  password: "****"

# Enable Home Assistant API
api:
  encryption:
    key: "****"

########### End base configuration ###########

# Enable components
external_components:
  - source: github://dmamontov/esphome-blekeyboard

ble_keyboard:
  id: my_ble_keyboard
  name: "MyBleKeyboard"
  manufacturer_id: "Apple"
  battery_level: 50
  buttons: true

text_sensor:
  - platform: homeassistant
    id: input_text
    entity_id: input_text.blekeyboard_new_message
    internal: true

sensor:
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s

button:
  - platform: restart
    entity_category: "config"
    name: "Restart"

  - platform: template
    name: "Release"
    id: key_release
    icon: "mdi:send"
    on_press:
      then:
        - ble_keyboard.print:
            id: my_ble_keyboard
            text: !lambda "return id(input_text).state;"
        - ble_keyboard.release: my_ble_keyboard

  - platform: template
    name: "Ctrl + A"
    id: key_ctrl_a
    icon: "mdi:vector-combine"
    on_press:
      then:
        - ble_keyboard.combination:
            id: my_ble_keyboard
            delay: 8
            keys:
              - 0x80
              - "a"

Please complete the following information:

Any suggestions?

dmamontov commented 2 years ago

@gekberlin The libraries that the component uses do not support this framework. One for sure. I'll try to port it, lmbo write to the author.

dmamontov commented 2 years ago

@gekberlin

Because I don't have this board, I just tried to compile it.

Try to do the same: https://github.com/dmamontov/esphome-blekeyboard/blob/dev/examples/esp32c3.yaml

Also use the dev version of this component:

external_components:
   - source: github://dmamontov/esphome-blekeyboard@dev

!!! Pay attention to this line: https://github.com/dmamontov/esphome-blekeyboard/blob/dev/examples/esp32c3.yaml#L73

gekberlin commented 2 years ago

Hi @dmamontov, works perfect. Thank you really much. May I can ask an additional question: Is there a possibility to (temporally) turn off bluetooth or the auto reconnect function? I ask because, with your node I do send a command to a chromebase to force suspend, which like said before works now perfectly fine, the esp keyboard gets disconnected as expected. Then unfortunately the esp keyboard forces an auto reconnect which interrupt the suspend process of chromeOS and that's the reason why the chromebase then stays activated.

dmamontov commented 2 years ago

@gekberlin I will try to study this issue. This property is private in the library. But I'll try to get around it somehow. I will report separately.

gekberlin commented 2 years ago

Cool your help is much appreciated!

dmamontov commented 2 years ago

@gekberlin

enjoy)

https://github.com/dmamontov/esphome-blekeyboard/releases/tag/v2.3.0