Cov txheej txheem:

Raspberry Pi Zero W Datalogger: 8 Kauj Ruam (nrog Duab)
Raspberry Pi Zero W Datalogger: 8 Kauj Ruam (nrog Duab)

Video: Raspberry Pi Zero W Datalogger: 8 Kauj Ruam (nrog Duab)

Video: Raspberry Pi Zero W Datalogger: 8 Kauj Ruam (nrog Duab)
Video: {meme} Japenese Office Girl Fast typing 443?!wpm 😨😱Fastest typer in the world 🔥😲 2024, Kaum ib hlis
Anonim
Raspberry Pi Zero W Datalogger
Raspberry Pi Zero W Datalogger

Siv Raspberry Pi Zero W, koj tuaj yeem ua tus pheej yig thiab yooj yim siv datalogger, uas tuaj yeem txuas nrog lub network wifi hauv ib cheeb tsam, lossis ua lub chaw nkag nkag hauv thaj chaw uas tso cai rau koj rub cov ntaub ntawv wirelessly nrog koj lub xov tooj.

Kuv nthuav qhia qhov teeb tsa no ntawm American Geophysical Union Lub Rooj Sib Tham 2017, raws li txoj hauv kev los ua koj tus kheej cov ntaub ntawv logger teeb tsa. Koj tuaj yeem pom qhov kev nthuav qhia ntawm no.

Koj yuav xav tau dab tsi:

  • Raspberry Pi Zero W.
  • Ib daim npav micro SD
  • USB cable lossis USB fais fab mov
  • Lub khoos phis tawj nrog USB daim npav nyeem ntawv
  • Yeem (tab sis muaj txiaj ntsig):

    • miniHDMI -> HDMI adapter (txuas Pi rau lub vijtsam)
    • USB OTG adapter (txuas cov keyboard rau Pi

Kauj Ruam 1: Teeb Pi Zero W

Txhawm rau pib, muab cov duab Rasbian tso rau ntawm daim npav microSD (hauv qhov kev qhia no kuv siv 2017-07-05-raspbian-jessie-lite, muaj nyob ntawm no). Ib qho Lite version tuaj yeem siv tau (tsis muaj lub desktop) raws li kev teeb tsa yuav ua tiav ntawm kab hais kom ua.

Ntxig daim npav SD rau hauv Pi, txuas lub vijtsam thiab keyboard, thiab ua kom lub zog txuas los ntawm ntsaws rau hauv lub hwj chim cable. Kev teeb tsa lub taub hau kuj tseem tuaj yeem ua tau, tab sis yuav xav tau txuas dua SSH.

Tom qab Pi tau pib nkag mus (lub npe siv tsis raug: pi, tus password: raspberry), thiab hloov tus lej zais nrog cov lus txib "passwd".

Cov keyboard tuaj yeem teeb tsa los ntawm kev nkag mus "sudo raspi-config" hauv lub davhlau ya nyob twg.

Kauj ruam 2: Txuas rau WiFi

Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi
Txuas mus rau WiFi

Txhawm rau txuas rau is taws nem, peb yuav qhia tus Pi uas lub network txuas rau. Pib los ntawm qhib cov ntawv hauv qab no;

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Hauv qhov no, ntxiv cov ntaub ntawv network hauv qab;

network = {

ssid = "npe network" psk = "network password"}

Nyob rau hauv rooj plaub ntawm kev lag luam network, koj tuaj yeem siv cov teeb tsa hauv qab no (kho WPA-EAP // TTLA // MSCHAPv2 rau qhov teeb tsa siv tau).

network = {

ssid = "ssid" #Nkag mus rau koj lub npe network key_mgmt = WPA-EAP eap = TTLS tus kheej = "xxxxx" #Nkag mus rau koj tus lej nkag nkag tus lej nkag mus = "xxxxx" #Nkag mus rau qhov ua tiav theem 2 = "auth = MSCHAPv2"}

Txuag los ntawm nias CTRL+O, thiab tawm nrog CTRL+X.

Tam sim no siv koj cov ntaub ntawv teeb tsa hauv/etc/network/interfaces

sudo nano/etc/network/interfaces

Hloov wlan0 ib feem rau:

wb wlan0

iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Ib zaug ntxiv, khaws cov ntawv (CTRL+O) thiab tom qab ntawd tawm (CTRL+X).

Tom qab rov pib dua (sudo rov pib dua), koj lub wifi txuas yuav tsum ua haujlwm. Koj tuaj yeem sim qhov no los ntawm pinging lub vev xaib;

pib ping www.google.com

Tshem tawm ping nrog CTRL+C.

Txhawm rau txuas rau Pi hla SSH wirelessly, koj yuav tsum pab kom SSH:

sudo raspi-teeb tsa

Nkag mus rau "5 Kev Xaiv Kev Sib Txuas", thiab pab kom SSH. Tom qab ntawd rov qab thiab tawm qhov teeb tsa.

Saib tus IP chaw nyob ntawm Pi:

ifconfig

Tus IP yuav nyob hauv "inet addr:" ntawm wlan0 interface.

Tam sim no koj tuaj yeem txuas rau Pi hla WiFi, yog tias koj nyob hauv tib lub network. Rub tawm Putty (rau lub qhov rais), nkag mus rau tus IP chaw nyob uas koj pom hauv "Host Name", thiab nias "Qhib". Tom qab lees txais cov lus ceeb toom tam sim no koj yuav tsum tuaj yeem pom kab hais kom ua thiab nkag mus.

Kauj Ruam 3: Hloov kho thiab Txhim Kho Cov Software Yuav Tsum Tau

Hloov kho thiab teeb tsa Cov Software Xav Tau
Hloov kho thiab teeb tsa Cov Software Xav Tau
Hloov kho thiab teeb tsa Cov software xav tau
Hloov kho thiab teeb tsa Cov software xav tau

Tom qab WiFi ua haujlwm, hloov kho Pi nrog:

sudo apt -tau hloov tshiab -y && sudo apt -tau upgrade -y

Tom qab qhov hloov tshiab tau ua tiav (nws tuaj yeem siv sijhawm me ntsis), teeb tsa software uas peb yuav siv nrog;

sudo apt-tau nruab python3 python3-serial apache2 -y

Kauj Ruam 4: Txuas mus rau Sensor (Hauv Qhov Piv Txwv no Arduino)

Ib qho txuas Arduino ua ke nrog cov keyboard siv lub USB hub, lossis txuas Arduino ntawm ib qho USB chaw nres nkoj nkaus xwb, thiab teeb tsa nrog SSH hla WiFi.

Txhawm rau tuaj yeem nkag mus rau qhov chaw nres nkoj txuas Arduino tau txuas nrog, nws muaj txiaj ntsig zoo los muab kev nkag mus rau tus lej pi lub neej ntawd. Raws li Arduino feem ntau yog muab rau chaw nres nkoj "/dev/ttyACM0", siv cov lus txib hauv qab no los muab 'pi' cov neeg siv nkag mus rau chaw nres nkoj:

sudo chown pi: /dev /ttyACM0

Piv txwv tias, Arduino twb tau teeb tsa kom xa cov ntaub ntawv hla qhov chaw nres nkoj, koj tuaj yeem saib cov ntaub ntawv hauv sej raws li hauv qab no:

Qhib nab nab;

nab hab sej 3

Ntshuam serial:

ntshuam ntshuam

Qhib qhov chaw nres nkoj com:

ser = serial. Serial (chaw nres nkoj = '/dev/ttyACM0', baudrate = 9600, sij hawm = 5)

Qhov twg baudrate ntawm Arduino tau teeb tsa rau 9600 hauv qhov no.

Koj tuaj yeem nyeem thiab luam kab los ntawm kev ua cov cai hauv qab no:

ser.readline (). txiav txim siab ('utf-8')

Yog tias koj muaj nws ua haujlwm, koj tuaj yeem kaw qhov txuas thiab tawm Python nrog:

ser.close ()

tawm ()

Kauj Ruam 5: Teeb WiFi Muaj Peev Xwm Muaj Peev Xwm Muaj Peev Xwm

Los ntawm teeb tsa koj Pi Zero W hauv hom nkag mus rau wifi, koj tuaj yeem txuas rau nws nrog txhua lub cuab yeej wifi. Qhov no tso cai teeb tsa lub logger thiab rub tawm cov ntaub ntawv hla wifi, tsis muaj cov kab lossis cov tsav tsheb xav tau.

Txog qhov no, Adafruit muaj cov lus qhia zoo muaj. Qee cov lus me me:

  • Rau /etc/hostapd/hostapd.conf tus neeg tsav tsheb, siv tsis txhob siv kab tsav tsheb.
  • Kauj ruam "Hloov hostapd" yuav tsum tsis tsim nyog.

Yog tias qhov nkag mus tsis ua haujlwm tom kawg ntawm kev qhia, sim rov pib Pi (sudo reboot).

Kauj Ruam 6: Hloov Chaw Ntawm Wifi Nkag Mus Siv Tus Kheej thiab Cov Neeg Siv Khoom

Qee zaum koj yuav xav hloov kho software, lossis teeb tsa software tshiab rau koj li Raspberry Pi, tab sis qhov no yuav tsum muaj kev sib txuas hauv is taws nem. Luckily hloov ntawm ob yog yooj yim heev.

Txuas rau Pi nrog SSH (hla kab, tsis yog wifi!). Pib los ntawm kev siv cov kev pabcuam nkag mus siv:

sudo cystemctl nres hostapd.service

sudo cystemctl nres isc-dhcp-server.service

Tom qab ntawd hloov cov ntaub ntawv network cuam tshuam:

sudo nano/etc/network/interfaces

Ntawm no koj yuav tsum tawm tswv yim tawm tswv yim tsis, thiab tsis-tawm tswv yim kev sib txuas hauv network. Hloov nws los ntawm qhov no:

#-Hosting tsis:

pub-hotplug wlan0 iface wlan0 inet zoo li qub chaw nyob 192.168.42.1 netmask 255.255.255.0 # -Network (tus thov kev pabcuam) tsis: #auto wlan0 # iface wlan0 inet dhcp # wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Txog qhov no:

#-Hosting tsis: #pub-hotplug wlan0 #iface wlan0 inet zoo li qub #chaw nyob 192.168.42.1 #netmask 255.255.255.0 #-Network (tus thov) tsis: pib wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Txuag thiab kaw cov ntawv.

Tom ntej no koj khiav cov lus txib hauv qab no:

sudo systemctl pib wpa_supplicant.service

sudo ifdown wlan0 sudo ifup wlan0

Tam sim no koj tus Pi yuav tsum txuas rau wifi dua, tso cai rau koj hloov kho thiab teeb tsa software.

Txhawm rau rov qab mus rau hom kev nkag, hloov ib ncig ntawm cov lus hauv/etc/network/interfaces, thiab rov pib dua Pi.

Kauj Ruam 7: Cov Lus Cim Kawg

Lus Cim Kawg
Lus Cim Kawg

Teeb tsa lub vev xaib

Lub server apache nyob hauv/var/www/. Txhawm rau hloov nplooj ntawv tsis raug, hloov kho /var/www/html/index.html cov ntaub ntawv.

Koj tuaj yeem ua cov ntaub ntawv ntawm no txhawm rau rub tawm hla lub wifi txuas, los ntawm kev tshawb xyuas koj lub browser mus rau Pi tus IP chaw nyob (192.168.42.1). Txhua lub cuab yeej siv tau wifi tuaj yeem rub tawm lawv yam tsis muaj software ntxiv.

Kev sib txuas SFTP

Hla SSH, tuaj yeem ua FTP kev sib txuas. Koj tuaj yeem siv Filezilla kom xa cov ntaub ntawv ntau sai thiab yooj yim (saib duab).

Sijhawm Tiag

Raws li lub moos sab hauv ntawm Pi yuav ploj mus ntau yog tias tsis muaj kev sib txuas rau internet, yuav tsum tau siv lub sijhawm tiag tiag (RTC) module yog tias yuav tsum tau siv lub sijhawm kom raug. Ib qho piv txwv yog RasClock, cov lus qhia teeb tsa tuaj yeem pom ntawm no. Lwm lub moos i2c kuj tseem muaj (piv txwv li DS3231)

Xaus

Yog tias txhua yam mus tau zoo, tam sim no koj yuav tsum muaj Pi Zero datalogger ua haujlwm! Python logging tsab ntawv piv txwv suav nrog hauv cov kauj ruam tom ntej.

Kauj Ruam 8: Piv Txwv Python Logging Script

import os

ntshuam serial los ntawm lub sijhawm ntshuam sijhawm los ntawm datetime ntshuam datetime ntshoo numpy li np ser = serial. Serial (chaw nres nkoj = 'COM4', baudrate = 57600, sijhawm tas = 5) directory = r '\ var / www / html / data / anemometer / WMPro1352_ 'ser.flushInput () ser.flushOutput () sim: thaum Tseeb: day_timestring = datetime.strftime (datetime.now (),'%Y%m%d ') file_today = directory + day_timestring +'.dat ' #Nyeem tawm cov ntaub ntawv thiab tam sim tau txais lub sijhawm kab = ser.readline (). txiav txim siab ('utf-8') tam sim no = datetime.strftime (datetime.now (), '%Y-%m-%d%H:%M:% S.%f ') line = line.split (', ') try: u = float (line [1]) except: u = np.nan try: v = float (line [2]) except: v = np..nan try: w = float (line [3]) except: w = np.nan try: c = float (line [5]) except: c = np.nan Ts = 1/403*c ** 2 - 273.15 sim: Ta = ntab (kab [8]) tsuas yog: Ta = np.nan yog (os.path.isfile (file_today)): nrog qhib (file_today, 'a') raws li fileobject: fileobject.write (tam sim no+',') fileobject.write (str (u)+','+str (v)+','+str (w)+','+str (c)+','+str (Ts)+','+ str (Ta)+'\ n') fileobject.clos e () lwm: nrog qhib (file_today, 'w') raws li fileobject: fileobject.write ('"Sijhawm", "u", "v", "w", "c", "Ts", "Ta" n ') fileobject.write (nowtime+', ') fileobject.write (str (u)+', '+str (v)+', '+str (w)+', '+str (c)+', '+str (Ts)+', '+str (Ta)+' / n ') fileobject.close () tshwj tsis yog KeyboardInterrupt: ser.close ()

Pom zoo: