直接換 /usr/share/plymouth/themes/pix/splash.png 檔案就可以了。
to remove lightning bulb: add "avoid_warnings=1" to /boot/config.txt
https://blog.gtwang.org/iot/raspberry-pi-vcgencmd-hardware-information/
free -h // Mem 3.6Gi
htop // Mem 3.64G
https://www.raspberrypi.org/documentation/configuration/external-storage.md
sudo blkid
sudo mkdir /mnt/mydisk
sudo mount /dev/sda1 /mnt/mydisk
ls /mnt/mydisk
格式化 sudo mkfs -t ext4 /dev/sdb
unmount
sudo umount /mnt/mydisk
That depends on what file system they use. If they are ext2/3/4 you can use e2label or if FAT32 then dosfslabel e.g.
sudo e2label /dev/sda1 MyNewLabel
sudo dosfslabel /dev/sda1 MyNewLabel
sudo nano /boot/config.txt
dtoverlay=gpio-shutdown,gpio_pin=21,active_low=1,gpio_pull=up 在最後一行加入這一個文字。
uname -a 查詢 kernel 版本
/opt/vc/bin/vcgencmd version 查詢 firmware 版本
cat /proc/version 查詢更完整的 kernel 資料
如何在 Jessie Lite 上安裝視窗環境呢? 只要用 sudo apt-get update 和 sudo apt-get install lxde 就可以將 LXDE 和相依的套件裝起來,大約會新裝 602 個套件共計 842MB。之後就可以用 startx 開始使用 GUI
run top -u root you'll get only root processes.
Disk Space, Memory Use, and CPU Load: du, df, free, and w 記憶體free -h,磁碟df -h,使用者w
EtcherPortable download
Pi Power Tools https://github.com/Botspot/Pi-Power-Tools#img-mode 推薦使用,備份之後再擴容,不受記憶卡容量不同之限制
download & install
wget -O - https://raw.githubusercontent.com/Botspot/Pi-Power-Tools/master/update | bash
uninstall
sudo apt purge gparted yad systemd-container xserver-xephyr expect
rm -rf ${HOME}/Pi-Power-Tools ${HOME}/Pi-Power-Tools.old
rm ${HOME}/Desktop/ppt.desktop ${HOME}/.local/share/applications/ppt.desktop
Flash OS images to SD cards & USB drives, safely and easily.
https://www.raspberrypi.org/downloads/raspbian/
login root
sudo useradd -m jj
sudo passwd jj
sudo usermod john -g sudo
ip addr show
樹莓派(raspberry)啟用root 帳號
默認用戶是pi 密碼為raspberry
sudo passwd –unlock root
sudo raspi-config
Raspberry Pi
ifconfig
PC
Advanced IP Scanner that can scan an entire network
Cell Phone
Mac OS
The Best WiFi Analyser For Mac (2019)
修改 /etc/network/interfaces,請執行:
sudo nano /etc/network/interfaces
將裏頭的內容修改為:
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
address 192.168.1.222
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid 無線網路的名稱
wpa-psk 無線網路的密碼
修改完成以後,依序按下「Ctrl+X」、「Y」與「Enter」儲存檔案,接著修改 DNS Server 設定,因為我實際上運行時,預設的 DNS Server 設定沒有用,請執行:
nano /etc/resolv.conf
加入新的 DNS Server 設定,例如:
nameserver 8.8.8.8
nameserver 8.8.8.4
同樣依序按下「Ctrl+X」、「Y」與「Enter」儲存檔案,接著 sudo poweroff 關機,拔除電源與 USB 鍵盤,重新接上電源開機完成後,你就可以 SSH 至方才指定的 IP 位址,使用 pi 與自設的密碼登入。
fcitx
sudo apt-get install fcitx-table-boshiamy (嘸蝦米)
sudo apt-get install fcitx-table-cangjie-big (倉頡大字集)
sudo apt-get install fcitx-table-zhengma-large (鄭碼大字集)
sudo apt-get install fcitx-table-wubi-large (五筆大字集)
sudo apt-get install fcitx-chewing (新酷音)
sudo apt-get install fcitx-sunpinyin (双拼)
sudo apt-get install fcitx-table-easy-big (輕鬆大詞庫)
sudo apt-get install fcitx-m17n
scim
sudo aptitude update
sudo aptitude install -y task-chinese-t-desktop
sudo nano /etc/default/keyboard
把 將XKBLAYOUT=“gb “ 改為 將XKBLAYOUT=”us”,再按 Ctrl + X 離開,重啟一次就會變回正常的鍵盤。
然後再於 Terminal 輸入:sudo aptitude install -y scim scim-tables-zh
那麼就安裝好中文輸入法,在偏好設定中 > SCIM Input Method 進行設定。
其他的輸入法請參考
安裝全部文鼎中文字型,可輸入以下指令:
$ sudo apt-get install fonts-arphic*
[cwTex圓體]
$ sudo apt-get install fonts-cwtex-yen
修改中文環境
nano /etc/default/locale
LC_ALL=zh_TW.UTF-8
sudo nano /etc/ssh/sshd_config
port 22 change to port 3391
sudo service sshd restart
PuTTY xxx.xxx.xxx.xxx
login jj
su - root
sudo apt-get update
sudo apt-get install xrdp
orangepi pc 要用如下
sudo apt-get install xrdp tightvncserver
Setup Options
https://opensource.com/article/17/3/building-personal-web-server-raspberry-pi-3
sudo ifconfig
ssh pi@192.168.1.115
sudo apt-get install xrdp
建議使用 vnc 較好***
將目前已經安裝的套件都先更新到最新。
sudo apt update
sudo apt upgrade
sudo apt-get install build-essential make gccg++ git-core
wget -O wordpress.zip http://www.minjieren.com/download.aspx?id=1080
wget --limit-rate=300k http://www.minjieren.com/wordpress-3.1-zh_CN.zip
wget --ftp-user=xxxx --ftp-password=xxxxx ftp://120.97.62.97/jj/mp3/*
sudo timedatectl set-time "2014-11-08 06:40:00"
sudo timedatectl set-timezone Asia/Taipei
sudo timedatectl set-ntp true
alsamixer
amixer help
amixer scontrols
amixer -c <card-number> set <control> <value> amixer -c 0 set Master 100% amixer -c 0 set Master mute
/etc/systemd/system/talk.service
systemctl list-unit-files
systemctl start {SERVICENAME}
systemctl stop {SERVICENAME}
systemctl enable {SERVICENAME}
systemctl disable {SERVICENAME}
下載一個檔:
curl ftp://120.97.62.97/SleepAway.mp3 –u jj:jaxxsjxan -o *.mp3
上載一個檔:
curl –u name:passwd -T size.mp3 ftp://malu.me/mp3/
df -h 看一下目前系統硬碟的使用情形
先用fdisk 擴大 ./ 的容量, 再用resize2fs /dev/ssdxxxxxx
fdisk -l
https://diyprojects.io/share-file-orange-pi-armbian-raspberry-pi-raspbian-samba/#.XbZzUegzaUk
sudo apt install smplayer
1. Add the following to /etc/apt/sources.list:
deb http://dl.google.com/linux/chrome/deb/ stable main
$ wget https://dl-ssl.google.com/linux/linux_signing_key.pub
$ sudo apt-key add linux_signing_key.pub
$ sudo apt-get update
$ sudo apt-get install chromium
sudo apt-get install bluetooth bluez blueman
sudo reboot
sudo apt-get install samba samba-common-bin
mkdir /home/pi/shared
sudo nano /etc/samba/smb.conf
[pimylifeupshare]
path = /home/pi/shared
writeable=Yes
create mask=0777
directory mask=0777
public=no
sudo smbpasswd -a pi
sudo systemctl restart smbd
hostname -I
另一個選擇是 將RaspberryPi 安裝 OpenMediaVault 變成 NAS
sudo apt-get install vsftpd
sudo nano /etc/vsftpd.conf
replace with
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
user_sub_token=$USER
local_root=/home/$USER/FTP
編輯完畢按 Ctrl+O (Enter) 存檔, 再按 Ctrl+X 跳出 Nano 即可.
mkdir -p /home/<user>/FTP/files
chmod a-w /home/<user>/FTP
sudo service vsftpd restart
如此就可以用 pi 帳號以port 22 之 sftp 連上樹莓派
如果要在登入 FTP 伺服器時直接進入 /var/www/html 目錄, 可以先建立一個使用者帳號例如 tony :
pi@raspberrypi:~ $ sudo useradd tony
pi@raspberrypi:~ $ sudo passwd tony
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
然後用 usermod 指令更改其預設目錄 :
pi@raspberrypi:~ $ sudo usermod -d /var/www/html/tony tony
You have new mail in /var/mail/pi
這樣用 tony 這個帳號登入 FTP 伺服器時, 就會直接進入 /var/www/html/tony 這個目錄了.
service --status-all
sudo apt update
sudo apt install filezilla
How to install a web server on the Raspberry Pi (Apache + PHP + MySQL)
sudo apt update
sudo apt upgrade
sudo apt install apache2
sudo chown -R pi:www-data /var/www/html/
sudo chmod -R 770 /var/www/html/
sudo apt install php php-mbstring
sudo rm /var/www/html/index.html
echo "<?php phpinfo ();?>" > /var/www/html/index.php
sudo apt install mariadb-server php-mysql
sudo mysql --user=root 可以用此進入sql command
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
exit 離開 sql command
mysql --user=root --password=yourmysqlpassword 萬一有錯可以用這一個命令回到 sql command 來修改
sudo apt install phpmyadmin 選擇apache2 及 dbconfig-common 安裝時遇到 選擇 no
sudo phpenmod mysqli
sudo /etc/init.d/apache2 restart
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
http://127.0.0.1/phpmyadmin 在瀏覽器url中 輸入
sudo nano /boot/config.txt
hdmi_group=1
hdmi_mode=4
Press Control-x
Press y
Press [enter]
sudo reboot
查看可用模式
tvservice –m CEA
tvservice -s
display_rotate=0
display_rotate=1
display_rotate=2
display_rotate=3
0 is the normal configuration. 1 is 90 degrees. 2 is 180 degress. 3 is 270 degrees.
7 inch screen
# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt=800 480 60 6 0 0 0
max_usb_current=1
sudo raspi-config
Select Option 7 Advanced Options and press Enter, then select Option A4: Audio and press Enter
wget www.waveshare.com/w/upload/4/4b/LCD-show-161112.tar.gz
tar xvf LCD-show-161112.tar.gz
cd LCD-show
sudo ./LCD35-show
sudo ./LCD-hdmi 切換回HDMI
有關微雪的產品,提供一個教學的網站,可到以[微雪課堂] 取得相關資料
cat /sys/class/thermal/thermal_zone0/temp
raspistill -o image.png
raspistill -vf -hf -o cam2.jpg Vertical Flip & Horizontal Flip
預覽指令:
raspistill -f (全螢幕預覽)
raspistill -t 10000 (預覽十秒 參數單位為毫秒)
raspistill -p 0,0,100,100 (預覽視窗設定 x,y,w,h)
raspistill -f -op 100 (設定預覽視窗透明度 參數範圍 0-255)
拍照指令:
raspistill -o test.jpg (輸出圖檔 儲存路徑/檔案名稱)
raspistill -o test.jpg -hf(水平翻轉)
raspistill -o test.jpg -vf(垂直翻轉)
raspistill -o test.jpg -w 100 -h 100 (設定圖片大小 寬 高)
raspistill -o test.jpg -q (設定影像品質 參數範圍 0-100)
錄影指令:
raspivid -o test.mp4
自動加檔案名字 camera.sh
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
raspistill -vf -hf -o /home/pi/camera/$DATE.jpg
chmod +x camera.sh
./camera.sh
另一個範例 拍照 Script
vi ~/takeapic.sh
#!/bin/bash
# 5 second, rotate 180 degree, shutter 0.5s, filename YYYYMMDD_HHMMSS.jpg
raspistill -vf -hf -x -n -e jpg -ISO 800 -ex auto -awb fluorescent -q 100 -w 2560 -h 1440 -t 1 -ss 50000 -o /home/user/DCIM/`date +%Y%m%d_%H%M%S`.jpg
旋轉:180 度紀錄EXIF:是編碼:jpg感光度:800曝光模式:自動白平衡:螢光燈品質:100解析度:2560 x 1440拍照延遲:1秒快門:0.5s儲存位置:/home/user/DCIM/[日期_時間].jpg錄影 Script
touch ~/takevideo.sh
chmod 511 ~/takevideo.sh
vi ~/takevideo.sh
raspivid -vf -hf -awb fluorescent -w 1920 -h 1080 -fps 30 -t 10000 -o /home/user/DCIM/`date +%Y%m%d_%H%M%S`.mp4
== 即時串流低延遲 Webcam (mJPEG) == 640 x 360 / 30fps ,畫面高速移動,CPU使用率約 0.62 (不到 1 core) 2018 四月份的系統檔之前才可用
# 安裝設定 golang
sudo apt install golang-1.6 git
export PATH=$PATH:/usr/lib/go-1.6/bin
export GOPATH=~/go
# 下載 mjpeg-server
mkdir ~/go
cd ~/go
git clone https://github.com/speps/grumpy-pi-mjpg.git
# 編譯 mjpeg-server
cd grumpy-pi-mjpg/
go build mjpg-server.go
# 啟動相機錄影,將流導向給 mjpeg-server
raspivid -vf -hf -cd MJPEG -w 640 -h 360 -fps 30 -t 0 -n -b 6000000 -o - | ./mjpg-server
# 觀看串流
http://[raspberry_IP]:8081
匯入相關模組
import picamera
from time import sleep
初始化
camera = picamera.PiCamera()
捕獲影象
camera.capture(‘image.jpg’)
開啟預覽
camera.start_preview()
垂直翻轉
camera.vflip = True
水平翻轉
camera.hflip = True
控制攝像頭亮度
camera.brightness = 60
控制攝像頭錄影
camera.start_recording(‘video.h264’)
程式休眠,但攝像頭繼續工作
sleep(5)
停止錄影
camera.stop_recording()
對焦和測試:
電腦上使用USB攝像頭,調整焦距到最好的顯示效果
(驅動程式請往這裡下載:win7-USB-camera-software.rar)
拍攝影片:
sudo apt-get update
sudo apt-get install ffmpeg
ffmpeg -f video4linux2 -r 7 -s 640x480 -i /dev/video0 video0.avi
播放影片:
omxplayer -o hdmi video0.avi
拍照-安裝軟體:
sudo apt-get install fswebcam
拍照-抓取圖片:
fswebcam -r 640x480 image.jpg
sudo apt-get install tmux
tmux
按任何快捷鍵之前一定要先按 Ctrl + b 如說要水平分割出一個 pane,就要先按 Ctrl + b 再按 %
% 垂直分割
" 水平分割
o 交换窗格
x 关闭窗格
c 開新 window
n 切換到下一個 window
p 切換到前一個 window
sudo apt-get update
sudo apt-get install pptpd
sudo nano /etc/pptpd.conf
Add to it:
localip 192.168.1.67
remoteip 192.168.1.200-250
sudo nano /etc/ppp/pptpd-options
ms-dns 8.8.8.8
sudo nano /etc/ppp/chap-secrets
greenterminal * password123 *
sudo service pptpd restart
sudo service pptpd status
sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1
sudo sysctl -p
sudo service pptpd restart
要學習 Docker ,有三個重要的名稱一定要瞭解,包括:Image、Container及Repository。
• 映像檔(Image):就是一個唯讀的模板。Docker 執行容器前需要本地存在對應的映像檔,如果映像檔不存在本地,Docker 會從映像檔倉庫下載。
• 容器(Container):容器是獨立執行的一個或一組應用,以及它們的執行態環境,對應到虛擬機,類比執行一整套作業系統。Docker 的容器是從映像檔建立的執行實例,它可以被啟動、開始、停止、刪除。每個容器都是相互隔離的、保證安全的平台。
• 倉庫(Repository):是集中存放映像檔檔案的場所。倉庫分為公開倉庫(Public)和私有倉庫(Private)兩種形式。官方提供 Docker Hub 作為映像檔登錄及註冊(Registry),這是類似 Github 程式碼儲存服務。一個 Docker Registry 中可以包含多個倉庫(Repository);每個倉庫可以包含多個標籤(Tag);每個標籤對應一個映像檔。
curl -sSL https://get.docker.com | sh 安裝 Docker
sudo usermod -aG docker pi 將 pi 這個使用者帳號加入 docker 群組
docker search raspbian
開機時,自動執行 Docker:
$ sudo systemctl enable docker
• 重新開機後,手動執行 Docker daemon:
$ sudo systemctl start docker
或
$ sudo /etc/init.d/docker start
docker pull resin/rpi-raspbian
docker run resin/rpi-raspbian /bin/echo 'Hello world'
docker run -ti resin/rpi-raspbian
搜尋 Docker Hub上可用的映像檔:
$ sudo docker search armhf
查詢 Docker上可用的映像檔:
$ sudo docker images
從倉庫取得所需要的映像檔。
$ sudo docker pull resin/rpi-raspbian
執行安裝映像檔
$ sudo docker run -ti resin/rpi-raspbian
-i 開啟標準輸出入(STDIN)
-t 配置一個虛擬終端機
移除本地端映像檔
$ sudo docker rmi -f resin/rpi-raspbian
** 注意 docker rm 命令是移除容器。
其他的指令
docker container ls --all
docker container ls
docker container kill [containerID]
也可以使用docker container run命令的--rm参数,在容器终止运行后自动删除容器文件。
docker container run --rm -p 8000:3000 -it koa-demo /bin/bash
-d:在后台运行
-p :容器的80端口映射到127.0.0.2:8080
--rm:容器停止运行后,自动删除容器文件
--name:容器的名字为mynginx
type ctrl+d to exit the session
typing ctrl+p and ctrl+q keeps the container running but frees up your terminal
docker ps -a # 查看正在运行的容器
docker ps # 查看容器
docker stop nginx # 停止正在运行的容器
docker start nginx # 启动一个已经停止的容器
docker start nginx # 重启一个容器
docker rm nginx # 删除容器
docker image pull hello-world
docker container logs [containerID]
docker container exec -it [containerID] bash
docker container cp [containID]:[/path/to/file] .
容器里面网页文件所在的目录/usr/share/nginx/html
容器里面配置文件所在的目录/etc/nginx
一、外部文件位置
$ mkdir nginx-docker-demo
$ cd nginx-docker-demo
然后,新建一个html子目录。
$ mkdir html
在这个子目录里面,放置一个index.html文件,内容如下。
<h1>Hello World</h1>
二、複製配置文件至容器外
把容器里面的 Nginx 配置文件拷贝到本地。
$ docker container cp mynginx:/etc/nginx .
上面命令的含义是,把mynginx容器的/etc/nginx拷贝到当前目录。不要漏掉最后那个点。
执行完成后,当前目录应该多出一个nginx子目录。然后,把这个子目录改名为conf。
$ mv nginx conf
三、設定啟動對映命令
docker container run --rm --name mynginx --volume "$PWD/html":/usr/share/nginx/html --volume "$PWD/conf":/etc/nginx -p 80:80 -d nginx
PHP-FPM
从 Dockerhub拉取 PHP-FPM 镜像
$ docker pull php:fpm
$ docker run --name php-fpm -p 9000:9000 -d php:fpm
把配置文件复制到本地:
$ cd ~/www
$ docker cp php-fpm:/usr/local/etc/php-fpm.d/www.conf www.conf
$ docker cp php-fpm:/usr/src/php/php.ini-production php.ini
打開 Browser 輸入 http://localhost
docker container stop nginx 容器终止
Apache 2.4 httpd
docker run -dit --name jj-web -p 80:80 -v /home/pi/Web/www/:/usr/local/apache2/htdocs/ httpd:2.4
使用 Docker 執行 python 的 gpio 控制 LED 燈
sudo pip3 install docker-compose
docker-compose version
DS18B20 Temperature Sensor With Python (Raspberry Pi)
送溫度資料至 ThingSpeak 的程式 及控制GPIO17 輸出的繼電器
import sys
import RPi.GPIO as GPIO
import urllib.request
from time import sleep
temper2 = 0
GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers
RELAIS_1_GPIO = 17
GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Assign mode
def getSensorData():
tempfile = open("/sys/bus/w1/devices/28-0417000302ff/w1_slave")
thetext = tempfile.read()
tempfile.close()
tempdata = thetext.split("\n")[1].split(" ")[9]
temperature = float(tempdata[2:])
temperature = temperature / 1000
return (temperature)
# main() function
def main():
# use sys.argv if needed
baseURL = 'https://api.thingspeak.com/update?api_key=4ASVH9KA1AY2SDB3'
while True:
try:
temper2 = getSensorData()
print (temper2)
if (temper2 > 28) : GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)
if (temper2 <27) : GPIO.output(RELAIS_1_GPIO, GPIO.LOW)
f = urllib.request.urlopen(baseURL + "&field1=%s" % (temper2))
print( f.read())
f.close()
sleep(60)
except:
print( 'exiting.')
break
# call main
if __name__ == '__main__':
main()
Show temp chart from ThingSpeak:
ASPBERRY PI 3 MODEL B 與 1-WIRE DS18B20 之應用
get CPU temprature vcgencmd measure_temp
import pygame
### import RPi.GPIO as GPIO
import time
import datetime
pygame.init()
##### screen = pygame.display.set_mode((640, 480))
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
##clock = pygame.time.Clock()
done = False
while not done:
tFile = open('/sys/class/thermal/thermal_zone0/temp')
temp = float(tFile.read())
tempC = temp/1000
font = pygame.font.SysFont("comicsansms", 48)
text = font.render( "CPU Temp: "+str(tempC), True, (0, 128, 0))
font = pygame.font.SysFont("comicsansms", 96)
text1 = font.render( str(datetime.datetime.now().strftime("%H:%M:%S")), True, (0, 128, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
done = True
screen.fill((255, 255, 255))
screen.blit(text1,
(240 - text1.get_width() // 2, 160 - text1.get_height() // 2 -50))
screen.blit(text,
(240 - text.get_width() // 2, 160 - text.get_height() // 2 + 50))
pygame.display.flip()
####clock.tick(2)
time.sleep(1)
startup.sh 開機時自動執行多個程式 建議使用 crontab來啟動這個程式
#!/bin/bash
cd /home/pi/
/usr/bin/python3 /home/pi/send_ip_line.py
export GOOGLE_APPLICATION_CREDENTIALS="/home/pi/jjlab-speech-send-cc165e9881e4.json"
/usr/bin/python3 /home/pi/mqtt_google_say.py
send_ip_line.py 發送ip至你的LINE
### send ip to line send_ip_line.py
import socket
import requests
import subprocess
import os
#ssid = os.popen("netsh wlan show interfaces").read() # for windows use 取得 ssid
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
#print(s.getsockname()[0])
#ipaddress = os.popen("ifconfig wlan0 \
# | grep 'inet addr' \
# | awk -F: '{print $2}' \
# | awk '{print $1}'").read()
ssid = os.popen("iwconfig wlan0 \
| grep 'ESSID' \
| awk '{print $4}' \
| awk -F\\\" '{print $2}'").read()
# 使用 GET 方式下載普通網頁
message = "你的樹莓派位址是 "+s.getsockname()[0] +"你的ssid是 "+ssid
# 送line訊息給你
my_params = {'token': 'RqFM12eMY4yNPP3PAh8xykKee5cHZXVGZDgMrdddF3Px', 'message': message}
r = requests.get('http://3.114.197.59/test/line_notify.php', params = my_params)
s.close()
print(message)
#print("ssid: " + ssid)
#print("ipaddress: " + ipaddress)
sudo nano /home/pi/.bashrc
echo Running at boot
python3.7 ./jjspeechmqtt.py
sudo crontab -e
@reboot sudo python3 /home/pi/pi-rc522/pirc522/jjrfid.py >> /home/pi/log.txt 2>&1
or
@reboot sleep 20 ; /home/pi/startup.sh
starup.sh
#!/bin/bash
export GOOGLE_APPLICATION_CREDENTIALS="/home/pi/jjlab-speech-send-cc165e9881e4.json"
python3 jjspeechmqtt.py
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be execute
sudo apt-get install python3-pyaudio
pip3 install gcloud
pip3 install google-api-python-client
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
Troubleshooting: If your LEDs only flicker erratically instead of performing a nice demo we need to make some edits to /boot/config.txt, execute:
sudo nano /boot/config.txt
and either uncomment or add the following lines:
hdmi_force_hotplug=1
hdmi_force_edid_audio=1
save, reboot, and reattempt to run strandtest.py as above.
# Simple test for NeoPixels on Raspberry Pi
import time
import board
import neopixel
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
# NeoPixels must be connected to D10, D12, D18 or D21 to work.
pixel_pin = board.D18
# The number of NeoPixels
num_pixels = 8
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False,
pixel_order=ORDER)
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
r = g = b = 0
elif pos < 85:
r = int(pos * 3)
g = int(255 - pos*3)
b = 0
elif pos < 170:
pos -= 85
r = int(255 - pos*3)
g = 0
b = int(pos*3)
else:
pos -= 170
r = 0
g = int(pos*3)
b = int(255 - pos*3)
return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0)
def rainbow_cycle(wait):
for j in range(255):
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + j
pixels[i] = wheel(pixel_index & 255)
pixels.show()
time.sleep(wait)
#while True:
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((255, 0, 0))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((255, 0, 0, 0))
pixels.show()
time.sleep(1)
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((0, 255, 0))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((0, 255, 0, 0))
pixels.show()
time.sleep(1)
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((0, 0, 255))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((0, 0, 255, 0))
pixels.show()
time.sleep(1)
#rainbow_cycle(0.005) # rainbow cycle with 1ms delay per step
# Comment this line out if you have RGBW/GRBW NeoPixels
pixels.fill((0, 0, 0))
# Uncomment this line if you have RGBW/GRBW NeoPixels
# pixels.fill((0, 0, 255, 0))
pixels.show()
sudo raspi-config select Jack or HDMI
cat /proc/asound/cards
sudo nano /etc/modules add
snd-usb-audio
sudo nano .asoundrc
pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}
sudo nano /boot/config.txt
# Enable audio (loads snd_bcm2835)
#dtparam=audio=on 禁能
https://github.com/tuomasjjrasanen/python-uinput
cd /home/pi/py_switch
sudo modprobe uinput
sudo python switch.py
switch.py
import RPi.GPIO as GPIO
import time
import uinput
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
device = uinput.Device([
uinput.KEY_P,
uinput.KEY_N,
uinput.KEY_F5,
uinput.KEY_M,
uinput.KEY_A
])
view = 'm'
while True:
input_state_back = GPIO.input(19)
input_state_forward = GPIO.input(20)
input_state_multi = GPIO.input(21)
if input_state_back == False:
print('Button P Pressed')
device.emit_click(uinput.KEY_P)
time.sleep(0.5)
if input_state_forward == False:
print('Button N Pressed')
device.emit_click(uinput.KEY_N)
time.sleep(0.5)
if input_state_multi == False and input_state_back == False and input_state_forward == False:
print('All buttons pressed')
os.system('sudo reboot')
if input_state_multi == False:
start = time.time()
time.sleep(0.01)
while input_state_multi == False:
time.sleep(0.01)
print('Multibutton is pressed')
end = time.time()
multi_press_time = end-start
input_state_multi = GPIO.input(21)
if input_state_multi == True or multi_press_time > 5.5:
print('Button press in', multi_press_time)
break
if multi_press_time < 5:
if view == 'm':
device.emit_click(uinput.KEY_A)
view = 'a'
print('keypress A')
time.sleep(0.5)
elif view == 'a':
device.emit_click(uinput.KEY_M)
view = 'm'
print('keypress m')
time.sleep(0.5)
else:
print('Keypress: F5')
device.emit_click(uinput.KEY_F5)
time.sleep(0.5)
if input_state_multi == False and input_state_back == False and input_state_forward == False:
print('All buttons pressed')
os.system('sudo reboot')
sudo nano /boot/config.txt
Add the following entry to the end of the file:
dtoverlay=spi-bcm2708
Install the SPI-Py library
git clone https://github.com/lthiery/SPI-Py
cd SPI-Py
sudo python3 setup.py install
Download the pi-rc522 files using
cd ~
git clone https://github.com/ondryaso/pi-rc522.git
cd pi-rc522
sudo python3 setup.py install
The code below shows the steps required to check for a card and read the UID. The UID is made up of a list of 4 values which are printed on a single line.
#!/usr/bin/python3
import sys
sys.path.insert(0, "/home/pi/pi-rc522/ChipReader")
import rfid
import signal
import time
import RPi.GPIO as GPIO
import requests
rdr = rfid.RFID()
util = rdr.util()
util.debug = False
url="http://13.56.153.188/Switch/IOcontrol.php?command=toggle&device=6bDMRXov"
def buzzer():
GPIO.output(ledPin, True)
time.sleep(0.1)
GPIO.output(ledPin, False)
time.sleep(0.1)
GPIO.output(ledPin, True)
time.sleep(0.1)
GPIO.output(ledPin, False)
# Use physical pin numbers
GPIO.setmode(GPIO.BOARD)
# Set up header pin 12 (GPIO18) as an input
ledPin = 12
print ("Setup Pin 12 is OutPut...")
GPIO.setup(ledPin, GPIO.OUT)
while True:
#Request tag
(error, data) = rdr.request()
if not error:
print ("\nDetected")
(error, uid) = rdr.anticoll()
if not error:
#Print UID
print ("Card read UID: "+str(hex(uid[0]).lstrip("0x").rstrip("L"))+
"."+str(hex(uid[1]).lstrip("0x").rstrip("L"))+"."+str(hex(uid[2]).lstrip("0x").rstrip("L"))+
"."+str(hex(uid[3]).lstrip("0x").rstrip("L")))
buzzer()
r = requests.get(url)
time.sleep(1)
Copy the files inside pirc522 into your script's directory, Change the import name from "RFID" to rfid and chage it for the class call also (from "RFID.RFID()" to "rfid.RFID()", Then edit the rfid.py and change the import statement int the util function (at the end of program) from "from .util import RFIDUtil" to "from util import RFIDUtil"
store.txt 及更新的檔案 add to raspberry1(ID).zip
clock.py /home/pi/clock.py 檔案 放置位置
test1.py /home/pi/test1.py
ota.py 檢查更新及下載解壓
import requests
import json
from time import sleep
import tempfile
import datetime
import os
import zipfile
import shutil
import time
##from concurrent.futures import ThreadPoolExecutor
import threading
ID = "raspberry1"
url="http://61.219.106.180/ota/raspberry/"
user = 'jj'
data_file = "Templates/download.zip"
def getfile():
# If the file exists, delete it
if os.path.isfile(data_file):
#os.remove('Templates/*.*')
shutil.rmtree('Templates/')
print('delete file in Temp')
os.mkdir('Templates/')
else:
print('no file in Temp')
#dowlad file
urlfile = url +ID +".zip"
print(urlfile)
r = requests.head(urlfile, allow_redirects=True)
if r.status_code == 200:
print ("file in url , Exists!")
r = requests.get(urlfile)
with open(data_file, "wb") as code:
code.write(r.content)
zip_ref = zipfile.ZipFile(data_file, 'r')
zip_ref.extractall('Templates/')
zip_ref.close()
r = requests.head('http://61.219.106.180/ota/ota_delete.php?delete_file='+ID+'.zip', allow_redirects=True)
print('delete file from url')
os.system('sudo reboot now')
if __name__ == '__main__':
getfile()
ota_boot.py 重新啟動搬移至正確位置
import requests
import json
from time import sleep
import tempfile
import datetime
import os
import zipfile
import shutil
import time
##from concurrent.futures import ThreadPoolExecutor
import threading
ID = "raspberry1"
url="http://61.219.106.180/ota/raspberry/"
user = 'jj'
data_file = "Templates/download.zip"
def move_location():
if os.path.isfile('Templates/store.txt'):
print('open store.txt')
f = open("Templates/store.txt", "r")
for x in f:
str = x.split( )
print(str[0])
shutil.move('Templates/'+str[0], str[1])
f.close()
#os.remove('Templates/*.*')
shutil.rmtree('Templates/')
print('delete file in Temp')
os.mkdir('Templates/')
os.system('sudo chmod 777 Templates')
if __name__ == '__main__':
move_location()
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git cups wiringpi build-essential libcups2-dev libcupsimage2-dev python-serial python-pil python-unidecode system-config-printer
sudo usermod -a -G lpadmin pi
sudo nano /etc/cups/cupsd.conf
修改如下:
Listen your_host_name:631 -----------> Port 631
另外編輯以下區塊
<location>
Order allow,deny
Allow all #add this line
</location>
...
<location admin="">
Order allow,deny
Allow all #add this line
</location>
重新啟動 CUPS server
sudo /etc/init.d/cups restart
接著就可以用打開瀏覽器以 http://192.168.0.xxx:631/ 的形式訪問 CUPS Web interface 了。
lpstat -p
SpliX is a set of CUPS printer drivers for SPL (Samsung Printer Language) printers.
sudo apt-get install printer-driver-splix
cd ~
git clone https://github.com/adafruit/zj-58
cd zj-58
make
sudo ./install
To set up this printer as the system default
sudo lpadmin -p ZJ-58 -E -v serial:/dev/serial0?baud=19200 -m zjiang/ZJ-58.ppd
sudo lpoptions -d ZJ-58
lp -d JJ_printer test.txt
sudo chmod a+rw /dev/usb/lp0
echo "Test Print 測試列印 " > /dev/usb/lp0
Printer Listings
http://www.openprinting.org/printers
https://www.cyut.edu.tw/~ckhung/b/gnu/printing.php
DISPLAY=:0 chromium-browser --kiosk http://61.219.106.180/test/FlipClock/examples/countdown-stop-callback.html
killall -KILL chromium-browse
Raspberry Pi to install MagicMirror²:
bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/raspberry.sh)"
cd MagicMirror/
npm install && npm start
npm start does not work via SSH. But you can use DISPLAY=:0 nohup npm start & instead.
you can use npm start dev which will start MM with Dev Tools enabled
To access toolbar menu when in mirror mode, hit ALT key.
To toggle the (web) Developer Tools from mirror mode, use CTRL-SHIFT-I or ALT and select View.
Ctrl-Q quit
/home/pi/MagicMirror/config/config.js language: "zh-tw" 改為中文
連接天氣,行事曆 config.js
{ module: "calendar", header: "JJ Calendar", position: "top_left", config: { calendars: [ { symbol: "calendar-check", url: "webcal://calendar.google.com/calendar/ical/egls0mo6rpnv3n8s%40group.calendar.google.com/private-90d4c9f3e5bdeabd99d256705ddf7d1e/basic.ics" } ] } }, { module: "compliments", position: "lower_third" }, { module: "currentweather", position: "top_right", config: { location: "Taipei", locationID: "1668341", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city appid: "97e9128e6b88f4cc52ffd8be6a7" } }, { module: "weatherforecast", position: "top_right", header: "未來天氣", config: { location: "台北市", locationID: "1668341", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city appid: "97e9128e6b85f4cc52ffd8be6a7" } },修改 compliments.js
compliments: { anytime: [ "嗨! 有活力哦!!" ], morning: [ "早安你好,迎接美好的一天!!", "祝你有個美好的一天!!", "昨晚睡的還好吧!!" ], afternoon: [ "嗨 好朋友 你好 !!!", "下午來一杯咖啡和點心,休息一下!!", "你看起來精神很好哦!!" ], evening: [ "保持你的熱情與動力 !!", "你看起是如此熱情洋溢 !!", "感覺你真性感!!" ] },新聞推播 config.js
feeds: [ { title: "中央社 重點新聞", url: "http://feeds.feedburner.com/cnaFirstNews?format=xml" }改變顯示字型大小 custom.css
.medium {
font-size: 40px;
line-height: 45px;
}
cd MagicMirror/DISPLAY=:0 nohup npm start &1. (Please note, you will need the x11-xserver-utils package installed.)
sudo apt-get install x11-xserver-utils
edit /etc/xdg/lxsession/LXDE-pi/autostart:
//////////////////////////sudo nano /etc/xdg/lxsession/LXDE-pi/autostart///////
sudo nano .config/lxsession/LXDE-pi/autostart or
sudo nano /etc/xdg/lxsession/LXDE/autostart
Add the following lines:
@xset s noblank
@xset s off
@xset -dpms
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@chromium-browser --kiosk --disable-session-crashed-bubble --disable-infobars http://YOUR WEBSITE URL
2. Edit /etc/lightdm/lightdm.conf: 推薦這種方法
sudo nano /etc/lightdm/lightdm.conf
Add the following line below [SeatDefaults] (Please note, you may need to add the [SeatDefaults] section.)
[SeatDefaults]
xserver-command=X -s 0 -dpms
https://cannotdisplay.com/solved-set-up-a-raspberry-pi-as-a-window-display-kiosk-mode/
sudo apt-get update -y
sudo apt-get install kodi
sudo apt-get install -y kodi-pvr-iptvsimple
sudo apt-get install bluetooth libbluetooth-dev
sudo python3 -m pip install pybluez
hcitool scan 可以掃描附近的藍芽裝置
hciconfig 確認藍牙裝置接收器已被啟動
sudo bluetoothctl 命令行上使用之 Bluetooth control application
scan on 掃描可用藍芽裝置
pair XX:XX:XX:XX:XX:XX 配對裝置
ls /dev/input 顯示已連接之裝置
cat /dev/input/eventX 讓我們使用以下命令從設備中打印出所有傳入數據(將eventX替換為設備代碼)它應該吐出一堆廢碼
sudo pip install evdev
python /usr/local/lib/python2.7/dist-packages/evdev/evtest.py 它用來測試及顯示搖桿的對應碼
python use evdev 抓取藍芽搖桿的動作及碼
#import evdevfrom evdev import InputDevice, categorize, ecodeshttps://atceiling.blogspot.com/2020/03/raspberry-pi-64raspap.html
apt-get install mosquitto
service mosquitto status
https://blog.gtwang.org/iot/raspberry-pi/raspberry-pi-mosquitto-mqtt-broker-iot-integration/
sudo nano /etc/profile
export GOOGLE_APPLICATION_CREDENTIALS="jjlab-speech-send-cc165e9881e4.json" (put this at the end of your file)
(saves the file)
https://www.instructables.com/id/Easy-Raspberry-Pi-Based-ScreensaverSlideshow-for-E/
feh – a fast and light image viewer
sudo apt-get install feh
feh -Y -x -q -D 5 -B black -F -Z -z -r /media/
Here is the explanation of the parameters used in our reference command.
man feh
-Z Auto Zoom
-x Borderless
-F Fullscreen
-Y hide pointer
-B image background
-q quiet no error reporting
-z Randomise
-r Recursive search all folders in folders
-D Slide delay in seconds