From 6541e34ab55908780a9bc4c0a6f9e4bfc1a4b341 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Fri, 5 Jan 2024 16:39:44 +0800 Subject: [PATCH] update --- close_blue_led.py | 18 ++++++++++++++++++ conf/example/bash/cron_set.sh | 7 +++++++ .../bash/start_dataupload_internal_one_hour.sh | 2 ++ .../bash/stop_dataupload_internal_one_hour.sh | 2 ++ conf/example/cron_for_dataupload.conf | 2 ++ cron_set.sh | 8 -------- open_blue_led.py | 18 ++++++++++++++++++ sensor_to_local.py | 4 ++++ sensor_to_server.py | 3 +++ 9 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 close_blue_led.py create mode 100644 conf/example/bash/cron_set.sh create mode 100644 conf/example/bash/start_dataupload_internal_one_hour.sh create mode 100644 conf/example/bash/stop_dataupload_internal_one_hour.sh create mode 100644 conf/example/cron_for_dataupload.conf delete mode 100644 cron_set.sh create mode 100644 open_blue_led.py diff --git a/close_blue_led.py b/close_blue_led.py new file mode 100644 index 0000000..e83d03a --- /dev/null +++ b/close_blue_led.py @@ -0,0 +1,18 @@ +''' +实验名称:熄灭第1个LED +实验平台:核桃派 +''' + +# 导入相关模块 +import board +from digitalio import DigitalInOut, Direction + +if __name__ == '__main__': + + try: + # 构建LED对象和初始化 + led = DigitalInOut(board.LED) # 定义引脚编号 + led.direction = Direction.OUTPUT # IO为输出 + led.value = 0 # 输出低电平,熄灭板载LED蓝灯 + except Exception as e: + pass diff --git a/conf/example/bash/cron_set.sh b/conf/example/bash/cron_set.sh new file mode 100644 index 0000000..fa397c2 --- /dev/null +++ b/conf/example/bash/cron_set.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +sudo crontab -l > cron.cron +echo "*/1 * * * * /usr/bin/bash /home/pi/lot_manager/conf/example/bash/start_dataupload_internal_one_hour.sh" >> cron.cron +sudo crontab cron.cron +sudo systemctl restart cron.service +sudo rm -rf cron.cron \ No newline at end of file diff --git a/conf/example/bash/start_dataupload_internal_one_hour.sh b/conf/example/bash/start_dataupload_internal_one_hour.sh new file mode 100644 index 0000000..9b5b4b4 --- /dev/null +++ b/conf/example/bash/start_dataupload_internal_one_hour.sh @@ -0,0 +1,2 @@ +#!/bin/bash +supervisorctl restart data_upload \ No newline at end of file diff --git a/conf/example/bash/stop_dataupload_internal_one_hour.sh b/conf/example/bash/stop_dataupload_internal_one_hour.sh new file mode 100644 index 0000000..8b2e79a --- /dev/null +++ b/conf/example/bash/stop_dataupload_internal_one_hour.sh @@ -0,0 +1,2 @@ +#!/bin/bash +supervisorctl stop data_upload \ No newline at end of file diff --git a/conf/example/cron_for_dataupload.conf b/conf/example/cron_for_dataupload.conf new file mode 100644 index 0000000..c9744d3 --- /dev/null +++ b/conf/example/cron_for_dataupload.conf @@ -0,0 +1,2 @@ +# 每隔一分钟执行一次任务 +*/1 * * * * /usr/bin/bash /home/pi/lot_manager/conf/example/bash/start_dataupload_internal_one_hour.sh \ No newline at end of file diff --git a/cron_set.sh b/cron_set.sh deleted file mode 100644 index c45c58c..0000000 --- a/cron_set.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e -sudo crontab -l > cron.cron -echo "0 9 * * * sudo /usr/bin/python /home/pi/lot_manager/open_led.py" >> cron.cron -echo "0 17 * * * sudo /usr/bin/python /home/pi/lot_manager/close_led.py" >> cron.cron -sudo crontab cron.cron -sudo systemctl restart cron.service -sudo rm -rf cron.cron \ No newline at end of file diff --git a/open_blue_led.py b/open_blue_led.py new file mode 100644 index 0000000..a49b419 --- /dev/null +++ b/open_blue_led.py @@ -0,0 +1,18 @@ +''' +实验名称:熄灭第1个LED +实验平台:核桃派 +''' + +# 导入相关模块 +import board +from digitalio import DigitalInOut, Direction + +if __name__ == '__main__': + + try: + # 构建LED对象和初始化 + led = DigitalInOut(board.LED) # 定义引脚编号 + led.direction = Direction.OUTPUT # IO为输出 + led.value = 1 # 输出高电平,点亮板载LED蓝灯 + except Exception as e: + pass diff --git a/sensor_to_local.py b/sensor_to_local.py index 91fd0a0..56bb999 100755 --- a/sensor_to_local.py +++ b/sensor_to_local.py @@ -1,4 +1,5 @@ import os +import subprocess import time import serial @@ -190,6 +191,9 @@ def local(): } t = LOT_DATA(**data) add(t) + subprocess.Popen( + ["/usr/bin/bash /home/pi/lot_manager/conf/example/bash/stop_dataupload_internal_one_hour.sh"], + shell=True) except Exception as e: # print(e) pass diff --git a/sensor_to_server.py b/sensor_to_server.py index 3a27c29..e31999f 100755 --- a/sensor_to_server.py +++ b/sensor_to_server.py @@ -195,6 +195,9 @@ def get_data(): t2 = LOT_DATA(**data) client.publish(publish_topic, payload=json.dumps(data, ensure_ascii=False), qos=0) add(t2) + subprocess.Popen( + ["/usr/bin/bash /home/pi/lot_manager/conf/example/bash/stop_dataupload_internal_one_hour.sh"], + shell=True) except Exception as e: # print(e) pass