-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc1100.sh
executable file
·62 lines (54 loc) · 2.04 KB
/
dc1100.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Copyright 2017 Robert W Igo
#
# http://bob.igo.name
# http://www.linkedin.com/profile/view?id=22294307
#
# This file is part of AirQuality.
#
# AirQuality is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# AirQuality is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with AirQuality. If not, see <http:#www.gnu.org/licenses/>.
OPENHAB_URL=http://openhab.igo:8080
OPENHAB_LARGE_PARTICLES_ITEM=Large_Particles
OPENHAB_SMALL_PARTICLES_ITEM=Small_Particles
Usage() {
echo "USAGE:"
echo `basename $0` "[-p PORT]"
echo "-p: Serial port where your DC1100 is attached (omit to try auto-discovery)"
echo "e.g."
echo "$0 -p /dev/ttyUSB0"
exit 4
}
while getopts "p:" FLAG ; do
case "$FLAG" in
p) port="$OPTARG";;
*) Usage;;
esac
done
# Try to auto-determine the port if it's not provided. This makes a big assumption that only one FTDI serial device
# converter is attached via USB and that it's the DC1100.
if [ "$port" == "" ]; then
port="/dev/"`grep -a 'FTDI USB Serial Device converter now attached to' /var/log/kern.log | tail -1 | awk -F 'now attached to ' '{print $2}'`
fi
if [ "$port" == "/dev/" ]; then
Usage
fi
stty -F $port 9600 cs8 -cstopb -parenb
while read -r line < $port; do
echo $line
small=`echo $line | awk -F',' '{print $1}'`
large=`echo $line | awk -F',' '{print $2}'`
curl --header "Content-Type: text/plain" --request PUT --data $small ${OPENHAB_URL}/rest/items/${OPENHAB_SMALL_PARTICLES_ITEM}/state
curl --header "Content-Type: text/plain" --request PUT --data $large {$OPENHAB_URL}/rest/items/${OPENHAB_LARGE_PARTICLES_ITEM}/state
done