Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:04:39+00:00 2026-05-25T17:04:39+00:00

I am currently trying to connect to a GPS Bluetooth device. My Python 2.7

  • 0

I am currently trying to connect to a GPS Bluetooth device. My Python 2.7 code worked correctly initially but I have now tried to implement my code into a while loop so that, whilst my device is not available, it will continue to keep on looping for it. Unfortunately, my code seems to be stuck in a loop and repeatedly prints out the error message “Unable to Locate Bluetooth GPS Device. Retrying…” I’m using the Bluetooth module from PyBluez.

Here’s my code:-

import bluetooth

target_address = "00:11:22:33:44:55:66"

discovered_devices = discover_devices()  # Object to discover devices from Bluetooth module

while True:
    print "Attempting to locate the correct Bluetooth GPS Device..."
    for address in discovered_devices:
        if address != target_address:
            print "Unable to Locate Bluetooth GPS Device. Retrying..."
        else:
            print "Bluetooth GPS Device Located: ", target_address
            break

# move on to next statement outside of loop (connection etc...)

As said, basically what I am looking to achieve is for the device discovery object to start and a message appear on console to indicate it is looking for a device transmitting the specified device address (ie “00:11:22:33:44:55:66”). Should no device have this address, I’d like the code to present an error message relating to being unable to locate device and then I’d like it to continue to keep on looking.

On a side, I would also ultimately like to edit this code so that, after attempting to locate the device for X amount of time / on a number of X occasions but to no avail, I’d like the code to end and the program to present an error message. Any guidance on that?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:04:39+00:00Added an answer on May 25, 2026 at 5:04 pm

    The line

    discovered_devices = discover_devices()
    

    should go inside your while loop, before entering the for loop.

    Then replace your while loop by a for loop to limit the number of attempts.

    And to properly exit the inner for loop, do as @Jeremy said: add

    else:
        continue
    break
    

    at the end of it.

    You may also want to wait between each attempt using sleep() at each iteration of your outer loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to connect to nominets whois service via fsockopen but I'm
I'm trying to connect to an Oracle DB which is currently offline. When it's
I am currently trying to connect to my Novell LDAP in SSL using C#
I've been trying my hand at OO PHP, and currently have three files. I
I'm currently trying to connect to a webservice placed on https://xxx.xxx.xx/myapp It has anonymous
I am currently trying to learn J2ME and build a connect four game (some
I am currently working on an Android app and I am trying to connect
I am currently trying to connect a C# program with a Sharepoint. What I
I've added my iOS app to iTunes Connect and is currently trying to upload
I currently have a school assignment that involves both PHP and asp.net. Now the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.