ããã©ã¬ã³ãRaspberry Piã§æ®å½±ãããã¼ã¿ãèªåã§pCloudã«ã¢ãããã¼ããã¹ãã¼ããã¤ã¯ã
pCloudã¯è²·ãåãåã®ãã©ã¤ãã¼ãã¯ã©ã¦ãã§ãï¼
ã¡ããã¡ããã»ã¼ã«ããã¦ããã®ã§ããè²·ãå¾ãªæã«è²·ã£ã¦ãã¾ãã®ããªã¹ã¹ã¡ã§ããç§ã¯ååã®ãã©ãã¯ãã©ã¤ãã¼ã»ã¼ã«ã§è³¼å ¥ãã¾ããã
ãã®pCloudã«ã¯ãªãã¨Linux CLIç¨ãç¨æããã¦ãã¾ããç´ æ´ãããã§ããããããRaspberry PIã§ã使ããªããã試ãã¦ã¿ããã¨ã«ãã¾ãã
å ã Intelç³»ã®CPUã§ããæ¤è¨¼ããã¦ããªããããã®ã§ããããã¦ã©ãºãã¤ARM ç¨ã® pCloud CLIã¯åãã§ããããï¼
ããNetworkã«ã¤ãªãã£ãæç¹ã§ãã©ã¬ã³åç»ãGPSãã¬ã¼ã®æ å ±ãã¯ã©ã¦ãã«ã¢ãããã¼ãã§ããã°æé«ã§ããã§ã¯ã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ãããã
ã½ã¼ã¹ã³ã¼ãã¨ã¤ã³ã¹ãã¼ã«æ¹æ³ã®èª¬æã¯ä»¥ä¸ã«ããã¾ãã
ã§ã¯ã¾ãã¯ãã«ãã®ããã®ç°å¢æ§ç¯ã
pi@raspberrypi:~ $ sudo apt-get install cmake zlib1g-dev libboost-system-dev libboost-program-options-dev libpthread-stubs0-dev libfuse-dev libudev-dev fuse build-essential git Reading package lists... Done Building dependency tree... Done Reading state information... Done libpthread-stubs0-dev is already the newest version (0.4-1). libpthread-stubs0-dev set to manually installed. libudev-dev is already the newest version (247.3-7+rpi1+deb11u1). libudev-dev set to manually installed. zlib1g-dev is already the newest version (1:1.2.11.dfsg-2+deb11u2). cmake is already the newest version (3.18.4-2+rpt1+rpi1+deb11u1). The following packages were automatically installed and are no longer required: libevent-core-2.1-7 libevent-pthreads-2.1-7 libopts25 raspinfo sntp Use 'sudo apt autoremove' to remove them. Suggested packages: libboost1.74-doc libboost-atomic1.74-dev libboost-chrono1.74-dev libboost-container1.74-dev libboost-context1.74-dev libboost-contract1.74-dev libboost-coroutine1.74-dev libboost-date-time1.74-dev libboost-exception1.74-dev libboost-fiber1.74-dev libboost-filesystem1.74-dev libboost-graph1.74-dev libboost-graph-parallel1.74-dev libboost-iostreams1.74-dev libboost-locale1.74-dev libboost-log1.74-dev libboost-math1.74-dev libboost-mpi1.74-dev libboost-mpi-python1.74-dev libboost-numpy1.74-dev libboost-python1.74-dev libboost-random1.74-dev libboost-regex1.74-dev libboost-serialization1.74-dev libboost-stacktrace1.74-dev libboost-test1.74-dev libboost-thread1.74-dev libboost-timer1.74-dev libboost-type-erasure1.74-dev libboost-wave1.74-dev libboost1.74-tools-dev libmpfrc++-dev libntl-dev libboost-nowide1.74-dev The following NEW packages will be installed: libboost-program-options-dev libboost-program-options1.74-dev libboost-system-dev libboost-system1.74-dev libboost-system1.74.0 libboost1.74-dev libfuse-dev 0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded. Need to get 11.4 MB of archives. After this operation, 156 MB of additional disk space will be used. Get:1 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian bullseye/main armhf libboost1.74-dev armhf 1.74.0-9 [9,534 kB] Get:2 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian bullseye/main armhf libboost-program-options1.74-dev armhf 1.74.0-9 [374 kB] Get:3 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf libboost-program-options-dev armhf 1.74.0.3+b1 [4,616 B] Get:4 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian bullseye/main armhf libboost-system1.74.0 armhf 1.74.0-9 [242 kB] Get:5 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian bullseye/main armhf libboost-system1.74-dev armhf 1.74.0-9 [243 kB] Get:6 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf libboost-system-dev armhf 1.74.0.3+b1 [4,744 B] Get:7 http://ftp.jaist.ac.jp/pub/Linux/raspbian-archive/raspbian bullseye/main armhf libfuse-dev armhf 2.9.9-5 [1,018 kB] Fetched 11.4 MB in 8s (1,367 kB/s) Selecting previously unselected package libboost1.74-dev:armhf. (Reading database ... 123565 files and directories currently installed.) Preparing to unpack .../0-libboost1.74-dev_1.74.0-9_armhf.deb ... Unpacking libboost1.74-dev:armhf (1.74.0-9) ... Selecting previously unselected package libboost-program-options1.74-dev:armhf. Preparing to unpack .../1-libboost-program-options1.74-dev_1.74.0-9_armhf.deb ... Unpacking libboost-program-options1.74-dev:armhf (1.74.0-9) ... Selecting previously unselected package libboost-program-options-dev:armhf. Preparing to unpack .../2-libboost-program-options-dev_1.74.0.3+b1_armhf.deb ... Unpacking libboost-program-options-dev:armhf (1.74.0.3+b1) ... Selecting previously unselected package libboost-system1.74.0:armhf. Preparing to unpack .../3-libboost-system1.74.0_1.74.0-9_armhf.deb ... Unpacking libboost-system1.74.0:armhf (1.74.0-9) ... Selecting previously unselected package libboost-system1.74-dev:armhf. Preparing to unpack .../4-libboost-system1.74-dev_1.74.0-9_armhf.deb ... Unpacking libboost-system1.74-dev:armhf (1.74.0-9) ... Selecting previously unselected package libboost-system-dev:armhf. Preparing to unpack .../5-libboost-system-dev_1.74.0.3+b1_armhf.deb ... Unpacking libboost-system-dev:armhf (1.74.0.3+b1) ... Selecting previously unselected package libfuse-dev:armhf. Preparing to unpack .../6-libfuse-dev_2.9.9-5_armhf.deb ... Unpacking libfuse-dev:armhf (2.9.9-5) ... Setting up libboost-system1.74.0:armhf (1.74.0-9) ... Setting up libboost1.74-dev:armhf (1.74.0-9) ... Setting up libfuse-dev:armhf (2.9.9-5) ... Setting up libboost-program-options1.74-dev:armhf (1.74.0-9) ... Setting up libboost-program-options-dev:armhf (1.74.0.3+b1) ... Setting up libboost-system1.74-dev:armhf (1.74.0-9) ... Setting up libboost-system-dev:armhf (1.74.0.3+b1) ... Processing triggers for libc-bin (2.31-13+rpt2+rpi1+deb11u5) ...
使¥ç¨ãã£ã¬ã¯ããªä½æãã¦ã
pi@raspberrypi:~ $ mkdir console-client
ã½ã¼ã¹ã³ã¼ããã¯ãã¼ã³ãã¦ãã¾ãã
pi@raspberrypi:~ $ git clone https://github.com/pcloudcom/console-client.git ./console-client/ Cloning into './console-client'... remote: Enumerating objects: 8217, done. remote: Counting objects: 100% (89/89), done. remote: Compressing objects: 100% (68/68), done. remote: Total 8217 (delta 28), reused 67 (delta 21), pack-reused 8128 Receiving objects: 100% (8217/8217), 22.39 MiB | 3.03 MiB/s, done. Resolving deltas: 100% (5788/5788), done. Updating files: 100% (1552/1552), done.
ã½ã¼ã¹ã®ãã«ã
pi@raspberrypi:~/console-client/pCloudCC/lib/pclsync $ make fs gcc -Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=core2 -I../sqlite -DP_ELECTRON -fPIC -DP_OS_LINUX -D_FILE_OFFSET_BITS=64 -DP_SSL_MBEDTLS -I../mbedtls/include -c -o pcompat.o pcompat.c cc1: error: unrecognized -mtune target: core2 cc1: note: valid arguments are: arm8 arm810 strongarm strongarm110 fa526 fa626 arm7tdmi arm7tdmi-s arm710t arm720t arm740t arm9 arm9tdmi arm920t arm920 arm922t arm940t ep9312 arm10tdmi arm1020t arm9e arm946e-s arm966e-s arm968e-s arm10e arm1020e arm1022e xscale iwmmxt iwmmxt2 fa606te fa626te fmp626 fa726te arm926ej-s arm1026ej-s arm1136j-s arm1136jf-s arm1176jz-s arm1176jzf-s mpcorenovfp mpcore arm1156t2-s arm1156t2f-s cortex-m1 cortex-m0 cortex-m0plus cortex-m1.small-multiply cortex-m0.small-multiply cortex-m0plus.small-multiply generic-armv7-a cortex-a5 cortex-a7 cortex-a8 cortex-a9 cortex-a12 cortex-a15 cortex-a17 cortex-r4 cortex-r4f cortex-r5 cortex-r7 cortex-r8 cortex-m7 cortex-m4 cortex-m3 marvell-pj4 cortex-a15.cortex-a7 cortex-a17.cortex-a7 cortex-a32 cortex-a35 cortex-a53 cortex-a57 cortex-a72 cortex-a73 exynos-m1 xgene1 cortex-a57.cortex-a53 cortex-a72.cortex-a53 cortex-a73.cortex-a35 cortex-a73.cortex-a53 cortex-a55 cortex-a75 cortex-a76 cortex-a76ae cortex-a77 neoverse-n1 cortex-a75.cortex-a55 cortex-a76.cortex-a55 neoverse-v1 neoverse-n2 cortex-m23 cortex-m33 cortex-m35p cortex-m55 cortex-r52 native make: *** [<builtin>: pcompat.o] Error 1
ãã£ã¨ããã§ã¨ã©ã¼ã§ãã
cc1: error: unrecognized -mtune target: core2
ã¨ããã¨ã©ã¼ãåºã¦ãã¾ãã
Googleæ¤ç´¢ããã¨ãããã¤ã·ã¥ã¼ãæãã£ã¦ã¾ããã
pCloud CLI for ARM · Issue #175 · pcloudcom/console-client · GitHub
-mtune=native ã«å¤æ´ãã¾ããããnativeã¯ã³ã³ãã¤ã©ããã«ãã³ã³ãã¥ã¼ã¿ã® CPU ãèªåæ¤åºããã¢ã¼ãã§ãã
ã¡ãªã¿ã«ãRaspberry Pi Zero 2 Wã®CPUã¯ä»¥ä¸ã®éãã§ããã
pi@raspberrypi:~/console-client/pCloudCC/lib/pclsync $ uname -a Linux raspberrypi 5.15.84-v7+ #1613 SMP Thu Jan 5 11:59:48 GMT 2023 armv7l GNU/Linux
Makefileãéãã
CFLAGS=-Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=core2 -I../sqlite -DP_ELECTRON -fPIC
ã¨ãªã£ã¦ãããã¨ãã
CFLAGS=-Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=native -I../sqlite -DP_ELECTRON -fPIC
ã«å¤æ´ãã¾ããå度make fsãã¦ã¿ã¾ãããã
pi@raspberrypi:~/console-client/pCloudCC/lib/pclsync $ make fs ï¼çç¥ï¼ gcc -Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=native -I../sqlite -DP_ELECTRON -fPIC -DP_OS_LINUX -D_FILE_OFFSET_BITS=64 -DP_SSL_MBEDTLS -I../mbedtls/include -c -o pcrc32c.o pcrc32c.c gcc -Wall -Wpointer-arith -O2 -g -fno-stack-protector -fomit-frame-pointer -mtune=native -I../sqlite -DP_ELECTRON -fPIC -DP_OS_LINUX -D_FILE_OFFSET_BITS=64 -DP_SSL_MBEDTLS -I../mbedtls/include -c -o pfsstatic.o pfsstatic.c ar rcu psynclib.a pcompat.o psynclib.o plocks.o plibs.o pcallbacks.o pdiff.o pstatus.o papi.o ptimer.o pupload.o pdownload.o pfolder.o psyncer.o ptasks.o psettings.o pnetlibs.o pcache.o pscanner.o plist.o plocalscan.o plocalnotify.o pp2p.o pcrypto.o pssl.o pfileops.o ptree.o ppassword.o prunratelimit.o pmemlock.o pnotifications.o pexternalstatus.o publiclinks.o pbusinessaccount.o pcontacts.o poverlay.o poverlay_lin.o poverlay_mac.o poverlay_win.o pcompression.o pasyncnet.o ppathstatus.o pdevice_monitor.o ptools.o pssl-mbedtls.o pfs.o ppagecache.o pfsfolder.o pfstasks.o pfsupload.o pintervaltree.o pfsxattr.o pcloudcrypto.o pfscrypto.o pcrc32c.o pfsstatic.o plocks.o ar: `u' modifier ignored since `D' is the default (see `U') ranlib psynclib.a
ä»ã®ã¢ã¸ã¥ã¼ã«ããã«ããã¦ããã¾ãã
pi@raspberrypi:~/console-client/pCloudCC/lib/pclsync $ cd ../mbedtls/ pi@raspberrypi:~/console-client/pCloudCC/lib/mbedtls $ cmake . -- The C compiler identification is GNU 10.2.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/pi/console-client/pCloudCC/lib/mbedtls pi@raspberrypi:~/console-client/pCloudCC/lib/mbedtls $ make clean pi@raspberrypi:~/console-client/pCloudCC/lib/mbedtls $ make Scanning dependencies of target mbedtls [ 1%] Building C object library/CMakeFiles/mbedtls.dir/aes.c.o [ 2%] Building C object library/CMakeFiles/mbedtls.dir/aesni.c.o [ 4%] Building C object library/CMakeFiles/mbedtls.dir/arc4.c.o ï¼çç¥ï¼ [ 95%] Building C object library/CMakeFiles/mbedtls.dir/x509write_crt.c.o [ 97%] Building C object library/CMakeFiles/mbedtls.dir/x509write_csr.c.o [ 98%] Building C object library/CMakeFiles/mbedtls.dir/xtea.c.o [100%] Linking C static library libmbedtls.a [100%] Built target mbedtls
cmakeãã¾ãã
pi@raspberrypi:~/console-client/pCloudCC/lib/mbedtls $ cd ../.. pi@raspberrypi:~/console-client/pCloudCC $ cmake . -- The C compiler identification is GNU 10.2.1 -- The CXX compiler identification is GNU 10.2.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found Boost: /usr/lib/arm-linux-gnueabihf/cmake/Boost-1.74.0/BoostConfig.cmake (found version "1.74.0") found components: system program_options -- Configuring done -- Generating done -- Build files have been written to: /home/pi/console-client/pCloudCC pi@raspberrypi:~/console-client/pCloudCC $ make Scanning dependencies of target sqlite3 [ 10%] Building C object CMakeFiles/sqlite3.dir/lib/sqlite/sqlite3.c.o ï¼çç¥ï¼ [100%] Linking CXX executable pcloudcc [100%] Built target pcloudcc
ãã¾ããã«ãã§ããããã§ããæå¾ã«ã¤ã³ã¹ãã¼ã«ãã¦å®äºã§ãã
pi@raspberrypi:~/console-client/pCloudCC $ sudo make install [ 20%] Built target sqlite3 [ 80%] Built target pcloudcc_lib [100%] Built target pcloudcc Install the project... -- Install configuration: "" -- Installing: /usr/local/bin/pcloudcc -- Set runtime path of "/usr/local/bin/pcloudcc" to "" -- Installing: /usr/local/lib/libpcloudcc_lib.so
èªèããã¾ãã
pi@raspberrypi:~/console-client/pCloudCC $ sudo ldconfig
æ¥ç¶ãã¦ã¿ã¾ãããã-sãªãã·ã§ã³ãä»ããã¨ãã¹ã¯ã¼ããä¿åãã¾ãã以éã¯ãã¹ã¯ã¼ãå ¥åä¸è¦ã§ãã
pi@raspberrypi:~ $ pcloudcc -u username -p -s pCloud console client v.2.0.1 Please, enter password Down: Everything Downloaded| Up: Everything Uploaded, status is LOGIN_REQUIRED logging in Down: Everything Downloaded| Up: Everything Uploaded, status is CONNECTING Down: Everything Downloaded| Up: Everything Uploaded, status is SCANNING event1073741824 event1073741825 Down: Everything Downloaded| Up: Everything Uploaded, status is READY
ãããæ¥ç¶ã§ãã¾ããï¼ï¼ï¼
ã©ãºãã¤ã§pCloudã«æ¥ç¶åºæ¥ãã¨ã¯æåã§ãï¼
ãã¦ã³ãå ãæå®ãã¾ãã
mkdir -p /home/pi/mnt/pcloud pcloudcc -u username -p -s -m /home/pi/mnt/pcloud
/home/pi/mnt/pcloudã«ãã¦ã³ãããã¾ãããã®ãã©ã«ãã¯ãããã¯ã¼ã¯ã»ã¹ãã¬ã¼ã¸ã§ããã©ãºãã¤ä¸ã«ã¯åå¨ãããã¯ã©ã¦ãã¨é£æºãã¦ãã¾ããããã«ãã¡ã¤ã«ãã³ãã¼ããã¨ãCloudã¸UPããã¾ãã
ã¯ã©ã¤ã¢ã³ãã忢ããã«ã¯ã-kã§finalizeã³ãã³ããéãã¾ãã
pi@raspberrypi:/media/usb0 $ pcloudcc -u username -k pCloud console client v.2.0.1 Supported commands are: startcrypto <crypto pass>, stopcrypto, finalize, q, quit > finalize
忢ãããæã«ã¾ã Upããã¦ããªããã¡ã¤ã«ãããå ´åã~/.pcloud/Cacheã«ãã¡ã¤ã«ãããç¶æ ã§ããä¿çä¸ã®è»¢éãã¡ã¤ã«ãæ®ã£ã¦ããç¶æ ã§ãããã®ãã©ã«ãã®ä¸èº«ãcachedã ãã«ãªãã¨ããã¹ã¦ã¢ãããã¼ããããç¶æ ã§ãããã¨ãæå³ãã¦ãã¾ãã
pi@raspberrypi:~/.pcloud/Cache $ ls ~/.pcloud/Cache 52000000d 54000000d 56000000d 58000000d 5a000000d 5c000000d 5e000000d 60000000d 62000000d 64000000d 66000000d 68000000d 6a000000d 6c000000d 53000000d 55000000d 57000000d 59000000d 5b000000d 5d000000d 5f000000d 61000000d 63000000d 65000000d 67000000d 69000000d 6b000000d cached
pCloudをマウントする|[無料公開]pCloudを使いディスクレスのNASを作成する
ãåèã«ãèµ·åæã«ãã¦ã³ãããããã«ãµã¼ãã¹åãã¦ããã¾ãã
/etc/systemd/system/pcloud.serviceãã使ãã¾ãã
sudo vim /etc/systemd/system/pcloud.service
[Unit] Description=pCloud Command Line Client After=network-online.target [Service] Type=simple User=pi Group=pi WorkingDirectory=/home/pi/ ExecStart=/usr/local/bin/pcloudcc -u your_account_here Restart=always [Install] WantedBy=multi-user.target
your_account_hereããpCloudã®ã¢ã«ã¦ã³ãï¼ã¡ã¼ã«ã¢ãã¬ã¹ï¼ã«å¤æ´ãã¦ããã¾ãã
ã¦ããããã¡ã¤ã«ãé ç½®ãããdaemon-reloadã§åæ ããpcloudãµã¼ãã¹ã®èµ·åã»çµäºã®ãã¹ããè¡ããpcloudãµã¼ãã¹ãèªåèµ·åããããã«è¨å®ãã¾ãããã
pi@raspberrypi:~ $ sudo systemctl daemon-reload pi@raspberrypi:~ $ sudo systemctl start pcloud pi@raspberrypi:~ $ sudo systemctl status pcloud â pcloud.service - pCloud Command Line Client Loaded: loaded (/etc/systemd/system/pcloud.service; disabled; vendor preset: enabled) Active: active (running) since Sat 2023-03-25 11:23:10 JST; 2s ago Main PID: 15516 (pcloudcc) Tasks: 13 (limit: 869) CPU: 1.185s CGroup: /system.slice/pcloud.service ââ15516 pCloudDrive
Mar 25 11:23:10 raspberrypi systemd[1]: Started pCloud Command Line Client. Mar 25 11:23:10 raspberrypi pcloudcc[15516]: pCloud console client v.2.0.1
pi@raspberrypi:~ $ sudo systemctl stop pcloud pi@raspberrypi:~ $ sudo systemctl enable pcloud Created symlink /etc/systemd/system/multi-user.target.wants/pcloud.service â /etc/systemd/system/pcloud.service.
æå¾ã«ãã©ãºãã¤ãåèµ·åãã¦ã¿ã¦ãèªåãã¦ã³ãããããã¨ã確èªãã¾ãããã ### ãã©ã¬ã³åç»ãpCloudã«ã¢ãããã¼ãããããã°ã©ã ã使ããã ããã°ã©ã ã®è¦ä»¶ã¯ãã£ã¨ä»¥ä¸ã®ãããªæãã * åç»ãã¡ã¤ã«ã®ã¿ã¤ã ã¹ã¿ã³ãã確èªããå¤ããã®ããpCloudã«ã¢ãããã¼ããã¦ããã * USBã90ï¼ ã«ãªã£ããå¤ãåç»ããæ¶ãã¦ãããããå¤ããã¡ã¤ã«åªå ã§ã¯ã©ã¦ãã«Up * ãã¡ã¤ã«ãpCloudã®ãããã¯ã¼ã¯ã»ã¹ãã¬ã¼ã¸ã«ã³ãã¼ããã * ã³ãã¼å¦çã¯æ°åç§å¾ ãããããã¨ãããã®ã§å¥ã¹ã¬ããã§åããã * ããããã®ãã¡ã¤ã«ã¯pCloudã®ã¯ã©ã¤ã¢ã³ãããã£ãã·ã¥ãã¦ãããã * pCloudã«ã¢ãããã¼ããããã¡ã¤ã«ã®ã¿ã¤ã ã¹ã¿ã³ããè¦ãã¦ãããæ¬¡åã¯ãã®ã¿ã¤ã ã¹ã¿ã³ããããæ°ãããã¡ã¤ã«ã ãã¢ãããã¼ããããã¨ã§ãè¤æ°åã¢ãããã¼ããã¦ãã¾ããªãããã«èæ ®ããã * ã¿ã¤ã ã¹ã¿ã³ããæ°ãããã¡ã¤ã«ã¯ãã¾ã ä¿åéä¸ã®åç»ãã¡ã¤ã«ãããããªãã®ã§ãç¾å¨æéãã2å以ä¸ï¼120ç§ä»¥ä¸ï¼çµéãããã¡ã¤ã«ã¢ãããã¼ã対象ã¨ããã ãããå®ç¾ããããã®copy_cloud颿°ãä½æã æçµçã«ãdashcamã¹ã¯ãªããã¯æ¬¡ã®ããã«ãªãã¾ããã
!/usr/bin/env python3
from usbVideoDevice import UsbVideoDevice # https://smartphone-zine.hatenablog.com/entry/2023/02/25/065957 import subprocess import psutil # ãã©ã«ãæ®éç¢ºèª import os # ãã¡ã¤ã«æä½ã«ä½¿ã import sys # ããã°ã©ã ãéä¸ã§çµäºãããã®ã«ä½¿ã from operator import itemgetter # ã¤ãã©ãã«ããä»»æã®è¦ç´ ãæãåºã import signal # éåæã¤ãã³ãã«ãã³ãã©ãè¨å®ãã import threading import time # ã¹ãªã¼ãç¨ import shelve # æå¾ã«ã¯ã©ã¦ãã¸ã¢ãããããã¡ã¤ã«ã®æ¥æããã以éã®ãã¼ã¿ãpCloudã¸Upãã import shutil # ãã¡ã¤ã«ã®ã³ãã¼ import datetime # æ¥æå¦ç
config = shelve.open("dashcam") # è¨å®ãã¡ã¤ã«éã try: cloud_up_time = config["cloud_up_time"] except Exception as e: cloud_up_time = 0 print('Error: {0}'.format(e), file=sys.stderr)
print('\n------------[cloud_up_time]:' + str(datetime.datetime.fromtimestamp(cloud_up_time)))
pCloudã®ä¿åå ãã©ã«ã
pCloud = '/home/pi/mnt/pcloud/Dashcam/'
pCliudã使ç¨ããã¦ã¼ã¶
pCloud_user = 1000
ãã¼ã¿ãä¿åãããã©ã«ã EX) folder = '/media/usb0/'
folder = '/media/usb0/'
ä¿åå½¢å¼
extension = ".avi"
ãã¹ã¯ä½¿ç¨çããã®ï¼ ãè¶ ãããå¤ããã¡ã¤ã«ãåé¤
dsk_usage_ratio = 90.0
åæ¹ã«ã¡ã©ã®USBãã¼ãçªå·ã¨ç»åãµã¤ãº
front_cam_port = 4 front_cam_size = '1920x1080'
徿¹ã«ã¡ã©ã®USBãã¼ãçªå·
rear_cam_port = 1 rear_cam_size = '1280x720'
video_front_p = None # é²ç»ç¨ã®ããã»ã¹ã§ã video_rear_p = None # é²ç»ç¨ã®ããã»ã¹ã§ã
ã«ã¡ã©ã®Videoãã¼ãå¤å®
usbVideoDevice = UsbVideoDevice() video_front = "/dev/video" + str(usbVideoDevice.getId(front_cam_port)) video_rear = "/dev/video" + str(usbVideoDevice.getId(rear_cam_port))
Ctrl+C or KILL ã§æ¢ããããæã®å¦ç
def sig_handler(signum, frame) -> None: print('\n\n\n------------sig_handler()\n\n\n') global video_front_p global video_rear_p
config.close() # cloud_up_timeããã£ã¹ã¯ã«æ°¸ç¶åããã
if not video_front_p is None:
# video_front_p.terminate()
video_front_p.kill()
if not video_rear_p is None:
# video_rear_p.terminate()
video_rear_p.kill()
sys.exit(1) # ããã°ã©ã ãéä¸ã§çµäºããã
é²ç»å¦ç
def record(): global video_front_p global video_rear_p video_front_p = subprocess.Popen( ['ffmpeg', '-loglevel', 'error', '-use_wallclock_as_timestamps', '1', '-rtbufsize', '300M', '-f', 'v4l2', '-input_format', 'h264', '-video_size', front_cam_size, '-framerate', '30', '-i', video_front, '-c:v', 'copy', '-f', 'segment', '-strftime', '1', '-segment_time', '60', '-segment_atclocktime', '1', '-reset_timestamps', '1', folder + '%Y-%m-%d%H-%M-%S_f' + extension]) video_rear_p = subprocess.Popen( ['ffmpeg', '-loglevel', 'error', '-use_wallclock_as_timestamps', '1', '-rtbufsize', '300M', '-itsoffset', '-4.80', '-f', 'alsa', '-ac', '2', '-ar', '8000', '-acodec', 'pcm_s32le', '-thread_queue_size', '256', '-i', 'dmic_sv', '-f', 'v4l2', '-input_format', 'h264', '-video_size', rear_cam_size, '-i', video_rear, '-c:v', 'copy', '-acodec', 'aac', '-ar', '8000', '-b:a', '128k', '-vol', '512', '-f', 'segment', '-strftime', '1', '-segment_time', '60', '-segment_atclocktime', '1', '-reset_timestamps', '1', folder + '%Y-%m-%d%H-%M-%S_r' + extension])
def diskfree(): file_list = [] # ãã£ã¹ã¯ä½¿ç¨çãåå¾ dsk = psutil.disk_usage(folder) print('\n------------usage:' + str(dsk.percent)) if dsk.percent <= dsk_usage_ratio: return
# ãã¡ã¤ã«ãã¼ã¿åå¾
for file in os.listdir(folder):
file_info = os.stat(folder + file)
file_list.append([folder + file, file_info.st_mtime, int(file_info.st_size / 1024)])
# å¤ãé ã«ã½ã¼ã
file_list.sort(key=itemgetter(1))
# ãã¡ã¤ã«ã®åé¤
for file in file_list:
if os.path.isfile(file[0]):
if dsk.percent > dsk_usage_ratio:
print('\n------------[DELETE]' + file[0])
os.remove(file[0])
dsk = psutil.disk_usage(folder)
print('\n------------usage:' + str(dsk.percent))
else:
break
pCloudã¸ã¢ãããã¼ãããã
æå¾ã«ã¢ãããã¼ããããã¡ã¤ã«ã®ã¿ã¤ã ã¹ã¿ã³ããcloud_up_timeã«è¦ãã¦ããããã以éã«ä½æããããã¡ã¤ã«ã®ã¿Uploadããã
ç¡éã«ã¼ãå¦çã«ãªã£ã¦ããã®ã§ãå¥ã¹ã¬ããã§å¼ã³åºãã
def copy_cloud(): global cloud_up_time
while True:
# ãã¡ã¤ã«ãã¼ã¿åå¾
file_list = []
for file in os.listdir(folder):
file_info = os.stat(folder + file)
# UNIXæéï¼ã¨ããã¯ç§ï¼ãå
¥ãã¦ã½ã¼ãã§ããããã«ããã
file_list.append([folder + file, file_info.st_mtime, int(file_info.st_size / 1024)])
# å¤ãé ã«ã½ã¼ã
file_list.sort(key=itemgetter(1))
# time.time()-120 # 2ååã®UnixTimeãå¾ãæ¹æ³ãï¼ã¨ããã¯ç§ï¼ãªã®ã§120ç§ãæ¸ç®ããã°OK
# ååã¯ã©ã¦ãã«Uploadãããã¡ã¤ã«ã®æéï¼cloud_up_timeï¼ä»¥éãä¸ã¤ã2åå以åã®ãã¡ã¤ã«ãã¯ã©ã¦ãã«Uploadããã
for file in file_list:
if os.path.isfile(file[0]):
if cloud_up_time <= file[1] <= time.time() - 120:
# pCloudãã¦ã³ããã£ã¬ã¯ããªã«ã³ãã¼
try:
shutil.copy(file[0], pCloud)
cloud_up_time = file[1] # ååã¯ã©ã¦ãUploadãããã¡ã¤ã«ã®æéæ´æ°
print('\n------------[upload]:' + file[0] + " " + str(datetime.datetime.fromtimestamp(file[1])))
except Exception as err:
print('Error: {0}'.format(err), file=sys.stderr)
else:
print('\n------------[skip]:' + file[0] + " " + str(datetime.datetime.fromtimestamp(file[1])))
time.sleep(1)
def main(): # ã¹ã¯ãªãããæ¢ãããããããã»ã¹ã忢ãã signal.signal(signal.SIGTERM, sig_handler) # KILLãããã¨ã signal.signal(signal.SIGINT, sig_handler) # Ctrl+Cãããã¨ã
# é²ç»éå§
record()
# pCloudã¸ã¢ãããã¼ãã
thread = threading.Thread(target=copy_cloud)
thread.start()
while True:
# ãã£ã¹ã¯ã使ç¨çãè¶
ãããå¤ããã¡ã¤ã«ãåé¤ãã
thread = threading.Thread(target=diskfree)
thread.start()
# æ«ãå¾
ã¤
time.sleep(60)
if name == 'main': main()
仿¥ã¯ããã¾ã§ã§ãã