Skip to content

Instantly share code, notes, and snippets.

@tomasinouk
Last active October 27, 2016 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasinouk/bf03b1f941c1dee4b0f1 to your computer and use it in GitHub Desktop.
Save tomasinouk/bf03b1f941c1dee4b0f1 to your computer and use it in GitHub Desktop.
Conel, Smartworkx start-up script - alarm sms and email based on Input status

Installation

  1. Copy&paste into Start-up Script in the Conel router menu.
  2. Fill in your email and mobile number.
  3. Apply.
  4. Reboot the router.

Modification

Please refer to offical Conel documentation Commands&Scripts_v2_v3_EN

cat > /var/scripts/sms << EOF
#!/bin/sh
if [ "\$1" = "1" ]; then
if [ "\$3" = "STATUS" ]; then

OUTPUT1="\$(gsminfo | grep Signal)"
OUTPUT2="\$(ethtool eth0 | grep Link)"
OUTPUT3="\$(status sys | grep Temp)"
SMS="\$OUTPUT1 \$OUTPUT2 \$OUTPUT3"

gsmsms \$2 "\$SMS"
fi
fi 
EOF


# -------------sending SMS and email based on input status-------------
# ---------------------------------------------------------------------

# -------------phone numbers-------------
PHONE_NO1="xx0401234567"
PHONE_NO2="xx0401234567"
PHONE_NO3="xx0401234567"
PHONE_NO4="xx0401234567"

# -------------email addresses-------------
EMAIL1="test1@madisontech.com"
EMAIL2="test2@madisontech.com"

#------------- Text Strings -------------
BIN0_TEXT_OUT_ON="Input-0 ON"
BIN0_TEXT_OUT_OFF="Input-0 OFF"
BIN1_TEXT_OUT_ON="Input-1 ON"
BIN1_TEXT_OUT_OFF="Input-1 OFF"
BIN2_TEXT_OUT_ON="Input-2 ON"
BIN2_TEXT_OUT_OFF="Input-2 OFF"
BIN3_TEXT_OUT_ON="Input-3 ON"
BIN3_TEXT_OUT_OFF="Input-3 OFF"
BIN4_TEXT_OUT_ON=" Input-4 ON"
BIN4_TEXT_OUT_OFF="Input-4 OFF"

#-------------SMS ALARM CODE(NO NOT EDIT)-------------
#default expected original states (1 = relay open, 0 = relay closed, 2 = send a message every boot)
OLD0="2"
OLD1="2"
OLD2="2"
OLD3="2"
OLD4="2"

#let it boot before trying to send messages (20sec is safe)
sleep 20 

while true
do
	/usr/bin/io get bin0
	VAL0=$?  #get result from io command
	if [ "$VAL0" != "$OLD0" ]; then #value changed
		if [ "$VAL0" = "0" ]; then #relay closed
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4 
			do
				gsmsms "$i" "$BIN0_TEXT_OUT_OFF"
				#echo "sent message $BIN0_TEXT_OUT_OFF to $i" >> /tmp/log	#good to have for audit log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN0_TEXT_OUT_OFF"
			done
		elif [ "$VAL0" = "1" ]; then #relay open
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN0_TEXT_OUT_ON"
				#echo "sent message $BIN0_TEXT_OUT_ON to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN0_TEXT_OUT_ON"
			done
		fi
		OLD0=$VAL0
	fi

	/usr/bin/io get bin1
	VAL1=$?
	if [ "$VAL1" != "$OLD1" ]; then
		if [ "$VAL1" = "0" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN1_TEXT_OUT_OFF"
				#echo "sent message $BIN1_TEXT_OUT_OFF to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN1_TEXT_OUT_OFF"
			done
		elif [ "$VAL1" = "1" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN1_TEXT_OUT_ON"
				#echo "sent message $BIN1_TEXT_OUT_ON to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN1_TEXT_OUT_ON"
			done
		fi
		OLD1=$VAL1
	fi

	/usr/bin/io get bin2
	VAL2=$?
	if [ "$VAL2" != "$OLD2" ]; then
		if [ "$VAL2" = "10" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN2_TEXT_OUT_OFF"
				#echo "sent message $BIN2_TEXT_OUT_OFF to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN2_TEXT_OUT_OFF"
			done
		elif [ "$VAL2" = "11" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN2_TEXT_OUT_ON"
				#echo "sent message $BIN2_TEXT_OUT_ON to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN2_TEXT_OUT_ON"
			done
		fi
		OLD2=$VAL2
	fi

	/usr/bin/io get bin3
	VAL3=$?
	if [ "$VAL3" != "$OLD3" ]; then
		if [ "$VAL3" = "10" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN3_TEXT_OUT_OFF"
				#echo "sent message $BIN3_TEXT_OUT_OFF to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN3_TEXT_OUT_OFF"
			done
		elif [ "$VAL3" = "11" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN3_TEXT_OUT_ON"
				#echo "sent message $BIN3_TEXT_OUT_ON to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN3_TEXT_OUT_ON"
			done
		fi
		OLD3=$VAL3
	fi

	/usr/bin/io get bin4
	VAL4=$?
	if [ "$VAL4" != "$OLD4" ]; then
		if [ "$VAL4" = "10" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN4_TEXT_OUT_OFF"
				#echo "sent message $BIN4_TEXT_OUT_OFF to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN4_TEXT_OUT_OFF"
			done
		elif [ "$VAL4" = "11" ]; then
			for i in $PHONE_NO1 $PHONE_NO2 $PHONE_NO3 $PHONE_NO4
			do
				gsmsms "$i" "$BIN4_TEXT_OUT_ON"
				#echo "sent message $BIN4_TEXT_OUT_ON to $i" >> /tmp/log
			done
			for a in $EMAIL1 $EMAIL2 
			do
				/usr/bin/email -t "$a" -s "$BIN4_TEXT_OUT_ON"
			done
		fi
		OLD4=$VAL4
	fi

	sleep 1

done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment