Skip to content

Instantly share code, notes, and snippets.

@luandro
Last active July 25, 2021 11:15
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 luandro/181a7811967ef824f49f7e9106b7a427 to your computer and use it in GitHub Desktop.
Save luandro/181a7811967ef824f49f7e9106b7a427 to your computer and use it in GitHub Desktop.
OpenWRT ESP relay control
#!/bin/sh
# /usb/bin/control_irrigation.sh
# Don't forget to: chmod +x /usb/bin/control_irrigation.sh
command=$1
channel=$2
IP=$(cat /tmp/dhcp.leases | grep ESP |cut -d " " -f 3| awk '{print $1}')
echo $1 on channel $2 on IP $IP
if [ $1 == 'start' ]
then
if [ $2 == 4 ]
then
echo -e '\xA0\x04\x01\xA5' | nc $IP 8080
fi
if [ $2 == 3 ]
then
echo -e '\xA0\x03\x01\xA4' | nc $IP 8080
fi
if [ $2 == 2 ]
then
echo -e '\xA0\x02\x01\xA3' | nc $IP 8080
fi
if [ $2 == 1 ]
then
echo -e '\xA0\x01\x01\xA2' | nc $IP 8080
fi
fi
if [ $1 == 'stop' ]
then
if [ $2 == 4 ]
then
echo -e '\xA0\x04\x00\xA4' | nc $IP 8080
fi
if [ $2 == 3 ]
then
echo -e '\xA0\x03\x00\xA3' | nc $IP 8080
fi
if [ $2 == 2 ]
then
echo -e '\xA0\x02\x00\xA2' | nc $IP 8080
fi
if [ $2 == 1 ]
then
echo -e '\xA0\x01\x00\xA1' | nc $IP 8080
fi
fi
# etc/crontabs/root
0 4 * * * control_irrigation.sh start 1
25 4 * * * control_irrigation.sh stop 1
25 4 * * * control_irrigation.sh start 2
50 4 * * * control_irrigation.sh stop 2
50 4 * * * control_irrigation.sh start 3
15 5 * * * control_irrigation.sh stop 3
15 5 * * * control_irrigation.sh start 4
40 5 * * * control_irrigation.sh stop 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment