Construction of Haikang Ehome protocol server

Posted by programming_passion on Sat, 29 Jan 2022 20:13:42 +0100

I Haikang EHome agreement preview process

1.0 introduction

EHOME protocol is a push mode protocol for communication between equipment and server. It is applicable to network camera, network ball machine, DVR, NVR, on-board DVR, on-board forensics system, individual soldier, alarm host and other equipment supporting EHOME protocol.
Haikang devices can actively register the cloud based on the ehome protocol, which is different from the restriction that onvif can only be used in the LAN.
This service software is based on the Haikang private agreement EHOME v2 X version, and strive to build an open source security basic product.

1.1. flow chart

1.2. Access steps of EHOME protocol

The EIKON protocol is used to register the EIKON device with the private address, which is more applicable to the EIKON protocol than the EIKON protocol. The EIKON protocol is used to register the EIKON device with the private address.

Integrating the home SDK to complete the video preview function requires the use of the central management service CMS component and the streaming media service SMS component.

In combination with the above figure, the basic steps to complete the preview playback of home protocol device access are as follows:

1> Call NET_ECMS_XMLConfig and GetDevAbility command obtain the device capability and judge whether preview is supported.
The device capability is returned by pOutBuf.
·If supported, the node will be returned, and you can continue with the following steps.
·Otherwise, end the task.

2> Call NET_ESTREAM_StartListenPreview starts the SMS listening service and receives the connection request from the device.

3> Call NET_ESTREAM_SetExceptionCallBack registers an exception callback function for SMS.

4> The exception information will be called back to the registered callback function. Please handle the exception in time to avoid blocking.

5> Call NET_ECMS_StartGetRealStreamV11 sends the preview start request from CMS to the device.

6> Send the address and port number of SMS to the device, and automatically assign a session ID to CMS.

7> Call NET_ESTREAM_SetPreviewDataCB registers a callback function for SMS to receive real-time streams from devices.

8> Call NET_ECMS_StartPushRealStream sends the real-time streaming request from CMS to the device.

9> The device automatically connects to SMS and starts sending real-time stream to SMS.

II Device registration message

2.2. After the device to platform is registered, the Haikang device will actively connect to the configured ehome platform

Send message as follows

<?xml version="1.0" encoding="GB2312"?>
<PPVSPMessage>
	<!--ehome Protocol version-->
    <Version>2.0</Version> 
   	<!--Signaling interaction serial number-->
    <Sequence>21910</Sequence>
	<!--Indicates that the request was sent-->
	<CommandType>REQUEST</CommandType>
	<!--Device registration command-->	
    <Command>REGISTER</Command>
    <Params>
        <NetUnitType>PU</NetUnitType>
        <!--Equipment serial number: unique-->
        <DeviceID>560796072</DeviceID>
        <!--Device firmware version-->
        <FirmwareVersion>V5.4.5 build 170302</FirmwareVersion>
        <!--Device native IP-->
        <LocalIP>192.168.1.100</LocalIP>
        <!--Device native port-->
        <LocalPort>9486</LocalPort>
        <!--Equipment type: see special documents-->
        <DevType>31</DevType>
        <!--Equipment manufacturer-->
        <Manufacture>0</Manufacture>
    </Params>
</PPVSPMessage>

2.3. After receiving the equipment registration instruction, the EHOME platform

The returned message is as follows

<?xml version="1.0" encoding="GB2312" ?>
<PPVSPMessage>
	<!--The platform version number may not be consistent with the equipment-->
    <Version>2.5</Version>
    <!--Signaling interaction serial number-->	
    <Sequence>21910</Sequence>
    <!--Indicates that a reply is sent-->
    <CommandType>RESPONSE</CommandType>
    <!--Indicates that the reply is registration signaling-->
    <Method>REGISTER</Method>
    <WhichCommand>REGISTER</WhichCommand>
    <!--Registration status code-->
    <Status>200</Status>
    <!--Status code description-->
    <Description>OK</Description>
    <Params>
    	<!--Keep alive interval in seconds-->
        <KeepAliveSeconds>15</KeepAliveSeconds>
        <!--Platform alarm service information-->
        <AlarmServerIP>10.21.84.13</AlarmServerIP>
        <AlarmServerPort>7332</AlarmServerPort>
        <AlarmServerType>2</AlarmServerType>
        <!--Time synchronization configuration information-->
        <NTPServerIP>10.17.132.231</NTPServerIP>
        <NTPServerPort>123</NTPServerPort>
        <NTPInterval>3600</NTPInterval>
        <!--Picture service information-->
        <PictureServer>10.21.84.48</PictureServer>
        <PictureServerPort>10002</PictureServerPort>
        <PictureServerType>2</PictureServerType>   
        <!--Basically meaningless-->
        <BlackListAddr></BlackListAddr>
        <BlackListName></BlackListName>
        <BlackListPort>0</BlackListPort>
        <BlackListUser></BlackListUser>
        <BlackListPassword></BlackListPassword>
        <RegisterServerIP></RegisterServerIP>
        <RegisterServerPort>0</RegisterServerPort>
    </Params>
</PPVSPMessage>

III Preview request message

3.1. Platfrom = > > device, ehome platform launch Preview

Request message

<?xml version="1.0" encoding="GB2312" ?>
<PPVSPMessage>
    <Version>2.5</Version>
    <Sequence>3566</Sequence>
    <CommandType>REQUEST</CommandType>
    <Method>MEDIA</Method>
    <Command>INVITESTREAM</Command>
    <Params>
    	<!-- Request device channel number-->
        <Channel>1</Channel>
        <!-- Request device bitstream type: MAIN:Main code stream, SUB: Sub code stream, THIRD: Three bit stream-->
        <ChannelType>MAIN</ChannelType>
        <SinkIP>192.168.1.133</SinkIP>
        <SinkPort>8000</SinkPort>
    </Params>
</PPVSPMessage>

3.2. Device = > > platform, the device returns to the platform request stream

Return message

<?xml version="1.0" encoding="GB2312"?>
<PPVSPMessage>
    <Version>2.0</Version>
    <Sequence>3566</Sequence>
    <CommandType>RESPONSE</CommandType>
    <WhichCommand>INVITESTREAM</WhichCommand>
    <!-- Status code after the current request flow, 200 indicates success, see error code for others-->
    <Status>200</Status>
    <Description>OK</Description>
    <Params>
        <!-- Current request flow location indicator, similar to ssrc-->
        <Session>679647373</Session>
    </Params>
</PPVSPMessage>

3.3. Platfrom = > > device, stop VOD

Request message

<?xml version="1.0" encoding="GB2312" ?>
<PPVSPMessage>
    <Version>2.5</Version>
    <Sequence>8068</Sequence>
    <CommandType>REQUEST</CommandType>
    <Method>MEDIA</Method>
    <Command>BYESTREAM</Command>
    <Params>
    	<!--With the start of on-demand Session agreement -->
        <Session>679647373</Session>
    </Params>

3.4. Device = > > platfrom, the device returns the stop status to the platform

Return as follows

<?xml version="1.0" encoding="GB2312"?>
<PPVSPMessage>
    <Version>2.0</Version>
    <Sequence>8068</Sequence>
    <CommandType>RESPONSE</CommandType>
    <WhichCommand>BYESTREAM</WhichCommand>
    <Status>200</Status>
    <Description>OK</Description>
    <Params>
    	<!--With the start of on-demand Session agreement -->
        <Session>679647373</Session>
    </Params>
</PPVSPMessage>

Hello! This is the first time you have used the welcome page displayed by the Markdown editor. If you want to learn how to use the Markdown editor, you can read this article carefully to understand the basic grammar of Markdown.

IV Video stream

4.1. Haikang's camera is on demand through TCP through Haikang ehome protocol. The stream pushed by the camera is not a standard PS stream

The stream format is as follows

2400013980600000000000000a689ebc0d000001ba5e269c2ee401028f63feffff007d4909000001e000128c80092789a70bb9fffffffc000000010930000001e0001a8c0005fffffffffc00000001060109004e082468000003000180000001e000da8c0004fffffff80000000161e2727088000411c4469504636f3802c8118505f81b0b3171564e0668c371e18a3614cf05a24bcf006d9a6ad1ffc3efc7917c8cce99343b4e839750fefd8f32361ab3270444fbc90eb51586ad45d445f11ec996ea36aeab6446958282a9f687350a42463ed140d4465783237338b91d4c0dbebb8d3cc61e8092cd7124f6dd41c30f87771e399896cd633c0dfb6fcab16d472c25788870ee859f7eabce0c982024ca0eabdaaec2422ac14929c0002792538f0c0b7ed51d0ef09988ca548018530494fcdfd400000300b929180062c0

It can be seen that 000001ba is the header of PS stream and PS is loaded in RTP package. Let's analyze the bytes in front of PS header:

24 00 01 39 80 60 00 00 00 00 00 00 0a 68 9e bc 0d

The first two bytes of 24 00 are '$', which is a bit like the rtsp protocol of tcp transmission;
01 39 is the length of RTP package, here 313;
80 60 00 00 00 00 0a 68 9e bc is the standard 12 bit RTP header, in which the 3rd and 4th bytes are the sequence number, here is 00 00, 0a 68 9e bc is ssrc;
0d, which is considered as the separator between RTP header and PS package.

V Build home server

5.1. Open source project

https://github.com/tsingeye/FreeEhome link.

5.2. Download and compile the complete program

https://github.com/tsingeye/FreeEhome/releaseslink.

5.3. Modify CMS configuration

Enter the freeehomecms = > conf folder
According to app The notes in the conf file are modified according to the actual situation, as follows:

#ehomeCMS service address
udpAddr = "192.168.1.72:7660"
#Streaming media SMS address
streamStartIP = "192.168.1.72"
streamStartPort = 10000
#Live broadcast waiting timeout, 3 seconds by default
waitStreamSessionTime = 3
#The timeout for closing the live broadcast is 3 seconds by default
waitHookSessionTime = 3

#The streaming media distribution service configuration must be in English; Split
streamIP = "192.168.1.72;192.168.1.72"
#hls port
hlsPort = "10080;10080"
#rtmp port
rtmpPort = "1935;1935"
#rtsp port
rtspPort = "10554;10554"

PS. the IP and ports mentioned above shall be modified according to the actual configuration and SMS

5.1 modify SMS configuration

Enter FreeEhomeSMS folder
Found config INI file, which can be modified optionally. The streaming media distribution port must be consistent with the configuration in CMS.
[hook] if CMS and SMS are on the same machine, you don't need to repair it. Otherwise, it is modified to the actual address of CMS here
[rtp_proxy] part of the configuration is the collection address of Haikang ehome protocol, which should be consistent with CMS

[rtp_proxy]
checkSource=1
dumpDir=
port=10000
timeoutSec=15
[hook]
admin_params=secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc
enable=1
on_flow_report=
on_http_access=
on_play=
on_publish=http://127.0.0.1:8080/index/hook/on_publish
on_record_mp4=
on_rtsp_auth=
on_rtsp_realm=
on_server_started=
on_shell_login=
on_stream_changed=
on_stream_none_reader=http://127.0.0.1:8080/index/hook/on_stream_none_reader
on_stream_not_found=http://127.0.0.1:8080/index/hook/on_stream_not_found
timeoutSec=20

5.2 operation

At present, the release version only supports Windows platform

1. Run in terminal mode: double click freeehome exe MediaServer. Exe

2. Run in service mode: double click to execute install Bat can be installed as system service; uninstall.bat serves for unloading the system; MediaServer does not support Windows system services.

5.3 operation cms


5.4 running SMS

5.5 access project

http://localhost:8081
admin 123456

5.6 equipment query and Preview

5.7 front end project compilation and operation

1. Development tool VScode
2. Development environment vue (online reference)
3. Download items https://github.com/tsingeye/FreeEhome link.
4. Import projectadd folder to workspace Add Folder to Workspace
5. Download cnpm component compilation environment
6. Change the project configuration api interface platform address

7. Compile the project

# install dependencies
set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy RemoteSigned -Scope Process
cnpm install

8. Operation project

# serve with hot reload at localhost:8080
cnpm run dev

9. Browser access

http://localhost:8081/     admin  123456

Thanks to the blogger: the open source project provided by tsingeye https://github.com/tsingeye
The above summary is all personal and online experience summary. If there are similarities, please understand. Welcome to discuss technology, pay attention and continue to update later

Topics: Java Linux network Vue.js RESTful