Step 1: sudo -i Step 2: nano /boot/config.text Step 3: Add this in # Automatically load overlays for detected cameras OR [all] section "dtoverlay=imx519" Step 4: reboot Step 5: execute this command in terminal libcamera-hello
pico w 联网获取网页信息
import network import urequests # set your WiFi Country rp2.country('CN') wlan = network.WLAN(network.STA_IF) wlan.active(True) # set power mode to get WiFi power-saving off (if needed) wlan.config(pm = 0xa11140) wlan.connect('YourHomeSSID', 'YourSSIDPassword') # Make GET request r = urequests.get("http://mixleg.com") print(r.content) r.close()
远程网页控制
#webled.py
import netman
import socket
from machine import Pin
led = Pin("LED", Pin.OUT)
country = 'CN'
ssid = '2312'
password = 'only'
wifi_connection = netman.connectWiFi(ssid,password,country)
html = """<!DOCTYPE html>
<html>
<head> <title>Pico W</title> </head>
<body> <h1>Pico W</h1>
<p>Current status: %s</p>
<p><a href="http://"""+wifi_connection[0]+"""/light/on">Turn ON</a></p>
<p><a href="http://"""+wifi_connection[0]+"""/light/off">Turn OFF</a></p>
<p>by <a href="http://mixdiy.com">mixdiy.com</a></p>
</body>
</html>
"""
# Open socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print('listening on', addr)
# Initialize LED status
led.value(0)
stateis = "LED is OFF"
# Listen for connections
while True:
try:
cl, addr = s.accept()
print('client connected from', addr)
request = cl.recv(1024)
print(request)
request = str(request)[0:50] # The [0:50] avoids getting the url directory from referer
led_status = request.find('GET / HTTP')
led_on = request.find('/light/on')
led_off = request.find('/light/off')
print( 'led on = ' + str(led_on))
print( 'led off = ' + str(led_off))
if led_status >0:
print("LED status request") # No LED action
if led_on >0:
print("led on")
led.value(1)
stateis = "LED is ON"
if led_off >0:
print("led off")
led.value(0)
stateis = "LED is OFF"
response = html % stateis
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
cl.send(response)
cl.close()
except OSError as e:
cl.close()
print('connection closed')
#netman.py
import network, rp2
import time
def connectWiFi(ssid,password,country):
rp2.country(country)
wlan = network.WLAN(network.STA_IF)
wlan.config(pm = 0xa11140)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
status = wlan.ifconfig()
print( 'ip = ' + status[0] )
return status
AP
import socket import network import machine ssid = 'MicroPython-AP' password = '123456789' led = machine.Pin("LED",machine.Pin.OUT) ap = network.WLAN(network.AP_IF) ap.config(essid=ssid, password=password) ap.active(True) while ap.active() == False: pass print('Connection successful') print(ap.ifconfig()) html = """<!DOCTYPE html> <html> <head> <title>Pico W</title> </head> <body> <h1>Pico W</h1> <p>Hello from Pico W.</p> </body> </html> """ addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] s = socket.socket() s.bind(addr) s.listen(1) print('listening on', addr) led.off() # Listen for connections while True: try: cl, addr = s.accept() print('client connected from', addr) request = cl.recv(1024) led.on() print(request) cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') cl.send(html) cl.close() led.off() except OSError as e: cl.close() print('connection closed')
树莓派cron 和 Crontab设置开机定时任务
树莓派默认系统下启动、重启、停止、查询状态的命令
service cron start
service cron restart
service cron stop
service cron status
树莓派默认系统下设置crontab【定时任务】为开机启动和开机不启动
systemctl is-enabled cron.service --- 查看crond是否为开机自启动
systemctl enable cron.service --- 将服务设置为开启启动
systemctl disable cron.service --- 关闭服务开机自启动
树莓派——Cron和Crontab(定时任务)
Cron是Unix系统的一个配置定期任务的工具,用于定期或者以一定的时间间隔执行一些命令或者脚本;可执行的任务范围可以是每天夜里自动备份用户的home文件夹,也可以每个小时记录CPU的信息日志。
crontab(cron table)命令用于编辑执行中的定期任务列表,并且操作是基于每个用户的,每一个用户(包括root用户)都拥有自己的crontab。
EDITING CRONTAB(编辑crontab)
运行crontab和-e选项来编辑cron table:
crontab -e
SELECT AN EDIROR(选择一个编辑器)
第一次运行crontab命令的时候会提示你选择一个编辑器。如果你不确定使用哪一个,你可以直接回车选择默认的nano编辑器。
每一项cron实体的内容都包含六个部分:分钟、小时、月份中的哪一天、年份中的哪一月、星期中的哪一天,还有定时执行的命令。
# m h dom mon dow command # * * * * * command to execute # ┬ ┬ ┬ ┬ ┬ # │ │ │ │ │ # │ │ │ │ │ # │ │ │ │ └───── 星期中的哪一天(0-7)(从0到6代表星期日到星期六,也可以使用名字;7是星期天,等同于0) # │ │ │ └────────── 月份 (1 - 12) # │ │ └─────────────── 月份中的日 (1 - 31) # │ └──────────────────── 小时 (0 - 23) # └───────────────────────── 分钟 (0 - 59)
例如:
0 0 * * * /home/pi/backup.sh
这项cron实例将会在每一天的午夜执行backup.sh脚本。
*/5 * * * * sudo python /home/pi/Downloads/DDNS-master/run.py
这项cron实例将会每5分钟执行run.py脚本。
利用树莓派建立打印共享服务器
利用树莓派建立打印共享服务器
https://zhuanlan.zhihu.com/p/496961274
安装插件
https://developers.hp.com/hp-linux-imaging-and-printing/plugins
Plugins
安装驱动及打印程序
首先更新源并安装Hp的打印机驱动 hplip
$ sudo apt update
$ sudo apt install hplip
然后安装Apple开源的远程打印工具 cups,并配置相应权限
$ sudo apt install cups # Install cups package
$ sudo usermod -aG lpadmin pi # Add user to lpadmin group,pi is your user name
$ sudo cupsctl --remote-any # open remote access
然后使用在同一局域网的电脑,访问 https://树莓派IP:631
连接打印机和树莓派,点击Add Printer添加打印机,在弹出的窗口中输入对应的用户信息,使用在上一步中用户组中添加的用户
然后按着一步步的指引,选择HP LaserJet 1020打印机,然后按照提示,选择和名称对应的驱动,我们会发现 LaserJet 1020 对应驱动会提示:HP laserjet requires proprietary plugin,也就是我们不仅需要这个通用的驱动,而且需要一些额外的插件,打印机才能正常工作。
查阅资料发现:HP官方已经给出了说明,我们需要查看hplip版本,然后安装对应的驱动插件。
首先我们查看一下版本,发现是3.20.3版本
$ sudo apt show hplip
Package: hplip
Version: 3.20.3+dfsg0-2
Priority: optional
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers ubuntu-devel-discuss@lists.ubuntu.com
Original-Maintainer: Debian Printing Team debian-printing@lists.debian.org
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 518 kB
然后在 插件列表 中找到 3.20.3 对应的hplip-3.20.3-plugin.run和hplip-3.20.3-plugin.run.asc,使用wget下载到树莓派本地。
Package: hplip Version: 3.17.10+repack0-5 Priority: optional Section: utils Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian Printing Team <debian-printing@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 1,595 kB Depends: adduser, cups, hplip-data (= 3.17.10+repack0-5), libhpmud0 (= 3.17.10+repack0-5), libsane-hpaio (= 3.17.10+repack0-5), lsb-base, printer-driver-hpcups (= 3.17.10+repack0-5), python3-dbus, python3-gi, python3-pexpect, python3-pil, python3-reportlab, wget, python3 (<< 3.7), xz-utils, python3 (>= 3.6~), libc6 (>= 2.17), libcups2 (>= 1.6.0), libdbus-1-3 (>= 1.9.14), libsane1 (>= 1.0.24) Recommends: avahi-daemon, policykit-1, printer-driver-postscript-hp, sane-utils Suggests: hplip-doc, hplip-gui, python3-notify2, system-config-printer Homepage: https://developers.hp.com/hp-linux-imaging-and-printing Task: ubuntu-desktop, kubuntu-desktop, xubuntu-core, xubuntu-desktop, lubuntu-desktop-share, lubuntu-gtk-desktop, lubuntu-desktop, lubuntu-qt-desktop, ubuntustudio-desktop-core, ubuntustudio-desktop, ubuntukylin-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-budgie-desktop Supported: 5y Download-Size: 1,030 kB APT-Manual-Installed: yes APT-Sources: http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main arm64 Packages Description: HP Linux Printing and Imaging System (HPLIP)
运行 hp-setup -i 使用命令行进行安装,按照提示命令,进行插件的安装。
[scode type=“yellow”]这里建议提前下好安装,而不是直接联网下载,速度较快,指定路径需要为绝对路径[/scode]
至此,我们可以尝试使用手机或者电脑搜索打印机来进行打印测试,没有其他意外的话,可以发现打印成功!
另一种办法
raspberry 4安装HP 1020 plus打印机,利用树莓派4制作无线打印服务器

opencv 3d camera
建立自己的物联网3d打印摄像机系统
安装php扩展extension-xml等
安装Brizy时会出现缺失的安装
extension-xml/extension-zip/extension-curl
sudo apt-get install php7.4-xml
sudo apt-get install php7.4-zip
sudo apt-get install php7.4-curl
为ubuntu添加desktop应用
.Desktop文件
- 为某一应用创建
.desktop
文件
[Desktop Entry]
Name=application_name
Exec=/xxx/xxx/xx.AppImage # 可执行文件,非root权限
Icon=/xxx/xxx/xxx.png #icon path
Type=Application
StartupNotify=true
- 为该
.desktop
添加可执行权限,并移动到/usr/share/applications/
目录下。
sudo chmod +x xxx.desktop
sudo mv xxx.desktop /usr/share/applications/
刷新图标
在我们修改某
.desktop
图标后,发现并没有更新。这是因为系统对这些应用的图标进行了缓存,这时就需要刷新图标缓存。
sudo update-icon-cache /usr/share/icons/*
syncthing同步工具
p2p同步工具
https://www.jianshu.com/p/9e6289478bc8
安装 syncthing
首先需要获取最新版本的下载链接,打开官方 Github 项目的发布页。因为树莓派的 CPU 是 ARM 架构,所以我们需要文件名类似 syncthing-linux-arm-xxxxx.tar.gz 的下载链接,右键复制链接即可。笔者撰写文章时,链接为:https://github.com/syncthing/syncthing/releases/download/v0.14.49-rc.2/syncthing-linux-arm-v0.14.49-rc.2.tar.gz。
接下来通过 SSH 连接到树莓派,并获取文件,命令行如下:
cd ~
wget https://github.com/syncthing/syncthing/releases/download/v0.14.49-rc.2/syncthing-linux-arm-v0.14.49-rc.2.tar.gz
tar -zxvf syncthing-linux-arm-v0.14.49-rc.2.tar.gz
命令执行完成后,文件便下载解压完成了,为了便于操作,我们重命名下文件夹:
mv syncthing-linux-arm-v0.14.49-rc.2 syncthing
chmod +x ~/syncthing/syncthing
部署 syncthing
安装完成后,我们先运行一下:
~/syncthing/syncthing
这时会输出一些提示信息,我们可以等待两分钟让它自行初始化。
接着,我们开始修改配置文件以便局域网访问:
nano ~/.config/syncthing/config.xml
找到如下内容:
<gui enabled="true" tls="false">
<address>127.0.0.1:8384</address>
<apikey>XXXXXX</apikey>
</gui>
将 127.0.0.1:8384 修改为 0.0.0.0:8384,之后 ctrl+o 回车保存,ctrl+x 退出编辑。
开机自启
这里参考了在树莓派上用 Syncthing 自建私有云盘的实现。
树莓派上执行命令:
sudo nano /etc/init.d/syncthing
粘贴如下内容:
#!/bin/sh
### BEGIN INIT INFO
# Provides: Syncthing
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Syncthing
# Description: Syncthing is for backups
### END INIT INFO
# Documentation available at
# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
# Debian provides some extra functions though
. /lib/lsb/init-functions
DAEMON_NAME="syncthing"
DAEMON_USER=pi
DAEMON_PATH="/home/pi/syncthing/syncthing"
DAEMON_OPTS=""
DAEMON_PWD="${PWD}"
DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=0
DAEMON_LOG='/var/log/syncthing'
[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}"
do_start() {
local result
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
if [ $? -eq 0 ]; then
log_warning_msg "${DAEMON_NAME} is already started"
result=0
else
log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
touch "${DAEMON_LOG}"
chown $DAEMON_USER "${DAEMON_LOG}"
chmod u+rw "${DAEMON_LOG}"
if [ -z "${DAEMON_USER}" ]; then
start-stop-daemon --start --quiet --oknodo --background \
--nicelevel $DAEMON_NICE \
--chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$?
else
start-stop-daemon --start --quiet --oknodo --background \
--nicelevel $DAEMON_NICE \
--chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \
--chuid "${DAEMON_USER}" \
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$?
fi
log_end_msg $result
fi
return $result
}
do_stop() {
local result
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
if [ $? -ne 0 ]; then
log_warning_msg "${DAEMON_NAME} is not started"
result=0
else
log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
result=$?
log_end_msg $result
rm "${DAEMON_PID}"
fi
return $result
}
do_restart() {
local result
do_stop
result=$?
if [ $result = 0 ]; then
do_start
result=$?
fi
return $result
}
do_status() {
local result
status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
result=$?
return $result
}
do_usage() {
echo $"Usage: $0 {start | stop | restart | status}"
exit 1
}
case "$1" in
start) do_start; exit $? ;;
stop) do_stop; exit $? ;;
restart) do_restart; exit $? ;;
status) do_status; exit $? ;;
*) do_usage; exit 1 ;;
esac
之后 ctrl+o 回车保存,ctrl+x 退出。执行命令:
#添加执行权限
sudo chmod +x /etc/init.d/syncthing
#添加自启启动
sudo update-rc.d syncthing defaults
现在还可以通过如下命令操作 syncthing:
sudo service syncthing start
sudo service syncthing stop
sudo service syncthing restart
sudo service syncthing status
配置 syncthing
树莓派上运行启动命令:
~/syncthing/syncthing
启动 syncthing 之后,打开 syncthing 的 web 图形界面,地址为:http://树莓派的IP地址:8384,我们可以通过 web 界面进行一些配置。
点击右上角「操作」,选择「设置」,点击第二个标签「图形用户界面」,填写「图形管理界面用户名」及「图形管理界面密码」,之后点击「保存」。
因为我的树莓派是在局域网中使用,所以我关闭了全球发现,打开设置的第三个标签「连接」,取消勾选「全球发现」。
接着为了实现备份的目的,开始配置文件夹,这里我把默认的文件夹移除了,新增了一个文件夹,点击主界面的「添加文件夹」,填入配置。
文件夹路径填写希望保存在树莓派的路径即可。
同步配置
以上完成后,我们就可以开始进行手机端的配置啦。首先在手机上安装 syncthing 客户端。Syncthing 的 Android 客户端开源项目地址给出了在F-Droid的下载链接。
安装完成后,打开应用。初始化之后,同样删除默认文件夹,再点击右上角加号按钮新建一个。
填写完成后,点击右上角勾号保存。
打开树莓派的 syncthing 后台(http://树莓派ip:8384),点击主界面「添加远程设备」,填写设备 ID(在 Android 应用侧边栏显示设备 ID 选项)及设备名。之后打开 Android 应用,滑动侧边栏,打开「网页管理页面」,网页顶端会有个请求添加的提示,点击添加即可,如果没有就手动添加。
至此,就实现了树莓派和手机文件夹同步的功能,不论在手机上拍摄照片,或是修图删除图片,打开 syncthing Android 应用之后,就会自动上传改动到树莓派,保证了两端文件夹的一致。
高阶配置
如果需要实现即使手机上删除了照片,树莓派依旧有存档该如何实现呢?
首先,在 Android 应用中,点击文件夹,勾选「仅发送」。
之后,打开树莓派 web 后台,点击右上角「操作」,选择「高级」,点开「文件夹”xxx”」,勾选「Ignore Delete」即可。
域名生成程序
python 打包工具pyinstaller与Nuitka
Nuitka:Python 打包工具
直接利用pip即可安装:pip install Nuitka
nuitka3 --standalone --show-memory --show-progress --nofollow-imports --plugin-enable=qt-plugins --follow-import-to=utils,src --output-dir=out --windows-icon-from-ico=./logo.ico demo.py
Mac os下安装nuitka
#出错时ModuleNotFoundError: No module named '_tkinter'
brew install python-tk@3.9
[Ubuntu下出错ModuleNotFoundError: No module named 'tkinter'的解决]
sudo apt-get install tcl-dev tk-dev python3-tk
安装nuitka
pip install -U nuitka
xcodebuild -runFirstLaunch
nuitka3 --run gendomain.py
#ModuleNotFoundError: No module named 'lxml'
pip install lxml
nuitka3 --standalone --macos-create-app-bundle gendomain.py
生成程序后从目录中拷贝到需要的位置并将其加入到访达的应用程序中