Code – part 3 | Binary Watch

Last we talked about the Binary watch I was busy finishing up the second rendition of the working code and getting ready to complete the schematic.

As the date I head off to college comes nearer and nearer, the urgency of finishing my projects is heightening! And so I take to Spacemacs to venture through the depths of ATmega328P’s sleep modes, RTC modes, and more…

I roughly sketched out a nice schematic on EagleCAD that will soon be posted in my GitHub, but I gotta finish some hardware testing before that happens.

As for the code side of things, the next steps were to research sleep modules and see which ones work with my project set-up the best.

Reading through the datasheet is rather monotonous, it gave me a vague idea of what the sleep modules were, but I still had a hazy view of what I needed to do, so I headed over to the Arduino Stack Exchange.

My initial (albeit naive) idea was to keep the CPU, flash, and Clock running while putting all other modules to sleep. I started to test this, but disabling the modules had hardly no effect on the current pull of the ATmega328p, which was another reason I asked on Stack Exchange. One person said,

You do not want to keep the CPU running on a battery-powered project! You should use a timer for keeping the time, and let the CPU sleep. Ideally, you would connect a 32,768 Hz crystal to TOSC1/TOSC2 and have Timer 2 work in RTC mode. I have a clock running since June 2012 on the same pair of AA cells using this low-power technique.

This piqued my interest, so I went to research heavily on what RTC mode was, and how this stuff works alongside a sleep mode.

RTC stands for Real Time Clock, which is typically a 32.768kHz crystal externally connected to TOSC1/TOSC2 or XTAL1/XTAL2 pins. This RTC mode allows the entire microcontroller to sleep, while still ticking the external clock outside the sleep mode. With SLEEP_MODE_PWR_SAVE, the second-to-lowest power saving mode, you can wake it up through either a timer interrupt or a signal on the INT0/INT1 pin.

This seemed like the best solution, but how to implement it?
I have found *tons* of different code and libraries for this, so much so that I just got confused.

After much research and questioning, I came to two conclusions, of which I will try both:

1) Write code to work with an RTC/IC, like the DS1307 and code from this arduino library, that way I don’t have to mess around with setting all the hardware bits and bytes and confusing myself to no end. (more documentation on the arduino library here) It seems as though the DS1307 is a plug’n’play device, as long as you get the code right.

2) [as of 3-15-17 at 23:19] Test out Nick Gammon’s response on my Stack Exchange question. The code he gave me was very insightful with accomplishing all the bits and bytes and changing the hardware registers.

I have ordered some 32.768kHz crystals and the DS1307 board, both of which should come this Monday. In the meantime, I typed up some quick code to go with the DS1307, and adjusted the code from stack exchange. Both compile normally, so we’ll have to see how it works out when the actual hardware arrives. I’m sure mass debugging will entail…

Depending on which one works best for my purposes, I’ll adapt the schematic to the design and then start work on the PCB.



Connecting the Webserver to A Domain

Over the past week I have dedicated an insane amount of hours to getting this wordpress blog ported to my other domain. To do this, I had to set up a web server and redesign the website in HTML/CSS format.

To do this, I didn’t want to have to learn HTML, so I use a “wysiwyg” What You See Is What You Get HTML site generator, where you do all the design and it generates HTML code for you. I used BlueGriffon, and by far a great tool than some of the other wysiwyg things I found out there. BlueGriffon has a fairly smooth user interface, and an easy way of configuring things to the way you want them.

I used the Site Wizard’s tutorials on how to use BlueGriffon to generate a fully functioning website. His stuff is super thorough, so if you have absolutely no technical knowledge at all you’d be able to follow his stuff very easily.

I figured the best way to share files between my server and computer for now would be a GitHub repository. This repo stores all my sites files, so I can edit them on my computer, push to the repo, and pull on the server to put the changes in effect. Supes ezpz.

Now, to actually get the domain working with my server:

I didn’t have git or tmux installed, so that was the first pit stop. Since I’m using FreeBSD 12.0-CURRENT, there are no packages that are updated for the OS (since it’s a developers version, you have to install everything by hand. Even the package manager.

Anyway, to install git, cd /usr/ports/devel/git
sudo make
sudo make install
sudo make clean

The next step was to fix the DocumentRoot in two files, so my domain knows where to access the site files.

First, change DocumentRoot in /usr/local/etc/apache24/httpd.conf,

I git cloned thalliastree into apache’s data repo, so the path I put in DocumentRoot was:

DocumentRoot       /usr/local/www/apache24/data/thalliastree/

Also update the <Directory "path/here"> thing to have the same path as DocumentRoot.

Inside the <Directory "/usr/local/www/apache24/data/thalliastree/"> code block, you need to specify the initial index file that will pop up on your screen when someone accesses your site, which looks like this:
DirectoryIndex index.html

Where index.html is the homepage file for your site.

We need to update the path of one more file:

sudo vim /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf

Find the DocumentRoot line, then update the path to be the same as the one you updated earlier.

After that, everything should be ready to go, if you followed my other blog post: Setting up A Web Server on FreeBSD 12.0-CURRENT

Run sudo service apache24 restart on your webserver, direct a browser to your domain, and viola! Your newly designed website should appear 🙂

I had a problem where I couldn’t access my website from inside my network, which was partly fixed by adding an entry in /etc/hosts.

Now that this is all over, I can debut my new site, stay tuned for a blog post about moving to my newly hosted site 🙂


Setting Up A Web Server on FreeBSD 12.0-CURRENT

A project I’ve been meaning to accomplish before college is setting up a web server on my home server to host my blog. Now that I successfully got the wifi and ZNC working, I can get into some more exciting things!

My first task was to find out how to get a web server running on FreeBSD 12.0-CURRENT. This was pretty easy.

(make sure you have root permissions before proceeding)
portsnap extract
portsnap fetch update
cd /usr/ports/www/apache24/
sudo make install clean

You’ll have to wait a while after that last command, so be patient. This should get apache24 installed on your server. Often it may stop and ask you a few questions while installing, hit OK or Y to continue with the settings. Seriously, it took around an hour on my computer, so find something entertaining to learn or do while you wait!

Once that’s finished, sudo vim /etc/rc.conf and add the line apache24_enable="YES". Save and quit.

Next, cp /usr/local/etc/apache24/httpd.conf /root/httpd.conf.bak
Then, sudo vim /usr/local/etc/apache24/httpd.conf

Make ServerAdmin the email address you would like the server to send emails to if it encounters errors, and the ServerName as your IP address:port:

ServerName Ip.Addr.Number:80

After setting that up, I thought it wise to set up security type things before I put any data onto the domain I bought. From research and talking with UTW, setting up HTTPS seemed like the best idea.

Before I get that set up, though, I needed to get my domain to stop pointing at NameCheap’s servers and point to my server.

I went into NameCheap, found my domain, clicked on Advanced DNS and under the first option, Host Records you add 2 new A records.
One should have the host as @ and your IP address following that, and the second one should have the host as www with your IP address.
Make sure to delete the CNAME record that directs it to namecheap, as well.


(pardon my terrible mouse-handwriting.)


Next is setting up the SSL/TTS security stuff. We’re going to make a few directories, first.

mkdir /usr/local/etc/apache24/sites-available
mkdir /usr/local/etc/apache24/sites-enabled

Then we’re going to add a line into our configuration file:

sudo vim /usr/local/etc/apache24/httpd.conf

and add IncludeOptional etc/apache24/sites-enabled/*.conf underneath the ServerName line.

Now we need to enable the TLS module for Apache,

sudo vim /usr/local/etc/apache24/modules.d/020_mod_ssl.conf

and add these lines:

Listen 443
SSLProtocol ALL -SSLv2 -SSLv3
SSLPassPhraseDialog builtin
SSLSessionCacheTimeout 300

Save and quit, now head back to /usr/local/etc/apache24/httpd.conf and uncomment the line LoadModule ssl_module libexec/apache24/

Now we need to create a TLS configuration file:

sudo vim /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf

And add:

Don’t forget to update the places that say with your actual domain name.

Finally, we can move on to Let’s Encrypt! cd into /usr/ports/security/py-certbot and sudo make install clean. After it compiles, run sudo pkg install py27-certbot py27-acme.

Once complete, you can use this command to generate your certificate!

certbot certonly --webroot -w /usr/local/www/apache24/data/ -d -d

When generating my certbot certification, I ran into an error:

Detail: No valid IP addresses found for

To fix the first one, I had to change a record from A + DNS to a singular A record. Next, I made sure to port forward ports 80 and 443 on my router.

If you’re not sure how to port forward, find your local IP address and enter it into your browser. That should take you to your ISPs home page, where you can log in. From there, click around in settings until you find Port Forwarding options, and set up forwarding for HTTP(port 80) and HTTPS (port 443).

I also ran into the error that says, Error getting validation data. This was fixed by making sure the CNAME record in namecheap’s domain records was deleted.

Now we need to update the certificates in the configuration file.

sudo vim /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf and add these certificate lines:

SSLCertificateFile "/usr/local/etc/letsencrypt/live/"
SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/"
SSLCertificateChainFile "/usr/local/etc/letsencrypt/live/"

I got a few errors with these too, so make sure you have the right directories when you put them in the configuration file.

Then we’ll create a symlink for the sites-enabled directory, so TLS can find your cert files.

ln -sf /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf /usr/local/etc/apache24/sites-enabled/

Make sure there are no syntax errors:

apachectl -t

then sudo restart apache!

sudo service apache24 restart

Now to see if it actually worked. Run sockstat -4 | grep httpd, which should output something like this: screenshot.png

If that is what your output looks like, then time to celebrate!

My only error so far is that I cannot load my webpage from within my home network. I can access it outside of my home wifi network and others can access it as well, but other than that I have no access. Which is rather strange, but I’ll figure that out soon.

Next steps: find out how to get my blog on this thing.


i3wm Setting up backlight and sound

When moving to i3 window manager, my backlight and sound keys got disabled. This is a super simple fix.

Get to your i3 config in .config/i3/config, and enter these lines for the backlight:

# audio
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl -- set-sink-volume 0 +5%
bindsym XF86AudioLowerVolume exec --no-startup-id pactl -- set-sink-volume 0 -5%
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle

and enter in these for brightness:

bindsym XF86MonBrightnessUp exec "bash -c 'expr $(cat /sys/class/backlight/intel_backlight/brightness) + 100 | sudo tee /sys/class/backlight/intel_backlight/brightness'"
bindsym XF86MonBrightnessDown exec "bash -c 'expr $(cat /sys/class/backlight/intel_backlight/brightness) - 100 | sudo tee /sys/class/backlight/intel_backlight/brightness'"

Viola! Everything should work now 🙂

Difference between a Dictionary, an Array, a Record, and a Map

In programming, there are different structures available to sort your data.

These structures can look like a list, a dictionary, array, record, map, and I’m sure there are more that are slipping my mind at the moment. What distinguishes all these from each other?


An array is a linear list of data that is indexed. You can access the chunks of data by referencing the array, and the part of memory the data is stored in.
Arrays are linearly ordered, so it keeps its index structure. Arrays hold homogeneous data, meaning it can only hold one data-type at a time.
You could have an array of strings, or an array of integers, but you can’t have an array that holds integers and strings. Certain programming languages, like common lisp, allow arrays to have heterogeneous (different) datatypes, whereas other programming languages are strict about having the same datatype.
Arrays can be fixed-length or resizable.


A record differs from an array because they must be a fixed number of fields, the fields each have a name, and the fields can hold different datatypes. There is no general order to the record, so the fields are accessed by name.

You could have a record named “Friend” that holds someone’s name, age, and date of birth. Then you could create an array to hold the record. A record’s values are called “members”.


A dictionary is a data structure that organizes data in key:value pairs. You access the value from the dictionary by identifying/passing the key, which is searched for in the dictionary, then the value matching the key is returned.

You could have “name” : “thallia”, “hobby” : “coding”. You could even have a dictionary within a dictionary, with sub-key/pair values depending on the sort of data you need to store.

The Map is, according to my research, virtually the same as a dictionary. Certain languages “name” dictionaries Maps, and certain languages say maps are “dictionaries”. They can be used synonymously, but that is typically avoided because the term “maps” is found in functional programming, which references high-order functions.

Happy learning!