Discussion:
[BlueCove-users] How can I know when a remoteDevice sends me a data?
Sergio Alvarado
2016-01-08 21:02:25 UTC
Permalink
is there a way to create something like an listener for recieve data?

I'm trying to work with bluetooth arduino and Java, I have been able to
send data from pc to arduino (for example, press a Jbutton, arduino turns
on a led), but I don't know how to do that when arduino bluetooh sends me a
data the program detect it (for example, pressing an button in arduino,
sends a message and the program print it without I have to touch it)

With SerialPort this is easy, just add a SerialPortEventListener, but I
don't know how to do it with Bluetooth.

The connection with the remote device is this

Thanks

try {
ServiceRecord serviceRecord = (ServiceRecord)
listener.getServices().get(listener.getDevices().get(0))[0];
if(serviceRecord == null) {
System.out.println("The connection could not be made. Device not
discovered");
} else {
String url =
serviceRecord.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT,
false);
if(url == null) {
System.out.println("The connection could not be made. Connection url not
found");
} else {
Connection connection = Connector.open(url);
if(connection instanceof StreamConnectionNotifier) {
streamConnNotifier = (StreamConnectionNotifier)connection;
streamConnection = streamConnNotifier.acceptAndOpen();
} else if(connection instanceof StreamConnection) {
streamConnNotifier = null;
streamConnection = (StreamConnection)connection;
} else {
throw new Exception("Connection class not known. " +
connection.getClass().getCanonicalName());
}
System.out.println("aqui");
//read string from spp client
Input = streamConnection.openInputStream();
Output = streamConnection.openOutputStream();
retvalue = true;
}
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("The connection could not be made." + e.getMessage());
}
--
You received this message because you are subscribed to the Google Groups "bluecove-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bluecove-users+***@googlegroups.com.
To post to this group, send email to bluecove-***@googlegroups.com.
Visit this group at https://groups.google.com/group/bluecove-users.
For more options, visit https://groups.google.com/d/optout.
Loading...