[Solved] EV3 + Bluetooth

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

nzelot
New User
Posts: 4
Joined: Mon Oct 21, 2013 3:13 pm

[Solved] EV3 + Bluetooth

Postby nzelot » Mon Oct 21, 2013 3:24 pm

Hey Guys,

I just started programming my new EV3.
So far all things work great.
But now I was trying to connect to my Laptop via Bluetooth for Interaction.
The connection can be established (via Laptop) but when I try to open a Output or InputStream on the EV3 it always crashes with a NullPointer.

This is my code:

Code: Select all

//[...]
NXTConnection con = Bluetooth.getNXTCommConnector().waitForConnection(10000, NXTConnection.PACKET);

con.openDataOutputStream().write("Hello World".getBytes());
//[...]


As I watched into the lejos code, I saw that the waitForConnection() Method always returns a null.

So is there an other method establishing a valid connection?
And also with which class can I communicate with the EV3 from my Laptop?

Thanks for your help. 8)

nZeloT
Last edited by nzelot on Mon Oct 21, 2013 4:28 pm, edited 1 time in total.

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 + Bluetooth

Postby gloomyandy » Mon Oct 21, 2013 3:43 pm

What version of leJOS are you using? I don't think that waiting for an inbound connection over Bluetooth has been implemented yet...
https://sourceforge.net/p/lejos/ev3/ci/ ... ector.java
How are you connecting your EV3 to your Laptop at the moment? If using WiFi you could just use that, using TCP from Java is pretty easy...

If you want to use Bluetooth between your laptop and EV3 just establish a Bluetooth PAN link from your laptop and then use a TCP connection over it...


Andy

nzelot
New User
Posts: 4
Joined: Mon Oct 21, 2013 3:13 pm

Re: EV3 + Bluetooth

Postby nzelot » Mon Oct 21, 2013 3:50 pm

I'm using the current master from git. As I said, it's not implemented yet.

Connection to the EV3 is established via the laptop by clicking connect on the ev3 in the bluethoot devices window :mrgreen:

Could you please show some code on how to establish such a tcp connection?
Is it done by just opening a Socket to the bluetooth adress? or is there any special thing to do?

nzelot

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: EV3 + Bluetooth

Postby gloomyandy » Mon Oct 21, 2013 4:16 pm

So you already have Bluetooth working and I assume you can connect using ssh or telnet to 10.0.1.1 if so then you are all set. Just google for how to listen for a TCP connection and how to open a TCP connection using Java... The address you use on the client side (your laptop probably) is the TCP address of your EV3 (so probably 10.0.1.1 unless you have changed things), not the Bluetooth address. You don't need an address on the server side. If you are trying to connect from the EV3 to your PC things get a little more tricky, you have to work out what address has been allocated by the EV3 to your PC for the Bluetooth connection. To be honest I wouldn't bother doing that unless you are happy with network programming. Oh and please note that git master is very volatile at the moment. We don't really recommend using it if you want to get things done!

http://docs.oracle.com/javase/tutorial/ ... erver.html

One of the huge advantages of the EV3 is that you can use standard mechanisms like TCP. No more messing around with odd protocols etc. This allows you to use existing code and do things like use the standard Java remote debug capabilities.

nzelot
New User
Posts: 4
Joined: Mon Oct 21, 2013 3:13 pm

Re: EV3 + Bluetooth

Postby nzelot » Mon Oct 21, 2013 4:27 pm

Ok just figured it out.
Thanks for your help.

My Solution for now (for everyone else searching for this problem xD):

EV3:

Code: Select all

//[...]
ServerSocket serv = new ServerSocket(1111);
Socket s = serv.accept(); //Wait for Laptop to connect
DataInputStream in = new DataInputStream(s.getInputStream());
DataOutputStream out = new DataOutputStream(s.getOutputStream());

//Test msg from laptop
System.out.println(in.readUTF());
//[...]


Laptop:

Code: Select all

//[...]
Socket s = new Socket("10.0.1.1", 1111);
DataOutputStream out = new DataOutputStream(s.getOutputStream());
out.writeUTF("Hello EV3!");
//[...]


And BTW I'm just using master because the naming of packages and classes is not as confusing as in 0.4, but I wont update the my local copy everytime an update is pushed xD

nzelot

gamesover
New User
Posts: 9
Joined: Fri Aug 28, 2015 12:08 am

Re: [Solved] EV3 + Bluetooth

Postby gamesover » Fri Aug 28, 2015 1:56 am

May I ask in such case, who is client and who is server? I guess my win 7 pc is server and ev3 brick is client?

jormip
New User
Posts: 3
Joined: Fri Oct 21, 2016 3:33 pm

Re: [Solved] EV3 + Bluetooth

Postby jormip » Mon Sep 18, 2017 3:07 pm

The above code Server-Client model works well for USB not for bluetooth.

The triple Lejos-Bluetooth-Windows10 must be incompatible and I did not understand why.

I paired succefully the Lejos EV3 with my windows10 PC but using java I can´t do a program that open succefully a connection between both. I tried a Java program using the client-server TCP-IP model and did not work .

I also tried a program that uses JAVA bluetooth library that works fine with NXT but with Lejos EV3 was not able to open succefully a remote connection. The program identifies locally the remote device but fails when tries to open the URL.

Someone will give me some clues for the solution to connect using bluetooth a Lejos EV3 and a Java program?

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: [Solved] EV3 + Bluetooth

Postby gloomyandy » Mon Sep 18, 2017 4:00 pm

Are you sure you have actually established a PAN over Bluetooth between the PC and the EV3? You need the EV3 set into access point mode, to pair them and then to connect the PC to the access point. Once you have done that you should be able to ping the EV3 from the PC as address 10.0.1.1, and use standard TCP/IP between programs running on both systems.
leJOS news https://lejosnews.wordpress.com/

jormip
New User
Posts: 3
Joined: Fri Oct 21, 2016 3:33 pm

Re: [Solved] EV3 + Bluetooth

Postby jormip » Mon Sep 25, 2017 2:39 pm

Maybe I didn´t undertand how to define a bluetooth PAN correctly.

I did all steps of the following article:

https://sourceforge.net/p/lejos/wiki/Co ... ?version=1

and I never seen "EV3 Network Access Point BlueZ PAN Service" in my computer but both are paired.

Maybe I did anything wrong. Any help?

jormip
New User
Posts: 3
Joined: Fri Oct 21, 2016 3:33 pm

Re: [Solved] EV3 + Bluetooth

Postby jormip » Mon Sep 25, 2017 3:09 pm

The ping 10.0.1.1 only works when USB is connected. If I disconnect the USB connection, the ping returns "Request Time out".


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest