Skip to content

DiscoverConnect.ino displays the incorrect value for COD (Class of Device). #8684

Closed
@esp32beans

Description

@esp32beans

Board

ESP32 devkit

Device Description

ESP32 devkit board plugged in via USB to PC. No other hardware plugged into the board.

Hardware Configuration

No connections to GPIO pins.

Version

v2.0.13

IDE Name

Arduino IDE 1.8.19

Operating System

Ubuntu 22.04

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

Logging shows the correct value ESP_BT_GAP_DEV_PROP_COD 0x40680 but the sketch shows cod: 26380. Note 0x40680 = 263808 (base 10) so the incorrect value is the decimal value with the least significant digit chopped off.

[  7020][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x40680
[  7027][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 189
[  7034][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : BlueTooth Printer : 17
>>>>>>>>>>>Found a new device asynchronously: Name: BlueTooth Printer, Address: 66:12:56:03:28:18, cod: 26380, rssi: -67

The COD is a 24 bit value so "val[6]" is too small. It would be better to display COD in hex like the log message.

char val[6+1];  // +1 for NUL terminator
snprintf(val, sizeof(val), "%06x", getCOD() & 0xFFFFFF);
res += ", cod: 0x";

Fixing BTAdvertisedDeviceSet::toString() will also make other examples show the correct COD.

Sketch

https://github.com/espressif/arduino-esp32/blob/master/libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino

Debug Message

[  7020][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x40680
[  7027][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 189
[  7034][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : BlueTooth Printer : 17
>>>>>>>>>>>Found a new device asynchronously: Name: BlueTooth Printer, Address: 66:12:56:03:28:18, cod: 26380, rssi: -67

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions