Skip to content

Commit 89e9178

Browse files
authored
Merge branch 'espressif:master' into patch-3
2 parents 3cfeb3b + adfaaec commit 89e9178

29 files changed

+661
-135
lines changed

.github/scripts/install-platformio-esp32.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespressif32"
4-
PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master"
4+
PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git"
55

66
TOOLCHAIN_VERSION="8.4.0+2021r2-patch3"
77
ESPTOOLPY_VERSION="~1.30100.0"

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
if: |
1616
github.event.workflow_run.event == 'pull_request' &&
1717
(github.event.workflow_run.conclusion == 'success' ||
18-
(github.event.workflow_run.conclusion == 'failure')
18+
github.event.workflow_run.conclusion == 'failure')
1919
steps:
2020
- name: Download and Extract Artifacts
2121
env:

boards.txt

+110
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ esp32s3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
184184
esp32s3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
185185
esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
186186
esp32s3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
187+
esp32s3.menu.PartitionScheme.rainmaker=RainMaker
188+
esp32s3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker
189+
esp32s3.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728
187190

188191
esp32s3.menu.CPUFreq.240=240MHz (WiFi)
189192
esp32s3.menu.CPUFreq.240.build.f_cpu=240000000L
@@ -304,6 +307,9 @@ esp32c3.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
304307
esp32c3.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
305308
esp32c3.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
306309
esp32c3.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
310+
esp32c3.menu.PartitionScheme.rainmaker=RainMaker
311+
esp32c3.menu.PartitionScheme.rainmaker.build.partitions=rainmaker
312+
esp32c3.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728
307313

308314
esp32c3.menu.CPUFreq.160=160MHz (WiFi)
309315
esp32c3.menu.CPUFreq.160.build.f_cpu=160000000L
@@ -475,6 +481,9 @@ esp32s2.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
475481
esp32s2.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9MB FATFS)
476482
esp32s2.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
477483
esp32s2.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
484+
esp32s2.menu.PartitionScheme.rainmaker=RainMaker
485+
esp32s2.menu.PartitionScheme.rainmaker.build.partitions=rainmaker
486+
esp32s2.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728
478487

479488
esp32s2.menu.CPUFreq.240=240MHz (WiFi)
480489
esp32s2.menu.CPUFreq.240.build.f_cpu=240000000L
@@ -14258,3 +14267,104 @@ deneyapkart1A.menu.DebugLevel.verbose=Verbose
1425814267
deneyapkart1A.menu.DebugLevel.verbose.build.code_debug=5
1425914268

1426014269
##############################################################
14270+
14271+
AirM2M_CORE_ESP32C3.name=AirM2M_CORE_ESP32C3
14272+
AirM2M_CORE_ESP32C3.vid.0=0x303a
14273+
AirM2M_CORE_ESP32C3.pid.0=0x1001
14274+
14275+
AirM2M_CORE_ESP32C3.upload.tool=esptool_py
14276+
AirM2M_CORE_ESP32C3.upload.maximum_size=1310720
14277+
AirM2M_CORE_ESP32C3.upload.maximum_data_size=327680
14278+
AirM2M_CORE_ESP32C3.upload.flags=
14279+
AirM2M_CORE_ESP32C3.upload.extra_flags=
14280+
AirM2M_CORE_ESP32C3.upload.use_1200bps_touch=false
14281+
AirM2M_CORE_ESP32C3.upload.wait_for_upload_port=false
14282+
14283+
AirM2M_CORE_ESP32C3.serial.disableDTR=false
14284+
AirM2M_CORE_ESP32C3.serial.disableRTS=false
14285+
14286+
AirM2M_CORE_ESP32C3.build.tarch=riscv32
14287+
AirM2M_CORE_ESP32C3.build.target=esp
14288+
AirM2M_CORE_ESP32C3.build.mcu=esp32c3
14289+
AirM2M_CORE_ESP32C3.build.core=esp32
14290+
AirM2M_CORE_ESP32C3.build.variant=AirM2M_CORE_ESP32C3
14291+
AirM2M_CORE_ESP32C3.build.board=AirM2M_CORE_ESP32C3
14292+
AirM2M_CORE_ESP32C3.build.bootloader_addr=0x0
14293+
14294+
AirM2M_CORE_ESP32C3.build.cdc_on_boot=0
14295+
AirM2M_CORE_ESP32C3.build.f_cpu=160000000L
14296+
AirM2M_CORE_ESP32C3.build.flash_size=4MB
14297+
AirM2M_CORE_ESP32C3.build.flash_freq=80m
14298+
AirM2M_CORE_ESP32C3.build.flash_mode=dio
14299+
AirM2M_CORE_ESP32C3.build.boot=dio
14300+
AirM2M_CORE_ESP32C3.build.partitions=default
14301+
AirM2M_CORE_ESP32C3.build.defines=
14302+
14303+
AirM2M_CORE_ESP32C3.menu.CDCOnBoot.default=Disabled
14304+
AirM2M_CORE_ESP32C3.menu.CDCOnBoot.default.build.cdc_on_boot=0
14305+
AirM2M_CORE_ESP32C3.menu.CDCOnBoot.cdc=Enabled
14306+
AirM2M_CORE_ESP32C3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1
14307+
14308+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
14309+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.default.build.partitions=default
14310+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
14311+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
14312+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.default_8MB=8M Flash (3MB APP/1.5MB FAT)
14313+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
14314+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336
14315+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.minimal=Minimal (1.3MB APP/700KB SPIFFS)
14316+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.minimal.build.partitions=minimal
14317+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.no_ota=No OTA (2MB APP/2MB SPIFFS)
14318+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.no_ota.build.partitions=no_ota
14319+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
14320+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3g=No OTA (1MB APP/3MB SPIFFS)
14321+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3g.build.partitions=noota_3g
14322+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3g.upload.maximum_size=1048576
14323+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_ffat=No OTA (2MB APP/2MB FATFS)
14324+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_ffat.build.partitions=noota_ffat
14325+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_ffat.upload.maximum_size=2097152
14326+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3gffat=No OTA (1MB APP/3MB FATFS)
14327+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3gffat.build.partitions=noota_3gffat
14328+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.noota_3gffat.upload.maximum_size=1048576
14329+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
14330+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.huge_app.build.partitions=huge_app
14331+
AirM2M_CORE_ESP32C3.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
14332+
14333+
AirM2M_CORE_ESP32C3.menu.CPUFreq.160=160MHz (WiFi)
14334+
AirM2M_CORE_ESP32C3.menu.CPUFreq.160.build.f_cpu=160000000L
14335+
AirM2M_CORE_ESP32C3.menu.CPUFreq.80=80MHz (WiFi)
14336+
AirM2M_CORE_ESP32C3.menu.CPUFreq.80.build.f_cpu=80000000L
14337+
AirM2M_CORE_ESP32C3.menu.CPUFreq.40=40MHz
14338+
AirM2M_CORE_ESP32C3.menu.CPUFreq.40.build.f_cpu=40000000L
14339+
AirM2M_CORE_ESP32C3.menu.CPUFreq.20=20MHz
14340+
AirM2M_CORE_ESP32C3.menu.CPUFreq.20.build.f_cpu=20000000L
14341+
AirM2M_CORE_ESP32C3.menu.CPUFreq.10=10MHz
14342+
AirM2M_CORE_ESP32C3.menu.CPUFreq.10.build.f_cpu=10000000L
14343+
14344+
AirM2M_CORE_ESP32C3.menu.FlashFreq.80=80MHz
14345+
AirM2M_CORE_ESP32C3.menu.FlashFreq.80.build.flash_freq=80m
14346+
AirM2M_CORE_ESP32C3.menu.FlashFreq.40=40MHz
14347+
AirM2M_CORE_ESP32C3.menu.FlashFreq.40.build.flash_freq=40m
14348+
14349+
AirM2M_CORE_ESP32C3.menu.UploadSpeed.921600=921600
14350+
AirM2M_CORE_ESP32C3.menu.UploadSpeed.921600.upload.speed=921600
14351+
AirM2M_CORE_ESP32C3.menu.UploadSpeed.115200=115200
14352+
AirM2M_CORE_ESP32C3.menu.UploadSpeed.115200.upload.speed=115200
14353+
AirM2M_CORE_ESP32C3.menu.UploadSpeed.1152000=1152000
14354+
AirM2M_CORE_ESP32C3.menu.UploadSpeed.1152000.upload.speed=1152000
14355+
14356+
14357+
AirM2M_CORE_ESP32C3.menu.DebugLevel.none=None
14358+
AirM2M_CORE_ESP32C3.menu.DebugLevel.none.build.code_debug=0
14359+
AirM2M_CORE_ESP32C3.menu.DebugLevel.error=Error
14360+
AirM2M_CORE_ESP32C3.menu.DebugLevel.error.build.code_debug=1
14361+
AirM2M_CORE_ESP32C3.menu.DebugLevel.warn=Warn
14362+
AirM2M_CORE_ESP32C3.menu.DebugLevel.warn.build.code_debug=2
14363+
AirM2M_CORE_ESP32C3.menu.DebugLevel.info=Info
14364+
AirM2M_CORE_ESP32C3.menu.DebugLevel.info.build.code_debug=3
14365+
AirM2M_CORE_ESP32C3.menu.DebugLevel.debug=Debug
14366+
AirM2M_CORE_ESP32C3.menu.DebugLevel.debug.build.code_debug=4
14367+
AirM2M_CORE_ESP32C3.menu.DebugLevel.verbose=Verbose
14368+
AirM2M_CORE_ESP32C3.menu.DebugLevel.verbose.build.code_debug=5
14369+
14370+
#############################################################

cores/esp32/esp32-hal-i2c.c

+2
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
317317
hal.dev = I2C_LL_GET_HW(i2c_num);
318318
i2c_hal_set_bus_timing(&(hal), frequency, src_clk);
319319
bus[i2c_num].frequency = frequency;
320+
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2
321+
i2c_set_timeout((i2c_port_t)i2c_num, I2C_LL_MAX_TIMEOUT);
320322
}
321323

322324
end:

cores/esp32/esp32-hal-log.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ void log_print_buf(const uint8_t *b, size_t len);
206206
#undef ESP_EARLY_LOGD
207207
#undef ESP_EARLY_LOGV
208208

209-
#define ESP_LOGE(tag, ...) log_e(__VA_ARGS__)
210-
#define ESP_LOGW(tag, ...) log_w(__VA_ARGS__)
211-
#define ESP_LOGI(tag, ...) log_i(__VA_ARGS__)
212-
#define ESP_LOGD(tag, ...) log_d(__VA_ARGS__)
213-
#define ESP_LOGV(tag, ...) log_v(__VA_ARGS__)
214-
#define ESP_EARLY_LOGE(tag, ...) isr_log_e(__VA_ARGS__)
215-
#define ESP_EARLY_LOGW(tag, ...) isr_log_w(__VA_ARGS__)
216-
#define ESP_EARLY_LOGI(tag, ...) isr_log_i(__VA_ARGS__)
217-
#define ESP_EARLY_LOGD(tag, ...) isr_log_d(__VA_ARGS__)
218-
#define ESP_EARLY_LOGV(tag, ...) isr_log_v(__VA_ARGS__)
209+
#define ESP_LOGE(tag, format, ...) log_e("[%s] " format, tag, ##__VA_ARGS__)
210+
#define ESP_LOGW(tag, format, ...) log_w("[%s] " format, tag, ##__VA_ARGS__)
211+
#define ESP_LOGI(tag, format, ...) log_i("[%s] " format, tag, ##__VA_ARGS__)
212+
#define ESP_LOGD(tag, format, ...) log_d("[%s] " format, tag, ##__VA_ARGS__)
213+
#define ESP_LOGV(tag, format, ...) log_v("[%s] " format, tag, ##__VA_ARGS__)
214+
#define ESP_EARLY_LOGE(tag, format, ...) isr_log_e("[%s] " format, tag, ##__VA_ARGS__)
215+
#define ESP_EARLY_LOGW(tag, format, ...) isr_log_w("[%s] " format, tag, ##__VA_ARGS__)
216+
#define ESP_EARLY_LOGI(tag, format, ...) isr_log_i("[%s] " format, tag, ##__VA_ARGS__)
217+
#define ESP_EARLY_LOGD(tag, format, ...) isr_log_d("[%s] " format, tag, ##__VA_ARGS__)
218+
#define ESP_EARLY_LOGV(tag, format, ...) isr_log_v("[%s] " format, tag, ##__VA_ARGS__)
219219
#endif
220220
#endif
221221

cores/esp32/esp32-hal-touch.c

+34-17
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ static void __touchInit()
119119
if (err != ESP_OK) {
120120
goto err;
121121
}
122-
// Initial no Threshold and setup
123-
for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) {
124-
__touchInterruptHandlers[i].fn = NULL;
125-
touch_pad_config(i, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK
126-
}
127122
// keep ISR activated - it can run all together (ISR + touchRead())
128123
err = touch_pad_isr_register(__touchISR, NULL);
129124
if (err != ESP_OK) {
@@ -148,18 +143,7 @@ static void __touchInit()
148143
// Touch Sensor Timer initiated
149144
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); // returns ESP_OK
150145
touch_pad_fsm_start(); // returns ESP_OK
151-
152-
// Initial no Threshold and setup - TOUCH0 is internal denoise channel
153-
for (int i = 1; i < SOC_TOUCH_SENSOR_NUM; i++) {
154-
__touchInterruptHandlers[i].fn = NULL;
155-
touch_pad_config(i); // returns ESP_OK
156-
}
157-
// keep ISR activated - it can run all together (ISR + touchRead())
158-
err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE);
159-
if (err != ESP_OK) {
160-
goto err;
161-
}
162-
touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK
146+
//ISR setup moved to __touchChannelInit
163147
#endif
164148

165149
initialized = true;
@@ -170,13 +154,43 @@ static void __touchInit()
170154
return;
171155
}
172156

157+
static void __touchChannelInit(int pad)
158+
{
159+
static bool channels_initialized[SOC_TOUCH_SENSOR_NUM] = { false };
160+
if(channels_initialized[pad]){
161+
return;
162+
}
163+
164+
#if SOC_TOUCH_VERSION_1 // ESP32
165+
// Initial no Threshold and setup
166+
__touchInterruptHandlers[pad].fn = NULL;
167+
touch_pad_config(pad, SOC_TOUCH_PAD_THRESHOLD_MAX); // returns ESP_OK
168+
#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3
169+
// Initial no Threshold and setup
170+
__touchInterruptHandlers[pad].fn = NULL;
171+
touch_pad_config(pad); // returns ESP_OK
172+
// keep ISR activated - it can run all together (ISR + touchRead())
173+
esp_err_t err = touch_pad_isr_register(__touchISR, NULL, TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE);
174+
if (err != ESP_OK) {
175+
log_e(" Touch sensor initialization error.");
176+
return;
177+
}
178+
touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); // returns ESP_OK
179+
#endif
180+
181+
channels_initialized[pad] = true;
182+
delay(20); //delay needed before reading from touch channel after config
183+
}
184+
173185
static touch_value_t __touchRead(uint8_t pin)
174186
{
175187
int8_t pad = digitalPinToTouchChannel(pin);
176188
if(pad < 0){
177189
return 0;
178190
}
191+
179192
__touchInit();
193+
__touchChannelInit(pad);
180194

181195
touch_value_t touch_value;
182196
touch_pad_read_raw_data(pad, &touch_value);
@@ -198,6 +212,9 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
198212
} else {
199213
// attach ISR User Call
200214
__touchInit();
215+
#if SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3
216+
__touchChannelInit(pad);
217+
#endif
201218
__touchInterruptHandlers[pad].fn = userFunc;
202219
__touchInterruptHandlers[pad].callWithArgs = callWithArgs;
203220
__touchInterruptHandlers[pad].arg = Args;

libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32c3

Whitespace-only changes.

libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32s2

Whitespace-only changes.

libraries/BluetoothSerial/examples/DiscoverConnect/.skip.esp32s3

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* Bluetooth Classic Example
3+
* Scan for devices - asyncronously, print device as soon as found
4+
* query devices for SPP - SDP profile
5+
* connect to first device offering a SPP connection
6+
*
7+
* Example python server:
8+
* source: https://gist.github.com/ukBaz/217875c83c2535d22a16ba38fc8f2a91
9+
*
10+
* Tested with Raspberry Pi onboard Wifi/BT, USB BT 4.0 dongles, USB BT 1.1 dongles,
11+
* 202202: does NOT work with USB BT 2.0 dongles when esp32 aduino lib is compiled with SSP support!
12+
* see https://github.com/espressif/esp-idf/issues/8394
13+
*
14+
* use ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE in connect() if remote side requests 'RequireAuthentication': dbus.Boolean(True),
15+
* use ESP_SPP_SEC_NONE or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE in connect() if remote side has Authentication: False
16+
*/
17+
18+
#include <map>
19+
#include <BluetoothSerial.h>
20+
21+
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
22+
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
23+
#endif
24+
25+
#if !defined(CONFIG_BT_SPP_ENABLED)
26+
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
27+
#endif
28+
29+
BluetoothSerial SerialBT;
30+
31+
32+
#define BT_DISCOVER_TIME 10000
33+
esp_spp_sec_t sec_mask=ESP_SPP_SEC_NONE; // or ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE to request pincode confirmation
34+
esp_spp_role_t role=ESP_SPP_ROLE_SLAVE; // or ESP_SPP_ROLE_MASTER
35+
36+
// std::map<BTAddress, BTAdvertisedDeviceSet> btDeviceList;
37+
38+
void setup() {
39+
Serial.begin(115200);
40+
if(! SerialBT.begin("ESP32test", true) ) {
41+
Serial.println("========== serialBT failed!");
42+
abort();
43+
}
44+
// SerialBT.setPin("1234"); // doesn't seem to change anything
45+
// SerialBT.enableSSP(); // doesn't seem to change anything
46+
47+
48+
Serial.println("Starting discoverAsync...");
49+
BTScanResults* btDeviceList = SerialBT.getScanResults(); // maybe accessing from different threads!
50+
if (SerialBT.discoverAsync([](BTAdvertisedDevice* pDevice) {
51+
// BTAdvertisedDeviceSet*set = reinterpret_cast<BTAdvertisedDeviceSet*>(pDevice);
52+
// btDeviceList[pDevice->getAddress()] = * set;
53+
Serial.printf(">>>>>>>>>>>Found a new device asynchronously: %s\n", pDevice->toString().c_str());
54+
} )
55+
) {
56+
delay(BT_DISCOVER_TIME);
57+
Serial.print("Stopping discoverAsync... ");
58+
SerialBT.discoverAsyncStop();
59+
Serial.println("discoverAsync stopped");
60+
delay(5000);
61+
if(btDeviceList->getCount() > 0) {
62+
BTAddress addr;
63+
int channel=0;
64+
Serial.println("Found devices:");
65+
for (int i=0; i < btDeviceList->getCount(); i++) {
66+
BTAdvertisedDevice *device=btDeviceList->getDevice(i);
67+
Serial.printf(" ----- %s %s %d\n", device->getAddress().toString().c_str(), device->getName().c_str(), device->getRSSI());
68+
std::map<int,std::string> channels=SerialBT.getChannels(device->getAddress());
69+
Serial.printf("scanned for services, found %d\n", channels.size());
70+
for(auto const &entry : channels) {
71+
Serial.printf(" channel %d (%s)\n", entry.first, entry.second.c_str());
72+
}
73+
if(channels.size() > 0) {
74+
addr = device->getAddress();
75+
channel=channels.begin()->first;
76+
}
77+
}
78+
if(addr) {
79+
Serial.printf("connecting to %s - %d\n", addr.toString().c_str(), channel);
80+
SerialBT.connect(addr, channel, sec_mask, role);
81+
}
82+
} else {
83+
Serial.println("Didn't find any devices");
84+
}
85+
} else {
86+
Serial.println("Error on discoverAsync f.e. not workin after a \"connect\"");
87+
}
88+
}
89+
90+
91+
String sendData="Hi from esp32!\n";
92+
93+
void loop() {
94+
if(! SerialBT.isClosed() && SerialBT.connected()) {
95+
if( SerialBT.write((const uint8_t*) sendData.c_str(),sendData.length()) != sendData.length()) {
96+
Serial.println("tx: error");
97+
} else {
98+
Serial.printf("tx: %s",sendData.c_str());
99+
}
100+
if(SerialBT.available()) {
101+
Serial.print("rx: ");
102+
while(SerialBT.available()) {
103+
int c=SerialBT.read();
104+
if(c >= 0) {
105+
Serial.print((char) c);
106+
}
107+
}
108+
Serial.println();
109+
}
110+
} else {
111+
Serial.println("not connected");
112+
}
113+
delay(1000);
114+
}

0 commit comments

Comments
 (0)