raspberry pi 3 B+ requires latest raspbian stretch

I just received a raspberry pi 3 B+ this week that I ordered from Newark.  I am using it to build another battery capacity test  data acquisition + analyzer.  I love the pi’s SD card copier accessory.  I used it to burn an exact copy of the image I have on a working analyzer to a fresh 8GB SD card.  This is particularly useful on this project because I have so many special packages, file systems, daemons, and configuration options set up on this pi, and wanted an exact copy.  The one I copied it from was running on a pi 3.  I put the SD card into my new pi 3 B+ and fired it up.

Raspberry pi 3 B+
Raspberry pi 3 B+

The power LED had a regular blinking pattern; three short, four long – if I remember correctly.  At first I thought I had a bad pi out of the box.  I then began to suspect the SD card.  It was the cheapest class 10 SD card I could find on Newark.  I put it into a pi 2 and it booted up just fine, so that wasn’t it.  Lo, and behold the pi 3 B+ will not run on raspbian jessie;  it must be stretch running linux kernel 4.1.

I downloaded the latest version of raspbian stretch, reformatted my SD card to a FAT file system, and used etcher to burn the image to the card.  Put it in, fired it up, and bam!  It started up just fine.  Bad thing is I will have to manually configure everything from scratch.

 

protect against wordpress xmlrpc.php exploit

goaccess has already paid off for me.  I have been checking it daily since I installed it and noticed that my most requested page was xmlrpc.php.  Tons of data was being POSTed to it.  After a quick search, I came across a tutorial for a brute-force attack to login to a wordpress site.

wordpress xmlrpc.php attack detection with goaccess
wordpress xmlrpc.php attack detection with goaccess

I immediately logged into my VPS and renamed my xmlrpc.php file, and the attacks stopped.  Thanks, goaccess.

goaccess web access log analyzer

Back when I was a freelance web designer,  I hosted most of my sites via a reseller account I had with Hostgator.  I was really pleased with the service.  They used cPanel, which in my opinion is very feature rich and easy to use.  It is the next best thing to a VPS.  Hostgator also provided the all-important awstats traffic analyzer.  I still think awstats is an extremely good access log analyzer,  parsing the log in every conceivable way and producing easy to understand graphs.

example of awstats
example of awstats

Setting up awstats on a server can be a pain, especially if you have several virtual hosts.  I just wanted something simple to check the traffic for this blog.  After contemplating writing my own analyzer, I decided to go with goaccess.  I followed this tutorial on digitalocean, and I am very pleased so far.

goaccess web access log analyzer
goaccess web access log analyzer

I manually went through parts of the access log, and obviously I have some bots from an ip address in hong kong trying to post bogus data to scripts that dont exist.  They didn’t get anything.

ip in hong kong POSTing bogus data to my webserver
ip in hong kong POSTing bogus data to my webserver

goaccess does just about everything I am interested in:  top pages, bandwidth, OS, browser, and referrers.  I highly recommend it.

DIY Home security with Raspberry pi zero w + Perl

I got a ring doorbell for Christmas.  It was a very thoughtful gift and I gotta admit it is very slick.  However, for some time, I have been using a home made security system based on the raspberry pi zero w and perl.

home made home security node based on pi zero w
home made home security node based on pi zero w

I designed it so that each node sends udp messages to a udp + LAMP server. I can view all the events on the server’s web interface.

UDP server receiving message from a node
UDP server receiving message from a node

The front-door node also has a TMP36 temperature sensor read by an MCP3008 adc, and a raspberry pi camera.  When the door is opened, it takes a picture two seconds later, and uploads it to the LAMP server.

diy home security web interface
diy home security web interface

I set up port forwarding on my ISP router so I can view my LAMP server from anywhere.

The udp client and server scripts are incredibly simple.

perl udp client script
perl udp client script
perl udp server script
perl udp server script
tmp36 + MCP3008 schematic
tmp36 + MCP3008 schematic
entry contact and LCD schematic
entry contact and LCD schematic

I go into somewhat more detail on my hackster account.  Off-the-shelf home security and automation products are fairly inexpensive and easy to set up nowadays, but for me, it’s just so much fun to build my own from scratch.

pine64 as a terminal server via UART

Still working on the maker space and expanding my networking lab.  I added a cisco 1721 router with a 10-base T wan interface card and a serial 1T WIC in addition to the built-in fast ethernet interface.  I also added an old cisco 2514 with two built-in AUI (ethernet) interfaces and two serial interfaces.

Cisco 1721 and 2514 routers
Cisco 1721 and 2514 routers

The computer at my work bench doesn’t have a serial interface that I can connect to the routers’ console interfaces, and I was too lazy to go get my usb to serial converter out of my van; especially when I had my pine64 nearby with an rs-232 to TTL converter.  I fired up my pine64 and connected the rs-232 to TTL converter to the UART pins on the pi-2-bus.  The converter and the console port of the routers are both DTE devices, so a null-modem (serial crossover) cable / adapter are necessary.  I hooked it all up like so:

Pine64 as a simple terminal server
Pine64 as a simple terminal server

Here you can see I have my pine64 connected to a cisco console cable via a null modem adapter and a gender changer.  First I had to ssh into the pine.   Now to install screen on my pine64.


sudo apt-get install screen
sudo screen /dev/ttyS2 9600

The second command tells screen to use ttyS2, which is the serial interface that is on the pi-2 bus and use 8-N-1 and 9600 baud. Now I’m in.

cisco router IOS command line interface
cisco router IOS command line interface

multipurpose J-K flip-flop circuit using an SN74LS109AJ

Since the new year, I have been working on setting up a maker space in my garage.  It’s coming along pretty good.  I set up some lights and receptacles on my existing utility counter top, and extended my wired network to a wall-mounted rack where I have some of my networking lab already installed.

home maker space
My home maker space

While organizing my tools and components, I came across a bunch of different IC’s that I didn’t know I had like the 74LS109AJ dual J-K-not flip-flop.

SN74LS109AF dual JK filp-flop
SN74LS109AF dual JK filp-flop

These can be very useful for a number of applications.  Back in school,  I used several of these in tandem to increment memory addresses in EEPROM’s.  Here is a small example of such a circuit using the 555 timer circuit I recently built.

JK flip flop truth table
JK flip flop truth table

Basically, I wired up the IC to toggle.  I used the output of the 555 astable multivibrator circuit as clk input to filp-flop one, and then had Q1 as input to flip-flop two.  It basically divides the frequency of the 555 twice.

555 timer and JK flip-flop breadboard
555 timer and JK flip-flop breadboard
binary counter with 555 and JK flip-flop
frequency divider with 555 and JK flip-flop

analyzing SPI on an MCP3208 12-bit analog to digital converter

The MCP3208 12-bit analog-to-digitial converter is the basis of my battery load test analyzer and online monitoring system which I call pid3A .  As I have mentioned before,  I implemented a bit-banged SPI driver for the mcp3208 in the perl programming language.  I use the analog-to-digital converters (adc’s) to sample the voltages of each cell in the battery plant at regular intervals to make graphs of the discharge curves.

MCP3208 Analog to digital converter
MCP3208 Analog to digital converter

pid3A is in it’s 2nd prototype and can accurately measure up to 24 cell voltages at a time with it’s three 8-channel mcp3208’s.  Occasionally, I will burn up a single channel on one of the adc’s, rendering the whole chip useless for my application.

I have written a lot of diagnostic software for pid3A to make sure the adc’s are functioning properly before I begin an IEEE450  load test.  To test all 24 channels, I made a test plug that puts 2.5VDC on each channel, takes 5 samples, and give the the binary output code and actual voltage of each sample.  It then gives me a color-coded go/no-go visual indication.  If there are any bad channels, I just change out the adc chip and re-run the diagnostic test.

mcp3208 test plug
pid3A test plug

Here is a sample of the output:

mcp3208 diagnostics
diagnostic testing of each ADC channel

You can see that the adc output codes and voltages are very steady.  The voltage is a function of the digital output code of the adc.  Above, most of the output codes are 2049.  Knowing this, and the reference voltage of 4.998VDC, you can calculate the actual voltage using this equation:

mcp3208 digital output code equation
mcp3208 digital output code equation

This is absolutely necessary for troubleshooting quickly, but sometimes I need to know what is going on at a microscopic level.  My multi-channel logic analyzer is the perfect tool to look at the underlying SPI protocol.

IEEE450 battery load test analyzer
IEEE450 battery load test analyzer

I know this just looks like a mess of wires, but I have my logic analyzer hooked up to the data-in, data-out, chip select, and clock lines of one of my mcp3208 chips.  Here is a close up of a frame from my diagnostic script:

SPI examination using PulseView
SPI examination using PulseView

This shows the driver clocking in 19 pulses.  The first few bits on the MOSI line tell the adc to use single (as opposed to differential) mode, and sample channel 001.  The rest of the MOSI bits are ‘don’t care’ bits, so my driver just set them all high.  The MISO line is the mcp3208 clocking out the actual binary output code.  In this case it is 2045, which in binary is 011111111101.  The slave select line goes low to initiate a sample, and goes high when finished.  PulseView shows me precisely what is happening, and lets me easily analyze the SPI protocol for proper function per the datasheet below:

mcp3208 SPI protocol framing
mcp3208 SPI protocol framing

HiLetgo 24MHz 8-channel logic analyzer + PulseView

I just recently got a HiLetgo 24MHz 8 channel USB logic analyzer on Amazon for $11.  I am blown away what you can do with it.

HiLetgo 24MHz 8-channel logic analyzer
HiLetgo 24MHz 8-channel logic analyzer

I downloaded a copy of the AppImage forPulseView at Sigrok.org.  With this setup, I have an amazing multi-channel oscilloscope right on my computer for just a few dollars.

I have three examples to show some of it’s capability based on some of my recent posts

  1. an example of a bit-banged SPI driver I wrote for a MAX7219 7-segment display driver
  2. the output of the 555 timer circuit I built in a recent post
  3. the I2C sda and scl lines of the MCP23008 perl-based gpio extender driver I wrote.

Here is the setup I have for the MAX7219 display driver.

pine64 driving a MAX7219 display driver

I am using my new pine64 to drive the display.  The datasheet for the max7219 describes in detail how to operate the chip like how to configure the driver via control registers and the data format. Below is the expected data format per the datasheet:

MAX7219 data format
MAX7219 data format

I connected my logic analyzer to the MOSI, CLK, and slave select lines and here is the output in PulseView.

Pulseview SPI
Pulseview SPI scan

You can see on the slave select line, I go high and low and then bang in 16 pulses on the clock line.   The data is on the MOSI (master out, slave in) line and tells the driver which LED’s to turn on.  This is awesome for troubleshooting problems with digital circuits.  What is really cool is PulseView’s ability to decode SPI.  The bottom line show the content of the frames in hex and binary.

Pulseview decoding SPI frames
Pulseview decoding SPI frames

One thing I find interesting with my perl based, bit-bang driver is that the clock pulses are irregular in their duty cycle.  This is easy to see if you zoom in on the clock line.

SPI Clock line of bit-banged driver. Irregular duty cycle.
SPI Clock line of bit-banged driver. Irregular duty cycle.

Each dot on the square wave represents a sample pulseview took.

Now for the output of the 555 astable multi-vibrator circuit I recently blogged about.  These were the parameters of my circuit.

555 timer calculator output
555 timer calculator output

And here is what PulseView saw.

555 astable multivibrator output seen with pulseview
555 astable multivibrator output seen with pulseview

The calculator says 4.3Hz and a 52.38% duty cycle.  That is pretty much what PulseView said.  The output of the 555 timer is very precise and regular.

Finally, lets take a look at an I2C example using my MCP23008 driver from the binary counter example I recently blogged about.  Well, this is the first scan with the logic analyzer that I am actually using the device’s hardware, in this case I2C.  That being the case, it is much faster than my bit-bang SPI example, and certainly the 4.3Hz 555 circuit.  At first glance, it doesn’t look like much.  I did tell PulseView what protocol I was using, and which lines were sda and scl.

I2C Logic analyzer output
I2C Logic analyzer output

You just see some periodic blips on the lines, but the frames are accurately decoded.  You have to zoom in to see what precisely is going on with the pulses.

I2C clock pulses
I2C clock pulses

Above is a blown up view of one of the blips from the complete trace above.

Every maker should have a logic analyzer for development and troubleshooting, and I highly recommend the HiLetgo analyzer I use.

decoding ADS-B with rtl-sdr

Per Wikipedia:

Automatic dependent surveillance—broadcast (ADS–B) is a surveillance technology in which an aircraft determines its position via satellite navigation and periodically broadcasts it, enabling it to be tracked.

It’s really easy and fun to see what planes are flying near you with a software-defined-radio dongle and dump1090.

After installing dump1090, you can see nearby aircraft information like the flight number, altitude, lat/lon, and speed.  Here’s what I saw one afternoon near Memphis, TN:

./dump1090 --net --interactive

dump1090 command line mode
dump1090 command line mode

After just a few seconds on starting dump1090, planes start to appear.  To view this information on a map, launch a browser and go to localhost port 8080.


localhost:8080

dump1090 web interactive
dump1090 web interactive
dump1090 flight information
dump1090 flight information

It even provides links to FlightAware, so you can see even more information about a particular flight.

Flight Aware
Flight Aware
Flight Aware website
Flight Aware website

kjvbible.tk: perl + CGI

KJV Bible
KJV Bible

I have been a Christian since I was 12.  I began reading the Bible for myself at 13.  I became more serious in my study at 20, and have been diligently studying ever since.  I enjoy it tremendously.  I really try to meditate on what I am studying; try to imagine what it must have been like for the people involved;  try to understand why a certain passage is in the Bible and it’s true meaning; is there something in between the lines I can deduct?   Along those lines, I like to hear what other people think about it.  Those with whose theology I agree with, and those I do not.  Those who reject it all together, and why they think that way.

I also read several Bible commentaries as I study.  There are so many of them out there.  Most of which, I have no interest in.  There is also so much software and Bible study websites out there that it can be bewildering.  I decided that I wanted to make my own Bible study website that suits me, and only contains the resources that I am interested in.

When I decided undertake this project several years ago, I had a successful free-lance website business called Nerd for Hire.  I was building and hosting custom designed PHP web applications, primarily serving real estate industry and used car lots in the greater Memphis, TN area.  I was  focused on PHP/MySQL, the then new jQuery, AJAX, CSS, etc., and hosting it all on a reseller account I had with Host Gator.  It was a nice side gig until Craigslist started charging $5 for dealers to post cars on their site.  Craigslist was essential for directing traffic to the dealer’s website where the whole inventory could be advertised.  I briefly moved over to backpage.com, but it just wasn’t the same.  Increasingly, my customers wanted incredible, custom-made web applications (my specialty), but didn’t want to pay much for them.  It became to much effort for too little financial reward, and I ended up folding.

 

This was around 2010.  Perl was unfashionable at this time, and perl/CGI was certainly not the tool of choice for web applications anymore as fast as PHP had gotten.  Never one to go along with fads,  I had been reading an entry-level perl book that was 8 years old at the time (got it for $0.01 + $3.99 shipping on Amazon),  and I was VERY interested in learning perl because it seemed like it could do everything: text processing, databases, windows applications, server side scripting,  etc.

perl books

I figure the best way to learn a new language is to do a big project in it.  I proceeded to write a CGI application in perl to read the King James Version Bible.  Am I KJV only? No.  Is it my favorite? Pretty much.  I forget where I found a SQL file of the KJV bible, but I did, and imported it into my home LAMP server via phpmyadmin.  I then wrote an object oriented CGI application to read the Bible on my home network.   I purposefully ignored any css styling, and just wanted a simple, stripped down design.  I began using it daily during my study, being really pleased with myself for having got that far.

I was using Power Bible CD at the time, and had really taken a liking to the Adam Clarke Bible Commentary.  I wanted to add it to my little project so I didn’t have to go between applications during my study.  I created a database schema and manually copied and pasted every single chapter of the Adam Clarke Commentary from studylight.org.  It was tedious, and painful, but it worked.  Once I had it in database form,  I added scripting so that the commentary was displayed side by side with the chapter in the Bible I was reading.  Soon after, I added the Joseph Benson Commentary in the same inefficient fashion.

After some time, I discovered the Internet Sacred Text Archive, www.sacred-texts.com, which contained numerous Bible commentaries and other interesting resources.  I got a little more sophisticated, and wrote scripts (wget + perl) to automatically download the commentaries chapter by chapter and save them as text files on my computer.  I then wrote scripts that  merged them all together into a csv file, and imported them into a MySQL database.  I did the same with a few Bible dictionaries, encyclopedias, etc. from the Internet Archive.  I was getting pretty good with perl’s regular expressions and amazed at how easy it was to do really powerful things in perl with such little effort.

Sacred-Texts.com
Sacred-Texts.com

So, I got my CGI application together the way I wanted it, and was still just using it on my internal LAMP server.  I had recently started renting a VPS from digitalocean.com for a for-sale-by-owner real estate project.  I decided to put my humble project on the internet, since I already had the hosting resources.  I decided to go with a free domain: www.kjvbible.tk.  I am still hosing it on a VPS from digitalocean.  Other sites I am hosting there are using PHP 7.  PHP is smoking fast, and comes with OPcache standard.  On the other hand, perl CGI is an anachronism, SUPER DUPER slow, and taxing on the CPU.  I really don’t care though.  It’s out there for the world to see.  Ad-free and just a simple, easy-to-use place to study the Bible.

Hebrew New Testament
Hebrew New Testament at www.kjvbible.tk