All posts for the month October, 2021

Now and then, heavily used systems may need to have their swap usage cycled (reset) to increase performance. There are many occasions where even though a system has enough RAM, there may still be a growing swap usage. The steps I outline here are safe to run on a production host to reduce swap usage and return swap contents to RAM.

Check current swap use:

root@pkvm1:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           7800        4822         383           1        2594        2668
Swap:          4095         429        3666

We can see here that about 430MB of swap is used even though there is plenty of RAM available. In this case, the system gets average consistent use and has been up for 206 days. We want to also see what the swappiness setting is currently set at and maybe reduce it:

root@pkvm1:~# cat /proc/sys/vm/swappiness

root@pkvm1:~# sysctl vm.swappiness=20
vm.swappiness = 20
root@pkvm1:~# cat /proc/sys/vm/swappiness

This new setting of 20 should help the system swap less often. We now want to force the system to move swap contents back to RAM where it belongs. To do that, we’ll turn swap off, and WAIT approx. 30 seconds, then turn swap back on:

root@pkvm1:~# swapoff -a
root@pkvm1:~# swapon -a
root@pkvm1:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           7800        5295         143           2        2360        2194
Swap:          4095           0        4095

We can now see that swap contents has been moved to RAM and that swap has reclaimed space. It should be easy to write a cron job to check swap usage and periodically do this when swap usage goes above an acceptable threshold.

Those plug-in smart switches that are uniquitous in the market are only good to 10 amps. (most of them) I had one on my dehumidifier project to control when the dehumidifier would turn on and off (by turning it completely off, we save energy and money on the electric bill). After a couple years of use, the “plug in” smart switch died, likely because the dehumidifier draws close to or beyond the current limit of the small relay in those switches. I looked around on the ‘Net and was hard pressed to find something that would handle higher currents. The unit is on a 20A circuit so I needed to be sure that whatever I used was rated to switch that much current. Most of the relays that are out there for “arduino” projects seem to also be limited to 10 amps as well. Boo!

I found a relay on Amazon that was capable of switching up to 30 amps! I’m thinking “this ought to last”, but I need to build a circuit that can energize a 12V DC coil. The ESP8266 module runs on 5 volts, and doesn’t put out nearly enough voltage and current to drive the coil. I needed to add a 12 volt modular switching power source, a 5 volt regulator for the ESP8266, and a MOSFET transistor pack (triggered by the GPIO pin on the ESP8266) to switch the 12 volt supply and send DC to energize the relay coil. Here’s what I used to build this industrial strength appliance smart switch:

Of course, it goes without saying, I installed the open source Tasmota software on the ESP8266 module! I then set pin D1 to drive the relay:

12 VDC buck switching supply:

120-240VAC IN – 12VDC OUT

Here’s a picture of the ESP8266, 5VDC buck regulator, and MOSFET module all wired up on a PCB. This is what gives the switch its smarts and allows the automation system to control it over MQTT/WiFi:

Here you can see the large relay. It is DPDT (double pole, double throw), has a 12V coil, and the switch contacts are rated for 30A @250VAC:

This is the entire smartswitch build finished:

All enclosed in a sealed IP67 rated enclosure. This design can be used outdoors!

And of course, with power applied (it passed the smoke test!):


A neighbor (looking at you Chad) recommended cloudflare for my website and I figured I’d try it out.  Doing so entailed changing my NS records on my domain at the registrar.  This effectively moved all my DNS zone for the domain over to cloudflare.  Awesome!  Getting the benefits of cloudflare, only thing is, I realized that my old bash script which kept my home network IP tied to a DNS host name now no longer works.  I needed to update it.   So I set out to rewrite the script and figured I’d share it here, hopefully to help someone else wanting to have a DDNS hostname for a dynamic IP at home.  Without further delay, here’s the script, all that is needed is to plug in the values for the variable, set it in a crontab, and done:


myip=$(/usr/bin/curl -X GET "")
# Populate with your own cloudflare specs
myZoneID   = ""
myRecordID = ""
myKey      = ""
hostname   = ""
email      = ""

curl -X PUT "$myZoneID/dns_records/$myRecordID" \
        -H "X-Auth-Email: $email" \
        -H "X-Auth-Key: $myKey" \
        -H "Content-Type: application/json" \
        --data '{"type":"A","name":"'$hostname'","content":"'$myip'","ttl":1,"proxied":false}'

echo "$time IP Updated to: $myip for $hostname" >> /var/log/DNS-UPDATE-$(date +"%Y-%m-%d").log

In addition to updating your DNS record, this also keeps logs of the changes to preserve a history of IP address changes.