2015/09/03

Intel Edison as a Bluetooth low energy (BLE) peripheral

I have had the chance to play with Intel Edison recently. The goal is to make Intel Edison act as a BLE peripheral. There are nice articles about it and I followed instructions in those pages. But there were some small problems to achieve my goal.


First of all, I flash Edison with the latest firmware; Intel Edison® Board Firmware Software Release 2.1 (edison-image-ww25.5-15.zip). Or uname -a shows
Linux Edison3 3.10.17-poky-edison+ #1 SMP PREEMPT Fri Jun 19 12:06:40 CEST 2015 i686 GNU/Linux
Or /etc/version says
weekly-159
Your Edison might behave differently if different version is running.

To make long story short,


Basic settings including wifi network

# configure-edison --setup


Install software using opkg

Edit /etc/opkg/base-feeds.conf file.
# vi /etc/opkg/base-feeds.conf

Add following lines.
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32

Install systemd-dev and bluez5-dev.
# opkg install systemd-dev
# opkg install bluez5-dev

Install software using npm

# npm -g install async
# npm install noble
# npm install bleno

Enable Bluetooth device

Disable bluetooth daemon (bluetoothd). You need run it only once.
# systemctl disable bluetooth

You have to run these commands every time after boot.
# rfkill unblock bluetooth
# hciconfig hci0 up

Run sample program (echo)

Start node process.
# cd node_moduels/bleno/examples/echo
# node main.js

While a node process is running, open other terminal and down/up hci0 device.
# hciconfig hci0 down
# hciconfig hci0 up

Now, try to connect from other BLE supported device, such as a smartphone. There should be a BLE peripheral named 'echo'. I use an Android application, "BLE scanner". With this app, you can read and write data to/from BLE device, that is quite handy.

Problems


Network interface, usb0

After running configure-edison command, there are two network interfaces; usb0 and wlan0. But I could not connect to Edison using ssh via wifi because the routing table is looks like below.
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.2.253   0.0.0.0         UG        0 0          0 usb0
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 usb0
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 wlan0

I do not need usb0. So disable it.
# ifconfig usb0 down

It deletes default gateway too, so add it again.
# route add default gw default-gateway-IP-address
In my case,
# route add default gw 192.168.2.253

Or you can permanently change usb0's IP address by editing the following file.
# vi /etc/systemd/network/usb0.network


Installing Bleno

When installing Bleno, it installs bluetooth-hci-socket module too. But it requires libudev.h and there is no such file in Edison as default. Thus it failed to install Bleno.
The header file is included in systemd-dev package. And so you need to install it before installing Bleno.

Running Bleno

Before disable bluetoothd, it advertises a name using a host name. If you name your Edison board "my_edison", you will see "my_edison" bluetooth device from other device. After disable bluetoothd (or kill bluetoothd process), the board still advertises using a bluetooth chip name? In my case, "BCM43340B0 37.4 MHz WLBGA_iTR Intel Edison-0122-N".
I am not an expert of Bluetooth and so I do not know a proper solution. But I found the workaround of it. To let Bleno process advertise correctly, hci0 interface needs to be down and up again while Bleno process is running. And so Bleno process can advertise its own name.

0 件のコメント:

コメントを投稿