20180129
This commit is contained in:
parent
28c5a00d19
commit
b9d3dfe2c2
@ -1,4 +1,9 @@
|
|||||||
# raspberrypi
|
# raspberrypi
|
||||||
|
|
||||||
raspberrypi_zero GPIO 实现的智能家居
|
raspberrypi zero w GPIO 实现的智能家居
|
||||||
- 根据 http://shumeipai.nxez.com/2016/06/26/raspberry-pi-diy-with-a-smart-home-server.html
|
- 参考:http://shumeipai.nxez.com/2016/06/26/raspberry-pi-diy-with-a-smart-home-server.html
|
||||||
|
|
||||||
|
- 我发现传感器的数据是实时的,传感器的工作必须是实时的
|
||||||
|
- 有时做不到数据的准确
|
||||||
|
- 就做了多进程的shell(不同pid)来满足传感器数据现状,一个进程收集传感器数据,另一个进程处理.
|
||||||
|
_
|
||||||
|
BIN
raspberrypi_zero/gpio/.info.sh.swp
Normal file
BIN
raspberrypi_zero/gpio/.info.sh.swp
Normal file
Binary file not shown.
@ -18,12 +18,17 @@ function DATE()
|
|||||||
S=$(date "+%S");
|
S=$(date "+%S");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SLEEP()
|
||||||
|
{
|
||||||
|
sleep $@
|
||||||
|
}
|
||||||
|
|
||||||
function get18b20data()
|
function get18b20data()
|
||||||
{
|
{
|
||||||
MODEL="28-04174019f0ff";
|
MODEL="28-04174019f0ff";
|
||||||
if test -d "/sys/devices/w1_bus_master1/${MODEL}"; then
|
if test -d "/sys/devices/w1_bus_master1/${MODEL}"; then
|
||||||
temperature=$(cat /sys/devices/w1_bus_master1/28-04174019f0ff/w1_slave | grep 't=' | sed 's/^.*t=//g' | awk '{print $1/1000}');
|
temperature=$(cat /sys/devices/w1_bus_master1/28-04174019f0ff/w1_slave | grep 't=' | sed 's/^.*t=//g' | awk '{print $1/1000}');
|
||||||
echo $y年$m月$d日$H时$M分$S秒
|
#echo $y年$m月$d日$H时$M分$S秒
|
||||||
echo -ne "当前室内温度: ";
|
echo -ne "当前室内温度: ";
|
||||||
echo -e "\e[1;31m${temperature}℃ \e[0m";
|
echo -e "\e[1;31m${temperature}℃ \e[0m";
|
||||||
else
|
else
|
||||||
@ -46,20 +51,23 @@ function lightinfo()
|
|||||||
bindir="/root/gpio"
|
bindir="/root/gpio"
|
||||||
! test -d ${bindir} && exit 1;
|
! test -d ${bindir} && exit 1;
|
||||||
#时间范围
|
#时间范围
|
||||||
high="1900";
|
high="1500";
|
||||||
low="2400";
|
low="2400";
|
||||||
|
|
||||||
#当前时间
|
#当前时间
|
||||||
now=$(date +%H%M);
|
now=$(date +%H%M);
|
||||||
bcm_lightpin="21";
|
bcm_lightpin="20";
|
||||||
wiringpi_lightpin="29";
|
wiringpi_lightpin="28";
|
||||||
#wiringpi_infrared="20";
|
|
||||||
|
wiringpi_infrared="6";
|
||||||
|
|
||||||
#判断手机是否在线
|
#判断手机是否在线
|
||||||
phoneip="192.168.137.27";
|
#phoneip="192.168.137.27";
|
||||||
phonelogic="$(ping ${phoneip} -c 1 -S 1 &> /dev/null; echo $?)";
|
#phonelogic="$(ping ${phoneip} -c 1 -S 1 &> /dev/null; echo $?)";
|
||||||
|
|
||||||
#判断人体红外线传感器
|
#判断人体红外线传感器
|
||||||
infrared=$(${bindir}/info_infrared ${wiringpi_infrared});
|
#infrared=$(${bindir}/info_infrared ${wiringpi_infrared});
|
||||||
|
infrared=$(cat ${bindir}/infrared.log 2> /dev/null);
|
||||||
|
|
||||||
#距离传感器
|
#距离传感器
|
||||||
l="60";
|
l="60";
|
||||||
@ -78,20 +86,31 @@ function lightinfo()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DATE;
|
#DATE;
|
||||||
#getcpudata;
|
#getcpudata;
|
||||||
#get18b20data >> ~/temperature.txt;
|
#get18b20data >> ~/temperature.txt;
|
||||||
lightinfo;
|
lightinfo;
|
||||||
|
|
||||||
|
|
||||||
|
function WHILE()
|
||||||
|
{
|
||||||
|
while true; do
|
||||||
|
${bindir}/info_infrared ${wiringpi_infrared} > infrared.log
|
||||||
|
SLEEP 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
function main_()
|
function main_()
|
||||||
{
|
{
|
||||||
while true; do
|
while true; do
|
||||||
if [ "${now}" -ge "${high}" -a "${now}" -le "${low}" ]; then #检测时间段
|
if [ "${now}" -ge "${high}" -a "${now}" -le "${low}" ]; then #检测时间段
|
||||||
if [ "${phonelogic}" == "0" ]; then #检测手机IP
|
#if [ "${phonelogic}" == "0" ]; then #检测手机IP
|
||||||
#if [ "${infrared}" = "1" ]; then #检测人体红外线
|
#echo ${infrared}
|
||||||
|
if [ "${infrared}" = "1" ]; then #检测人体红外线
|
||||||
#if [ "${distance}" -ge ${l} -a "${distance}" -le ${s} ]; then #检测距离范围
|
#if [ "${distance}" -ge ${l} -a "${distance}" -le ${s} ]; then #检测距离范围
|
||||||
if test "${lightpinvalue}" = "0"; then #检测灯pin值
|
if test "${lightpinvalue}" = "0"; then #检测灯pin值
|
||||||
${start_light};
|
${start_light};
|
||||||
|
SLEEP 9;
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if test "${lightpinvalue}" = "1"; then #如果开着就关闭
|
if test "${lightpinvalue}" = "1"; then #如果开着就关闭
|
||||||
@ -104,20 +123,47 @@ while true; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
lightinfo; #再次获取信息
|
lightinfo; #再次获取信息
|
||||||
sleep 7; #睡眠
|
SLEEP 1; #睡眠
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts :d pi
|
while getopts :ds: pi
|
||||||
do
|
do
|
||||||
case ${pi} in
|
case ${pi} in
|
||||||
d)
|
d)
|
||||||
daemon='&';
|
daemon='&';
|
||||||
;;
|
;;
|
||||||
|
s)
|
||||||
|
case $OPTARG in
|
||||||
|
"stop")
|
||||||
|
array=$(ls ${bindir}/log/)
|
||||||
|
for arr in ${array[@]}; do
|
||||||
|
kill $(cat ${bindir}/log/${arr})
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
:
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
h|?)
|
h|?)
|
||||||
:
|
echo "
|
||||||
|
raspberrypi zero w 智能灯控
|
||||||
|
$0 Usage: $0 [-?|h] [-d] [-s]
|
||||||
|
-d Daemon.
|
||||||
|
-s kill Daemon, signal: stop.
|
||||||
|
|
||||||
|
by aixiao.
|
||||||
|
"
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
WHILE &
|
||||||
|
WHILEID="$(echo $!)"
|
||||||
|
echo ${WHILEID} > log/infrared.pid 2> /dev/null
|
||||||
eval main_ ${daemon}
|
eval main_ ${daemon}
|
||||||
|
echo $! > log/main.pid 2> /dev/null
|
||||||
|
1
raspberrypi_zero/gpio/infrared.log
Normal file
1
raspberrypi_zero/gpio/infrared.log
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
1
raspberrypi_zero/gpio/log/infrared.pid
Normal file
1
raspberrypi_zero/gpio/log/infrared.pid
Normal file
@ -0,0 +1 @@
|
|||||||
|
14389
|
1
raspberrypi_zero/gpio/log/main.pid
Normal file
1
raspberrypi_zero/gpio/log/main.pid
Normal file
@ -0,0 +1 @@
|
|||||||
|
14392
|
Loading…
Reference in New Issue
Block a user