如何解决接收由本机应用程序发送的数据
一个具有反应本机的应用程序和带有ble模块mlt-bt05的arduino nano。我尝试使用react-native-ble-plx库从应用程序向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 = "";
}
}
}
我尝试使用BLE终端应用程序通过IOS发送带有此arduino代码的数据,并且在端口监视器中我看到消息,但我的本地应用程序没有显示消息。
存在来自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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。