Eric J Ma's Website

3D Printed WiFi Access QR Codes: Part 1

written by Eric J. Ma on 2018-09-01 | tags: python qr codes wifi 3d printing security coding technology diy networking home project guest network pyqrcode pypng solidpython numpy click 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 installed in your environment:

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

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

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

Finally, if you'd like to work with command line interfaces and Flask, you'll need:

  1. click [pip/conda]
  2. Flask [pip/conda]

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:

  • SSID (a.k.a. Network Name): Family Guest Network
  • Password: vn8h2sncu093y3nd!
  • Security Type (one of WPA or WEP): WPA

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.webp('home_guest_wifi.webp')

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 URL 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!


Cite this blog post:
@article{
    ericmjl-2018-3d-1,
    author = {Eric J. Ma},
    title = {3D Printed WiFi Access QR Codes: Part 1},
    year = {2018},
    month = {09},
    day = {01},
    howpublished = {\url{https://ericmjl.github.io}},
    journal = {Eric J. Ma's Blog},
    url = {https://ericmjl.github.io/blog/2018/9/1/3d-printed-wifi-access-qr-codes-part-1},
}
  

I send out a newsletter with tips and tools for data scientists. Come check it out at Substack.

If you would like to sponsor the coffee that goes into making my posts, please consider GitHub Sponsors!

Finally, I do free 30-minute GenAI strategy calls for teams that are looking to leverage GenAI for maximum impact. Consider booking a call on Calendly if you're interested!