Wednesday, November 11, 2015

Voice Control Home Automation via Amazon Echo and Siri HomeKit - DIY

Voice Control Home Automation via Amazon Echo and Siri HomeKit - DIY


This is a quick start tutorial on setting up the Raspberry Pi 2 as a Home Automation System with Voice Control from Amazon Echo (Alexa) or Apple HomeKit (Siri). This is not a comprehensive tutorial, but should get you started.


Last Updated: 4/24/2016

REQUIREMENT:

Raspberry Pi 2 or Pi 3
8GB or larger microSD Card
Aeon Labs Z-Wave Z-Stick - Series 2 OR Gen5
Aeon Labs - Z-Wave Smart Energy Switch

OPTIONAL:
Logitech Harmony Home Hub
Amazon Echo or Amazon Dot

LET'S START:

Download Raspbian Jessie
Write the Raspbian Jessie Image to MicroSD Card
Insert MicroSD Card in Raspberry Pi 2 and Boot.
Connect to Pi using SSH (pi/raspberry)
Expand Filesystem - Ensures that all of the SD card storage is available to the OS
#Expand Filesystem and Reboot
sudo raspi-config

#Reboot Required and Important

#Initial Update and required packages
#All one line - cut/paste recommend
#Go get some coffee
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y install python2.7 libavahi-compat-libdnssd-dev git unzip curl subversion build-essential usbutils psmisc htop samba-common-bin samba php5 php5-cli php5-curl wicd-curses libudev-dev

###################################
#SAFE CUT/PASTE FROM THIS POINT 
#TO FIRST REBOOT
###################################

#apache get installed somewhere, so stop and disable it
sudo /etc/init.d/apache2 stop
sudo update-rc.d -f apache2 remove

#Setup SAMBA
#No password, Everyone has read/write access to \\<IPAddress>\root
cd /etc/samba
sudo mv smb.conf smb.conf.org
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/smb.conf
sudo /etc/init.d/samba restart

#OPENHAB INSTALL
sudo mkdir -p /opt/openhab/addons_all
cd /opt/openhab

#Download current release
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.8.2-runtime.zip
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.8.2-addons.zip
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.8.2-demo.zip

#unzip
sudo unzip distribution-1.*-runtime.zip
sudo unzip distribution-1.*-addons.zip -d /opt/openhab/addons_all
sudo unzip -n distribution-1.*-demo.zip

#delete
sudo rm distribution-1.*-runtime.zip
sudo rm distribution-1.*-addons.zip
sudo rm distribution-1.*-demo.zip

#Addons (aka bindings) is what make OpenHAB so powerful
#To install Addons, copy them into the addons folder
sudo cp addons_all/org.openhab.action.harmonyhub*.jar addons
sudo cp addons_all/org.openhab.binding.harmonyhub*.jar addons
sudo cp addons_all/org.openhab.binding.exec*.jar addons
sudo cp addons_all/org.openhab.binding.http*.jar addons
sudo cp addons_all/org.openhab.binding.networkhealth*.jar addons
sudo cp addons_all/org.openhab.binding.ntp*.jar addons
sudo cp addons_all/org.openhab.binding.wol*.jar addons
sudo cp addons_all/org.openhab.binding.zwave*.jar addons
sudo cp addons_all/org.openhab.binding.systeminfo*.jar addons
sudo cp addons_all/org.openhab.io.harmonyhub*.jar addons
sudo cp addons_all/org.openhab.persistence.exec*.jar addons

#SIGAR for OpenHAB Systeminfo Binding
#https://github.com/openhab/openhab/wiki/Systeminfo-Binding
sudo mkdir -p /opt/openhab/lib
sudo wget https://groups.google.com/group/openhab/attach/ab7030271be23f05/sigar-raspbian.zip?part=0.1 -O /tmp/sigar-raspbian.zip
sudo unzip /tmp/sigar-raspbian.zip -d /tmp
sudo cp /tmp/sigar-raspbian/lib/* /opt/openhab/lib
sudo rm /tmp/sigar-raspbian.zip

#AMAZON ECHO BRIDGE INSTALL
#Go here for latest - https://github.com/armzilla/amazon-echo-ha-bridge/releases

sudo mkdir /opt/amazon-echo-bridge
cd /opt/amazon-echo-bridge
sudo wget --no-check-certificate https://github.com/armzilla/amazon-echo-ha-bridge/releases/download/v0.2.1/amazon-echo-bridge-0.2.1.jar


#HABMIN1 INSTALLATION
cd /opt/openhab
sudo wget https://github.com/cdjackson/HABmin/releases/download/0.1.3-snapshot/habmin.zip
sudo unzip habmin.zip
sudo rm habmin.zip
#delete old zwave binding
sudo rm addons/org.openhab.binding.zwave-1.5.0-SNAPSHOT.jar

#HABMIN2 INSTALLATION - requires HABMIN1
#HABMIN2 no longer works with OpenHAB 1 (only OpenHAB 2)
cd /opt/openhab/addons
sudo wget https://github.com/cdjackson/HABmin/blob/master/addons/org.openhab.io.habmin-1.7.0-SNAPSHOT.jar
sudo wget https://github.com/cdjackson/HABmin2/releases/download/0.0.15/org.openhab.ui.habmin_2.0.0.SNAPSHOT-0.0.15.jar
sudo chmod 755 *

sudo mkdir -p /opt/openhab/webapps/habmin2
cd /opt/openhab/webapps/habmin2
sudo wget https://github.com/cdjackson/HABmin2/releases/download/0.0.15/HABmin2-0.0.15-release.zip
sudo unzip HABmin2-0.0.15-release.zip
sudo rm HABmin2-0.0.15-release.zip

#OPENHAB CONFIG
#mail, security, zwave, harmonyhub
cd /opt/openhab/configurations
sudo cp openhab_default.cfg openhab.cfg

#SAMPLE OPENHAB ITEMS
cd /opt/openhab/configurations/items
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/default.items

#SAMPLE OPENHAB SITEMAPS
cd /opt/openhab/configurations/sitemaps
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/default.sitemap
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/homekit.sitemap

#Z-WAVE Z-STICK OPENHAB CONFIGURATION
#Plug in Z-Stick
#Assuming Z-Wave Stick is attached to ttyUSB0
sudo sed -i 's^#zwave:port=^zwave:port=/dev/ttyUSB0^' /opt/openhab/configurations/openhab.cfg

#CUSTOM SCRIPTS
sudo mkdir /opt/openhab/custom_scripts

#Shutdown Windows PC Script
cd /opt/openhab/custom_scripts
sudo wget  --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/turnoffWindowsComputer.sh
sudo chmod +x turnoffWindowsComputer.sh

#PHP-FINDMYIPHONE
cd /opt/openhab/custom_scripts
sudo git clone git://github.com/albeebe/PHP-FindMyiPhone
sudo cp PHP-FindMyiPhone/class.findmyiphone.php .

sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/listiclouddevices.php
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/turnoniphone.php
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/turnoffiphone.php

#NODEJS for SIRI HomeKit Bridge

#Remove conflicting nodejs
sudo apt-get -y remove nodejs

#Install nodejs
cd /tmp
sudo wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
sudo rm node_latest_armhf.deb

#OpenHAB HomeKit Bridge
cd /opt
sudo git clone git://github.com/htreu/OpenHAB-HomeKit-Bridge
cd OpenHAB-HomeKit-Bridge

#This will take a while
cd /opt/OpenHAB-HomeKit-Bridge
sudo npm install -g npm@3.3.12

#Start OpenHAB on boot
cd /etc/init.d/
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/etc/init.d/openhab
sudo chmod a+x openhab
sudo update-rc.d openhab defaults

#Home Kit Startup Script Setup
cd /opt/OpenHAB-HomeKit-Bridge
sudo cp start.sh.template start.sh
sudo chmod +x start.sh

#Amazon-Echo-Bridge Script Setup
cd /opt/amazon-echo-bridge/
sudo wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/echobridgestart.sh
sudo chmod +x echobridgestart.sh

#Start bridges on boot

#delete 'exit 0' (backup rc.local also)
sudo sed -i.bak '/exit 0/d' /etc/rc.local

echo 'sleep 10' | sudo tee --append /etc/rc.local
echo 'sudo /opt/amazon-echo-bridge/echobridgestart.sh &' | sudo tee --append /etc/rc.local
echo 'sleep 60 #Give OpenHAB Time to Start' | sudo tee --append /etc/rc.local
echo 'sudo /opt/OpenHAB-HomeKit-Bridge/start.sh &' | sudo tee --append /etc/rc.local
echo 'exit 0' | sudo tee --append /etc/rc.local

###################################
#END CUT/PASTE 
###################################

#REBOOT
sudo reboot

#Configure Amazon Echo Bridge at
#http://IPADDRESS:8081/configurator.html
#Add sample items
cd /tmp
wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/iphone.json
wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/smartswitch.json
wget --no-check-certificate http://dl.dropbox.com/u/42238/debian/openhab/custom_scripts/windowspc.json
curl -H "Content-Type: application/json" --data @iphone.json http://localhost:8081/api/devices
curl -H "Content-Type: application/json" --data @smartswitch.json http://localhost:8081/api/devices
curl -H "Content-Type: application/json" --data @windowspc.json http://localhost:8081/api/devices

#FIND MY IPHONE SETUP
#CONFIGURE SAMPLE SCRIPTS
#Edit listiclouddevices.php with your iCloud username (email) and password

cd /opt/openhab/custom_scripts
sudo nano listiclouddevices.php


#Run it to find your deviceID
#DeviceID will be something like Eu4EGWK1Yt5+2JtKM7YNA++hxNtDw4ZzZuwT9BLxYcL2d7FaULCJMuHYVNSUzmXV<
php ./listiclouddevices.php

#Edit turnoniphone.php, turnoffiphone.php
#with username, password and deviceID
sudo nano turnoniphone.php
sudo nano turnoffiphone.php

#Run scripts to test
php ./turnoniphone.php
php ./turnoffiphone.php


#TURN OFF COMPUTER SCRIPT SETUP
#edit script with IPAddress, Username and Password
sudo nano turnoffWindowsComputer.sh

#Turn on your computer and test script
./turnoffWindowsComputer.sh
#Computer Power On will be handled via WOL Binding
#https://github.com/openhab/openhab/wiki/Wake-on-LAN-Binding-(WoL)

#Test via OpenHAB WebApp - http://IPADDRESS:8080/openhab.app

Download the OpenHAB iOS/Android app.

Ask Alexa to discover your devices - "Alexa, discover devices". Add additional devices via http://IPADDRESS:8081/configurator.html.

For HomeKit Siri setup, download Elgato Eve on iOS device
https://itunes.apple.com/us/app/elgato-eve/id917695792?mt=8

Launch Elgato Eve->Add Accessory
Under "SELECT ACCESSORY" you should see "OpenHAB HomeKit Bridge". Select it.
Select "Add to xxx" (xxx being whatever name you used)
Ignore warning about the accessory not being certified - Add Anyway
Select "Enter code manually"
Type in "031-45-154"


To reset HomeKit and start over, delete Elgato Eve app and then go into Settings->Privacy->HomeKit and select "Reset HomeKit Configuration"


Hardware:

Amazon Echo - http://www.amazon.com/dp/B00X4WHP5E/?tag=blogqnologyco-20
Voice Remote for Amazon Echo - http://www.amazon.com/dp/B00L9EPT8O/?tag=blogqnologyco-20
Logitech Harmony Home Hub - http://www.amazon.com/dp/B00N3RFC4G/?tag=blogqnologyco-20
Raspberry Pi 2 - http://www.amazon.com/dp/B00T2U7R7I/?tag=blogqnologyco-20
Aeon Labs Z-Wave Z-Stick Series 2 USB Dongle - http://www.amazon.com/dp/B003MWQ30E/?tag=blogqnologyco-20
(Newer version - Buy this version instead of the above) Aeon Labs Aeotec Z-Wave Z-Stick, Gen5 Z-Wave Plus - ZW090 - http://www.amazon.com/dp/B00X0AWA6E/?tag=blogqnologyco-20
Wink Connected Home Hub - http://www.amazon.com/dp/B00PV6GAI4/?tag=blogqnologyco-20
GE Link Smart Connected LED Light Bulb - http://www.amazon.com/dp/B00NOL16K0/?tag=blogqnologyco-20
GE Z-Wave On/Off/Dim Dimmer Switch (45612  - no neutral) - http://www.amazon.com/dp/B006LQFHN2/?tag=blogqnologyco-20
RGB LED Light Strip 5 meter with remote and power supply - http://www.amazon.com/dp/B00ASHQQKI/?tag=blogqnologyco-20

Harmony Hub Control for RGB LED discussion - http://forums.logitech.com/t5/Harmony-Remotes/RGB-Controller-44keys-exist-in-Harmony-DB/td-p/423325

Not shown in video, but I have everything running through this so I can monitor energy usage. I would also be able to determine if my TV is on by the amount of watts being drawn.
Aeon Labs - Z-Wave Smart Energy Switch - http://www.amazon.com/dp/B007UZH7B8/?tag=blogqnologyco-20

Software:

Raspbian Jessie -  https://www.raspberrypi.org/downloads/raspbian/
OpenHab - http://www.openhab.org/getting-started/index.html
Amazon Echo Bridge - https://github.com/armzilla/amazon-echo-ha-bridge
OpenHab HomeKit Bridge - https://github.com/htreu/OpenHAB-HomeKit-Bridge
PHP-FindMyiPhone - https://github.com/albeebe/PHP-FindMyiPhone

=======
Credit/References:

https://www.reddit.com/r/homeautomation/comments/377onm/extending_amazon_echo_voice_control_to_existing/

Getting Started with OpenHAB Home Automation on Raspberry Pi
http://www.makeuseof.com/tag/getting-started-openhab-home-automation-raspberry-pi/

[HOW TO] CONTROL YOUR OPENHAB ITEMS USING THE AMAZON ECHO - http://tinsley.io/2015/06/control-your-items-using-the-amazon-echo-openhab/

OpenHAB Community - https://community.openhab.org/


Friday, April 10, 2015

OpenWRT on Pogoplug v3/Oxnas (Pro/Classic)

This tutorial assumes you have completed my previous tutorial - Hacking the Pogoplug v3/Oxnas (Pro/Classic) with Debian
- and already running Debian from a USB drive on the Pogoplug V3.

OpenWRT will be installed on the internal flash (NAND) of the Pogoplug. You will still be able to boot Debian from USB when attached.

Known Issues:

 - RT3090 (PCIE) Wi-Fi in the Pro is not working. 
All commands below needs to be executed from Debian.

#Verify MTD partition
cat /proc/mtd
#root@debian:~# cat /proc/mtd
#dev: size erasesize name
#mtd0: 00e00000 00020000 "boot"
#mtd1: 07200000 00020000 "data"

#download firmware/nand utilities
cd /tmp
wget http://download.qnology.com/pogoplug/v4/fw_printenv
wget http://download.qnology.com/pogoplug/v4/fw_setenv
wget http://download.qnology.com/pogoplug/v4/ubiattach
wget http://download.qnology.com/pogoplug/v4/ubimkvol
wget http://download.qnology.com/pogoplug/v4/ubiformat

#make executable
chmod +x fw_printenv fw_setenv ubiattach ubimkvol ubiformat

#format mtd1 (data)
/tmp/ubiformat /dev/mtd1

#attach
/tmp/ubiattach /dev/ubi_ctrl -m 1
/tmp/ubimkvol /dev/ubi0 -m -N rootfs

#mount ubi rootfs to /tmp/ubi
mkdir /tmp/ubi
mount -t ubifs ubi0:rootfs /tmp/ubi

#We're using the snapshot trunk release.

#There is no rootfs tarball, so we'll extract 
#it from the squashfs sysupgrade tar
cd /tmp
wget http://downloads.openwrt.org/snapshots/trunk/oxnas/generic/openwrt-oxnas-pogoplug-pro-squashfs-sysupgrade.tar

#extract
tar -xvf openwrt-oxnas-pogoplug-pro-squashfs-sysupgrade.tar

#unsquashfs
apt-get install squashfs-tools
unsquashfs sysupgrade-pogoplug-pro/root


#move extracted rootfs to ubi
mv squashfs-root/* /tmp/ubi

#download kernel zImage
mkdir -p /tmp/ubi/boot
cd /tmp/ubi/boot
wget http://downloads.openwrt.org/snapshots/trunk/oxnas/generic/openwrt-oxnas-zImage

#rename zImage file
mv openwrt-oxnas-zImage zImage


#download fdt
wget http://downloads.openwrt.org/snapshots/trunk/oxnas/generic/openwrt-oxnas-pogoplug-pro.dtb
wget http://download.qnology.com/pogoplug/oxnas/ox820-pogoplug-classic.dtb


sync
cd /
umount /tmp/ubi

#Setup uBoot Environment
#Cut and Paste this whole section
/tmp/fw_setenv zimage '/boot/zImage'
/tmp/fw_setenv loadaddr '0x60500000'
/tmp/fw_setenv fdt_addr '0x62c00000'
/tmp/fw_setenv loadubi 'echo Trying to boot from NAND ...;if run mountubi; then run loadubizimage;run loadubifdt;ubifsumount;run bootzubi;fi'
/tmp/fw_setenv mountubi 'ubi part data; ubifsmount ubi0:rootfs'
/tmp/fw_setenv loadubizimage 'ubifsload ${loadaddr} ${zimage}'
/tmp/fw_setenv loadubifdt 'ubifsload ${fdt_addr} ${fdt_file_ubi}'
/tmp/fw_setenv bootzubi 'echo Booting from nand ...; run setargsubi; bootz ${loadaddr} - ${fdt_addr};'
/tmp/fw_setenv setargsubi 'setenv bootargs console=ttyS0,115200n8 ubi.mtd=1 root=ubi0:rootfs rw rootfstype=ubifs rootwait ${mtdparts}'

#Select the appropriate fdt - Pro (Wi-Fi) versus regular.

#Pogoplug Pro
/tmp/fw_setenv fdt_file_ubi '/boot/openwrt-oxnas-pogoplug-pro.dtb'

#Non-Pro (use this if unsure)
/tmp/fw_setenv fdt_file_ubi '/boot/ox820-pogoplug-classic.dtb'

#S
etup boot order.
#USB first, then UBI/NAND
/tmp/fw_setenv dt_bootcmd_usb 'usb start; run dt_usb_bootcmd; usb stop'

/tmp/fw_setenv bootcmd 'run dt_bootcmd_usb; run loadubi; reset'

#poweroff Pogoplug and then remove USB flash drive.
poweroff

OpenWRT Initial Boot via Telnet

At this point, we're ready to boot into OpenWRT. During the bootup process the LED on the Pogoplug will blink. However once it successfully boots into OpenWRT the LED will be completely off.

Note that by default, OpenWRT will default to 192.168.1.1 and will (or should) act as a DHCP Server.  Plug a network cable from your computer directly into the Pogoplug and power it on (do not plug the Pogoplug into your router). You should now be able to Telnet into the Pogoplug at 192.168.1.1 (username and password not required). If you're not able to telnet into the Pogoplug try setting a static IP address of 192.168.1.2 on your computer.

Note that SSH is disabled and will automatically start after a root password is set.

#set passwd and enable ssh
passwd

#Reconfigure Network to DHCP Client
#disable dhcp server on lan
#Ignore if any error.
uci set dhcp.lan.ignore=1
uci commit dhcp
/etc/init.d/dnsmasq restart

#set wired ethernet interface to dhcp client
uci set network.lan.proto=dhcp
uci commit network

#reboot
reboot

OpenWRT SSH and Initial Package Installation

Plug the Pogoplug and your computer back into your network/router. Check your router for the IP Address assigned to your Pogoplug. You should now be able to SSH into the Pogoplug.

Note that since we're using the daily snapshot trunk build of OpenWRT, you'll need to install your kernel packages right away (kmod-xxx), otherwise it will get out of sync.

opkg update

#Pogoplug has 128MB flash
#No need to be stingy on the packages
opkg install nano wget luci uboot-envtools pciutils usbutils htop wireless-tools kmod-rt2x00-pci kmod-usb-storage block-mount kmod-fs-ext4 kmod-fs-vfat kmod-fs-ntfs kmod-nls-cp437 kmod-nls-iso8859-1 e2fsprogs fdisk kmod-usb2 samba36-server samba36-client luci-app-samba kmod-rtl8187 wireless-tools kmod-usb-net-asix-ax88179 kmod-rt2800-lib kmod-rt2800-usb kmod-rt2x00-lib kmod-rt2x00-usb kmod-usb-serial-pl2303  kmod-usb-serial-cp210x  kmod-usb-serial-ftdi picocom screen

#Assume you're using the USB RT5370 Wi-Fi below 
#Regenerate Wi-Fi configuration
#Verify if Wi-Fi is working properly
rm -f /etc/config/wireless 
wifi detect > /etc/config/wireless

#If wireless is working properly, you should see something
cat /etc/config/wireless

#Enable Wi-Fi
sed -i 's^option disabled 1^option disabled 0^' /etc/config/wireless
/etc/init.d/network restart

Note that the built in Wi-Fi (PCIE) on the Pogoplug Pro is not working.

If you need wireless, I would highly recommend a USB Wi-Fi card based on the RT5730 chipset for less than $8.

Mini Wireless 150Mbs USB Ralink RT5370 (or from Ebay)

Tuesday, April 7, 2015

Hacking the Pogoplug v3/Oxnas (Pro/Classic) with Debian

This is quick publish tutorial on installing Debian on the Pogoplug V3(Oxnas)

All credit to @bodhi on Jeff Doozan's Forum for the uBoot, Debian rootfs, instructions and support. Note that I re-hosted some of @bodhi's files for an easier install.


References:


WARNING: You can potentially brick your Pogoplug following this tutorial. Your warranty will be voided. These instructions are for the Pogoplug V3/Oxnas. Flashing the uBoot below on any other model of the Pogoplug will result in a brick. There is no going back to the Pogoplug OS. You will not be able to use the my.pogoplug.com service. Proceed at your own risk.



Requirements:


1) Pogoplug V3 - Dual 700Mhz ARM, 128MB RAM, SATA (internal), Gigabit Ethernet, 4 USB 2.0 Ports, Wireless*

*Only Pogoplug Pro comes with built in Wi-Fi (AzureWave AW-NE762H 802.11 b/g/n PCI Express RT3090)

Model numbers located on bottom of foot. Please ignore the label on the box. You can potential receive a Pogoplug V2 (POGO-E02 Kirkwood) when buying a P21/P22.




Check the bottom of the Pogoplug's foot for correct model


2) USB Flash Drive (2GB+) or USB Hard Drive


Recommendations/Tested:



Outline of Steps:

  • uBoot Installation via SSH Console
  • Setup Netconsole
  • Debian Installation on USB Hard/Flash Drive
  • Initial Debian Setup
  • Upgrade Debian to 3.18.5 kernel
  • Pogoplug Pro Wireless Configuration



Enable SSH Access to Pogoplug


There are two methods to enable SSH on your Pogoplug.

1) Official Method - Activate on my.pogoplug.com and then enable SSH

2) Backdoor Method (credit to GTVHacker.com)

Make sure your Pogoplug is connected to your network and has internet access.

Check your router or use a network scanning tool (iNet Network Scanner on iPhone) to determine the IP Address of the Pogoplug.

From a Linux computer (e.g. another Pogoplug running Debian/Alarm) run the below curl command.

curl -k "https://root:ceadmin@[PogoplugIPAddress]/sqdiag/HBPlug?action=command&command=dropbear%20start";

Note that the backdoor method is not persistent (SSH access will not be available after a reboot).

uBoot Installation via SSH Console


Use Putty or your favorite SSH client to connect to your Pogoplug.

If you used the "Official Method" for activating and enabling SSH on your Pogoplug, then the username will be "root" and the password will be whatever you set (note that it's not the same password used to log into my.pogoplug.com).
For the "Backdoor Method", the username and password is root/ceadmin.

From here, everything is done via the SSH console.


#Verify Pogoplug is expected version (Oxnas)
cat /proc/cpuinfo | grep Hardware

#Stop here if not expected output.
#Expected output
#Hardware : Oxsemi NAS

#stop my.pogoplug.com service
killall hbwd


#download firmware utilities
cd /tmp
wget http://download.qnology.com/pogoplug/v4/nanddump
wget http://download.qnology.com/pogoplug/v4/nandwrite
wget http://download.qnology.com/pogoplug/v4/flash_erase
wget http://download.qnology.com/pogoplug/v4/fw_printenv
wget http://download.qnology.com/pogoplug/v4/fw_setenv


#make executable
chmod +x flash_erase fw_printenv fw_setenv nanddump nandwrite


#remount '/' as read/write
#by default the Pogoplug OS (internal flash) is read only
mount -o remount,rw /


#setup fw_env.config for oxnas
echo "/dev/mtd0 0x00100000 0x20000 0x20000">/etc/fw_env.config


#save original envs
/usr/local/cloudengines/bin/blparam > /blparam.txt


#Download and flash new uBoot
wget http://download.qnology.com/pogoplug/oxnas/uboot.2013.10-tld-4.ox820.bodhi.tar
wget http://download.qnology.com/pogoplug/oxnas/uboot.2013.10-tld-4.ox820.bodhi.tar.md5


#check md5sum
md5sum -c uboot.2013.10-tld-4.ox820.bodhi.tar.md5


#extract uBoot files
tar -xf uboot.2013.10-tld-4.ox820.bodhi.tar

#BE EXTRA CAREFUL WITH THE THESE COMMANDS.
#NO TYPOS! CUT AND PASTE.
#Erase and flash uboot on mtd0
#Flash encoded spl stage1 to 0x0
/tmp/flash_erase /dev/mtd0 0x0 6
/tmp/nandwrite /dev/mtd0 uboot.spl.2013.10.ox820.850mhz.mtd0.img


#Flash uboot to 0x40000
/tmp/nandwrite -s 262144 /dev/mtd0 uboot.2013.10-tld-4.ox820.mtd0.img

#Flash uboot environment
#Erase 1 block starting 0x00100000
/tmp/flash_erase /dev/mtd0 0x00100000 1
/tmp/nandwrite -s 1048576 /dev/mtd0 pogopro_uboot_env.img


#Set MAC Address
/tmp/fw_setenv ethaddr "$(cat /sys/class/net/eth0/address)"


#default to pogoplug classic dtb
/tmp/fw_setenv fdt_file '/boot/dts/ox820-pogoplug-classic.dtb'
/tmp/fw_setenv dt_load_dtb 'ext2load usb 0:1 $dtb_addr $fdt_file'

#double check the MAC Address matches with
#what is on the bottom of your Pogoplug
/tmp/fw_printenv ethaddr

#print out all uboot environment parameters
#make sure there are no errors
/tmp/fw_printenv > /fw_printenv.txt
/tmp/fw_printenv



Setup Netconsole

More info here - http://forum.doozan.com/read.php?3,14,14


#Update IP Addresses as appropriate
#ipaddr = Pogoplug IP
/tmp/fw_setenv preboot 'run preboot_nc'
/tmp/fw_setenv ipaddr '192.168.1.10'
/tmp/fw_setenv serverip '192.168.1.100'



Debian Installation on USB Hard/Flash Drive


Plug in your USB flash drive

#Partition your USB flash/hard drive
/sbin/fdisk /dev/sda

# Type in the following commands to erase
# and re-partition USB flash/hard drive
#(WARNING - FLASH/HARD DRIVE WILL BE COMPLETELY WIPED):
#
# p # list current partitions
# o # to delete all partitions
# n # new partition
# p # primary partition
# 1 (one) # first partition
# <enter> # default start block
# <enter> # default end block (to use the whole drive)
# If you're using a hard drive, create a small
# 4GB partition instead of using the whole drive,
# leaving the rest for a data partition
# +4G # to create a 4GB partition
# w # write new partition to disk


#Format USB Flash Drive
cd /tmp
wget http://archlinuxarm.org/os/pogoplug/mke2fs
chmod 755 mke2fs

#format as ext3 and label partition as 'rootfs'
./mke2fs -L rootfs -j /dev/sda1

#mount
mkdir /tmp/usb
mount /dev/sda1 /tmp/usb
cd /tmp/usb

#Download Debian rootfs
wget http://download.qnology.com/pogoplug/oxnas/Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2
wget http://download.qnology.com/pogoplug/oxnas/Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2.md5

#check md5sum
md5sum -c Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2.md5

#extract
tar -xvjf Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2

#cleanup
rm Debian-3.17.0-oxnas-tld-1-rootfs-bodhi.tar.bz2*

#Sync and reboot, cross your fingers
sync
cd ..
umount /tmp/usb
reboot


At this point, your Pogoplug should boot back up into Debian. Note that the IP Address of your Pogoplug may have changed. Double check your router for the IP Address assigned to your Pogoplug or use a network scanning tool (iNet Network Scanner on iPhone) to determine the IP Address of the Pogoplug.

For Debian, the default username and password is root/root.

Initial Debian Setup


#Change password
passwd

#Generate New OpenSSH Keys
rm /etc/ssh/ssh_host*
ssh-keygen -A

#Initial update
apt-get update
apt-get upgrade

#Set hostname to DebianPlug or whatever you like
echo DebianPlug>/etc/hostname

#Set Time Zone
tzselect

reboot


Upgrade Debian to 3.18.5 kernel


Latest kernel and instructions here - http://forum.doozan.com/read.php?2,16044


#backup original kernel files
cd /boot
mkdir backup
mv *3.17* backup
mv uImage backup/uImage3.17
mv uInitrd backup/uInitrd3.17

#download from bodhi's dropbox
wget --no-check-certificate https://www.dropbox.com/s/o9fp0xg8b6aajg6/linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2

#check md5
echo "df386f09cf7323472d40432d3da382d5 linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2" |md5sum -c

#extract
tar -xvjf linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2

#install kernel and headers
dpkg -i linux-image-3.18.5-oxnas-tld-1_1_armel.deb
dpkg -i linux-headers-3.18.5-oxnas-tld-1_1_armel.deb

#Create uImage and uInitrd manually
mkimage -A arm -O linux -T kernel -C none -a 0x60008000 -e 0x60008000 -n Linux-3.18.5-oxnas-tld-1 -d /boot/vmlinuz-3.18.5-oxnas-tld-1 /boot/uImage

mkimage -A arm -O linux -T ramdisk -C gzip -a 0x60000000 -e 0x60000000 -n initramfs-3.18.5-oxnas-tld-1 -d /boot/initrd.img-3.18.5-oxnas-tld-1 /boot/uInitrd


#clean up
rm linux-3.18.5-oxnas-tld-1.bodhi.tar.bz2
rm *.dtb

#reboot and verify
reboot

uname -a


Pogoplug Pro Wireless Configuration


#update fdt file to pogoplug pro and reboot
#Warning: if you don't truly have a pro, your pogoplug
#will not boot properly.

fw_setenv fdt_file '/boot/dts/ox820-pogoplug-pro.dtb'
reboot


Follow Debian on Pogoplug Tutorial - Wireless Configuration


Pogoplug Pro - AzureWave AW-NE762H 802.11 b/g/n PCI Express RT3090

Pogoplug V3 - Dual 700Mhz ARM, 128MB RAM, SATA (internal),
Gigabit Ethernet, 4 USB 2.0 Ports, Wireless (Pro only)



Wednesday, February 11, 2015

OpenWRT on Pogoplug Mobile

Booting OpenWRT from internal flash on Pogoplug Mobile

In this tutorial we're replacing the original Pogoplug OS on the internal flash with OpenWRT. OpenWRT is a lightweight but feature rich Linux distribution for embedded devices. 


The Pogoplug is arguably one of the best OpenWRT platform for the price and performance. You can use OpenWRT on the Pogoplug as your main Linux distro skipping the need for a USB flash drive or SD Card, or just use it as a Rescue System (for fixing corrupt disk or reinstallation) if something goes wrong with your ALARM or Debian installation.


This tutorial assumes you have completed my previous tutorial - Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) - and already running Debian or ArchLinuxARM (from a USB drive or SD Card) on the Pogoplug Mobile.


Note that for the Series 4, the USB3 ports does not work properly yet with OpenWRT. Hopefully this will get resolved in the near future. [Edit] - Looks like the USB3 ports work with USB3 devices and if you plug in a USB3 device, the other USB3 port will work with a USB2 device.


WARNING: There is no going back to the Pogoplug OS. You will not be able to use the my.pogoplug.com service. Please proceed at your own risk.


LETS GET STARTED:

Boot up Debian or ArchLinuxARM on your Pogoplug. All commands below assumes you're running Debian or ALARM.

#Update mtdparts so we have one continuous partition to work with.
cd /tmp
wget http://download.qnology.com/pogoplug/v4/fw_setenv
chmod +x fw_setenv

#setup fw_env.config
echo "/dev/mtd0 0xc0000 0x20000 0x20000">/etc/fw_env.config

#1MB for the uBoot, the rest for rootfs (~122MB)
/tmp/fw_setenv mtdparts 'mtdparts=orion_nand:1M(u-boot),-(rootfs)'



#This reboot is important
reboot

After rebooting double check the mtdpart is correct.

cat /proc/mtd

#root@debian:~# cat /proc/mtd
#dev: size erasesize name
#mtd0: 00100000 00020000 "u-boot"
#mtd1: 07f00000 00020000 "rootfs"
#mtd2: 00010000 00008000 "spi0.0"


#download firmware/nand utilities
cd /tmp
wget http://download.qnology.com/pogoplug/v4/fw_printenv
wget http://download.qnology.com/pogoplug/v4/fw_setenv
wget http://download.qnology.com/pogoplug/v4/ubiattach
wget http://download.qnology.com/pogoplug/v4/ubimkvol
wget http://download.qnology.com/pogoplug/v4/ubiformat

#make executable
chmod +x fw_printenv fw_setenv ubiattach ubimkvol ubiformat   

#format mtd1 (rootfs)
#Will be prompted for confirmation three times.
/tmp/ubiformat /dev/mtd1

/tmp/ubiattach -p /dev/mtd1
/tmp/ubimkvol /dev/ubi0 -m -N rootfs

#mount ubi rootfs to /tmp/ubi
mkdir /tmp/ubi
mount -t ubifs ubi0:rootfs /tmp/ubi

#Chaos Calmer 15.05
cd /tmp
wget http://downloads.openwrt.org/chaos_calmer/15.05/kirkwood/generic/openwrt-15.05-kirkwood-generic-rootfs.tar.gz
wget http://downloads.openwrt.org/chaos_calmer/15.05/kirkwood/generic/openwrt-15.05-kirkwood-zImage   
wget http://downloads.openwrt.org/chaos_calmer/15.05/kirkwood/generic/md5sums

#Trunk release.
#Note that Barrier Breaker 14.07 doesn't work.
#cd /tmp
#wget http://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/openwrt-kirkwood-generic-rootfs.tar.gz
#wget http://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/openwrt-kirkwood-zImage
#wget http://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/md5sums


#check that zImage and rootfs.tar.gz are OK
md5sum -c md5sums

#extract rootfs.tar.gz to ubi rootfs at 
/tmp/ubi
cd /tmp/ubi
tar xvzf /tmp/openwrt*rootfs.tar.gz

mkdir boot
mv /tmp/openwrt*kirkwood-zImage ./boot/zImage

#FDT from http://forum.doozan.com/read.php?2,12096
cd boot

wget http://download.qnology.com/pogoplug/v4/kirkwood-pogoplug_v4.dtb

sync
cd /

umount /tmp/ubi


#Setup uBoot Environment

#Cut and Paste this whole section
/tmp/fw_setenv fdt_file '/boot/kirkwood-pogoplug_v4.dtb'
/tmp/fw_setenv loadaddr '0x800000'
/tmp/fw_setenv zimage '/boot/zImage'
/tmp/fw_setenv fdt_addr '0x1c00000'
/tmp/fw_setenv loadubi 'echo Trying to boot from NAND ...;if run mountubi; then run loadubizimage;run loadubifdt;ubifsumount;run bootzubi;fi'
/tmp/fw_setenv mountubi 'ubi part rootfs; ubifsmount ubi0:rootfs'
/tmp/fw_setenv loadubizimage 'ubifsload ${loadaddr} ${zimage}'
/tmp/fw_setenv loadubifdt 'ubifsload ${fdt_addr} ${fdt_file}'
/tmp/fw_setenv bootzubi 'echo Booting from nand ...; run setargsubi; bootz ${loadaddr} - ${fdt_addr};'
/tmp/fw_setenv setargsubi 'setenv bootargs console=${console},${baudrate} ${optargs} ubi.mtd=1 root=ubi0:rootfs rw rootfstype=ubifs rootwait ${mtdparts}'

#Setup boot order.
#USB->SD->SATA->UBI/NAND
/tmp/fw_setenv bootcmd 'run bootcmd_usb; run bootcmd_mmc; run bootcmd_sata; run loadubi; reset'

#poweroff Pogoplug and remove SD Card and USB flash drive.
poweroff

At this point, we're ready to boot into OpenWRT. Note that by default, OpenWRT will default to 192.168.1.1 and will act as a DHCP Server. Plug a network cable from your computer directly into the Pogoplug and power it on. You should now be able to Telnet into the Pogoplug at 192.168.1.1 (username and password not required). Note that SSH is disabled and will automatically start after a root password is set.

#####Initial Boot via Telnet######
#set passwd and enable ssh
passwd

#Reconfigure Network to DHCP Client

#disable dhcp server on lan
uci set dhcp.lan.ignore=1
uci commit dhcp
/etc/init.d/dnsmasq restart

#set wired ethernet interface to dhcp client
uci set network.lan.proto=dhcp
uci commit network
reboot


Plug the Pogoplug and your computer back into your network. Check your router for the IP Address assigned to your Pogoplug. You should now be able to SSH into the Pogoplug.

Note that since we're using the daily snapshot trunk build of OpenWRT, you'll need to install your kernel packages right away (kmod-xxx), otherwise it will get out of sync.



#####Initial OpenWRT configuration#####
opkg update

#Install some essential packages
opkg install nano wget luci uboot-envtools pciutils usbutils 
kmod-usb2 kmod-usb3 kmod-mmc kmod-usb-storage block-mount kmod-fs-ext4 kmod-fs-vfat kmod-fs-ntfs kmod-nls-cp437 kmod-nls-iso8859-1 e2fsprogs fdisk 

#SAMBA - configure via luci web gui
opkg install samba36-server samba36-client luci-app-samba



Major credit goes to @moonman on the ArchLinuxArm Forum - http://archlinuxarm.org/forum/viewtopic.php?f=30&t=8383

Wednesday, November 26, 2014

Debian on Pogoplug Tutorial - Webmin Installation

This is a continuation of my Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) Tutorial.




Webmin Installation


#Install required packages
apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

#downloand and install webmin
cd /tmp
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.720_all.deb
dpkg --install webmin_1.720_all.deb


#Webmin will automatically start on boot up.
#To stop Webmin from starting at bootup
update-rc.d -f webmin remove

#Auto Start Webmin on Boot
update-rc.d webmin defaults



Access Webmin @ https://IPAddress:10000

Reference: http://www.webmin.com/deb.html

Debian on Pogoplug Tutorial - MJPG-Streamer (WebCam) Installation

This is a continuation of my Hacking the Pogoplug v4 (Series 4 and Mobile) with Linux (Debian or Arch) Tutorial.



Tested WebCams:

NOTE - Newer kernel needs a patch. See https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=109352. Will update tutorial when I get a chance.

MJPG-Streamer Installation

#Install required packages
apt-get install unzip subversion libv4l-dev libjpeg8-dev imagemagick build-essential psmisc

#build mjpg-streamer
mkdir /tmpbuild
cd /tmpbuild
wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
unzip mjpg-streamer-code-182.zip
cd mjpg-streamer-code-182/mjpg-streamer
make
make install
cd /
rm -rf /tmpbuild

#Test - start mjpg_streamer on port 8088
#http://ipaddress:8088
mjpg_streamer -i "/usr/local/lib/input_uvc.so -f 15 -r 640x480 -d /dev/video0" -o "/usr/local/lib/output_http.so -w /usr/local/www -p 8088"

#Download service file for auto start on bootup
cd /etc/init.d
wget --no-check-certificate https://dl.dropboxusercontent.com/u/42238/pogoplug/debian/mjpg_streamerd
chmod +x mjpg_streamerd
update-rc.d mjpg_streamerd defaults


Motion (webcam security software) installation and configuration to come in another tutorial