Tuesday, December 29, 2020

The Kitty Tube Project

Our neighborhood has a lot of feral cats. Well, they are mostly feral. By this I mean most of them will not suffer a touch from a human while a small segment of them will. Behind our back yard and across the alley, some neighbors have established a bit of colony. There are some shelters and the cats get fed back there. So, most of the population is visible in our back yard. However, one kept showing up in front of our house, a fixed female gray and white tabby. 

We started feeding her this year. Mrs. Fowler decided she should be named Lana. I sometimes call her Lala and well now she gets called either interchangeably. Before long a big oafish fixed tuxedo cat started to show up at feeding times as well. He became Sylvester. We have not verified Sylvester's gender, but since he's such a big cat, we just assumed male. The two get along okay and we have been feeding them both and no others happily since.

For a couple of years I've considered adding some feral cat shelters of my own. The colony out back is fine, but cats can be a disagreeable lot, so I always thought it would be good to add a little extra capacity. I looked at various howtos and tutorials. Some of the DIY cat shelters are quite nice. I even went as far as to online shop a local home center for parts. But, I became frustrated. So I shopped for ready-made shelters on Amazon. This is where I found The Kitty Tube. It seemed a sound offering. It's definitely a little pricey, but very well engineered. I bought it for Lala. We weren't sure where she slept and it's been an unusually cold year.

Me being me, my first thought after ordering this was, "I bet I could add a camera to this thing so we would know what goes in it." I had a spare Wyze Cam and I was planning to place the shelter near our basement window. So once it was set up, the camera was added and Lala moved in the very first day.

As I mentioned, It's been pretty cold this year. We've had night time temperatures in the teens. I have read, that cats, in an insulated enclosed space, can raise the ambient temperature with their body heat. So, I got to wondering, "How warm does Lala make the shelter?" And thus I have now embarked on a project to make a remote temperature sensor. Sure, I could buy one. But it's more fun to make my own.

I have an old Node MCU ESP 8266. This is essentially a WiFi capable Arduino. My plan is to wire a temperature sensor to it. I'm testing an LM35 I had in my parts bin right now. It's running a simple web server and I can get a quick temperature reading by curling it's address. Once I know it works as I want, I'll package it up somehow, stick it in Lala's shelter, and power it from the USB plug on the back of the Wyze Cam. Then I will have my answer.

Monday, November 2, 2020

What is sed?

What have I learned about sed?

Well, it's a stream editor, meaning it edits text that's fed through it.

When using sed to edit, you use regex filters and commands to make changes to the text.

I learned that sed applies it's entire program (filters and commands) to each line. So, it's important to be careful how you write these. If applied in the wrong order, you may over-edit the line you are editing.

I've learned that sed sends its output to the operating system's standard output stream. This means that you need to redirect this output to a file if you want to preserve the edits. It's a good idea to send the output to a temporary file first and then overwrite the original once you have confirmed correct edits.

Saturday, October 24, 2020

From IP to Hex and back again

 Did a one-liner to convert an IP address as a string into a string with 4 hex number pairs.

hexip=$(echo $ip | awk -F '.' '{printf "%02x%02x%02x%02x\n", $1,$2,$3,$4}')

Then from this string back to an IP address.

echo $hexip | grep -Eo '[A-Za-z0-9]{2}' | paste -s | awk -F '\t' '{printf "%d.%d.%d.%d","0x"$1,"0x"$2,"0x"$3,"0x"$4}'

Edit: It has occurred to me that given the fixed nature of the hexip string (it is always character pairs) there is no reason to grep and paste before using awk. Instead, this can all be done with one awk program.

echo $hexip | awk -F " " '{gsub(/../,"& "); printf "%d.%d.%d.%d","0x"$1,"0x"$2,"0x"$3,"0x"$4}'

IP and Grep to extract address

 This is just another one line command to extract a system IP address

ip -4 a show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

IP and JQ to extract address

 So I wanted to try to extract just the IP address of a named network adapter using bash. There are lots of ways to do this, but it turns out that the linux ip command supports output to JSON. This gets me thinking jq. After testing on Manjaro and Amazon Linux 2, this is the most reliable command I found.

ip -4 -j a | jq -r '.[] | select(.ifname | contains("eth0")) | .addr_info[].local'

Obviously the interface name is going to be different on different systems

 RasPi Pico and an OLED Screen My project for this morning was to connect a small I2C OLED screen to Raspberry Pi Pico and make it do someth...