Installing OctoPi-TFT using the OctoPi Image

This tutorial uses vi to edit files this can be replaced with nano or some other text editor.

Parts

Step 1: Connect the PiTFT to the Pi

You can connect the PiTFT before you start any of the other steps.

Step 2: Install and Configure OctoPrint

Follow the instructions form the OctoPrint website https://octoprint.org/download/

Step 3: Install Raspbian Desktop

sudo /home/pi/scripts/install-desktop

sudo reboot

Step 4: Install Dependencies

sudo apt-get install xinit
sudo apt-get install x11-xserver-utils
sudo apt-get install xserver-xorg-input-evdev

Step 5: Move 40-libinput.conf

sudo mv /usr/share/X11/xorg.conf.d/40-libinput.conf ~/

Step 6: Install PiTFT Drivers

Use the Easy Install method that Adafruit supplies

We’ve created a custom kernel package based of off Notro’s awesome framebuffer work, so you can install it over your existing Raspbian (or derivative) images in just a few commands. Our tutorial shows you how to install the software, as well as calibrate the touchscreen, display images such as from your PiCam and more!

Adafruit
cd ~
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
chmod +x adafruit-pitft.sh
sudo ./adafruit-pitft.sh
  • For the 3.5″ PiTFT select #4
  • If you want the HDMI port on top like I do select #3
  • Would you like the console to appear on the PiTFT display? No
  • Would you like the HDMI display to mirror to the PiTFT display? Yes

Step 7: Uninstall Lightdm window manager

sudo dpkg -r --force-depends lightdm

Step 8: Install OctoPi-TFT

cd ~
wget https://github.com/darksid3r/OctoPrint-TFT/releases/download/1.1/octoprint-tft_stretch_1.1.git91fa718-1_armhf.deb
sudo dpkg -i octoprint-tft_stretch_1.1.git91fa718-1_armhf.deb

Step 9: Edit OctoPi-TFT Configuration File

Edit you configuration file.

sudo vi /etc/octoprint-tft-environment

This is what mine looks like. You will need to change the OCTOPRINT_APIKEY to match yours. It can be found on the settings page in OctoPrint. I also removed the comments from here so it is easier to read.


OCTOPRINT_CONFIG_FILE=

OCTOPRINT_HOST=http://127.0.0.1:5000

OCTOPRINT_APIKEY=YOUR_APIKEY_GOES_HERE

OCTOPRINT_TFT_STYLE_PATH=/opt/octoprint-tft/styles/default/

OCTOPRINT_TFT_RESOLUTION=480x320

Step 10: Reboot & Test

sudo reboot

Step 11: Check /boot/config.txt

You can disregard this step if everything is working as expected. My display resolution wasn’t correct so I had to change the last line of the /boot/config.txt file from hdmi_cvt=720 480 60 1 0 0 0 to hdmi_cvt=480 320 60 1 0 0 0.

sudo vi /boot/config.txt
sudo reboot

Resources

I used these resources to put together this tutorial.

Custom 3 Button CircuitPython Keyboard

Introduction

I have been doing audio editing for side project at work. These are long form audio recordings of an hour or more. I am using Adobe Audition to do my editing. After doing several of these, I noticed that I use two main functions frequently.

  1. ‘Silence’
  2. ‘Ripple Cut’ -> ‘ Time Selection in All Tracks’

The ripple cut function either used a significant number of mouse clicks or keyboard shortcuts that required both hands. There are probably a few different potential solutions to this problem. I could have changed the keyboard shortcuts to something else, but I wanted this to be easy to use and I wanted to be able to use it on any computer.

I recently completed a project using that used the PyPortal to send keyboard commands to my computer to open applications. Also, I had purchased an Adafruit Trinket M0 recently and wanted to build a project with it, so I decided to build a mini keyboard that only had a few buttons.

Parts

Schematics

Code

I modified the the Trinket IO Demo code. I removed some stuff that I didn’t need and had to make sure that holding down a key was treated the exact same as a single key press.

Results

The first button is used for play/pause, the second button is used to do the ripple cut and the third button is used to do the silencing. This tool has made it so much easier to edit audio content.

Update – 18 Apirl 201

If you liked this, check out this much more detailed project by Glen Akins (@bikerglen)

Ender 3 – 3D Printer & OctoPrint

Background

I recently purchased a Creality Ender 3 3D printer. I bought this for several reasons:

  1. It is very affordable at $229 on Amazon.
  2. It had a lot of good reviews
  3. Is the Most Popular 3D Printer of Spring 2019
  4. There are lots of upgrades/mods for this printer
    1. 35 Must-Have Creality Ender 3 (Pro) Upgrades & Mods in 2019.

OctoPrint

My interest was peaked when I saw the Raspberry Pi upgrade option under the possible upgrades/mods you could do to the Ender 3.

Let’s face it, we can’t be around to supervise our 3D printer 100 percent of the time. That’s why OctoPrint has become the standard for makers who want to monitor and control their 3D printer remotely. To run this terrific web interface, you need to purchase a Raspberry Pi board.


OctoPrint will allow you to control and observe your Creality Ender 3 from within a web browser. It’s 100 percent open source, which has led to a plethora of unique plugins created by the vast community. On the browser, you can watch prints through an embedded webcam feed, control print temperatures, obtain feedback on current print status, and even start and pause your printer no matter where you are.

35 Must-Have Creality Ender 3 (Pro) Upgrades & Mods in 2019.

I had an extra Raspberry Pi laying around and decided to give it a shot. The software that runs on the Pi is called OctoPrint. Installation and configuration is very straight forward and there are lots of help documents and tutorial videos. I am not going to get into any of the setup in this post, but below is the video that I found most helpful.

How to Install Octoprint on a Creality Ender 3

First Print with OctoPrint

I am currently using a simple USB webcam for the OctoPi. I want to upgrade it to use a mounted Raspberry Pi camera so that it follows the printer head. The video below is a time lapse that was captured using OctoPrint of the mount and case for the Pi camera being 3D printed.

Video 3D print of camera holder for Pi Camera and ender

PyPortal App Launcher

Introduction

PyPortal is a microcontroller that can be programmed using CircuitPython. It has a touchscreen and can be used as a emulate a keyboard and mouse. For this project, we will create a touchscreen with icons that will allow us to launch applications when pressed.

  1. Design: discussions how the touchscreen image and layout are created.
  2. Shortcuts: Create Keyboard Shortcuts to Launch Applications in macOS ( Windows)
  3. Code: CircuitPython code to be added to you PyPortal

The code and design files can be found on Github.

Design

The PyPortal initializes rendering a background image that is .BMP (bitmap image). So I created a template background image that I could insert icons into using Adobe Illustrator. Using this file, I copied and pasted my icons on to the location I wanted and then deleted the while squares underneath.

Icon template file. 3 rows of 4 icons 50×50 pixels. – button-template-12.ai

In order to detect button presses we need to know the boundaries for each icon. The image below shows the pixel length to each border.

Annotated background icon image.

Columns are organized from left to right, from A to D. Rows are organized from top to bottom, from 1 to 3. Please see the below table.

ABCD
1A1B1C1D1
2A2B2C2D2
3A3B3C3D3

We need to know this information in order to determine if an icon is pressed. A touch event returns an (x,y) point with (0,0) being the top left corner. All icons in column B can only be pressed if the x of the touch event is between 97.5 and 147.5. Likewise, all icons in row 1 can only be pressed if the y of the touch event is between 100 and 150. Therefore, if the touch event returns (100,130), then the icon located at B2 has been pressed.

Shortcuts

The easiest way to launch applications using CircuitPython is by sending keyboard commands to your computer. In order to accomplish this on a macOS we need to create these keyboard shortcuts. This is fairly trivial on windows.

  1. Launch Automator on your mac
  2. Create a new “Quick Action”
    1. File -> New -> “Quick Action” -> Choose
  3. Under actions search for “Launch Application”
  4. Drag “Launch Application” into the window
  5. From the drop down list select the application that you want to open
  6. Switch the “Workflow Receives” drop down to “no input”
  7. Save your quick action
    1. Either CONTROL+S or File -> Save
  8. Close Automator
  9. Create the keyboard shortcut to activate the “Quick Action” you created
    1. Go to Settings -> Keyboard
    2. Click on the Shortcuts tab
    3. Select Services
    4. Scroll to the General section near the bottom.
    5. Highlight the “Quick Action” you created and click the Add Shortcut button.
    6. Press the keyboard keys that you want to set the shortcut to.
    7. I used “ALT+CONTROL+SHIFT+COMMAND+[FIRST LETTER OF APP]” for each of my shortcuts. I did this because I knew there would be no other shortcuts using this combination.

Code

The code has comments throughout and they should explain everything. If you have questions please feel free to email me or DM me on twitter. You will need to copy the below code as code.py in the root of your PyPortal as well as you BMP icon file. Please update the below code with your keyboard shortcuts and the name of your BMP icon file.

Cloudflare DNS Propagation Issues

Background

I have been doing website migrations and have been updating the DNS entries of these websites to point at the new server’s IP addresses. I have been getting major propagation delays on my personal devices when checking the sites I have migrated. It took me a little while to realize that this was most likely a Cloudflare DNS issue. When I switched my personal devices DNS servers to Google’s (8.8.8.8) and they worked.

Google DNS was used to circumvent Turkey blocking Twitter, ultimately leading Turkey to block Google DNS in 2014.

I use Cloudflare DNS on all of my personal devices. I mainly do this for privacy and security reasons. They also have simple instructions to set it up on numerous devices.

  • iPhone
  • Android
  • MacOS
  • Windows
  • Linux
  • Router

Solution

After doing some googling, I stumbled across 1.1.1.1 Purge Cache. Everything worked as soon as I used this tool. It took me a while to find this tool as most of the results relate to propagation delays related to using CDN tool that Cloudflare provides.

Using Let’s Encrypt to Secure WordPress on AWS Lightsail

This tutorial is a slightly modified version of the tutorial on Bitnami’s documentation site This tutorial will show you how to:

  1. Install LEGO (Let’s Encrypt client written in GO)
  2. Generate TLS/SSL Certificate with Lego
  3. Configure Apache to use the TLS/SSL Certificate
  4. Configure Apache to only use HTTPS
  5. Update wp-config.php
  6. Automate Certificate Renewal

Prerequisites

  1. A running Bitnami instance on AWS Ligthsail.
  2. A registered domain name configured properly for your Bitnami instance.

Step 1 – Install a TLS/SSL Certificate with Let’s Encrypt

Let’s Encrypt certificates are fetched via client software running on your server. The Lego client simplifies the process of Let’s Encrypt certificate generate. To use it, follow these steps:

First, change directories to the tmp directory.

cd /tmp

I think the git repository for Lego has moved from https://github.com/xenof/lego to https://github.com/go-acme/lego.

Copy the latest version of the LEGO client from github:

sudo curl -s https://api.github.com/repos/xenolf/lego/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d '"' -f 4 | wget -i -
sudo curl -s https://api.github.com/repositories/37038121/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d '"' -f 4 | wget -i -

Unpack the source code:

sudo tar xf lego_vX.Y.Z_linux_amd64.tar.gz

Move the source code into /usr/local/bin

sudo mv lego /usr/local/bin/lego

Step 2 – Generate a TLS/SSL Certificate with Let’s Encrypt

First, turn off apache (or nginx). The Lego client needs port 80 available to complete the request.

sudo /opt/bitnami/ctlscript.sh stop apache

You can now run the Lego client to generate your certificate and key. Replace EMAIL-ADDRESS and DOMAIN with your email address that you want to receive expiration notifications and the domain of your site.

sudo lego --email="EMAIL-ADDRESS" --domains="DOMAIN" --path="/etc/lego" run
sudo lego --http --email="EMAIL-ADDRESS" --domains="DOMAIN" --path="/etc/lego" run

Agree to the terms of service.  A set of certificates will now be generated in the /etc/lego/certificates directory. This set includes the server certificate file DOMAIN.crt and the server certificate key file DOMAIN.key.

Step 3 – Configure Apache to use the TLS/SSL Certificate

This section differs from the bitnami tutorial. The bitnami tutorial has you replace the existing self-signed certificates.

Navigate to the bitnami configuration directory for apache.

cd /opt/bitnami/apache2/conf/bitnami

Open the bitnami.conf file for editing.

sudo vi bitnami.conf

Change the SSLCertificateFile and SSLCertificateKeyFile directives to point to your newly generated certificates.

SSLCertificateFile "/etc/lego/certificates/DOMAIN.crt"
SSLCertificateKeyFile "/etc/lego/certificates/DOMAIN.key"

Start apache.

sudo /opt/bitnami/ctlscript.sh start apache

Step 4 – Force HTTPS

Add the following to the top of the /opt/bitnami/apps/wordpress/conf/httpd-prefix.conf file:

sudo vi /opt/bitnami/apps/wordpress/conf/httpd-prefix.conf
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

Restart apache.

sudo /opt/bitnami/ctlscript.sh restart apache

Step 5 – Update wp-config.php

Make sure you update WP_SITEURL and WP_HOME in /opt/bitnami/apps/wordpress/htdocs/wp-config.php

define('WP_SITEURL', 'https://example.com/');
define('WP_HOME', 'https://example.com/');

Step 6 – Automate Certificate Renewal

To automatically renew your certificates before they expire, write a script to perform the tasks required to renew the certificate and schedule a cron job to run the script periodically.

First using your favorite editor, create a script renew-certificate.shin the /etc/lego directory.

sudo vi /etc/lego/renew-certificate.sh

Add the following lines to your file. Again, make sure to replace DOMAIN and EMAIL-ADDRESS.

#!/bin/bash

sudo /opt/bitnami/ctlscript.sh stop apache
sudo /usr/local/bin/lego --email="EMAIL-ADDRESS" --domains="DOMAIN" --path="/etc/lego" renew
sudo /opt/bitnami/ctlscript.sh start apache
#!/bin/bash

sudo /opt/bitnami/ctlscript.sh stop apache
sudo /usr/local/bin/lego --http --email="EMAIL-ADDRESS" --domains="DOMAIN" --path="/etc/lego" renew
sudo /opt/bitnami/ctlscript.sh start apache

This script will stop apache, run the Lego client with the renew command, and then start apache again.

Make the script executable

sudo chmod +x /etc/lego/renew-certificate.sh

Execute the following command to open the crontab editor.

sudo crontab -e

A cron job allows you to run a certain command a set time. Add the following lines to the crontab file and save it.

0 0 1 * * /etc/lego/renew-certificate.sh 2> /dev/null

This cron job will run on the first day of every month at midnight.

Issues Updating Drupal Core from 8.5.1 to 8.5.3

Introduction

Another highly critical security advisory has been issued for Drupal.

A remote code execution vulnerability exists within multiple subsystems of Drupal 7.x and 8.x. This potentially allows attackers to exploit multiple attack vectors on a Drupal site, which could result in the site being compromised. This vulnerability is related to Drupal core – Highly critical – Remote Code Execution – SA-CORE-2018-002. Both SA-CORE-2018-002 and this vulnerability are being exploited in the wild.

I ran into two different issues when updating from Drupal version 8.5.1 to 8.5.3 using composer on a Drupal instance.

Issue 1: Cannot Allocate Memory

composer update
...
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 30 updates, 0 removals
  - Updating guzzlehttp/guzzle (6.3.2 => 6.3.3): The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details
                                                    

  [ErrorException]                                   
  proc_open(): fork failed - Cannot allocate memory 

I was able to fix the issue by following the link in the error message: https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors. Increasing the swap space fixed this issue.

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

Issue 2: Nothing to install or update

composer update
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update

This was another trivial issue. The composer.json file was restricted the update from updating past version 8.5.1

composer prohibits drupal/core:8.5.3
drupal-composer/drupal-project - requires drupal/core (8.5.1)

Changing the require section in the composer.json from:

“require”:{
	

	"drupal/core": "8.5.1",

}

To

“require”:{


	"drupal/core": "~8.5",


}

This tells composer that it can update to the latest version of the Drupal core in 8.5.x.

composer update
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating drupal/core (8.5.1 => 8.5.3):  Checking out b012f0ae51
Writing lock file
Generating autoload files
Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)Downloading (100%)> DrupalProject\composer\ScriptHandler::createRequiredFiles

Success!

Mount SFTP over SOCKS Proxy in OSX with Cyberduck

I can only access certain servers at work over SSH if I am using a machine with a certain static IP address. I wanted to be able to mount the servers file space using SFTP on a Macbook Air when I am either at home or at  a remote location. I investigated a lot of different ways to accomplish this with little success. After a lot of trial and error I was able to create a Socks proxy to my work machine using ssh and then mount the server file systems by using Cyberduck and enabling the use of the socks proxy.

Network Diagram
Network Diagram

First, I needed to create the socks proxy. In order to do this I had to SSH into my work machine and dynamical forward a port 8080. You may forward any port that is not being used greater than 1024. This will send any traffic on that port through the tunnel and out of the machine that you are connected to.

ssh [email protected] -D8080

After I have created the SSH connection with the dynamic port forwarding, I enabled the socks proxy in OSX Network Preferences -> Advanced -> Proxies. Check the “SOCKS Proxy” box. Then, set the “SOCKS Proxy Server” to 127.0.0.1:8080. Finally, add the IP or Domain of the machine that has the SSH connection to the “Bypass proxy settings for these Hosts & Domains” box.

OSX Socks proxy settings
OSX SOCKS Proxy Settings

Now enable the proxy in Cyberduck. Go to “Cyberduck” -> “System Preferences” -> “Connection” and check the box that says “Use system proxy settings”.

Cyberduck system preferences for proxies
Cyberduck system preferences for proxies

Now every connection in Cyberduck will flow through your SOCKS proxy that you set up so you can mount the remote server file system over SFTP.

Using Twitter API with a Proxy in WordPress

1280px-Reverse_proxy_h2g2bob.svg

I was launching a new WordPress website at work that was developed by an outside agency. This site was using twitteroauth built into the theme to access the twitter API. Where I work all the web servers are behind a firewall with a strict whitelist for all incoming and outgoing connections besides the incoming HTTP and HTTPS requests. This makes it difficult to access the twitter API because it could be a different IP address every time. To solve this issues my work provides a proxy server to make requests out to. So my research began.

WordPress began to provide configuration settings in the wp-config.php file for them (http://wpengineer.com/1227/wordpress-proxysupport/):

define('WP_PROXY_HOST', '192.168.84.101');
define('WP_PROXY_PORT', '8080');
define('WP_PROXY_USERNAME', 'my_user_name');
define('WP_PROXY_PASSWORD', 'my_password');
define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');

Unfortunately, the developers built the twitter api into their theme so I had to manually track down the API calls to modify them to use the WordPress configuration settings. In the twitteroauth.php file in the themes folder I was able to add three lines to the
curl_setopt parameters to function http (http://php.net/manual/en/function.curl-setopt.php):

curl_setopt($ci, CURLOPT_PROXY, '192.168.84.101');
curl_setopt($ci, CURLOPT_PROXYPORT, 8080);
curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1);

Everything worked once I added those three lines.