Skip to content

Commit e179029

Browse files
committedSep 29, 2018
support LED setting
1 parent 205ca32 commit e179029

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mqtt/thermostat/mqtt.marko
2+
mqtt/thermostat/thermostat.marko

‎mqtt/client/install-client.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ if [ ! -f $LOCALSCRIPTDIR/mqtt.cfg ]; then
2525
wget --no-check-certificate -q $BASEURL/client/mqtt.cfg -O $LOCALSCRIPTDIR/mqtt.cfg
2626
fi
2727

28+
if [ ! -f $LOCALSCRIPTDIR/led.cfg ]; then
29+
wget --no-check-certificate -q $BASEURL/client/led.cfg -O $LOCALSCRIPTDIR/led.cfg
30+
fi
31+
2832
chmod 755 $LOCALDIR/mosquitto_pub
2933
chmod 755 $LOCALDIR/mosquitto_sub
3034
chmod 755 $LOCALSCRIPTDIR/mqrun.sh
@@ -34,7 +38,7 @@ chmod 755 $LOCALSCRIPTDIR/mqsub.sh
3438
chmod 755 $LOCALSCRIPTDIR/mqstop.sh
3539

3640
poststart=/etc/persistent/rc.poststart
37-
startscript=$LOCALSCRIPTDIR/mqrun.sh
41+
startscript="sleep 10; $LOCALSCRIPTDIR/mqrun.sh"
3842

3943
if [ ! -f $poststart ]; then
4044
echo "$poststart not found, creating it ..."

‎mqtt/client/led.cfg

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# set the led state using this configuration, none of the settings mandatory!
2+
# afterboot ... led state after starting
3+
# relay_off ... led state when all relays are OFF
4+
# relay_on ... led state if one relay is ON
5+
# 0=OFF, 1=BLUE, 2=YELLOW, 3=BOTH, 4=ALTERNATE
6+
7+
afterboot=3
8+
# relay_on=1
9+
# relay_off=0

‎mqtt/client/mqsub.sh

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
log() {
44
logger -s -t "mqtt" "$*"
55
}
6+
source $BIN_PATH/client/led.cfg
7+
8+
# initially set the LED. If configured it can be switched along with the relay later
9+
if [ -n "$afterboot" ];
10+
then
11+
echo $afterboot > /proc/led/status
12+
fi
613

714
log "MQTT listening..."
815
$BIN_PATH/mosquitto_sub -I $clientID -h $mqtthost $auth -v -t $topic/+/+/set | while read line; do
@@ -18,9 +25,17 @@ $BIN_PATH/mosquitto_sub -I $clientID -h $mqtthost $auth -v -t $topic/+/+/set | w
1825
if [ "$inputVal" == "1" ]
1926
then
2027
val=1
28+
if [ -n "$relay_on" ];
29+
then
30+
echo $relay_on > /proc/led/status
31+
fi
2132
elif [ "$inputVal" == "0" ]
2233
then
2334
val=0
35+
if [ -n "$relay_off" ];
36+
then
37+
echo $relay_off > /proc/led/status
38+
fi
2439
else
2540
continue
2641
fi

‎mqtt/client/readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ lock=1
5252
voltage=0
5353
```
5454

55+
## LED
56+
You can configure the LED using the file `led.cfg`.
57+
58+
```
59+
# set the led state using this configuration, none of the settings mandatory!
60+
# afterboot ... led state after starting
61+
# relay_off ... led state when all relays are OFF
62+
# relay_on ... led state if one relay is ON
63+
# 0=OFF, 1=BLUE, 2=YELLOW, 3=BOTH, 4=ALTERNATE
64+
65+
afterboot=3
66+
# relay_on=1
67+
# relay_off=0
68+
```
69+
5570
# Published data
5671

5772
The mPower device will publish messages every 60 seconds to different topics. Example:

0 commit comments

Comments
 (0)
Please sign in to comment.