bluetooth not working

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc

Moderators: roger, 99jonathan, imaqine

bluetooth not working

Postby zatalian » Sat Sep 26, 2009 10:58 am

Hi,

I'm new to lejos and i'm trying to connect to my nxt using bluetooth.

I'm using 64 bit linux.
I was able to do all the steps in the "Getting started on Linux" guide. The firmware (0.85) is successfully flashed into the nxt.
I am able to do everything over usb

When i thy bluetooth i see the device (called NXT-HOME) but i can't connect to it. I'm getting the following error :


Code: Select all
nxj -r View
leJOS NXJ> Linking...
leJOS NXJ> Uploading...
BlueCove version 2.1.0 on bluez
leJOS NXJ> Exception in open: Open of NXT-HOME failed: Failed to create socket. [93] Protocol not supported
leJOS NXJ> Failed to connect to any NXT
an error occurred: No NXT found - is it switched on and plugged in (for USB)?
BlueCove stack shutdown completed


Is this a known problem, perhaps with a solution?
zatalian
New User
 
Posts: 2
Joined: Sat Sep 26, 2009 10:50 am

Postby gloomyandy » Sat Sep 26, 2009 11:46 am

Hi,
What happens if you try to use nxjbrowse? Do you see a list of nxts?
What is the name of your nxt?
You may need to pair your pc with the NXT before you can access it. You will probably have to use a Linux utility to do this...

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

Postby zatalian » Sat Sep 26, 2009 4:29 pm

I had to load the rfcomm module manually to get a little further. Now i get :

Code: Select all
BlueCove version 2.1.0 on bluez
leJOS NXJ> Exception in open: Open of NXT-HOME failed: Failed to connect. [13] Permission denied
leJOS NXJ> Failed to connect to any NXT
BlueCove stack shutdown completed


When i use nxjbrowse I can see the nxt but i can't connect to it.

How do i pair my pc with the nxt? I'm quite new to bluetooth. I bought a usb-bluetooth dongle only for my nxt so it's the first device ever to connect to my pc.
zatalian
New User
 
Posts: 2
Joined: Sat Sep 26, 2009 10:50 am

Postby legott » Wed Jul 28, 2010 12:34 pm

I've the same problem. The robot NXT can see my computer (Windows7 64bit) and my computer can see the NXT. But I cannot connect the two devices.

First I tried to connect via the lejos-menu in my robot. Here I get the message (after giving the pin) "UNSUCCESSFUL".

The second try failed, too. I copied a piece of code and tried a few things. But the program cannot create a BTConnection. My btc-Object is always null. But the NXT can get all data from the RemoteDevice-Object (called btrd). Here you can see my code.

Code: Select all
import java.util.Vector;

import javax.bluetooth.RemoteDevice;

import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class BTConnectTest {

   public static void main(String[] args) throws Exception {
      
      //Search for BT-Devices
      
      byte[] cod = {0,0,0,0};
      LCD.drawString("Searching...\n", 0, 0);
      Vector devList = Bluetooth.inquire(5, 10, cod);
      if(devList == null) {
         LCD.clear();
         LCD.drawString("Inquire returns null", 0, 0);
         Button.waitForPress();
         System.exit(0);
      }
      else if(devList.size() > 0) {
         String[] names = new String[devList.size()];
         for(int i=0; i<devList.size(); i++) {
            RemoteDevice btrd = (RemoteDevice) devList.elementAt(i);
            names[i] = btrd.getFriendlyName(false);
            LCD.clear();
            LCD.drawString("Got device "+names[i]+"\n", 0, 0);
         }
      }
      
      //add the BT-Devices to the internal BT-devices-list
      
      for(int i=0; i<devList.size(); i++) {
         RemoteDevice btrd = (RemoteDevice) devList.elementAt(i);
         Bluetooth.addDevice(btrd);
      }
      
      //create the RemoteDevice
      
      RemoteDevice btrd = Bluetooth.getKnownDevice("WIN7");
      //RemoteDevice btrd = (RemoteDevice) devList.elementAt(0);
      if(btrd == null) {
         System.out.println("failed to initial btrd");
         Button.waitForPress();
         System.exit(0);
      }
      
      //System.out.println("BT-Adress: "+btrd.getBluetoothAddress());
      //System.out.println("Dev-Adress:"+btrd.getDeviceAddr());
      //System.out.println("FriendlyNameF:"+btrd.getFriendlyName(false));
      //System.out.println("FriendlyNameT:"+btrd.getFriendlyName(true));
      //Button.waitForPress();
      
      //try to initial the connection
      
      //BTConnection btc = Bluetooth.connect(btrd);
      final byte[] pin = {(byte) '0', (byte) '0', (byte) '0', (byte) '0'};
      BTConnection btc = null;
      
      btc = Bluetooth.connect(btrd);
      if(btc == null) {
         System.out.println("Bluetooth.connect(btrd) failed");
         Button.waitForPress();
      }
      if(btc == null) {
         btc = Bluetooth.connect(btrd.getDeviceAddr(), NXTConnection.RAW, pin);
         System.out.println("btc is still null");
         Button.waitForPress();
         System.exit(0);
      }
      System.out.println("connection successful");
      byte[] status = Bluetooth.getConnectionStatus();
      if(status == null) {
         btc.close();
         System.out.println("no status :(");
         Button.waitForPress();
         System.exit(0);
      }
      System.out.println("all wonderfull :) you could send data as from now");
      Button.waitForPress();
      
      
   }
}


Ideas? Thanks a lot. G.Timo
legott
New User
 
Posts: 11
Joined: Wed Sep 16, 2009 8:05 am

Postby Shawn » Sat Jul 31, 2010 1:50 am

Did you get it going?

Try to connect from the PC.

wait for a connection on the NXT. It's in the api.
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

Postby gloomyandy » Sat Jul 31, 2010 8:05 am

Make sure you have paired the two devices before you do anything else. It ias always best to pair the devices from the PC (Pairing from the NXT is really only there as a last resort and to allow pairing with devices like GPS etc.)...

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

Postby legott » Sat Jul 31, 2010 9:15 am

Shawn wrote:Try to connect from the PC.
What is the best way to do this?

Shawn wrote:wait for a connection on the NXT. It's in the api.
Thanks, this code I've found.

gloomyandy wrote:Make sure you have paired the two devices before you do anything else. It ias always best to pair the devices from the PC (Pairing from the NXT is really only there as a last resort and to allow pairing with devices like GPS etc.)...
Thanks. The pairing from the NXT does not fit. I hope, the other direction will have success.
legott
New User
 
Posts: 11
Joined: Wed Sep 16, 2009 8:05 am

Postby Shawn » Sat Jul 31, 2010 10:18 am

legott wrote: What is the best way to do this?


Look at BTSend in /pcsamples

I'm not sure where that is on windows. Maybe it's in documents or something. Anyway, programs in /samples run on you nxt and /pcsamples run on your pc. They are a goldmine![/quote]
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

Postby legott » Mon Aug 02, 2010 6:25 pm

Thanks. After trying a lot, it works. :)
legott
New User
 
Posts: 11
Joined: Wed Sep 16, 2009 8:05 am

Re: bluetooth not working

Postby pcProfie » Tue Mar 12, 2013 5:44 am

Hey :)
I have the same problem now, but i have a presentation next saturday.
can you please show me your code?
how did you solve the problem?

and the method .elementAt won't work here. (it's a method to connect two nxts, isn't it?)

Code: Select all
public DataOutputStream connectMyNxt() throws Exception {
        LCD.drawString("Connecting...", 0, 0);
        RemoteDevice btrd = (RemoteDevice)Bluetooth.getKnownDevicesList().elementAt(0);
        LCD.drawString("Device: " + btrd, 0, 1);
        BTConnection connection = Bluetooth.connect(btrd);
        LCD.drawString("Connected to: " + connection,0,2);
        DataOutputStream output = connection.openDataOutputStream();
        Thread.sleep(2000);
        Sound.twoBeeps();
        return output;
    }


when i compile it it says: cannot find symbol- medhod elementAt(int)
i've imported this:
Code: Select all
import java.io.*;
import javax.bluetooth.*;
import lejos.nxt.comm.*;
import lejos.nxt.remote.*;
import lejos.nxt.*;


can i use get() here?
Code: Select all
RemoteDevice btrd = (RemoteDevice)Bluetooth.getKnownDevicesList().get(0);


when i start the btsend of the pcsamples it shows this error (but no error after compiling):
Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: lejos.nxt.NXT.getUserPages()I
at lejos.nxt.NXT.getUserPages(Native Method)
at lejos.nxt.Flash.<clinit>(Flash.java:16)
at lejos.nxt.SystemSettings.<clinit>(SystemSettings.java:32)
at lejos.nxt.comm.NXTCommDevice.loadSettings(NXTCommDevice.java:165)
at lejos.nxt.comm.NXTCommDevice.<clinit>(NXTCommDevice.java:20)
at javax.bluetooth.DiscoveryAgent$1.run(DiscoveryAgent.java:194)

code:
Code: Select all
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import lejos.pc.comm.NXTCommLogListener;
import lejos.pc.comm.NXTConnector;

/**
 * This is a PC sample. It connects to the NXT, and then
 * sends an integer and waits for a reply, 100 times.
 *
 * Compile this program with javac (not nxjc), and run it
 * with java.
 *
 * You need pccomm.jar and bluecove.jar on the CLASSPATH.
 * On Linux, you will also need bluecove-gpl.jar on the CLASSPATH.
 *
 * Run the program by:
 *
 *   java BTSend
 *
 * Your NXT should be running a sample such as BTReceive or
 * SignalTest. Run the NXT program first until it is
 * waiting for a connection, and then run the PC program.
 *
 * @author Lawrie Griffiths
 *
 */
public class BTSend {   
   public static void main(String[] args) {
      NXTConnector conn = new NXTConnector();
   
      conn.addLogListener(new NXTCommLogListener(){

         public void logEvent(String message) {
            System.out.println("BTSend Log.listener: "+message);
            
         }

         public void logEvent(Throwable throwable) {
            System.out.println("BTSend Log.listener - stack trace: ");
             throwable.printStackTrace();
            
         }
         
      }
      );
      // Connect to any NXT over Bluetooth
      boolean connected = conn.connectTo("btspp://");
   
      
      if (!connected) {
         System.err.println("Failed to connect to any NXT");
         System.exit(1);
      }
      
      DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
      DataInputStream dis = new DataInputStream(conn.getInputStream());
            
      for(int i=0;i<100;i++) {
         try {
            System.out.println("Sending " + (i*30000));
            dos.writeInt((i*30000));
            dos.flush();         
            
         } catch (IOException ioe) {
            System.out.println("IO Exception writing bytes:");
            System.out.println(ioe.getMessage());
            break;
         }
         
         try {
            System.out.println("Received " + dis.readInt());
         } catch (IOException ioe) {
            System.out.println("IO Exception reading bytes:");
            System.out.println(ioe.getMessage());
            break;
         }
      }
      
      try {
         dis.close();
         dos.close();
         conn.close();
      } catch (IOException ioe) {
         System.out.println("IOException closing connection:");
         System.out.println(ioe.getMessage());
      }
   }
}



thanks,
pcProfie
pcProfie
New User
 
Posts: 13
Joined: Thu Aug 02, 2012 4:18 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff