84 Commits

Author SHA1 Message Date
星光-k
0b7f6c4dfc Update README.md 2025-01-14 09:14:02 +08:00
星光-k
bca24803a5 Update install.sh 2025-01-14 08:10:10 +08:00
星光-k
75528eba1c Update install.sh 2025-01-14 07:54:48 +08:00
星光-k
b159a7a402 Update install.sh 2025-01-14 07:36:03 +08:00
星光-k
c5c7b055e3 Update install.sh 2025-01-14 07:30:06 +08:00
星光-k
69d32309a7 Update install.sh 2025-01-14 07:28:03 +08:00
星光-k
cb89e6cd5c Update install.sh 2025-01-14 07:22:45 +08:00
星光-k
902c237010 Update install.sh 2025-01-14 07:06:03 +08:00
星光-k
20f8a5a181 Update install.sh 2025-01-14 07:03:34 +08:00
星光-k
fa4c0e5a9e Update install.sh 2025-01-14 06:57:24 +08:00
星光-k
c35ec31440 Update main.py 2025-01-14 06:37:01 +08:00
星光-k
9d76efe6ee 更新 clean.py 2025-01-13 21:44:19 +00:00
星光-k
f4752268e8 更新 main.py 2025-01-13 20:32:24 +00:00
星光-k
90ae8aab3d 更新 main.py 2025-01-13 19:51:19 +00:00
星光-k
3a3407c735 更新 main.py 2025-01-13 19:39:31 +00:00
星光-k
a4f140966a 更新 start.sh 2025-01-13 19:10:21 +00:00
星光-k
d0adc8b213 更新 start.sh 2025-01-13 19:04:01 +00:00
星光-k
21f637f1cf 更新 start.sh 2025-01-13 18:54:20 +00:00
星光-k
bebbbc554c 更新 start.sh 2025-01-13 18:46:44 +00:00
星光-k
c8419c2fe8 更新 start.sh 2025-01-13 18:45:30 +00:00
星光-k
9ec0b39b16 更新 start.sh 2025-01-13 18:40:33 +00:00
星光-k
6ec682cb1a 更新 start.sh 2025-01-13 18:40:06 +00:00
星光-k
a9809e68f1 更新 clean.sh 2025-01-13 18:05:33 +00:00
星光-k
67fd8f3c2d 更新 clean.sh 2025-01-13 18:05:03 +00:00
星光-k
e4802e0ee4 更新 clean.sh 2025-01-13 18:04:52 +00:00
星光-k
b3feb79540 更新 start.sh 2025-01-13 17:50:01 +00:00
星光-k
5aed29edac 更新 start.sh 2025-01-13 17:22:29 +00:00
星光-k
ac7c8b2378 更新 install.sh 2025-01-13 17:18:01 +00:00
星光-k
ee5d2bb1ba 更新 start.sh 2025-01-13 16:25:50 +00:00
星光-k
0d849f7a7e 更新 start.sh 2025-01-13 15:24:46 +00:00
星光-k
78f7f9b597 更新 clean.sh 2025-01-13 14:45:09 +00:00
星光-k
4baaf25d44 更新 start.sh 2025-01-13 14:43:04 +00:00
星光-k
a2df4e6162 Update clean.sh 2025-01-13 18:57:49 +08:00
星光-k
f0541b1ee0 更新 clean.sh 2025-01-13 09:16:40 +00:00
星光-k
b30d12742e Update README.md 2025-01-13 16:24:05 +08:00
星光-k
aae214de87 Update install.sh 2025-01-13 16:22:23 +08:00
星光-k
34d2ea6840 Update install.sh 2025-01-13 16:06:41 +08:00
星光-k
df98d198d0 Update install.sh 2025-01-13 16:04:12 +08:00
星光-k
d6d86a0424 Update install.sh 2025-01-13 16:01:10 +08:00
星光-k
d32459ce9d Update install.sh 2025-01-13 15:51:08 +08:00
星光-k
6b5b8a935a Update install.sh 2025-01-13 15:49:39 +08:00
星光-k
0db4d98671 Update install.sh 2025-01-13 15:48:42 +08:00
星光-k
6bf064e941 Update README.md 2025-01-13 15:42:03 +08:00
星光-k
1ae2f31142 Update install.sh 2025-01-13 15:40:15 +08:00
星光-k
380bea6607 Update install.sh 2025-01-13 15:36:55 +08:00
星光-k
964811eac8 Update install.sh 2025-01-13 15:32:18 +08:00
星光-k
e2fb9777b1 Update install.sh 2025-01-13 15:28:37 +08:00
星光-k
50fba1dde9 Update README.md 2025-01-13 15:25:33 +08:00
星光-k
1be53da061 Update install.sh 2025-01-13 15:23:19 +08:00
星光-k
8d40fcd1b4 Update install.sh 2025-01-13 15:10:51 +08:00
星光-k
b7fbbcfe8f Update install.sh 2025-01-13 15:07:49 +08:00
星光-k
ba8b4894a5 Update install.sh 2025-01-13 15:06:56 +08:00
星光-k
e34c22c1be Update README.md 2025-01-13 14:57:05 +08:00
星光-k
67799d0038 Update README.md 2025-01-13 14:56:29 +08:00
星光-k
0fbbaa5bef Update README.md 2025-01-13 14:39:26 +08:00
星光-k
0f91590755 Update main.py 2025-01-13 14:33:25 +08:00
星光-k
2a93811d2f Update README.md 2025-01-13 14:22:46 +08:00
星光-k
8a4cce18f1 Add files via upload 2025-01-13 06:22:04 +00:00
星光-k
9f31dd8677 Delete pic/1736672578025.jpg 2025-01-13 14:21:29 +08:00
星光-k
20743401ae Update README.md 2025-01-13 14:20:05 +08:00
星光-k
050d3ca8a6 Update README.md 2025-01-13 14:18:12 +08:00
星光-k
3be8e7e63a Update install.sh 2025-01-13 14:08:06 +08:00
星光-k
b688062ca4 Update main.py 2025-01-13 02:30:00 +08:00
星光-k
d63d12de38 Update README.md 2025-01-12 21:41:51 +08:00
星光-k
9ef97ab7a2 Update install.sh 2025-01-12 21:32:30 +08:00
星光-k
6651491941 Update install.sh 2025-01-12 21:24:22 +08:00
星光-k
d498dad18f Update install.sh 2025-01-12 21:07:11 +08:00
星光-k
2bd8dc0bc6 Update install.sh 2025-01-12 21:04:03 +08:00
星光-k
7873004d74 Update install.sh 2025-01-12 20:57:55 +08:00
星光-k
a5eec2e9a3 Update install.sh 2025-01-12 20:26:49 +08:00
星光-k
a8059bac56 Update README.md 2025-01-12 17:06:41 +08:00
星光-k
a80e3a2722 Update README.md 2025-01-12 17:06:05 +08:00
星光-k
c60fccb210 Update README.md 2025-01-12 17:05:24 +08:00
星光-k
53e1845ce4 Update README.md 2025-01-12 17:04:29 +08:00
星光-k
3844f71943 Add files via upload 2025-01-12 09:03:30 +00:00
星光-k
b2336dcbfb Update clean.sh 2025-01-12 16:52:01 +08:00
星光-k
5a976157c2 Rename clean-info.log to info-clean.log 2025-01-12 16:42:51 +08:00
星光-k
b6866ee2b9 Update clean.sh 2025-01-12 16:39:55 +08:00
星光-k
32565ef2f5 Update clean.sh 2025-01-12 16:36:58 +08:00
星光-k
0c4282ebc9 Update start.sh 2025-01-12 16:33:04 +08:00
星光-k
f8b2c1b332 Update install.sh 2025-01-12 16:25:59 +08:00
星光-k
5b5dace7d3 Update install.sh 2025-01-12 16:22:08 +08:00
星光-k
04ab97f5b6 Update clean.sh 2025-01-12 16:21:45 +08:00
星光-k
0565fd6cf5 Update start.sh 2025-01-12 16:18:33 +08:00
8 changed files with 145 additions and 74 deletions

View File

@@ -26,9 +26,7 @@
https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series#rtc-on-board
https://www.pisugar.com/
ps:如果没有使用此模块则需要更改代码内容,以避免运行出错。
以上可能python脚本已解决
ps:代码里需要nc命令需要安装netcat安装内容已集成到“[需要安装的软件和依赖](https://github.com/kxgx/2.13-Ink-screen-clock#%E9%9C%80%E8%A6%81%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%92%8C%E4%BE%9D%E8%B5%96)"
@@ -59,28 +57,36 @@ sudo reboot
![image](https://www.waveshare.net/w/upload/a/a0/RPI_open_spi_2.jpg)
#### wifi连接管理
可以使用[PiSugar/sugar-wifi-conf:让树莓派提供蓝牙BLE服务使用小程序可以随时更改树莓派的wifi连接
](https://github.com/PiSugar/PiSugar/wiki/PiSugar-WiFi-config#sugar-wifi-conf)
## 使用脚本直接安装(推荐)
### 参数定义
```Bash
--zh 设置系统语言为zh_CN,UTF-8
--cn 替换apt镜像源为中国镜像源
--debug 输出详细信息
--zh 设置系统语言为zh_CN,UTF-8
--cn 替换apt镜像源为中国镜像源
--gitcn 克隆中国仓库
--pisugar-wifi-conf 安装pisugar-wifi-conf
--pisugar-power-manager 安装pisugar-power-manager
--version <tag> 版本号
--debug 输出详细信息
```
###
```Bash
#国源默认设置
#国源默认设置
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
```
```Bash
#国内源--cn设置
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn
#中国源全参数设置(不使用--debug参数)
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --version <tag> --zh --cn --gitcn --pisugar-power-manager --pisugar-wifi-conf
```
```Bash
#默认源默认设置
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
```
```Bash
#默认源--cn设置
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn
#默认源全参数设置(不使用--debug参数)
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --version <tag> --zh --cn --gitcn --pisugar-power-manager --pisugar-wifi-conf
```
## 需要安装的软件和依赖:
@@ -89,27 +95,25 @@ curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh
PiSugar 3官方文档 https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series#software-installation
```Bash
sudo apt-get update
sudo apt install -y git
sudo apt-get install -y netcat*
sudo apt-get install -y python3-pip
sudo apt-get install -y python3-pil
sudo apt-get install -y python3-numpy
sudo apt install -y python3-gpiozero
sudo pip3 install spidev borax pillow requests --break-system-packages
sudo apt-get install -y git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential
sudo pip3 install spidev borax pillow requests
wget https://cdn.pisugar.com/release/pisugar-power-manager.sh
bash pisugar-power-manager.sh -c release
```
#### 傻瓜式安装命令和执行启动文件:
#### 安装命令和执行启动文件组合命令
```Bash
sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python3-pip && sudo apt-get install -y python3-pil && sudo apt-get install -y python3-numpy && sudo apt install -y python3-gpiozero && sudo apt-get install -y netcat* && sudo pip3 install spidev borax pillow requests --break-system-packages && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://github.com/kxgx/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh
sudo apt-get update && sudo apt-get install -y git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential && sudo pip3 install spidev borax pillow requests && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://github.com/kxgx/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh
```
##### 使用国内仓库:
```Bash
sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python3-pip && sudo apt-get install -y python3-pil && sudo apt-get install -y python3-numpy && sudo apt install -y python3-gpiozero && sudo apt-get install -y netcat* && sudo pip3 install spidev borax pillow requests --break-system-packages && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://gitee.com/xingguangk/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh
sudo apt-get update && sudo apt-get install -y git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential && sudo pip3 install spidev borax pillow requests && sudo pip3 install spidev borax pillow requests --break-system-packages && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://gitee.com/xingguangk/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh
```
###### 注意
```Bash
# 如果使用的是非lite系统请在pip3安装部分添加
--break-system-packages
```
总体采用局刷方案,程序运行后一直处于程序的获取新数据的过程中,当发现数据变化后即开始自动局刷。
特别注意:
在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据
![image](https://raw.githubusercontent.com/huanglinsd/2.13-Ink-screen-clock/main/pic/IMG_1245.JPG)
# 效果展示
总体采用局刷方案,程序运行后一直处于程序的获取新数据的过程中,当发现数据变化后即开始自动局刷。
![image](https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/pic/1736749257603.jpg)

View File

@@ -34,7 +34,7 @@ def clear_screen():
epd.Clear(0xFF)
# 等待一段时间,确保清除操作完成
time.sleep(1)
#time.sleep(1)
# 将屏幕置于睡眠模式
logging.info("Putting e-Paper display to sleep")

View File

@@ -5,10 +5,10 @@ dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir=${dir%/*}
screen_name="clean_screen"
service_name="raspi_e-Paper.service"
hold_time_seconds=3 # 设置维持时间例如300秒5分钟
hold_time_seconds=10 # 设置维持时间例如300秒5分钟
# 创建一个新的screen会话并运行Python脚本
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/clean-info.log 2>&1
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name 2>&1
# 等待维持时间
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
@@ -24,4 +24,4 @@ for pid in $pids; do
screen -S $pid -X quit
done
echo "脚本运行完成服务已停止screen会话已结束"
echo "脚本运行完成服务已停止screen会话已结束"

View File

@@ -12,6 +12,12 @@ DEFAULT_LANG="en_US.UTF-8"
USE_CN_MIRROR=false
# 控制调试输出
DEBUG=false
# 检查是否使用中国git仓库
USE_CN_GIT=false
# 检查是否安装pisugar-wifi-conf
USE_PISUGAR_WIFI_CONF=false
# 检查是否安装pisugar-power-manager
USE_PISUGAR_POWER_MANAGER=false
# 解析命令行参数
while [ "$#" -gt 0 ]; do
@@ -22,6 +28,23 @@ while [ "$#" -gt 0 ]; do
--cn)
USE_CN_MIRROR=true
;;
--gitcn)
USE_CN_GIT=true
;;
--pisugar-wifi-conf)
USE_PISUGAR_WIFI_CONF=true
;;
--pisugar-power-manager)
USE_PISUGAR_POWER_MANAGER=true
;;
--version)
if [ -z "$2" ]; then
echo "错误: --version 参数后需要跟版本号"
exit 1
fi
VERSION="$2" # 将版本号赋值给变量 VERSION
shift 2 # 移动参数,跳过版本号参数及其值
;;
--debug)
DEBUG=true
;;
@@ -101,8 +124,8 @@ is_raspberry_pi() {
# 定义链接变量
DEBIAN_MIRROR="http://deb.debian.org/debian/"
DEBIAN_SECURITY_MIRROR="http://security.debian.org/"
PI_SUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock.git"
PISUGAR_WIFI_CONF_URL="https://cdn.pisugar.com/PiSugar-wificonfig/script/install.sh"
PISUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
PIPY_MIRROR="https://pypi.org/simple"
# 修改 Raspberry Pi 特定源链接
RASPBERRY_PI_SOURCE_DEBIAN11="https://archive.raspberrypi.org/debian/"
@@ -112,13 +135,19 @@ RASPBERRY_PI_SOURCE_DEBIAN12="https://archive.raspberrypi.com/debian/"
if [ "$USE_CN_MIRROR" = true ]; then
DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian/"
DEBIAN_SECURITY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian-security"
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock.git"
PIPY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
# 使用中国镜像源时Raspberry Pi 特定源链接保持不变
RASPBERRY_PI_SOURCE_DEBIAN11="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"
RASPBERRY_PI_SOURCE_DEBIAN12="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"
fi
# 定义仓库链接变量
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock"
# 如果使用中国仓库,则更新链接变量
if [ "$USE_CN_GIT" = true ]; then
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock"
fi
# 更新源列表函数
update_sources_list() {
local version=$1
@@ -171,15 +200,13 @@ update_sources_list() {
# 安装包函数
install_packages() {
if ! sudo apt-get update; then
echo "正在更新源列表"
if ! sudo apt-get -q -y update; then
echo "更新源列表失败" >&2
exit 1
fi
if ! sudo apt-get upgrade -y; then
echo "系统更新失败" >&2
exit 1
fi
if ! sudo apt-get install -y git pigpio raspi-config netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
echo "正在安装软件包"
if ! sudo apt-get -q -y install git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
echo "软件包安装失败" >&2
exit 1
fi
@@ -187,8 +214,10 @@ install_packages() {
# 安装pip包函数
install_pip_packages() {
if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests --break-system-packages; then
echo "pip软件包安装包失败" >&2
echo "正在安装pip软件包"
if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests; then
echo "pip软件包安装失败如果是最新版系统或是非lite系统" >&2
echo "请手动运行sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests --break-system-packages" >&2
exit 1
fi
}
@@ -202,22 +231,24 @@ setup_service() {
# 检查墨水屏时钟仓库是否存在
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then
echo "正在克隆仓库"
cd ~
if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then
echo "克隆墨水屏时钟仓库失败" >&2
if ! git clone -b $VERSION $INK_SCREEN_CLOCK_REPO_URL; then
echo "克隆仓库失败" >&2
exit 1
fi
# 设置start.sh和clean.sh脚本的执行权限
chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
else
echo "墨水屏时钟仓库文件夹已存在,跳过克隆"
echo "仓库文件夹已存在,跳过克隆"
fi
# 检查服务文件是否存在
if [ -f "$service_file_path" ] && [ -f "$service1_file_path" ]; then
# 检查服务是否已经启用
if ! systemctl is-enabled $service_path &>/dev/null && ! systemctl is-enabled $service1_path &>/dev/null; then
echo "正在复制服务文件并启用服务"
# 复制服务文件到 systemd 目录
if sudo cp "$service_file_path" /etc/systemd/system/ && sudo cp "$service1_file_path" /etc/systemd/system/; then
# 重载 systemd 管理器配置
@@ -239,10 +270,34 @@ setup_service() {
fi
}
# 安装pisugar-power-manager函数
install_pisugar-power-manager() {
if [ "$USE_PISUGAR_POWER_MANAGER" = true ]; then
echo "正在安装pisugar-power-manager"
if ! curl -sSL "$PISUGAR_POWER_MANAGER_URL" | sudo bash -s - -c release; then
echo "pisugar-power-manager安装失败" >&2
echo "如需要请手动运行curl -sSL $PISUGAR_POWER_MANAGER_URL | sudo bash -s - -c release" >&2
exit 1
fi
fi
}
# 安装pisugar-wifi-conf函数
install_pisugar-wifi-conf() {
if [ "$USE_PISUGAR_WIFI_CONF" = true ]; then
echo "正在安装pisugar-wifi-conf"
if ! curl -sSL "$PISUGAR_WIFI_CONF_URL" | sudo bash; then
echo "pisugar-wifi-conf安装失败" >&2
echo "如需要请手动运行curl $PISUGAR_WIFI_CONF_URL | sudo bash" >&2
exit 1
fi
fi
}
# 主逻辑
# 检测是否是Debian系统
if [ -f /etc/debian_version ]; then
echo "检测到Debian$DEBIAN_VERSION系统"
echo "检测到Debian$DEBIAN_VERSION系统"
# 提取版本号的小数点前的部分
if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then
@@ -262,6 +317,8 @@ if [ -f /etc/debian_version ]; then
install_packages
install_pip_packages
setup_service
install_pisugar-wifi-conf
install_pisugar-power-manager
;;
12)
echo "执行Debian 12 (Bookworm) 相关操作"
@@ -269,6 +326,8 @@ if [ -f /etc/debian_version ]; then
install_packages
install_pip_packages
setup_service
install_pisugar-wifi-conf
install_pisugar-power-manager
;;
*)
echo "未知的Debian版本: $MAJOR_VERSION" >&2

View File

@@ -66,25 +66,8 @@ def Memory_footprint():#显示内存占用百分比
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
def CPU_usage(): #显示CPU占用百分比
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
def power_battery():
try:
# 获取电池电量
battery_percentage = subprocess.check_output(
"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'",
shell=True,
text=True
).strip()
# 检查电量信息
if not battery_percentage:
return "无效"
# 返回电量百分比
return f"{int(battery_percentage)}%"
except Exception as e:
# 返回错误信息
return "失败"
def power_battery():#获取当前电池电量
return(str(int(subprocess.check_output(u"echo \"get battery\" | nc -q 0 127.0.0.1 8423|awk -F':' '{print int($2)}'", shell = True ).decode('gbk')))+u'%')
# 打印电量信息
print(power_battery())
def Bottom_edge(): #在图片中添加底边内容
@@ -252,7 +235,7 @@ try:
getWeath()#天气获取函数开始运行
epd = epd2in13_V4.EPD() #初始化
epd.init()#设定屏幕刷新模式
epd.Clear(0xFF) #清除屏幕内容
#epd.Clear(0xFF) #清除屏幕内容
##################屏幕初始化#########################
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
logging.info("Initialize and clear the display")#屏幕开始准备相关展示
@@ -261,7 +244,7 @@ try:
Basic_refresh() #全局刷新
Partial_refresh() #局部刷新
epd.init()
#epd.Clear(0xFF)
epd.Clear(0xFF)
epd.sleep()
except IOError as e:
logging.info(e)
@@ -279,11 +262,11 @@ except Exception as e:
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()
#exit()
# 脚本正常结束后的清理操作
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()
#exit()

View File

@@ -1,15 +1,40 @@
#!/bin/bash
# 脚本文件名
f_name=main.py
# 获取脚本所在目录的路径
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# 日志目录,假设是脚本所在目录的上一级目录
logdir=${dir%/*}
# screen会话名称
screen_name="main_screen"
# 查找并结束所有与指定screen_name相关的screen会话
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}')
for pid in $pids; do
screen -S $pid -X quit
done
# 函数用于启动Python脚本
start_script() {
# 创建一个新的screen会话并运行Python脚本
# 输出重定向到日志文件
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name 2>&1
}
# 创建一个新的screen会话并运行Python脚本
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1
# 无限循环,直到脚本被手动停止
while true; do
# 检查是否有与指定screen_name相关的screen会话正在运行
existing_sessions=$(screen -ls | grep -w $screen_name)
# 如果找到正在运行的screen会话则结束它们
if [ -n "$existing_sessions" ]; then
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}')
for pid in $pids; do
screen -S $pid -X quit
done
fi
# 启动Python脚本
start_script
# 等待一段时间,检查脚本是否还在运行
sleep 180
if ! screen -list | grep -q $screen_name; then
echo "脚本意外停止。正在重启..."
fi
done

BIN
pic/1736749257603.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 MiB