Disclosure of Invention
In order to overcome the defects of the prior art, one of the purposes of the invention is to provide a data interaction method for a server and low-power-consumption equipment, which can solve the problems that in the prior art, the external power supply is easily influenced by the external natural environment, so that the high power consumption required by the communication between the server and the low-power-consumption equipment is difficult to ensure, and the like.
The second object of the present invention is to provide an electronic device, which can solve the problem of high power consumption in the prior art, which is required for ensuring communication between a server and a low-power device because an external power supply is easily affected by an external natural environment.
It is a third object of the present invention to provide a computer-readable storage medium capable of solving the problems of the prior art that it is difficult to secure high power consumption required for communication between a server and a low power consumption device because an external power supply is easily affected by an external natural environment.
One of the purposes of the invention is realized by adopting the following technical scheme:
the data interaction method applied to the server and the low-power consumption equipment runs on the server side, and comprises the following steps:
the starting step: starting the server and ensuring that the server is in a waiting connection state;
a connection establishment step: when a connection request of low-power-consumption equipment is detected, establishing connection between the low-power-consumption equipment and a server;
and a data receiving step: receiving data and storing the received data in a buffer;
and a data calculation step: and taking the received data out of the cache area, calling a resolving program to resolve, and closing the connection between the server and the low-power-consumption equipment when all the data are received.
Further, the data sent by the low power consumption device to the server is provided with a request header and a byte terminator, and the data between the request header and the byte terminator is used as one frame of data;
the data resolving step further includes: when the data of the current frame is received, the received data of the current frame is taken out of the buffer area, and a settlement program is called for resolving; and when the bytes of the received data are byte ending symbols, the data of the current frame are considered to be received completely.
Further, the data interaction method further comprises the following steps:
suspending the step of receiving data: in the data receiving process, when a control command is detected, a pause instruction is sent to the low-power-consumption equipment, so that the low-power-consumption equipment pauses sending data to the server, and a connection state is kept between the low-power-consumption equipment and the server;
a command sending step: transmitting a control command to the low power consumption device;
continuing to receive data: after the control command is sent, sending a receiving command to the low-power-consumption equipment, so that the low-power-consumption equipment continues to send data to the server, and executing the data receiving step.
Further, a data calculation step: and carrying out resolving operation on the data in a multi-task and multi-thread mode.
Further, the data resolving step further includes releasing the space of the buffer area after the data is fetched from the buffer area.
Further, the control command is sent by the PC side and stored in the database.
Or, the data interaction method applied to the server and the low-power-consumption equipment runs on the low-power-consumption equipment, and the data interaction method comprises the following steps:
connection request step: sending a connection request to a server and establishing connection with the server;
and a data transmission step: dividing the monitored data into multi-frame data according to the data packets, and sequentially sending the multi-frame data to a server, so that the server stores the data in a cache; wherein each frame of data includes a request header, data, and a byte terminator;
disconnecting: and after all the data are sent to the server, receiving a disconnection command returned by the server, and disconnecting the connection with the server.
Further, the data interaction method further comprises the following steps:
suspending the data transmission step: after receiving the pause instruction, pausing sending data to the server and maintaining connection with the server;
a command receiving step: receiving a control command sent by a server;
continuing to send data: and after receiving the receiving instruction, continuing to execute the data sending step.
The second purpose of the invention is realized by adopting the following technical scheme:
an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, said processor when executing said program performing the steps of a data interaction method for a server and a low power consumption device as employed for one of the purposes of the present invention.
The third purpose of the invention is realized by adopting the following technical scheme:
a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of a data interaction method for a server and a low power consumption device as employed for one of the objects of the invention.
Compared with the prior art, the invention has the beneficial effects that:
according to the invention, the server is always in a state of waiting for the connection of the equipment, and when data transmission is needed, the low-power-consumption equipment is started and the connection with the server is established, so that the data transmission is realized; when data transmission is not needed, the low-power-consumption equipment is in a dormant state and is disconnected with the server, so that the problem that a large amount of power supplies are needed to be consumed because the low-power-consumption equipment is in a communication connection state for a long time can be avoided, the consumption of the battery power of the low-power-consumption equipment is greatly reduced, the problem that the high power consumption needed in the communication process cannot be guaranteed because the external power supplies are easily influenced by external environments in the prior art is solved, and meanwhile, the cruising ability of the low-power-consumption equipment is greatly improved.
Detailed Description
The present invention will be further described with reference to the accompanying drawings and detailed description, wherein it is to be understood that, on the premise of no conflict, the following embodiments or technical features may be arbitrarily combined to form new embodiments.
Example 1
As shown in fig. 1, the invention provides a data communication interaction system applied between a server and low-power consumption equipment, which removes the complex operation that the traditional equipment needs an external power supply, such as ensuring the high power consumption of a communication module in the data communication process to ensure the cruising ability management through a set cable, and avoids the complicated operation that project maintenance personnel need to replace a battery frequently to check the power consumption condition of the equipment while ensuring the cruising ability of the equipment.
The method relates to a server and low-power-consumption equipment, wherein the server is always in a waiting state when in data communication, and the low-power-consumption equipment is waited to initiate connection. Because the server is positioned in the remote monitoring center and is stable in power supply, the server is always in a state of waiting for the low-power-consumption equipment to initiate connection, so that the low-power-consumption equipment cannot be always in a connection state, and the power consumption of the communication module in the low-power-consumption equipment can be greatly reduced.
The invention also sets up the data message for data transmission between the low power consumption device and the server correspondingly, for example, sets up request header and byte ending symbol in the data message, and takes the request header and byte ending symbol as the beginning and ending mark of a frame of data. When the request head is received by the server, a buffer space is opened up in the server and used for storing bytes received later; when encountering the byte ending symbol, taking out all bytes in the cache, and carrying out resolving treatment on the bytes; at this time, the buffer space is also released, so that the buffer of the server is ensured not to be overloaded.
In addition, in the connection process, the server also detects whether a command needs to be issued to the low-power-consumption equipment, if so, the server sends a pause command to the low-power-consumption equipment after receiving the data of the current frame, so that the low-power-consumption equipment pauses to send data messages to the server, and the low-power-consumption equipment is kept in a non-dormant state at the moment; and then the server takes out the corresponding command from the database and transmits the command to the low-power-consumption equipment, and after the command is transmitted, the low-power-consumption equipment continues to transmit the data message to the server until all the data are transmitted, and the low-power-consumption equipment enters a dormant state.
That is, the present invention puts the server in a state of waiting for the connection of the low power consumption device, and the low power consumption device is put in a sleep state.
When the low-power consumption equipment needs to send the data message to the server, the low-power consumption equipment starts and sends a connection request to the server and establishes connection, and sends the data message to the server until the connection state between the low-power consumption equipment and the server is disconnected after the data message is sent, and the low-power consumption equipment can enter a dormant state.
In addition, in the connection process, if the server needs to send a command to the low-power-consumption device, the low-power-consumption device only needs to pause sending data to the server, receives the command, and continues sending the data message after the command is received. Although the command execution time interval is longer, the consumption of the battery power of the low-power-consumption equipment can be effectively controlled, so that the cruising ability of the low-power-consumption equipment is greatly improved. The request header and the byte ending symbol are also set for the data message, and the integrity of the data message is also ensured.
In addition, the server in the invention adopts a method of processing one frame of data simultaneously by multitasking and multithreading for the data resolving process, thereby ensuring the data processing efficiency, ensuring that the circuit is not blocked, ensuring that the server always keeps smooth transmission, and being suitable for the connection of a plurality of devices and the server. The resolving operation, such as identifying the number of the site, identifying the data type and data value, storing in corresponding buffer area, post statistics, conversion processing, etc.
Based on the foregoing, the present invention provides a data interaction method applied to a server and a low power consumption device, where the data interaction method is operated in the server, as shown in fig. 2, and includes:
step S11, starting the server and keeping the server in a state of waiting for connection all the time.
And step S12, when the connection of the low-power-consumption equipment is detected, the connection between the low-power-consumption equipment and the server is established, and the receiving is started.
Step S13, storing the received frame data in a buffer area. In addition, in order to ensure that the cache in the server does not always exist, the cache area may be established only when data is received for the first time after the connection is established. And then after the connection is disconnected, the data in the buffer area is taken out, and the buffer area is deleted.
Step S14, judging whether the received frame data is complete, if not, continuing to receive; if yes, go to step S15. For example, when the byte of the received data is a byte terminator, the data of the current frame is considered to be received completely. That is, when the low-power consumption device transmits data, the data is packetized and divided into a plurality of frames, and then the frames are transmitted to the server one by one, so that the integrity of the data can be ensured.
And step S15, taking the received data out of the buffer area, calling a preset resolving program to resolve the data, then continuing to receive the data, executing the steps S13, S14 and S15 until the data is received, closing the connection between the low-power-consumption equipment and the server, and enabling the low-power-consumption equipment to be in a dormant state.
In the process of receiving data, it is detected that a control command sent by the PC end needs to be sent to the low-power consumption device, that is, as shown in fig. 3, the data interaction method further includes:
and step S16, when a control command is detected in the process of receiving the data, sending a pause instruction to the low-power-consumption equipment, so that the low-power-consumption equipment pauses sending the data, and ensuring that the low power consumption equipment and the server are in a connection state.
And step S17, issuing a control command to the low-power-consumption equipment, continuously receiving the data sent by the low-power-consumption equipment after the control command is sent, and performing corresponding operations, such as executing step S13, step S14, step S15, step S16 and the like, until the data is received, and disconnecting the low-power-consumption equipment.
That is, the invention can greatly reduce the average power consumption of the low-power-consumption equipment and improve the endurance capacity of the low-power-consumption equipment by only keeping the server in the waiting connection state all the time; the use of data packetization may make the data more complete. The method of flexibly embedding the communication link is adopted for issuing the command, and the control command and the like are transmitted without additionally establishing communication between the equipment end and the server, so that the communication time is greatly shortened, and the effect of saving electricity is further achieved.
Example two
The present invention also provides another preferred embodiment of a data interaction method applied to a server and a low power consumption device, where the data interaction method operates on the low power consumption device, as shown in fig. 4, and the data interaction method includes:
step S21, a connection request is sent to the server, and connection with the server is established. When data is required to be sent, the low-power-consumption equipment is started and a connection request is sent to the server, so that the low-power-consumption equipment can be ensured not to be in a communication connection state all the time, and the power consumption is greatly saved.
Step S22, dividing the monitored data into multi-frame data according to the data packets, and sequentially sending the multi-frame data to a server, so that the server stores the data in a cache; wherein each frame of data includes a request header, data, and a byte terminator. The integrity of data transmission can be ensured by performing packetization processing on the transmitted data.
Step S23, after all the data are sent to the server, a disconnection command returned by the server is received, and the connection with the server is disconnected.
Further, as shown in fig. 5, the data interaction method further includes:
and step S24, after receiving the pause instruction, pausing sending data to the server and maintaining connection with the server.
Step S25, receiving the control command sent by the server, and executing the corresponding operation on the control command. Such as down to the corresponding monitoring device to perform the corresponding operation.
After the control command is received, the data is continuously transmitted, for example, step S22 is performed.
The invention realizes the transmission of the control command by embedding the transmission of the notification command into the data communication link, thereby greatly shortening the communication time.
Example III
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on a process, the processor implementing the following steps when executing the program:
the starting step: starting the server and ensuring that the server is in a waiting connection state;
a connection establishment step: when a connection request of low-power-consumption equipment is detected, establishing connection between the low-power-consumption equipment and a server;
and a data receiving step: receiving data and storing the received data in a buffer;
and a data calculation step: and taking the received data out of the cache area, calling a resolving program to resolve, and closing the connection between the server and the low-power-consumption equipment when all the data are received.
Further, the data sent by the low power consumption device to the server is provided with a request header and a byte terminator, and the data between the request header and the byte terminator is used as one frame of data;
the data resolving step further includes: when the data of the current frame is received, the received data of the current frame is taken out of the buffer area, and a settlement program is called for resolving; and when the bytes of the received data are byte ending symbols, the data of the current frame are considered to be received completely.
Further, the data interaction method further comprises the following steps:
suspending the step of receiving data: in the data receiving process, when a control command is detected, a pause instruction is sent to the low-power-consumption equipment, so that the low-power-consumption equipment pauses sending data to the server, and a connection state is kept between the low-power-consumption equipment and the server;
a command sending step: transmitting a control command to the low power consumption device;
continuing to receive data: after the control command is sent, sending a receiving command to the low-power-consumption equipment, so that the low-power-consumption equipment continues to send data to the server, and executing the data receiving step.
Further, a data calculation step: and carrying out resolving operation on the data in a multi-task and multi-thread mode.
Further, the data resolving step further includes releasing the space of the buffer area after the data is fetched from the buffer area.
Further, the control command is sent by the PC side and stored in the database.
Alternatively, the processor, when executing the program, performs the steps of:
connection request step: sending a connection request to a server and establishing connection with the server;
and a data transmission step: dividing the monitored data into multi-frame data according to the data packets, and sequentially sending the multi-frame data to a server, so that the server stores the data in a cache; wherein each frame of data includes a request header, data, and a byte terminator;
disconnecting: and after all the data are sent to the server, receiving a disconnection command returned by the server, and disconnecting the connection with the server.
Further, the data interaction method further comprises the following steps:
suspending the data transmission step: after receiving the pause instruction, pausing sending data to the server and maintaining connection with the server;
a command receiving step: receiving a control command sent by a server;
continuing to send data: and after receiving the receiving instruction, continuing to execute the data sending step.
Example IV
The present invention also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
the starting step: starting the server and ensuring that the server is in a waiting connection state;
a connection establishment step: when a connection request of low-power-consumption equipment is detected, establishing connection between the low-power-consumption equipment and a server;
and a data receiving step: receiving data and storing the received data in a buffer;
and a data calculation step: and taking the received data out of the cache area, calling a resolving program to resolve, and closing the connection between the server and the low-power-consumption equipment when all the data are received.
Further, the data sent by the low power consumption device to the server is provided with a request header and a byte terminator, and the data between the request header and the byte terminator is used as one frame of data;
the data resolving step further includes: when the data of the current frame is received, the received data of the current frame is taken out of the buffer area, and a settlement program is called for resolving; and when the bytes of the received data are byte ending symbols, the data of the current frame are considered to be received completely.
Further, the data interaction method further comprises the following steps:
suspending the step of receiving data: in the data receiving process, when a control command is detected, a pause instruction is sent to the low-power-consumption equipment, so that the low-power-consumption equipment pauses sending data to the server, and a connection state is kept between the low-power-consumption equipment and the server;
a command sending step: transmitting a control command to the low power consumption device;
continuing to receive data: after the control command is sent, sending a receiving command to the low-power-consumption equipment, so that the low-power-consumption equipment continues to send data to the server, and executing the data receiving step.
Further, a data calculation step: and carrying out resolving operation on the data in a multi-task and multi-thread mode.
Further, the data resolving step further includes releasing the space of the buffer area after the data is fetched from the buffer area.
Further, the control command is sent by the PC side and stored in the database.
Alternatively, the computer program when executed by a processor performs the steps of:
connection request step: sending a connection request to a server and establishing connection with the server;
and a data transmission step: dividing the monitored data into multi-frame data according to the data packets, and sequentially sending the multi-frame data to a server, so that the server stores the data in a cache; wherein each frame of data includes a request header, data, and a byte terminator;
disconnecting: and after all the data are sent to the server, receiving a disconnection command returned by the server, and disconnecting the connection with the server.
Further, the data interaction method further comprises the following steps:
suspending the data transmission step: after receiving the pause instruction, pausing sending data to the server and maintaining connection with the server;
a command receiving step: receiving a control command sent by a server;
continuing to send data: and after receiving the receiving instruction, continuing to execute the data sending step.
The above embodiments are only preferred embodiments of the present invention, and the scope of the present invention is not limited thereto, but any insubstantial changes and substitutions made by those skilled in the art on the basis of the present invention are intended to be within the scope of the present invention as claimed.