-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmqpub-static.sh
56 lines (45 loc) · 1.48 KB
/
mqpub-static.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
#!/bin/sh
# homie spec (incomplete)
$PUBBIN -h $mqtthost $auth -t $topic/\$homie -m "2.1.0" -r
$PUBBIN -h $mqtthost $auth -t $topic/\$name -m "$devicename" -r
$PUBBIN -h $mqtthost $auth -t $topic/\$fw/version -m "$version" -r
$PUBBIN -h $mqtthost $auth -t $topic/\$fw/name -m "mPower MQTT" -r
IPADDR=`ifconfig ath0 | grep 'inet addr' | cut -d ':' -f 2 | awk '{ print $1 }'`
$PUBBIN -h $mqtthost $auth -t $topic/\$localip -m "$IPADDR" -r
NODES=`seq $PORTS | sed 's/\([0-9]\)/port\1/' | tr '\n' , | sed 's/.$//'`
$PUBBIN -h $mqtthost $auth -t $topic/\$nodes -m "$NODES" -r
UPTIME=`awk '{print $1}' /proc/uptime`
$PUBBIN -h $mqtthost $auth -t $topic/\$stats/uptime -m "$UPTIME" -r
properties=relay
if [ $energy -eq 1 ]
then
properties=$properties,energy
fi
if [ $power -eq 1 ]
then
properties=$properties,power
fi
if [ $voltage -eq 1 ]
then
properties=$properties,voltage
fi
if [ $lock -eq 1 ]
then
properties=$properties,lock
fi
# node infos
for i in $(seq $PORTS)
do
$PUBBIN -h $mqtthost $auth -t $topic/port$i/\$name -m "Port $i" -r
$PUBBIN -h $mqtthost $auth -t $topic/port$i/\$type -m "power switch" -r
$PUBBIN -h $mqtthost $auth -t $topic/port$i/\$properties -m "$properties" -r
$PUBBIN -h $mqtthost $auth -t $topic/port$i/relay/\$settable -m "true" -r
done
if [ $lock -eq 1 ]
then
for i in $(seq $PORTS)
do
$PUBBIN -h $mqtthost $auth -t $topic/port$i/lock/\$settable -m "true" -r
done
fi
$PUBBIN -h $mqtthost $auth -t $topic/\$online -m "true" -r