{"id":73,"date":"2023-05-31T12:46:57","date_gmt":"2023-05-31T11:46:57","guid":{"rendered":"https:\/\/calero-tech.net\/?p=73"},"modified":"2023-05-31T14:36:23","modified_gmt":"2023-05-31T13:36:23","slug":"wi-fi-qr-code","status":"publish","type":"post","link":"https:\/\/calero-tech.net\/?p=73","title":{"rendered":"Wi-Fi QR Code"},"content":{"rendered":"\n<p>Hey everyone, Mike here! Have you ever found yourself in a situation where you have friends over and they ask for your Wi-Fi password? You stumble over to your ISP-provided modem, trying to read off a complex password like &#8220;Hot-67-surfertrees- &#8230; No, wait, surfer&#8230; After 67. Yes, no&#8230;&#8221; Or perhaps you have your own wireless router, but still, communicating the password becomes a hassle with visitors not hearing you correctly or knowing when to replace letters with numbers.<\/p>\n\n\n\n<p>Fear not! Today, we&#8217;re going to leave these first-world problems behind and learn how to create a QR code using Python. This QR code can be scanned by your visitors using their device&#8217;s camera. But before we begin, make sure you:<\/p>\n\n\n\n<p>A. Understand how to use Python.                                                                                       B. Have Python installed and set up on your computer.<\/p>\n\n\n\n<p>Let&#8217;s get started! Open your favorite IDE and create a new file. Feel free to name it whatever you like. For this example, I&#8217;ll be calling the file &#8220;ezQR.py.&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"719\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1024x719.png\" alt=\"\" class=\"wp-image-74\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1024x719.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-300x211.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-768x539.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image.png 1424w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>First, we need to import a module called &#8220;pyqrcode.&#8221; This module is a QR code generator that automates most of the building process. With just a few lines of code, you&#8217;ll be done. Type the following line to import the module:                      &#8220;import pyqrcode&#8221;. <\/p>\n\n\n\n<p>If &#8220;pyqrcode&#8221; fails to import, you can try installing it by running the following command:<\/p>\n\n\n\n<ul>\n<li>On macOS: pip install pyqrcode<\/li>\n\n\n\n<li>On Windows: python3 -m pip install pyqrcode<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"794\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1-1024x794.png\" alt=\"\" class=\"wp-image-75\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1-1024x794.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1-300x233.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1-768x595.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-1.png 1282w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next, we&#8217;ll create a few variables that we&#8217;ll be using later in our code. Let&#8217;s create them in this order:<\/p>\n\n\n\n<p>&#8220;Wifi_Name = &#8216;Enter the SSID of your wireless network'&#8221;                                &#8220;Wifi_Protocol = &#8216;Enter your encryption protocol'&#8221;                                      &#8220;Wifi_Password = &#8216;Enter your wireless network password'&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"794\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-4-1024x794.png\" alt=\"\" class=\"wp-image-78\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-4-1024x794.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-4-300x233.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-4-768x595.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-4.png 1282w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now, let&#8217;s create the variable to generate the actual QR code. In your IDE, enter the following line: &#8220;QRCode = pyqrcode.create(F&#8217;WIFI:S:{Wifi_Name};T:{Wifi_Protocol};P:{Wifi_Password}::&#8217;)&#8221;.<\/p>\n\n\n\n<p>The &#8220;QRCode&#8221; variable is the Python variable we&#8217;re creating that utilizes the &#8220;pyqrcode&#8221; module. This module allows us to call the variables we created earlier.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"794\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-3-1024x794.png\" alt=\"\" class=\"wp-image-77\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-3-1024x794.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-3-300x233.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-3-768x595.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-3.png 1282w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Great! Now let&#8217;s move on to saving the QR code. For this next part, let&#8217;s import the &#8220;pypng&#8221; module by typing &#8220;import png&#8221;. If the import fails, you can try installing the module by running the following command:<\/p>\n\n\n\n<ul>\n<li>On macOS: pip install pypng<\/li>\n\n\n\n<li>On Windows: python3 -m pip install pypng<\/li>\n<\/ul>\n\n\n\n<p>After importing &#8220;pypng,&#8221; let&#8217;s also import &#8220;sys&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"372\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-5-1024x372.png\" alt=\"\" class=\"wp-image-79\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-5-1024x372.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-5-300x109.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-5-768x279.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-5-1536x559.png 1536w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-5.png 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s close this out by creating the output file, scaling the size of the PNG, and printing the output to let us know where the QR code is saved.<\/p>\n\n\n\n<p>First, we&#8217;ll create the variable that stores the location and name of the file. Enter the following line: output_file = \u2018\/the\/path\/you\/want\/this\/saved\/to\/file_name.png\u2019<\/p>\n\n\n\n<p>Next, let&#8217;s specify how large we want to scale the QR code by using the QRCode.png() function. Add the following line: QRCode.png(Output_file, scale=8)<\/p>\n\n\n\n<p>Finally, let&#8217;s print out the location by adding: print(\u201cQR code saved as\u201d, output_file)<\/p>\n\n\n\n<p>At this point, your code should look like this &#8211;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"564\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-6-1024x564.png\" alt=\"\" class=\"wp-image-80\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-6-1024x564.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-6-300x165.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-6-768x423.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-6-1536x846.png 1536w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-6.png 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If your code looks like the above then hit run and let&#8217;s get our QR code!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"559\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-7-1024x559.png\" alt=\"\" class=\"wp-image-81\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-7-1024x559.png 1024w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-7-300x164.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-7-768x419.png 768w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-7-1536x838.png 1536w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-7.png 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"424\" height=\"424\" src=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-2.png\" alt=\"\" class=\"wp-image-76\" srcset=\"https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-2.png 424w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-2-300x300.png 300w, https:\/\/calero-tech.net\/wp-content\/uploads\/2023\/05\/image-2-150x150.png 150w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/figure>\n\n\n\n<p>I hope you had a great time creating your own QR code with me! It&#8217;s always exciting to create cool new things. Until next time, take care and have fun exploring the world of Python!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey everyone, Mike here! Have you ever found yourself in a situation where you have friends over and they ask for your Wi-Fi password? You stumble over to your ISP-provided modem, trying to read off a complex password like &#8220;Hot-67-surfertrees- &#8230; No, wait, surfer&#8230; After 67. Yes, no&#8230;&#8221; Or perhaps you have your own wireless router, but still, communicating the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[15,14],"tags":[11,12,13],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/calero-tech.net\/index.php?rest_route=\/wp\/v2\/posts\/73"}],"collection":[{"href":"https:\/\/calero-tech.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/calero-tech.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/calero-tech.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/calero-tech.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=73"}],"version-history":[{"count":2,"href":"https:\/\/calero-tech.net\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/calero-tech.net\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions\/152"}],"wp:attachment":[{"href":"https:\/\/calero-tech.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/calero-tech.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/calero-tech.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}