question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about the connection of device

See original GitHub issue

Hi, i’m trying to use this library for my application. I follow the guide on your site (https://www.polidea.com/blog/ReactNative_and_Bluetooth_to_An_Other_level/ ) I managed to make the connection with the device but when I try to get the notification depending on the uuid I get this kind of error “ERROR: Service 0000F0F1-0000-1000-8000-00805F9B34FB for device ? not found” Now i don’t understand how to do with the the notification (the service number is right. ) Thank you.

This is the code:

export default class Main extends Component {
  constructor() {
    super();
    this.manager = new BleManager()
    this.state = {info: "", values: {}}
    this.prefixUUID = "0000F0F"
    this.suffixUUID = "-0000-1000-8000-00805F9B34FB"
    this.sensors = {
      1: "Accelerometer",
      2: "Humidity",
      3: "Magnetometer",
      4: "Barometer",
      5: "Gyroscope"
    }

    }

  serviceUUID(num) {
      return this.prefixUUID + num  + this.suffixUUID
    }

  notifyUUID(num) {
      return this.prefixUUID + num + this.suffixUUID
    }
writeUUID(num) {
      return this.prefixUUID + num + this.suffixUUID
    }

scanAndConnect(){
      this.manager.startDeviceScan(null, null, (error, device) => {
        if (error) {
            return
        }
        let model = '0030'; // this is an example
        if (device.name == this.model_dx(model)  ) {
          this.manager.stopDeviceScan();
          device.connect()
            .then((device) => {
              this.info("Discovering services and characteristics ")
              return device.discoverAllServicesAndCharacteristics()
            })
            .then((device) => {
              this.info("Setting notifications")
              return this.setupNotifications(device)

            })
            .catch((error) => {
              this.error(error.message)
            });
        }

      });
    }

async setupNotifications(device) {
    for (const id in this.sensors) {
      const service = this.serviceUUID(id)
      const characteristicW = this.writeUUID(id)
      const characteristicN = this.notifyUUID(id)

      const characteristic = await device.readCharacteristicForService(service, characteristicN)
      device.monitorCharacteristicForService(service, characteristicN, (error, characteristic) => {
        if (error) {
          this.error(error.message)
          return
        }
        this.updateValue(characteristic.uuid, characteristic.value)
      })
    }
  }
........
.......


    render() {
       return (
         <View>
           <Text>{this.state.info}</Text>
           {Object.keys(this.sensors).map((key) => {
          return <Text key={key}>
                   {this.sensors[key] + ": " + (this.state.values[this.notifyUUID(key)] || "-")}
                 </Text>
        })}
         </View>
       )
     }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:30

github_iconTop GitHub Comments

1reaction
dariuszseweryncommented, May 28, 2019

I guess I can close now

1reaction
dariuszseweryncommented, May 28, 2019

https://github.com/Polidea/react-native-ble-plx/wiki/Device-Connecting

It is possible to have a few connections established at the same time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 Questions to Ask Before Connecting Smart Devices
8 Questions to Ask Before Connecting Smart Devices · Does this device come with a default username and password? · Does this device...
Read more >
Top 5 Questions Our Customers Ask About Connected Devices
Top 5 Questions Our Customers Ask About Connected Devices · 1. How Fast Can I Get From Concept To Production? · 2. When...
Read more >
Eight questions you should be asking about the internet of things
How will the IoT change our daily lives, what impact will it have on sustainability and what shouldn't be connected?
Read more >
10 answer To Your Question About Networking - avianet.aero
How Does Network Work? Links and nodes are the fundamental building blocks of computer networking. A network node could be a data ...
Read more >
Network Components (Devices) | Networking Quiz - Quizizz
Q. A Network device has two ports. It splits one network to two networks to decrease the number of collisions or it connects...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found