Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c3a39a0
Bin files for MQTT
eteixido1 Aug 27, 2019
61031ac
mqtt.conf example
eteixido1 Aug 27, 2019
14672a9
mqtt-control & mqtt-status autostart
eteixido1 Aug 27, 2019
57e52d7
mqtt-control & mqtt-status autostart
eteixido1 Aug 27, 2019
a81f06e
mqtt-control & mqtt-status controlscripts
eteixido1 Aug 27, 2019
b61fa98
mqtt scripts
eteixido1 Aug 27, 2019
3dacef1
MQTT bin files
eteixido1 Aug 27, 2019
9cdb873
mqtt.conf file
eteixido1 Aug 27, 2019
13fd988
Delete busybox
eteixido1 Aug 27, 2019
7cfd1f9
Delete mosquitto_pub
eteixido1 Aug 27, 2019
2745cf0
Delete mosquitto_pub.bin
eteixido1 Aug 27, 2019
e726ade
Delete mosquitto_sub
eteixido1 Aug 27, 2019
fb7a00b
Delete mosquitto_sub.bin
eteixido1 Aug 27, 2019
590aae1
Delete mqtt-control
eteixido1 Aug 27, 2019
c46fed5
Delete mqtt-status
eteixido1 Aug 27, 2019
a01f7dc
Delete mqtt.conf
eteixido1 Aug 27, 2019
9784e3d
Delete mosquitto_pub-OLD
eteixido1 Aug 27, 2019
41047bd
Delete mosquitto_sub-OLD
eteixido1 Aug 27, 2019
d3ea60c
it's not necessari
eteixido1 Aug 28, 2019
7214fcd
it's not necessary
eteixido1 Aug 28, 2019
f1aad89
20190830-bin
eteixido1 Aug 30, 2019
d6bf737
20190830-autostart
eteixido1 Aug 30, 2019
153fa09
20190830-mqtt.conf
eteixido1 Aug 30, 2019
19d9b30
20190830-controlscripts mqtt-control mqtt-status
eteixido1 Aug 30, 2019
313be8a
20190830-scripts mqtt
eteixido1 Aug 30, 2019
920334b
20190830-script common_function.sh
eteixido1 Aug 30, 2019
58c5b77
mqtt configuration info
eteixido1 Sep 7, 2019
4273393
Delete getimage
eteixido1 Sep 10, 2019
f22df1b
Delete mosquitto_pub.bin
eteixido1 Sep 10, 2019
1599336
Delete mosquitto_sub.bin
eteixido1 Sep 10, 2019
f1b8f1b
Changed mqtt binaries for Openfang existing ones
eteixido1 Sep 10, 2019
9737742
changing binaries needed
eteixido1 Sep 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added fs/opt/bin/busybox
Binary file not shown.
2 changes: 2 additions & 0 deletions fs/opt/config/autostart/mqtt-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/opt/controlscripts/mqtt-control
2 changes: 2 additions & 0 deletions fs/opt/config/autostart/mqtt-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/opt/controlscripts/mqtt-status
42 changes: 42 additions & 0 deletions fs/opt/config/mqtt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
############################################################
# edit this file and move it to /opt/config/mqtt.conf #
############################################################

export LD_LIBRARY_PATH='/thirdlib:/lib:/opt/lib'

# Options for mosquitto_sub & mosquitto_pub
USER=mosquitto-user
PASS=mosquitto-pass
HOST=mosquitto-host-broker
PORT=1883

# Define a location
LOCATION="Home"

# Define device name
DEVICE_NAME="mijia-open-1"

# Define the base topic used by the camera
# send a message to myhome/openfang/set with the payload help for help.
# Results will be placed in myhome/openfang/${command} or topic/openfang/error - so please subscribe topic/openfang/# for testing purposes
TOPIC="$LOCATION/$DEVICE_NAME"

# Define an autodiscovery prefix, if autodiscovery is desired:
# AUTODISCOVERY_PREFIX="homeassistant"

# Define additional options for Mosquitto here.
# For example --cafile /opt/config/DST_Root_CA_X3.pem --tls-version tlsv1
# or use a special id to connect to brokers like azure
MOSQUITTOOPTS=""

# Add options for mosquitto_pub like -r for retaining messages
MOSQUITTOPUBOPTS=""

# Send a mqtt statusupdate every n seconds
STATUSINTERVAL=30

# Publish and update the light dependant resistor (LDR) status or not. The
# default value if the variable is not set is to send it. This might be useful
# for owners of devices that lack the hardware sensor to avoid publishing
# rubbish.
SENDLDR="true"
51 changes: 51 additions & 0 deletions fs/opt/controlscripts/mqtt-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
PIDFILE="/run/mqtt-control.pid"

if [ ! -f /opt/config/mqtt.conf ]; then
echo "You have to configure mqtt first. Please see /opt/config/mqtt.conf.dist for further instructions"
fi

status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
fi
}

start()
{
if [ -f $PIDFILE ]; then
echo "MQTT Control already running";
else
. /opt/config/mqtt.conf
if [ -z ${AUTODISCOVERY_PREFIX+x} ];
then echo "MQTT autodiscovery is not enabled";
else
echo "MQTT autodiscovery is enabled - now publishing initial configurations";
/opt/scripts/mqtt-autodiscovery.sh
fi
echo "Starting MQTT - Control"
/opt/bin/busybox nohup /opt/scripts/mqtt-control.sh &>/dev/null &
echo "$!" > "$PIDFILE"
fi
}

stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill "$pid" && rm "$PIDFILE"
killall mosquitto_sub 2>/dev/null
killall mosquitto_sub.bin 2>/dev/null
fi
}

if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi
42 changes: 42 additions & 0 deletions fs/opt/controlscripts/mqtt-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
PIDFILE="/run/mqtt-status.pid"

if [ ! -f /opt/config/mqtt.conf ]; then
echo "You have to configure mqtt first. Please see /opt/config/mqtt.conf.dist for further instructions"
fi

status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
fi
}

start()
{
if [ -f $PIDFILE ]; then
echo "MQTT-Status already running";
else
echo "Starting MQTT-Status"
/opt/bin/busybox nohup /opt/scripts/mqtt-status-interval.sh &>/dev/null &
echo "$!" > "$PIDFILE"
fi
}

stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill "$pid" && rm "$PIDFILE"
fi
}

if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi
95 changes: 58 additions & 37 deletions fs/opt/scripts/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ yellow_led() {
setgpioled $(nvram get 2860 yellow_led_pin) 0
;;
status)
status=$(getgpioled $(nvram get 2860 yellow_pin))
status=$(getgpioled $(nvram get 2860 yellow_led_pin))
case $status in
0)
echo "OFF"
Expand Down Expand Up @@ -291,94 +291,115 @@ rtsp_mjpeg_server() {
esac
}

# Control the motion detection function
motion_detection() {
# Control the night mode
night_mode() {
case "$1" in
on)
/system/sdcard/bin/setconf -k m -v 4
ir_led on
ir_cut off
/usr/bin/setconf -k n -v 1
;;
off)
/system/sdcard/bin/setconf -k m -v -1
ir_led off
ir_cut on
/usr/bin/setconf -k n -v 0
;;
status)
status=$(/system/sdcard/bin/setconf -g m 2>/dev/null)
status=$(/usr/bin/setconf -g n)
case $status in
-1)
0)
echo "OFF"
;;
*)
1)
echo "ON"
;;
esac
;;
esac
}

# Control the motion tracking function
motion_tracking() {
# Control the auto night mode
auto_night_mode() {
case "$1" in
on)
/system/sdcard/bin/setconf -k t -v on
/system/sdcard/controlscripts/auto-night-detection start
;;
off)
/system/sdcard/bin/setconf -k t -v off
/system/sdcard/controlscripts/auto-night-detection stop
;;
status)
status=$(/system/sdcard/bin/setconf -g t 2>/dev/null)
case $status in
true)
if [ -f /run/auto-night-detection.pid ]; then
echo "ON"
;;
*)
else
echo "OFF"
;;
esac
fi
;;
esac
}

# Control the night mode
night_mode() {
# Take a snapshot
snapshot(){
filename="/opt/DCIM/snapshot.jpg"
/usr/bin/getimage > "$filename" &
sleep 1
}

# Reboot the System
reboot_system() {
/sbin/reboot
}

# Re-Mount the SD Card
remount_sdcard() {
mount -o remount,rw /opt
}

##############################################################################################################################################################
##################### VALIDATED
##############################################################################################################################################################

# Control the motion detection function
motion_detection() {
case "$1" in
on)
ir_led on
ir_cut off
/usr/bin/setconf -k n -v 1
/usr/bin/setconf -k m -v 4
;;
off)
ir_led off
ir_cut on
/usr/bin/setconf -k n -v 0
/usr/bin/setconf -k m -v -1
;;
status)
status=$(/usr/bin/setconf -g n)
status=$(/usr/bin/setconf -g m 2>/dev/null)
case $status in
0)
-1)
echo "OFF"
;;
1)
*)
echo "ON"
;;
esac
;;
esac
}

# Control the auto night mode
auto_night_mode() {
# Control the motion tracking function
motion_tracking() {
case "$1" in
on)
/system/sdcard/controlscripts/auto-night-detection start
/usr/bin/setconf -k t -v on
;;
off)
/system/sdcard/controlscripts/auto-night-detection stop
/usr/bin/setconf -k t -v off
;;
status)
if [ -f /run/auto-night-detection.pid ]; then
status=$(/usr/bin/setconf -g t 2>/dev/null)
case $status in
true)
echo "ON"
else
;;
*)
echo "OFF"
fi
;;
esac
;;
esac
}
Expand Down
Loading