如何使用Arduino IDE在ESP32上读取/连接BLE信标?

时间:2019-10-29 10:46:12

标签: iot arduino-ide esp32

我希望将ESP32连接到与Arduino配对的JDY-08,以用于某些智能传感器应用程序。我想读取在iBeacon模式下设置的JDY-08发送的整数。我尝试了ESP32库附带的示例,该库在ESP32_BLE_Arduino中名为BLE_CLient。代码可以找到我正在使用的设备,即与Arduino UNO结合使用的JDY-08。我用我的nRF应用程序检查服务和char UUID。谁能告诉我出什么问题了?

JDY-08代码:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup(){
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop(){
  float temperature = 0.0;
  int sample;
  float ten_samples = 0.0;

  for (sample = 0; sample < 10; sample++) {
      temperature = ((float)analogRead(A0) * 5.0 / 1024.0) - 0.5;
      temperature = temperature / 0.01;
      delay(100);
      ten_samples = ten_samples + temperature;
  }

  temperature = ten_samples / 10.0;
  int temperature_translate = (int)temperature;
  mySerial.print(temperature_translate);
  Serial.print(temperature_translate);
  ten_samples = 0.0;

  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

1 个答案:

答案 0 :(得分:0)

使用WEB蓝牙API进行一些检查,使用它可以接收从ESP32发送的数据通知。

因此,首先看一下您是否可以使用此Web界面接收来自ESP32的数据: https://googlechrome.github.io/samples/web-bluetooth/notifications.html

确保正确设置了UUID,我发现对于像JDY-08这样的设备,短的UUID标识为0x35655可能还不够,您需要获取它们的长版本,它们看起来更像是0000180a-0000- 1000-8000-00805f9b34fb,这也可能与ESP32 UUID一起发生,因此请使用以下工具进行检查:

https://googlechrome.github.io/samples/web-bluetooth/

在简历中:

  • 使用WEB蓝牙API获取信息并连接到设备

  • 仔细检查服务和特征的UUID

如果此方法有效,但仍无法通过JDY-08接收:

  • 检查TX和RX位置,它们可能会反转

问题不在发布的代码上。