We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Bluetooth library for processing
Pages: 1 2 3 4
Bluetooth library for processing (Read 25572 times)
Bluetooth library for processing
Nov 15th, 2007, 2:43am
 
hi,

I needed bluetooth support in processing recently, but couldn't find any working libraries.

So I ported Mobile Processing Bluetooth library to Proce55ing. I'm now looking for beta testers.

You can download the library here:
http://www.extrapixel.ch/processing/bluetoothDesktop/


Docs are still incomplete, but you should get it working with the included example sketch. Also read the howto.txt included in the download.

Would be great if Windows (works!)/Linux users could test it with one of the available free JSR-82 implementations (see howto.txt).
I only tested it on MacOS X with the (not free) Avetana JSR-82 implementation. (14-day trial version available here: http://www.avetana-gmbh.de/avetana-gmbh/produkte/jsr82.eng.xml )
Re: Bluetooth library for processing
Reply #1 - Nov 16th, 2007, 8:48am
 
hi extrapixel
when i try to connect to a service
it trow this error
java.lang.RuntimeException: java.lang.Exception: Connection could not be created with remote device!

Re: Bluetooth library for processing
Reply #2 - Nov 16th, 2007, 3:36pm
 
oops, i get the same error. I have not tried this kind of connection, only the other way around. I'll have a look into it.
A mobile phone (or whatever) can connect to a service you create with bluetoothDesktop though.

What operating system and jsr-82 implementation are you using?

Re: Bluetooth library for processing
Reply #3 - Nov 16th, 2007, 6:22pm
 
i am on a macbookpro with avetana
i try to connect the processing using a standard java bluetooth conection like this:
try
         {
Connection connection = Connector.open("btspp://001CD4453AA4:5;authenticate=false;master=false;encrypt=f
alse");
......
and i have 3 of 4 times the same error
perhaps the problem is on the processing applet
Re: Bluetooth library for processing
Reply #4 - Nov 16th, 2007, 6:22pm
 
i am on a macbookpro with avetana
i try to connect the processing using a standard java bluetooth conection like this:
try
         {
Connection connection = Connector.open("btspp://001CD4453AA4:5;authenticate=false;master=false;encrypt=f
alse");
......
and i have 3 of 4 times the same error
perhaps the problem is on the processing applet
Re: Bluetooth library for processing
Reply #5 - Nov 17th, 2007, 5:43am
 
on what side are you getting the errors? Processing? Who's hosting the service?

The error you get typically happens when you try to connect to the same service more than once (like hitting that key twice Wink)

I posted an example of a simple client/server app here:
http://www.extrapixel.ch/processing/bluetoothDesktop/examples.html
It's a server for mobile phones (Mobile Processing) and a client for Processing.
Re: Bluetooth library for processing
Reply #6 - Nov 20th, 2007, 3:17pm
 
I tested bluetoothDesktop on Windows using the bluecove implementation today. Works like a charm. So, bluetoothDesktop works with Windows (all free) and and OS X (14-days trial, EUR 25.- *). Linux support remains untestet...

* Bluecove also announced that there will be OS X support in their next release, scheduled Christmas 2007. So soon we're gonna have an opensource JSR-82 implementation for Mac, Windows and Linux.

For more info see
http://www.extrapixel.ch/processing/bluetoothDesktop/installation.html
Re: Bluetooth library for processing
Reply #7 - Nov 21st, 2007, 4:13pm
 
Hi,

Just wanted to thank you for the good work. By the way, I tested the library in Ubuntu 7.0.4 with the 25EUR version of Avetana (Linux experienced people could compile the free version because the binaries distributed with previous bluetooth libraries seem to be deprecated, as well as the precompiled distributions in CVS: http://avetanabt.cvs.sourceforge.net/avetanabt/avetanabt/). It works! Both examples run without problems, with just a strange inability to retrieve the device's name, so it prints connected to device 'null'...nonetheless the devices are recognized and the services are listed...there's also communication with the mobile server.

I have a further question: Is it possible to transfer text? like sms to a desktop application? Is there any example around?

Best...
Re: Bluetooth library for processing
Reply #8 - Nov 21st, 2007, 4:47pm
 
Hi,

great, thanks for you report! so it's basically workin on all 3 platforms. Strange thing with the device name though. So, with the simpleBluetooth example, what names are null? the ones of the found devices (left coloumn) or the names of the connected clients (right coloumn)?

Text exchange can easily be done using the writeUTF("text") and the readUTF() methods. But I think you can't access the message-inbox of the phone (or I just don't know how). However, there is the Messaging Library in Mobile Processing, which let's you get incoming sms messages while the sketch is running. Have a look here:
http://mobile.processing.org/reference/libraries/messaging/index.php
Re: Bluetooth library for processing
Reply #9 - Nov 21st, 2007, 6:19pm
 
Hi,

Just the Device appears as null. The Services are ok. Thanx for the tip, I just need to send strings from client to server so I guess it's pretty straight forward. Nonetheless I've never worked with mobile P5 and I'm having trouble to transform the client code to mobile version. Mind to offer a small introductory help perhaps? This is the code, when I try to make the midlet it throws a compiler error...but cannot guess what's wrong:

import processing.bluetooth.*;




PFont font;
Bluetooth bt;
String msg = "inactive";
Client server;
final String SERVICE_NAME = "simpleService";

void setup() {
 font = loadFont();
 textFont(font);
 try {
   bt = new Bluetooth(this, Bluetooth.UUID_RFCOMM); // RFCOMM
   bt.find();
   msg = "searching...";
 }
 catch (RuntimeException e) {
   msg = "error. is your bluetooth on?";
   //println(e);
 }

}
void destroy() {
 bt.stop();
}

void draw() {
 background(0);
 fill(255);
 text(msg, 3, 10);
}

void libraryEvent(Object library, int event, Object data) {
 if (library == bt) {
   if (event == Bluetooth.EVENT_DISCOVER_SERVICE_COMPLETED) {
     Service[] services = (Service[])data;

     msg = "Search completed.";

     // now search for the service we want
     for (int i=0; i<services.length; i++) {
       //println(services[i].name);
       if (services[i].name.equals(SERVICE_NAME)) {
         msg = "Service " + SERVICE_NAME + " found";

         try {
           // we found our service, so try to connect to it
           // if we try to connect to it more than once, this will throw an error.
           server = services[i].connect();
           msg = "Connected to service " + SERVICE_NAME + " on server " + server.device.name;
           return;
         }
         catch (Exception e) {
           msg = "Found service " + SERVICE_NAME + " on Server " + server.device.name + ", but connection failed";
           //println(e);
           return;
         }
       }
     }

    // msg = "Service " + SERVICE_NAME + " not found.";
   }
 }
}
Re: Bluetooth library for processing
Reply #10 - Nov 21st, 2007, 8:54pm
 
hi,

the compilation error most probably comes from not having the mobile sdk installed, or not referencing it right under Preferences-> mobile. http://mobile.processing.org/download/index.php explains how to do it in Win/OS X, but I don't know if it works at all under Linux.

Your code compiles on my machine. But there might be a problem with this line:
  bt = new Bluetooth(this, Bluetooth.UUID_RFCOMM); // RFCOMM
unless you have the patched mobile bluetooth library from here http://todbot.com/blog/2006/09/12/roombactrl-drive-your-roomba-with-your-cell-phone/ installed, it won't work. But you can also just use
  bt = new Bluetooth(this);
it will then communicate over the standard serial protocol. No problem, 'cause if you're using RFCOMM on the computer side, it will find the devices broadcasting over the serial protocol.
Re: Bluetooth library for processing
Reply #11 - Nov 24th, 2007, 2:20pm
 
Hi Extrapixel...I'm back on the bluetooth business. Sorry to bother again but...It doesn't seem to work yet! The code is compiling now and runs in my phone, the server is also running on Processing0132 on MacOX, but the client doesn't find any services. Is it a port problem? or it lies   somewhere in the code? This is the updated server code (the client code remains the same, only with the problematic line changed to 'new Bluetooth(this;)'):
------------------------------------------------------------
import bluetoothDesktop.*;




final String SERVICE_NAME = "simpleService";
Bluetooth bt;
String[] clients = new String[0];
PFont font;
String msg;  // status message
String FONT = "Univers-30.vlw";

void setup() {
 size (400, 400);
 //// set up font
 font = loadFont(FONT);
 textFont(font,12);

 // initialize Bluetooth library
 bt = new Bluetooth(this, Bluetooth.UUID_RFCOMM); // RFCOMM

 // start service
 bt.start(SERVICE_NAME);

 msg = "no client connected";
}

void destroy() {
 bt.stop();
}

void draw() {
 background(255);

 fill(0);
 text(msg, 3,height/2);

 // draw connected clients
 for (int i=0; i<clients.length; i++) {
   text(clients[i], 6, height/2+(i+1)*17);
 }
}

// gets called by BT if something happens
void clientConnectEvent(Client client) {

 clients = (String[]) append(clients, client.device.name);
 msg = clients.length + " Clients connected:";

}
-----------------------------------------------------------
Sometimes I also get a message when running the  server...something about not matching ports, but right now is not showing...any idea?

Hope you got some minutes to check it...I'll keep on trying, Thanks
Re: Bluetooth library for processing
Reply #12 - Nov 24th, 2007, 5:31pm
 
I really need to straighten out this UUID-thing in the documentation.

Simply use the (Mobile Processing-)default UUID on OS X by creating the bluetooth object like this in P5:
bt = new Bluetooth(this);

OR

Keep the RFCOMM on OS X but change your bt-line in Mobile Processing like this:
bt = new Bluetooth(this, 0x0003);


0x0003 stands for RFCOMM. In bluetoothDesktop, I added some constants for the commonly used channels.
Basically, use the same channel (UUID) on both computer & phone, and it should just work. For example, put them to the default channel by creating both bluetooth objects like so:
bt = new Bluetooth(this);
Re: Bluetooth library for processing
Reply #13 - Dec 15th, 2007, 10:59am
 
my nokia working fine when i try to connecting with my pc,
however,after i run the example from the "bluetoothdesktop"
it gave me the error below:

"Loading library BTCheckMS from ld.library.path
java.lang.RuntimeException: No supported stack installed or no dongle available"

i just can't sort it out,any help? many thxs!!
Re: Bluetooth library for processing
Reply #14 - Dec 15th, 2007, 1:27pm
 
Would help if you're more specific...which example are you running and where are you getting the exception? On the phone or on the computer? Do you have Avetana or other JSR-82 implementation installed on the BTdesktop library folder?  

Pages: 1 2 3 4