Data sending method, gateway and sensor node
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method for sending data, a gateway, and a sensor node.
Background
The wireless sensor network is a wireless network formed by a large number of static or mobile internal sensor nodes in the network in a self-organizing and multi-hop mode, and aims to cooperatively sense, acquire, process and transmit monitoring information in a network coverage geographical area, and report the monitoring information to an external server for analysis and processing through gateway equipment. In the working process of the gateway, an external server needs to be corresponded with an internal sensor node, so that the data of the sensor node is sent to the server through the gateway.
In the prior art, two situations exist when a sensor node sends data to an external server. The first method is that the sensor node sends feedback data when feeding back the query information sent by the external server, and the process is as follows: the external server sends the query information to the gateway, the gateway queries in the corresponding relation between the external server and the internal sensor node which are stored in advance, and if the target internal sensor node exists, the query information is sent to the internal sensor node; and after the internal sensor node finishes the query task, sending the result to the gateway, querying the address of the external server by the gateway through the corresponding relation between the external server and the internal sensor node which is stored in advance, and returning the query result to the external server. The second is that the sensor node actively reports the monitoring data to an external server, and the process is as follows: the sensor node sends the reported monitoring data to the gateway, the gateway inquires the address of the server receiving the monitoring data from the corresponding relation between the external server and the internal sensor node which is stored in advance, and reports the monitoring data to the external server according to the address of the external server.
In the process of implementing the invention, the inventor finds that the prior art has at least the following problems:
the sensor node sends data to the external server, and no matter whether the data is passively fed back to the external server or actively reported to the external server, the sensor node can not determine the relevant information of the external server and the corresponding service type information, only sends the data to the gateway, the gateway inquires through the corresponding relation between the external server and the sensor node, and then sends the data to the inquired external server. Due to the asymmetric network transparency, the sensor node cannot know the information of the external server sending the query information, so that the security of returning the information to the external server cannot be judged, and the asymmetric network transparency is a restriction on security performance for more and more complex application requirements and high-performance nodes.
Disclosure of Invention
In order to solve the problem of performance restriction caused by information opaqueness when an intranet sensor and an extranet server transmit data in the prior art, the embodiment of the invention provides a data sending method, a gateway and a sensor node. The technical scheme is as follows:
in one aspect, a method for transmitting data is provided, and the method includes:
receiving data sent by a sensor node to a mapping node, wherein the data carries a node address of the mapping node;
and inquiring the address of an external server corresponding to the node address of the mapping node in a pre-stored corresponding relation between the mapping node and the external server, and sending the data to the external server according to the inquired address of the external server.
In another aspect, a method of transmitting data is provided, the method including:
receiving second query information forwarded by a gateway, wherein the second query information carries a node address of a mapping node for sending the second query information;
judging whether the node address of the mapping node sending the second query information carried in the second query information is the node address of the mapping node which is in the broadcast information sent by the gateway and is in accordance with the monitoring data type of the mapping node in advance;
if so, returning feedback data corresponding to the second query information to the gateway, wherein the feedback data carries the node address of the mapping node corresponding to the server receiving the feedback data in the network, so that the gateway forwards the feedback data according to the node address of the mapping node carried in the feedback data.
In another aspect, a gateway for transmitting data is provided, the gateway comprising:
the first receiving module is used for receiving data sent by a sensor node to a mapping node, wherein the data carries a node address of the mapping node;
and the processing module is used for inquiring the address of the external server corresponding to the node address of the mapping node in the pre-stored corresponding relation between the mapping node and the external server, and sending the data to the external server according to the inquired address of the external server.
In another aspect, a sensor node for transmitting data is provided, the sensor node comprising:
a third receiving module, configured to receive second query information forwarded by a gateway, where the second query information carries a node address of a mapping node that sends the second query information;
the judging module is used for judging whether the node address of the mapping node which is carried in the second query information and used for sending the second query information is the node address of the mapping node which is in the broadcast information sent by the gateway and is received in advance and has the same type with the monitoring data of the gateway;
and if so, returning the feedback data corresponding to the second query information to the gateway, wherein the feedback data carries the node address of the mapping node corresponding to the server receiving the feedback data in the network, so that the gateway forwards the feedback data according to the node address of the mapping node carried in the feedback data.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
by pre-establishing the mapping node of the external server in the network, when data are transmitted between the external server and the sensor node in the intranet through the gateway, the sensor node can obtain the information of the mapping node corresponding to the external server which actively reports the information in advance, so that the whole communication process is more transparent, and the safety of the complex network communication process between the sensor and the external server in the network is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart of a method for transmitting data according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a method for sending data according to a second embodiment of the present invention;
fig. 3 is a schematic flowchart of a method for sending data according to a third embodiment of the present invention;
fig. 4 is a flowchart illustrating a method for sending data according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of a gateway for sending data according to a fifth embodiment of the present invention;
fig. 6 is a schematic structural diagram of a sensor node for sending data according to a sixth embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Example one
An embodiment of the present invention provides a method for sending data, and referring to fig. 1, the method includes:
101: receiving data sent by a sensor node to a mapping node, wherein the data carries a node address of the mapping node;
102: and inquiring the address of an external server corresponding to the node address of the mapping node in a pre-stored corresponding relation between the mapping node and the external server, and sending the data to the external server according to the inquired address of the external server.
The embodiment of the invention realizes that when the external server and the sensor node in the intranet transmit data through the gateway by pre-establishing the mapping node of the external server in the network, the sensor node can obtain the information of the mapping node corresponding to the external server which actively reports information or receives feedback information in advance, so that the whole communication process is more transparent, and the safety of the complex network communication process between the sensor and the external server in the network is improved.
Example two
Referring to fig. 2, it should be noted that the embodiment of the present invention takes a wireless sensor network as an example, and describes a process of establishing a mapping node in the wireless sensor network in advance for an external server that communicates with a sensor node in the wireless sensor network.
The method comprises the following steps:
201: when the sensor node communicates with the external server for the first time, the node address of the mapping node is distributed for the external server, and the server is added into the network, so that the mapping node and the external server are in one-to-one correspondence in the network.
Specifically, when a sensor node inside the wireless sensor network communicates with a server of an external network, the communicated data is forwarded through a gateway. The communication can be that the internal sensor in the wireless sensor network actively reports the monitoring data or the server of the external network sends the query information to the internal sensor in the wireless sensor network, and the communication process at this moment is the process of the gateway according to the forwarded data in the prior art, and the communication process between the external node and the internal node is realized through the address mapping relation stored in the gateway. In the first communication process, the gateway records the address of a server in communication and service type information corresponding to the server, and the address of the server can be acquired by receiving query information of the server at the moment, or can be acquired by an address mapping relation recorded in the gateway when monitoring information is reported by an internal sensor node; the service type information corresponding to the server can be obtained from the received query information of the server, or the service type information of the server receiving the monitoring information can be obtained through the information type corresponding to the reported monitoring information when the monitoring information is reported by the internal sensor node. Further, the address of the server may be an IP (Internet Protocol) address or other address information for identifying the source of the server, which is not limited herein.
The server is used as a new node in a wireless sensing network and is added into the wireless sensing network through a gateway. When the wireless sensor network is added, an internal address needs to be obtained in the wireless sensor network, and then the gateway can forward data to the wireless sensor network according to the internal address. Therefore, a star network which takes the gateway as a root node and takes the mapping node corresponding to the server as a child node is formed inside the gateway, and the network is connected to the internal network through the gateway. And after the address is distributed, the node address is notified to the server for backup.
And associating and storing related information of the newly added server in the wireless sensor network in the gateway, wherein the associated information comprises the address of the server, the node address of the mapping node in the wireless sensor network, the network identifier of the current wireless sensor network, namely the intranet ID and the service type information of the server. For example, table 1 shows the association relationship of the relevant information of the server in the wireless sensor network, which is established in the gateway.
| External server address |
Mapping node addresses of nodes |
Intranet ID |
Service type information |
| 123.123.125.2 |
0x1578 |
0x2534 |
0x2587 (temperature Collection) |
| 23.123.125.25 |
0x1579 |
0x2534 |
0x2541 (moisture collection) |
| 123.189.145.78 |
0x1520 |
0x2534 |
0x1247 (price information) |
TABLE 1
Preferably, the gateway can be associated with the types of data collected by each sensor in the current wireless sensor network according to the service type information corresponding to the server, so that the gateway can provide better related information according to the association relationship and can transmit data to the sensor node corresponding to the service type information of the server more quickly. For example: the service type information of a certain server is collected temperature information, the gateway correspondingly associates the identifiers of all sensor nodes which are in charge of temperature collection in the network with the identifier of the server, the server sends query information of unified uploading data to the gateway in the process that the server needs the sensor nodes to report data in a unified mode, and the gateway directly corresponds to all the sensor nodes which collect the temperature information according to the association relation and sends commands to all the sensor nodes which collect the temperature information.
The address assignment to the server can be obtained in two ways, so step 201 may specifically be:
2011: when the sensor node in the network communicates with the external server for the first time, sending request information for allocating node addresses in the network for the external server to an intranet coordinator node, receiving and recording the allocated node addresses returned by the intranet coordinator node, and adding a server corresponding to the node addresses into the network.
An intranet coordinator node exists in the wireless sensor network, the node is responsible for allocating an intranet address to a joining node in the wireless sensor network, the newly joining node can comprise a sensor node, and in the embodiment of the invention, a mapping node of a newly joining server can also be included, and the intranet coordinator node allocates a 16-bit node address to the server and returns the node address to the gateway for storage. Furthermore, the intranet coordinator node also plays a role in allocating a sending time slot for the gateway in the communication process of the wireless sensor network, and when the gateway receives a request for forwarding data, the data is scheduled to be forwarded by requesting the time slot from the intranet coordinator node.
2012: when a sensor node in the network is communicated with the external server for the first time and has the function of an intranet coordinator node, a node address is distributed in the network for the external server, the distributed node address returned by the intranet coordinator node is recorded, and the server corresponding to the node address is added into the network.
When the intranet coordinator node is the gateway, a 16-bit node address is allocated to the server through the function of the intranet coordinator node, and recording is performed in the gateway.
202: and broadcasting the node address of the mapping node and the service type information corresponding to the external server to the sensor node in the network, so that the sensor node in the network records the node address of the mapping node with the same data type as the monitored data type of the sensor node according to the service type information corresponding to the external server.
Specifically, after a mapping node corresponding to a new server is added to the wireless sensor network, the gateway sends information of the mapping node corresponding to the newly added server to each node in the current wireless sensor network in a broadcast manner, informs each node of the newly added node, carries relevant information of the newly added node in the broadcast, and informs each node in the current wireless sensor network. Wherein, the related information comprises: and the node address of the mapping node corresponding to the server in the wireless sensor network and the service type information corresponding to the server are used for informing the sensor nodes in each wireless sensor network of which the mapping node corresponding to the newly added server is used for receiving.
203: and the sensor node receives broadcast information sent by the gateway, wherein the broadcast information carries the node address of a mapping node corresponding to an external server in the network and the service type information corresponding to the external server.
204: and recording the node address of the mapping node with the same type as the monitoring data of the node according to the service type information corresponding to the external server carried in the broadcast information.
Through the service type information corresponding to the server in the broadcast information, the sensor node can know whether the data is consistent with the monitored data. If the mapping node addresses are consistent with the destination address of the mapping node address of the server in the wireless sensor network, the sensor node records the node address of the mapping node corresponding to the server in the wireless sensor network, and when the current sensor node reports the monitoring data periodically next time, the destination address carried in the monitoring data, namely the recorded mapping node address, can be used as the destination address of the node address of the mapping node corresponding to the server receiving the monitoring data in the wireless sensor network. On the other hand, the node address of the mapping node with the same self-monitoring data type recorded by the sensor node may also be used as a consideration standard for judging the security of the current server when the sensor node receives the query information sent by the server, if the mapping node address of the server in the network is broadcasted by the gateway, the server is verified, otherwise, the mapping node address is non-secure, and the sensor node may not respond to the query information.
The embodiment of the invention realizes that when the external server and the sensor node in the intranet transmit data through the gateway by pre-establishing the mapping node of the external server in the network, the sensor node can obtain the information of the mapping node corresponding to the external server which actively reports information or receives feedback information in advance, so that the whole communication process is more transparent, and the safety of the complex network communication process between the sensor and the external server in the network is improved.
EXAMPLE III
Referring to fig. 3, it should be noted that, in the embodiment of the present invention, after the mapping node is constructed in the second embodiment, the external server sends query information to the sensor node in the wireless sensor network, and in the embodiment of the present invention, the data sent by the sensor node to the external server is feedback data fed back to the external server according to the query information sent by the external server. Further, before the sensor sends data to the gateway, the embodiment of the present invention further includes the processes of step 301 to step 303.
The method comprises the following steps:
301: the gateway receives first query information sent by an external server to a sensor node in a network, wherein the first query information carries a node address of the sensor node.
Specifically, the external server carries a network identifier in first query information sent to the wireless sensor network, so that the gateway determines whether the received first query information is sent to the network where the gateway is located according to the network identifier after receiving the first query information.
302: and the gateway inquires the node address of the mapping node corresponding to the external server in the network in the pre-stored corresponding relation between the mapping node and the external server.
The gateway inquires the node address of the mapping node in the wireless sensor network corresponding to the address of the external server according to the pre-established corresponding relation between the external server and the mapping node in the wireless sensor network.
303: and the gateway replaces the source address in the first query information with the node address of the mapping node corresponding to the external server in the network to generate second query information, and sends the second query information to the sensor node.
And repackaging the first query information sent by the external server, the node address of the mapping node corresponding to the external server in the wireless sensor network and the network identifier in the wireless sensor network to generate second query information.
304: and the sensor node receives second query information forwarded by the gateway, wherein the second query information carries the node address of the mapping node which sends the second query information.
305: and the sensor node judges whether the node address of the mapping node which sends the second query information and is carried in the second query information is the node address of the mapping node which is consistent with the monitoring data type of the sensor node in the broadcast information sent by the gateway and received in advance.
Judging whether the received query information sent by the mapping node corresponding to the external server is sent by the external server approved by the gateway or not by judging the node address of the mapping node which is recorded by the sensor node and is consistent with the monitoring data type of the sensor node, and if so, executing step 306.
306: if so, the sensor node returns feedback data corresponding to the second query information to the gateway, and the feedback data carries the node address of a mapping node corresponding to the server receiving the feedback data in the network, so that the gateway forwards the feedback data according to the node address of the mapping node carried in the feedback data.
And when the sensor node returns the feedback data to the external server according to the second query information, the returned mapping node address corresponding to the external server is used as a target address sent by the sensor node and is packaged into the feedback data together.
307: and the gateway receives data sent to a mapping node by a sensor node, wherein the data carries the node address of the mapping node.
Specifically, in the embodiment of the present invention, the data received by the gateway in this step is feedback data fed back to the external server.
308: the gateway inquires the address of an external server corresponding to the node address of the mapping node in a pre-stored corresponding relation between the mapping node and the external server, and sends the data to the external server according to the inquired address of the external server.
And the gateway searches the address of the target server in a mapping node and external server correspondence table stored in the gateway through the mapping node address carried in the feedback data. And returns feedback data to the server according to the IP address.
According to the embodiment of the invention, the mapping node of the external server in the network is pre-established, so that when the external server and the sensor node in the intranet transmit data through the gateway, the sensor node can acquire the information of the mapping node corresponding to the server for receiving the feedback information, the whole communication process is more transparent, and the safety of the complex network communication process between the sensor in the network and the external server is improved.
Example four
Referring to fig. 4, it should be noted that, in the embodiment of the present invention, after the mapping node is constructed in the second embodiment, the external server actively uploads the monitoring data to the sensor node in the wireless sensor network, in the embodiment of the present invention, the data sent by the sensor node to the external server is the monitoring data periodically reported to the external server.
The method comprises the following steps:
401: the sensor node reports monitoring data to an external server with the same type as the monitoring data of the sensor node regularly, and the monitoring data carries the node address of a mapping node corresponding to the external server receiving the monitoring data in the network.
The process is that when the sensor reports the monitoring data periodically, the gateway broadcasts information to the network to obtain the node address of the mapping node corresponding to the server with the same type as the monitoring data in the wireless sensing network, the monitoring data sent by the sensor node carries the node address as the destination address, and the gateway can forward the data in a routing mode after receiving the data.
402: and the gateway receives data sent to a mapping node by a sensor node, wherein the data carries the node address of the mapping node.
403: the gateway inquires the address of an external server corresponding to the node address of the mapping node in a pre-stored corresponding relation between the mapping node and the external server, and sends the data to the external server according to the inquired address of the external server.
The embodiment of the invention realizes that when the external server and the sensor node in the intranet transmit data through the gateway by pre-establishing the mapping node of the external server in the network, the sensor node can acquire the information of the mapping node corresponding to the external server which actively reports the information in advance, so that the whole communication process is more transparent, and the safety of the complex network communication process between the sensor and the external server in the network is improved.
EXAMPLE five
An embodiment of the present invention provides a gateway for sending data, referring to fig. 5, where a mapping node of an external server in a network is pre-established, and the gateway includes:
a first receiving module 501, configured to receive data sent by a sensor node to a mapping node, where the data carries a node address of the mapping node;
the processing module 502 is configured to query, in a pre-stored correspondence between a mapping node and an external server, an address of the external server corresponding to a node address of the mapping node, and send the data to the external server according to the queried address of the external server.
In a specific embodiment, the gateway further includes:
an address allocation module 503, configured to allocate a node address of a mapping node to an external server when a sensor node communicates with the external server for the first time, and add the server to the network, so that the mapping node and the external server are in one-to-one correspondence in the network.
The address assignment module 503 includes:
a first address allocation unit 5031, configured to send, to an intranet coordinator node, request information for allocating a node address in a network to the external server when a sensor node in the network communicates with the external server for the first time, receive and record an allocated node address returned by the intranet coordinator node, and add a server corresponding to the node address to the network;
a second address allocating unit 5032, configured to, when a sensor node in the network communicates with the external server for the first time and has a function of an intranet coordinator node, allocate a node address in the network for the external server, record an allocated node address returned by the intranet coordinator node, and add a server corresponding to the node address to the network.
Wherein the gateway further comprises:
a broadcasting module 504, configured to broadcast the node address of the mapping node and the service type information corresponding to the external server to the sensor nodes in the network, so that the sensor nodes in the network record the node address of the mapping node, which is consistent with the data type monitored by the sensor nodes, according to the service type information corresponding to the external server.
Further, the data sent by the sensor to the gateway includes: the feedback data fed back to the external server and the monitoring data reported to the external server periodically, correspondingly, when the data is the feedback data fed back to the external server, the gateway further includes:
a second receiving module 505, configured to receive first query information sent by an external server to a sensor node in a network, where the first query information carries a node address of the sensor node;
a query module 506, configured to query, in a pre-stored correspondence between a mapping node and an external server, a node address of a mapping node corresponding to the external server in the network;
an information generating module 507, configured to replace a source address in the first query information with a node address of a mapping node corresponding to the external server in the network to generate second query information, and send the second query information to the sensor node.
The embodiment of the invention realizes that when the external server and the sensor node in the intranet transmit data through the gateway by pre-establishing the mapping node of the external server in the network, the sensor node can acquire the information of the mapping node corresponding to the external server which actively reports the information in advance, so that the whole communication process is more transparent, and the safety of the complex network communication process between the sensor and the external server in the network is improved.
EXAMPLE six
An embodiment of the present invention provides a sensor node for sending data, and referring to fig. 6, the sensor node includes:
a third receiving module 601, configured to receive second query information forwarded by a gateway, where the second query information carries a node address of a mapping node that sends the second query information;
a determining module 602, configured to determine whether a node address of a mapping node that sends the second query information and is carried in the second query information is a node address of the mapping node that is in accordance with a monitoring data type of the mapping node in broadcast information sent by the gateway and received in advance;
a returning module 603, configured to return the feedback data corresponding to the second query information to the gateway if the second query information is true, where the feedback data carries a node address of a mapping node corresponding to the server that receives the feedback data in the network, so that the gateway forwards the feedback data according to the node address of the mapping node carried in the feedback data.
In a specific embodiment, the sensor node further comprises:
a fourth receiving module 604, configured to receive broadcast information sent by the gateway, where the broadcast information carries a node address of a mapping node corresponding to an external server in the network and service type information corresponding to the external server.
A recording module 605, configured to record, according to the service type information corresponding to the external server carried in the broadcast information, a node address of the mapping node that is consistent with the monitoring data type of the mapping node.
A reporting module 606, configured to report the monitoring data to an external server with a same type as the monitoring data of the external server at regular intervals, where the monitoring data carries a node address of a mapping node in the network corresponding to the external server that receives the monitoring data.
The embodiment of the invention realizes that when the external server and the sensor node in the intranet transmit data through the gateway by pre-establishing the mapping node of the external server in the network, the sensor node can acquire the information of the mapping node corresponding to the external server which actively reports the information in advance, so that the whole communication process is more transparent, and the safety of the complex network communication process between the sensor and the external server in the network is improved.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.