Saturday, December 26, 2015

It Worked For Me (Sort Of) - Raspberry PI and D-Link DWA-171A1

I recently purchased a D-Link DWA-171A1 Wireless AC Dual Band USB Adapter to use with a Raspberry PI 2 B after seeing a posting that stated that it worked out of the box.  Well…

It didn’t work out of the box but I was able to get it to work by compiling the driver.  I used this code from GitHub on the Raspbian Jessie image dated 11/21/2015

  1. Loaded the Raspbian Jessie image from here: https://www.raspberrypi.org/downloads/raspbian/ Linux raspberrypi (4.1.13-v7+)  to my SD Card.
  2. Added the following packages using apt-get: apt-get install dkms build-essential bc
  3. Downloaded and unzip the driver from abperiasamy/rtl8812AU_8821AU_linux GitHub repository:  https://github.com/abperiasamy/rtl8812AU_8821AU_linux/archive/master.zip
  4. Download the appropriate kernel headers for your version of Raspbian.  I found the ones I needed here: https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/.
  5. Install the headers using sudo dpkg –i <package name>.deb.
  6. cd to the directory you unziped the driver into.
  7. Using nano or some other editor update the Makefile:
  8. CONFIG_PLATFORM_I386_PC = n
    CONFIG_PLATFORM_ARM_RPI = y
  9. The using the following commands build and install the driver.
  10. # sudo make clean
    # sudo make
    # sudo make install
    # sudo modprobe -a 8812au
You should now see the DWA-171 as a wireless interface and should be able to configure it.
I tried the same procedure using a Raspberry Pi B running Arch Linux with a 3.12.26-1-ARCH kernel and wasn’t able to get the driver to compile.
Thanks to all those who made resources available to help me along this journey.

Thursday, December 24, 2015

Project Raspberry Pi Music Player

Two weeks ago my wife informed me that the CD player attached to our stereo wasn’t working.  After a tinkering with it for a while, I decided that I wasn’t going to be able to fix it.

Over the years, we have moved from playing CDs to listening to music using computers, tablets and MP3 players.  The one time where we use the CD player is during the Holidays.

So now the holidays were almost upon us and no CD player.

I decided that this would be an opportunity to put one of the many single board computers (SBCs) to use.  I had a Raspberry PI B that I have been using in various projects over the past several years.  I had recently added a Raspberry Pi 2 B and a Raspberry Pi Zero so I figured I could turn the older system into a music player.

I figured correctly that given the huge community around the Pi that there would be at least a couple of options.  As it turned out I was not disappointed.

There are a number of options for music players for the Pi.  I checked out four of them installing three before finalizing on one.

The fist three volumio, rune, and Moode have the same look and feel as they came out of the RaspFi project and utilize the Music Player Daemon (MPD).  Pi MusicBox comes from a different lineage and has a different look and feel.

I installed all three RaspFi based versions.  There is one major difference between rune audio Player and volumio / Moode and that is that it is based on Arch Linux where as volumio and Moode based on Raspberian.  All three offer SD card images that can be downloaded, written to an SD card and insterted in the Pi and have you up and running in less than an hour.

These programs all support the Pi’s onboard audio as well as specialty Pi audio i2s audio boards as well as usb audio.  For my installation I am using the onboard audio.  With this setup I just needed a 3.5mm to RCA cable which I connected into my stereo receiver.

I started with volumio and had some success but the player ui would stall and leave me with spinning arrows.  I moved to rune audio Player and it was a much better experience.  I had some problems at first and that led me to check out Moode, but I didn’t like the ui as much and decided to go back and look at solving my problems with rune.

The first problem I had with rune was that songs would cut out.  Doing some network testing I determined that my wifi connection would drop occasionally and that caused the drop outs. The solution to this was to move the songs locally.  At fist moving the songs locally didn’t solve my problem.  Song continued to cut out.  I determined that the usb drive I was using was periodically resetting.  I moved to another usb drive and the problem went away.

I have been running rune for about a week now and am pretty happy with it.  I will detail my build over the next couple of days and post it here.

Wednesday, July 22, 2015

TI SimpleLink SensorTag 2015 - Development Environment Guide

Gerard at 43oh has posted an excellent guide for setting up the development environment for the CC2650STK.  I highly recommend that you check it out before you attempt to install Code Composer Studio.

image

Sunday, July 12, 2015

TI SimpleLink SensorTag 2015 - Python

Code for these examples is on GitHub in the dhSensorTag2015 repository.

Having successfully accessed data on the sensor tag I decided to try my hand at programmatically accessing data from the sensor tag.  I started out with the same two examples I had developed in bash: 1) to get the device name; and 2) get the humidty reading from the humidity sensor.

Surprisingly there are not too many options when it comes to Bluetooth Low Engergy APOs for Windows 7 or Linux. One of the few that exists is Ian Harvey’s bluepy for python on Linux.

Python isn’t something I use very much.  I do most of my work in Perl and C with a bit of Java thrown in for Android.  Fortunately there are a set of pretty good set of instructions for setting up bluepy on the Raspberry Pi that can be found at: http://www.elinux.org/RPi_Bluetooth_LE.  The output from these instructions is below:

pi@raspberrypi ~ $ git clone https://github.com/IanHarvey/bluepy.git
Cloning into 'bluepy'...
remote: Counting objects: 459, done.
remote: Total 459 (delta 0), reused 0 (delta 0), pack-reused 459
Receiving objects: 100% (459/459), 1.51 MiB | 556 KiB/s, done.
Resolving deltas: 100% (172/172), done.
pi@raspberrypi ~ $ cd bluepy/bluepy
pi@raspberrypi ~/bluepy/bluepy $ make
gcc -L. -O0 -g -DHAVE_CONFIG_H -I../bluez-5.4/attrib -I../bluez-5.4 -I../bluez-5.4/lib -I../bluez-5.4/src -I../bluez-5.4/gdbus -I../bluez-5.4/btio `pkg-config glib-2.0 dbus-1 --cflags` -o bluepy-helper bluepy-helper.c ../bluez-5.4/lib/bluetooth.c ../bluez-5.4/lib/hci.c ../bluez-5.4/lib/sdp.c ../bluez-5.4/lib/uuid.c ../bluez-5.4/attrib/att.c ../bluez-5.4/attrib/gatt.c ../bluez-5.4/attrib/gattrib.c ../bluez-5.4/attrib/utils.c ../bluez-5.4/btio/btio.c ../bluez-5.4/src/log.c `pkg-config glib-2.0 --libs`
pi@raspberrypi ~/bluepy/bluepy $ python btle.py B0:B4:48:B9:2C:82

Running the script generates the a dump of the services and characteristics.

Connecting to: B0:B4:48:B9:2C:82, address type: public
Service <uuid=Generic Access handleStart=1 handleEnd=7> :
    Characteristic <Device Name>, supports READ
    -> 'SensorTag 2.0'
    Characteristic <Appearance>, supports READ
    -> '\x00\x00'
    Characteristic <Peripheral Preferred Connection Parameters>, supports READ
    -> 'P\x00\xa0\x00\x00\x00\xe8\x03'
Service <uuid=f000aa70-0451-4000-b000-000000000000 handleStart=63 handleEnd=70> :
    Characteristic <f000aa71-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00'
    Characteristic <f000aa72-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa73-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'P'
Service <uuid=f000ac00-0451-4000-b000-000000000000 handleStart=81 handleEnd=88> :
    Characteristic <f000ac01-0451-4000-b000-000000000000>, supports NOTIFY READ WRITE
    -> '\x00\x00'
    Characteristic <f000ac02-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x02\x02\x00\x00\x00'
    Characteristic <f000ac03-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00D'
Service <uuid=Generic Attribute handleStart=8 handleEnd=11> :
    Characteristic <Service Changed>, supports INDICATE
Service <uuid=ffe0 handleStart=71 handleEnd=75> :
    Characteristic <ffe1>, supports NOTIFY
Service <uuid=f000aa64-0451-4000-b000-000000000000 handleStart=76 handleEnd=80> :
    Characteristic <f000aa65-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x7f'
    Characteristic <f000aa66-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
Service <uuid=f000aa00-0451-4000-b000-000000000000 handleStart=31 handleEnd=38> :
    Characteristic <f000aa01-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00'
    Characteristic <f000aa02-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa03-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'd'
Service <uuid=f000ffc0-0451-4000-b000-000000000000 handleStart=97 handleEnd=65535> :
    Characteristic <f000ffc1-0451-4000-b000-000000000000>, supports NOTIFY WRITE NO RESPONSE WRITE
    Characteristic <f000ffc2-0451-4000-b000-000000000000>, supports NOTIFY WRITE NO RESPONSE WRITE
Service <uuid=f000aa20-0451-4000-b000-000000000000 handleStart=39 handleEnd=46> :
    Characteristic <f000aa21-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00'
    Characteristic <f000aa22-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa23-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'd'
Service <uuid=Device Information handleStart=12 handleEnd=30> :
    Characteristic <System ID>, supports READ
    -> '\x82,\xb9\x00\x00H\xb4\xb0'
    Characteristic <Model Number String>, supports READ
    -> 'CC2650 SensorTag\x00'
    Characteristic <Serial Number String>, supports READ
    -> 'N.A.\x00'
    Characteristic <Firmware Revision String>, supports READ
    -> '1.01 (Mar 13 2015)\x00'
    Characteristic <Hardware Revision String>, supports READ
    -> 'PCB 1.2\x00'
    Characteristic <Software Revision String>, supports READ
    -> 'N.A.\x00'
    Characteristic <Manufacturer Name String>, supports READ
    -> 'Texas Instruments\x00'
    Characteristic <IEEE 11073-20601 Regulatory Cert. Data List>, supports READ
    -> '\xfe\x00experimental'
    Characteristic <PnP ID>, supports READ
    -> '\x01\r\x00\x00\x00\x10\x01'
Service <uuid=f000aa80-0451-4000-b000-000000000000 handleStart=55 handleEnd=62> :
    Characteristic <f000aa81-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    Characteristic <f000aa82-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00\x02'
    Characteristic <f000aa83-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'n'
Service <uuid=f000ccc0-0451-4000-b000-000000000000 handleStart=89 handleEnd=96> :
    Characteristic <f000ccc1-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '6\x00\x00\x00d\x00'
    Characteristic <f000ccc2-0451-4000-b000-000000000000>, supports WRITE
    Characteristic <f000ccc3-0451-4000-b000-000000000000>, supports WRITE
Service <uuid=f000aa40-0451-4000-b000-000000000000 handleStart=47 handleEnd=54> :
    Characteristic <f000aa41-0451-4000-b000-000000000000>, supports NOTIFY READ
    -> '\x00\x00\x00\x00\x00\x00'
    Characteristic <f000aa42-0451-4000-b000-000000000000>, supports READ WRITE
    -> '\x00'
    Characteristic <f000aa44-0451-4000-b000-000000000000>, supports READ WRITE
    -> 'd'

At this point I created a directory SensorTag2015 off my home directory to work in.  I copied the bluepy python files into a subdirectory bluepy.  This gave me a setup that looked like this.

image

In the SensorTag2015 directory I created and ran my python examples.  I started with a very simple script that expects an address for the sensor tag on the command line.

pi@raspberrypi ~/SensorTag2015 $ python getDeviceName.py 00:00:00:00:00:00
SensorTag 2.0
pi@raspberrypi ~/SensorTag2015 $

The script imports two methods from the bluepy.btle fileand then it defines a UUID for the device name.  It checks to make sure that at least one argument is passed and then establishes a connection to the sensor tag.  If the script fails to connect to the sensor tag check to make sure that the sensor tag is advertising.  If it isn't push the left button and check that the green LED is flashing.  Once connected the script checks to make sure that the device name characteristic is readable, reads it and prints it out.

getDeviceName.py

import sys
from bluepy.btle import UUID, Peripheral

temp_uuid = UUID(0x2A00)

if len(sys.argv) != 2:
  print "Fatal, must pass device address:", sys.argv[0], ""
  quit()

p = Peripheral(sys.argv[1])

try:
    ch = p.getCharacteristics(uuid=temp_uuid)[0]
    if (ch.supportsRead()):
            print ch.read()

finally:
    p.disconnect()

Next I developed a slightly more complicated script for reading the Humidity sensor.  The template I developed with this script is what I used for most of the examples.

The script expects the address of the sensor tag to be passed on the command line as with the script above.  Then it defines TI unique UUIDs to configure the sensor and to get data from the sensor.  Next it sets up the values that get written to the sensor's configure UUID to turn the sensor on or off.  Note you must turn a sensor on before you are able to read it and get values other than zero back.

After these variables are setup the script connects to the sensor tag.  Once connected the script writes the value to turn on the sensor to the configuration UUID.  Then it reads the raw data from the sensor tag, converts it to values and calculates the sensor value.  The formulas for calculating the sensor values were pulled from the Android App source code. After the values are printed out the script turns of the sensor and disconnects from the device.

getHumidity.py

#
# TI SimpleLink SensorTag 2015
# Date: 2015 07 06
#
# Sensor: Humidity Temperature
# Values: Temperature and Humidity
#
import struct, sys, traceback
from bluepy.btle import UUID, Peripheral, BTLEException

def TI_UUID(val):
    return UUID("%08X-0451-4000-b000-000000000000" % (0xF0000000+val))

config_uuid = TI_UUID(0xAA22)
data_uuid = TI_UUID(0xAA21)

sensorOn  = struct.pack("B", 0x01)
sensorOff = struct.pack("B", 0x00)

if len(sys.argv) != 2:
  print "Fatal, must pass device address:", sys.argv[0], ""
  quit()

try:
  print "Info, trying to connect to:", sys.argv[1]
  p = Peripheral(sys.argv[1])

except BTLEException:
  print "Fatal, unable to connect!"
  
except:
  print "Fatal, unexpected error!"
  traceback.print_exc()
  raise

else:

  try:
    print "Info, connected and turning sensor on!"
    ch = p.getCharacteristics(uuid=config_uuid)[0]
    ch.write(sensorOn, withResponse=True)
    
    print "Info, reading values!"
    ch = p.getCharacteristics(uuid=data_uuid)[0]
    
    # IR Temperature sensor returns 4 bytes object(LSB),
    # object(MSB), ambient(LSB) and ambient(MSB).
    # Python unpack using "<" which denotes little-endian format
    # and "hh" which denotes 2 unsigned short (2 byte/16 bit) values.
    rawVals=ch.read()
    #(tempVal, humidVal) = struct.unpack('<HH', ch.read())
    tempVal = (ord(rawVals[1])<<8)+ord(rawVals[0])
    humidVal = (ord(rawVals[3])<<8)+ord(rawVals[2])
    
    #object temp and ambient temp are calculated as shown below
    print "Temp: %.2f F" % float((tempVal / 65536.0 * 165 - 40) * 1.8 + 32)
    print "Humidity: %.2f %%RH" % float(humidVal / 65536.0 * 100)
    
    print "Info, turning sensor off!"
    ch = p.getCharacteristics(uuid=config_uuid)[0]
    ch.write(sensorOff, withResponse=True)
    
  except:
    print "Fatal, unexpected error!"
    traceback.print_exc()
    raise

  finally:
    print "Info, disconnecting!"
    p.disconnect()
    
finally:
  quit()

On GitHub in the dhSensorTag2015 repository you will find these examples as well as additional examples to read the other sensors. 

A couple of things to bear in mind with these examples:

  • These examples were written using python 2.7.10 and were developed using V1.12 (Jun 23 2015) of TI’s firmware.
  • The barometer example calculation in the Andriod App doesn’t appear to be correct and therefore the example uses an updated calculation.
  • Data from all of the sensor examples, except the movement sensor, has been validated.

Friday, July 3, 2015

TI SimpleLink SensorTag 2015 - Reading Temperature and Humidity

Next up we are going to read the temperature and humidity from the HC1000 Humidity Sensor.  Each of the sensors that are accessible on the sensor tag has a GATT Service defined for it.  Below is the Humidity Service.

Handle Type Type (text) GATT Server Description/Value (text)
(hex) (hex) Permissions
0x27 0x2800 GATT Primary Service Declaration R Humidity Service
0x28 0x2803 GATT Characteristic Declaration R Humidity Data
0x29 0xAA21 Humidity Data RN TempLSB:TempMSB:HumidityLSB:HumidityMSB
0x2A 0x2902 Client Characteristic Configuration RW Write "01:00" to enable notifications, "00:00" to disable
0x2B 0x2803 GATT Characteristic Declaration R Humidity Config
0x2C 0xAA22 Humidity Config RW Write "01" to start measurements, "00" to stop
0x2D 0x2803 GATT Characteristic Declaration R Humidity Period
0x2E 0xAA23 Humidity Period RW Period = [Input*10] ms, (lower limit 100 ms), default 1000 ms

Before you can read a sensor value from the service you must turn it on.  For the Humidity Service this is done by writing a 01 to the handle at 0x2C labeled in the table above as Humidity Config.  Once you have turned on the Humidity Service you will read values from the handle at 0x29 labeled Humidity Data.

Referring to the table above we see that four values will be returned from left to right:

  1. Temp(LSB) - The least significant byte of the temperature data in hex.
  2. Temp(MSB) - The most significant byte of the temperature data in hex.
  3. Humidity(LSB) - The least significant byte of the humidity data in hex.
  4. Humidity(MSB) - The most significant byte of the humidity data in hex.

On page 14 of data sheet for the HC1000 Humidity Sensor are the formulas for converting this data into a temperature reading and a humidity reading.

  • Temperature in Celsius = (Temp(MSB) * 0x100 + Temp(LSB)) / 65536 * 165 – 40
  • Humidity = (Humidity(MSB) * 0x100 + Humidity(LSB)) / 65536 * 100

To get the values for the temperature and humidity readings follow the steps below.  In this example the values returned are 64 66 0c a2.

pi@raspberrypi ~ $ gatttool -b B0:B4:48:B9:2C:82 -I
[B0:B4:48:B9:2C:82][LE]> connect
Attempting to connect to B0:B4:48:B9:2C:82
Connection successful
[B0:B4:48:B9:2C:82][LE]> char-write-req 0x2C 01
Characteristic value was written successfully
[B0:B4:48:B9:2C:82][LE]> char-read-hnd 0x29
Characteristic value/descriptor: 64 66 0c a2
[B0:B4:48:B9:2C:82][LE]> char-write-req 0x2C 00
Characteristic value was written successfully
[B0:B4:48:B9:2C:82][LE]> disconnect
[B0:B4:48:B9:2C:82][LE]> exit

The resulting temperature is:

(0x66 * 0x100 + 0x64) / 65536 * 165 – 40 = 26.19 C

The resulting humidity is:

(0xa2 * 0x100 + 0x0C) / 65536 * 100 = 63.30%

Below is a bash script that will perform the commands above and calculate the temperature and humidity.

getTempHumidity.sh

#!/bin/bash
if [ "$#" != 1 ]; then
  echo "Need to pass BLE Address $0 <BLE Address>"
else
  echo "Turning on Temperature and Humidity Sensor"
  gatttool -b $1 --char-write-req --handle=0x2C --value=01
  echo "Getting Temperature and Humidity"
  for i in `seq 1 10`;
  do
    sleep 1
    str=`gatttool -b $1 --char-read --handle=0x29`
    # Discard everything up to and including the ": " in the

    # gatttool response.  Put the four bytes returned into an
    # array. Then swap the bytes and put the results in a variable. 
    #
Use bc to compute the temp and humdity.
    IFS=' ' read -a array <<< ${str#*: }
    temp="0x${array[1]}${array[0]}"
    temp=$((temp))
    humidity="0x${array[3]}${array[2]}"
    humidity=$((humidity))
    printf "temp: %s, humidity: %s\n" \
      `echo "scale=4; ($temp/65536*165-40)*1.8+32" | bc -l` \
      `echo "scale=4; ($humidity*1.0/65536.0)*100.0" | bc -l`
  done
  echo "Turning off Temperature and Humidity Sensor"
  gatttool -b $1 --char-write-req --handle=0x2C --value=00
fi

TI SimpleLink SensorTag 2015 - Reading the Device Name

In the last post we reviewed setting up a Raspberry Pi with Bluetooth to access the sensor tag.  We finished up by successfully performing a Bluetooth Low Energy scan which saw the sensor tag and returned the address.

In this post we will walk through reading and writing to the sensor tag using gatttool which is provided as part of the bluez Bluetooth stack.

Reading the Sensor Tag’s Device Name

As discussed in the previous post you will need to make sure your sensor tag is advertising.  When advertising the green LED visible on the back of the sensor tag will be blinking.  If it isn’t blinking try removing and reinstalling the battery.  If that doesn’t work replace the battery.

In the example below the hcitool lescan function is used to find the sensor tag.  It reports back the sensor tag’s address shown in green below.  Once you have the sensor tag’s address you should run gatttool providing –b and the address and a –I.  The –b tells gatttool that the next set of numbers is the address of the device you want to use.  The –I is for interactive mode.  gatttool has both an interactive mode and a command line mode.

As you can see the steps start with connecting to the device.  If the connect fails it could be because you waited too long and the sensor tag exited advertise mode or it could be that you have a version of gatttool that doesn’t work.  Put the sensor tag back into advertise mode, make sure the green LED is blinking and try to connect again.  If it fails this time it is most likely problem with gatttool.

Once you successfully connect to the sensor tag the green LED will stop flashing.  Enter the char-read-hnd command which stands for read characteristic by handle for handle 0x3 which is the device name.  You should get back the string of numbers below which if you convert from ascii values to characters spells SensorTag 2.0.

Disconnect from the sensor tag and the green LED should start blinking again and exit gatttool.

pi@raspberrypi ~ $ sudo hcitool lescan
LE Scan ...
B0:B4:48:B9:2C:82 (unknown)
B0:B4:48:B9:2C:82 CC2650 SensorTag
^C
pi@raspberrypi ~ $ gatttool -b B0:B4:48:B9:2C:82 -I
[B0:B4:48:B9:2C:82][LE]> connect
Attempting to connect to B0:B4:48:B9:2C:82
Connection successful
[B0:B4:48:B9:2C:82][LE]> char-read-hnd 0x3
Characteristic value/descriptor: 53 65 6e 73 6f 72 54 61 67 20 32 2e 30
[B0:B4:48:B9:2C:82][LE]> disconnect

[B0:B4:48:B9:2C:82][LE]> exit

Below is a bash script that will perform the commands above and translate the numeric values to their ascii equivalents.

getDeviceName.sh

#!/bin/bash
if [ "$#" != 1 ]; then
  echo "Need to pass BLE Address $0 <BLE Address>"
else
  # Discard everything up to and including the ": " in the
  # gatttool response.  Put the bytes returned into an array. 
  # Convert the bytes to ascii and print out.
  str=`gatttool -b $1 --char-read --handle=0x3`
  IFS=' ' read -a array <<< ${str#*: }
  for element in "${array[@]}"
  do
    printf "\x$(printf "%x" "0x$element")"
  done
  echo
fi

TI SimpleLink SensorTag 2015 - First Steps

After running through the Android (or IOS) App the next step was to manually read and write data from and to the sensor tag.

For this I used a Raspberry PI B running the most current version of Raspbian dated 2015-05-05 downloaded from the Raspberry PI Downloads page and an IOGEAR Bluetooth 4.0 USB Micro Adapter

Raspbian doesn’t have Bluetooth support loaded. Unfortunately, the version that is currently in the repository doesn’t have a working copy of gatttool.  As a result you will need both install Bluetooth using apt-get and build bluez from source.

pi@raspberrypi ~ $ sudo apt-get install --no-install-recommends bluetooth
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  bluez libcap-ng0
Recommended packages:
  bluez-alsa bluez-cups bluez-gstreamer
The following NEW packages will be installed:
  bluetooth bluez libcap-ng0
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/945 kB of archives.
After this operation, 2,203 kB of additional disk space will be used.
Do you want to continue [Y/n]?
Selecting previously unselected package libcap-ng0.
(Reading database ... 78835 files and directories currently installed.)
Unpacking libcap-ng0 (from .../libcap-ng0_0.6.6-2_armhf.deb) ...
Selecting previously unselected package bluez.
Unpacking bluez (from .../bluez_4.99-2_armhf.deb) ...

<messages removed to save space>

pi@raspberrypi ~ $ sudo service bluetooth status
[ ok ] bluetooth is running.

pi@raspberrypi ~ $

Bluez source can be downloaded from https://www.kernel.org/pub/linux/bluetooth/.  At the time I am writing this July 3, 2015 the current version is 5.31 which built find on the most recent release of Raspbian. 

Follow the commands below to build bluez.  While you need to build bluez you don’t need to install what you build.  You just need to copy the new version of gatttool to /usr/bin and you should be set to go.

pi@raspberrypi ~ $ sudo apt-get install --no-install-recommends bluetooth
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  bluez libcap-ng0
Recommended packages:
  bluez-alsa bluez-cups bluez-gstreamer
The following NEW packages will be installed:
  bluetooth bluez libcap-ng0
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 945 kB of archives.
After this operation, 2,203 kB of additional disk space will be used.
Do you want to continue [Y/n]?
Get:1
http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcap-ng0 armhf 0.6.6-2 [12.3 kB]
Get:2
http://mirrordirector.raspbian.org/raspbian/ wheezy/main bluez armhf 4.99-2 [895 kB]

<messages removed to save space>

Setting up libcap-ng0 (0.6.6-2) ...
Setting up bluez (4.99-2) ...
[ ok ] Reloading system message bus config...done.
[ ok ] Starting bluetooth: bluetoothd rfcomm.
Setting up bluetooth (4.99-2) ...
pi@raspberrypi
~ $ wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.31.tar.xz
--2015-07-03 20:23:58--  https://www.kernel.org/pub/linux/bluetooth/bluez-5.31.tar.xz
Resolving www.kernel.org (www.kernel.org)... 198.145.20.140, 199.204.44.194, 149.20.4.69, ...
Connecting to www.kernel.org (www.kernel.org)|198.145.20.140|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1631664 (1.6M) [application/x-xz]
Saving to: `bluez-5.31.tar.xz'

100%[======================================>] 1,631,664    756K/s   in 2.1s

2015-07-03 20:24:08 (756 KB/s) - `bluez-5.31.tar.xz' saved [1631664/1631664]
pi@raspberrypi ~ $ tar xf bluez-5.31.tar.xz
pi@raspberrypi ~ $ cd bluez-5.31/
pi@raspberrypi ~/bluez-5.31 $ ./configure --disable-systemd
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes

<messages removed to save space>

config.status: creating lib/bluez.pc
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
pi@raspberrypi ~/bluez-5.31 $ make
  GEN      lib/bluetooth/bluetooth.h
  GEN      lib/bluetooth/hci.h
  GEN      lib/bluetooth/hci_lib.h
  GEN      lib/bluetooth/sco.h
  GEN      lib/bluetooth/l2cap.h
  GEN      lib/bluetooth/sdp.h
  GEN      lib/bluetooth/sdp_lib.h
  GEN      lib/bluetooth/rfcomm.h

<messages removed to save space>

CC       tools/obex-server-tool.o
CCLD     tools/obex-server-tool
CC       tools/bluetooth-player.o
CCLD     tools/bluetooth-player
CC       tools/obexctl.o
CCLD     tools/obexctl
CC       tools/hid2hci.o
CCLD     tools/hid2hci
GEN      tools/97-hid2hci.rules
pi@raspberrypi ~/bluez-5.31 $sudo cp ./attrib/gatttool /usr/bin/

There are two tools that you will be using with your write data to the sensor tag. 

  • hcitool is the primary command line tool for configuring Bluetooth connections.  It is used to scan for your sensor tag.
  • gatttool is a tool that provides command line access to GATT Services on a Bluetooth Low Energy device.

To scan the sensor tag you will need to make sure that it is advertising. When the sensor tag is advertising there is a green led that flashes.  The led can be seen if you turn the sensor tag over.  It will is in the right window in the green circle.  If it is not flashing then you will need to press the round button on the right side of the sensor tag shown in the yellow circle.   If it doesn’t try removing and reinstalling the battery.  If that doesn’t work replace the battery.

SLST2-Left_thumb1 SLST2-Front_thumb1 SLST2-Right01_thumb1 SLST2-Back01_thumb1

Left

Front

Right

Back

Once you have the sensor tag broadcasting go to your terminal window and type the hcitool command below.

pi@raspberrypi ~ $ sudo hcitool lescan
LE Scan ...
B0:B4:48:B9:2C:82 (unknown)
B0:B4:48:B9:2C:82 CC2650 SensorTag
^C
pi@raspberrypi ~ $

After a second you should see your sensor tag print out on your terminal.  Once it has you can enter a ^C to stop the scan.  For the next step you will need the address of you sensor tag which is highlighted in green above.

Congratulations you have now successfully scanned your sensor tag.  Next up reading data from the sensor tag.

Tuesday, June 30, 2015

TI SimpleLink SensorTag 2015

I recently came across the TI’s latest SimpleLink SensorTag and was immediately intrigued.  Here is a device that for $29 gets you Bluetooth Smart packaged with a microcontroller and 10 sensors in a compact package all powered by a CR2032 coin cell.

I decided to pick on up along with the $15 Debug DevPack.  They arrived this past Friday and I took some time over the weekend to start looking them over.

SimpleLinkBoxes_thumb1

The initial setup is about as easy as it gets.  Open the box, pull the battery tab and download software from Google Play for Android or iTunes for Apple IOS.  In my case I installed the Android app on my Nexus 7 2013 and was off an running.

sensorTag app from android


The Android allows you to access a number of the sensors and get real-time data from them.  It also allows you to perform over the air firmware upgrades.  It is a great launching point for getting to know the SimpleLink SensorTag better.

More to follow…

Saturday, June 20, 2015

It Worked For Me - Arduino Pro Mini DTR Reset Fix

I am not sure what happened but all of a sudden the DTR Reset on one of my Arduino Pro Mini boards stopped working using my 3.3V FTDI Basic.  Using an SN3904 NPN Transistor I was able to get it working again.

ArduinoMiniProReset_bb

ArduinoMiniProReset_schem

Tuesday, March 31, 2015

It Worked for Me - An Webserver under FreeRTOS on an ESP8266

If you are looking for a webserver to run on an ESP8266 using the FreeRTOS SDK the httpserver_raw server in the contrib-1.4.1.zip file is worth a look.

It compiles and runs using the Unofficial Development Kit for Espressif ESP8266 under Cygwin64 on Windows 7.

The zip file is located at: http://download.savannah.gnu.org/releases/lwip/.

image

Sunday, March 22, 2015

ESP8266 Program Examples

Back in December I had ordered and received an Olimex MOD-WIFI-ESP8266-DEV.  I posted some overview and setup information.

Now I have developed some examples that demonstrate native programming of the ESP8266 in c. The examples were built on Windows using Cygwin64 and the Unofficial Development Kit for Expressif ESP8266.

The examples contain a good bit of documentation in the hopes that they will help other people with their projects.

The basic flow of an ESP8266 program using the Espressif SDK is an event / callback model.  The user defines a set of callbacks in user_init.c.  The callbacks are triggered when events such as a timer also setup in user_init.c expires. 

Another example is a callback that is triggered when a connection is made to the ESP8266 by a client.  This callback can take action based on the connection and may in turn setup additional callbacks.

The example code is on GitHub at digitalhack / dhESP8266.

Hello Digitalhack Example

The first example is a take on the standard helloworld.  I demonstrates use of the user_init.c function for setting up the program, a timer and timer callback function ands printing output to UART0 and UART1.

UART0 is a full UART with both TX and RX that is used to load your code to the ESP8266.  UART1 only has a TX signal and is used for debug messages.

Screen capture from Cygwin of make and flashing the code to the esp8266.

image

UART0 Output from Example

image

UART1 Output from Example

image

Basic Connect Example

This example shows how to setup the ESP8266 to connect to a wireless access point.  The ssid and password for the wireless network are in user_config.h in the examples include file.

UART1 Output from Example

image

Once you see the ip address the EXP8266 has acquired on the debug line (UART1) you should be able to ping the ip address and get a response.

image

Simple Server Example

This example shows how to setup a very simple server.  When a user telnets to the ESP8266 they are prompted for a name.  Once this is entered it is echoed name back to the user before disconnecting.  It demonstrates the callbacks necessary to for TCP communication.

UART1 Output from Example

image

Cygwin screen capture of a session.

image

The example code is on GitHub at digitalhack / dhESP8266.

Saturday, March 7, 2015

pcDuino3 Nano / OpenMediaVault - Setup Windows File Sharing

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

Once you have successfully installed OpenMediaVault you will need a basic configuration to be able to use it. Below is a set of steps that will provide you with basic file sharing for Windows.  You will setup a share named testshare which can be accessed by user testuser using password test123. 

These steps are just to get you started.  The resulting configuration isn’t secure and shouldn’t be used except as a starting point.

To get started enter the IP address of your pcDuino3 Nano OpenMediaVault server.  You will get prompted to login.  Enter username: admin and password: openmediavault and then select the Login button.

image

The page that will come up provides basic information about your OpenMediaServer.  The first thing to do is set the Hostname and Domain name.  Select Network (1) from the menu on the left.

image

Enter the Hostname (1): testshares and Domain name (2): testnet.local.  The select Save (3).

image

Anytime you change a parameter in OpenMediaVault it will ask you to apply the changes.  To do this  you will select Apply (1) and then Yes (2).

image

A message box informing you that the changes are being applied will be shown.  When that message box goes away the changes will have been applied. 

Note that for the steps subsequent to this I will be omitting these two web pages from the instructions as they are always the same.

image

Once the changes have been applied we will next add a user.  To add users select User (1) from the menu on the left.

image

On the next page select +Add (1) and then Add (2).

image

Enter a Username (1): testuser, Password (2): test123, and Confirm password (3): test123.  Make sure that the users Group is selected as that will give you read and write access to the share we create.  Finally select Save (4).  As stated above you will need to Apply the change, select Yes, and wait for the change to be applied.

image 

After you have applied the changes your user will be show.  The next step is to create a file system on our SATA drive.  To do this select File Systems (1) from the menu on the left.

image

On the web page the appears you will select +Create (1)

image

In the box that is displayed select your device (1).  Your SATA device will likely be the only device to select.  Enter a Label (2): Data and select OK (3).

image

After selecting OK you will be warned that all your data on the device will be lost.  Make sure you don’t have anything on the device you care about and select Yes (2).

image

When the device completes formatting you will be returned to the device page and you will need to mount your device.  Select your device (1) and then select Mount (2).  Next select Apply the changes and select Yes.

image

Your device should now show that it is mounted (1).  Next we will create a shared folder.  To do this select Shared Folders (2).

image

On the Shared Folders page select +Add (1).

image

On the Add shared folder box enter the Name (1): testshare, Volume (2): Data and let everything else default.  Select 3 to create the share.

image

The Shared Folders page will now show you shared folder.  The next step is to enable and configure SMB/CIFS.  To do this select SMB/CIFS from the menu on the left.

image

On the SMB/CIFS Setting Tab Enable (1), enter your Workgroup (2): WORKGROUP and then select Save (3).  You will need to Apply the settings and select Yes to apply.

image

The next step is to setup the share.  On the Shares Tab select +Add (1).

image

Check the Enable box (1) and then select you Shared folder (2): testshares and let the rest default.  Finally select Save, the Apply and Yes.

image

The Shares Tab should now show you Shared folder (1).

image

From your windows host browse your network and you should see the TESTSHARES server (1).  Select the server and logon using Username:testuser and Password: test123.

image

After you authenticate you should be able to see the share you created from your Windows PC.

image

You can find more information on OpenMediaVault at http://www.openmediavault.org/.  The Wiki is especially helpful.

Monday, March 2, 2015

pcDuino3 Nano - Home Server NAS Performance

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

Last week I got a comment on my pcDuino3 Nano – NAS or ??? posting where the commenter had found the pcDuino3 Nano unusable as a NAS due to slow performance and lockups.  As I hadn’t done any testing I decided to run some tests.

For testing I used OpenMediaVault running on Debian Wheezy.  The test machine and the pcDuino3 Nano were connected via Gig LAN ports.  On the pcDuino2 Nano I was using a 2.5 inch SATA drive rated at 72000 RPM and 3.0 Gb/s.  For running the tests I used the Intel NAS Performance Toolkit

I ran 8 passes of the full test suite.  The system never locked up and response time was in line with what I would expect from the board.  It will not win any competitions for speed but it is quite usable.

For comparison I ran 4 passes of the full test suite on my Raspberry PI OpenMediaServer.  The Pi also ran all the tests successfully but with much slower response times.

Below is a summary of the results of the tests.

  pcDiuno3 Nano Raspberry PI
HD Video Playback 18.1 4.1
2x HD Video Playback 16.8 4.3
4x HD Video Playback 16.1 4.5
HD Video Record 24.4 9.4
HD Playback and Record 23.0 5.9
Content Creation 3.9 1.2
Office Productivity 25.3 12.9
File copy to NAS 13.1 6.0
File copy from NAS 30.3 3.9
Dir copy to NAS 3.4 2.8
Dir copy from NAS 6.6 2.9
Photo Album 4.1 2.2

I am working on some posts about configuring OpenMediaVault on the pcDuino3 Nano. I should have them posted in a week or two.

Monday, February 16, 2015

pcDuino3 Nano - OpenMediaVault Install

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

Now that I had a clean Debian root file system the next step was to install OpenMediaVault. This was accomplished by following the steps below.

Install the pre-requisite packages.

root@pcduino3-nano:~# apt-get install build-essential git u-boot-tools texinfo texlive ccache zlib1g-dev gawk bison flex gettext uuid-dev libusb-1.0-0-dev

Add openmediavault to your sources.

root@pcduino3-nano:~# echo "deb http://packages.openmediavault.org/public kralizec main" > /etc/apt/sources.list.d/openmediavault.list

root@pcduino3-nano:~# wget -O - http://packages.openmediavault.org/public/archive.key | apt-key add -

root@pcduino3-nano:~# apt-get update

root@pcduino3-nano:~# apt-get install openmediavault

After you answer Y to the install there will be five screens that will require you to provide input.

Package configuration

┌────────────────────────┤ Postfix Configuration ├────────────────────────┐
│                                                                         │
│ Please select the mail server configuration type that best meets your
│ needs.

│  No configuration:
│   Should be chosen to leave the current configuration unchanged.
│  Internet site:
│   Mail is sent and received directly using SMTP.
│  Internet with smarthost:
│   Mail is received directly using SMTP or by running a utility such
│   as fetchmail. Outgoing mail is sent using a smarthost.
│  Satellite system:
│   All mail is sent to another machine, called a 'smarthost', for
│   delivery.
│  Local only:

│                                 <Ok>
│                                                                         │
└─────────────────────────────────────────────────────────────────────────┘

 

Package configuration

                    ┌──────┤ Postfix Configuration ├───────┐
                    │ General type of mail configuration:  │
                    │                                      │
                    │       No configuration               │
                    │       Internet Site                  │
                    │       Internet with smarthost        │
                    │       Satellite system               │
                    │       Local only                     │
                    │                                      │
                    │                                      │
                    │       <Ok>           <Cancel>        │
                    │                                      │
                    └──────────────────────────────────────┘

 

Package configuration

┌───────────────────────────┤ Configuring mdadm ├───────────────────────────┐
│                                                                           │
│ If the system's root file system is located on an MD array (RAID), it
│ needs to be started early during the boot sequence. If it is located on
│ a logical volume (LVM), which is on MD, all constituent arrays need to
│ be started.

│ If you know exactly which arrays are needed to bring up the root file
│ system, and you want to postpone starting all other arrays to a later
│ point in the boot sequence, enter the arrays to start here.
│ Alternatively, enter 'all' to simply start all available arrays.

│ If you do not need or want to start any arrays for the root file system,
│ leave the answer blank (or enter 'none'). This may be the case if you
│ are using kernel autostart or do not need any arrays to boot.


│                                  <Ok>
│                                                                           │
└───────────────────────────────────────────────────────────────────────────┘

 

Package configuration

                ┌────────────┤ Configuring mdadm ├────────────┐
                │ MD arrays needed for the root file system:  │
                │                                             │
                │ all________________________________________ │
                │                                             │
                │                   <Ok>                      │
                │                                             │
                └─────────────────────────────────────────────┘

 

Package configuration

┌─────────────────────────┤ ProFTPD configuration ├─────────────────────────┐
│ ProFTPD can be run either as a service from inetd, or as a standalone     │
│ server. Each choice has its own benefits. With only a few FTP             │
│ connections per day, it is probably better to run ProFTPD from inetd in   │
│ order to save resources.                                                  │
│                                                                           │
│ On the other hand, with higher traffic, ProFTPD should run as a           │
│ standalone server to avoid spawning a new process for each incoming       │
│ connection.                                                               │
│                                                                           │
│ Run proftpd:                                                              │
│                                                                           │
│                                from inetd                                 │
│                                standalone                                 │
│                                                                           │
│                                                                           │
│                                  <Ok>                                     │
│                                                                           │
└───────────────────────────────────────────────────────────────────────────┘

Once the install completes initialize OpenMediaVault.

root@pcduino3-nano:~# omv-initsystem

Now reboot the system.  When is has rebooted from a web browser on another machine you should be able to login with Username: admin and Password: openmediavault.