Question about the connection of device
See original GitHub issueHi, 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:
- Created 4 years ago
- Comments:30
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess I can close now
https://github.com/Polidea/react-native-ble-plx/wiki/Device-Connecting