【问题标题】:No error - sending data from phone app to hm-10 BLE module not working没有错误 - 从手机应用程序向 hm-10 BLE 模块发送数据不起作用
【发布时间】:2019-02-13 17:19:51
【问题描述】:

我创建了一个 react Native 应用程序,我正在使用 react-native-ble-manager 库。 https://www.npmjs.com/package/react-native-ble-manager

我正在使用带有 arduino nano 的 hm-10 BLE 模块,使用此代码 ->

#include <SoftwareSerial.h>
#define LED_PIN 13

SoftwareSerial mySerial(0, 1); // RX, TX  
// Connect HM10      Arduino Uno
//     Pin 1/TXD          Pin 7
//     Pin 2/RXD          Pin 8

void setup() {  
  Serial.begin(9600);
  // If the baudrate of the HM-10 module has been updated,
  // you may need to change 9600 by another value
  // Once you have found the correct baudrate,
  // you can update it using AT+BAUDx command 
  // e.g. AT+BAUD0 for 9600 bauds
  mySerial.begin(9600);
}

void loop() {  
  int c;
  int s;
  if (Serial.available()) {
    s = Serial.read();
    Serial.println("Got other input:");
    Serial.println(c);
  }
  if (mySerial.available()) {
    c = mySerial.read();  
    Serial.println("Got input:");
    Serial.println(c);
  }
}

http://acoptex.com/uploads/HM10ServicesandCharacteristics.pdf

通过阅读上面关于 HM-10 的文档,我正在连接到第三个服务。 在我的 react 应用程序中,我能够找到并保存与文档匹配的服务 uuid 和特征 uuid。

https://github.com/Polidea/react-native-ble-plx/wiki/Characteristic-Writing

从上面的文档中,在 react-native-ble-manager 文档中用于写入我在我的代码中使用此方法的设备

deviceObject.writeCharacteristicWithoutResponseForService(writeService, writeChar, encodedString);

我可以通过 arduino 串行监视器发送数据,代码会打印值,但是当我使用上述方法从手机应用程序发送数据时,串行监视器中不会打印任何值。

我不确定我哪里出错了。我已经让手机应用程序连接并发送数据到 arduino101 上的蓝牙模块,但是当使用 arduino nano 连接到 hm-10 并发送数据时,什么也没有发生。

【问题讨论】:

  • 更新:我使用了 MSMBLE 应用程序,我可以在串行监视器中输入字符并在应用程序上读取它们,但我无法将字符从应用程序发送到设备
  • 你为什么在硬件串行引脚上使用软件串行?
  • 我没有直接的答案,我看到的所有草图都使用了这个
  • 感谢您提到有关使用软件串行和硬件串行引脚的信息,我很遗憾您没有提出要更改的建议,但它让我朝着正确的方向前进,我A:在 arduino nano 上使用 D2 和 D3 以及 B:将 softwareSerial 对象的波特率设置为 57600,因为我发现了一些提到 arduino nano 所需的文档

标签: android react-native arduino bluetooth-lowenergy


【解决方案1】:

您可以查看我们的辅助项目,该项目使用相同的库向 Arduino 发送颜色并处理 LED 灯https://github.com/SparingSoftware/HomeLed 在 Arduino 方面,我们也使用串行端口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-19
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    相关资源
    最近更新 更多