Friday, October 6, 2017

Google/Sphinx Speech Recognition using PyAudio and SpeechRecognition module on Raspberry Pi

The following steps show you how to test Google/Sphinx Speech Recognition using PyAudio and SpeechRecognition module on Raspberry Pi using a C-Media USB Microphone.

1. Test USB Microphone

1.A: Use "cat /proc/asound/cards" to check if C-Media USB Microphone is listed.
1.B: Use "alsamixer" to addjust USB Microphone gain
1.C: Use "arecord -D sysdefault:CARD=1 -duration=10 -f cd -vv ~/mic.wav" to record something into mic.wav
1.D: Use "aplay ./mic.wav -D sysdefault:CARD=0" to play mic.wave to verify USB Microphone works fine.

2. Install python3-pip and SpeechRecognition module
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install SpeechRecognition

3. Install PyAudio
sudo apt-get install git
sudo git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo apt-get install python3-dev
cd pyaudio
sudo python3 setup.py install

4. Install flac which would be used by Google Speech Recognition.
sudo apt-get install flac

5. Test PyAudio and SpeechRecognition module using Googole: Using the following python code saved in google.py and run "python3 google.py"

#!/usr/bin/env python3

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
r.energy_threshold = 4000

while True:
  with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

  try:
    print("The audio file contains: " + r.recognize_google(audio))

  except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")

  except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))

6. Setup pocketsphinx
sudo apt-get install swig
sudo apt-get install libpulse-dev
sudo pip3 install pocketsphinx


7. Test PyAudio and SpeechRecognition module using pocketsphinx: Using the following python code saved in sphinx.py and run "python3 sphinx.py"

#!/usr/bin/env python3

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
r.energy_threshold = 4000

while True:
  with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

  try:
    print("Sphinx thinks you said " + r.recognize_sphinx(audio))
  except sr.UnknownValueError:
    print("Sphinx could not understand audio")
  except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))



Sunday, September 3, 2017

Secure Zigbee Pairing Using NFC

As we all know that Zigbee protocol is vulnerable when a new device join the network. If a non-preconfigured device joins a network, a single key may be sent unprotected and enable encrypted communication. This one-time transmission of the unprotected key results in a short time frame of exploitation in which the key could be sniffed by an attacker. We implement a more secure Zigbee Pairing Using NFC and all of implementations are based on TI CC2530-CC2592 and TRF7963A as the following block diagram. The network key is send through TRF7963A from Zigbee coordinator (connecting to IOT GW) to NFC tag which is connected to Zigbee device. So, network key won't go over the air during Zigbee pairing and it won't be captured by any Zigbee sniffer.



The following video gives a demonstration about the process.




Friday, June 23, 2017

Build TI Z-Stack Linux Home Gateway reference design to run on both Linux 16.04 AMD64 (64Bit) and x86 (32Bit).

1. Download Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run from http://www.ti.com/tool/z-stack-archive.

2.a. If you use  Linux 16.04 x86 (32Bit), you can run Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run to extract Z-Stack Linux Gateway source code to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src

2.b. If you use  Linux 16.04 AMD64 (64Bit),you can refer to http://processors.wiki.ti.com/index.php/Sitara_Linux_SDK_64_Bit_Ubuntu_Support and have to run the following apt-get install command to install necessary packages before you run Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run 32 bit script to unpack Z-Stack Linux Gateway source code to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src.

 sudo apt-get install libc6:i386
 sudo apt-get install libx11-6:i386 libasound2:i386 libatk1.0-0:i386 libcairo2:i386 libcups2:i386 libdbus-glib-1-2:i386 libgconf-2-4:i386 libgdk-pixbuf2.0-0:i386 libgtk-3-0:i386 libice6:i386 libncurses5:i386 libsm6:i386 liborbit2:i386 libudev1:i386 libusb-0.1-4:i386 libstdc++6:i386 libxt6:i386 libxtst6:i386 libgnomeui-0:i386 libusb-1.0-0-dev:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386

3. Revise the build script package_builder_bbb (in red) under “your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\scripts\”

...
#Target platform:
    #export TARGET_PLATFORM="BEAGLEBONE_BLACK"
    export TARGET_PLATFORM="x86"

...
    cd $NPI_SOURCE/Projects/tools/LinuxHost
    make clean
    make create_output
    #make arch-all-armBeagleBone CC_armBeagleBone=$COMPILER |& tee -a $MAKE_LOG_FILE
    make $BUILD_TYPE |& tee -a $MAKE_LOG_FILE

...
# *** Copy resources ***********************************************************************************

#cp $NPI_SOURCE/Projects/tools/LinuxHost/out/NPI_lnx_armBeagleBone_server $BINARIES_SERVERS_DIR/NPI_lnx_${PLATFORM_SUBSTRING}_server
cp $NPI_SOURCE/Projects/tools/LinuxHost/out/NPI_lnx_${PLATFORM_SUBSTRING}_server $BINARIES_SERVERS_DIR/NPI_lnx_${PLATFORM_SUBSTRING}_server


4.Download protobuf 2.5.0-9ubuntu1 source package from https://launchpad.net/ubuntu/+source/protobuf/2.5.0-9ubuntu1 and build/install it with the following steps.
 
   4.a. Extra protobuf 2.5.0-9ubuntu1 to protobuf 2.5.0 folder and switch into protobuf 2.5.0 folder
   4.b. run "./configure"
   4.c. run "make"
   4.d. run "sudo make install"
   4.e. run "sudo ldconfig"

5.Download protobuf-c 0.15-1build1 source package from https://launchpad.net/ubuntu/+source/protobuf-c/0.15-1build1 and build/install it with the following steps.
 
   5.a. Extra protobuf-c 0.15-1build1 to protobuf-c-0.15 folder and switch into protobuf-c-0.15 folder
   5.b. run "./configure"
   5.c. run "make"
   5.d. run "sudo make install"
   5.e. run "sudo ldconfig"

6. Create a new folder "tools" and export TCLIB to it using the following lines:

   cd ~
   mkdir tools
   export TCLIB=~/tools

7. Switch to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\ and run ./build_all

8. The output will be at "your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\ERROR_out\z-stack_linux_gateway_x86_binaries.tar". The build error is due to the lack of comparison file but the output binaries still work on x86 environment.

9. Copy and untar “z-stack_linux_gateway_x86_binaries.tar” to your working directory on x86 (called ).

10. Disable flowcontrol in NPI_Gateway.cfg like the followings:

    ...
    [UART]
    speed=115200 ; speed
    flowcontrol=0 ; 1=enabled 0=disable
    ...

11. Please follow the (Z-Stack Linux Gateway User Guide.pdf, Chap 6.3) to start the application. Please note you have to specify x86 when you run zigbeeHAgw like "sudo ./zigbeeHAgw x86" in one terminal and run "./start_application" on another terminal.

















Wednesday, May 10, 2017

How to generate Zigbee Host application code for EFR32 from Simplicity Studio

You can generate Zigbee Host application code for EFR32 from Simplicity Studio by doing the following steps:


1. Go to Simplicity Studio->New->New Project and select "Silicon Labs AppBuilder Project"


2. Select "ZCL Application Framework V2" and press Next button.


3. Select "EmberZnet 5.9.1.0 GA Host 5.9.1.0" and press Next button.


4. Select "HaGatewayReference" and press Next button.


5. Use default project name or input yours. Then, press Next button and Finish button.


6. Go to HAL configuration in HaGatewayReferenceHost.isc. Select EFR32-EZSP as Wireless Chip and your Host type in Platform configuration. Then, press "Generate" button to generate HaGatewayReferenceHost example code.

7. Put the generated HaGatewayReferenceHost example code to your target platform and build to run it.

Thursday, April 27, 2017

Running 6lbr on Raspberry Pi with WiFi enable

The following steps show you how to run 6lbr on Raspberry Pi with WiFi enable. I use Wi-Pi WiFi dongle in my test.

1. Run "sudo iwlist wlan0 scan" to scan WiFi AP

2. Edit wpa_supplicant.conf to add your WiFi AP SSID, password, and settings by running "sudo vi /etc/wpa_supplicant/wpa_supplicant.conf"



3. Run "sudo ifdown wlan0" and "sudo ifup wlan0" to restart wlan0.

4. Kill existing wpa_supplicant process by running "sudo kill -9 $(ps -ef | grep wpa | awk '{print $2}')" and run "sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf" to start it again with new settings in wpa_supplicant.conf.

5. Run "sudo dhclient" to get DHCP client IP and run "ifconfig wlan0" to check if you get correct client IP.


6. Restart Raspberry Pi and ssh to it using wlan0 DHCP client IP get in step 5.

7. Edit /etc/6lbr/6lbr.conf to use wlan0 as ETH interface.


8. Start 6lbr and you can test it with wlan0 now.

For details of running 6lbr with CC2531EMK on Raspberry Pi, you can refer to "Setup 6lbr to run 6LowPAN with CC2531 USB dongle on Raspberry Pi 2B."

Wednesday, March 29, 2017

Build TI Z-Stack Linux Home Gateway reference design for x86 Linux

The following steps show you hot to build TI Z-Stack Linux Home Gateway reference design for x86 Linux.

1. Download Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run from http://www.ti.com/tool/z-stack-archive.

2. Setup a 32 bit Ubuntu and run Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run to extract Z-Stack Linux Gateway source code to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src

3. Revise the build script package_builder_bbb (in red) under “your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\scripts\”

...
#Target platform:
    #export TARGET_PLATFORM="BEAGLEBONE_BLACK"
    export TARGET_PLATFORM="x86"

...
    cd $NPI_SOURCE/Projects/tools/LinuxHost
    make clean
    make create_output
    #make arch-all-armBeagleBone CC_armBeagleBone=$COMPILER |& tee -a $MAKE_LOG_FILE
    make $BUILD_TYPE |& tee -a $MAKE_LOG_FILE

...
# *** Copy resources ***********************************************************************************

#cp $NPI_SOURCE/Projects/tools/LinuxHost/out/NPI_lnx_armBeagleBone_server $BINARIES_SERVERS_DIR/NPI_lnx_${PLATFORM_SUBSTRING}_server
cp $NPI_SOURCE/Projects/tools/LinuxHost/out/NPI_lnx_${PLATFORM_SUBSTRING}_server $BINARIES_SERVERS_DIR/NPI_lnx_${PLATFORM_SUBSTRING}_server


4.a Install protobuf by doing the following two apt-get install

       sudo apt-get install protobuf-c-compiler
       sudo apt-get install protobuf-compiler

4.b Create a new folder "tools" and export TCLIB to it using the following lines:
  
       cd ~
       mkdir tools
       export TCLIB=~/tools/

5. Switch to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\ and run ./build_all

6. The output will be at "your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\ERROR_out\z-stack_linux_gateway_x86_binaries.tar". The build error is due to the lack of comparison file but the output binaries still work on x86 environment.

7. Copy and untar “z-stack_linux_gateway_x86_binaries.tar” to your working directory on x86 (called ). Please follow the (Z-Stack Linux Gateway User Guide.pdf, Chap 6.3) to start the application. Please note you have to specify x86 when you run zigbeeHAgw like "sudo ./zigbeeHAgw x86"

8. If you run it successfully, you will see the results like the following screen shot.


Thursday, March 9, 2017

SPI connection between LAUNCHXL-CC1310/LAUNCHXL-CC2650 and ENC28J60 to run 6lbr

You can do the following SPI connection between ENC28J60 and LAUNCHXL-CC1310/LAUNCHXL-CC2650 to run 6lbr
  • SCLK : LaunchPad DIO10
  • MOSI : LaunchPad DIO9
  • MISO : LaunchPad DIO8
  • CS : LaunchPad DIO14
  • GND :  LaunchPad GND
  • VCC : LaunchPad 3V3

6lbr SW can be built by following steps in http://sunmaysky.blogspot.tw/2017/01/build-6lbr-for-cc2650dk-or-cc1310dk.html . After run 6lbr on LAUNCHXL-CC1310/LAUNCHXL-CC2650, you can see the following UART output.