We will start to analyze KC868-Hx or KC868-HxB communication protocol. The KC868-H2B,KC868-H4B,KC868-H8B,KC868-H16B,KC868-H32B just different channel relays. The protocol is almost same.
First, we list all the protocol command. If you use KC868-Hx series relay controller, when the controller is set in “TCP server” mode by Vircom tool, PC is a client device. The default IP address and Port of the controller are “192.168.1.200” and “4196”.
This is VirCom tool for network setting. But when you using KC868-HxB series relay controller, never use VirCom tool again.
If you use KC868-HxB series relay controller, when the controller is set in “TCP server” mode by webpage, PC is a client device. The default IP address and Port of the controller are “192.168.1.200” and “4196”.
Download “VirCom” network config tool:
Download TCP Server&Client Debugger:
KC868-Hx Smart Controller protocol document:
1.Turn one relay ON and OFF:
A.Turn ON one relay:
Send: RELAY-SET-255,x,1 （x is the channel of Relay）
Feedback: RELAY-SET-255,x,1,OK (Turn ON Relay x successed)
FeedBack: RELAY-SET-255,x,1,ERROR (Turn ON Relay x failed)
B.Turn OFF one relay:
Send:RELAY-SET-255,x,0 （x is the channel of Relay）
FeedBack: RELAY-SET-255,x,0,OK (Turn OFF Relay x successed)
FeedBack: RELAY-SET-255,x,0,ERROR (Turn OFF Relay x failed)
The third byte parameter in the protocol-“action 0/1”: “0” means “off” and “1” means “on”. For example: if we want to turn ON relay1, we can send the command “RELAY-SET-255,1,1”, the first parameter “255” is a fixed number,not to change.
If we want to turn OFF relay1, we can send the command “RELAY-SET-255,1,0”, If we want to turn ON relay2, we can send the command “RELAY-SET-255,2,1”, the first parameter “255” is a fixed number; The second parameter “2” means relay2 and the third parameter “1” means “ON”.
2.Read status of one relay:
Send: RELAY-READ-255,x （x is the channel of Relay）
Feedback: RELAY-READ-255,x (x is the channel of Relay), y ( status 0 / 1), OK/ERROR
For example, if we want to know whether relay1 is in “ON” or “OFF” state, we can send: “RELAY-READ-255,1”, the first parameter “255” is a fixed number, the second parameter “1” means relay1.
After send the command, controller feedback “RELAY-READ-255,1,0,OK”, “0” means current state is “OFF” state, and if it is “1”, the current state is “ON” state.
If you want to read other relay, you can change another channel number.
3.Read status of input port:
Feedback: RELAY-GET_INPUT-255,x (x is 1 byte:state), OK/ERROR
Note: when controller’s input port is triggered (short circuit input port with GND), controller will auto send a string: “RELAY-ALARM-Y,OK” Y means which input port triggered.
The input port can connect with dry node type sensor.
Send “RELAY-GET_INPUT-255” to controller, then feedback: “RELAY-GET_INPUT-255,255,OK”. The second parameter of “255” is the state byte of the 8 input ports. We use 8-bit binary to represent the state of the 8 inputs. “0” is for “short” and “1” is for “not short”.
If 8 input ports are all not short with GND, the input ports state is (11111111)b, every number “1” is binary, and then we convert the 8-bit “1” to a decimal number, which is the number “255”.
If 8 input ports are all short with GND, the input ports state is (00000000)b. every number “0” is binary, and we convert the 8-bit “0” to a decimal number, which the number is also “0”.
If the state is “not short with GND” for the input ports 1 to 4 and “short with GND” for the input ports 5 to 8, the input port state is (00001111)b, “00001111” is binary. Then we convert the 8-bit “00001111” to a decimal number, which the number is “15”. It means the device will return “RELAY-GET_INPUT-255, 15, OK” for this input port state.
Actually, we do not need to always read the input port status; we can use the trigger active command to check the status. When the trigger command is feedback by controller, the client receives the “RELAY-ALARM-Y” string, then we send string “RELAY-GET_INPUT-255” for read input port status. As shown in the following figure, when we manually short the input1 with tweezers,controller will send string “RELAY-ALARM-1”, at this time, we send read state command ”RELAY-GET_INPUT-255”, controller will return ”RELAY-GET_INPUT-255,254,OK”, as told above, the number “254” is a decimal number, we convert it into the binary, which is “11111110”, the binary numbers “1” and “0” represent “not triggered” and “triggered”. So we know the input1 is status of “0”, which is triggered.
Note: if want to use alarm message function, you must let your ethernet and wifi work mode=”TCP Server”, “UDP” can’t work for this function. Both ethernet and wifi need set work mode to “TCP Server”.
4.Turn all relay ON and OFF by one command:
Send: RELAY-SET_ALL-255,D0 (D0: relay1->relay8)
Send: RELAY-SET_ALL-255,D1,D0 (D0: relay1->relay8, D1: relay9->relay16)
Send: RELAY-SET_ALL-255,D3,D2,D1,D0 (D0: relay1->relay8, D1: relay9->relay16,D2: relay17->relay24,D3: relay25->relay32)
one command to control multiple relays at the same time. What’s the difference?
“Turn one relay ON and OFF” command also can turn relay ON/OFF, but If we want to control multiple relays together, we need to send multiple control commands and take some time to execute.
Now we can control multiple relays, such as “all ON”, “all OFF,” or some channels “ON”, some channels “OFF”, only one command can do it. And the speed of multiplex control is also fast. We can see that in the command, D0–D3 is a byte represents the states of the relay outputs want to set, and now the “1” means “ON,” “0” means “OFF”, as the same it is 8-bit binary to indicate the state of each relay, then converted to decimal number to send command.
For example: if we want to turn ON 8 channel relays, we can send the command “RELAY-SET_ALL-255,255”, we want to turn OFF 8 channel relays, then we can send the command “RELAY-SET_ALL-255,0”. If you want to turn ON the relay1,relay2,relay3,relay4 and turn OFF the relay5,relay6,relay7,relay8, the parameter is defined as “00001111”, converted to the decimal number of “15 “, and the command is “RELAY-SET_ALL-255,15″
If we use KC868-H32 smart controller, there are 32 channel relays. Similar as the device KC868-H8, every 8 relays’ status use 1 byte data, so 32 channel total use 4 bytes.
if work with KC868-H8, “D0” means relay1->relay8, if work with KC868-H32, “D0” means relay1->relay8, “D1” means relay9->relay16 , “D2” means relay17->relay24, and “D3” means relay25->relay32
“D0”,”D1″,”D2″,”D4” must be a decimal number, which can be converted from 8-bit binary data with “0” and “1”. “1” is for “ON” and “0” is for “OFF”
5.Read all relays status by one command:
Actually, we can also read all relays’ status by one command. For example: send “RELAY-STATE-255”, if we work with KC868-H8 smart controller, it will return “RELAY-STATE-255,255,OK”, the number “255” can be converted into the 8-bit binary “11111111”. We already know that the “1” means “ON”. So the return means all relays are ON.
D0,D1,D2,D3 means as the command in “Turn all relay ON and OFF by one command”.
6.Turn ON all Relays
Turn ON all relays by one command.All parameters are fixed.
7.Turn OFF all Relays
Turn OFF all relays by one command.All parameters are fixed.
8.Change the converse state of the relay
Send:RELAY-KEY-255,x,1 （x is the channel of Relay）
Feedback:RELAY-KEY-255,x,1,OK （x is the channel of Relay）
change the status of one relay, such as your relay is ON, when send this command , relay will be OFF. if your relay is OFF, when send this command , relay will be ON.
Note: command 6,7,8 need your controller is new firmware version, Begin year 2020, all controller is new version. If your controller is old version, Please contact with us to help you update the smart controller’s firmware.