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.

Can't monitor device

See original GitHub issue

According 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:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
WQvistcommented, Feb 6, 2020

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.

1reaction
dariuszseweryncommented, Feb 5, 2020

I dunno. I want to check what is going on.

btw. you directly set the state this.state.connectedTo = device.id

Read more comments on GitHub >

github_iconTop 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 >

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