TOCOS TWE-LiteとToCoStick(トコスティック)で温湿度計AM2321センサーのデバック中
とりあえずマイナスの温度も表示出来たのでデバッグ中コードを書いとこ
ちなみに母艦はRemote-Hand_Raspberry_pi_0.22.zip
Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Dec 28 13:29:57 2015 from dell
[root@~]# /usr/local/bin/epicon -s 115200 -ql /dev/ttyUSB0 -c ./am2321_test
:7889AA0201060304021400D857
2015/12/28 15:00:37,21.6℃ 53.2%[root@~]#
[root@~]# /usr/local/bin/epicon -s 115200 -ql /dev/ttyUSB0 -c ./am2321_test
-1[root@~]# /usr/local/bin/epicon -s 115200 -ql /dev/ttyUSB0 -c ./am2321_test
:7889AA0201060304021900D753
2015/12/28 15:01:03,21.5℃ 53.7%[root@~]#
[root@~]# cat am2321_test
#/bin/sh
#/usr/local/bin/epicon -s 115200 -ql /dev/ttyUSB0 -c comnand_file
OK="01"
NG="00"
READ="02"
CMD="00"
RES="00"
RD="-1"
LEN="0"
echo -en ":7888AA015C0000X"\r\n
msleep 20
read -s -t 1 RD || RD="-1"
#echo $RD >/dev/stderr
echo -en ":7888AA015C03020004X"\r\n
msleep 20
read -s -t 1 RD || RD="-1"
#echo $RD >/dev/stderr
msleep 1500
echo -en ":7888AA025C0006X"\r\n
msleep 20
RD="-1"
read -s -t 2 RD || RD="-1"
LEN=`echo -en $RD|awk '{printf(length($0))}'`
if [ $LEN != 28 ];then
echo -en "-1" >/dev/stderr
exit
fi
echo $RD >/dev/stderr
if [ $RD != "X-1" ];then
CMD=`echo -en $RD |awk '{printf(substr($1,8,2))}'`
RES=`echo -en $RD |awk '{printf(substr($1,10,2))}'`
if [ $CMD = $READ -a $RES = $OK ];then
NOWDATE=`date '+%Y/%m/%d %T'|awk '{printf("%s %s",\$1,\$2)}'`
HUMH=`echo -en $RD |awk '{printf(substr($1,18,2))}'`
HUMLH=`echo -en $RD |awk '{printf(substr($1,20,1))}'`
HUMLL=`echo -en $RD |awk '{printf(substr($1,21,1))}'`
DHUMH=$((0x$HUMH * 256))
DHHML=$((0x$HUMLH * 16))
HUM=$(($(($(($DHUMH + $DHHML)) + 0x$HUMLL)) / 10))
HUMMOD=$(($(($(($DHUMH + $DHHML)) + 0x$HUMLL)) % 10))
TMPH=`echo -en $RD |awk '{printf(substr($1,22,2))}'`
TMPLH=`echo -en $RD |awk '{printf(substr($1,24,1))}'`
TMPLL=`echo -en $RD |awk '{printf(substr($1,25,1))}'`
TMP=""
if [ $((0x$TMPH & 0x80)) != 0 ];then
TMPH=$((0x$TMPH & 0x7F))
TMP="-"
fi
DTMPH=$((0x$TMPH * 256))
DTMPLH=$((0x$TMPLH * 16))
TMP=${TMP}$(($(($(($DTMPH + $DTMPLH)) + 0x$TMPLL)) / 10))
TMPMOD=$(($(($(($DTMPH + $DTMPLH)) + 0x$TMPLL)) % 10))
else
echo -en "-1" >/dev/stderr
exit
fi
fi
echo -en ${NOWDATE},${TMP}.${TMPMOD}℃ ${HUM}.${HUMMOD}% >/dev/stderr
[root@~]#