Skip to content

Commit 9d0d643

Browse files
committed
v3.0.7.0 - breaking change: hard coded to Arduino esp32 v3.0.7
1 parent e19d654 commit 9d0d643

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# SparkFun Apple Accessory Arduino Library
22

3-
An Arduino Library for Apple Accessories using iAP2 connections - precompiled for ESP32
3+
An Arduino Library for Apple Accessories using iAP2 connections - precompiled for Arduino esp32 v3.0.7 (IDF 5.1)
44

55
This library supports communication with Apple Accessories using the iAP2 protocol, as defined in the Accessory Interface Specification (Release R44). Unfortunately, the Interface Specification is only available under NDA. This library is precompiled for the ESP32 to protect the source code.
66

7-
iAP2 is supported over several transports, including Bluetooth, UART and USB. The [ESP32_BluetoothSerial](./examples/ESP32_BluetoothSerial/ESP32_BluetoothSerial.ino) example demonstrates how to communicate with an Accessory using ESP32 BluetoothSerial as the transport. The example depends on a modified version of BluetoothSerial which makes ACL more accessible. It also depends on a modified version of libbt.a which has been compiled with SPP enabled.
7+
iAP2 is supported over several transports, including Bluetooth, UART and USB. The [ESP32_BluetoothSerial](./examples/ESP32_BluetoothSerial/ESP32_BluetoothSerial.ino) example demonstrates how to communicate with an Accessory using ESP32 BluetoothSerial as the transport. The example depends on a modified version of BluetoothSerial which makes ACL more accessible. It also depends on a modified version of libbt.a which has been compiled with BLUEDROID, L2CAP and SDP enabled.
88

99
## Repository Contents
1010

examples/ESP32_BluetoothSerial/ESP32_BluetoothSerial.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
5050
(SPP is disabled in the standard libbt.a)
5151
52-
Tried and tested on: Arduino esp32 v3.1.3 (IDF 5.3) and v3.2.0 (IDF 5.4)
52+
Tried and tested on: Arduino esp32 v3.0.7 (IDF 5.1)
5353
5454
*/
5555

@@ -161,12 +161,12 @@ void setup()
161161

162162
esp_sdp_init();
163163

164-
esp_bluetooth_sdp_raw_record_t record = {(esp_bluetooth_sdp_types_t)0};
165-
record.hdr.type = ESP_SDP_TYPE_RAW;
166-
record.hdr.uuid.len = sizeof(UUID_IAP2);
167-
memcpy(record.hdr.uuid.uuid.uuid128, UUID_IAP2, sizeof(UUID_IAP2));
168-
record.hdr.service_name_length = strlen(sdp_service_name) + 1;
169-
record.hdr.service_name = (char *)sdp_service_name;
164+
esp_bluetooth_sdp_hdr_overlay_t record = {(esp_bluetooth_sdp_types_t)0};
165+
record.type = ESP_SDP_TYPE_RAW;
166+
record.uuid.len = sizeof(UUID_IAP2);
167+
memcpy(record.uuid.uuid.uuid128, UUID_IAP2, sizeof(UUID_IAP2));
168+
record.service_name_length = strlen(sdp_service_name) + 1;
169+
record.service_name = (char *)sdp_service_name;
170170
esp_sdp_create_record((esp_bluetooth_sdp_record_t *)&record);
171171

172172
// ==============================================================================================================
148 KB
Binary file not shown.

examples/ESP32_BluetoothSerial/src/BluetoothSerial/BluetoothSerial.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ static esp_bd_addr_t _peer_bd_addr;
7373
static char _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
7474
static bool _isRemoteAddressSet;
7575
static bool _isMaster;
76+
#ifdef CONFIG_BT_SSP_ENABLED
7677
static bool _enableSSP;
7778
static bool _IO_CAP_INPUT;
7879
static bool _IO_CAP_OUTPUT;
80+
#endif
7981
esp_bt_pin_code_t _pin_code = {0};
8082
uint8_t _pin_code_len = 0; // Number of valid Bytes in the esp_bt_pin_code_t array
8183
static esp_spp_sec_t _sec_mask;
@@ -654,7 +656,8 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
654656
esp_bt_gap_pin_reply(param->pin_req.bda, true, _pin_code_len, _pin_code);
655657
}
656658
break;
657-
case ESP_BT_GAP_CFM_REQ_EVT: // Enum 6 - Security Simple Pairing User Confirmation request.
659+
#ifdef CONFIG_BT_SSP_ENABLED
660+
case ESP_BT_GAP_CFM_REQ_EVT: // Enum 6 - Security Simple Pairing User Confirmation request.
658661
log_i("ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", param->cfm_req.num_val);
659662
if (confirm_request_callback)
660663
{
@@ -669,10 +672,11 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
669672
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
670673
}
671674
break;
672-
675+
#endif
673676
case ESP_BT_GAP_KEY_NOTIF_EVT: // Enum 7 - Security Simple Pairing Passkey Notification
674677
log_i("ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
675678
break;
679+
#ifdef CONFIG_BT_SSP_ENABLED
676680
case ESP_BT_GAP_KEY_REQ_EVT: // Enum 8 - Security Simple Pairing Passkey request
677681
log_i("ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
678682
if (key_request_callback)
@@ -686,7 +690,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
686690
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, false);
687691
}
688692
break;
689-
693+
#endif
690694
case ESP_BT_GAP_READ_RSSI_DELTA_EVT: // Enum 9 - Read rssi event
691695
log_i("ESP_BT_GAP_READ_RSSI_DELTA_EVT Read rssi event");
692696
break;
@@ -741,9 +745,11 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
741745
param->acl_disconn_cmpl_stat.reason, param->acl_disconn_cmpl_stat.handle);
742746
break;
743747

748+
#if false
744749
case ESP_BT_GAP_ENC_CHG_EVT: // Enum 21
745750
log_i("ESP_BT_GAP_ENC_CHG_EVT");
746751
break;
752+
#endif
747753

748754
default:
749755
log_i("ESP-BT_GAP_* unknown message: %d", event);
@@ -824,7 +830,8 @@ static bool _init_bt(const char *deviceName, bt_mode mode)
824830
esp_bluedroid_status_t bt_state = esp_bluedroid_get_status();
825831
if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED)
826832
{
827-
833+
//#ifdef CONFIG_BT_SSP_ENABLED
834+
#if false
828835
// Start with SSP
829836
esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT();
830837
if (_enableSSP == false)
@@ -835,6 +842,13 @@ static bool _init_bt(const char *deviceName, bt_mode mode)
835842
log_e("initialize bluedroid failed");
836843
return false;
837844
}
845+
#else
846+
if (esp_bluedroid_init())
847+
{
848+
log_e("initialize bluedroid failed");
849+
return false;
850+
}
851+
#endif
838852
}
839853

840854
if (bt_state != ESP_BLUEDROID_STATUS_ENABLED)
@@ -867,8 +881,10 @@ static bool _init_bt(const char *deviceName, bt_mode mode)
867881
}
868882

869883
log_i("device name set");
870-
esp_bt_gap_set_device_name(deviceName);
884+
esp_bt_dev_set_device_name(deviceName);
885+
//esp_bt_gap_set_device_name(deviceName);
871886

887+
#ifdef CONFIG_BT_SSP_ENABLED
872888
if (_enableSSP)
873889
{
874890
log_i("Simple Secure Pairing");
@@ -892,6 +908,7 @@ static bool _init_bt(const char *deviceName, bt_mode mode)
892908
}
893909
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
894910
}
911+
#endif
895912

896913
_aclConnected = false;
897914

@@ -1104,6 +1121,7 @@ void BluetoothSerial::memrelease()
11041121
esp_bt_mem_release(ESP_BT_MODE_BTDM);
11051122
}
11061123

1124+
#ifdef CONFIG_BT_SSP_ENABLED
11071125
void BluetoothSerial::onConfirmRequest(ConfirmRequestCb cb)
11081126
{
11091127
confirm_request_callback = cb;
@@ -1118,6 +1136,7 @@ void BluetoothSerial::respondPasskey(uint32_t passkey)
11181136
{
11191137
esp_bt_gap_ssp_passkey_reply(current_bd_addr, true, passkey);
11201138
}
1139+
#endif
11211140

11221141
void BluetoothSerial::onAuthComplete(AuthCompleteCb cb)
11231142
{
@@ -1135,6 +1154,7 @@ esp_err_t BluetoothSerial::register_callback(esp_spp_cb_t callback)
11351154
return ESP_OK;
11361155
}
11371156

1157+
#ifdef CONFIG_BT_SSP_ENABLED
11381158
// Enable Simple Secure Pairing (using generated PIN)
11391159
// This must be called before calling begin, otherwise has no effect!
11401160
void BluetoothSerial::enableSSP()
@@ -1179,6 +1199,8 @@ void BluetoothSerial::disableSSP()
11791199
_enableSSP = false;
11801200
}
11811201

1202+
#else
1203+
11821204
bool BluetoothSerial::setPin(const char *pin, uint8_t pin_code_len)
11831205
{
11841206
if (pin_code_len == 0 || pin_code_len > 16)
@@ -1190,6 +1212,7 @@ bool BluetoothSerial::setPin(const char *pin, uint8_t pin_code_len)
11901212
memcpy(_pin_code, pin, pin_code_len);
11911213
return (esp_bt_gap_set_pin(ESP_BT_PIN_TYPE_FIXED, _pin_code_len, _pin_code) == ESP_OK);
11921214
}
1215+
#endif
11931216

11941217
bool BluetoothSerial::connect(String remoteName)
11951218
{

examples/ESP32_BluetoothSerial/src/BluetoothSerial/BluetoothSerial.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ class BluetoothSerial : public Stream {
5656
void onData(BluetoothSerialDataCb cb);
5757
esp_err_t register_callback(esp_spp_cb_t callback);
5858

59+
#ifdef CONFIG_BT_SSP_ENABLED
5960
void onConfirmRequest(ConfirmRequestCb cb);
6061
void onKeyRequest(KeyRequestCb cb);
6162
void respondPasskey(uint32_t passkey);
63+
#endif
6264
void onAuthComplete(AuthCompleteCb cb);
6365
void confirmReply(boolean confirm);
6466

67+
#ifdef CONFIG_BT_SSP_ENABLED
6568
void enableSSP();
6669
void enableSSP(bool inputCapability, bool outputCapability);
6770
void disableSSP();
71+
#else
6872
bool setPin(const char *pin, uint8_t pin_code_len);
73+
#endif
6974
bool connect(String remoteName);
7075
bool connect(
7176
uint8_t remoteAddress[], int channel = 0, esp_spp_sec_t sec_mask = (ESP_SPP_SEC_ENCRYPT | ESP_SPP_SEC_AUTHENTICATE),

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Apple Accessory Arduino Library
2-
version=1.0.2
2+
version=3.0.7.0
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=An Arduino library for SparkFun Apple Accessories
Binary file not shown.

0 commit comments

Comments
 (0)