CN106912100B - Time Synchronization Method of Home Appliance Network Based on TPSN and TSync - Google Patents
Time Synchronization Method of Home Appliance Network Based on TPSN and TSync Download PDFInfo
- Publication number
- CN106912100B CN106912100B CN201710150367.5A CN201710150367A CN106912100B CN 106912100 B CN106912100 B CN 106912100B CN 201710150367 A CN201710150367 A CN 201710150367A CN 106912100 B CN106912100 B CN 106912100B
- Authority
- CN
- China
- Prior art keywords
- time
- node
- synchronization
- nodes
- network
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W56/00—Synchronisation arrangements
- H04W56/001—Synchronization between nodes
- H04W56/0015—Synchronization between nodes one node acting as a reference for the others
-
- G—PHYSICS
- G04—HOROLOGY
- G04R—RADIO-CONTROLLED TIME-PIECES
- G04R20/00—Setting the time according to the time information carried or implied by the radio signal
- G04R20/02—Setting the time according to the time information carried or implied by the radio signal the radio signal being sent by a satellite, e.g. GPS
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04J—MULTIPLEX COMMUNICATION
- H04J3/00—Time-division multiplex systems
- H04J3/02—Details
- H04J3/06—Synchronising arrangements
- H04J3/0635—Clock or time synchronisation in a network
- H04J3/0638—Clock or time synchronisation among nodes; Internode synchronisation
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Radar, Positioning & Navigation (AREA)
- Remote Sensing (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Synchronisation In Digital Transmission Systems (AREA)
- Mobile Radio Communication Systems (AREA)
Abstract
本发明公开了一种基于TPSN和TSync的家电网络时间同步方法,包括以下步骤:S1、在智能家电增设一个GPS信号接收器,并以此智能家电节点作为时间同步的根节点,并确立或者更新根节点;S2、确定源时间:设定源时间从(TG,TB,TS)三者中获取。S3、选择同步方式。本发明所述的基于TPSN和TSync的家电网络时间同步方法,对于同步源时间的确定,没有选取单一的时间源,而是是综合了GPS信号接收器和网络服务器以及节点内部时钟针对不同的情况,采取不同的时间源,进而使得时间同步的有效性大大提高,避免了时间同步的时间盲区,是一种针对不同的情形采取不同的无线网络节点时间同步方法。
The invention discloses a home appliance network time synchronization method based on TPSN and TSync, which includes the following steps: S1. Add a GPS signal receiver to the smart home appliance, and use the smart home appliance node as the root node of time synchronization, and establish or update Root node; S2. Determine the source time: set the source time to be obtained from (T G , T B , T S ). S3. Select a synchronization mode. The home appliance network time synchronization method based on TPSN and TSync described in the present invention does not select a single time source for the determination of the synchronization source time, but integrates the GPS signal receiver, the network server and the internal clock of the node for different situations. , adopting different time sources, thereby greatly improving the effectiveness of time synchronization, avoiding the time blind zone of time synchronization, is a method for adopting different wireless network node time synchronization methods for different situations.
Description
技术领域technical field
本发明涉及智能家电无线网络的监测数据时间同步方法,特别涉及到一种基于TPSN方法和TSync混合时间同步方法。The invention relates to a monitoring data time synchronization method of a smart home appliance wireless network, in particular to a hybrid time synchronization method based on a TPSN method and TSync.
背景技术Background technique
目前,智能电网,是电力行业新的发展方向,其实现取决于实时精确地掌握电网各个环节的信息。作为“智能信息感知末梢”的家庭用电网络,为电力运行管理部门提供精准的,各用电器运行信息时间同步的数据,必将为推动智能电网发展的提供重要动力。At present, the smart grid is a new development direction of the power industry, and its realization depends on the real-time and accurate grasp of the information of each link of the power grid. As the "intelligent information perception end", the household electricity network provides accurate and time-synchronized data for the power operation management department, which will surely provide an important impetus for promoting the development of the smart grid.
从上世纪末至本世纪初,世界各国开始采用信息技术、微电子技术和计算机技术对传统低压电器进行技术提升,技术上已取得重大突破,使电网用户端电气设备初步实现了可通信、智能控制和网络控制。通过计算机网络,精确地检测、计算和监视用户端电气设备的运行状态,使配电网络达到最佳的配合,大大地提高了电网运行的经济性安全性和可靠性,并为用户端电气设备的系统集成、实现负载监控、故障预警、电能质量管理、电能管理、分布式新能源的接入、分布式储能装置接入等功能奠定了技术基础。双向通信、双向计费以及电网与用户的互动,也将大大提高能源利用效率。因此,智能电网用户端电气设备对智能电网的节能、安全、可靠运行,对新能源的开发、应用,对提高能源效率起着十分重要的作用,是坚强智能电网的重要组成部分。From the end of the last century to the beginning of this century, countries around the world began to use information technology, microelectronics technology and computer technology to upgrade the traditional low-voltage electrical appliances, and a major breakthrough has been made in technology, making the electrical equipment at the user end of the power grid initially realize communication and intelligent control. and network control. Through the computer network, accurately detect, calculate and monitor the operating status of the user-side electrical equipment, so that the power distribution network can achieve the best coordination, greatly improving the economic security and reliability of the power grid operation, and providing user-side electrical equipment It has laid a technical foundation for system integration, load monitoring, fault warning, power quality management, power management, access to distributed new energy, and access to distributed energy storage devices. Two-way communication, two-way billing, and the interaction between the grid and users will also greatly improve energy efficiency. Therefore, the smart grid user-side electrical equipment plays a very important role in the energy saving, safe and reliable operation of the smart grid, the development and application of new energy, and the improvement of energy efficiency. It is an important part of a strong smart grid.
家庭能量管理系统是指以信息和通信技术为手段,以在实现用户电器管理、监测和减少能量消费为目标。对于实现各个家庭用电设备的协调控制,达成管理目标,各个智能用电设备的时间同步是必不可少的。能够实现家电网络各节点的时间同步,对于智能家电相关的科研也有重大意义,对于智能家电运行模型建立,智能家电故障诊断有着很重要的价值。The home energy management system refers to the use of information and communication technology as a means to realize the management, monitoring and reduction of energy consumption of user electrical appliances. To realize the coordinated control of various household electrical equipment and achieve management goals, the time synchronization of each intelligent electrical equipment is essential. Being able to realize the time synchronization of each node of the home appliance network is also of great significance for scientific research related to smart home appliances. It is also of great value for the establishment of smart home appliance operation models and smart home appliance fault diagnosis.
为了使得智能家电网络所有节点的监测数据能够相互参考,便于对整个家电网络进行协同控制和家庭能量消费优化,因此需要对所有智能家电节点进行时间同步。时间同步后的监测数据将具有更高的科研价值,能够为家庭能量管理系统的设计和相关研究提供更加精确合理的数据。In order to make the monitoring data of all nodes of the smart home appliance network refer to each other, and facilitate the coordinated control of the entire home appliance network and the optimization of household energy consumption, it is necessary to synchronize the time of all smart home appliance nodes. The monitoring data after time synchronization will have higher scientific research value, and can provide more accurate and reasonable data for the design and related research of the home energy management system.
随着未来社会的发展,智能家居所包含的家电设备会很多,其中一些包括消防安全监测的设备需要不间断工作,因此为了提高时间同步的可靠性,增加时间同步源时间的可信度。With the development of the future society, there will be many home appliances included in the smart home, and some of them, including fire safety monitoring equipment, need to work continuously. Therefore, in order to improve the reliability of time synchronization, the credibility of the time synchronization source time should be increased.
因此,设计出一种家电网络各节点的时间同步方法成为了人们亟待解决的问题。Therefore, designing a time synchronization method for each node of the home appliance network has become a problem to be solved urgently.
发明内容Contents of the invention
根据上述提出的技术问题,而提供一种基于TPSN和TSync的家电网络时间同步方法,用于解决现有技术中缺少一种可靠的家电网络各节点的时间同步方法的缺点。本发明采用的技术手段如下:According to the above-mentioned technical problems, a time synchronization method for home appliance network based on TPSN and TSync is provided, which is used to solve the shortcoming of lacking a reliable time synchronization method for each node of home appliance network in the prior art. The technical means adopted in the present invention are as follows:
一种基于TPSN和TSync的家电网络时间同步方法,包括以下步骤:A kind of home appliance network time synchronization method based on TPSN and TSync, comprises the following steps:
S1、确立根节点:在智能家电增设一个GPS信号接收器,并以此智能家电节点作为时间同步的根节点,设定无线传感网络中有N个节点,获取所有节点的时间,GPS时间TG,网络服务器时间TS,本地根节点时间TB,并确立或者更新根节点。S1. Establish the root node: add a GPS signal receiver to the smart home appliance, and use the smart home appliance node as the root node for time synchronization, set N nodes in the wireless sensor network, and obtain the time of all nodes, GPS time T G , the network server time T S , the local root node time T B , and establish or update the root node.
S2、确定源时间:S2. Determine the source time:
设定源时间从(TG,TB,TS)三者中获取;当TG有效,则TG优先级最高,作为源时间;当TG无效,TS有效,则TS优先级仅次于TG,作为源时间;当TG无效,TS无效,则选择TB作为源时间。Set the source time to be obtained from (T G , T B , T S ); when T G is valid, T G has the highest priority as the source time; when T G is invalid and T S is valid, T S has the highest priority Second only to T G , as the source time; when T G is invalid and T S is invalid, select T B as the source time.
S3、选择同步方式:采用连续同步和按需同步互补方式进行同步;连续同步采用TSync算法进行时间同步,设置为规定时间内同步一次;按需同步采用TPSN算法进行时间同步,根据用户自由选择进行时间同步。S3. Select the synchronization method: use continuous synchronization and on-demand synchronization complementary methods for synchronization; continuous synchronization uses TSync algorithm for time synchronization, set to synchronize once within a specified time; on-demand synchronization uses TPSN algorithm for time synchronization, according to the user's free choice Time synchronization.
作为优选步骤S1中所述的确立或者更新根节点的方法具体包括以下步骤:The method for establishing or updating the root node as described in the preferred step S1 specifically includes the following steps:
S11、临时变量用Ttemp表示,Ttemp=α×TS+β×TG,(α+β)=1。S11. The temporary variable is represented by T temp , T temp =α×T S +β×T G , (α+β)=1.
S12、当TS和TG都能够准确获取,则Ttemp=α×TS+β×TG,(α+β)=1,其中权值分配上,使得α=0.3,β=0.7。S12. When both T S and T G can be obtained accurately, then T temp =α×T S +β×T G , (α+β)=1, where the weights are distributed such that α=0.3, β=0.7.
当TS能够获得,而TG无法获得,则使TG=0,α=1,则Ttemp=TS。When T S can be obtained but T G cannot be obtained, T G =0, α=1, then T temp =T S .
当TG能够获得,而TS无法获得,则使TS=0,β=1,那么Ttemp=TG。When T G can be obtained but T S cannot be obtained, T S =0, β=1, then T temp =T G .
当TG和TS均无法获得,使TG=0,TS=0,则Ttemp=0。When neither T G nor T S can be obtained, T G =0, T S =0, then T temp =0.
S13、获取无线网络中N个节点的内部时钟{T1,T2,T3……TN},然后根据公式(1.1)计算每一个内部时钟与Ttemp的差值的最小值:S13. Obtain the internal clocks {T 1 , T 2 , T 3 ... T N } of N nodes in the wireless network, and then calculate the minimum value of the difference between each internal clock and T temp according to formula (1.1):
{abs(T1-Ttemp),abs(T2-Ttemp),abs(T3-Ttemp),……abs(TN-Ttemp)}min (1.1)。{abs(T 1 -T temp ), abs(T 2 -T temp ), abs(T 3 -T temp ),... abs(T N -T temp )} min (1.1).
S14、当abs(TK-Ttemp)的值最小,则选取第K个节点为根节点;当Ttemp=0,则不更新根节点。S14. When the value of abs(T K −T temp ) is the smallest, select the Kth node as the root node; when T temp =0, do not update the root node.
作为优选步骤S2中GPS时间TG的有效性判定具体包括以下步骤:As the validity judgment of GPS time T G in the preferred step S2 specifically comprises the following steps:
—比较TG与TB和TS之间的误差,取值最大的{abs(TG-TS),abs(TG-TB)}max,当最大误差时间大于10min,则认定GPS接收器出现故障,进而判定GPS时间TG无效。—Comparing the error between T G and T B and T S , take the largest value {abs(T G -T S ),abs(T G -T B )} max , when the maximum error time is greater than 10min, then consider GPS The receiver fails, and the GPS time T G is determined to be invalid.
—当时间服务器出现故障或者网络中断,则判断abs(TG-TB)是否大于10min,当abs(TG-TB)大于10min,则认为GPS接收器出现故障,进而判定GPS时间TG无效。—When the time server fails or the network is interrupted, judge whether the abs(T G -T B ) is greater than 10 minutes. When the abs(T G -T B ) is greater than 10 minutes, it is considered that the GPS receiver is faulty, and then determine the GPS time T G invalid.
—对最近30min时间的GPS接收到的时间值进行五次差值运算,- Perform five difference calculations on the time value received by GPS in the last 30 minutes,
{T1,T2,T3,T4……Tmax},其中max相当于30min时间内获取的所有时间点数目,如果GPS信号没有一点时间缺失的话max=1800,实际以存储的时间数据为准,{T 1 , T 2 , T 3 , T 4 ... T max }, where max is equivalent to the number of all time points acquired within 30 minutes, if the GPS signal does not have any time missing, then max=1800, the actual time data stored prevail,
进行第一次差值运算,获取{T11,T12,T13,T1i……T1(max-1)},其中T1i=Ti+1-Ti,i=(1,2,3,4……max-1);Perform the first difference operation to obtain {T 11 , T 12 , T 13 , T 1i ... T 1(max-1) }, where T 1i =T i+1 -T i , i=(1,2 ,3,4...max-1);
进行第二次差值运算,{T21,T22,T23,T2i……T2(max-2)},其中T2i=T1i+1-T1i,i=(1,2,3,4……max-2);Perform the second difference operation, {T 21 , T 22 , T 23 , T 2i ... T 2(max-2) }, where T 2i =T 1i+1 -T 1i , i=(1,2, 3,4...max-2);
以此类推,第k次差值运算,{Tk1,Tk2,Tk3,Tki……Tk(max-k)},其中Tki=T(k-1)i+1-T(k-1)i,i=(1,2,3,4……max-k);By analogy, the k-th difference operation, {T k1 , T k2 , T k3 , T ki ... T k(max-k) }, where T ki =T (k-1)i+1 -T ( k-1)i , i=(1,2,3,4...max-k);
进行到第五次差值所得到的结果{T51,T52,T53,T5i……T5(max-5)}max如果小于1s则认为GPS信号获取的时间TG有效,否则放弃GPS时间TG作为时间源。The result of the fifth difference is {T 51 , T 52 , T 53 , T 5i ... T 5(max-5) } max If it is less than 1s, the time T G of GPS signal acquisition is considered valid, otherwise give up GPS time T G as time source.
作为优选步骤S2中网络服务器时间TS的有效性判定:As the validity judgment of the network server time T S in the preferred step S2:
当断网情况下,端口网络时间无法获得,则网络服务器时间TS设置为0,TS无效。When the network is disconnected and the port network time cannot be obtained, the network server time T S is set to 0, and T S is invalid.
当联网情况下,基于NTP服务地址获取网络时间,无线网络内部时间确定,网络层次的发现与建立,具体包括以下步骤:In the case of networking, the network time is obtained based on the NTP service address, the internal time of the wireless network is determined, and the discovery and establishment of the network level specifically includes the following steps:
S21、根节点设置自己的层次号为1。S21. The root node sets its own level number to 1.
S22、根节点广播一个信息包,包含根节点的ID以及层次号。S22. The root node broadcasts an information packet, which includes the ID and the layer number of the root node.
S23、当通信范围内的节点收到信息包,将自己的层次级别设置为信息包中层次号加1。S23. When a node within the communication range receives the information packet, it sets its own hierarchical level as the hierarchical number in the information packet plus 1.
S24、接收节点广播新的包含自己的ID和层次号的信息包,接收到的节点以同样的方式设置自己的层次号。S24. The receiving node broadcasts a new information packet containing its own ID and layer number, and the receiving node sets its own layer number in the same manner.
S25、重复步骤S24,直到整个网络中的节点都建立自己的层级级别,其中已有层次号的节点再次接收到广播的信息包时,做忽略处理。S25. Step S24 is repeated until all the nodes in the entire network have established their own hierarchical levels. When the nodes with existing hierarchical numbers receive the broadcasted information packet again, they will be ignored.
S26、假设最后建立的层次为k层,{1,2,3……k}层的节点个数为{n1,n2,n3,……nk},总节点个数为N,则计算每一层的概率设置为{p1,p2,p3,……pk}分别为 S26. Assuming that the last established layer is k layer, the number of nodes in {1,2,3...k} layer is {n 1 ,n 2 ,n 3 ,...n k }, and the total number of nodes is N, Then calculate the probability of each layer as {p 1 ,p 2 ,p 3 ,...p k } are respectively
S27、根据不同的概率来计算内部节点时间的期望值,每一层选取一个节点,这样避免了层中节点的失效,获取它们的时间分别为{T1i,T2i,T3i……Tki},此时间下标中{1i≤n1,2i≤n2,3i≤n3,……ki≤nk},计算时间期望 S27. Calculate the expected value of internal node time according to different probabilities, select a node for each layer, so as to avoid the failure of nodes in the layer, and obtain their time respectively as {T 1i , T 2i , T 3i ... T ki } , in this time subscript {1i≤n 1 ,2i≤n 2 ,3i≤n 3 ,…ki≤n k }, the calculation time expectation
S27、无线网络中N个节点的内部时钟{T1,T2,T3……TN}与时间期望ET进行差值计算,误差最小的时间{abs(T1-ET),abs(T2-ET),abs(T3-ET),……abs(TN-ET)}min作为无线网络内部时钟的源时间。S27. Calculate the difference between the internal clocks {T 1 , T 2 , T 3 ... T N } of N nodes in the wireless network and the time expectation E T , and the time with the smallest error {abs(T 1 -E T ), abs (T 2 -E T ),abs(T 3 -E T ),…abs(T N -E T )} min is used as the source time of the internal clock of the wireless network.
作为优选步骤3中连续同步所述的TSync算法是通过HRTS和ITR两种算法来进行同步,HRTS是同步根节点发出同步信号进行同步的,ITR是通过普通的节点向临近节点发出同步请求,并最终将请求传递给根节点的一种同步方式,两者互相补充,同时运行,属于主动同步和请求同步互补。As the TSync algorithm described in the continuous synchronization in the preferred step 3 is to synchronize by HRTS and ITR two algorithms, HRTS is that the synchronization root node sends a synchronization signal to synchronize, ITR is to send a synchronization request to an adjacent node by a common node, and A synchronization method that finally passes the request to the root node. The two complement each other and run at the same time. It belongs to the complementary of active synchronization and request synchronization.
作为优选所述的HRTS算法同步具体包括以下步骤:As preferably described HRTS algorithm synchronization specifically comprises the following steps:
S311、根节点在控制信道在时间t1广播一个sync_begin信标。S311. The root node broadcasts a sync_begin beacon on the control channel at time t1.
S312、根节点随机指定的一个子节点跳到指定的时钟信道进行回复,例如n2。S312. A child node randomly designated by the root node jumps to a designated clock channel to reply, for example, n2.
S313、节点n2在时间t3回复给根节点自己的接收时间t2和t3。S313. Node n2 replies to the root node its own receiving time t2 and t3 at time t3.
S314、根节点记录接收到的时间戳t4,这样根节点拥有t1-t4所有的时间戳。S314. The root node records the received timestamp t4, so that the root node has all the timestamps of t1-t4.
S315、根节点计算时间d2,然后广播t2,d2给控制信道的所有节点,其中 S315. The root node calculates the time d2, and then broadcasts t2 and d2 to all nodes of the control channel, wherein
S316、所有临近子节点,例如n2,n3,n4,n5,比较时间t2和接收时间戳t2',例如n3计算时间漂移d'd'=t2-t2'。S316. All adjacent child nodes, such as n2, n3, n4, and n5, compare the time t2 with the received timestamp t2', for example, n3 calculates the time drift d'd'=t2-t2'.
S317、节点n3的时间校正为T=t+d2+d',其中t为n3节点的本地时间;S317, the time of node n3 is corrected as T=t+d2+d', where t is the local time of node n3;
S318、节点n2,n3,n4,n5初始化sync_begin信标给它们的下游节点,重复以上步骤。S318. Nodes n2, n3, n4, and n5 initialize sync_begin beacons to their downstream nodes, and repeat the above steps.
作为优选所述的ITR算法同步具体包括以下步骤:As preferably described ITR algorithm synchronization specifically comprises the following steps:
S321、节点n1在控制信道中发送ITR_QUERY信号,发送同步请求的时钟信道在ITR_QUERY中被指定。S321. The node n1 sends an ITR_QUERY signal in the control channel, and the clock channel for sending the synchronization request is specified in the ITR_QUERY.
S322、节点n1的父节点n2收到请求后,会在控制信道发送ITR_ACK信号通知它的父节点,本实例图中是根节点BS;一般情况下,上游父节点会一直发送ITR_ACK信号直到到达根节点。S322. After the parent node n2 of node n1 receives the request, it will send an ITR_ACK signal to notify its parent node in the control channel. In this example, it is the root node BS; under normal circumstances, the upstream parent node will send the ITR_ACK signal until it reaches the root node. node.
S323、节点n2的父节点BS,接受到ITR_ACK后,转换到指定的时钟信道,时钟信道信息包含在ITR_ACK中;沿ITR_ACK传播路径上的所有节点都转换到指定的时钟信道。S323. After receiving the ITR_ACK, the parent node BS of the node n2 switches to the specified clock channel, and the clock channel information is included in the ITR_ACK; all nodes along the propagation path of the ITR_ACK switch to the specified clock channel.
S324、节点n2接收到n1的同步请求,通过指定的时钟信道发送到节点BS。S324. Node n2 receives the synchronization request from n1 and sends it to node BS through a specified clock channel.
S325、节点BS发起同样的过程发送时间给节点n1。S325. The node BS initiates the same process to send the time to the node n1.
S326、节点n1根据节点BS反馈的时间同步自己的时间。S326. The node n1 synchronizes its own time according to the time fed back by the node BS.
作为优选步骤3中连续同步所述的按需同步TPSN算法包括层次发现阶段和同步阶段,所述层次发现阶段,每个节点拥有自己的层次号,把具有层次的网络结构看成生成树,具体包括以下步骤:The on-demand synchronous TPSN algorithm described as continuous synchronization in the preferred step 3 includes a hierarchy discovery stage and a synchronization stage. In the hierarchy discovery stage, each node has its own hierarchy number, and the network structure with hierarchy is regarded as a spanning tree, specifically Include the following steps:
S331、树的根节点担任时钟源节点,设其层次号为0。S331. The root node of the tree serves as the clock source node, and its level number is set to 0.
S332、根节点广播一个信息包,包含根节点的ID以及层次号。S332. The root node broadcasts an information packet, which includes the ID and the layer number of the root node.
S333、当通信范围内的节点收到信息包,将自己的层次级别设置为信息包中层次号加1。S333. When a node within the communication range receives the information packet, it sets its own hierarchy level to the hierarchy number in the information packet plus 1.
S334、接收节点广播新的包含自己的ID和层次号的信息包,接收到的节点以同样的方式设置自己的层次号。S334. The receiving node broadcasts a new information packet containing its own ID and layer number, and the receiving node sets its own layer number in the same manner.
S335、重复步骤S334,直到整个网络中的节点都建立自己的层级级别,已有层次号的节点再次接收到广播的信息包时,做忽略处理。S335. Step S334 is repeated until all the nodes in the entire network have established their own hierarchical levels. When the nodes with existing hierarchical numbers receive the broadcast information packet again, they ignore it.
所述同步阶段具体包括以下步骤:The synchronization phase specifically includes the following steps:
S341、节点R和节点S的层次号分别为第k层和第k+1层,同步时,上层节点R广播一个时间同步请求信息包,通知S节点做好时间同步的准备。S341. The layer numbers of node R and node S are the kth layer and the k+1th layer respectively. During synchronization, the upper layer node R broadcasts a time synchronization request packet to notify S node to prepare for time synchronization.
S342、节点S经过一段随机时间的等待后,在T1时刻向节点R发送含有时刻T1的同步信息包。S342. After waiting for a random period of time, the node S sends a synchronization information packet containing the time T1 to the node R at the time T1.
S343、节点R接收到信息包后,使用本地时钟来记录接收时间T2,则有:T2=T1+Δ+d,其中,Δ表示节点间的时间偏移,d表示消息的传输时延。S343. After receiving the information packet, the node R uses the local clock to record the receiving time T 2 , then: T 2 =T 1 +Δ+d, where Δ represents the time offset between nodes, and d represents the transmission time of the message delay.
S344、节点R以同样的方式在时刻T3向节点S发送一个确认消息,该消息中包含(T1、T2、T3)。S344. Node R sends a confirmation message to node S at time T 3 in the same manner, and the message includes (T 1 , T 2 , T 3 ).
S345、节点S在T4时刻用本地时间记录下接收消息的时间T4,满足:T4=T3-Δ+d,其中,Δ表示节点间的时间偏移,d表示消息的传输时延;由公式T2=T1+Δ+d和T4=T3-Δ+d得到:S345. Node S records the time T 4 of receiving the message in local time at T 4 , which satisfies: T 4 =T 3 -Δ+d, where Δ represents the time offset between nodes, and d represents the transmission delay of the message ; Obtained by the formulas T 2 =T 1 +Δ+d and T 4 =T 3 -Δ+d:
和 and
S346、根据步骤S345的计算结果修改节点的时间为一致。S346. Modify the time of the nodes to be consistent according to the calculation result of step S345.
与现有技术相比较,本发明所述的基于TPSN和TSync的家电网络时间同步方法,在步骤S1中,对于同步源时间的确定,没有选取单一的时间源,而是是综合了GPS信号接收器和网络服务器以及节点内部时钟针对不同的情况,采取不同的时间源,进而使得时间同步的有效性大大提高,避免了时间同步的时间盲区。Compared with the prior art, the home appliance network time synchronization method based on TPSN and TSync described in the present invention, in step S1, does not select a single time source for the determination of the synchronization source time, but integrates GPS signal reception Servers, network servers, and internal clocks of nodes adopt different time sources for different situations, which greatly improves the effectiveness of time synchronization and avoids time blind spots in time synchronization.
在步骤S2中,对于GPS时间的有效性判定采用了五次差值法,而对于无线网络内部时间采取了先确立网络层次,然后根据网络层次的节点数量来分配概率值,进而计算期望值来获取更具有可靠性的时间。In step S2, the five-time difference method is used to determine the validity of GPS time, and the internal time of the wireless network is adopted to first establish the network level, then assign probability values according to the number of nodes in the network level, and then calculate the expected value to obtain A more reliable time.
对于网络服务器时间的获取选取了多个的时间服务器地址作为备用,以中国国家授时中心的时间作为首先。在源时间的获取后,设置了不同的优先级,以GPS时间优先级最高,网络服务器时间次之和本地时间优先级最低来根据不同的情况来确定源时间。For the acquisition of the network server time, multiple time server addresses are selected as backups, and the time of the China National Time Service Center is used as the first. After the source time is acquired, different priorities are set, the GPS time has the highest priority, the network server time takes the second place, and the local time has the lowest priority to determine the source time according to different situations.
在确定了源时间之后根据,步骤S3中,用户选择不同的时间同步算法,来决定进行连续时间同步还是按需时间同步,连续时间同步是同步时间周期较短的时间同步方法,时间同步间隔设置为0.5小时或1小时,TSync同步算法,是由科罗拉多大学Richard Han和HuiDai提出的,是一种灵活的、自组织的、没有固定网络拓扑结构和传输延迟的时间同步服务。After determining the source time, in step S3, the user selects a different time synchronization algorithm to decide whether to perform continuous time synchronization or on-demand time synchronization. Continuous time synchronization is a time synchronization method with a shorter synchronization time period, and the time synchronization interval is set It is 0.5 hours or 1 hour. The TSync synchronization algorithm, proposed by Richard Han and HuiDai of the University of Colorado, is a flexible, self-organizing time synchronization service without fixed network topology and transmission delay.
按需同步则是根据用户的需求,决定同步时间,没有一定的时间间隔,按需同步采取TPSN协议的时间同步方法。On-demand synchronization is to determine the synchronization time according to the user's needs. There is no certain time interval, and the time synchronization method of the TPSN protocol is adopted for on-demand synchronization.
两种时间同步算法的采用的,是根据两种算法的特点来进行的,综合两种算法的优点,TSync同步算法是一种轻量级算法,收敛快,时间短,适合连续同步。TPSN算法的速度慢,可靠性高,适合按需同步。The adoption of the two time synchronization algorithms is based on the characteristics of the two algorithms. Combining the advantages of the two algorithms, the TSync synchronization algorithm is a lightweight algorithm with fast convergence and short time, suitable for continuous synchronization. The TPSN algorithm has slow speed and high reliability, and is suitable for on-demand synchronization.
本发明所述的基于TPSN和TSync的家电网络时间同步方法,是一种针对不同的情形采取不同的无线网络节点时间同步方法。The home appliance network time synchronization method based on TPSN and TSync in the present invention is a time synchronization method using different wireless network nodes for different situations.
附图说明Description of drawings
下面结合附图和具体实施方式对本发明作进一步详细的说明。The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
图1是本发明时间同步整体流程图。Fig. 1 is an overall flowchart of the time synchronization of the present invention.
图2是本发明根节点确立和更新流程图。Fig. 2 is a flowchart of root node establishment and update in the present invention.
图3是本发明源时间确定的流程图。Fig. 3 is a flowchart of source time determination in the present invention.
图4是本发明GPS时钟有效性的判定方法流程图。Fig. 4 is a flow chart of the method for judging the validity of the GPS clock in the present invention.
图5是本发明网络内部源时间的确定流程图。Fig. 5 is a flow chart of determining the internal source time of the network in the present invention.
图6是本发明TSync算法的HRTS阶段流程图。FIG. 6 is a flowchart of the HRTS stage of the TSync algorithm of the present invention.
图7是本发明TSync算法的ITR阶段流程图。FIG. 7 is a flow chart of the ITR stage of the TSync algorithm of the present invention.
图8是本发明d2计算原理图。Fig. 8 is a schematic diagram of the calculation principle of d2 in the present invention.
图9是本发明TPSN算法层次发现阶段流程图。Fig. 9 is a flow chart of the discovery phase of the TPSN algorithm level of the present invention.
图10是本发明TPSN算法同步阶段原理图。Fig. 10 is a schematic diagram of the synchronization phase of the TPSN algorithm of the present invention.
具体实施方式Detailed ways
如图1所示,一种基于TPSN和TSync的家电网络时间同步方法,包括以下步骤:As shown in Figure 1, a home appliance network time synchronization method based on TPSN and TSync includes the following steps:
S1、确立根节点:在智能家电(例如空调)增设一个GPS信号接收器,并以此智能家电节点作为时间同步的根节点,设定无线传感网络中有N个节点,获取所有节点的时间,GPS时间TG,网络服务器时间TS,本地根节点时间TB,并确立或者更新根节点。S1. Establish the root node: add a GPS signal receiver to the smart home appliance (such as an air conditioner), and use the smart home appliance node as the root node for time synchronization, set N nodes in the wireless sensor network, and obtain the time of all nodes , GPS time T G , network server time T S , local root node time T B , and establish or update the root node.
如图2所示,步骤S1中所述的确立或者更新根节点的方法具体包括以下步骤:As shown in Figure 2, the method for establishing or updating the root node described in step S1 specifically includes the following steps:
S11、临时变量用Ttemp表示,以这个时间变量做为网络内部节点进行对比时间对比的基准,这个变量与GPS时间和网络服务器时间紧密相关,因此设定该时间为GPS时间和网络服务器时间经过加权计算相加之后的时间,权值系数分别为α和β,由于该基准时间必须要与GPS时间和网络服务器时间相互接近,因此权值系数之和为1。S11. The temporary variable is represented by T temp , and this time variable is used as the benchmark for comparing the time of the internal nodes of the network. This variable is closely related to the GPS time and the network server time, so the time is set as the GPS time and the network server time. The time after the weighted calculation is added, and the weight coefficients are α and β respectively. Since the reference time must be close to the GPS time and the network server time, the sum of the weight coefficients is 1.
临时变量Ttemp=α×TS+β×TG,(α+β)=1。Temporary variable T temp =α×T S +β×T G , (α+β)=1.
S12、当TS和TG都能够准确获取,则Ttemp=α×TS+β×TG,(α+β)=1,其中权值分配上,使得α=0.3,β=0.7。S12. When both T S and T G can be obtained accurately, then T temp =α×T S +β×T G , (α+β)=1, where the weights are distributed such that α=0.3, β=0.7.
当TS能够获得,而TG无法获得,则使TG=0,α=1,则Ttemp=TS。When T S can be obtained but T G cannot be obtained, T G =0, α=1, then T temp =T S .
当TG能够获得,而TS无法获得,则使TS=0,β=1,那么Ttemp=TG。When T G can be obtained but T S cannot be obtained, T S =0, β=1, then T temp =T G .
当TG和TS均无法获得,使TG=0,TS=0,则Ttemp=0。When neither T G nor T S can be obtained, T G =0, T S =0, then T temp =0.
S13、获取无线网络中N个节点的内部时钟{T1,T2,T3……TN},然后根据公式(1.1)计算每一个内部时钟与Ttemp的差值的最小值:S13. Obtain the internal clocks {T 1 , T 2 , T 3 ... T N } of N nodes in the wireless network, and then calculate the minimum value of the difference between each internal clock and T temp according to formula (1.1):
{abs(T1-Ttemp),abs(T2-Ttemp),abs(T3-Ttemp),……abs(TN-Ttemp)}min (1.1)。{abs(T 1 -T temp ), abs(T 2 -T temp ), abs(T 3 -T temp ),... abs(T N -T temp )} min (1.1).
S14、当abs(TK-Ttemp)的值最小,则选取第K个节点为根节点;当Ttemp=0,则不更新根节点。S14. When the value of abs(T K −T temp ) is the smallest, select the Kth node as the root node; when T temp =0, do not update the root node.
在步骤S1中,对于同步源时间的确定,没有选取单一的时间源,而是是综合了GPS信号接收器和网络服务器以及节点内部时钟针对不同的情况,采取不同的时间源,进而使得时间同步的有效性大大提高,避免了时间同步的时间盲区。In step S1, for the determination of the synchronization source time, a single time source is not selected, but a combination of the GPS signal receiver, the network server and the internal clock of the node, and different time sources are adopted for different situations, thereby making time synchronization The effectiveness is greatly improved, and the time blind zone of time synchronization is avoided.
S2、确定源时间:S2. Determine the source time:
如图3所示,设定源时间从(TG,TB,TS)三者中获取;As shown in Figure 3, the set source time is obtained from (T G , T B , T S );
当TG有效,则TG优先级最高,作为源时间。When T G is valid, T G has the highest priority and is used as the source time.
如图4所示,步骤S2中GPS时间TG的有效性判定具体包括以下步骤:As shown in Figure 4, the validity determination of the GPS time T G in step S2 specifically includes the following steps:
—比较TG与TB和TS之间的误差,取值最大的{abs(TG-TS),abs(TG-TB)}max,当最大误差时间大于10min,则认定GPS接收器出现故障,进而判定GPS时间TG无效。—Comparing the error between T G and T B and T S , take the largest value {abs(T G -T S ),abs(T G -T B )} max , when the maximum error time is greater than 10min, then consider GPS The receiver fails, and the GPS time T G is determined to be invalid.
—当时间服务器出现故障或者网络中断,则判断abs(TG-TB)是否大于10min,当abs(TG-TB)大于10min,则认为GPS接收器出现故障,进而判定GPS时间TG无效。—When the time server fails or the network is interrupted, judge whether the abs(T G -T B ) is greater than 10 minutes. When the abs(T G -T B ) is greater than 10 minutes, it is considered that the GPS receiver is faulty, and then determine the GPS time T G invalid.
—对最近30min时间的GPS接收到的时间值进行五次差值运算,- Perform five difference calculations on the time value received by GPS in the last 30 minutes,
{T1,T2,T3,T4……Tmax},其中max相当于30min时间内获取的所有时间点数目,如果GPS信号没有一点时间缺失的话max=1800,实际以存储的时间数据为准,{T 1 , T 2 , T 3 , T 4 ... T max }, where max is equivalent to the number of all time points acquired within 30 minutes, if the GPS signal does not have any time missing, then max=1800, the actual time data stored prevail,
进行第一次差值运算,获取{T11,T12,T13,T1i……T1(max-1)},其中T1i=Ti+1-Ti,i=(1,2,3,4……max-1);Perform the first difference operation to obtain {T 11 , T 12 , T 13 , T 1i ... T 1(max-1) }, where T 1i =T i+1 -T i , i=(1,2 ,3,4...max-1);
进行第二次差值运算,{T21,T22,T23,T2i……T2(max-2)},其中T2i=T1i+1-T1i,i=(1,2,3,4……max-2);Perform the second difference operation, {T 21 , T 22 , T 23 , T 2i ... T 2(max-2) }, where T 2i =T 1i+1 -T 1i , i=(1,2, 3,4...max-2);
以此类推,第k次差值运算,{Tk1,Tk2,Tk3,Tki……Tk(max-k)},其中Tki=T(k-1)i+1-T(k-1)i,i=(1,2,3,4……max-k);By analogy, the k-th difference operation, {T k1 , T k2 , T k3 , T ki ... T k(max-k) }, where T ki =T (k-1)i+1 -T ( k-1)i , i=(1,2,3,4...max-k);
进行到第五次差值所得到的结果{T51,T52,T53,T5i……T5(max-5)}max如果小于1s则认为GPS信号获取的时间TG有效,否则放弃GPS时间TG作为时间源。The result of the fifth difference is {T 51 , T 52 , T 53 , T 5i ... T 5(max-5) } max If it is less than 1s, the time T G of GPS signal acquisition is considered valid, otherwise give up GPS time T G as time source.
当TG无效,TS有效,则TS优先级仅次于TG,作为源时间。When T G is invalid and T S is valid, the priority of T S is second only to T G as the source time.
步骤S2中网络服务器时间TS的有效性判定:Validity determination of network server time T S in step S2:
当断网情况下,端口网络时间无法获得,则网络服务器时间TS设置为0,TS无效。When the network is disconnected and the port network time cannot be obtained, the network server time T S is set to 0, and T S is invalid.
当联网情况下,网络时间服务器选择:When connected to the Internet, the network time server selects:
通常同以下NTP服务地址获取网络时间Usually get the network time with the following NTP service address
server ntp-sop.inria.frserver 210.72.145.44(中国国家授时中心服务器IP地址)server ntp-sop.inria.frserver 210.72.145.44 (China National Time Service Center server IP address)
server 133.100.11.8preferserver 133.100.11.8prefer
server 210.72.145.44server 210.72.145.44
server 203.117.180.36server 203.117.180.36
server 131.107.1.10server 131.107.1.10
server 64.236.96.53server64.236.96.53
server 130.149.17.21server 130.149.17.21
server 66.92.68.246server66.92.68.246
server www.freebsd.orgserverwww.freebsd.org
server 18.145.0.30server 18.145.0.30
server clock.via.netserver clock.via.net
server 137.92.140.80server 137.92.140.80
server 133.100.9.2server 133.100.9.2
server 128.118.46.3server 128.118.46.3
server ntp.nasa.govserver ntp.nasa.gov
server 129.7.1.66server 129.7.1.66
网络时间的获取,首先从中国国家授时中心获取,其次才会从其他地址获取,获取。The acquisition of network time is first obtained from the China National Time Service Center, and then obtained from other addresses.
基于NTP服务地址获取网络时间,无线网络内部时间确定,如图5所示,网络层次的发现与建立,如图9所示,具体包括以下步骤:The network time is obtained based on the NTP service address, and the internal time of the wireless network is determined, as shown in Figure 5. The discovery and establishment of the network level, as shown in Figure 9, specifically includes the following steps:
S21、根节点设置自己的层次号为1。S21. The root node sets its own level number to 1.
S22、根节点广播一个信息包,包含根节点的ID以及层次号。S22. The root node broadcasts an information packet, which includes the ID and the layer number of the root node.
S23、当通信范围内的节点收到信息包,将自己的层次级别设置为信息包中层次号加1。S23. When a node within the communication range receives the information packet, it sets its own hierarchical level as the hierarchical number in the information packet plus 1.
S24、接收节点广播新的包含自己的ID和层次号的信息包,接收到的节点以同样的方式设置自己的层次号。S24. The receiving node broadcasts a new information packet containing its own ID and layer number, and the receiving node sets its own layer number in the same manner.
S25、重复步骤S24,直到整个网络中的节点都建立自己的层级级别,其中已有层次号的节点再次接收到广播的信息包时,做忽略处理。S25. Step S24 is repeated until all the nodes in the entire network have established their own hierarchical levels. When the nodes with existing hierarchical numbers receive the broadcasted information packet again, they will be ignored.
S26、假设最后建立的层次为k层,{1,2,3……k}层的节点个数为{n1,n2,n3,……nk},总节点个数为N,则计算每一层的概率设置为{p1,p2,p3,……pk} 分别为 S26. Assuming that the last established layer is k layer, the number of nodes in {1,2,3...k} layer is {n 1 ,n 2 ,n 3 ,...n k }, and the total number of nodes is N, Then calculate the probability of each layer and set it as {p 1 ,p 2 ,p 3 ,…p k } respectively as
S27、根据不同的概率来计算内部节点时间的期望值,每一层选取一个节点,这样避免了层中节点的失效,获取它们的时间分别为{T1i,T2i,T3i……Tki},此时间下标中{1i≤n1,2i≤n2,3i≤n3,……ki≤nk},计算时间期望 S27. Calculate the expected value of internal node time according to different probabilities, select a node for each layer, so as to avoid the failure of nodes in the layer, and obtain their time respectively as {T 1i , T 2i , T 3i ... T ki } , in this time subscript {1i≤n 1 ,2i≤n 2 ,3i≤n 3 ,…ki≤n k }, the calculation time expectation
S27、无线网络中N个节点的内部时钟{T1,T2,T3……TN}与时间期望ET进行差值计算,误差最小的时间{abs(T1-ET),abs(T2-ET),abs(T3-ET),……abs(TN-ET)}min作为无线网络内部时钟的源时间。S27. Calculate the difference between the internal clocks {T 1 , T 2 , T 3 ... T N } of N nodes in the wireless network and the time expectation E T , and the time with the smallest error {abs(T 1 -E T ), abs (T 2 -E T ),abs(T 3 -E T ),…abs(T N -E T )} min is used as the source time of the internal clock of the wireless network.
当TG无效,TS无效,则选择TB作为源时间,TB为本地根节点时间,即无线网络内部时间。When T G is invalid and T S is invalid, T B is selected as the source time, and T B is the local root node time, that is, the internal time of the wireless network.
在步骤S2中,对于GPS时间的有效性判定采用了五次差值法,而对于无线网络内部时间采取了先确立网络层次,然后根据网络层次的节点数量来分配概率值,进而计算期望值来获取更具有可靠性的时间。In step S2, the five-time difference method is used to determine the validity of GPS time, and the internal time of the wireless network is adopted to first establish the network level, then assign probability values according to the number of nodes in the network level, and then calculate the expected value to obtain A more reliable time.
对于网络服务器时间的获取选取了多个的时间服务器地址作为备用,以中国国家授时中心的时间作为首先。在源时间的获取后,设置了不同的优先级,以GPS时间优先级最高,网络服务器时间次之和本地时间优先级最低来根据不同的情况来确定源时间。For the acquisition of the network server time, multiple time server addresses are selected as backups, and the time of the China National Time Service Center is used as the first. After the source time is acquired, different priorities are set, the GPS time has the highest priority, the network server time takes the second place, and the local time has the lowest priority to determine the source time according to different situations.
S3、选择同步方式:采用连续同步和按需同步互补方式进行同步。S3. Selecting a synchronization method: performing synchronization in a complementary manner of continuous synchronization and on-demand synchronization.
连续同步采用TSync算法进行时间同步,连续同步是指同步时间间隔较短,设置为规定时间内同步一次,通常设置为0.5小时或1小时同步一次,采用TSync算法对整个节点网络进行时间同步。Continuous synchronization uses the TSync algorithm for time synchronization. Continuous synchronization means that the synchronization time interval is relatively short. It is set to synchronize once within a specified time, usually set to synchronize once every 0.5 hours or 1 hour, and uses the TSync algorithm to synchronize the time of the entire node network.
按需同步采用TPSN算法进行时间同步,按需同步则是独立于连续同步之外的一种同步方式,根据用户自由选择进行时间同步的一种同步方式,并且按需同步并不影响连续同步算法的运行。On-demand synchronization uses the TPSN algorithm for time synchronization. On-demand synchronization is a synchronization method independent of continuous synchronization. It is a synchronization method for time synchronization according to the user's free choice, and on-demand synchronization does not affect the continuous synchronization algorithm. running.
步骤3中连续同步所述的TSync算法是通过HRTS和ITR两种算法来进行同步,HRTS是同步根节点发出同步信号进行同步的,ITR是通过普通的节点向临近节点发出同步请求,并最终将请求传递给根节点的一种同步方式,两者互相补充,同时运行,属于主动同步和请求同步互补。The TSync algorithm described in the continuous synchronization in step 3 is synchronized through two algorithms, HRTS and ITR. HRTS is a synchronization root node that sends a synchronization signal for synchronization. ITR sends a synchronization request to an adjacent node through an ordinary node, and finally sends A synchronization method in which the request is passed to the root node. The two complement each other and run at the same time. It belongs to the complementary of active synchronization and request synchronization.
在某些情况下,基于HRTS算法的主动式的同步方案,并不能够成功得同步节点太多的情况,因此,ITR作为HRTS的补充,提供了一种每个传感器节点独立获取时间并且和周围环境同步的一种基于需求的时间同步方法。In some cases, the active synchronization scheme based on the HRTS algorithm cannot successfully synchronize too many nodes. Therefore, as a supplement to HRTS, ITR provides a way for each sensor node to independently obtain time and communicate with the surrounding A demand-based time synchronization method for environment synchronization.
如图6所示,所述的HRTS算法同步具体包括以下步骤:As shown in Figure 6, the HRTS algorithm synchronization specifically includes the following steps:
S311、根节点在控制信道在时间t1广播一个sync_begin信标,如图6-(a)所示。S311. The root node broadcasts a sync_begin beacon on the control channel at time t1, as shown in FIG. 6-(a).
S312、根节点随机指定的一个子节点跳到指定的时钟信道进行回复,例如n2。S312. A child node randomly designated by the root node jumps to a designated clock channel to reply, for example, n2.
S313、节点n2在时间t3回复给根节点自己的接收时间t2和t3,如图6-(b)所示。S313. Node n2 replies to the root node its own receiving time t2 and t3 at time t3, as shown in Figure 6-(b).
S314、根节点记录接收到的时间戳t4,这样根节点拥有t1-t4所有的时间戳。S314. The root node records the received timestamp t4, so that the root node has all the timestamps of t1-t4.
S315、根节点计算时间d2,d2计算原理所涉及的参数,如图8所示,然后广播t2,d2给控制信道的所有节点,如图6-(c)所示,其中 S315. The root node calculates time d2, parameters involved in the calculation principle of d2, as shown in Figure 8, and then broadcasts t2, d2 to all nodes of the control channel, as shown in Figure 6-(c), wherein
S316、所有临近子节点,例如n2,n3,n4,n5,比较时间t2和接收时间戳t2',例如n3计算时间漂移d'd'=t2-t2'。S316. All adjacent child nodes, such as n2, n3, n4, and n5, compare the time t2 with the received timestamp t2', for example, n3 calculates the time drift d'd'=t2-t2'.
S317、节点n3的时间校正为T=t+d2+d',其中t为n3节点的本地时间。S317. The time of node n3 is corrected as T=t+d2+d′, where t is the local time of node n3.
S318、节点n2,n3,n4,n5初始化sync_begin信标给它们的下游节点,重复以上步骤。S318. Nodes n2, n3, n4, and n5 initialize sync_begin beacons to their downstream nodes, and repeat the above steps.
如图7所示,所述的ITR算法同步具体包括以下步骤:As shown in Figure 7, the ITR algorithm synchronization specifically includes the following steps:
S321、节点n1在控制信道中发送ITR_QUERY信号,发送同步请求的时钟信道在ITR_QUERY中被指定,如图7-(a)所示。S321. The node n1 sends an ITR_QUERY signal in the control channel, and the clock channel for sending the synchronization request is specified in the ITR_QUERY, as shown in FIG. 7-(a).
S322、节点n1的父节点n2收到请求后,会在控制信道发送ITR_ACK信号通知它的父节点,本实例图7中是根节点BS;一般情况下,上游父节点会一直发送ITR_ACK信号直到到达根节点,如图7-(b)所示。S322. After the parent node n2 of node n1 receives the request, it will send an ITR_ACK signal to notify its parent node on the control channel. In this example, the root node BS in Figure 7; under normal circumstances, the upstream parent node will always send the ITR_ACK signal until it reaches Root node, as shown in Figure 7-(b).
S323、节点n2的父节点BS,接受到ITR_ACK后,转换到指定的时钟信道,时钟信道信息包含在ITR_ACK中;沿ITR_ACK传播路径上的所有节点都转换到指定的时钟信道。S323. After receiving the ITR_ACK, the parent node BS of the node n2 switches to the specified clock channel, and the clock channel information is included in the ITR_ACK; all nodes along the propagation path of the ITR_ACK switch to the specified clock channel.
S324、节点n2接收到n1的同步请求,通过指定的时钟信道发送到节点BS,如图7-(c)所示。S324. Node n2 receives the synchronization request from n1 and sends it to node BS through a specified clock channel, as shown in FIG. 7-(c).
S325、节点BS发起同样的过程发送时间给节点n1。S325. The node BS initiates the same process to send the time to the node n1.
S326、节点n1根据节点BS反馈的时间同步自己的时间。S326. The node n1 synchronizes its own time according to the time fed back by the node BS.
如图9所示,步骤3中连续同步所述的按需同步TPSN算法包括层次发现阶段和同步阶段;所述层次发现阶段,每个节点拥有自己的层次号,把具有层次的网络结构看成生成树,具体包括以下步骤:As shown in Figure 9, the on-demand synchronous TPSN algorithm described in continuous synchronization in step 3 includes a hierarchy discovery phase and a synchronization phase; in the hierarchy discovery phase, each node has its own hierarchy number, and the network structure with hierarchy is regarded as Generate a tree, specifically including the following steps:
S331、树的根节点担任时钟源节点,设其层次号为0。S331. The root node of the tree serves as the clock source node, and its level number is set to 0.
S332、根节点广播一个信息包,包含根节点的ID以及层次号。S332. The root node broadcasts an information packet, which includes the ID and the layer number of the root node.
S333、当通信范围内的节点收到信息包,将自己的层次级别设置为信息包中层次号加1。S333. When a node within the communication range receives the information packet, it sets its own hierarchy level to the hierarchy number in the information packet plus 1.
S334、接收节点广播新的包含自己的ID和层次号的信息包,接收到的节点以同样的方式设置自己的层次号。S334. The receiving node broadcasts a new information packet containing its own ID and layer number, and the receiving node sets its own layer number in the same manner.
S335、重复步骤S334,直到整个网络中的节点都建立自己的层级级别,已有层次号的节点再次接收到广播的信息包时,做忽略处理,实现TPSN拓扑结构的建立。S335. Step S334 is repeated until all the nodes in the entire network have established their own hierarchical levels. When the nodes with existing hierarchical numbers receive the broadcasted information packet again, they ignore the processing to realize the establishment of the TPSN topology.
如图10,所述同步阶段具体包括以下步骤:As shown in Figure 10, the synchronization phase specifically includes the following steps:
S341、节点R和节点S的层次号分别为第k层和第k+1层,同步时,上层节点R广播一个时间同步请求信息包,通知S节点做好时间同步的准备。S341. The layer numbers of node R and node S are the kth layer and the k+1th layer respectively. During synchronization, the upper layer node R broadcasts a time synchronization request packet to notify S node to prepare for time synchronization.
S342、节点S经过一段随机时间的等待后,在T1时刻向节点R发送含有时刻T1的同步信息包。S342. After waiting for a random period of time, the node S sends a synchronization information packet containing the time T1 to the node R at the time T1.
S343、节点R接收到信息包后,使用本地时钟来记录接收时间T2,则有:T2=T1+Δ+d,其中,Δ表示节点间的时间偏移,d表示消息的传输时延。S343. After receiving the information packet, the node R uses the local clock to record the receiving time T 2 , then: T 2 =T 1 +Δ+d, where Δ represents the time offset between nodes, and d represents the transmission time of the message delay.
S344、节点R以同样的方式在时刻T3向节点S发送一个确认消息,该消息中包含(T1、T2、T3)。S344. Node R sends a confirmation message to node S at time T 3 in the same manner, and the message includes (T 1 , T 2 , T 3 ).
S345、节点S在T4时刻用本地时间记录下接收消息的时间T4,满足:T4=T3-Δ+d,其中,Δ表示节点间的时间偏移,d表示消息的传输时延;由公式T2=T1+Δ+d和T4=T3-Δ+d得到:S345. Node S records the time T 4 of receiving the message in local time at T 4 , which satisfies: T 4 =T 3 -Δ+d, where Δ represents the time offset between nodes, and d represents the transmission delay of the message ; Obtained by the formulas T 2 =T 1 +Δ+d and T 4 =T 3 -Δ+d:
和 and
S346、根据步骤S345的计算结果修改节点的时间为一致。S346. Modify the time of the nodes to be consistent according to the calculation result of step S345.
本发明所述的时间同步过程要按照具体步骤内容中的流程进行,各时间同步方法的优先级不得改变。The time synchronization process in the present invention should be carried out according to the flow in the specific steps, and the priority of each time synchronization method must not be changed.
在确定了源时间之后根据,步骤S3中,用户选择不同的时间同步算法,来决定进行连续时间同步还是按需时间同步,连续时间同步是同步时间周期较短的时间同步方法,时间同步间隔设置为0.5小时或1小时,TSync同步算法是由科罗拉多大学Richard Han和HuiDai提出的,是一种灵活的、自组织的、没有固定网络拓扑结构和传输延迟的时间同步服务。After determining the source time, in step S3, the user selects a different time synchronization algorithm to decide whether to perform continuous time synchronization or on-demand time synchronization. Continuous time synchronization is a time synchronization method with a shorter synchronization time period, and the time synchronization interval is set It is 0.5 hours or 1 hour. The TSync synchronization algorithm was proposed by Richard Han and HuiDai of the University of Colorado. It is a flexible, self-organizing time synchronization service without fixed network topology and transmission delay.
按需同步则是根据用户的需求,决定同步时间,没有一定的时间间隔,按需同步采取TPSN协议的时间同步方法。On-demand synchronization is to determine the synchronization time according to the user's needs. There is no certain time interval, and the time synchronization method of the TPSN protocol is adopted for on-demand synchronization.
两种时间同步算法的采用的,是根据两种算法的特点来进行的,综合两种算法的优点,TSync同步算法是一种轻量级算法,收敛快,时间短,适合连续同步。TPSN算法的速度慢,可靠性高,适合按需同步。The adoption of the two time synchronization algorithms is based on the characteristics of the two algorithms. Combining the advantages of the two algorithms, the TSync synchronization algorithm is a lightweight algorithm with fast convergence and short time, suitable for continuous synchronization. The TPSN algorithm has slow speed and high reliability, and is suitable for on-demand synchronization.
本发明实现基于TPSN方法和TSync混合时间同步的家电无线网络时间同步方法,综合利用了外置GPS时钟、网络时间服务器、以及智能家电内部时钟三种时间来源,针对不同的情况采用不同的时间同步方法,避免了时间同步空白时间段的出现,保证了智能家电监控数据时间数据的可靠性和精确性。The present invention realizes the home appliance wireless network time synchronization method based on the TPSN method and TSync hybrid time synchronization, comprehensively utilizes three time sources of external GPS clock, network time server, and smart home appliance internal clock, and adopts different time synchronization methods for different situations The method avoids the occurrence of a time synchronization blank time period, and ensures the reliability and accuracy of the monitoring data and time data of smart home appliances.
本发明所述的GPS时钟来源是能够安装在在户外的GPS信号接收装置,室内的GPS信号不能作为时钟信号来源。The GPS clock source of the present invention is a GPS signal receiving device that can be installed outdoors, and indoor GPS signals cannot be used as a clock signal source.
以上所述,仅为本发明较佳的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,根据本发明的技术方案及其发明构思加以等同替换或改变,都应涵盖在本发明的保护范围之内。The above is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto, any person familiar with the technical field within the technical scope disclosed in the present invention, according to the technical solution of the present invention Any equivalent replacement or change of the inventive concepts thereof shall fall within the protection scope of the present invention.
Claims (6)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710150367.5A CN106912100B (en) | 2017-03-14 | 2017-03-14 | Time Synchronization Method of Home Appliance Network Based on TPSN and TSync |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710150367.5A CN106912100B (en) | 2017-03-14 | 2017-03-14 | Time Synchronization Method of Home Appliance Network Based on TPSN and TSync |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106912100A CN106912100A (en) | 2017-06-30 |
CN106912100B true CN106912100B (en) | 2019-12-31 |
Family
ID=59186412
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710150367.5A Expired - Fee Related CN106912100B (en) | 2017-03-14 | 2017-03-14 | Time Synchronization Method of Home Appliance Network Based on TPSN and TSync |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106912100B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110620629A (en) * | 2018-06-19 | 2019-12-27 | 佛山市顺德区美的电热电器制造有限公司 | Clock synchronization method, equipment and computer storage medium |
CN109150359B (en) * | 2018-09-30 | 2020-03-27 | 珠海格力电器股份有限公司 | Time synchronization method and device of air conditioning unit |
CN111769895B (en) * | 2019-04-01 | 2023-09-12 | 西安诺瓦星云科技股份有限公司 | Multi-device timing method and system and device timing method and device |
CN110061797A (en) * | 2019-05-29 | 2019-07-26 | 海尔优家智能科技(北京)有限公司 | Method for synchronizing time, device, storage medium and computer equipment |
CN112769517B (en) * | 2021-01-14 | 2024-01-12 | 武汉光庭信息技术股份有限公司 | T-BOX time synchronization method and device |
CN118102434B (en) * | 2024-04-18 | 2024-10-18 | 南京乐韵瑞信息技术有限公司 | Audio synchronous playback method, system and storage medium |
CN118802054B (en) * | 2024-09-13 | 2025-01-24 | 深圳市中孚能电气设备有限公司 | Data processing method, device, equipment and storage medium based on big data analysis |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102412957A (en) * | 2011-12-05 | 2012-04-11 | 上海电器科学研究院 | High-precision synchronous clock adjusting method |
CN102769870A (en) * | 2011-05-05 | 2012-11-07 | 苏州两江科技有限公司 | Low-energy-consumption time synchronization method of wireless sensor networks |
CN103746762A (en) * | 2013-11-29 | 2014-04-23 | 中国矿业大学 | Wireless sensor network time synchronization method layered as required |
CN104378193A (en) * | 2013-08-16 | 2015-02-25 | 北京卓越信通电子股份有限公司 | Time synchronization system and method, exchanger and embedded interface board |
CN104754722A (en) * | 2013-12-26 | 2015-07-01 | 中国科学院沈阳自动化研究所 | Time synchronization method oriented to hierarchical heterogeneous network |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7139225B2 (en) * | 2003-03-27 | 2006-11-21 | Qualcomm, Incorporated | Virtual real-time clock based on time information from multiple communication systems |
US8472283B2 (en) * | 2010-10-05 | 2013-06-25 | Jeremy Laurence Fischer | Clock synchronization |
-
2017
- 2017-03-14 CN CN201710150367.5A patent/CN106912100B/en not_active Expired - Fee Related
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102769870A (en) * | 2011-05-05 | 2012-11-07 | 苏州两江科技有限公司 | Low-energy-consumption time synchronization method of wireless sensor networks |
CN102412957A (en) * | 2011-12-05 | 2012-04-11 | 上海电器科学研究院 | High-precision synchronous clock adjusting method |
CN104378193A (en) * | 2013-08-16 | 2015-02-25 | 北京卓越信通电子股份有限公司 | Time synchronization system and method, exchanger and embedded interface board |
CN103746762A (en) * | 2013-11-29 | 2014-04-23 | 中国矿业大学 | Wireless sensor network time synchronization method layered as required |
CN104754722A (en) * | 2013-12-26 | 2015-07-01 | 中国科学院沈阳自动化研究所 | Time synchronization method oriented to hierarchical heterogeneous network |
Also Published As
Publication number | Publication date |
---|---|
CN106912100A (en) | 2017-06-30 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106912100B (en) | Time Synchronization Method of Home Appliance Network Based on TPSN and TSync | |
CN107949047B (en) | Wireless sensor network consistency time synchronization method for reducing network communication traffic | |
CN101909345B (en) | Multi-hop dynamic ad hoc network method of wide field sensor network | |
CN102158983B (en) | Method for constructing 6LoWPAN wireless sensor network | |
Song et al. | Design of wireless sensor network-based greenhouse environment monitoring and automatic control system | |
CN103458498B (en) | An Intelligent Time Synchronization Method for Wireless Sensor Networks | |
CN112073460B (en) | Data acquisition unit, data transmission method and comprehensive energy monitoring system | |
CN113098674A (en) | Time synchronization method and system for data link terminal of high-speed carrier self-organizing network | |
CN108900273A (en) | A kind of consistent method for synchronizing time of wireless sensor network multi-hop | |
Pinho et al. | A robust gradient clock synchronization algorithm for wireless sensor networks | |
CN105188126A (en) | Distributed multi-hop wireless network clock synchronization method based on mean field | |
CN105491656B (en) | A kind of lightweight method for synchronizing time towards extensive ad hoc network | |
Wang et al. | A survey of time synchronization algorithms for wireless sensor networks | |
CN103532230A (en) | Intelligent power distribution network IEEE1588 timing synchronization system on basis of industrial Ethernet tangency access rings | |
CN107197514A (en) | Cognitive global clock synchronization method for wireless sensor networks and its application in multi-hop networks | |
CN106656395B (en) | Based on the improved power grid time synchronized measurement system of self study and method | |
CN113079563A (en) | Wireless sensor network synchronization method based on multiple clock sources | |
Martirosyan et al. | Preserving temporal relationships of events for wireless sensor actor networks | |
Xu et al. | An improved flooding time synchronization protocol for industrial wireless networks | |
Nayyer et al. | A comparative study of time synchronization protocols in wireless sensor network | |
CN106507440B (en) | Sensor network system, networking and information interaction method | |
Zhang | Research on WSN Time Synchronization Algorithm Based on Smart Campus | |
CN111641993B (en) | Time synchronization method for energy perception dynamic topology control | |
Guo et al. | Fast layered-synchronization algorithm for adhoc networks | |
CN104540212B (en) | On-demand clock synchronization method for wireless sensor network based on AODV routing protocol |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20191231 |
|
CF01 | Termination of patent right due to non-payment of annual fee |