Android with root Git for version control Lircd with Raspberry Pi for IR receiver and sender Tips for Windows Depolying your own password management tool -- KeeWeb Depoly your flask app into Heroku Fix shit IE code manually ISBN to Book Category by Scraping DangDang A Generic Makefile for C/C++ Program Configure Raspberry pi Remove watermark with PyPDF2 tips for docker Anaconda+TensorFlow+CUDA Snippets Configure Remote Mathematica Kernel Build your own ngrok server Access Array SSL VPN 使用Rstudio制作html5幻灯片 tips for Mac OS X system Tips for ipython notebook 配置Ubuntu server + Openbox (Obuntu) tips for Vimperator tips for Vim 安装CUDA My First Jekyll Blog rsync常见选项 在Linux中读取Ipod touch的文件 tip for texmacs 在VPS上建站的一些tip Gnuplot绘图札记 Samba系统和autofs自动挂载 Linux中alsamixer声卡无法录音 搭建自己的RSS订阅器——Tiny Tiny RSS Grub2引导安装Ubuntu awk tips 将Ubuntu系统装入U盘 The Great Rtorrent 编译GCC 再这样剁手!!!该死的libgd 使用ulimit进行资源限制 使用SSH代理上IPV6 使用RCurl抓取网页数据 修复Ubuntu Grub记 openbox中的文件关联 在Ubuntu 12.04下编译qtiplot 处理BCM4312网卡驱动纪实 配置我的Ubuntu Server记 Cygwin杂记 Linux 使普通用户具有以超级权限执行脚本 让firefox自定义地处理文件类型 WordPress优秀主题及插件 在phpcloud上搭建wordpress UBUNTU下用pptpd做VPN server ubuntu升级内核过后的一些问题 安装telnet服务 kubuntu札记 64位kubuntu札记 统计软件R Virtualbox stardict星际译王 Ubuntu重装windows系统后的grub引导修复 SSH服务及花生壳域名解析 采用cbp2make工具由code::blocks工程创建makefile文件 UBUNTU 札记

Configure Raspberry pi

2018年06月19日

Install image to SD card

Use a GUI program or sudo dd bs=1M if=Downloads/2017-04-10-raspbian-jessie-lite.img of=/dev/disk2 in Linux/MAC OS.

Headless Boot

cd /path/to/pi/boot first and then:

cat > wpa_supplicant.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
    ssid="this-is-wifi"
    psk="zeroshaha"
    key_mgmt=WPA-PSK
    scan_ssid=1
}
EOF
touch ssh

Change username/password

ssh pi@pi0 first, then ssh root@pi0 again.

# first time
sudo raspi-config #extent file system and hostname

sudo sed -i 's%#PermitRootLogin prohibit-password%PermitRootLogin yes%' /etc/ssh/sshd_config
sudo passwd root #reset the passwd for root 
sudo reboot

# second time
usermod -l nick pi && groupmod -n nick pi && usermod -d /home/nick -m nick #change user/group name and reset home
sed -i 's%PermitRootLogin yes%%' /etc/ssh/sshd_config

usermod -p ! root # reset password for root to impossible

Install Bluealsa

sudo apt install bluealsa or compile it yourself:

cd ~
git clone https://github.com/mstorsjo/fdk-aac
cd fdk-aac
libtoolize
autoreconf --install
mkdir build && cd build
../configure --prefix=/usr
make
make install

cd ~
sudo apt install libasound2-dev libbluetooth-dev libsbc-dev
git clone https://github.com/Arkq/bluez-alsa.git
cd bluez-alsa
mkdir build && cd build
autoreconf --install
mkdir build && cd build
../configure --enable-aac --enable-debug
make
make install

sudo ln -s /usr/lib/alsa-lib/libasound_module_ctl_bluealsa.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_ctl_bluealsa.so
sudo ln -s /usr/lib/alsa-lib/libasound_module_pcm_bluealsa.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_bluealsa.so

echo export LIBASOUND_THREAD_SAFE=0 >> ~/.bashrc

tee /lib/udev/rules.d/62-bluealsa.rules <<EOF 
ACTION=="add", KERNEL=="hci0", ENV{SYSTEMD_WANTS}+="bluealsa.service"
EOF

cat <<EOF > /lib/systemd/system/bluealsa.service
[Unit]
Description=BluezAlsa proxy (modified)
Requires=bluetooth.service
After=bluetooth.target bluetooth.service

[Service]
Type=simple
ExecStart=/usr/bin/bluealsa

[Install]
WantedBy=multi-user.target
EOF

# need to disable it if pulseaudio installed 
sudo mv /usr/share/alsa/pulse-alsa.conf{,.bak}
sudo mv /usr/share/alsa/alsa.conf.d/50-pulseaudio.conf{,.bak}
sudo mv /usr/share/alsa/alsa.conf.d/pulse.conf{,.bak}
sudo systemctl disable pulseaudio

Setup Bluetooth

Remove the old one and then reconnect, the last failed connect may cause some problems

sudo bluetoothctl
#>> power on
#>> scan on 
#>> remove FC:58:FA:30:6B:6A 
#>> pair FC:58:FA:30:6B:6A
#>> trust FC:58:FA:30:6B:6A
#>> connect FC:58:FA:30:6B:6A

Setup default Audio device

cat <<EOF > /etc/asound.conf
pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "bluetooth"
}

ctl.!default {
	type bluealsa
}

pcm.bluetooth {
	type plug
	slave.pcm {
		type bluealsa
		device "FC:58:FA:30:6B:6A"
		profile "a2dp"
	}
	hint {
		show on
		description "Use the A2 bluetooth headset with Blue-Alsa module as default"
	}
}

pcm.mic {
  type plug
  slave {
    pcm "plughw:1,0"
  }
}
EOF

Disable on board wifi or bluetooth

cat >> /boot/config.txt <<EOF
dtoverlay=pi3-disable-wifi
#dtoverlay=pi3-disable-bt
EOF
sudo systemctl stop bluetooth.service && sudo systemctl disable bluetooth.service
sudo systemctl stop hciuart.service && sudo systemctl disable hciuart.service

Maybe set the proxy

echo export https_proxy=http://127.0.0.1:8123 >> ~/.bashrc
echo export http_proxy=http://127.0.0.1:8123 >> ~/.bashrc
cat >> /etc/hosts <<EOF
192.168.1.8	pi.local
EOF

cat > /etc/apt/apt.conf.d/05proxy <<EOF
Acquire::http::Proxy "http://pi.local:3142";
EOF

Install good software

sudo apt update

# remote file system
sudo apt install autofs cifs-utils
cat | sudo tee /etc/smbcredentials <<EOF
username=$USERNAME
password=$PASSWORD
EOF
sudo chown nick:nick /etc/smbcredentials
chmod 600 /etc/smbcredentials

cat | sudo tee /etc/auto.home <<EOF
/data            -fstype=cifs,credentials=/etc/smbcredentials,uid=1000,gid=1000 ://pi.local/data
/media            -fstype=cifs,credentials=/etc/smbcredentials,uid=1000,gid=1000 ://pi.local/media
#/home/user -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,workaround=rename,ssh_command=/usr/local/sbin/ssh_user :sshfs\#user@host\:/home/user
EOF
cat | sudo tee -a /etc/auto.master <<EOF
/- /etc/auto.home uid=1000,gid=1000,--timeout=30,--ghost
EOF

# audio system
sudo apt install -y cmus
mkdir -p ~/.cmus && echo "set output_plugin=alsa" > ~/.cmus/rc

# snowboy
sudo apt-get install python3-pyaudio sox libatlas3-base
mkdir -p ~/snowboy && curl -L https://github.com/kitt-ai/snowboy/tarball/v1.3.0 | tar zx -C snowboy --strip 1
curl 'https://transfer.sh/VtbYX/snowboy_py3-.tar.gz' |tar -xz -C snowboy --strip 1
curl 'https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/rpi-arm-raspbian-8.0-1.1.1.tar.bz2' |tar -xj -C snowboy --strip 1
python3 demo.py resources/models/snowboy.umdl

Turn PI zero to a USB Gadget

# enable the dwc2 kernel module
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
# make the pi work as ether gadget when dwc2 module loaded
sed -i 's#rootwait$#rootwait modules-load=dwc2,g_ether#' /boot/cmdline.txt

# configure the static IP for the USB PI, need to manually set the IP of your PC in the same network
cat > /etc/network/interfaces.d/usb0 <<EOF
allow-hotplug usb0
iface usb0 inet static
        address 192.168.7.2
        netmask 255.255.255.0
        network 192.168.7.0
        broadcast 192.168.7.255
        gateway 192.168.7.1
EOF

pi can also work as serial device, which do not need any driver. see more details in adafruit’s website.