Monday, April 25, 2016

Home Automation


Ultimate goal: implement home automation or IoT system on a budget.

A few components on my radar:

IoT systems:
meshblu - https://github.com/octoblu/meshblu
the thing system - https://github.com/TheThingSystem/steward
kaa - https://github.com/kaaproject/kaa
contiki - https://github.com/contiki-os/contiki
freeboard - https://github.com/Freeboard/freeboard

Home automation systems:
openhab - https://github.com/openhab/openhab or https://github.com/openhab/openhab2
homegenie - https://github.com/genielabs/HomeGenie.git
domoticz - https://github.com/domoticz/domoticz

Devices:
raspberry pi 2
esp8266

Helpful blogs or other resources:
http://www.datamation.com/open-source/35-open-source-tools-for-the-internet-of-things-1.html
http://tech.scargill.net/esp8266-and-mqtt-a-marriage-made-in-heaven/
http://tuanpm.net/native-mqtt-client-library-for-esp8266/
https://gcoupe.wordpress.com/2015/03/15/home-automation-revisited/

Sunday, March 29, 2015

Change forgotten password in linux using initramfs

If you have been encountered with a linux box and you can't remember the password or just desperately need to get into the box, here is an easy way of doing so without using any external tools.


  1. Reboot the box
  2. Hold down the shift button upon starting up so you get into the grub menu
  3. Press the "e" key to edit the first option in the menu
  4. Append "break=init" to the end of the line that contains the linux boot parameters
  5. Press F10 to boot using the edited grub script
  6. You should now be prompted with the initramfs user handle
  7. The partition that was mentioned in the grub menu is mounted, but in a readonly state
  8. /bin/mount -o remount,rw /
  9. passwd user
  10. exit
  11. exit
  12. You can now reboot normally and login as the user with the password you just changed

Monday, March 9, 2015

Quickly get openstack up and running

I just wanted to get openstack up and running to test it out.  Devstack is the quickest way to get this going.  Here's how I did it.

Environment:
macbook pro osx 10.10.2
brew
boot2docker

Steps:
  1. Get boot2docker
    1. brew install boo2docker
  2. Configure and run boot2docker (Allocate at least 3GB ram)
    1. boot2docker init -m 4096
    2. boot2docker up
    3. boot2docker ssh
  3. Get an ubuntu trust image
    1. docker pull debian:jessie
  4. Run it with the proper specs
    1. docker run -it -p 8000:80 -p 8443:443 --privileged --publish-all=true --name devstack debian:jessie /bin/bash
  5. Get the prerequisites for devstack
    1. apt-get update && apt-get -y install python net-tools bsdmainutils git build-essential libssl-dev libffi-dev python-dev sudo vim apt-utils
    2. yum update && yum install python git sudo iproute hostname
  6. Edit the policy-rc.d file or else we'll have issues with rabbitmq
    1. perl -pi -w -e 's/101/0/g;' /usr/sbin/policy-rc.d 
  7. Make a folder to put your devstack clone in and close it
    1. mkdir github
    2. cd github
    3. git clone https://git.openstack.org/openstack-dev/devstack
  8. Run devstack
    1. devstack/tools/create-stack-user.sh
    2. chown -R stack:stack /github/*
    3. su stack
    4. /devstack/stack.sh
  9. As a temporary fix until nova can be fixed as of 03/10/2015
    1. It will fail the first time, this is ok. It will complain about sslv3 because pyopenssl does not support sslv3 while nova still does
    2. cd /opt/stack/nova
    3. wget http://anonscm.debian.org/cgit/openstack/nova.git/plain/debian/patches/removed-reference-to-sslv3-removed-from-debian.patch?id=04d5dcd9e70c6caf0df7b10396285549a0e56e99
    4. git apply removed-reference-to-sslv3-removed-from-debian.patch\?id\=04d5dcd9e70c6caf0df7b10396285549a0e56e99 
    5. cd /github/devstack 
    6. ./clean.sh
    7. ./stack.sh

If you happen to encounter an error and need to restart, do the following:
  1. ./unstack.sh
  2. ./clean.sh
Then restart the process again with ./stack.sh

Issues:
  • cgroups is broken in ubuntu trusty.
  • tgt init script is broken in debian wheezy

Thursday, January 22, 2015

Fix Yosemite 10.10 Mac Mail Account Username Truncation

I have encountered an issue with a certain email account that required the username to be the actual email address.  By default on Yosemite (issue could be found on previous versions of OSX), the username of the account gets truncated upon creation.  This wouldn't be a problem if Mac Mail was designed with the ability to edit email account information, but it does not.  The username line that we need to edit is grayed out.

You have 2 options to repair this annoyance:

1. Remove and re-add the account again through Mac Mail preferences -> accounts with the correct username, not Mac Mail -> Accounts

2. (More fun way) Manually edit the plist located in /Users/yourusername/Library/Mail/V2/MailData/Accounts.plist
change your username under where it says username ;-)

This could also work if your username has changed or otherwise is in need of editing.

Wednesday, December 10, 2014

New Computer Build

Building my first legit computer! woo! I've bought plenty of parts in the past for my own and other client's computer, but have never built my own.  Here goes nothing!

I decided to be a bit adventurous and try to shove a reasonably higher end desktop into a 18" x 14" x 6" aluminum carrying case.  What I want out of this pc is to host lots of VMs which in turn host many intensive services and compile large programs.  Here are the specs:

Aluminum Breif Case:
http://www.amazon.com/gp/product/B0052PJ39C/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1

Intel i7-4790k
http://www.newegg.com/Product/Product.aspx?Item=N82E16819117369

EVGA NVIDIA GTX760 4gb
http://www.newegg.com/Product/Product.aspx?Item=N82E16814130949

Corsair H100i
http://www.newegg.com/Product/Product.aspx?Item=N82E16835181032

MSI Z97M micro ATX Gaming
http://www.newegg.com/Product/Product.aspx?Item=N82E16813130773

Mushkin Redline 1866 2x8gb model number 997119
http://www.newegg.com/Product/Product.aspx?Item=N82E16820226533

Corsair AX760
http://www.newegg.com/Product/Product.aspx?Item=N82E16817139042

Subtotal with discounts and rebates (black friday and cyber monday) : about $1050

Updates to come!

Tuesday, December 2, 2014

PXE Boot without hosting DHCP server (proxyDHCP)

proxyDHCP and PXE

My goal is to implement a way to create the most portable and plug-n-play method for PXE booting on an existing network regardless of subnet constraints.

A simple DHCP request is more than just acquiring an IP address, it has the capability to deliver information that aids in proper network configuration encompassing lots of special parameters in order to bring this DHCP requestor online.  Most just need an IP address and that's it.
A list of these special parameters can be analyzed here: http://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml

PXE booting is a method of booting off of the network.  This technology is not widely used because it is not enterprise reliable but is available in most standard bios configurations from major manufacturers of computers.

Why is PXE booting not reliable?  When a DHCP  request is made and it contains information containing PXE information, an IP address for the PXE host is delivered to the DHCP requester.  This IP address contains the bootable image or code that is to be transmitted over TFTP.  TFTP is very unreliable because there is no checking and is simply a game of chance.  Similiar to UDP, TFTP transfers do not check with the server to see if the packets were received so they could be lost in translation.  Also, TFTP does check to see if these packets are in order.

How can we make PXE reliable? Transfer the bootable image or code over HTTP.  As we all should know, HTTP is very reliable as it corrects both faults found in TFTP.

Unless the DHCP is configured otherwise, by nature computers don't care where the DHCP information comes from as long as they get it.  This sounds really insecure because it is.  This is also standard protocol for most internet connected "things".  On the flip side, if there is more than one DHCP server on the network actively leasing IP addresses a race will ensue to see which DHCP server can deliver the IP lease the quickest.  This is not an ideal situation for a stable and predictable network which is why PXE booting is almost always going to configured along side with the DHCP server.

What if there was a way to deliver PXE DHCP information without leasing an IP address or disrupting the natural flow of a predictable network and also reliably deliver bootable images and/or code?  There is, and I introduce proxyDHCP.

ProxyDHCP allows this very thing and, if configured properly, can adapt to the network in order to deliver a completely dynamic PXE server.  My post title was a little misleading in that a DHCP was not required... In fact it is required but in a state that would not interfere or modify the existing network.

I have done a lot of research and have concluded that psychomario's implementation of a runnable python-based PXE DHCP combo server is the best way for making this scenario a reality.

Huge props to psychomario for developing this awesome tool.

https://github.com/psychomario/PyPXE

However, there are a few caveats to these series of scripts.  The TFTP server and HTTP server python implementations only allow for 1 connection at a time.  The alternative would be to host your own TFTP and HTTP servers that can handle multiple connections such as a node.js simple server and "TFTP server for mac".  I have used both of these and successfully booted 20 computers at the same time in about 5 minutes with TinyCore Plus.



References, research, and code segments:

https://github.com/psychomario/PyPXE

http://www.fogproject.org/

http://www.fogproject.org/wiki/index.php/Using_FOG_with_an_unmodifiable_DHCP_server/_Using_FOG_with_no_DHCP_server

http://ipxe.org/gsoc

http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html

https://rom-o-matic.eu/

https://github.com/xbgmsharp/ipxe-buildweb/

/* ignore emacs backups and dotfiles */

    if (len == 0 ||

ent->d_name[len - 1] == '~' ||

(ent->d_name[0] == '#' && ent->d_name[len - 1] == '#') ||

ent->d_name[0] == '.')

      continue;

pypxe is the winner

Saturday, November 8, 2014

MR3020 Configuration After Installing a Snapshot

The MR3020 is a really neat and cheap router with a ton of capability if it's running Openwrt.  There have been a few formal releases over the past couple of years that are now considered obsolete.  The packages that are available to those releases are hardly ever upgraded as they were designed to work as they were at the time of the release.  If one would like to acquire and use the latest packages available to the Openwrt line, they would have to install a snapshot.  A snapshot is a nightly build of the very active Openwrt source.  These snapshots can be very unstable and possibly unusable, but the tradeoff can be worth it.  For me it was since I use dnsmasq a lot.
If you install a snapshot version on your router, you will not have luci.  This means everything has to be done by hand.  Here is how you do it on a MR3020.

Here are all of the packages currently installed with my snapshot:

base-files - 156-r43124
busybox - 1.22.1-3
dnsmasq - 2.72-1
dropbear - 2014.65-2
firewall - 2014-09-19
fstools - 2014-10-27-d71297353dc45eaf8f7c252246490746708530f9
hostapd-common - 2014-10-25-1
ip6tables - 1.4.21-1
iptables - 1.4.21-1
iw - 3.15-1
iwinfo - 2014-10-27.1-d5dc3d0605f76fbbbad005d998497e53a236aeda
jshn - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.10.58-1-8ba75c28f46d1c58a922f1e15f98d811
kmod-ath - 3.10.58+2014-10-08-1
kmod-ath9k - 3.10.58+2014-10-08-1
kmod-ath9k-common - 3.10.58+2014-10-08-1
kmod-cfg80211 - 3.10.58+2014-10-08-1
kmod-crypto-aes - 3.10.58-1
kmod-crypto-arc4 - 3.10.58-1
kmod-crypto-core - 3.10.58-1
kmod-gpio-button-hotplug - 3.10.58-1
kmod-ip6tables - 3.10.58-1
kmod-ipt-conntrack - 3.10.58-1
kmod-ipt-core - 3.10.58-1
kmod-ipt-nat - 3.10.58-1
kmod-ipv6 - 3.10.58-1
kmod-ledtrig-usbdev - 3.10.58-1
kmod-lib-crc-ccitt - 3.10.58-1
kmod-mac80211 - 3.10.58+2014-10-08-1
kmod-nf-conntrack - 3.10.58-1
kmod-nf-conntrack6 - 3.10.58-1
kmod-nf-ipt - 3.10.58-1
kmod-nf-ipt6 - 3.10.58-1
kmod-nf-nat - 3.10.58-1
kmod-nf-nathelper - 3.10.58-1
kmod-nls-base - 3.10.58-1
kmod-ppp - 3.10.58-1
kmod-pppoe - 3.10.58-1
kmod-pppox - 3.10.58-1
kmod-slhc - 3.10.58-1
kmod-usb-core - 3.10.58-1
kmod-usb-ohci - 3.10.58-1
kmod-usb2 - 3.10.58-1
libblobmsg-json - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
libc - 0.9.33.2-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libiwinfo - 2014-10-27.1-d5dc3d0605f76fbbbad005d998497e53a236aeda
libjson-c - 0.11-2
libjson-script - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
libnl-tiny - 0.1-3
libubox - 2014-10-14-464e05e33b4c086be0bd932760a41ddcf9373187
libubus - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
libuci - 2014-04-11.1-1
libxtables - 1.4.21-1
mtd - 20
netifd - 2014-10-24-b46a8f3b9794efed197ffd2f6f62eb946de5f235
odhcp6c - 2014-10-25-940e2141ab13727af6323c4d30002f785e466318
odhcpd - 2014-10-18-b461334ab277b6e8fd1622ab7c8a655363bd3f6c
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-7
ppp - 2.4.7-3
ppp-mod-pppoe - 2.4.7-3
procd - 2014-10-30-07c7864d49723b1264ee8bcd6861ea92f679ee98
swconfig - 10
uboot-envtools - 2014.07-1
ubox - 2014-10-06-0b274c16a3f9d235735a4b84215071e1e004caa9
ubus - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
ubusd - 2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3
uci - 2014-04-11.1-1
wpad-mini - 2014-10-25-1

You will notice luci is absent.

Here we go:

  1. First, here is the default configuration:
    1. The ethernet is configured with a dhcp server with a lan'd firewall with a static ip of 192.168.1.1
    2. The wifi is disabled and is not configured
      1. The default configuration for the enabled wireless interface is an access point, we need to get access to the internet so we can update and install the packages available to us in order to get luci.
      2. It is much easier to setup the wireless as a client with a wan and a gateway then to use the ethernet in the same manner since the majority is already setup to do so.
    3. The sliding switch (AP, WISP, 3G) is not active and currently does not serve a purpose besides allowing for a method to resort in a "failsafe" mode upon booting
  2. Connect your computer through ethernet is if it were a typical client accepting a dhcp lease
  3. Telnet to the static ip and change the root password by doing the following
    1. telnet 192.168.1.1
    2. passwd 
      1. enter the desired password
    3. exit
  4. Now ssh into the router by doing the following
    1. ssh root@192.168.1.1
    2. enter the password
  5. We are now in the router and will begin performing the configuration
  6. Enable the wireless
    1. vim /etc/config/wireless
    2. comment or delete the line that has "enabled 0"
    3. wifi down; wifi up
    4. The wifi has a default configuration as an access point
    5. see configuration below
  7. Setup the network configuration for the wireless as a client to get internet
    1. vim /etc/config/network
    2. see configuration below and append that to the end of the file
    3. wifi down; wifi up
  8. Setup the wireless network to interface with your external router or access point; the location where your local internet connection is coming from
    1. vim /etc/config/wireless
    2. see configuration below and edit the existing "radio0" device
    3. wifi down; wifi up
  9. Analyze the dmesg of the router.  If everything is configured correctly, you will notice that there will be a message that reads "wlan0 associated!"
  10. Verify that you are connected the internet
    1. ping google.com
      1. If you get ping responses then everything is good!
      2. If not, troubleshooting my need to take place... dmesg is your friend in this case
    2. opkg update
  11. We are now connected to the internet. You have 2 options at this point:
    1. You can read my previous post on how to make an extroot filesystem to allow more space for packages
    2. You can go ahead and install luci and luci-ssl (both are required in order for it to work correctly) and risk the possibility of a completely full disk
  12. With luci you can now easily configure your router
  13. As mentioned in my previous post on how to extroot your filesystem, you can restore the defaults if you screw up somehow by simply entering "firstboot"
  14. Finished!

Network file configuration to enable the wan firewall configuration for the client router with a couple of my favorite dns servers to get the best results (open dns and google):

config interface 'wan'       
        option ifname 'wlan0'
        option proto 'dhcp'
        option peerdns '0'   
        option dns '208.67.222.222 208.67.220.220 8.8.8.8 8.8.4.4'


Second wifi configuration for associating wireless with access point or router. This is configured to be a client (mode sta) to my wpa2 encrypted (encryption psk2) access point with a wan'd firewall and no dhcp since it will be accepting an ip lease (network wan):

config wifi-device 'radio0'               
        option type 'mac80211'            
        option channel '11'               
        option hwmode '11g'               
        option path 'platform/ar933x_wmac'
        option htmode 'HT20'    
                                
config wifi-iface               
        option device 'radio0'  
        option network 'wan'    
        option mode 'sta'       
        option ssid 'yourwifiSSIDhere' 
        option encryption 'psk2'                                    
        option key 'yourpasswordhere' 


Finished, enjoy! I hope this helped somebody and if you need any help with any of the above steps I'll the best I can to assist.