You are not logged in.
Pages: 1
Ok, so I lost my last post because CTRL-A is really close to CTRL-Q so this one is shorter:
Step 1: Turn on discoverability on the phone
Step 2: run "bluetooth-wizard" and pair the devices
Step 2.5: Start ICS on the phone and choose BT PAN and click connect
Step 3: run "tail /var/log/syslog" and look for a string like this: /org/bluez/hci0/dev_11_22_33_44_55_66
Step 4: save the code below as btpan.py and replace the device strign with the one from syslog
Step 5: "sudo python btpan.py"
Step 6: rejoice
There's a lot more work to do here but YAY it works. Hope you can figure it out too. Also, the stock RNDIS module works for USB tethering! Just make sure you click connect in the ICS app on the phone BEFORE connecting the device to the EEE. You should have a device ethX that you can use like normal.
import dbus
#import sys
import os
print 'Testing DBUS bluez';
bus = dbus.SystemBus();
#print bus;
conn = dbus.Interface(bus.get_object('org.bluez', '/org/bluez/hci0/dev_11_22_33_44_55_66'), 'org.bluez.Network');
#print conn;
iface = conn.Connect('NAP');
print 'Using ' + iface;
os.system('ifconfig up ' + iface);
os.system('dhclient ' + iface);Offline
good job!
Offline
Still can't get this working
I have some inherent problem with the bnep0 adaptor on my system. It creates the adaptor, initially connects for a split-second, but then just continues to drop the connection saying that the adaptor isn't there...
I wonder if it came about as a result of updating to Intrepid rather than doing a clean install?
Having said that, I have removed all trace of any bluetooth related packages and re-installed them hoping it would sort it - it doesn't ![]()
My phone is not a Windows mobile, however, but a Sony Ericsson W880i which previously under Hardy did Bluetooth PAN beautifully, and largely automagically - it initiated the GPRS connection as soon as pand requested an address...difficult to tell whether it's the phone or the EEE that's dropping the connection, now really...
Offline
I'll be taking a closer look at this later tonight/tomorrow.
Rod: Does your phone provide NAP? Also, have you successfully bound the device? Try "sdptool search -bdaddr 11:22:33:44:55:66 NAP" and see if your phone says it's providing the service. Also, do you have an entry in syslog for your phone?
One more thing to maybe try is "sdptool add PANU". I don't think this is required, but I did do that. Like I said, I'll try to get more crisp on the guts of this over the weekend.
Also: For debugging, you can use "hcitool scan" to get the address of your phone.
Offline
Ok so I spent a little more time on this and have a new script. If you're interested, give it a try.
Steps:
1) Copy the script and save it as btpan.py someplace where you can find it.
2) Enable your BT device on your EEE and also your target device
3) Pair the devices if you haven't already done that (use 'bluetooth-wizard' for this)
4) Open a terminal and go to the folder where the script is
5) run 'sudo python btpan.py' and follow the menus
That should be all there is to do. You can also use the tool to cleanly disconnect but there's no real need to do that.
Hope someone finds this useful.
# (c) 2008 Kyle Reed
# PAN tethering with WM device w/o using deprecated pand
# I don't claim to know Python, use at your own risk ;)
import dbus
import os
print 'Bluez 4.0 PAN Connection tool\n';
# get the system bus object
bus = dbus.SystemBus();
# get the adapter interface to query paired devices
adapter = dbus.Interface(bus.get_object('org.bluez', '/org/bluez/hci0'), 'org.bluez.Adapter');
# dump the paired devices list and prompt user for selection
counter = 0;
devices = adapter.ListDevices();
for d in devices:
counter += 1;
print '%d) %s' % (counter, d);
# get input
while True:
try:
index = int(raw_input('\nEnter the index of the device to use for PAN: '));
selected_dev_path = devices[index - 1];
break;
except ValueError:
print 'A valid number was expected. Try again.';
except IndexError:
print 'That\'s not a valid selection. Pick a value 1-%d' % (len(devices));
# get the network interface for the selected device
current_device = dbus.Interface(bus.get_object('org.bluez', selected_dev_path), 'org.bluez.Network');
# get properties for the device
props = current_device.GetProperties();
# dump properties and prompt user for action
print '\nCurrent device state: ';
for key in props.keys():
print '%s=\'%s\'' % (key, props[key]);
# get input
while True:
try:
selected_action = int(raw_input('\n1) Connect\n2) Disconnect\n0) Quit\nChoose an action: '));
break;
except ValueError:
print 'A valid number was expected. Try again';
# process selection
if selected_action == 1:
if props['Connected'] == 0:
print 'Connecting...';
try:
# connect and get interface
iface = current_device.Connect('NAP');
print 'Using network interface ' + iface;
# bring up the interface and start DHCP
os.system('ifconfig up ' + iface);
os.system('dhclient ' + iface);
print 'Connected';
except dbus.DBusException, e:
print 'Connection failed: %s' % (e)
else:
print 'Already Connected';
elif selected_action == 2:
if props['Connected']:
print 'Disconnecting...';
try:
# bring down interface
os.system('ifdown ' + props['Device']);
# disconnect
current_device.Disconnect();
print 'Disconnected';
except dbus.DBusException, e:
print 'Disconnect Failed: %s' % (e);
raise;
else:
print 'Not Connected';
else:
print 'Quitting...';Offline
neolith_GOD wrote:
I'll be taking a closer look at this later tonight/tomorrow.
Rod: Does your phone provide NAP? Also, have you successfully bound the device? Try "sdptool search -bdaddr 11:22:33:44:55:66 NAP" and see if your phone says it's providing the service. Also, do you have an entry in syslog for your phone?
One more thing to maybe try is "sdptool add PANU". I don't think this is required, but I did do that. Like I said, I'll try to get more crisp on the guts of this over the weekend.
Yes, the phone provides the service - I tried adding PANU too, still the same thing:
Here's my error (something similar happens when I use pand)
Connecting... Using network interface bnep0 bnep0: Unknown host ifconfig: `--help' gives usage information. Internet Systems Consortium DHCP Client V3.1.1 Copyright 2004-2008 Internet Systems Consortium. All rights reserved. For info, please visit http://www.isc.org/sw/dhcp/ SIOCSIFADDR: No such device bnep0: ERROR while getting interface flags: No such device bnep0: ERROR while getting interface flags: No such device Bind socket to interface: No such device
I'm convinced it's something that has been introduced on my install by the upgrade to Intrepid. The bnep0 interface would be automatically created perfectly under Hardy...
Offline
Rod Hull: That's really strange. bnep0 is returned from the Connect method, so bluez thinks it exists/creates it. I wonder why it goes away right away?
try:
# connect and get interface
iface = current_device.Connect('NAP'); #<--- the interface is returned here
print 'Using network interface ' + iface;Here's my error (something similar happens when I use pand)
So it this NOT working with the pand back-compat package either in Intrepid?
Offline
Yes. It initially connects (for a split-second). My phone acknowledges it (I can see its bluetooth icon change to signify a connection is made) and it even begins to fire up the GPRS connection automatically...
Literally as soon as it connects, it drops again, bnep0 disappears without a trace from my EEE, the GPRS connection and bluetooth connection are both terminated on the phone...
I can't figure it out. I've removed all trace of all bluetooth packages and config. files and reinstalled them and started from scratch, but it makes no difference...
The only thing I haven't tried is a total fresh install of Intrepid. I'd rather not have to resort to this ideally! At the end of the day I will probably only use GPRS->EEE via a USB cable, which works perfectly since bluetooth is inherently insecure and could lead to eavesdroppers in the places I'd use it (trains etc.).
It's just frustrating that I can't get it to work...
Offline
Not sure if anyone is still interested but I made some improvements to my script. It now has a GUI. Follow the instructions above to get it working.
#!/usr/bin/env python
# (c) 2008 Kyle Reed
# PAN tethering with WM device w/o using deprecated pand
# I don't claim to know Python, use at your own risk ;)
import pygtk
pygtk.require('2.0')
import gtk
import dbus
import os
### For passing errors to the GUI ###
class BTException:
def __init__(self, msg):
self.error_msg = msg
### BT Helper handles all of the DBUS stuff ###
# usage flow:
# __init__
# getDevicesList
# selectNetworkDevice
# getDeviceProperties
# Connnect|Disconnect
class BTHelper:
# create the helper object and initialize dbus
def __init__(self):
# get the system bus object
self.bus = dbus.SystemBus()
# get the adapter interface to query paired devices
self.adapter = dbus.Interface(self.bus.get_object(
'org.bluez', '/org/bluez/hci0'), 'org.bluez.Adapter')
# get the devices list #
def getDevicesList(self):
try:
self.devices = self.adapter.ListDevices()
return self.devices
except dbus.DBusException:
raise BTException('Could not get adapter interface, is your BT adapter on?')
# get the name of a device from a device string
# doesn't require selectNetworkDevice to be called
def getDeviceName(self, devicePath):
try:
tempDev = dbus.Interface(self.bus.get_object(
'org.bluez', devicePath), 'org.bluez.Device')
tempProps = tempDev.GetProperties()
return tempProps['Alias']
except dbus.DBusException:
return '[Error Fetching Name]'
# select device to query by index #
def selectNetworkDevice(self, index):
try:
self.current_device = dbus.Interface(self.bus.get_object(
'org.bluez', self.devices[index]), 'org.bluez.Network')
except dbus.DBusException:
raise BTException('Could not get network interface for device, is your device active?')
# returns information about the device #
def getDeviceProperties(self):
try:
self.deviceProps = self.current_device.GetProperties()
return self.deviceProps
except dbus.DBusException:
raise BTException('Could not get properties for device, did you select a device?')
# connects and initializes the connection #
def connectDevice(self):
if self.deviceProps['Connected'] == 0:
print 'Connecting...'
try:
# connect and get interface
iface = self.current_device.Connect('NAP')
print 'Using network interface ' + iface
# bring up the interface and start DHCP
os.system('ifconfig up ' + iface)
os.system('dhclient ' + iface)
print 'Connected'
except dbus.DBusException, e:
raise BTException('Connect Failed: %s' % (e))
else:
print 'Already Connected'
def disconnectDevice(self):
if self.deviceProps['Connected']:
print 'Disconnecting...'
try:
# bring down interface
os.system('ifdown ' + self.deviceProps['Device'])
# disconnect
self.current_device.Disconnect()
print 'Disconnected'
except dbus.DBusException, e:
raise BTException('Disconnect Failed: %s' % (e))
else:
print 'Not Connected'
### End BTHelper ###
### Defines the class that draws the GUI ###
class BTHelperGUI:
titleText = 'BlueTooth PAN Helper'
# show an exception message
def showErrorMsg(self, msg):
errorDlg = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg)
errorDlg.set_title(self.titleText)
errorDlg.run()
errorDlg.destroy()
### Signal Handler Methods
# exit button click
def handleExitClicked(self, widget, data=None):
print('Exiting')
self.exit()
# connect button clicked
def handleConnectClicked(self, widget, data=None):
try:
self.BTHelp.connectDevice()
self.getDeviceInformation()
except BTException, e:
self.showErrorMsg(e.error_msg)
# disconnect button clicked
def handleDisconnectClicked(self, widget, data=None):
try:
self.BTHelp.disconnectDevice()
self.getDeviceInformation()
except BTException, e:
self.showErrorMsg(e.error_msg)
# device selection changed
def handleDeviceSelectionChanged(self, widget, data=None):
selection = self.devicesListView.get_selection()
selectedIter = selection.get_selected()[1]
# nothing selected, return
if(selectedIter is None):
self.setButtonState(-1)
return
selectedIndex = self.devicesListStore.get_value(selectedIter, 2)
print('Selected %s' % (selectedIndex))
try:
self.BTHelp.selectNetworkDevice(selectedIndex)
self.getDeviceInformation()
except BTException, e:
self.showErrorMsg(e.error_msg)
# window manager is closing us (event)
def delete_event(self, widget, event, data=None):
self.exit()
return False
### End handler methods
### support methods ###
# process device names and add to devices list store
def processDevicesList(self):
# list devicees from the BT Adapter
try:
allDevices = self.BTHelp.getDevicesList()
count = 0;
for device in allDevices:
addrOnly = device.split('dev_')[-1]
addrOnly = addrOnly.replace('_', ':')
self.devicesListStore.append([addrOnly,
self.BTHelp.getDeviceName(device), count])
count += 1
except BTException, e:
self.showErrorMsg(e.error_msg)
# hard exit because we haven't stated the main loop
quit()
# get selected device information and set up controls
def getDeviceInformation(self):
try:
properties = self.BTHelp.getDeviceProperties()
self.statsListStore.clear()
self.statsListStore.append(['Connected',str(properties['Connected'])])
self.statsListStore.append(['Device',str(properties['Device'])])
self.setButtonState(int(properties['Connected']))
except BTException, e:
self.showErrorMsg(e.error_msg)
# enable/disable buttons are required
def setButtonState(self, state):
if(state == -1): # none selected
self.connectBtn.set_sensitive(False)
self.disconnectBtn.set_sensitive(False)
elif(state == 0): # disconnected
self.connectBtn.set_sensitive(True)
self.disconnectBtn.set_sensitive(False)
elif(state == 1): # connected
self.connectBtn.set_sensitive(False)
self.disconnectBtn.set_sensitive(True)
# common exit point for program
def exit(self):
gtk.main_quit()
### end support methods ###
def __init__(self):
self.BTHelp = BTHelper()
# create the main window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title(self.titleText)
self.window.set_default_size(400, 300)
self.window.set_border_width(10)
# set handlers for window events
self.window.connect('delete_event', self.delete_event)
# Devices list view
# set up data backend for devices list
# addr, name, index (hidden)
self.devicesListStore = gtk.ListStore(str, str, int)
self.processDevicesList()
# create devices list columns
devicesListCol = gtk.TreeViewColumn('Device Address')
devicesListCol2 = gtk.TreeViewColumn('Device Name')
# make text renderers and add to columns
addrCell = gtk.CellRendererText()
nameCell = gtk.CellRendererText()
devicesListCol.pack_start(addrCell, True)
devicesListCol2.pack_start(nameCell, True)
# set cell mappings to store data
devicesListCol.add_attribute(addrCell, 'text', 0)
devicesListCol2.add_attribute(nameCell, 'text', 1)
# create devices list and add columns
self.devicesListView = gtk.TreeView(self.devicesListStore)
self.devicesListView.append_column(devicesListCol)
self.devicesListView.append_column(devicesListCol2)
# set signal handlers for devices list
self.devicesListView.connect('cursor-changed', self.handleDeviceSelectionChanged)
# end devices list view
# stats list view
# create stats list data store
self.statsListStore = gtk.ListStore(str, str)
self.statsListStore.append(['Connected', ''])
self.statsListStore.append(['Device', ''])
# create stats columns
statsCol = gtk.TreeViewColumn('Property')
statsCol2 = gtk.TreeViewColumn('Value')
# create text renderers and add to columns
propCell = gtk.CellRendererText()
valueCell = gtk.CellRendererText()
statsCol.pack_start(propCell, True)
statsCol2.pack_start(valueCell, True)
# set data mappings with data store
statsCol.add_attribute(propCell, 'text', 0)
statsCol2.add_attribute(valueCell, 'text', 1)
# create stats list view
self.statsListView = gtk.TreeView(self.statsListStore)
self.statsListView.append_column(statsCol)
self.statsListView.append_column(statsCol2)
# end stats list view
# control buttons
self.connectBtn = gtk.Button('Connect')
self.disconnectBtn = gtk.Button('Disconnect')
self.exitBtn = gtk.Button('Exit')
# set handlers
self.exitBtn.connect('clicked', self.handleExitClicked)
self.connectBtn.connect('clicked', self.handleConnectClicked)
self.disconnectBtn.connect('clicked', self.handleDisconnectClicked)
# pack in a VBox
buttonBox = gtk.VBox(True, 2)
buttonBox.set_border_width(10)
buttonBox.pack_start(self.connectBtn)
buttonBox.pack_start(self.disconnectBtn)
buttonBox.pack_start(self.exitBtn)
# frames for decoration
statsFrame = gtk.Frame(' Status ')
statsFrame.add(self.statsListView)
buttonFrame = gtk.Frame(' Actions ')
buttonFrame.add(buttonBox)
# end control buttons
# add controls to layout
# +-----------------+
# | DEVLIST AREA |
# +-----+-----------+
# |STATS|BUTTONS |
# +-----+-----------+
tableLayout = gtk.Table(2, 2, False)
tableLayout.set_row_spacings(10)
tableLayout.set_col_spacings(10)
tableLayout.attach(self.devicesListView, 0, 2, 0, 1)
tableLayout.attach(statsFrame, 0, 1, 1, 2)
tableLayout.attach(buttonFrame, 1, 2, 1, 2)
# add layout to window
self.window.add(tableLayout)
self.window.show_all()
def main(self):
gtk.main()
### End BTHelperGUI ###
### Program Execution here ###
print('BlueTooth PAN Helper GUI')
btgui = BTHelperGUI()
btgui.main()Offline
Pages: 1