Sunday, September 4, 2016

Pi Zero Ethernet gadget

So I'm sitting here on Labor Day weekend (US) waiting for Hurricane Hermine to reach NJ. It's predicted to follow a similar path as Sandy. Needless to say it's making us all a little nervous in the North East. All's quiet on the Eastern Front (that's a weather joke).

While waiting I decided to give the Raspberry Pi Zero a try. I followed the directions at Andrew Mulholland's Setting up Pi Zero OTG. I loaded up Raspian Jessie lite, config'd it as a Ethernet gadget and plugged it's USB into my Debian box. Up popped USB0 with a link-local address (169.254.x.x/16). I can then ssh pi@raspberrypi.local to reach it. Cool, I have a nice Tardis USB hub that the Pi will fit perfectly into.

Now comes the fun! I want to update the software. But the link-local addresses aren't really route-able (to simplify the discussion, don't do it). So how do I get the Zero connected to the internet? Well one easy route is with several networking statements and a sub interface (USB0:1). I'd put this under the category of more advanced network setup for Linux because I'll be configuring 3 machines to handle this. I've decided not do use NAT as it's unnecessary on the inside of my network. So here is the configuration commands for the various servers:

Notes: Let me start by saying that I've got a lot of networking experience and I do a lot of experimenting on my network. I've built IP tunnels, VRRP, RIPv2, OSPF and IPv6 on my systems. I'm skipping a lot of details I don't think you'll need but hopefully I haven't ignored something important. I've arbitrarily chosen to give the Pi Zero the IP address of (USB0:1), the USB Host: (USB0:1), the USB Host Ethernet: (the eth0 or wlan0), The firewall is and it also has a DNS server on it. You may need to adjust the network addresses for your own use. Also I have Quagga with RIPv2 running (not required) so I could add static routes there and my other servers would learn the route. Finally, I've not made any of this permanent except for the firewall.

For the Pi Zero (as root):

 # On the Pi Zero
sudo bash
ifconfig usb0:1
echo -e "#\nnameserver" >/etc/resolv.conf
route add default gw usb0:1

Bonus statements for the Pi Zero, I mounted a Samba server (my NAS) to the Pi. You'll need to define the SMB_USER, SMB_PSWD and I've used the user pi and group pi in this example. On the Pi Zero (as root):

 # Make sure that cifs-utils is loaded
mkdir -p /cifs
mount.cifs //samba/{$SMB_USER}/zero /cifs \
  -o user=${SMB_USER},pass=${SMB_PSWD},\

For the USB Host (as root):

 # On the USB Host
echo 1 >/proc/sys/net/ipv4/ip_forward
# Or
sysctl -w net.ipv4.ip_forward=1
# vi /etc/sysctl.conf
# net.ipv4.ip_forward = 1
ifconfig usb0:1

On the firewall I've translated the commands to the typical Linux commands. You'll need to adjust these for your particular router. Mine is actually a Ubiquiti ERLite-3 and uses very different statements. On the firewall (as root):

 # On the router
route add -net netmask gw
# Or
ip route add via dev eth0

Now that all has been said and done I'll let you know that the Pi Zero still supports the ssh pi@raspberrypi.local. I'm working on 2 different Tardis USB Hubs. I think one will remain a USB hub with the Pi as an Ethernet Gadget while the other I will turn into a remote USB Hub (a Pi, Wireless Dongle and the remote USB code).

Saturday, February 6, 2016

Canceled ride, Feb 5th

Well I had planned on riding today but thought better of it as I noticed the roads were still a mess. I did show up at Village Park to meet my riders. Mark and I were there, Drew's ride had 4 people and there was Barry. Drew informed me that Barry isn't supposed to be riding until he gets a doctors note (good to know). Drew decided to ride, I thought it best not to chance it. There was water everywhere and with water there's bound to be black ice. I'm still dying to get my miles in but not at the cost of not being able to ride for weeks or months into the year. I still have March and April to get my miles up there. I'm planning on at least 1 double metric for June and possibly another for late May.

Saturday, October 10, 2015

Stressful month but my mind is still on Home Automation

I finished the article for Linux Magazine about Misterhouse (called King of the House). I didnt get a copy of the magazine, so I've ordered a copy of issue 178, which should be here soon. I've created a web page for the article and I'll add an errata in a short time as it needs a few minor things fixed up. I've been busy for the last month or two with all the things going on at work, around the house and at home. But in the back of my mind is always HA. Lately I've wanted to design a PCB based on the PIC32 chips. This will satisfy my electrical engineering background (I have a degree in electronics). These boards would form the basis for my HA remote nodes. I'll return to that shortly but in the meantime I mean to solve an issue with getting the remote nodes to be as dynamically configurable as possible (as reasonable?). I already have the PIC32/W550io board running a DHCP client. I'd love to see the board connect to a cloud MQTT service from a remote location (such as from IXR at Camp Evan (InfoAge)). The issue is dynamically configuring the topics (and eventually the IO). This requires a bit of coordination between application such as Misterhouse, MQTT and some kind of configuration Manager.

I've written a simple configuration manager in Node-Red/Node.js. The device publishes a hello to a given server and topic (device/hello). The manager then looks up the information and publishes the information to another topic (device/<mac>/cfg). Now I'll need to figure out how the device will interpret the information (then I can format the information properly such that it's easy to handle and easy parse).

I've also decided to setup a bridge between my MQTT and a Cloud MQTT. This will require a bit of planning but I can see this working well to allow remotes to share data and commands with Misterhouse which will only be connected to my local MQTT (not that it has to). While the very basic is working very well in Misterhouse, it does need additional work (error correction and failure recovery). All this means I need to work on my Mosquitto setup so that bridging, SSL/TSL, login/passwords and ACL are working properly.

Sunday, April 12, 2015

The campaign to revoke Gust, Gail and Windy's bike club membership!

I hereby put forth, before the board, a request to revoke Gust's, Gail's and Windy's club membership for abuse of rider members on club rides!

Wow, I thought last week's ride was windy. It was supposedly a stronger wind with higher gusts but this week's ride felt worse. I guess it really does have to do with ride selection. I was forced to start heading south into the open prairies of the NJ flat lands. This was the only way I could really get my mileage up to the 65 mile ride we did and ride to where I wanted to ride. Yes, I like to site-see while I ride, it's important. The hard part in selecting a ride is not only figuring out where you want to go but also figure out how to get there. My ride is called "Which every way the wind blows" because I tend to get head winds at some point. I try to adjust the ride as we go (hence cue sheets are useless on my rides). Yesterday's ride required I toss in a few extra miles and zig-zag through some tree lined and hilly roads (Province Line Rd outside Allentown NJ). One other part of ride selection is that I have hundreds of rides in my head and thousands of variations. This led to one funny incidence where a rider congratulated me on never getting lost to which I replied: "Oh $#!7 we took a wrong turn 3 miles back. We're doing the wrong ride.". I still get chided about that.

So other than the wind was there anything special about yesterday's ride? Well there were 3 other riders on my ride. Because of the mileage I tend to get only 1 or two riders. And the second, which was really exciting (okay, not really) was Hockamik Rd was being ground up. Never heard of it? Not surprised it's a bit off the beaten path near the Ft Dix Artillery range. We decided to ride down the road only to find it was extremely soft. Our tires sank to a depth of about two inches. Not what we expected from ground up road. We had expect a gravel like material. Boy were we disappointed. Another special thing about the ride was the gorgeous weather. It was in the mid 60's and I would gladly take the wind and that temperature vs the winter we had. The coldest ride I did was 26F which was only slightly better than being stuck indoors. Well next week I have a 78 - 82 mile ride down to the edge of the Barrens (Mt. Misery Rd and New Lisbon). Hopefully there will be less wind and my avg. speed can get to a respectable level. Besides putting on too much weight and asthma and wind and getting older and not getting in as much base miles as I usually do I can't understand why I'm so slow.

Tuesday, April 7, 2015

Who invited Gust, Gail and Windy?

Yup, Saturday, Sunday and Monday's rides were very windy and the usual trio decided to ride with us (Gust, Gail, and Windy). Of course now it's going to rain for the next few days (wish I could ride with Gust, Gail and Windy instead). Despite the 20+ mph NW winds it was nice to have warm day to ride. Saturday started out like any other ride, I wore out the rear tire and needed to replace it before we could leave Cranbury. I created a 50 mile loop that would first take us East, then turn North and allow us to zig-zag north and west to the Griggstown Canal. The 50 miles was important since I suffered a nasty asthma attack a few weeks ago and I haven't been able to build up my miles as much as I'd like. So how strong were the winds? Well I managed to get pushed up the hill at the quarry in Kingston (no pedaling required). Made this flatlander feel like quite the climber. ;-)

Our first rest stop was 36 miles into the ride at the Main Street Kingston Eatery on Rt 27 in Kingston. We met up with Wendell and his friends (they were riding fixed gears, ouch). It was nice to meet up with a bunch of cyclists who don't look at you funny when you says your only doing 50 miles. ;-)

Next month I have the CJBC's Farmlands Century. After that I start training like I'm doing the CJBC's Longest Day ride (210 miles). I won't actually be able to do the ride but I do love to do the training. So all these base miles should help smooth out that first Century. I'm also expecting that it will have an effect on my weight which I've allowed to get too far from healthy.