My favorites | Sign in
Project Home Wiki Issues Source
Search
for
GettingStarted  
How to get a grip on the BTstack
Featured
Updated May 20 (6 days ago) by m...@ringwald.ch

Introduction

On this page, we provide a quick walk-through to run example/test.c on an iPhone 3G(S) or iPod touch 2G/3G and connect to a WiiMote, while displaying acceleration and button reports. See below for iPhone simulator usage.

Requirements

  • the autotools
  • a toolchain for the iPhone. This introduction assumes the use of the XCode iPhone SDK on Mac OS X.
  • the ldid code-signing tool, either on your host or on the iPhone (via Cydia). If you install it on the build system, the signing is done automatically. For a Mac PPC, please use the one from Fink as the original sources by Jay Freeman have endianess issues.
  • a subversion client
  • a jailbroken iPhone or iPod touch 2G or later.

Steps to compile and run a BTstack example on the iPhone

  1. Install the BTstack package in Cydia
  2. get the BTstack project from the Google code SVN:
  3. svn checkout http://btstack.googlecode.com/svn/trunk/ btstack
  4. cd into the btstack folder
  5. cd btstack
  6. run the bootstrap helper
  7. ./bootstrap.sh
  8. configure BTstack for the iPhone if you have SDK 2.0 installed, or...
  9. ./configure --target=iphone
  10. ... if you only have a higher SDK from a newer Xcode installed, e.g. SDK 3.2
  11. ./configure --target=iphone --with-sdk-version=3.2
  12. in example/test.c, find the line with the hard-coded value for the MAC address of the WiiMote and enter yours. Mine has the address 00:19:1d:90:44:68
  13. build it
  14. make
  15. copy the example test to your iPhone. Replace 192.168.3.102 with the IP address of your device
  16. scp example/test mobile@192.168.3.102:.
  17. ssh into your device
  18. ssh mobile@192.168.3.102
  19. sign the binaries on the device, if you did not install ldid on your build system
  20.  ldid -S test
  21. make sure Bluetooth is turned OFF in the Settings.app
  22. run the test
  23. ./test
  24. check the output in both sessions. If everything works, the app will prompt you to make your WiiMote discoverable by pressing the buttons 1 and 2 together. Shortly after that you should get continuous accelerometer readings. You can press the Home button to quit the test app.

Important: My WLAN often breaks down when using Bluetooth. When logged in via SSH this looks like the app would not work or hang, when in reality the WLAN is just not working properly. Check the WLAN icon in the status bar. After the introduction of Internet tethering, I highly recommend to connect the iPhone via USB and use this connection for SSH. When using USB Tethering, my machine receives the IP address 192.168.20.3, and the iPhone can be accessed at 192.168.20.1.

Details

In main, the BTstack is opened and packet handlers are registered before the BTstack is asked to boot with the btstack_set_power_mode command. All commands to control the BTstack are send asynchronously with the bt_send_cmd. Finally the run_loop is executed. From there on, the rest of the test app runs as a finite state machine which processes events received from the BTstack. Be aware that error handling is barely performed. :)

Anyway, the different steps of the program are visible in the event handler. First, it reacts to the successful startup of the BTstack and set the local Bluetooth name. Then, pairing is enabled/disabled with the hci_write_authentication_enable HCI command, which is caused by the command complete event of the hci_hci_write_local_name. Again, a command complete event will trigger the next action. Now, the BTstack is asked to open an L2CAP channel to the hard-coded WiiMote at PSM 0x13 (HID Interrupt) where reports from the HID device are received. Upon success, a second channel for PSM 0x11 (HID Control) is opened. This channel is necessary to enable the reporting of acceleration readings and send the command to set LEDs which also stops the LEDs from blinking. Finally, we're ready to receive HID status reports. See the HID and the WiiMote documentation for more details on this.

As this event handler shows, everything is event-triggered. After sending a command to the BTdaemon, which in turn sends it to the Bluetooth chipset, we wait for the corresponding event to continue with our application. Instead of writing this single even handler, it is much better to follow the concept of finite state machines. Based on our current state, an event such as HCI events, triggers the next action and the transition to another state. For more insight inton finite state machine, I highly recommend the book by Miro Samek.

Develop BTstack apps in the iPhone Simulator

To develop iPhone apps on the Mac, you need a serial Bluetooth module like the Ericsson ROK Tester connected over a USB-to-Serial adapter, as the HCI_USB_Transport does not work yet. With such a setup, you can configure BTstack for running on the Mac host, not the iPhone as described above. You also have to specify the UART device, see ./configure --help

For testing you run BTdaemon in one terminal before starting your app in the simulator. The app will then connect to the BTdaemon over the local UNIX domain socket.

References

Help

If you really want to try the example app on your iPhone, but didn't get it to work although you've followed the instructions here, or, if you'd like to use Bluetooth in your own application (whatever OS/HW), please join the BTstack Developer Forum.

Comment by project member matthias.ringwald@gmail.com, Nov 8, 2009

Cydia packages are out: iPhoneInstallationViaCydia

Comment by project member matthias.ringwald@gmail.com, Nov 19, 2009

BTstack is an alternative to Apple's on the iPhone. No support for the Headphone or the A2DP protocol yet. Even then, integrating it into the OS will be tricky.

Comment by MaxWagne...@gmail.com, Dec 5, 2009

I'm probably missing something incredibly stupid, but I can't get the WiiMote? example to compile. I've been planning to add WiiMote? support to an app I'm working on, but for that I first need to get the WiiMote? demo to work as I want it before adding this capability into my app. I've been able to build the non-CocoaTouch? version of BTstack, but as soon as I try to do something with XCode, it fails to recognize or find anything under the format of <btstack/someHeader.h>. It's probably just some stupid mistake I made, but could you offer your advice?

Comment by project member matthias.ringwald@gmail.com, Dec 5, 2009

if you'd like to use Bluetooth in your own application (whatever OS/HW), please join the BTstack Developer Forum. either install the headers in /usr/include or set the "header search path" in XCode to the btsack/include/ directory

Comment by fop...@gmail.com, Dec 7, 2009

I'm really hoping we can see a demo of RFCOMM working with those SE Bluetooth Watches soon! That'd rock!

Comment by project member matthias.ringwald@gmail.com, Dec 21, 2009
Comment by pmatteu...@gmail.com, Jan 24, 2010

Hi guys. I'm got a bicycle with an array of sensors and a bluetooth module. It would be great if I could get this sending serial info to an iPod Touch. I discovered that the Bluetooth module in the iPod/iPhone is severely locked up by apple. Is this the solution? Using the BTstack, can I talk to any bluetooth device? Thanks!

Comment by project member matthias.ringwald@gmail.com, Jan 28, 2010

yes, you can.

Comment by emanuele...@gmail.com, Jan 29, 2010

Hi guys, I'm interesting to implemet in my application bluetooth using BTstack,Where I can find an example on using it with Xcode? I try with example in BTstack project but don't work.Can someone say me where I can found it? or where I can found documentation on using BTstack?

Comment by gwenhael...@gmail.com, Jan 29, 2010

Hi, I wish to create a graphic appplication with bluetooth support but I don't see how to do this. run_loop_execute seem blocking the application. I use a linux box, consequently I'm not able to compiling xcodeproj app (like WiiMoteOpenGLDemo). How to use btstack for a graphic app with a linux box. Thank you very much

Comment by project member matthias.ringwald@gmail.com, Jan 29, 2010

hi guys. join the dev group. ... either you write your app in an event driven way, by this your app gets caled by the run loop, or you could use an extra pthread for BTstack and use its intet-thread communication for signaling/data delivery.

Comment by ahadje...@gmail.com, Jan 31, 2010

how to get a hyperterminal working on the iphone and use btstack

Comment by gaoguil...@gmail.com, Jan 31, 2010

Hi, I wish to create a printer appplication with bluetooth support but I don't see how to do this. How to use btstack?

Comment by gaoguil...@gmail.com, Jan 31, 2010

Line Location bt_control_iphone.m:42: error: ../config.h: No such file or directory Line Location daemon.c:41: error: ../config.h: No such file or directory Line Location daemon.c:103: warning: unused variable 'handle' Line Location hci.c:47: error: ../include/btstack/version.h: No such file or directory Line Location hci.c:514: error: 'BTSTACK_MAJOR' undeclared (first use in this function) Line Location hci.c:515: error: 'BTSTACK_MINOR' undeclared (first use in this function) Line Location hci.c:516: error: 'BTSTACK_REVISION' undeclared (first use in this function) Line Location platform_iphone.c:40: error: ../config.h: No such file or directory Line Location run_loop.c:44: error: ../config.h: No such file or directory Line Location socket_connection.c:45: error: ../config.h: No such file or directory

Comment by project member matthias.ringwald@gmail.com, Feb 1, 2010

gaoguilomg: please follow the instruction on this side to compile BTstack

Comment by project member matthias.ringwald@gmail.com, Feb 1, 2010

ahadjeres: can you explain what exactly you'd like to do?

Comment by gaoguil...@gmail.com, Feb 1, 2010

thank you ,I follow the instruction, but I want to develop in Xcode,how to start?

Comment by project member matthias.ringwald@gmail.com, Feb 1, 2010

gaoguilomg: please follow the instruction on this page to compile BTstack. and then try using Xcode. You will have to set the include and libs used correctly.

Comment by gaoguil...@gmail.com, Feb 2, 2010

Thank you

Comment by jalj...@gmail.com, Feb 2, 2010

How to run this application ..... ? what is libBTstack.dylib ?

Comment by project member matthias.ringwald@gmail.com, Feb 2, 2010

which app? libBTstack.dylib is the client library an app uses to access Bluetooth services, check out Architecture

Comment by nickbi...@gmail.com, Feb 2, 2010

I'm really new to this, please excuse me if my questions are so noobie :( In the requirements: - The autotools is already in Mac OS X leopard 10.5.5 right ? so i dont need to install it. if not, where to find it. - pkg-config: I dont know how to install it. You said about get it from MacPorts?, but I search on the site, can't find it anywhere :( Correct me if I'm wrong. What I understand is I need to compile the btstack to get the libBTstack.dylib and copy it to my usr/local/lib and then also copy all the file in the "include" fold (.h files) to my xcode project then I'm good to go ?

Comment by cao_...@yahoo.com, Feb 3, 2010

Ok, I got the them all compiled. Have btstack package installed from cydia. I copied the test file and the rfcomm to my iphone. But they didn't run, all I got was "Killed" in the console. Anyone know how to fix this ?

Comment by andi...@gmail.com, Feb 4, 2010

The guida miss one step ldid -S BTdaemon ldid -S test If you don't execute this , you just get "Killed" output.

Comment by project member matthias.ringwald@gmail.com, Feb 4, 2010

hi. thanks for helping out. if you configure for iPhone and build with the Makefiles, ldid is automatically called on the executables.

Comment by andi...@gmail.com, Feb 4, 2010

also , I need run the BTdaemon and test use root role.

Comment by nickbi...@gmail.com, Feb 5, 2010

Thanks, I got it running :)

Comment by jalee...@gmail.com, Feb 9, 2010

in the above tutorial i covered first 7 steps . but . 1) in step 8 can i using any bluetooth device, like nokia phone and so on. instead of WiiMote? , how i get ip address of a bluetooth phone, to connect with this. 2) when i build " make " by staying in btstack i am geting one error. ie make1?: execvp: ./get_version.sh: Permission denied make1?: [libBTstack.dylib] Error 127 make: [all-recursive] Error 1

how to rectify this error. ?

thanks and regards

Comment by project member matthias.ringwald@gmail.com, Feb 9, 2010

jaleelpp: you can use inquiry command installed by the BTstack Cydia package. It will report remote baseband addresses (similar to MACs) and remote names. For the permission error, try "chmod +x get_version.sh" to make it executable.

Comment by jalee...@gmail.com, Feb 14, 2010

Hi All,

when i execute inquiry in the mini mac os, i getting error such as

"init_serialport: Unable to open port : No such file or directory

/dev/ttyS0: No such file or directory " how could i rectify this one ?, what is the reason for this error?

Thanks and regards jaleel

Comment by project member matthias.ringwald@gmail.com, Feb 15, 2010

For non-iPhone/iPod, you need an external serial/h4 bluetooth module which can be accessed as a serial port like /dev/ttyS0 (ttyS0 being the default serial port on a linux system). I'm using the Rok Tester http://www.tik.ee.ethz.ch/~beutel/projects/bttester/bt_tester.html with an Keyspan USB-to-Serial adapter. Yes, one could also use an external BT dongle, or even the internal one, but the USB code is not working yet - feel free to look into that. :)

Comment by milo.xia...@gmail.com, Feb 22, 2010

after made the application as above step. I ran it at my ipod touch 3rd. but ./BTdaemon: Bad CPU type in executable throw. How to fix? or ./configure -target=ipod?

And I also used xcode on my macbook pro (build in bluetooth chipset) built successfully the application but cannot be put to iphone-simulator (no app appears in ..../Applications folder)? Any progress to configure?

Comment by project member matthias.ringwald@gmail.com, Feb 22, 2010

iPod is configure as iPhone described above. see the previous post (Feb 15) on using BTstack on Mac. The only app wiht Xcode is the example/WiiMote?... demo. Please join the BTstack Dev Group.

Comment by iwatth, Feb 28, 2010

Another way to develop with Xcode and simulator.

run BTdaemon on iPhone/iPod in TCP socket mode (need a little code update on daemon.c) develop an application on iPhone simulator and connect to BTdaemon on iPhone (update socket_connection.c to change host name and update bt_stack.c to use TCP socket)

Comment by israel.b...@gmail.com, Apr 5, 2010

A great job! Is there a way to create a bluetooth virtual serial port on the itouch? so you can acess it with mobile terminal or any other program.

I guess this is also what ahadjeres is asking for

Comment by project member matthias.ringwald@gmail.com, Apr 21, 2010

hi (and sorry for answering late). A real virtual port requires a kernel extensions which is not possible on the iPhone AFAIK. An app could create an ptty which is similar, but you would need that app running. Usually you want to build an app on top of it and it that case you could just use libBTstack. Another idea: add example/rfcomm.c to MobileTerminal? - there is a SDK version that can be compiled in Xcode.

Comment by marco.ro...@gmail.com, May 4, 2010

Hi everybody, i just jailbroke my iphone with a 3.0 firmware and i am trying to run the example again. when i try to run: apt-get it says command not found.. , can anyone tell me the source to add to cydia to get apt-get command? Also, can someone tell me the source to get "ldid" and "BTstack daemon" on cydia?

i really appreciate that, thanks

Comment by project member matthias.ringwald@gmail.com, May 4, 2010

BTstack and ldid are regular packages in Cydia (hosted by BigBoss?)

Comment by adithya....@gmail.com, May 30, 2010

When i run ./BTdaemon, I get the following error ...

Socket created at /tmp/BTstack Error on bind() ...(Address already in use) BTdaemon started - stdout BTdaemon started - stderr

Furthermore, If i attempt running the apps test or rfcomm, these apps are killed rightaway. Help!

Comment by project member matthias.ringwald@gmail.com, May 30, 2010

@adithya If you installed BTstack via Cydia, BTdaemon is automatically started by launchd whenever an app tries to use it. so, just don't start it. If a test app gets killed right away, you didn't code sign them with the ldid tool. It is done automatically on the mac if you have ldid installed, you can also sign them on the device with ldid from the ldid package.

Comment by antonio....@gmail.com, May 30, 2010

Will PS3 controllers be supported?

Comment by project member matthias.ringwald@gmail.com, May 31, 2010

@antonio BTstack can already communicate with PS3, but one has to make an app that makes use of it too. I'm on it... :)

Comment by Lucleonh...@gmail.com, Jul 6, 2010

Is there any New Progress for communicating with the PS3? :)

Comment by project member matthias.ringwald@gmail.com, Jul 6, 2010

@lucleonhart no. no new progress. If nobody does, I'll do something with it in winter :)

Comment by skavih...@gmail.com, Aug 4, 2010

After completing the above steps and test run, the XCode compiler get the error: 'Btstack/hci_cmds.h: No such file or directory' in the BTInquiryViewController. I could see the file if it exists!. Can you tell me whats happening? please

Comment by project member matthias.ringwald@gmail.com, Aug 5, 2010

the CFLAGS and LDFLAGS are hard-coded, as I have no clue how use relative paths. please update them accordingly

Comment by klinena...@gmail.com, Oct 13, 2010

In my sourcecode for test.c it has the wiimote mac address commented out and an ipad mac uncommented. I have an ipad, is that code for connecting my phone to my ipad?

Comment by oa...@aol.com, Oct 17, 2010

im new to the jb scene but i have a question. will this make it to where i could use a bluetooth earpiece that i can connect to my phone, but connect it to my ipod to listen to music. i do not need to use the mic just simply for listening to music. im not sure what software i can use but i have a second generation ipod touch mc model running ios4 jailbroken. any help is much appreciated

Comment by iphoneap...@gmail.com, Nov 26, 2010

Hello,

How can we send HCI commands with btstack ?

Thanks in advance for your help,

Comment by jlr1...@gmail.com, Nov 26, 2010

Hello, Will you be updating BTStack GPS for io 4.2.1? Thanks, great product!!

Comment by project member matthias.ringwald@gmail.com, Nov 26, 2010

Please update BTstack package. Besides other bugs/details it forces an update of other components that caused crashes on 4.2.1. Everything's fine.

Comment by la@arlduc.org, Jan 5, 2011

Hi, it took me a while to figure out my WiiMote? MAC Address. Now that I've figured it out, I thought a "how-to" would help:

- Download and install DarwiinRemote? http://sourceforge.net/projects/darwiin-remote/ - Use DarwiinRemote? to connect the WiiMote? to your computer. - On a Macintosh, you can get the WiiMote? MAC address by opening System Preferences > Bluetooth Preferences, selecting the connected WiiMote? (it will be listed as "Nintendo RVL-CNT-01"), and showing more info for this device.

Comment by tz2...@gmail.com, Jan 26, 2011

I tried compiling on Linux. I don't see the libusb code/version in the svn above - or is it somewhere else in the tree or not in the repo?

Comment by frenke...@gmail.com, Jan 27, 2011

Can't build it (step 8) - I get libBTstack.dylib error 1. Please your help

Comment by project member matthias.ringwald@gmail.com, Jan 27, 2011

@tz2...: BTstack uses libusb 1.0. The USB driver was dormant for long as I thought it's broken/not working. However, over the holidays I tried again on Mac and as far as I could tell, it was fully working. So maybe libusb did fix some bugs, I did run into before.

Comment by tz2...@gmail.com, Jan 29, 2011

linux on the mac, or mac osx on the mac using a usb bluetooth dongle?

Comment by project member matthias.ringwald@gmail.com, Jan 29, 2011

I tried BTstack with libusb-1.0 from GIT on Mac OS X. Note: I did remove the IOBluetoothFamily.kext to get access to the internal USB Bluetooth module.

Comment by Terence...@gmail.com, Mar 8, 2011

I used BTStack on my iPhone, my wifi often breaks down when using Bluetooth. Did you have methods to fix this bug. (Note: I must use wifi to connect to my server.)

Comment by project member matthias.ringwald@gmail.com, Mar 9, 2011

@Terence: what app are you using with BTstack? The more you use Bluetooth, the less stable WiFi? gets, that's a physical problem. Doing inquires for extended amounts of time kills Wifi with high probability, sending much data, like with the Mouse app, seems to degrade Wifi performance.

Comment by Terence...@gmail.com, Mar 10, 2011
@matthias.ringwald: I used the BTStackCocoa project in the source, and I installed the btstack in my iPad3.2 and iPhone 3G from Cydia.

I ran the BTStackCocoa on iPhone 3G, wifi will break down after 1 minute; iPad 3.2 had different performances, the longest time is 4 minutes.

Comment by stefan...@hotmail.com, Mar 30, 2011

Hi, i did everything on the getting started tutorial(, but i used another iphone as wiimote) but i cant get it to work. when i want to run the test it says this :

fannes-boombox:~ mobile$ ./test -sh: ./test: No such file or directory

this didnt work so i used :

fannes-boombox:~ mobile$ sh test.c test.c: line 1: /Applications: is a directory test.c: line 2: syntax error near unexpected token `(' test.c: line 2: ` Copyright (C) 2009 by Matthias Ringwald' fannes-boombox:~ mobile$

and this sais i get an error.

can anyone help me please ?

Comment by project member matthias.ringwald@gmail.com, Mar 30, 2011

@Terence: prolonged inquiries make the Wifi break down, as both use the same spectrum. Same happens when you go Settings->General->Bluetooth and wait there for a few minutes.

Comment by si...@ultra-realistic.com, May 12, 2011

It would be great if we can make BTstack work with touchscreen. So that we can play iPhone on a big touchscreen. ,I'm making a bluetooth device for a 42 inch touchscreen will code for BTstack to deal with the touchscreen data later.

would be nice to chat with you guys>>mail me : Sifer@ultra-realistic.com

Comment by project member matthias.ringwald@gmail.com, Jun 4, 2011

@sifer: customGatz just release something like that, see http://www.customgadz.com/

Comment by ninjamas...@gmail.com, Dec 29, 2011

none of this makes since. how to i download this my iphone says it needs to be reinstalled btstack but i cant find it any where i am not a programer so i do not know what any of this means. so speak english.

Comment by Lv.j...@gmail.com, Dec 29, 2011

hello. is there a way to know bluetooth address of others' devices?

Powered by Google Project Hosting