Programming Manual en
Programming Manual en
V2.0.2
1 Protocol:Dingtian string...............................................................................................................3
1.1 Query status command/KeepAlive....................................................................................3
1.2 Control command..............................................................................................................4
1.2.1 ON/OFF/Toggle example.......................................................................................4
1.2.2 Delay example........................................................................................................4
1.2.3 Jogging(Pulse) example.........................................................................................5
1.2.4 Flash example.........................................................................................................5
1.2.5 Toggle example......................................................................................................5
2 Protocol:Dingtian binary..............................................................................................................6
2.1 default setting....................................................................................................................6
2.2 command...........................................................................................................................6
2.2.1 read relay status......................................................................................................7
2.2.2 write relay..............................................................................................................8
2.2.3 write relay with delay.............................................................................................9
2.2.4 write relay with jogging.......................................................................................10
2.2.5 relay keep alive.....................................................................................................11
2.2.6 write relay with flash............................................................................................12
2.2.7 write relay with toggle..........................................................................................13
2.2.8 find relay baord IP(UDP multicast)......................................................................14
3 Protocol:HTTP GET CGI...........................................................................................................15
3.1 load relay status...............................................................................................................15
3.2 set relay...........................................................................................................................18
3.3 set relay(multiple)...........................................................................................................21
3.3.1 HTTP Method: GET.............................................................................................21
3.3.2 HTTP Method: POST...........................................................................................23
3.4 command queue..............................................................................................................25
3.4.1 HTTP Method: GET.............................................................................................25
3.5 load input status..............................................................................................................27
3.6 load one input status........................................................................................................30
3.7 load one relay status........................................................................................................30
3.8 Session check..................................................................................................................31
3.8.1 web config to Enable HTTP Session check..........................................................31
3.8.2 HTTP CGI test tool..............................................................................................32
3.8.3 full example(success):..........................................................................................33
3.8.4 full example(fail)..................................................................................................34
4 Protocol:Modbus-RTU/TCP/ASCII...........................................................................................35
4.1 Registers..........................................................................................................................36
4.2 Modbus-RTU + Modbus-RTU Over TCP/UDP..............................................................38
4.2.1 0x03:Read holding register..................................................................................38
4.2.2 0x06:Write Single Register..................................................................................39
4.2.3 0x10: Write Multiple Register..............................................................................39
4.3 Modbus-TCP/UDP..........................................................................................................44
4.3.1 0x03:Read holding register..................................................................................44
4.3.2 0x06:Write Single Register..................................................................................45
4.3.3 0x10: Write Multiple Register..............................................................................46
4.4 Modbus-ASCII + Modbus-ASCII Over TCP/UDP.........................................................50
4.4.1 0x03:Read holding register..................................................................................50
4.4.2 0x06:Write Single Register..................................................................................51
4.4.3 0x10: Write Multiple Register..............................................................................52
5 Protocol:MQTT..........................................................................................................................56
5.4 MQTT Topic...................................................................................................................57
6 Protocol:CoAP...........................................................................................................................59
6.1 Compile libcoap..............................................................................................................59
6.2 Get relay status................................................................................................................59
6.3 Control relay(simple)......................................................................................................60
6.4 Control relay...................................................................................................................61
1 Protocol:Dingtian string
Suport TCP client, TCP server, UDP, CAN/RS485
Format
[relay1][relay2]...[relay32]:[input1][input2]...[input32]:[channel count]
example(2 channel):
00:11:2
example(4 channel):
0000:1111:4
example(8 channel):
00000000:11111111:8
example(16 channel):
0000000000000000:1111111111111111:16
example(24 channel):
000000000000000000000000:111111111111111111111111:24
example(32 channel):
00000000000000000000000000000000:11111111111111111111111111111111:32
Remarks
1 The command code is a text string and does not need to be followed by a return.
1.2 Control command
X R C P
1(ON) 1~32 relay null(ON/OFF) C parameter
2(OFF) X for all relay :(Delay)
T(toggle) *(Jogging)
F(flash)
13 # relay 3 ON
23 # relay 3 OFF
132 # relay 32 ON
232 # relay 32 OFF
1X # relay all ON
2X # relay all OFF
T1 # toggle R1
T2 # toggle R2
Support password
2.2 command
data bytes >=2byte store format is LSB
example:0x1234,store format is 0x34,0x12
format
filed bytes comment
command 1 0xFF: set relay
0x07: multicast set relay
result(xor 0xAA) 1 pc->device: 0 xor 0xAA
device->pc: result xor 0xAA
result=0 success
result=other fail
session 1 0~255
device reply the same
relay command 1 0: read relay status
1:write relay
2:write relay with delay
3:write relay with jogging
4:relay keep alive
8:write relay with flash
9:write relay with toggle
password 2 0~9999
0:no password
Password incurrent device no
reply
command data x
2.2.1 read relay status
pc send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 0: read relay status
password 2 0~9999
0:no password
device reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 0: read relay status
Relay status 1(2/4/8CH) Bit0~31 map to relay1~32
2(16CH) Bit=1 relay on
3(24CH) Bit=0 relay off
4(32CH)
Input status 1(2/4/8CH) Bit0~31 map to input1~32
2(16CH) Bit=1 input High
3(24CH) Bit=0 input Low
4(32CH)
Example:
pc send:
FF AA 00 00 34 12 # password 0x1234
device reply:
FF AA 00 00 01 FF # relay 1 on, all input High
2.2.2 write relay
pc send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 1:write relay
password 2 0~9999
0:no password
relay mask 1(2/4/8CH) Bit0~31 map to relay relay1~32
2(16CH) Bit=1,relay need update
3(24CH)
4(32CH)
relay set 1(2/4/8CH) Bit0~31 map to relay relay1~32
2(16CH) Bit=1,relay on
3(24CH) Bit=0,relay off
4(32CH)
device reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 1:write relay
Example:
pc send:
FF AA 00 01 34 12 05 01 # relay 1 on, rely 3 off
device reply:
FF AA 00 01
2.2.3 write relay with delay
pc send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 2:write relay with delay
password 2 0~9999
0:no password
relay index 1 Bit0=1 relay on
and relay on/off Bit0=0 relay off
Bit1~bit7=relay index
Relay delay 2 1~65535 unit(second)
second
device reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 2:write relay with delay
Example:
pc send:
FF AA 00 02 34 12 03 05 00 # relay 1 on, delay 5 second off
device reply:
FF AA 00 02
2.2.4 write relay with jogging
pc send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 3:write relay with jogging
password 2 0~9999
0:no password
relay index 1 Bit0=1 relay on
and relay on/off Bit0=0 relay off
Bit1~bit7=relay index
Relay jogging 2 1~65535 unit(100ms)
100ms 1=100ms
5=500ms
device reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 3:write relay with jogging
Example:
pc send:
FF AA 00 03 34 12 05 05 00 # relay 2 on, jogging
device reply:
FF AA 00 03
2.2.5 relay keep alive
device send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
pc not change
relay command 1 4: relay keep alive
device MAC 6 device MAC address
Relay status 1(2/4/8CH) Bit0~31 map to relay1~32
2(16CH) Bit=1 relay on
3(24CH) Bit=0 relay off
4(32CH)
Input status 1(2/4/8CH) Bit0~31 map to input1~32
2(16CH) Bit=1 input High
3(24CH) Bit=0 input Low
4(32CH)
pc reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
pc not change
relay command 1 4: relay keep alive
Example:
device send:
FF AA 00 04 BC 34 88 12 34 56 00 FF # MAC BC:34:88:12:34:56 00:relay1-8 OFF, FF:input1-8 HIGH
pc reply:
FF AA 00 00
2.2.6 write relay with flash
pc send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 8:write relay with flash
password 2 0~9999
0:no password
relay index 1 Bit0=1 relay on
and relay on/off Bit0=0 relay off
Bit1~bit7=relay index
Relay flash 2 1~65535 unit(100ms)
100ms 1=100ms
5=500ms
device reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 8:write relay with flash
Example:
pc send:
FF AA 00 08 34 12 05 05 00 # relay 2 on, flash with 500ms
device reply:
FF AA 00 08
2.2.7 write relay with toggle
pc send
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 9:write relay with toggle
password 2 0~9999
0:no password
relay index 1 Bit0~bit6=relay index
device reply
filed bytes comment
command 1 0xFF
result(xor 0xAA) 1 0 xor 0xAA=0xAA
session 1 0~255
device not change
relay command 1 9:write relay with toggle
Example:
pc send:
FF AA 00 09 34 12 02 # relay 3 toggle
device reply:
FF AA 00 09
2.2.8 find relay baord IP(UDP multicast)
pc send to multicast IP 224.0.2.11:60000
filed bytes comment
command 1 0x05
result(xor 0xAA) 1 0 xor 0xAA=0xAA
device reply
filed bytes comment
command 1 0x05
result(xor 0xAA) 1 0 xor 0xAA=0xAA
find_data 32 response C struct(LSB):
response C struct(LSB):
typedef struct _find_data_{
u32_dt sn;
u32_dt sw_ver;
u32_dt hw_ver;
u32_dt model;
u32_dt ip;
u32_dt netmask;
u32_dt gateway;
u32_dt dns;
} find_data;/* 32 bytes */
Example:
pc send:
05 AA # find relay board IP with UDP multicast
device reply:
head sn sw_ver hw_ver model ip netmask gateway dns
05 AA 14920000 0103D400 06030000 2E000000 6401A8C0 00FFFFFF 0101A8C0 0101A8C0
SN:37396
IP:192.168.1.100
netmask:255.255.255.0
gateway:192.168.1.1
dns:192.168.1.1
3 Protocol:HTTP GET CGI
Relay board as HTTP server, accept HTTP GET CGI request.
Support CGI relay on/off
Support CGI relay jogging
Support CGI relay delay
Support CGI password verification
2:delay
1~65535:time(second)
3:flash
1~255:time(1=100ms)
6 pwd 0~9999 0~9999
Password incurrent device no
response
2:type
1~65535:time(second)
2:delay
1~65535:time(second)
3:flash
1~255:time(1=100ms)
2:delay
1~65535:time(second)
3:flash
1~255:time(1=100ms)
HTTP response:
{"status":0}
3.4 command queue
3.4.1 HTTP Method: GET
HTTP GET request
parameter filed data comment
1 HTTP GET relay_queue.cgi cgi suffix variable
CGI API relay_queue.cgi,
relay_queue.php,
relay_queue.cs
is work ok
2 count 2-64 Max channel * 2
example: 4channel max is 4*2=8
3 pass 0-65535 max 5number password
0: no password
65535: mas password
4... cmd*count P0 0: RELAY_ONOFF command(3 parameters)
P1 Relay index 0-31 map to relay1-32
P2 Relay status 0:OFF 1:ON
P3 Delay n*100ms goto next command.
example n=5 means delay 500ms goto next command
Example 1:
# 0 RELAY_ONOFF relay1 ON, delay 1000ms(10*100ms) goto next command
# 2 RELAY_DELAY relay2 ON 5second then OFF, goto next command immediately
# 6 DELAY 10second
# 4 RELAY_TOGGLE relay1, goto next command immediately
Host: 192.168.1.9
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: session=12345678
Content-Type: text/html
Content-Length: 11
&0&0&0&1&0&
3.8.4 full example(fail)
HTTP GET request:
GET /relay_cgi.cgi?type=0&relay=0&on=0&time=0&pwd=0& HTTP/1.1
Host: 192.168.1.9
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: session=1234567
Content-Type: text/html
Content-Length: 7
&302&/&
4 Protocol:Modbus-RTU/TCP/ASCII
Support Modbus:
Modbus-RTU
Modbus-TCP/UDP
Modbus-ASCII
Modbus-RTU Over TCP/UDP
Modbus-ASCII Over TCP/UDP
Notice:
Modbus-RTU Over UDP/TCP,Modbus-ASCII Over UDP/TCP use RS485 addr
4.1 Registers
Register Name 0x03/0x06/0x10 Value
0x0000 Relay Count 0x03 2/4/8/16/32
0x0001 Relay Status 0x03 bit0~7 map to relay1~8
0x0002 Write Relay 0x06 bit0~7 new status of relay1~8(bit=1 ON,bit=0 OFF)
bit8~15 map to relay1~8 need update(bit=1 Update)
0x0012 Expand Write Relay Mask 1~16 0x10 relay1~16 mask bits; bit=1 need change,bit=0 no change
0x0013 Expand Write Relay mask 17~32 0x10 relay17~32 mask bits; bit=1 need change,bit=0 no change
0x0014 Expand Write Relay bits 1~16 0x10 relay1~16 relay bits; bit=1(ON),bit=0(OFF)
0x0015 Expand Write Relay bits 17~32 0x10 relay17~32 relay bits, bit=1(ON),bit=0(OFF)
Notice:
1、0x0003~6/0x0007~9/0x0012~15 is block,must written at the same time.
4.2 Modbus-RTU + Modbus-RTU Over TCP/UDP
4.2.1 0x03:Read holding register
Read all Relay Status
Send:
01 03 0000 0002 C40B
Recv:
01 03 04 0004 0000 BBF2
example:
below relay board “Serial Number” is 33630
so MQTT client id is:dingtian-relay33630
example:
/dingtian/relay33630/out/input_cnt
/dingtian/relaySN/out/relay_cnt publish 2,4,8,16,32
example:
/dingtian/relay33630/out/relay_cnt
/dingtian/relaySN/out/lwt_availability publish online,offline
example
/dingtian/relay33630/out/
lwt_availability
6 Protocol:CoAP
Relay board as CoAP server, accept CoAP Client request.
Support relay on/off
Support relay jogging
Support relay delay
Support password verification
ON/OFF example:
./coap-client -e "1:ON/OFF:0:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 ON
./coap-client -e "1:ON/OFF:0:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 ON
./coap-client -e "0:ON/OFF:0:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 OFF
./coap-client -e "0:ON/OFF:0:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 OFF
…
./coap-client -e "0:ON/OFF:0:4660" -m put coap://192.168.1.100/dingtian/r32 # relay32 OFF
DELAY example:
./coap-client -e "1:DELAY:5:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY ON 500ms
./coap-client -e "1:DELAY:0:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY stop
./coap-client -e "1:DELAY:5:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY ON 500ms
./coap-client -e "1:DELAY:0:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY stop
./coap-client -e "0:DELAY:5:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY OFF 500ms
./coap-client -e "0:DELAY:0:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY stop
./coap-client -e "0:DELAY:5:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY OFF 500ms
./coap-client -e "0:DELAY:0:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY stop
…
./coap-client -e "0:DELAY:5:4660" -m put coap://192.168.1.100/dingtian/r32 # relay32 DELAY OFF 500ms
JOGGING example:
./coap-client -e "1:JOGGING:5:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY ON 500ms
./coap-client -e "1:JOGGING:0:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY stop
./coap-client -e "1:JOGGING:5:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY ON 500ms
./coap-client -e "1:JOGGING:0:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY stop
./coap-client -e "0:JOGGING:5:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY OFF 500ms
./coap-client -e "0:JOGGING:0:4660" -m put coap://192.168.1.100/dingtian/r1 # relay1 DELAY stop
./coap-client -e "0:JOGGING:5:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY OFF 500ms
./coap-client -e "0:JOGGING:0:4660" -m put coap://192.168.1.100/dingtian/r2 # relay2 DELAY stop
…
./coap-client -e "0:JOGGING:5:4660" -m put coap://192.168.1.100/dingtian/r32 # relay32 DELAY OFF 500ms
TOGGLE example:
./coap-client -e "1:TOGGLE:0:4660" -m put coap://192.168.1.100/dingtian/r1 #relay1 toggle
./coap-client -e "1:TOGGLE:0:4660" -m put coap://192.168.1.100/dingtian/r2 #relay2 toggle
…
./coap-client -e "0:TOGGLE:0:4660" -m put coap://192.168.1.100/dingtian/r32 #relay32 toggle