esp32与android蓝牙,bluetooth - ESP32蓝牙。重定向串行输出 - SO中文参考 - www.soinside.com...

我很快找到了googling。或者,如果您想使用ESP32-idf。

[Arduino解决方案看起来像this:#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

void setup() {

SerialBT.begin("ESP32");

}

void loop() {

SerialBT.println("Hello World");

delay(1000);

}

ESP-IDF版本是bit more complex,但这是使用蓝牙api发送定期心跳的代码:#ifdef SUPPORT_HEARTBEAT

void spp_heart_beat_task(void * arg)

{

uint16_t cmd_id;

for(;;) {

vTaskDelay(50 / portTICK_PERIOD_MS);

if(xQueueReceive(cmd_heartbeat_queue, &cmd_id, portMAX_DELAY)) {

while(1){

if((is_connect == true) && (db != NULL) && ((db+SPP_IDX_SPP_HEARTBEAT_VAL)->properties & (ESP_GATT_CHAR_PROP_BIT_WRITE_NR | ESP_GATT_CHAR_PROP_BIT_WRITE))){

esp_ble_gattc_write_char( spp_gattc_if,

spp_conn_id,

(db+SPP_IDX_SPP_HEARTBEAT_VAL)->attribute_handle,

sizeof(heartbeat_s),

(uint8_t *)heartbeat_s,

ESP_GATT_WRITE_TYPE_RSP,

ESP_GATT_AUTH_REQ_NONE);

vTaskDelay(5000 / portTICK_PERIOD_MS);

}else{

ESP_LOGI(GATTC_TAG,"disconnect\n");

break;

}

}

}

}

}

#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值