Giter VIP home page Giter VIP logo

pi-btnap's Introduction

Bluetooth Network Access Point for Raspberry Pi

Introduction

Bluetooth allows classical networking (TCP/IP). Although the throughput is limited, it has a number of advantages, like low power consumption. One drawback is that it does not work out of the box, it needs some additional packages and the configuration is not simple.

This project mainly collects and combines files and code-snippets I found in the internet to provide an easy to install version of a bluetooth network access point. It is targeted at Raspberry Pis running Raspbian Jessie, but it should also run on other flavors of Linux, as long as they provide a Bluez5 stack.

Architecture

Depending on your needs, you can choose to setup the system as a server, a client or a nap (network access point).

A server provides access to the system. This setup is the right choice if you are running a standalone system and want to query settings or control it e.g. from a browser. This is an ideal setup to use with smartphones and tablets (at least under Android), because once paired the smartphone/tablet will automatically use the bluetooth-connection for networking.

A client needs a second bluetooth-device to establish a connection. The second device must be a server or a nap. With this setup, you can provide an internet connection to a Pi (e.g. a Pi-Zero) using a second pi as a nap.

A nap is a special version of the server. It bridges incoming connections to an existing network interface (typically ethernet) and allows clients to transparently access the network. Depending on your network configuration, the nap itself can be invisible for the clients.

All the functionality is wrapped in a Systemd-service named btnap.service. For servers and naps, this service automatically configures a network bridge. For every incoming connection it creates a new bluetooth-based network interface bnepX and adds it to the bridge. The difference between the server and the nap is that the latter also adds an existing network interface to the bridge, so all connected clients will use that interface for access to the network. Depending on your needs, you could also configure routing from the bridge-device to an existing network device, but this setup is not directly supported by this project.

For clients, the btnap.service will just establish a connection to the provided remote bluetooth device.

Installation

To install, just run the following commands (on Raspbian Jessie-Lite you have to install git first):

git clone https://github.com/bablokb/pi-btnap
sudo pi-btnap/tools/install-btnap  server [ifname] | client

The argument to install-btnap selects the role of the system. If you select the server role and provide an interface name, the system will act as a network-access-point (it adds the interface to the bridge). You can change the role afterwards by editing /etc/btnap.conf (see the section Configuration below).

The scripts installs some additional packages needed by the python-script. It adds a template configuration file (/etc/btnap.conf) and it enables (but doesn't start) the btnap.service. You could edit the install script before installation and provide your own defaults for a number of variables, but it is better to change the generated configuration file.

There are some install-time only configuration options (e.g. additional installation of dnsmasq). Please check the install-script and change as needed.

Configuration

All configuration is done in the file /etc/btnap.conf:

MODE="server"             # values: server|client

# server configuration
BR_DEV="br0"                # bridge-device
BR_IP="192.168.20.99/24"    # IP of bridge/network-size
BR_GW="192.168.20.1"        # GW-IP for bridge
ADD_IF=""                   # add eth0 to convert the server to a nap

# client configuration
REMOTE_DEV=""           # MAC of remote BT nap server

DEBUG=""                # set to anything to enable debug-messages

If the bridge IP (variable BR_IP) is in the range of your home-network, btnap-clients can access your server even if in nap-mode.

pi-btnap's People

Contributors

bablokb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pi-btnap's Issues

Kernel crash

Hello,
I configured and am using your tool to setup NAP on my Pi3 b+. It works pretty well, however, it crashs randomly and I see:

root@IQoT-000:/home/pi# tail -f /var/log/messages
Feb 12 22:25:24 IQoT-000 kernel: [ 3016.392058] Voltage normalised (0x00000000)
Feb 12 22:27:25 IQoT-000 kernel: [ 3137.032044] Voltage normalised (0x00000000)
Feb 12 22:29:23 IQoT-000 kernel: [ 3255.592050] Voltage normalised (0x00000000)
Feb 12 22:31:24 IQoT-000 kernel: [ 3376.232052] Voltage normalised (0x00000000)
Feb 12 22:33:24 IQoT-000 kernel: [ 3496.872068] Voltage normalised (0x00000000)
Feb 12 22:33:33 IQoT-000 kernel: [ 3505.886420] br0: port 1(bnep0) entered blocking state
Feb 12 22:33:33 IQoT-000 kernel: [ 3505.886445] br0: port 1(bnep0) entered disabled state
Feb 12 22:33:33 IQoT-000 kernel: [ 3505.886859] device bnep0 entered promiscuous mode
Feb 12 22:33:33 IQoT-000 kernel: [ 3505.887938] br0: port 1(bnep0) entered blocking state
Feb 12 22:33:33 IQoT-000 kernel: [ 3505.887954] br0: port 1(bnep0) entered forwarding state
Feb 12 22:34:24 IQoT-000 kernel: [ 3556.058096] br0: port 1(bnep0) entered disabled state
Feb 12 22:34:24 IQoT-000 kernel: [ 3556.062332] device bnep0 left promiscuous mode
Feb 12 22:34:24 IQoT-000 kernel: [ 3556.062356] br0: port 1(bnep0) entered disabled state
Feb 12 22:35:05 IQoT-000 kernel: [ 3597.350916] br0: port 1(bnep0) entered blocking state
Feb 12 22:35:05 IQoT-000 kernel: [ 3597.350926] br0: port 1(bnep0) entered disabled state
Feb 12 22:35:05 IQoT-000 kernel: [ 3597.351155] device bnep0 entered promiscuous mode
Feb 12 22:35:05 IQoT-000 kernel: [ 3597.352141] br0: port 1(bnep0) entered blocking state
Feb 12 22:35:05 IQoT-000 kernel: [ 3597.352151] br0: port 1(bnep0) entered forwarding state
Feb 12 22:35:10 IQoT-000 kernel: [ 3602.952117] Voltage normalised (0x00000000)
Feb 12 22:35:23 IQoT-000 kernel: [ 3615.432055] Voltage normalised (0x00000000)
Feb 12 22:35:43 IQoT-000 kernel: [ 3635.786222] br0: port 2(bnep1) entered blocking state
Feb 12 22:35:43 IQoT-000 kernel: [ 3635.786236] br0: port 2(bnep1) entered disabled state
Feb 12 22:35:43 IQoT-000 kernel: [ 3635.786807] device bnep1 entered promiscuous mode
Feb 12 22:35:43 IQoT-000 kernel: [ 3635.788729] br0: port 2(bnep1) entered blocking state
Feb 12 22:35:43 IQoT-000 kernel: [ 3635.788745] br0: port 2(bnep1) entered forwarding state
Feb 12 22:36:11 IQoT-000 kernel: [ 3663.272042] Voltage normalised (0x00000000)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.991930] ------------[ cut here ]------------
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992001] WARNING: CPU: 1 PID: 0 at net/sched/sch_generic.c:466 dev_watchdog+0x294/0x298
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992023] NETDEV WATCHDOG: bnep0 (): transmit queue 0 timed out
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992036] Modules linked in: fuse rfcomm bridge bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q garp stp llc binfmt_misc brcmfmac brcmutil sha256_generic cfg80211 rfkill snd_bcm2835(C) raspberrypi_hwmon hwmon snd_pcm bcm2835_codec(C) snd_timer bcm2835_v4l2(C) v4l2_mem2mem snd bcm2835_mmal_vchiq(C) videobuf2_dma_contig v4l2_common videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media vc_sm_cma(C) fixed uio_pdrv_genirq uio i2c_dev ip_tables x_tables ipv6
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992189] CPU: 1 PID: 0 Comm: swapper/1 Tainted: G         C        4.19.93-v7+ #1290
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992195] Hardware name: BCM2835
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992238] [<801120c0>] (unwind_backtrace) from [<8010d5f4>] (show_stack+0x20/0x24)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992260] [<8010d5f4>] (show_stack) from [<808453e8>] (dump_stack+0xe0/0x124)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992279] [<808453e8>] (dump_stack) from [<80120c9c>] (__warn+0x104/0x11c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992295] [<80120c9c>] (__warn) from [<80120d0c>] (warn_slowpath_fmt+0x58/0x74)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992313] [<80120d0c>] (warn_slowpath_fmt) from [<8076ad4c>] (dev_watchdog+0x294/0x298)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992338] [<8076ad4c>] (dev_watchdog) from [<80198fd8>] (call_timer_fn+0x3c/0x198)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992359] [<80198fd8>] (call_timer_fn) from [<80199220>] (expire_timers+0xec/0x14c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992380] [<80199220>] (expire_timers) from [<80199338>] (run_timer_softirq+0xb8/0x1ec)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992399] [<80199338>] (run_timer_softirq) from [<80102410>] (__do_softirq+0x190/0x3f0)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992415] [<80102410>] (__do_softirq) from [<80126e24>] (irq_exit+0xfc/0x120)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992434] [<80126e24>] (irq_exit) from [<8018023c>] (__handle_domain_irq+0x70/0xc4)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992449] [<8018023c>] (__handle_domain_irq) from [<801021b4>] (bcm2836_arm_irqchip_handle_irq+0x60/0xa4)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992464] [<801021b4>] (bcm2836_arm_irqchip_handle_irq) from [<801019bc>] (__irq_svc+0x5c/0x7c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992481] Exception stack(0xb694df38 to 0xb694df80)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992495] df20:                                                       80109ae4 00000000
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992512] df40: 40000093 40000093 80d04d70 b694c000 80d04db8 00000002 80d8efbe 410fd034
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992524] df60: 00000000 b694df94 80d0517c b694df88 00000000 80109ae8 40000013 ffffffff
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992541] [<801019bc>] (__irq_svc) from [<80109ae8>] (arch_cpu_idle+0x34/0x4c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992564] [<80109ae8>] (arch_cpu_idle) from [<808624d4>] (default_idle_call+0x34/0x48)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992585] [<808624d4>] (default_idle_call) from [<80152e80>] (do_idle+0xec/0x16c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992604] [<80152e80>] (do_idle) from [<801531c0>] (cpu_startup_entry+0x28/0x2c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992621] [<801531c0>] (cpu_startup_entry) from [<8010fedc>] (secondary_start_kernel+0x134/0x140)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992636] [<8010fedc>] (secondary_start_kernel) from [<0010270c>] (0x10270c)
Feb 12 22:36:37 IQoT-000 kernel: [ 3689.992663] ---[ end trace 2432ac594065705f ]---
Feb 12 22:36:52 IQoT-000 kernel: [ 3704.349314] br0: port 2(bnep1) entered disabled state
Feb 12 22:36:52 IQoT-000 kernel: [ 3704.350863] device bnep1 left promiscuous mode
Feb 12 22:36:52 IQoT-000 kernel: [ 3704.350882] br0: port 2(bnep1) entered disabled state
Feb 12 22:36:52 IQoT-000 kernel: [ 3704.434634] br0: port 1(bnep0) entered disabled state
Feb 12 22:36:52 IQoT-000 kernel: [ 3704.436821] device bnep0 left promiscuous mode
Feb 12 22:36:52 IQoT-000 kernel: [ 3704.436839] br0: port 1(bnep0) entered disabled state

Then I get disconnected (I am connecting to my Pi both from a Linux Mint box and my android phone). If I try to restablish, it reconnects, then after a while, crashs again.

Nevermind ... If you have some time to take a look and if you need me to test anything, just let me know !

Issue connecting two Raspberry Pis

Hi, we are trying to use your software to connect two Raspberry Pis, one is a Pi 3 the other a Pi Zero W. We installed btnap to both and set the Pi 3 as a server (No NAP) and the Pi Zero W as a client. Then we connected both using bluetooth. Should a network bridge appear on both devices? There is only a network bridge on the Pi 3. This is the output of Bluetoothctl:

pi@Team10Pi3:~ $ bluetoothctl
[NEW] Controller B8:27:EB:83:D9:51 Team10Pi3 [default]
[NEW] Device B8:27:EB:26:EB:88 raspberrypi
[bluetooth]# show
Controller B8:27:EB:83:D9:51
        Name: Team10Pi3
        Alias: Team10Pi3
        Class: 0x7c0000
        Powered: yes
        Discoverable: yes
        Pairable: yes
        UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: OBEX File Transfer        (00001106-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: OBEX Object Push          (00001105-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        UUID: IrMC Sync                 (00001104-0000-1000-8000-00805f9b34fb)
        UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
        UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
        UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
        UUID: Vendor specific           (00005005-0000-1000-8000-0002ee000001)
        UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
        UUID: Message Notification Se.. (00001133-0000-1000-8000-00805f9b34fb)
        UUID: Phonebook Access Server   (0000112f-0000-1000-8000-00805f9b34fb)
        UUID: Message Access Server     (00001132-0000-1000-8000-00805f9b34fb)
        UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v1D6Bp0246d052B
        Discovering: no
[bluetooth]# info B8:27:EB:26:EB:88
Device B8:27:EB:26:EB:88
        Name: raspberrypi
        Alias: raspberrypi
        Class: 0x6c0000
        Paired: yes
        Trusted: yes
        Blocked: no
        Connected: no
        LegacyPairing: no
        UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
        UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
        UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
        UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
        UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
        UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v1D6Bp0246d052B

Thanks for the help!

android fails to get internet access via NAP

Hi,
We established nap using btnap.service. Android device successfully connects via bluetooth and gets ip assigned to it. But fails to access internet. But with the same nap ios device can access internet. Can you please help, whats wrong we are doing?

Thanks.

Multiple connections

Hi, can this script allow multiple clients to connect to the raspi in "server" mode?

Raspberry Pi SSH over Bluetooth

I am struggling with finding a way to ssh into pi via bluetooth and I found this repository
Although I carefully followed all the steps to get the btnap server working, there are two missing packages that cannot be installed, maybe due to deprecation.
When running ./pi-btnap/tools/install-btnap server it returns these errors:

Package python-dbus is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package python-gobject is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-dbus' has no installation candidate
E: Package 'python-gobject' has no installation candidate

I didn't find a way to get these missing packages installed as to be used by the install script.
Your kind suggestions on how to get around this would be much appreciated.

My system is Raspberry pi zero 2 w running Raspberry Pi OS 32 bit kernel 5.10.92-v7+

Cannot pair with Galaxy S7 Edge

I can't pair my phone with the Pi. The raspberry detects my phone, when I type the pair command, phone seems to pair successfully. Right after I confirm the security PIN on both devices my phone disconnects.

Connect from macOS

Is there a way I could connect to the PAN on a Raspberry Pi from a Mac?
I see in the networking options of a mac if you are connected via bluetooth and a PAN is detected you can connect to it.

I see other services are broadcast when I connect such as Audio and causes my mac to try to pipe its audio through bluetooth as though the pi was a speaker.

Is it a matter of providing some kind of additional "PAN" service for devices that connect?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.