3D Printed WiFi Access QR Codes: Part 1

written by Eric J. Ma on 2018-08-20

3d printing qr codes python

Summary

In this blog post, I'll detail how I created a 3D printed QR code that can be used to help guests get on our home guest network in geek style. This part will detail the creation of a QR code with Python. The next part will detail how I created a program to generate 3D printable blocks. The final part will detail how I created a hybrid command line app and Flask app from the same code base, using click and Flask.

The Project

Over the weekend, I embarked on a project to create a 3D printed QR code that guests at our house could scan to gain access to our guest wireless network.

Why I decided to do this

From the standpoint of practicality, sure, it's trivial to open up phone settings, find the WiFi network name, and give them the password, but... this has the coolness factor associated with it! Imagine scanning a 3D-printed QR code! Until this becomes commonplace, it's a cool thing to be able to do.

Anyways, there's a ton of QR code generators out there on the web, and there's more than a handful of WiFi QR code generators out there - so why did I embark on this project?

Partly it's borne out of security reasons - I am not giving my WiFi password up to some random website. Who knows whether they're actually storing the passwords?

Another part of this is borne out of me wanting to scratch my itch surrounding QR codes. The last time I went to China (Xi'an and Shanghai, specifically), I saw QR codes everywhere. There surely had to be something good we could use this for at home that didn't involve just packing and storage.

Getting Setup

Ok, let's get started! To create QR codes, all you need are the following packages:

  1. pyqrcode [pip]
  2. pypng [pip]

If you want to do the 3D printing part, you'll need another set of packages:

  1. SolidPython [pip]
  2. numpy [conda/pip]

Encoding WiFi credentials in a QR code

Let's start by creating a QR code for our WiFi guest network.

Let's say that these are the security credentials for the network:

Because QR codes are merely two-dimensional barcodes that encode a string that can be parsed by another program, in order to create a QR-code that is readable for accessing WiFi, we need a string that can be parsed. This string is structured as follows:

WIFI:S:<SSID>;T:<WPA|WEP|>;P:<password>;;

So in our case, we would want a string that looks like:

WIFI:S:Family Guest Network;T:WPA;P:vn8h2sncu093y3nd!;;

Now, we can code up our Python program do encode the QR code for us. I'll assume you're running Python 3.6 or later.

import pyqrcode as pq
ssid = "Family Guest Network"
security = "WPA"
password = "vn8h2sncu093y3nd!"

qr = pq.create(f'WIFI:S:{ssid};T:{security};P:{password};;')
print(qr.terminal())

With that block of code, you should get a QR code printed to your terminal, just like that!

Let's say you wanted to do the simple thing, and just have a regular laser/inkjet printer make a printout of the QR code. To do so, you can save the QR code to disk as a PNG file:

qr.png('home_guest_wifi.png')

Conclusions

And just like that, you've used Python to create a WiFi QR code! How easy was that?

Along the way, I also used Kite in the Atom text editor while embarking on this project - this allowed me to view documentation and common usage patterns for the packages I imported.

Now, if you remember that QR codes are just "ASCII strings encoded in a 2D barcode", then you'll know that you can pass any arbitrary string into the pyqrcode.create() function. That means you can come up with any creative use of a short string that needs to be scanned to be useful! For example, you can create business cards with your LinkedIn profile embedded in the QR code, or use it to encode a serial number information on your possessions, or more!

Stay tuned for the coming blog posts!

Did you enjoy this blog post? Let's discuss more!


Joint, conditional, and marginal probability distributions

written by Eric J. Ma on 2018-08-07

statistics probability bayesian data science

Joint probability, conditional probability, and marginal probability... These are three central terms when learning about probability, and they show up in Bayesian statistics as well. However... I never really could remember what they were, especially since we were usually taught them using formulas, rather than pictures.

Well, for those who learn a bit better using pictures... if you know what a probability distribution is, then hopefully these help with remembering what these terms mean. (Clicking on the image will bring you to the original, hosted on GitHub.)

Did you enjoy this blog post? Let's discuss more!


d-separation in causal inference

written by Eric J. Ma on 2018-08-06

causal inference bayesian data science

Yesterday evening, I had an empty block of time during which I finally did a worked example of finding whether two nodes are "d-separated" in a causal graph. It was pretty instructive to implement the algorithm. It also reminded me yet again: there's this weird thing about me where I need programming to learn math!

Anyways, if you're interested in seeing the implementation, it's available at GitHub.

Did you enjoy this blog post? Let's discuss more!


nxviz 0.5 released!

written by Eric J. Ma on 2018-08-01

nxviz visualization data science software open source

A new version of nxviz is released!

In this update, I have added a declarative interface for visualizing geographically-constrained graphs. Here, nodes in a graph have their placement constrained by longitude and latitude.

An example of how to use it is below:

nxviz geoplots

In the GeoPlot constructor API, the keyword arguments node_lat and node_lon specify which node metadata are to be used to place nodes on the x- and y- axes.

By no means do I intend for GeoPlot to replace more sophisticated analysis methods; like seaborn, the interface is declarative; for me, the intent is to provide a very quick-and-dirty way for an end user to visualize graphs with spatially constrained nodes.

Please enjoy!

Did you enjoy this blog post? Let's discuss more!


pyjanitor 0.3 released!

written by Eric J. Ma on 2018-07-27

open source pyjanitor data science

A new release of pyjanitor is out!

Two new features that I have added in include:

  1. Concatenating column names into a single column, such that each item is separated by a delimiter.
  2. Deconcatenating a column into multiple columns, separating on the basis of a delimiter.

Both of these tasks come up frequently in data preparation.

For example, concatenating a few columns together oftentimes lets us create an unique index based sample properties.

On the other hand, deconcatenating columns into multiple columns can be useful when our index is used to store metadata. (This really shouldn't be happening, but... sometimes that's just how the world works right now...)

Here's an example of how it works:

To install pyjanitor, grab it from PyPI:

$ pip install pyjanitor

The conda-forge build will be coming soon!

Did you enjoy this blog post? Let's discuss more!