[solved] (Not) Possible to have BT + NFC on 1 ESP device?

I already had a Wemos D1 mini with a NFC reader which works fine.
Recently I installed a Wemos C3 to be able to use Bluetooth and got that working too.
Now I thought of adding the NFC reader to the C3 but an error scrolled by that only 1 api is ?possible/allowed? (don’t get that anymore)

Is it (not) possible to have those 2 functions on 1 device?

Yaml? Log?

esphome:
  name: wemos-c3-bt
  friendly_name: Wemos C3 BT

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:

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

ota:
  password: "password"


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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Wemos-C3-Bt Fallback Hotspot"
    password: "password"

captive_portal:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a

pn532_i2c:
  update_interval: 0.3s
  on_tag:
    then:
      - text_sensor.template.publish:
          id: badge_recognized
          state: !lambda 'return x;'
      - if:
          condition:
            text_sensor.state:
              id: badge_recognized
              state: 'XX-XX-XX-XX'
          then:
            - script.execute: person_1_detected

binary_sensor:
  - platform: status
    name: "Module Status"            

# Text sensors with general information.
text_sensor:
  # For Tag.
  - platform: template
    id: badge_recognized
    internal: true
    name: "Badge Recognized"
  - platform: template
    id: person_detected
    name: "Detected"    
  # Expose ESPHome version as sensor.
  - platform: version
    name: ESPHome Version
  # Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:
      name: IP
    ssid:
      name: SSID
    bssid:
      name: BSSID

# Sensors with general information.
sensor:
  # Uptime sensor.
  - platform: uptime
    name: Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s

script:
  - id: person_1_detected
    mode: single
    then:
      - text_sensor.template.publish:
          id: person_detected
          state: !lambda 'return "Nick";'
      - delay: 400ms
      - text_sensor.template.publish:
          id: person_detected
          state: !lambda 'return "Clear";'    

Thanks for looking into Nick!

Still waiting for logs, but I do notice your ble parameters are wrong. Those settings are only for wired Ethernet devices. See Bluetooth Proxy — ESPHome

Also don’t forget the c3 is a single core device, and may not be best suited to being a Bluetooth proxy.

This is the current log:

INFO ESPHome 2024.3.1
INFO Reading configuration /config/esphome/wemos-c3-bt.yaml...
INFO Starting log output from 172.16.0.48 using esphome API
INFO Successfully connected to wemos-c3-bt @ 172.16.0.48 in 0.064s
INFO Successful handshake with wemos-c3-bt @ 172.16.0.48 in 0.128s
[23:55:28][I][app:102]: ESPHome version 2024.3.1 compiled on Sep  3 2024, 22:26:24
[23:55:28][C][wifi:580]: WiFi:
[23:55:28][C][wifi:408]:   Local MAC: XX:XX:XX:XX:XX:XX
[23:55:28][C][wifi:413]:   SSID: 'ssid'[redacted]
[23:55:28][C][wifi:416]:   IP Address: 172.16.0.48
[23:55:28][C][wifi:420]:   BSSID: XX:XX:XX:XX:XX:XX[redacted]
[23:55:28][C][wifi:421]:   Hostname: 'wemos-c3-bt'
[23:55:28][C][wifi:423]:   Signal strength: -57 dB ▂▄▆█
[23:55:28][C][wifi:427]:   Channel: 1
[23:55:28][C][wifi:428]:   Subnet: 255.255.255.0
[23:55:28][C][wifi:429]:   Gateway: 172.16.0.1
[23:55:28][C][wifi:430]:   DNS1: 172.16.0.3
[23:55:28][C][wifi:431]:   DNS2: 0.0.0.0
[23:55:28][C][logger:166]: Logger:
[23:55:28][C][logger:167]:   Level: DEBUG
[23:55:28][C][logger:169]:   Log Baud Rate: 115200
[23:55:28][C][logger:170]:   Hardware UART: USB_CDC
[23:55:28][C][i2c.arduino:059]: I2C Bus:
[23:55:28][C][i2c.arduino:060]:   SDA Pin: GPIO4
[23:55:28][C][i2c.arduino:061]:   SCL Pin: GPIO5
[23:55:28][C][i2c.arduino:062]:   Frequency: 50000 Hz
[23:55:28][C][i2c.arduino:065]:   Recovery: bus successfully recovered
[23:55:28][I][i2c.arduino:075]: Results from i2c bus scan:
[23:55:28][I][i2c.arduino:077]: Found no i2c devices!
[23:55:28][C][template.text_sensor:020]: Template Sensor 'Badge Recognized'
[23:55:28][C][template.text_sensor:020]: Template Sensor 'Detected'
[23:55:28][C][uptime.sensor:031]: Uptime Sensor 'Uptime'
[23:55:28][C][uptime.sensor:031]:   Device Class: 'duration'
[23:55:28][C][uptime.sensor:031]:   State Class: 'total_increasing'
[23:55:28][C][uptime.sensor:031]:   Unit of Measurement: 's'
[23:55:28][C][uptime.sensor:031]:   Accuracy Decimals: 0
[23:55:28][C][uptime.sensor:031]:   Icon: 'mdi:timer-outline'
[23:55:28][C][bluetooth_proxy:088]: Bluetooth Proxy:
[23:55:28][C][bluetooth_proxy:089]:   Active: YES
[23:55:29][C][pn532:431]: PN532:
[23:55:29][C][pn532:443]:   Update Interval: 0.3s
[23:55:29][C][pn532_i2c:125]:   Address: 0x24
[23:55:29][C][status:034]: Status Binary Sensor 'Module Status'
[23:55:29][C][status:034]:   Device Class: 'connectivity'
[23:55:29][C][version.text_sensor:021]: Version Text Sensor 'ESPHome Version'
[23:55:29][C][version.text_sensor:021]:   Icon: 'mdi:new-box'
[23:55:29][C][esp32_ble:374]: ESP32 BLE:
[23:55:29][C][esp32_ble:376]:   MAC address: XX:XX:XX:XX:XX:XX
[23:55:29][C][esp32_ble:377]:   IO Capability: none
[23:55:29][C][esp32_ble_tracker:645]: BLE Tracker:
[23:55:29][C][esp32_ble_tracker:646]:   Scan Duration: 300 s
[23:55:29][C][esp32_ble_tracker:647]:   Scan Interval: 1100.0 ms
[23:55:29][C][esp32_ble_tracker:648]:   Scan Window: 1100.0 ms
[23:55:29][C][esp32_ble_tracker:649]:   Scan Type: ACTIVE
[23:55:29][C][esp32_ble_tracker:650]:   Continuous Scanning: True
[23:55:29][C][captive_portal:088]: Captive Portal:
[23:55:29][C][mdns:115]: mDNS:
[23:55:29][C][mdns:116]:   Hostname: wemos-c3-bt
[23:55:29][C][ota:096]: Over-The-Air Updates:
[23:55:29][C][ota:097]:   Address: wemos-c3-bt.local:3232
[23:55:29][C][ota:100]:   Using Password.
[23:55:29][C][ota:103]:   OTA version: 2.
[23:55:29][C][api:139]: API Server:
[23:55:29][C][api:140]:   Address: wemos-c3-bt.local:6053
[23:55:29][C][api:142]:   Using noise encryption: YES
[23:55:29][C][wifi_info:011]: WifiInfo SSID 'SSID'
[23:55:29][C][wifi_info:012]: WifiInfo BSSID 'BSSID'
[23:55:29][C][wifi_info:009]: WifiInfo IPAddress 'IP'
[23:55:29][C][wifi_signal.sensor:009]: WiFi Signal 'WiFi Signal'
[23:55:29][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[23:55:29][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[23:55:29][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[23:55:29][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0

I have almost turned the i-net upside down to get this working and finally, with these settings it works.

I didn’t know what to buy for this and I don’t know what the effect is in reality for being single core or multiple cores: it does the job so far.
I just wanted to be able to connect the NFC reader and as well have a BT receiver for a Shelly BLU button1

EDIT: this was the error regarding api

[E][bluetooth_proxy:439]: Only one API subscription is allowed at a time

Just pointing out what it says in the docs. Pleased it works for you.

Hard to find many references to that error. It is generated here

https://github.com/search?q=repo%3Aesphome%2Fesphome%20"Only%20one%20API%20subscription%20is%20allowed%20at%20a%20time"&type=code

So it’s easy to miss something when reading logs, but the log looks ok to me. Are you still having any problems?

1 Like

Please don’t misunderstand me: I appreciate it very much that you pointed that out!
To me, this ESP stuff is new and getting into to it is learning new things, concepts, …
Even though afterwards it all seems so simple, it took me fairly some time, to get this C3 to install/flash.

BT works but NFC does not.
As you can see from the log no i2c device is found…
Yes, I have no clue how to go from here.

I have the D1 for some time now and got NFC working.
At that time, I had no plans for using BT but then I bumped on the Shelly BLU button1 so I ordered it & the C3 for it’s BT capability.
Getting the BLU button into HA didn’t go smooth but finally works.
Now, I wanted to combine those 2 (NFC & BT) into the C3, as a challenge but also because I find it stupid to have 2 devices when it can be done by 1.

Should it be possible to have 2 functions (these or any other, given the controller supports it) in 1 device?
Your comment about being single core: I have no idea what the effect is in my case. Can you elaborate a little on that?

They should work together, but the c3 is a comparatively weak device, and Bluetooth proxy is quite resource intensive so maybe it is too much for it.

.

You have Bluetooth constantly scanning which makes it difficult for wifi to work as they use the same chip. What ancillary effects that will have, I don’t know. I strongly suggest you follow the docs, ie esp_32_tracker parameters should be left at the defaults.

If that doesn’t work, try disabling the Bluetooth stuff and see if the nfc works.

1 Like

You need to alternate ble and rest of the setup. Or use dual core board.
I use time based esp32_ble_tracker.start_scan and .stop_scan actions.
Also note:

2 Likes

Hi Karosm, that was the solution! :+1:

At first it seemed that it didn’t work but somehow, after a few days both methods work without a hiccup.
Even had some sudden, unexpected power cuts and yet, working fine.

Thanks a lot for your help! :bowing_man:

Nice to hear!

1 Like

Yeah, I wanted to give it some time to test to be sure before responding.

That’s the way to go.
I scan only 20secs every 15 min. Works for me but might not work in another setup.