Setup OctoPi (US Edition) – OctoPrint on a Raspberry Pi

Saturday, December 27, 2014 13:56 by Mario Lurig

OctoPrint-GCode-ViewerFirst and foremost, OctoPi is a fantastic pre-built image for a Raspberry Pi (Model A, B, or B+) that is designed to connect to your 3d printer and provide a web interface to interacting with your printer, all using the simple and powerful OctoPrint software. In my case, I’m connecting it to my Printrbot Simple Metal.

OctoPrint is incredibly powerful: you can connect a Raspberry Pi camera, print out a camera mount to attach it to your bed and actually watch your printer through the OctoPrint webpage (or record video, if that’s your thing). You could even do it in complete darkness (with IR LEDs). I have my printer in the same room, but it’s good to dream.

Getting Started

OctoPi requires at least a 4GB SD card (microSD for Raspberry Pi B+). You download the image file and write it to your SD card. You can now do your first boot of the Raspberry Pi (keyboard required during this phase, but it can be input-less once done).

The best getting started guide is a video by Thomas Sanladerer (embedded below). I’ve queued the video up to the first-boot section where he explains expanding to fill your full SD card and network configuration options.

The thing about OctoPi is it is maintained by a gentleman in the UK, and when using a mini keyboard for the US, typing certain characters can be… frustrating or impossible. So, there are two additional adjustments I recommend once you’ve booted up your new OctoPi. Reminder: Default login is username pi and password raspberry.

Change the Keyboard to US Standard

From the command line, run:
sudo dpkg-reconfigure locales
You want to use the menus to adjust the locale to en_US.UTF-8.

Then run:
sudo dpkg-reconfigure keyboard-configuration
This is a huge list, but find the Generic 101-key PC and select it.

Setup Auto-Login

Once those are changed it’s time to auto-login your Raspberry Pi. The below instructions assume the default user ‘pi’. These instructions are from OpenTechGuides.
Type:
sudo nano /etc/inittab

Navigate to the following line in inittab
1:2345:respawn:/sbin/getty 115200 tty1

And add a # at the beginning of the line to comment it out
#1:2345:respawn:/sbin/getty 115200 tty1

Add the following line just below the line you just edited:
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Press Ctrl+X to exit nano editor, Y to save the file, and Enter to confirm the filename.

Wrapping Up

Congratulations, you’re all set to plug your 3d printer into your Raspberry Pi! Just plug it in, restart the Pi (sudo reboot), unplug your keyboard, and head over to your main computer.
Note: Before disconnecting the keyboard, you may want to check the IP address of your OctoPi. Use the command ifconfig to display it.

If you’re on Windows like I am, you need to install the Bonjour service if you want to use http://octopi.local as the address. If you don’t care, you can just go directly to the IP address of your OctoPi. One last note for PrintrBot Simple Metal folks: Make sure that when connecting, you use the serial port labeled /dev/ttyACM0, otherwise it will not fully connect.

That’s it! You can now not only use your printer remotely, but you can use SSH to connect to the Pi directly if you want to shut it down when it won’t be in use for a while.

jQuery Mobile Filterable Collapsible Listview with Smart Expansion

Wednesday, February 12, 2014 20:29 by Mario Lurig

Wow, that’s a mouthful. Basically, I wanted to make use of the data-filter option to search a listview, but instead of a listview, I wanted it to be a collection of collapsible elements. Do accomplish this I needed some custom CSS to make it look right. Here is the example code with the ID iamalist. The page’s content section ID is iama, which is used in the CSS.
Read the rest of this entry »

Using AutoHotKey and Ditto with PHP

Tuesday, January 28, 2014 13:29 by Mario Lurig

I’m a purist I suppose. I write PHP, Javascript, CSS, and HTML in Notepad++. I don’t use an IDE (such as NetBeans), but I do have some shortcuts to make things go faster for me. The first one, Ditto, is a clipboard program that remembers the last 10 things put into the clipboard. This means you don’t have to worry about losing that copy/paste because it was overwritten. It’s simple, open, and a no-brainer addition. For those on OSX, Jumpcut is a great option.

The second one is AutoHotKey, which is crazy powerful, but for this example, I’m using its simple text replacement features. For instance, when I type qwhi, it is replaced with this:

while ($row = mysqli_fetch_assoc($result)){
 
}mysqli_free_result($result);

You can imagine how handy this can be. Below are some of the shortcodes I use in my AutoHotKey file. Enjoy.
Read the rest of this entry »

Mysqli and BLOB binary database fields

Monday, January 27, 2014 13:51 by Mario Lurig

This post exists to save you hours of research on the web. The following things may be true about you:

  • You recently transitioned from mysql PHP functions to mysqli functions (staying current)
  • You prefer procedural PHP over object-oriented PHP (functions and arrays are cooler than classes)
  • You are storing some data in a MySQL BLOB, MEDIUMBLOB, or LONGBLOB field, which is Binary

Read the rest of this entry »

mysqli_result() function to match mysql_result()

Wednesday, January 8, 2014 13:22 by Mario Lurig

As of PHP 5.5, the MySQL functions are deprecated and will be removed by PHP6. The recommendation is to switch to MySQLi functions, which conveniently offer both a procedural (my preference) and object-oriented structure. Luckily, it’s a rather easy transition to MySQLi as functions names and functions are nearly identical (just change mysql_ to mysqli_). The only exception to this is the mysql_result() function, which has no analog.

Quick review: mysql_result() is used to write less code when your database query is returning only a single row (LIMIT 1) and/or a single column.

$output = mysql_result($result,0);

Pretty simple and straightforward. To replicate this in MySQLi, the following function can be used:

function mysqli_result($res,$row=0,$col=0){ 
    $numrows = mysqli_num_rows($res); 
    if ($numrows && $row <= ($numrows-1) && $row >=0){
        mysqli_data_seek($res,$row);
        $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
        if (isset($resrow[$col])){
            return $resrow[$col];
        }
    }
    return false;
}

It has one improvement over mysql_result(), which is you can choose to only include the resource and no row and/or column. It will just assume mysqli_result($resource,0,0).

EDITED Dec 19, 2014
Function updated to allow for the column to be referenced by field name as well as numerical offset.

Regular Expression Crossword – Fun Practice with RegEx

Saturday, February 16, 2013 21:26 by Mario Lurig

RegEx CrosswordAfter seeing the post on Slashdot about the Regular Expressions crossword, I was inspired. I also wanted a puzzle that was easier and more approachable for the beginners or intermittent RegEx users.

So, I found a great base puzzle generator (javascript) and after a few hours, some graph paper, and some tweaks to the code, I created a RegEx crossword puzzle for others to check out. If people enjoy it, let me know in the comments. I’m thinking of putting out a physical workbook of these for fun.

jQuery Mobile 1.3 Swipe to Reveal Panel with Demo

Friday, February 1, 2013 23:10 by Mario Lurig

I wanted to make use of the new jQuery Mobile 1.3.0-beta1 feature called Panels, allowing you to overlay, push, or reveal a hidden panel of content on the left or right of the main window. This is most commonly used to provide extra navigation options. In my case, I wanted to show static content that is hyper relevant, but without crowding up the main window.

However, the docs recommend and demonstrate how to use a hyperlink to activate the panel, which is great in a header, footer, or in a button, but it seemed more natural to allow the user to swipe the screen either left or right to show the panel. Thus, I need to add the following code to the bottom of the page:

<script type='text/javascript'>
$(document).on('pageinit',function(){
	$("#content").on("swiperight",function(){
		$("#leftpanel").panel( "open");
	});
	$("#content").on("swipeleft",function(){
		$("#rightpanel").panel( "open");
	});
});
</script>

Read the rest of this entry »