November 15, 2017

One-Wire Temperature collection, publishing to EmonCMS using OmegaOnion

I needed a quick solution to log the temperature of my hot water cylinder at home, had an Omega Onion lying about so used that.

OmegaOnion
OmegaOnion EXP Dock
2 x DS18B20 Sensors, wired together with a 5K7 pull-up resistor

From a factory reset:


  • echo "w1-gpio-custom bus0=0,19,0" > /etc/modules.d/55-w1-gpio-custom
  • reboot
  • Find the names of the sensors, "ls /sys/devices/w1_bus_master1/
  • opkg install curl
  • opkg install nano
  • nano temp.sh
#!/bin/ash
temp1=$(awk -F= '/t=/ {printf "%.03f\n", $2/1000}' /sys/devices/w1_bus_master1/28-000006560975/w1_slave)
temp2=$(awk -F= '/t=/ {printf "%.03f\n", $2/1000}' /sys/devices/w1_bus_master1/28-0000065711e6/w1_slave)
curl --data "data={temp1:$temp1,temp2:$temp2}" "http://192.168.1.129/emoncms/input/post.json?node=55&apikey=xxxxxxxxxxxx"
printf "\n"$temp1"\t"$temp2

  • Then all you need is to create a cron job, crontab -e
*/5 * * * * /root/temp.sh >/dev/null

November 13, 2017

SprinklePi


HL-58S V1.2

IO Ports


Pins

11
12
13
15
16
18
22
7

EFA TLS Cert with Intermediate

Export Cert from NAS

Edit /etc/postfix/ssl/rsa_smtpd.pem

Remove the current contents

Paste in your private key
Then your certificate
Then your chain
save file

restart postfix - service postfix restart

August 28, 2017

ESXi 6.5 Install Realtek NIC Drivers

esxcfg-info | less -i

https://www.v-front.de/2015/03/vsphere-6-is-ga-ultimate-guide-to.html

Install Realtek R8168 drivers

# Lower the system's acceptance level to allow Community supported packages
esxcli software acceptance set --level=CommunitySupported
# open firewall for outgoing http requests:
esxcli network firewall ruleset set -e true -r httpClient
# Install e.g. net55-r8168 from the V-Front Online Depot
esxcli software vib install -d https://vibsdepot.v-front.de -n net55-r8168
# Reboot
reboot

Perl script to shutdown VM's on ESXi 6.5

I use this script to shutdown all my VM's when UPS battery is low, or when I need to do updates on my NAS'

#!/usr/bin/perl

# Get list of ALL VM's
# (\d{1,2})\s+([\w\d\-]+).*\n

$cmdvmlist = "vim-cmd vmsvc/getallvms";

# RegEX for running VM's
# ([\d]+\-[\w\d\s\.]+)\n\s+World ID:\s(\d+)

$cmdvmrunning = "esxcli vm process list";

$esxhost = "root\@192.168.1.26";

$vmlist = `ssh $esxhost $cmdvmlist`;

#print $vmlist;

# ([\d]+\-[\w\d\s\.]+)\n\s+World ID:\s(\d+)

my @shutdownorder;

$count=0;

print "VM Inventory on $esxhost\n";

while ($vmlist =~ /(\d{1,2})\s+([\w\d\-]+).*\n/g)
        {

        # Don't shutdown the VM running this script until last as it also controls APCUPSD

        if ($1 != 30)
                {
                $shutdownorder[$count] = $1;
                $shutdownordername[$count] = $2;
                $count++;
                }

        }

print "VMID\tName\n";

my $index;
for my $order (@shutdownorder) {
  print "$order \t $shutdownordername[$index++]\n";
}

# If shutdown argument is present, shutdown VM's

if ($ARGV[0] eq "shutdown")
        {
        open (my $fh, '>', "/tmp/esxhostscript");

        print "\nCreating Script for ESX Host\nUploading ";

        while (@shutdownorder)
                {
                $vm = shift(@shutdownorder);

                print $fh "vim-cmd vmsvc/power.shutdown $vm\n";
                }

        close $fh;

        # Copy script to ESX Host

        system("scp","/tmp/esxhostscript","root\@192.168.1.26:/tmp/esxhostscript");

        # Add Execute Permission

        system("ssh","root\@192.168.1.26","chmod +x /tmp/esxhostscript");

        # Execute Script

        system("ssh","root\@192.168.1.26","/tmp/esxhostscript");

        print "Waiting for VM's to shutdown\n";
        $timeout = 300;

        while (CheckRunning())
                {
                print "$timeout ";
                sleep 5;
                $timeout=$timeout-5;
                if ($timeout<=0){exit;}
                }
        print "\n\n";

        }

else
        {
        printf "shutdown argument not passed, no action taken\n"
        }


sub CheckRunning
        {

        $vmrun = `ssh $esxhost $cmdvmrunning`;

        while ($vmrun =~ /([\d]+\-[\w\d\s\.]+)\n\s+World ID:\s(\d+)/g)
                {

                if ($1 ne "0-Control")
                        {
                        return 1;
                        }
                }
        return 0;
        }

To start them backup I use the autostart script on the ESXi Host:

ssh root@192.168.1.26 /sbin/vmware-autostart.sh start


LetsEncrypt for EFA

Updating EFA Cert

On efa server chown -R billw:billw certs

On Ubuntu box

letsencrypt certonly --manual --preferred-challenges dns -d efa.wjw.nz

openssl x509 -outform der -in /etc/letsencrypt/live/efa.wjw.nz/cert.pem -out /etc/letsencrypt/live/efa.wjw.nz/localhost.crt
openssl rsa -outform der -in /etc/letsencrypt/live/efa.wjw.nz/privkey.pem -out /etc/letsencrypt/live/efa.wjw.nz/localhost.key
scp /etc/letsencrypt/live/efa.wjw.nz/cert.pem billw@192.168.1.46:/etc/pki/tls/certs/localhost.crt

July 04, 2017

landscape

apt-get install landscape-client

cd /etc/landscape

wget https://letsencrypt.org/certs/letsencryptauthorityx3.pem.txt

mv letsencryptauthorityx3.pem.txt letsencryptauthorityx3.pem

landscape-config --computer-title "TEMP" --account-name standalone  --url https://control.wjw.nz/message-system --ping-url https://control.wjw.nz/ping --ssl-public-key /etc/landscape/letsencryptauthorityx3.pem