树莓派一直每隔30s探测一次温湿度、气体,(不同季节的)温湿度超过正常值范围,树莓派将提示post到服务器端。
每隔30min使用抓图软件获取图像,运行模型后将结果post到服务器端。
#---注释解释器和编码---
#!/bin/bash
# -*- coding:utf-8 -*-
# author:zzz
#-------------------------
#---验证季节确定实验---
#月份数组,和date获取月份匹配
#Shell 数组用括号来表示,元素用"空格"符号分割开
array_month=(Apr May June Jul Aug Sept Oct Nov Dec Jan Feb Mar)
#date命令返回字段2为月份
time=date[2]
for(i=0;${time}!=$array_month[i];i++)
month=i
echo"month is ${month}"
#-------------------------
#---验证获取温湿度结果实验---
python dht11.py 0/1
#dht11.py中,获取tem参数为0,获取hum参数为1
#dht11.py中,sys.argv获取命令行参数
#sys.argv语法使用参考:https://www.runoob.com/python/python-command-line-arguments.html
#0--tem
tem=$?
#1--hum
#hum=$?
#$?仅对上一条指令负责,若无返回值则为0/1--分别表示程序执行成功/失败
#-------------------------
#---温湿度异常报警实验---
#春夏
if [ ${i}<6 ]; then
if [${tem} ]; then
echo "tem error!! tem: ${tem}"
#秋冬
else
if [ ${tem} ]; then
echo "tem error!! tem: ${tem}"
#if条件语句语法参考: https://www.cnblogs.com/kaishirenshi/p/9729800.html
#-------------------------
#-------抓图实验---------
fswebcam /dev/video0 ~/fruit_test.jpg
python /home/pi/Mask_RCNN-master/samples/demo.py
#demo.py中处理图片地址为抓图的保存地址,返回果蔬种类(字符串)
#完整shell中应将此字符串用python处理得到种类、数量再post到服务器端
#此处验证实验将字符串打印显示
echo "$?"
#-------------------------
树莓派开机后台运行shell脚本:
编辑# /etc/rc.local文件,在exit 0之前添加命令/脚本
eg:

附:
shell编写可参考的博客: https://blog.csdn.net/FJJJ8/article/details/84367050
树莓派查看时间(date): https://www.ncnynl.com/archives/201608/765.html
#---------------------------------------------------------------------验证实验过后的初稿01-----------------------------------------------------------------
#---注释解释器和编码---
#!/bin/bash
#-*-coding:utf-8-*-
# author:zzztime=$(date)
#-------------------------
#-------获取时间---------
time=$(date)
echo "${time}"
month_string=$(date "+%m")
echo ${month_string}
#string to number
echo "${month_string}"| awk '{print int($0)}'
month=$?
#-------------------------
#---验证季节确定实验---
# shell $?-> result
if [${month}-le 9]; then
if[${month}-ge 4]; then
echo "hot!"
else
echo "cool!"
fi
else
echo "cool!"
fi
#(shell中对格式十分重视!分分钟给你报错= =)
#-------------------------
#---验证获取温湿度结果实验---


tem=`python dhtl1l.py 0`
echo "${tem}"
mq=`./mq2`
echo "${mq}"
#-------------------------
#---温湿度异常报警实验---
#choosen
if [ ${month} -le 9 ]; then
if [ ${month} -ge 4 ]; then
#hot 8-10
echo "hot!"
else
#cool 4-5
if [ ${tem}-ge 8 ]; then
echo "cool and error"
fi
fi
else
echo "cool!"
fi
(再次BB:格式!)
#-------------------------
#-------抓图实验---------
fswebcam /dev/video0 /home/pi/Desktop/fruit_test.jpg


#-------------------------
浙公网安备 33010602011771号