Can't monitor device
See original GitHub issueAccording to the docs, I’ve done the following:
- Scanned for devices
- Connected to device
- device.discoverAllServicesAndCharacteristics
- writeCharacteristicWithResponseForDevice
My problem lies in reading the response I get from sending my command.
RX characteristic is writable, but TX is only notifiable and not readable. Therefore I need to monitor the characteristic with monitorCharacteristicForDevice, however I can’t get this to function.
I never recieve neither “Monitor success” nor “monitorDevice called” in the code below. If I run the checkBattery() function after connection it returns “Not monitoring”.
How do I read the return?
monitorDevice = () => {
console.log("monitorDevice called")
this.manager.monitorCharacteristicForDevice(this.state.connectedTo, SERVICE_UUID, TX_CHARACTERISTIC, (error, characteristic) => {
if (error) {
console.error("Error at receiving data from device", error);
return
}
else{
this.setState({monitoring:true})
console.log("Monitor success")
console.log("Monitor success " + characteristic.value);
this.state.messagesRecieved.push(characteristic.value)
return
}
})
}
connectAndFetchServicesAndCharacteristics = (device) => {
this.manager.connectToDevice(device.id, null)
.then(device => {
this.setState({connectedTo:device.id})
console.log('Connection successful\nScan stopped')
this.manager.stopDeviceScan();
this.setState({scan: false})
return device.discoverAllServicesAndCharacteristics()
})
.then(device => {
this.setState({servicesDiscovered: true})
console.log("Services discovered")
this.monitorDevice()
return
})
.catch(err => {
console.log(err)
})
}
checkBattery = () => {
if(this.state.monitoring){
this.manager.writeCharacteristicWithResponseForDevice(this.state.connectedTo,
SERVICE_UUID,
RX_CHARACTERISTIC,
"YmF0dGVyeQ==")
.then(characteristic => {
console.log("Successfully sent: " + characteristic.value)
return
})
.catch(err => {
console.log(err)
})
}
else{
alert("Not monitoring")
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
Question / Help - Audio Monitoring doesn't work at all
General rule for the audio monitoring device is that you cannot use any device that is also captured by OBS. You would create...
Read more >Troubleshoot external monitor connections in Windows 10
Before considering troubleshooting options, make sure your device is up to date. Select Start > Settings > Update & Security > Windows Update...
Read more >Fix Can't monitor or hear audio when when playing through OBS
Can't Hear Audio with Video Source Can't monitor (hear) audio when playing through OBS.
Read more >Troubleshooting steps if a device is not being added or the ...
Delete the newly discovered Agentless Server monitor. Go to Admin > Inventory > Add Monitor > Network Device. Once the Network Discovery page...
Read more >Solved: Windows 10 Not Detecting Second Monitor
It is possible that the reason your device cannot detect the second monitor relates to a recently updated device driver. In some cases,...
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
Progress! Hooking the peripheral up to a serial monitor I can see that the received string is basically gibberish. “battery” is received as “m畫mz�”. Some type of encoding problem
Edit: Solved it by using base-64 library instead of sending a string that was already base64 encoded.
I dunno. I want to check what is going on.
btw. you directly set the state
this.state.connectedTo = device.id