-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqttreader.sh
executable file
·50 lines (41 loc) · 1.31 KB
/
mqttreader.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
#!/bin/sh
MQTTREADER_INTOPIC="rtl_433/+/events"
MQTTREADER_OUTTOPIC="app/dewpoint/sensor/in"
MQTTHOST="localhost"
MQTTPORT="1883"
MQTTUSER=""
MQTTPASS=""
if [ -f "/etc/opendew/opendew.cfg" ]; then
. "/etc/opendew/opendew.cfg"
fi
if [ -f "/etc/opendew/lib.sh" ]; then
. "/etc/opendew/lib.sh"
fi
if [ -f "$HOME/.opendew/.dewreaderconfig" ]; then
. "$HOME/.opendew/.dewreaderconfig"
fi
SCRIPT_DIR=$(dirname -- "$0")
if [ -f "$SCRIPT_DIR/lib.sh" ]; then
. "$SCRIPT_DIR/lib.sh"
fi
to_sensor_in_string() {
IN="$1"
sensortemp=$(echo "$IN" | jq -r '.temperature_C')
sensorhum=$(echo "$IN" | jq -r '.humidity')
sensorid=$(echo "$IN" | jq -r '.id')
sensorchannel=$(echo "$IN" | jq -r '.channel')
sensorname=$(echo "id$sensorchannel-$sensorid")
echo "{\"name\":\"$sensorname\",\"temperature_C\":$sensortemp,\"humidity\":$sensorhum}"
}
while true
do
mosquitto_sub -h "$MQTTHOST" -p "$MQTTPORT" -u "$MQTTUSER" -P "$MQTTPASS" -t "$MQTTREADER_INTOPIC" | ( IFS='' ; while read line ;
do
check_main_process
sensorstring=$(to_sensor_in_string "$line") ;
#echo "$sensorstring" >>$queue ;
mosquitto_pub -h "$MQTTHOST" -p "$MQTTPORT" -u "$MQTTUSER" -P "$MQTTPASS" -t "$MQTTREADER_OUTTOPIC" -m "$sensorstring"
#echo "$sensorstring" ;
done ;
)
done