Saturday, September 4, 2021

 Home automation and Multiple rabbit holes


I've got two problems I'd like to solve, both of which seem easy, but don't have a ready-made bolt-on solution.  It feels like I'm missing an a-ha moment that would tie it all together.



Scenario 1:

Aranet4 air monitor doing CO2 monitoring

The Aranet only supports bluetooth, and doesn't have a web-hook or central logging system.

Winix Smart wi-fi 

Have it paired, and it supports alexa


Solution:

Buy/deploy a raspberry Pi with Bluetooth.  have it pair with the Aranet when the aranet is around.

Constantly read the Aranet.

When reading > 1000, then send a hook to Winix (via alexa?) to turn on

When reading > 900, send a hook to winix to turn off


--


Wemo light switches

we have switched outlets, which we're using to control both a fan and a light. Frequently turn off the light via the switch when the fan is supposed to be on, which kills both.

Solution:  look and see if I have hot wires in the wall and could make it half on?  
or:  Put in two wemos.  Now integrae them to homekit.  

Need:  Find a switch that will take wall power, and then just send a notification to homekit to turn certain devices on and off! Wall mount that so now wlal switch drives homekit, not power.


Tuesday, June 20, 2017

Checking linux congestion control

The network is slow!

Captures show no packet loss, and transit time across the LAN is negligible- but packets aren't getting out and put onto the wire quickly enough to make the transfer happen as fast as the user wants it.

TCP settings are all in files in /proc/sys/net/ipv4-  here's a quick line to print them all out.


ls -1 /proc/sys/net/ipv4/ | sort | while read line; do echo "$line,$(cat /proc/sys/net/ipv4/${line} 



The biggest thing I've found to look at are congestion control- tune it to your environment, but I have seen CUBIC work better than RENO to a significant degree in our cases.  I've gotten to "just change it to CUBIC and get back to me", but I haven't played with it in lab cases and forced every permutation of loss/delay/out of order in order to see what "real life experience" works with.


https://en.wikipedia.org/wiki/TCP_congestion_control

Tuning ideas- I'll take anything from nasa.gov:

https://www.nas.nasa.gov/hecc/support/kb/optional-advanced-tuning-for-linux_138.html


Friday, April 29, 2016

The Occasional sed, and other ways to solve problems

I find myself wanting to find things in text files, and rely upon the computer to get things right, rather than me spotting trends.  Sometimes I'll get close enough and then brute force the rest, but it's not 'the right way'.

Case in point:
I wanted to find a list of every feature set my NXOS boxes use.

Given:
All of my configs are in a standard directory


I can "grep feature *.cfg" and get a list-  but it comes out like this:

switchname.cfg:feature XXX
switchname2.cfg:feature XXX
switchname3.cfg:feature XXX

I can't pump it into "sort -u" which will uniqueify the list, because the filename was appended to the front of each line.

so my initial thought was to just trim off everything up to the : then sort on that, and I ended up down this rabbit hole:


grep ^feature *rt* | sed 's/\(^.*cfg:\)\(.*$\)/\2/' | sort -u  | more

this:
s/  starts the substitute pattern
 \( escape slash, and paren starts a catpure
^ matches beginning of line
.* matches everything
cfg:  search terminates on this
\) escape slash, and close parent to stop the capture

\( escape slash, and paren starts a capture
.*$ matches everything until the end of the line
\) escape slash, and close paren to end the capture

/ starts the replacement stanza
\2 specifies printing out the second capture group-  in essence, throwing everything in the line up to .cfg: away
/' end of the replacement stanza
| sort -u     sorts, and uniquifies it.






Of course, an easier way to do this was just:
grep -h 
prints out matches without prepending filename, and then I can just do the sort -u, and be done with it.

there's a lot of ways to skin a cat, and some are way more obvious than others.



Wednesday, March 4, 2015

Installing local packages for Python


As a network admin without admin rights on my box, installing modules is a pain.
Corporate politics make it tough to get things done quickly, if at all-  getting sudo privs, or even having an administrator install packages for me can be a no-go.

Here's the shorthands for what I've done to start installing non-standard python packages, so I can continue to script in my environment.

Proxy!

To get to the internet from my box, I need to turn on a proxy.

export http_proxy://192.168.1.1:80
export https_proxy://192.168.1.1:80


I can do this every time I log in-  or I can write it into my .bashrc
There's  lots of scripting you can do within your .bashrc to turn proxies on and off as needed-  but there's no need to get fancy for my work. Because my jumpbox is always at the same place and uses the same proxy, I don't need to get fancy and start importing variables to determine which proxy to use.
I put this into my .bashrc:

# Proxy package to turn proxy on and off
function proxy_on() {
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

        export http_proxy="http://webproxy_name:80"
        export https_proxy=$http_proxy
        echo "Proxy environment variable set."
        return 0

}

function proxy_off(){
    unset http_proxy
    unset https_proxy
    echo -e "Proxy environment variable removed."
}



Now when I log on, I just type 'proxy_on' or 'proxy_off' in order to get to the internet from my shell.

Way fancier ways and means of accomplishing more complex settings:
https://wiki.archlinux.org/index.php/proxy_settings


Setting the local repository for installation

 Now that I can get to the internet, easy_install won't time out.  But easy_install won't let me install the files, due to my non-elevated privs.

[host] easy_install netaddr
/usr/lib64/python2.6/site-packages/setuptools/package_index.py:7: DeprecationWarning: the md5 module is deprecated; use hashlib instead
  from md5 import md5
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 2] No such file or directory: '/usr/local/lib64/python2.6/site-packages/test-easy-install-29320.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib64/python2.6/site-packages/

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).


That's the kind of message I get when I try to install.  I need to specify a local directory!
There is a key bit of information I'll want, there, however-  note that I'm using python2.6-  your install may be different.

I'll create a directory in which to store my stuff:

mkdir -p $home/local/lib/python2.6/site-packages

The -p is needed to create all the parent directories from my home directory.
Note that the 2.6 portion of this path may change, depending upon your current version of python- you can determine this from the original error message.

Now I need to tell python where to look for these things:
export PYTHONPATH=${PYTHONPATH}:$HOME/local/lib/python2.6/site-packages


I can also dump that export into my .bashrc so I don't have to do it every time I log in.


At this point, I can install netaddr-

easy_install -d $HOME/local/lib/python2.6/site-packages netaddr

And now we're off to the races!

Other libraries I've  imported for their usefulness:


netaddr  - net addressing library - calculate subnets, etc.
infobloxpy  - interface into the Inboblox WAPI
ciscoconfparse  - parser for non NXOS configs
paramiko  - ssh client
pyexpect  - expect for python
beautifulsoup  - XML parsing (great for NXOS!)

Any other suggestions welcome!