Cov txheej txheem:

Alexa Tshuab Luam Ntawv - Upcycled Receipt Printer: 7 Kauj Ruam (nrog Duab)
Alexa Tshuab Luam Ntawv - Upcycled Receipt Printer: 7 Kauj Ruam (nrog Duab)

Video: Alexa Tshuab Luam Ntawv - Upcycled Receipt Printer: 7 Kauj Ruam (nrog Duab)

Video: Alexa Tshuab Luam Ntawv - Upcycled Receipt Printer: 7 Kauj Ruam (nrog Duab)
Video: NPAU SUAV POM Sau Ntawv 2024, Kaum ib hlis
Anonim
Image
Image
Alexa Tshuab Luam Ntawv | Tau Txais Cov Tshuab Luam Ntawv Zoo Tshaj
Alexa Tshuab Luam Ntawv | Tau Txais Cov Tshuab Luam Ntawv Zoo Tshaj

Kuv yog tus kiv cua ntawm rov ua dua qub thev naus laus zis thiab ua rau nws muaj txiaj ntsig dua. Ib pliag dhau los, Kuv tau txais lub tshuab luam ntawv qub qub, pheej yig, thiab kuv xav tau txoj hauv kev zoo los rov ua lub hom phiaj nws. Tom qab ntawd, dhau hnub so, Kuv tau txais khoom plig Amazon Echo Dot, thiab ib qho ntawm cov yam ntxwv kuv siv feem ntau yog ntxiv cov khoom noj khoom haus rau kuv cov npe khoom. Yog li kuv xav tias nws yuav txias los ua ke ob qho thiab siv lub tshuab txais nyiaj raws li lub tshuab luam ntawv IOT rau Alexa (lossis Google Tsev, lossis Siri, thiab lwm yam). Cia saib seb nws yuav siv dab tsi los ua kom lub tswv yim no muaj tiag.

Khoom siv

Nov yog cov ntu kuv siv rau txoj haujlwm no:

  1. Cov tshuab luam ntawv txais nyiaj thermal pheej yig (xav tau kev txhawb nqa ESC-POS)
  2. Amazon Alexa Device (lwm yam "pab hauv tsev" cov cuab yeej yuav ua haujlwm ib yam nkaus)
  3. Raspberry Pi Zero Wireless
  4. 7805 5v Tswj
  5. 10μf Capacitor
  6. 1 μf Capacitor

Lwm yam uas kuv siv rau txoj haujlwm no yog:

  1. Yog Qhov No Yog Li No (IFTTT.com)
  2. Cov Khoom Siv Hluav Taws Xob

Kauj Ruam 1: Teeb Kho Raspberry Pi Zero W

Teeb tsa Raspberry Pi Zero W
Teeb tsa Raspberry Pi Zero W
Teeb tsa Raspberry Pi Zero W
Teeb tsa Raspberry Pi Zero W
Teeb tsa Raspberry Pi Zero W
Teeb tsa Raspberry Pi Zero W

Thawj kauj ruam yog kom tau txais daim ntawv txais nyiaj qub tshuab luam ntawv dua. Kuv xaiv siv Raspberry Pi Zero W ua tus tswj hwm vim nws pheej yig tus nqi thiab qhov loj me. Nws yog qhov me me txaus kom haum rau sab hauv daim ntawv txais nyiaj lub tshuab luam ntawv nws tus kheej, yog li tsis muaj kev sib txuas sab nraud! Pi Zero W kuj tseem tau tsim hauv Wifi yog li txhua yam tau pib ua ke rau hauv nws qhov me me.

Txhawm rau kom Pi nce thiab khiav, peb yuav tsum rub tawm Raspbian OS thiab hlawv nws mus rau daim npav microSD siv qhov program xws li Etcher. Ntxig nws mus rau hauv Pi nrog rau HDMI cable, keyboard, nas, thiab tom qab ntawd lub zog.

Thaum Pi khau looj plab hlaub thiab koj nyob ntawm lub desktop interface, koj tuaj yeem txuas rau koj lub wireless los ntawm nyem rau ntawm lub cim wireless nyob rau sab xis thiab xaiv lub npe ntawm koj qhov kev sib txuas wireless. Tom qab ntawd yog tias koj nyem rau ntawm lub cim wireless tib yam, koj tuaj yeem mus rau lub network teeb tsa thiab teeb tsa tus IP zoo li qub kom peb tuaj yeem txuas tau yooj yim rau nws hla lub network. Thaum kawg, koj xav nyem rau ntawm cov ntawv qhia zaub mov tseem ceeb thiab xaiv "Raspbian Configuration Editor" thiab hauv qab "Interfaces" tab, xyuas kom SSH tau qhib. Tom qab ntawv khaws nws thiab rov pib dua koj Pi.

Kauj Ruam 2: Luam Ntawv Los Ntawm Pi

Luam Ntawv Los Ntawm Pi
Luam Ntawv Los Ntawm Pi
Luam Ntawv Los Ntawm Pi
Luam Ntawv Los Ntawm Pi

Thaum Raspbery Pi tau rov pib dua, nws yuav tsum txuas nrog koj lub wireless network nrog tus IP zoo li qub thiab nrog SSH qhib. Yog li tam sim no peb yuav tsum tuaj yeem txuas nrog nws nyob deb ntawm lwm lub khoos phis tawj. Txhawm rau ua qhov ntawd, koj yuav xav tau tus neeg siv SSH. Rau Windows, tus neeg siv khoom zoo yog Putty. Koj tuaj yeem txuas rau nws siv Pi's IP chaw nyob zoo li peb tau teeb tsa ua ntej. Tom qab ntawd koj tuaj yeem nkag mus siv "pi" raws li lub npe siv thiab "raspberry" ua tus password.

Tom qab ua tiav kev nkag mus, tam sim no peb yuav tsum nyob ntawm Pi lub davhlau ya nyob twg interface. Ntawm no peb tuaj yeem ntaus cov lus txib uas yuav ua rau ntawm Raspberry Pi. Piv txwv li, ib qho ntawm thawj yam peb xav ua yog xyuas kom lub software ntawm Pi tau hloov kho tshiab. Yog li, hauv lub davhlau ya nyob twg peb tuaj yeem ntaus:

sudo apt-tau hloov tshiab

Cov lus txib no yuav hloov kho cov software khaws cia ntawm Pi. Tom ntej no, peb tuaj yeem nruab ESC-POS software software thiab xav tau cov tsev qiv ntawv.

sudo apt-tau nruab python3 python3-setuptools python3-pip libjpeg8-devsudo pip3 nruab-hloov kho pip sudo pip3 nruab sej-escpos

Nrog qhov ua tiav, tam sim no peb tuaj yeem txuas Lub Tshuab Luam Ntawv mus rau Pi's Micro-USB chaw nres nkoj (siv lub adapter) thiab qhib nws. Tom qab ntawd hauv peb lub davhlau ya nyob twg peb tuaj yeem tsim tsab ntawv me me nab

nano nyob zoo_world.py

Thiab hauv nws peb tuaj yeem ntxiv tus lej nab npawb no

#!/usr/bin/pythonfrom escpos.printer import Usb p = Usb (0x0416, 0x5011) p.text ("Mini IOT Printer / n") p.close ()

Tawm nws (CTRL-X), txuag nws (CTRL-Y) thiab khiav nws los ntsuas nws

python3 nyob zoo_world.py

Kauj Ruam 3: Txuas rau Is Taws Nem Ntawm Yam (Ntu 1)

Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)
Txuas mus rau Internet ntawm Yam (Ntu 1)

Dab tsi zoo yuav lub tshuab luam ntawv tsis muaj dab tsi los luam? Kuv xav kom muaj peev xwm ua haujlwm los luam tawm los ntawm cov kev pabcuam internet sib txawv, xws li Alexa. Yog li kuv tuaj yeem ua tiav qhov ntawd li cas? Ib qho kev xaiv yog xaiv cov kev pabcuam internet tshwj xeeb, taug qab lawv cov ntaub ntawv API thiab sau daim ntawv thov raws li lawv cov API. Tab sis kuv xaiv mus txoj kev tub nkeeg…

Muaj lub vev xaib zoo hu ua "Yog Yog Li No" uas ua rau muaj kev cuam tshuam rau cov kev pabcuam internet sib txawv (Alexa, Google Tsev, Gmail, Facebook, Instagram, Twitter, thiab lwm yam) raws li txheej txheej. Piv txwv li, "yog" Kuv tshaj tawm rau Facebook (qhov no), "Tom qab ntawd" xa email rau kuv (qhov ntawd).

Yog li rau thawj ib nrab ntawm qhov no, Kuv tau kos npe rau tus as khauj dawb, koj tuaj yeem pib tsim "applet" tshiab rau cov kev pabcuam sib txawv uas koj xav ua. Qhov "Qhov no" ib feem ntawm kuv daim ntawv thov yuav yog Alexa. Muaj ntau qhov Alexa ua rau xaiv los ntawm, tab sis kuv yuav xaiv qhov uas hais tias "Nug dab tsi ntawm koj daim ntawv yuav khoom". Thiab thaum kawg peb xav kom nws ua rau Python tsab ntawv ntawm Raspberry Pi, yog li rau ntu "Ntawd" ntawm tsab ntawv, peb xav xaiv Webhooks.

Hauv qhov Webhooks xaiv, peb tuaj yeem ntxiv qhov URL uas taw rau peb Pi, uas peb yuav rov qab los rau tom qab. Peb tuaj yeem tawm ntawm Txoj Kev Teb raws li "Tau", thiab rau cov ntsiab lus hom xaiv "Plain Text". Rau Lub Cev Lub Cev, nyem "Ntxiv Cov Khoom Siv" thiab xaiv "Cov npe tag nrho". Qhov no yuav xa tag nrho cov npe khoom lag luam raws li Tau Txais.

Kauj Ruam 4: Txuas rau Internet ntawm Yam (Ntu 2)

Txuas mus rau Internet ntawm Yam (Ntu 2)
Txuas mus rau Internet ntawm Yam (Ntu 2)
Txuas mus rau Internet ntawm Yam (Ntu 2)
Txuas mus rau Internet ntawm Yam (Ntu 2)

Cov kauj ruam dhau los saib xyuas ntu "Internet", yog li tam sim no cia ua haujlwm ntawm "yam" ib feem siv Raspberry Pi. Txhawm rau sib txuas lus nrog "Yog Yog Li No" Webhooks applet, peb yuav tsum teeb tsa lub web server ntawm Raspberry Pi. Muaj ntau txoj hauv kev sib txawv los teeb tsa lub web server, tab sis txiav txim siab thaum kawg kuv xav khiav Python tsab ntawv, Kuv txiav txim siab siv Python's Flask server.

Tus Pi muaj txhua lub tsev qiv ntawv Flask tau teeb tsa ua ntej, yog li txhua yam peb yuav tsum tau ua yog pib sau cov ntawv xeem:

nano flask_test.py

Thiab hauv nws, cia ntxiv qee qhov chaws uas ua rau lub vev xaib yooj yim.

#! flask/bin/nab hab sej #QHIA NTAWV QHOV ZOO TSHAJ PLAWS los ntawm cov raj ntshuam ntshuam, thov #CREATE A FLASK VARIABLE app = Flask (_ name_) #CREATE AN 'INDEX' PAGE @app.route ('/') def index (): rov qab 'Koj lub Flask server ua haujlwm!' #RUN PROGRAM yog _name_ == '_main_': app.run (debug = Tseeb, host = '0.0.0.0')

Tam sim no tsuas yog khaws qhov program thiab khiav nws siv cov lus txib no:

sudo python3 flask_test.py

Koj yuav pom los ntawm cov lus teb hais tias qhov chaw nres nkoj pib uas Flask khiav ntawm yog chaw nres nkoj 5000. Yog li hauv lub vev xaib, yog tias koj ntaus koj tus IP Chaw Nyob IP: 5000, koj yuav tsum pom cov ntawv "Koj lub Flask server ua haujlwm!"

Peb muaj peb qhov kev xeem Python code los ntawm ua ntej uas luam tawm rau peb lub tshuab luam ntawv tau txais, thiab peb muaj peb qhov kev xeem Flask server. Yog li tom ntej no peb yuav tsum sib sau ua ke thiab suav nrog qee qhov chaws uas rub cov ntaub ntawv los ntawm peb li Webhook applet. Cia peb tsim cov ntaub ntawv Python tshiab:

nano iot_print_server.py

Thiab hauv nws, ntxiv cov cai hauv qab no:

#! flask/bin/python #QHIA TXOG FLASK THIAB PRINTER LIBRARIES los ntawm lub raj mis ntshuam Flask, thov los ntawm escpos.printer import Usb #ASSIGN VARIABLES FOR THE PRINTER AND FLASK p = Usb (0x0416, 0x5011) app = Flask (_ name_) #CREATE 'INDEX' PAGE @app.route ('/') def index (): rov qab 'Koj lub Flask server ua haujlwm!' #CREATE "PAGE" CALLED "LIST" FOR PRINTING ALEXA SHOPPING LIST @app.route ('/list') def list (): #CAPTURE "GET" DATA FROM IFTTT WEBOOKS content = request.get_data () #CONVERT RAW DATA TO STRING str_content = str (cov ntsiab lus) #DIVIDE DATA INTO SEPERATE LINES str_split = str_content.splitlines () #SEPERATE WORDS BY COMMA THIAB YUAV TSHIAB LIST newlist = rau lo lus hauv str_split: word = word.split (',') newlist.extend (lo lus) #REMOVE FORMATTING MARKS rmv_marks = [s.strip ("b '") rau s hauv cov npe tshiab] #PRINT HEADER #print ("Khw Muag Khoom / n") p.text ("Cov Ntawv Khw Muag Khoom: / n ") #ENUMERATE AND PRINT EACH ITEM IN LIST r = 1 rau x hauv rmv_marks: #print (str (r) +". " + X +" / n ") p.text (str (r) +". " + x + "\ n") r + = 1 #REREY RESULTS return 'x' #RUN THE PROGRAM if _name_ == '_main_': app.run (debug = True, host = '0.0.0.0')

Koj tuaj yeem khiav nws kom pom tias nws rov qab ua qhov yuam kev, tab sis nws yuav tsis ua haujlwm nrog peb lub webhook tseem tsis tau vim tias tam sim no, tus neeg rau zaub mov tsuas yog ua haujlwm hauv zos. Tseem tsis muaj URL sab nraud rau lub webhook txuas rau. Peb tuaj yeem teeb tsa chaw nres nkoj xa mus rau ntawm peb lub router thiab tsuas yog siv peb lub ntsej muag sab nrauv IP chaw nyob, tab sis qhov ntawd tsis muaj kev nyab xeeb tiag. Ua lwm txoj hauv kev, Kuv txiav txim siab mus nrog NGROK.

Kauj Ruam 5: Teeb Sab Nraud Kev Nkag Mus Nrog Ngrok

Teeb Sab Nraud Kev Nkag Mus Nrog Ngrok
Teeb Sab Nraud Kev Nkag Mus Nrog Ngrok
Teeb Sab Nraud Kev Nkag Mus Nrog Ngrok
Teeb Sab Nraud Kev Nkag Mus Nrog Ngrok

Ngrok teeb tsa kev sib txuas ruaj ntseg rau koj lub network tsis tas yuav nthuav tawm koj tus IP sab nraud lossis cuam tshuam nrog kev xa mus tom ntej. Tom qab kos npe rau tus as khauj dawb, nws muab koj daim ntawv tso cai tso cai rau koj. Tom qab ntawd ntawm koj tus Raspberry Pi, koj tuaj yeem rub tawm nws, unzip nws, txuas koj tus ntawv cim npe, thiab tom qab ntawd khiav nws ntawm chaw nres nkoj 5000:

mkdir ngrokcd ngrok wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable… unzip ngrok-stable-linux-arm./ngrok authtoken [ntxig koj daim ntawv cim npe ntawm no]./ngrok http 5000

*** TSEEM CEEB *** Qhov dawb version ntawm Ngrok tsis muab chaw nyob zoo rau koj, yog li txhua zaus koj rov khiav Ngrok, nws yuav muab lwm qhov chaw rau koj. Yog tias koj xav tau chaw nyob zoo li ntawd koj tsis tas yuav rov kho koj li Webhook, tom qab ntawd koj yuav tsum tau them nyiaj rau tus lej hloov kho tshiab.

Ib txoj hauv kev dawb rau Ngrok uas muaj IP zoo li qub hu ua "Serveo" ntawm www.serveo.net

************************

Ntawm qhov screen tshwm sim, nws muab koj qhov chaw nyob xa mus rau koj (https://random-string.ngrok.io) uas koj tuaj yeem siv hauv peb li Webhook applet. Yog li rov qab mus rau "Yog Yog Li No", hauv qhov URL teb, nkag mus rau koj qhov chaw nyob xa mus rau Ngrok thiab taw tes rau "nplooj ntawv" nplooj ntawv ntawm peb Cov Neeg rau zaub mov Flask. Nws yuav tsum saib tej yam zoo li no

random_string.ngrok.io/list

Tom qab ntawd mus tom ntej thiab txuag cov kev hloov pauv.

Txhawm rau sim nws, ua kom Ngrok khiav, qhib lub davhlau ya nyob twg tshiab, thiab khiav peb cov ntawv nab nab. Nrog ob yam khoom ua haujlwm, nug Alexa dab tsi ntawm koj daim ntawv teev npe yuav khoom. Tom qab ib feeb lossis ob, nws yuav tsum luam tawm cov txiaj ntsig. Yog tias koj xav kom nws luam tam sim ntawd, tsuas yog mus rau koj li Applet ntawm IFTTT thiab nyem "Txheeb Xyuas Tam Sim No". Yog tias txhua yam mus tau zoo, daim ntawv txais nyiaj yuav tsum luam tawm dab tsi ntawm koj daim ntawv yuav khoom! Qhov kawg me ntsis ntawm cov cai peb xav tau ntxiv yog ib txoj hauv kev rau autostart ngrok thiab peb cov neeg rau zaub mov flask txhua lub sijhawm Pi pib. Peb tuaj yeem ua qhov ntawd yooj yim los ntawm kev ua peb cov ntawv Python ua tiav:

chmod +x iot_print_server.py

Tom qab ntawd peb tuaj yeem hloov kho peb /etc/rc.local cov ntaub ntawv kom nws zoo li qhov no:

## Los ntawm lub neej ntawd tsab ntawv no tsis ua dab tsi. # Luam tus IP chaw nyob _IP = $ (hostname -I) || muaj tseeb yog tias ["$ _IP"]; ces printf "Kuv tus IP chaw nyob yog %s / n" "$ _IP" fi #autostart ngrok thiab taw qhia nws rau koj daim ntawv lees paub./home/pi/ngrok/ngrok http -config =/home/pi/.ngrok2/ngrok. yml 5000 #autostart lub tshuab luam ntawv sej tsab ntawv sudo python3 /home/pi/iot_receipt_printer.py & tawm 0

Kauj Ruam 6: Ntxiv Pi rau Lub Tshuab Luam Ntawv

Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv
Ntxiv Pi rau lub Tshuab Luam Ntawv

Lub tshuab luam ntawv txais nyiaj kuv muaj ntau qhov chaw khoob hauv lub casing. Thiab nrog Raspberry Pi Zero tau me me li nws yog, Kuv xav tias nws yuav txias tsuas yog zais nws hauv daim ntawv txais nyiaj thiaj li zoo li ib yam khoom siv. Qhov teeb meem nkaus xwb yog tias Lub Tshuab Luam Ntawv Tau Txais ntawm 12v thiab Pi khiav ntawm 5v. Yog li yog tias peb tsuas xav tau ib lub xov tooj txuas hluav taws xob rau ob qho tib si, peb yuav tsum nqis qis dua 12v lub zog xa mus rau 5v.

Siv 7805 tus tswj hluav taws xob, 1uf tus neeg siv hluav taws xob, thiab 10uf tus neeg siv hluav taws xob, Kuv muaj peev xwm tsim tau yooj yim 5v tus tswj hwm uas kuv txuas nrog lub logic board ntawm daim ntawv txais nyiaj. Kuv tau xaim "-" xaim mus rau hauv av, thiab tom qab ntawd kuv tau siv lub "+" xaim mus rau "ntawm" sab ntawm lub zog hloov pauv kom Pi yuav qhib thiab tua thaum lub tshuab luam ntawv tau qhib thiab tua. Siv ntau lub ntsuas, kuv tau sim kom paub tseeb tias cov zis tau nyab xeeb rau Pi. Tom qab ntawd kuv tau siv lub micro-usb cable thiab txuas nrog Pi. Tom qab ntsaws lub cable rau hauv lub tshuab luam ntawv thiab tig qhov hloov pauv, ob lub tshuab luam ntawv thiab Pi tau qhib!

Thaum kawg, Kuv drilled qhov kom txuas USB cable los ntawm Pi rau lub tshuab luam ntawv. Kuv pom qhov chaw tso 5v tus tswj hwm thiab Pi sab hauv lub tshuab luam ntawv, thiab tom qab ntawd kuv muab txhua yam rov qab los ua ke. Yog li tam sim no lub tshuab luam ntawv nws muaj nws tus kheej muaj lub web server ib yam nkaus!

Kauj Ruam 7: Ua Nws Ntxiv

Coj Nws Ntxiv
Coj Nws Ntxiv

Yog tias koj muaj peev xwm saib "Yog Yog Li No", tej zaum koj tau pom tias nws muaj ntau qhov kev pabcuam web sib txawv los txuas rau. Yog li yog tias koj tsis muaj Alexa, lossis tsis quav ntsej siv ib qho, koj tuaj yeem siv txoj haujlwm no luam tawm los ntawm txhua yam, xws li Facebook, Twitter, Gmail, Google Tsev, Evernote, Tumblr, Flickr, Wordpress, lwm yam Koj tuaj yeem pom kuv cov cai rau luam tawm Tweets ntawm kuv nplooj Github. Tam sim no mus thiab pom dab tsi koj tuaj yeem tuaj nrog!

IoT Kev Sib Tw
IoT Kev Sib Tw
IoT Kev Sib Tw
IoT Kev Sib Tw

Thawj qhov khoom plig hauv IoT Challenge

Pom zoo: