Is a Bluetooth PAN possible?

Discussion in 'iOS Programming' started by Michael.Hill, Sep 2, 2011.

  1. Michael.Hill macrumors newbie

    Joined:
    Jul 22, 2011
    #1
    Before I start writing an iPhone/iPad app, I want to know if it's even possible first. First off, I'm writing the app to be used in-house (not on app store). The problem is that wi-fi is not allowed, but bluetooth is allowed to be used. I want to have a MacBook Pro be a "Master" bluetooth server and have 6 iPads or iPhones to be "slaves". The "slaves" need to send data to the "master" to be put into a database. I'm just wanting to know if this kind of connection is possible. I'm having issues connecting my iPhone to my MacBook Pro through a Bluetooth PAN (which I think is the way I want to do it). My initial idea is to create a Bluetooth PAN. I'll know the IP address of the master, so I think I should be able to just send data to that IP address. I know bluetooth connections with other iPhones/iPads are possible with the Game Kit...but I didn't know if Apple crippled the ability to connect to a laptop to prevent unauthorized tethering.
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    The connection is possible. Look into Bonjour for the discovery process. Perhaps this overview is a good place to start. I can't recall if Gamekit is limited to communicating with iOS devices only.
     
  3. Michael.Hill thread starter macrumors newbie

    Joined:
    Jul 22, 2011
    #3
    Thanks for getting me in the right direction.

    Looking at this: http://forums.macrumors.com/showthread.php?t=1098868&highlight=bluetooth

    It looks like I might need to jailbreak whatever devices this goes on to install a better bluetooth stack, which is unfortunate. I really wanted others within my organization to put this on their own devices. I guess I can say what I want the app to do. There's an organization called FIRST Robotics, where high school students and mentors build a robot to compete with each other. An important part of developing strategy is to "scout" what other robots can do. I had an idea to create an iPad/iPhone app so students can use either their own iPhones or team-owned iPads to do this scouting. The problem is that the robots communicate on 802.11 frequencies, and FIRST has banned wifi networks (802.11a/b/g/n) at the events. 802.15, the group in which Bluetooth is defined, IS allowed. Unfortunately, communicating with cell towers is unreliable at the events because many areas are underground (and paying for data on six team-owned iPads would be very expensive).
     
  4. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #4
    Sounds like you want to exchange basic information between the Mac to the iOS devices. Easy. No need to jailbreak and switch out the BT stack on the iOS devices.

    I experimented with a game that exchanged images and game information. First I wrote it for iOS, I then ported it to my Mac. It worked fine. The game unfortunately hasn't been completed. ;(
     
  5. Michael.Hill thread starter macrumors newbie

    Joined:
    Jul 22, 2011
    #5
    Great, so did you use GameKit for that or just Bonjour?
     
  6. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #6
    I used Bonjour for the discovery, and the networking layers to connect and exchange information. I'd have to look at the code for more detail since it's been a while.

    At least one of the Stanford iPhone programming series has some basics on networking. Apple of course has some sample along the same lines. If you have a ADC membership, there are WDC videos that discuss networking in some detail. Also I know of a couple of books that discuss this topic well, but I'd have to look them up.
     
  7. Michael.Hill thread starter macrumors newbie

    Joined:
    Jul 22, 2011
    #7
    I don't have an ADC membership yet (I don't want to start paying until I deploy to non-JB phones/iPads). I do have the Stanford videos. Thanks for your help.
     
  8. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #8
    :eek: Looks like I have messed up. It's looking like iOS can't communicate via BT with the Mac. I'm going to look at this further during the weekend. I'm now upset with my self and curious.

    Instead of making your server a Mac, you could consider using another iOS device as your server/master. That does work. Of course, you may have a reason to make it a Mac.

    If you don't have an ADC license, I'm unsure how you can test unless you use the jailbreak method to get an app on your device. I'm not familiar with that.

    Bonjour does discovery over both wifi and bluetooth. I have two iPod touches and before testing over BT, I originally had wifi ON, on both which allowed the connection. This allows for faster testing. I then turned wifi OFF and the connection was made over BT instead. I find BT slower to both discover and transfer data. I've also read that you have to be more careful transfer large blocks of data over BT.

    Where my memory was wrong, is in my Mac side testing. I was testing via the iPhone simulator and that can only be done via wifi. I looked at my OS X specific code, and discovered I didn't implement the wireless communication yet. D'oh! :eek:
     
  9. Michael.Hill thread starter macrumors newbie

    Joined:
    Jul 22, 2011
    #9
    I probably could theoretically use an iPad or iPhone as the "Master", but to be honest, it's because I personally only own a MacBook Pro and a jailbroken iPhone (that answers how I test on my phone). I don't have a way of testing with an iOS master and iOS slave. I would also really like to host it on a Mac because frankly, it's a lot easier to interface with a database directly on a laptop. I'd really like an iPad, but I can't afford one right now (I'm waiting to start a new job on the 12th, so maybe after that...)
     
  10. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #10
    Effectively, you do. You can have code running in the simulator and the device at the same time and communicating via wifi. The simulator does not allow Bluetooth use. Later when you have another (students?) device to test with, just turn off wifi on one of the two and things should work as expected over BT. I just tested this successfully with my two iPod touches.

    I find the setup time of compiling to a device is much longer than to the simulator. What I did was compile to my device, then compile to my simulator. Code iteration would be done on the simulator until it was too far out of sync with the device at which time I'd compile to the device to update it.

    Debugging networking code can be a challenge. I had a lot of NSLog statements to understand where execution was and who's data I was displaying.


    I appreciate that. The keyboard alone is a lot easier than a small iPod touch screen. Kids are adept with mobile keyboards, so that might no matter.

    For the database, I'd expect you to use Core Data or SQLite directly, which run on both platforms. What has been your thoughts on that?
     
  11. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #11
    Found the Stanford lecture I was thinking about. It is lecture 17 from the Winter 2010 class.

    The course content has changed from one season to the next, so check them all out.
     

Share This Page