Last active
July 25, 2021 11:15
-
-
Save luandro/181a7811967ef824f49f7e9106b7a427 to your computer and use it in GitHub Desktop.
OpenWRT ESP relay control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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