Receive data sent by the react-native application ble

597 Views Asked by At

a have react-native app and arduino nano with ble module mlt-bt05. I trying send info from app to arduino with react-native-ble-plx lbrary, but serial monitor displays nothing.

Here is my react-native code

const msg = base64.encode(message);

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

And arduino code

#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 = "";
    }
  }
}

I was trying use BLE Terminal app for IOS for sending data with this arduino code and in the port monitor i see messages but no from my react-native app.

There is console.log of response from writeCharacteristicWithResponseForService

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
0

There are 0 best solutions below