RPi Bluetooth

From Datateknik
Revision as of 19:36, 15 September 2018 by Imra (Talk | contribs)

Jump to: navigation, search

hello

Contents

Bluetooth

SLAVE

modprobe bluetooth_6lowpan
lsmod | grep 6low #gives three (3) lines
echo "1" > /sys/kernel/debug/bluetooth/6lowpan_enable
lsmod | grep 6low #gives three (4) lines; now includes  ipv6 -> 6lowpan
#rename hci0 to "whatever"
hciconfig hci0 name rpi-slave
# doing "hcitool lescan" on a third comupter shows nothing
# this cammand is undocumented ?!?
hciconfig hci0 leadv
# the slave now shows up as BCM43438A1

MASTER

modprobe bluetooth_6lowpan
lsmod | grep 6low #gives three (3) lines
echo "1" > /sys/kernel/debug/bluetooth/6lowpan_enable
lsmod | grep 6low #gives three (4) lines; now includes  ipv6 -> 6lowpan
hciconfig hci0 name Master
#Use address of other side's hci0 (Low Energy Create Connexion)
hcitool lecc B8:27:EB:C1:E9:42
# lecc should return "connection handle 65"
sleep 5
echo "connect B8:27:EB:C1:E9:42" > /sys/kernel/debug/bluetooth/6lowpan_control
#still nothing in ifconfig
ifconfig bt0 up
ifconfig   # Finally!

Scanning BLE

Scanning BLE is from https://elinux.org/RPi_Bluetooth_LE

device testing

  1. Check what devices you've got

--- ON A PC ---

root@raspberry:/home/pi# lsusb
Bus 002 Device 004: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
Bus 002 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@raspberry:/home/pi# 

root@raspberry:/home/pi# lsusb -d 0a5c:5800
Bus 002 Device 004: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
root@raspberry:/home/pi# lsusb -v -d 0a5c:5800 

Bus 002 Device 004: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
 bDeviceClass            0 (Defined at Interface level)
 bDeviceSubClass         0 
 bDeviceProtocol         0 
 bMaxPacketSize0        64
 idVendor           0x0a5c Broadcom Corp.
 idProduct          0x5800 BCM5880 Secure Applications Processor
 bcdDevice            1.01
 iManufacturer           1 Broadcom Corp
 iProduct                2 5880
 iSerial                 3 0123456789ABCD
 bNumConfigurations      1
 Configuration Descriptor:
   bLength                 9
   bDescriptorType         2
   wTotalLength          139
   bNumInterfaces          2
   bConfigurationValue     0
   iConfiguration          0 
   bmAttributes         0xc0
     Self Powered
   MaxPower              100mA
   Interface Descriptor:
     bLength                 9
     bDescriptorType         4
     bInterfaceNumber        0
     bAlternateSetting       0
     bNumEndpoints           3
     bInterfaceClass       254 Application Specific Interface
     bInterfaceSubClass      0 
     bInterfaceProtocol      0 
     iInterface              4 Broadcom USH
     ** UNRECOGNIZED:  10 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x81  EP 1 IN
       bmAttributes            2
         Transfer Type            Bulk
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               0
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x01  EP 1 OUT
       bmAttributes            2
         Transfer Type            Bulk
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               0
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x85  EP 5 IN
       bmAttributes            3
         Transfer Type            Interrupt
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0010  1x 16 bytes
       bInterval              32
   Interface Descriptor:
     bLength                 9
     bDescriptorType         4
     bInterfaceNumber        1
     bAlternateSetting       0
     bNumEndpoints           3
     bInterfaceClass        11 Chip/SmartCard
     bInterfaceSubClass      0 
     bInterfaceProtocol      0 
     iInterface              5 Contacted SmartCard
     ChipCard Interface Descriptor:
       bLength                54
       bDescriptorType        33
       bcdCCID              1.00
       nMaxSlotIndex           0
       bVoltageSupport         7  5.0V 3.0V 1.8V 
       dwProtocols             3  T=0 T=1
       dwDefaultClock       4000
       dwMaxiumumClock      4000
       bNumClockSupported      0
       dwDataRate           9600 bps
       dwMaxDataRate      250000 bps
       bNumDataRatesSupp.      0
       dwMaxIFSD             247
       dwSyncProtocols  00000000 
       dwMechanical     00000000 
       dwFeatures       000102BA
         Auto configuration based on ATR
         Auto voltage selection
         Auto clock change
         Auto baud rate change
         Auto PPS made by CCID
         NAD value other than 0x00 accepted
         TPDU level exchange
       dwMaxCCIDMsgLen       271
       bClassGetResponse      00
       bClassEnvelope         00
       wlcdLayout           none
       bPINSupport             0 
       bMaxCCIDBusySlots       1
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x82  EP 2 IN
       bmAttributes            2
         Transfer Type            Bulk
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               0
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x02  EP 2 OUT
       bmAttributes            2
         Transfer Type            Bulk
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0040  1x 64 bytes
       bInterval               0
     Endpoint Descriptor:
       bLength                 7
       bDescriptorType         5
       bEndpointAddress     0x86  EP 6 IN
       bmAttributes            3
         Transfer Type            Interrupt
         Synch Type               None
         Usage Type               Data
       wMaxPacketSize     0x0010  1x 16 bytes
       bInterval              32

Device Status: 0x0000

 (Bus Powered)

root@raspberry:/home/pi#

root@raspberry:/home/pi# hciconfig hci0: Type: Primary Bus: USB BD Address: 00:1A:7D:DA:71:0E ACL MTU: 310:10 SCO MTU: 64:8 UP RUNNING RX bytes:718 acl:0 sco:0 events:54 errors:0 TX bytes:4158 acl:0 sco:0 commands:54 errors:0

root@raspberry:/home/pi# hciconfig -a hci0: Type: Primary Bus: USB BD Address: 00:1A:7D:DA:71:0E ACL MTU: 310:10 SCO MTU: 64:8 UP RUNNING RX bytes:718 acl:0 sco:0 events:54 errors:0 TX bytes:4158 acl:0 sco:0 commands:54 errors:0 Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT Name: 'raspberry' Class: 0x6c010c Service Classes: Rendering, Capturing, Audio, Telephony Device Class: Computer, Laptop HCI Version: 4.0 (0x6) Revision: 0x22bb LMP Version: 4.0 (0x6) Subversion: 0x22bb Manufacturer: Cambridge Silicon Radio (10)


root@raspberry:/home/pi# hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: 00:1A:7D:DA:71:0E  ACL MTU: 310:10  SCO MTU: 64:8

UP RUNNING RX bytes:94567 acl:0 sco:0 events:2186 errors:0 TX bytes:4223 acl:0 sco:0 commands:64 errors:0 Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT Name: 'raspberry' Class: 0x6c010c Service Classes: Rendering, Capturing, Audio, Telephony Device Class: Computer, Laptop HCI Version: 4.0 (0x6) Revision: 0x22bb LMP Version: 4.0 (0x6) Subversion: 0x22bb Manufacturer: Cambridge Silicon Radio (10)

root@raspberry:/home/pi# 

--- ON rPI ---

  1. lsusb
  1. Basic installation checks: The Pi 3's built-in Bluetooth adapter is called hci0. You can check it is operating correctly with the command:
    hciconfig (use hciconfig -a for more details)
root@raspberrypi:/home/pi# lsusb
Bus 001 Device 004: ID 0461:4d51 Primax Electronics, Ltd 0Y357C PMX-MMOCZUL (B) [Dell Laser Mouse]
Bus 001 Device 003: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 001 Device 002: ID 0424:2412 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The BLE adapter is not on the USB-bus in rPi Zero W !!

root@raspberrypi:/home/pi# hciconfig -a
hci0:	Type: Primary  Bus: UART
	BD Address: B8:27:EB:C1:E9:42  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING 
	RX bytes:1469 acl:0 sco:0 events:89 errors:0
	TX bytes:4405 acl:0 sco:0 commands:89 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 
	Name: 'raspberrypi'
	Class: 0x6c0000
	Service Classes: Rendering, Capturing, Audio, Telephony
	Device Class: Miscellaneous, 
	HCI Version: 4.1 (0x7)  Revision: 0x168
	LMP Version: 4.1 (0x7)  Subversion: 0x2209
	Manufacturer: Broadcom Corporation (15)

root@raspberrypi:/home/pi# 


  1. If you are on a laptop two(2) hci devices will show up, the first one is buggy
    hciconfig hci0 down
  2. Now you can try scanning for BLE devices
    hcitool lescan

Python programs

  1. do stuff
    sudo apt-get install python-pip
    sudo apt-get install libglib2.0-dev
    sudo pip install bluepy
    blescan

has GATTOOL anything to do with it ??

gatttool

https://elinux.org/RPi_Bluetooth_LE#Connecting_with_gatttool

Creating a channel, capable of 6lowPAN (IPv6)

[RFC7668] "IPv6 over Bluetooth LE is dependent on both Bluetooth 4.1 and IPSP 1.0 or ..."


Reading http://blog.bluetooth.com/bluetooth-meet-the-internet-internet-say-hello-to-bluetooth you find that BLE uses Generic Attribute Profile (GATT) which is modular, and not Generic Access Profil (GAP) which is static and used by Bluetooth Classic.

GATT has many forms of which one is Internet Protocol Support Profile (IPSP) (Beware of HTTP Proxy Service (HPS) which is something completely different

Picture http://blog.bluetooth.com/~/media/images/blog%20images/migrated/smarthomerouter-01.ahsx (IPv6-BLE switch -> Gateway -> IPv6-Wifi-Bulb == All Native IPv6)

Command for setting what I am (IPSP)

 lsmod | grep 6lo
 modprobe bluetooth_6lowpan
 echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
 modprobe bluetooth_6lowpan
 lsmod | grep 6lo
   bluetooth_6lowpan 24576 0
   6lowpan 36864 8 nhc_udp,nhc_routing,nhc_mobility,bluetooth_6lowpan,nhc_fragment,nhc_dest,nhc_hop,nhc_ipv6
   bluetooth 552960 32 btrtl,bluetooth_6lowpan,btintel,bnep,btbcm,rfcomm,btusb
   ipv6                  401548  29 6lowpan
 hciconfig hci0 lestates
   YES Non-connectable Advertising State
   < 20 more lines >
 
 hciconfig hci0 leadv
   LE set advertise enable on hci0 returned status 12
> #hciconfig hci0 lestates 
> Read LE supported states on hci0 returned status 12  

Yep, 0x0c or 12 is for unsupported command. So the fw doesn't seem to  have support for LE. 
Let me get back to you on this, need to check up what fw is upon the repository. 
Note
   If using a Linux kernel version less than 4.0, the kernel debug file 6lowpan_enable will not be present. 
   Instead you should use "echo 35 > /sys/kernel/debug/bluetooth/6lowpan_psm" to set PSM channel as 0x23 (35),
   and enable the bluetooth 6lowpan module.

Command for viewing other end capabilities (IPSP ??)

 hcitool lescan
 LE Scan ...
 CB:AF:14:57:D8:6E (unknown)
 CB:AF:14:57:D8:6E Test IPSP node
  \-- from http://docs.zephyrproject.org/samples/bluetooth/ipsp/README.html

Local setup: NOT WORKING !!

#!/bin/sh
. ./ibeacon.conf
echo "Launching virtual iBeacon..."
sudo hciconfig $BLUETOOTH_DEVICE up
sudo hciconfig $BLUETOOTH_DEVICE noleadv
sudo hciconfig $BLUETOOTH_DEVICE leadv 0
sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 $UUID $MAJOR $MINOR $POWER 00 00 00 00 00 00 00 00 00 00 00 00 00
echo "Complete"

Setting an IPv6 address

following the lowpan 802.15.4 blog

  • add
    apt-get install libnl-3-dev
  • This is a strange page
    https://devzone.nordicsemi.com/f/nordic-q-a/14292/iot-sdk-rpi3---using-jessie-with-bluetooth_6lowpan
    • that says:
      root@raspberry:/home/pi#
      root@raspberry:/home/pi# lsmod | grep 6lo
      root@raspberry:/home/pi# modprobe bluetooth_6lowpan
      root@raspberry:/home/pi# echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
      root@raspberry:/home/pi# modprobe bluetooth_6lowpan
      root@raspberry:/home/pi# lsmod | grep 6lo
      bluetooth_6lowpan 24576 0
      6lowpan 36864 8 nhc_udp,nhc_routing,nhc_mobility,bluetooth_6lowpan,nhc_fragment,nhc_dest,nhc_hop,nhc_ipv6
      bluetooth 552960 32 btrtl,bluetooth_6lowpan,btintel,bnep,btbcm,rfcomm,btusb
      root@raspberry:/home/pi#

Now to establish my Bluetooth connection between the Raspberry Pis I run though the following steps: On the Master device I run the following commands:

#need root access
sudo su

#enable 6lowpan over Bluetooth le
echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable

#start advertising Bluetooth LE service
hciconfig hci0 leadv

On the Slave device I run the following commands:

#need root access
sudo su

#enable 6lowpan over Bluetooth le
echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable

#establish le connection to master
hcitool lecc 5C:F3:70:XX:XX:XX

The hcitool lecc command always returns “Connection Handle 64”. At this point I have a stable connection between the two devices that I can verify using the hcitool con command.

I am now able to run the following command on either the master or the slave where the mac address is the address for the Bluetooth device I am connecting too:

echo “connect 5C:F3:70:XX:XX:XX 1” > /sys/kernel/debug/bluetooth/6lowpan_control

Whichever Raspberry Pi I run the command on establishes a 6lowpan connection and if I run the ifconfig command I see a new bt0 device.

Programming in python

Windows 10: Check BLE Version

Deltaco-CSR-DeviceManager.png
The LMP versions correspond to Bluetooth versions as follows:

   LMP 0.x - Bluetooth 1.0b
   LMP 1.x - Bluetooth 1.1
   LMP 2.x - Bluetooth 1.2
   LMP 3.x - Bluetooth 2.0 + EDR
   LMP 4.x - Bluetooth 2.1 + EDR
   LMP 5.x - Bluetooth 3.0 + HS
   LMP 6.x - Bluetooth 4.0
   LMP 7.x - Bluetooth 4.1
   LMP ​8.x - ​Bluetooth 4.2
   LMP 9.x - Bluetooth 5.0          
Source: https://superuser.com/questions/502825/how-can-i-find-out-what-version-of-bluetooth-my-laptop-supports

==LÄNKAR==Bluetooth 5 for rPI 3 ?!?: http://blog.bluetooth.com/bluetooth-developer-starter-kit-50

Firmware


+Start advertising with EIR data (__Linux only__):
+
+    var scanData = new Buffer(...); // maximum 31 bytes
+    var advertisementData = new Buffer(...); // maximum 31 bytes
+
+    bleno.startAdvertisingWithEIRData(advertisementData, scanData[, callback(error)]);
+
+  * For EIR format section [Bluetooth Core Specification](https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=229737) sections and 8 and 18 for more information the data format.
  • från tysk sida

https://forum.fhem.de/index.php?topic=68019.15


Hi und danke erstmal,

bin jetzt soweit mit fast allen befehlen durch 

Code: [Auswählen]
pi@raspberrypi:~ $ ls -l /dev/ser*
lrwxrwxrwx 1 root root 7 Feb 28 23:59 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Feb 28 23:59 /dev/serial1 -> ttyS0

das sieht schon mal gut aus, lt. deinem Howto
allerdings bekomme ich dennoch kein Device : 

Code: [Auswählen]
pi@raspberrypi:~ $ hcitool dev
Devices:
pi@raspberrypi:~ $ hcitool scan
Device is not available: No such device
pi@raspberrypi:~ $ 

glaub bin zu müde oder zu blind.
habt Ihr eine Idee ??

danke


pi@raspberrypi:~ $  systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
   Active: active (running) since Do 2017-03-09 22:05:23 CET; 22s ago
     Docs: man:bluetoothd(8)
 Main PID: 794 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─794 /usr/lib/bluetooth/bluetoothd
pi@raspberrypi:~ $ sudo service bluetooth status
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
   Active: active (running) since Do 2017-03-09 22:05:23 CET; 27s ago
     Docs: man:bluetoothd(8)
 Main PID: 794 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─794 /usr/lib/bluetooth/bluetoothd

pi@raspberrypi:~ $ sudo hciconfig dev
Can't get device info: No such device

pi@raspberrypi:~ $ sudo bluetoothctl
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
No default controller available
[bluetooth]# exit
Agent unregistered


pi@raspberrypi:~ $ dmesg | grep Blue
[   22.873317] Bluetooth: Core ver 2.22
[   22.873369] Bluetooth: HCI device and connection manager initialized
[   22.873381] Bluetooth: HCI socket layer initialized
[   22.873389] Bluetooth: L2CAP socket layer initialized
[   22.873408] Bluetooth: SCO socket layer initialized
[  103.040851] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[  103.040860] Bluetooth: BNEP filters: protocol multicast
[  103.040871] Bluetooth: BNEP socket layer initialized






so alles was mit Bluetooth zu tun hat gelöscht und folgendes getan

Code: [Auswählen]
sudo apt-get install raspberrypi-sys-mods

sudo apt-get --reinstall install pi-bluetooth

sudo shutdown -r now


dann 

Code: [Auswählen]
sudo systemctl start hciuart.service
pi@raspberrypi:~ $ systemctl status hciuart.service
● hciuart.service - Configure Bluetooth Modems connected by UART
   Loaded: loaded (/lib/systemd/system/hciuart.service; disabled)
   Active: active (running) since Fr 2017-03-10 00:17:11 CET; 5s ago
  Process: 951 ExecStart=/usr/bin/btuart (code=exited, status=0/SUCCESS)
 Main PID: 962 (hciattach)
   CGroup: /system.slice/hciuart.service
           └─962 /usr/bin/hciattach /dev/serial1 bcm43xx 460800 noflow -



und siehe da!!!

Code: [Auswählen]
pi@raspberrypi:~ $ hcitool dev
Devices:
	hci0	B8:27:EB:90:BC:6D

es geht!!

danke an alle!

HARDWARE

  1. pSoC
    • Raspberry Pi Zero W
  2. USB Dongle
  3. Intel (List of drivers: https://www.intel.com/content/www/us/en/support/articles/000005559/network-and-i-o/wireless-networking.html)
Personal tools
Namespaces

Variants
Actions
Navigation
Tools