Skip to content

Device or resource busy #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SeanMaday opened this issue Aug 21, 2017 · 3 comments
Closed

Device or resource busy #162

SeanMaday opened this issue Aug 21, 2017 · 3 comments
Labels

Comments

@SeanMaday
Copy link

SeanMaday commented Aug 21, 2017

I am trying to poll a Garmin Glo once per second from a Raspberry Pi 3 over Bluetooth and I am frequently getting a "Device or resource busy" error. My code is below. Is there a better way to architect this workflow?

#!/usr/bin/env python
# encoding: utf-8

import time
import json
import pynmea2
import bluetooth


def getLocation():
	bdAddr = "10:C6:FC:6B:13:A3"
	bdPort = 1
	sockObj = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
	sockObj.connect((bdAddr, bdPort))
	rawData = sockObj.recv(1024)
	sockObj.close()

	nmeaMsg = pynmea2.parse(rawData)

	outpuObj = {}
	outpuObj["rxLat"] = nmeaMsg.latitude
	outpuObj["rxLon"] = nmeaMsg.longitude
	outpuObj["rxStatus"] = nmeaMsg.status
	outpuObj["rxDatestamp"] = str(nmeaMsg.datestamp)
	outpuObj["rxTimestamp"] = str(nmeaMsg.timestamp)

	dataDir = "/home/pi"
	filePath = dataDir + "/" + "currentLocation.json"
	open(filePath, "wb").write(json.dumps(outpuObj))

	return outpuObj


def main():
        while True:
                try:
                        print getLocation()
                        time.sleep(1)

                except KeyboardInterrupt:
                        quit()

                except Exception,e:
                        print e
                        pass


if __name__ == "__main__":
	main()

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@FynnMazurkiewicz
Copy link

FynnMazurkiewicz commented Sep 1, 2017

The reason that you might be getting these are the quick successive calls to BluetoothSocket() and BluetoothSocket().close(). If the clean-up of the close-call takes longer than your 1 second sleep and the write(), your BluetoothDevice will still be blocked when you try to reopen the socket. Consider creating it and connecting once, leaving it open and only using recv in getLocation().

@rgov
Copy link
Collaborator

rgov commented Dec 20, 2017

Did that fix the issue for you, @SeanMaday ?

@stale
Copy link

stale bot commented Jul 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
PyBluez is not under active development, but we still accept pull requests!
If you've resolved your issue, please post your solution and close this issue. Future users will benefit from the knowledge you share. Thank you.

@stale stale bot added the wontfix label Jul 23, 2019
@stale stale bot closed this as completed Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants