1

a 具有带有 ble 模块 mlt-bt05 的 react-native 应用程序和 arduino nano。我尝试使用 react-native-ble-plx lbrary 将信息从应用程序发送到 arduino,但串行监视器什么也没显示。

这是我的反应原生代码

const msg = base64.encode(message);

let messageResponse = await connectedDevice.writeCharacteristicWithResponseForService(
  serviceUUID,
  uuid,
  msg,
);

和arduino代码

#include <SoftwareSerial.h>

SoftwareSerial ble_device(3,4);

String str_ii = "";
int ii_0 = 0;

void setup() {  
  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);

  ble_device.begin(9600);

  delay(100);
}

void loop() {
  while (ble_device.available()){
    char in_char = ble_device.read();

    if (int(in_char)!=-1 and int(in_char)!=42 and in_char != '\n'){
      str_ii+=in_char;
    }

    if (in_char=='\n'){
      delay(20);
      String msg = "Msg: ";
      msg+=str_ii;
      ble_device.print(msg);

      Serial.println(str_ii);

      if (str_ii == "on") {
        digitalWrite(LED_BUILTIN, HIGH);
      } else if (str_ii == "off") {
        digitalWrite(LED_BUILTIN, LOW);
      }
      str_ii = "";
    }
  }
}

我正在尝试使用 IOS 的 BLE 终端应用程序使用此 arduino 代码发送数据,在端口监视器中我看到消息,但没有来自我的 react-native 应用程序。

有来自 writeCharacteristicWithResponseForService 的响应的 console.log

id: 10758153120
uuid: "0000ffe1-0000-1000-8000-00805f9b34fb"
isNotifiable: true
isNotifying: false
isReadable: true
isWritableWithResponse: true
serviceID: 10773274432
value: null
isIndicatable: false
serviceUUID: "0000ffe0-0000-1000-8000-00805f9b34fb"
deviceID: "975EDC28-F6FC-562E-B837-445F2DB6865C"
isWritableWithoutResponse: true
4

0 回答 0