Alles was per HTTP gesteuert werden kann
-
Bart82
- Beiträge: 62
- Registriert: Mo 29. Mai 2017, 18:04
- Wohnort: Schweiz
Fr 23. Aug 2019, 20:35
Hallo zusammen
Hab mir ein Relay Bord gekauft ähnlich wie das von Nuts Beitrag.
Habe auch befehle im www gefunden.
Leider schaffe ich es nicht das dass ganze auch funktioniert.
Hat jemand Tipps oder sogar geschriebene Kommandos
Das Gerät hat bei mir die IP 192.168.1.210
http://www.hlktech.net/product_detail.php?ProId=48
Code: Alles auswählen
PREFIX="\xaa"
PREFIX2="\x0f"
SUFFIX="\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
SYNTAX="Usage: $0 RelayID MODE HOST PORT\n\
where\tRelayID := {0-F|all}\
\n\tMODE := on|off\
\n\tHOST := hostname/IP address of the HLK-SW16
\n\tPORT := port number of the HLK-SW16 (generally: 8080)
\n\
\n\
\texample#1: $0 15 off 10.10.10.199 8080\n\
\t(Turn RelayID#15 off)\n\
\n\
\texample#2: $0 all on 10.10.10.199 8080\n\
\t(Turn all relays on)\n\
\t\n
\t\n[script by ram@pluslab.com, if you like this script please drop a note]\n\
"
if [ -z $4 ]
then
echo -e "Error: Incomplete command"
echo -e $SYNTAX
exit
fi
case "$1" in
0) SWITCHID="\x00" ;;
1) SWITCHID="\x01" ;;
2) SWITCHID="\x02" ;;
3) SWITCHID="\x03" ;;
4) SWITCHID="\x04" ;;
5) SWITCHID="\x05" ;;
6) SWITCHID="\x06" ;;
7) SWITCHID="\x07" ;;
8) SWITCHID="\x08" ;;
9) SWITCHID="\x09" ;;
10) SWITCHID="\x0a" ;;
11) SWITCHID="\x0b" ;;
12) SWITCHID="\x0c" ;;
13) SWITCHID="\x0d" ;;
14) SWITCHID="\x0e" ;;
15) SWITCHID="\x0f" ;;
all) if [ "$2" == "on" ]; then
SWITCHID="\x01"
PREFIX2="\x0a"
fi
if [ "$2" == "off" ]; then
SWITCHID="\x02"
PREFIX2="\x0b"
fi
;;
*) echo -e "Error: invalid RelayID, only 0-15 or all"
ERROR="1"
;;
esac
case "$2" in
on) #echo "On $1"
SWITCHTO="\x01" ;;
off) #echo "Off $1"
SWITCHTO="\x02" ;;
*) echo -e "Error: invalid mode, only on or off"
ERROR="1"
;;
esac
if [ ! -z $ERROR ]; then
echo -e $SYNTAX
fi
ncat $3 $4 -c "bash -c \"echo -e '$PREFIX$PREFIX2$SWITCHID$SWITCHTO$SUFFIX'\""
$0 all on 192.168.1.210 8080\n\ http://@192.168.1.210 8080/relay.cgi?pulse1=pulse
-
jbmedia
- Administrator
- Beiträge: 4447
- Registriert: Mi 17. Feb 2016, 13:42
Mo 23. Sep 2019, 16:09
Rein von dem Skript ausgehend, müsste sich z.B. Relais 1 mit folgendem Befehl einschalten lassen.
- 1.png (5.42 KiB) 10605 mal betrachtet
Wir wünschen viel Spaß mit den Produkten und einen erfolgreichen Tag! Ihr jbmedia Team
-
Bart82
- Beiträge: 62
- Registriert: Mo 29. Mai 2017, 18:04
- Wohnort: Schweiz
-
Bart82
- Beiträge: 62
- Registriert: Mo 29. Mai 2017, 18:04
- Wohnort: Schweiz
Sa 5. Okt 2019, 23:54
Kann ich auch den Relais Status mit dem AIR abfragen?
Wen ja bräuchte ich wieder Hilfe
Code: Alles auswählen
#!/bin/bash
#
# HLK-SW16 scripts
# Copyright (C) 2018 Ram Narula ram@pluslab.com
# Licensed under the GPL-3.0 license.
#
PREFIX="\xaa"
PREFIX2="\x1e"
SWITCHID="\x01"
SWITCHTO="\x01"
SUFFIX="\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
SYNTAX="Usage: $0 HOST PORT\n\
where\tHOST := hostname/IP address of the HLK-SW16\
\n\tPORT := port number of the HLK-SW16 (generally: 8080)\
\n\n
\texample#1: $0 10.10.10.199 8080\n\
\t(Get each relay status of HLK-SW16 located at 10.10.10.199 port 8080)\n\
\t\n[script by ram@pluslab.com, if you like this script please drop a note]\n\
"
if [ -z $2 ]
then
echo -e "Error: Incomplete command"
echo -e $SYNTAX
exit
fi
OUTPUT=`(echo -e "$PREFIX$PREFIX2$SWITCHID$SWITCHTO$SUFFIX";sleep 1)| ncat $1 $2`
#OUTPUT=`ncat 10.10.97.199 8080 -c "bash -c \"echo -e '$PREFIX$PREFIX2$SWITCHID$SWITCHTO$SUFFIX';sleep 1\""`
#another try ncat 10.10.97.199 8080 -c "bash -c '(echo hello;sleep 3;read -n100 -d\"\\0x00\" abc;echo $abc)'"
USABLE=`echo $OUTPUT | od -A n -v -t x1 | tr -d '\n'|sed 's/.*cc 0c/cc 0c/'|sed 's/ dd .*/ dd/'`
counter=0
for byte in $USABLE; do
if [ "$counter" -eq "0" ]; then
counter=$((counter+1))
continue
fi
if [ "$counter" -eq "1" ]; then
counter=$((counter+1))
continue
fi
if [ "$counter" -eq "18" ]; then
counter=$((counter+1))
break
fi
case "$byte" in
01) STATUS="on" ;;
02) STATUS="off" ;;
*) STATUS="ERROR" ;;
esac
echo Relay \#$((counter-2)): $STATUS
counter=$((counter+1))
done
Bei Interesse hier noch die Befehle um alle Relais zu schalten
Code: Alles auswählen
Relay 1 on off
AA 0F 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 00 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 2 on off
AA 0F 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 3 on off
AA 0F 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 02 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 4 on off
AA 0F 03 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 03 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 5 on off
AA 0F 04 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 04 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 6 on off
AA 0F 05 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 05 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 7 on off
AA 0F 06 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 06 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 8 on off
AA 0F 07 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 07 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 9 on off
AA 0F 08 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 08 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 10 on off
AA 0F 09 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 09 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 11 on off
AA 0F 0a 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 0a 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 12 on off
AA 0F 0b 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 0b 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 13 on off
AA 0F 0c 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 0c 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 14 on off
AA 0F 0d 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 0d 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 15 on off
AA 0F 0e 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 0e 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
Relay 16 on off
AA 0F 0F 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB
AA 0F 0F 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 BB