Terminal control method and device based on applet, electronic equipment and storage medium
Through the terminal control method based on mini-programs, the Bluetooth module is used to establish a connection with the target terminal, and the mobile terminal controls the target terminal, solving the problems of high cost and long cycle of application software development in the power industry, and achieving the effect of shortening the development time and reducing development costs.
Patent Information
- Application Number
- CN202411625241.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-03-28
AI Technical Summary
In the power industry, the low interaction demand between the target terminal and the mobile terminal leads to the high cost of specialized application software and the long development cycle. How to shorten the development time and reduce the development cost while achieving the mobile terminal to control the target terminal has become a technical problem that needs to be solved urgently.
The terminal control method based on the applet is adopted to achieve the control of the target terminal by obtaining the current network status, initializing the Bluetooth module, scanning peripheral devices, establishing a Bluetooth connection, obtaining the service attributes and notification data of the target terminal, responding to setting instructions and firmware upgrade packages, etc.
The mini program controls the target terminal for parameter setting and version upgrade, which shortens the development time and reduces the development cost. At the same time, as an embedded lightweight software, the mini program can embed multiple applications to achieve unified control of operators and mobile terminals.
Smart Images

Figure CN119729428A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a terminal control method, device, electronic device and storage medium based on mini-programs. Background Art
[0002] The target terminal uses the serial port to communicate with the concentrator. It does not need to interact frequently with the mobile terminal. It only has low interaction requirements such as parameter setting and version upgrade, and has a weak dependence on the mobile terminal. Therefore, developing an application software specifically for the target terminal will not only prolong the development cycle, but also increase unnecessary expenses.
[0003] In view of this, how to shorten the development time and reduce the development cost while realizing the mobile terminal controlling the target terminal has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, the purpose of the present disclosure is to propose a terminal control method, device, electronic device and storage medium based on mini-programs to solve or partially solve the above-mentioned technical problems.
[0005] Based on the above purpose, the first aspect of the present disclosure proposes a terminal control method based on an applet, the method comprising:
[0006] Acquire a current network status, determine a target login method based on the current network status, and log in to the mini-program on the mobile terminal according to the target login method;
[0007] Initialize the Bluetooth adapter of the mobile terminal by calling the openBluetoothAdapter function, and enable the Bluetooth module of the mobile terminal by obtaining Bluetooth authorization;
[0008] The state of the Bluetooth adapter is monitored by calling the onBluetoothAdapterStateChange function, and when the Bluetooth adapter receives a state switching instruction, the Bluetooth adapter is switched from the on state to the off state, and then the Bluetooth adapter is controlled to restart;
[0009] Scan the surrounding devices using the Bluetooth module by calling the startBluetoothDevicesDiscovery function, and determine the Bluetooth devices that meet the constraint set from the surrounding devices by calling the getBluetoothDevices function;
[0010] Storing the Bluetooth device in a storage module of the mini-program, and rendering and displaying the Bluetooth device on a page of the mini-program;
[0011] Determine a target terminal from the peripheral devices based on the received connection instruction, control the mobile terminal to establish a connection with the target terminal by calling the createBLEConnection function, and monitor the Bluetooth connection status by calling the onBLEConnectionStateChange function;
[0012] Using the applet to obtain the service attributes of the target terminal, and receiving notification data sent by the target terminal;
[0013] In response to determining that a setting instruction is received through the applet, controlling the target terminal according to the setting instruction;
[0014] In response to determining that a firmware upgrade package is received through the applet, the target terminal is controlled according to the firmware upgrade package.
[0015] Based on the same inventive concept, the second aspect of the present disclosure proposes a terminal control device based on a mini-program, comprising:
[0016] A login module is configured to obtain a current network state, determine a target login method based on the current network state, and log in to the mini-program on the mobile terminal according to the target login method;
[0017] An initialization module is configured to initialize the Bluetooth adapter of the mobile terminal by calling an openBluetoothAdapter function, and to enable the Bluetooth module of the mobile terminal by obtaining Bluetooth authorization;
[0018] A restart module is configured to monitor the state of the Bluetooth adapter by calling the onBluetoothAdapterStateChange function, and control the Bluetooth adapter to restart when it is monitored that the Bluetooth adapter switches from the on state to the off state when receiving a state switching instruction;
[0019] A scanning module, configured to use the Bluetooth module to scan surrounding devices by calling a startBluetoothDevicesDiscovery function, and determine a Bluetooth device that meets a constraint set from the surrounding devices by calling a getBluetoothDevices function;
[0020] A display module, configured to store the Bluetooth device in the storage module of the mini-program, and render and display the Bluetooth device on a page of the mini-program;
[0021] A connection module is configured to determine a target terminal from the peripheral devices based on the received connection instruction, control the mobile terminal to establish a connection with the target terminal by calling a createBLEConnection function, and monitor the Bluetooth connection state by calling an onBLEConnectionStateChange function;
[0022] A receiving module, configured to obtain the service attributes of the target terminal using the applet, and receive notification data sent by the target terminal;
[0023] A first control module is configured to, in response to determining that a setting instruction is received through the applet, control the target terminal according to the setting instruction;
[0024] The second control module is configured to control the target terminal according to the firmware upgrade package in response to determining that a firmware upgrade package is received through the applet.
[0025] Based on the same inventive concept, the third aspect of the present disclosure proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the method as described above when executing the computer program.
[0026] Based on the same inventive concept, a fourth aspect of the present disclosure proposes a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method as described above.
[0027] From the above, it can be seen that the present disclosure provides a terminal control method, device, electronic device and storage medium based on a mini-program. Obtain the current network status, determine the target login method based on the current network status, and log in to the mini-program on the mobile terminal according to the target login method. In this way, regardless of whether the current network status is good or abnormal, the mini-program can be logged in to the mobile terminal, so that the target terminal can be controlled by the mini-program. Based on the received connection instruction, the target terminal is determined from the peripheral devices, and the mobile terminal is controlled to establish a connection with the target terminal by calling the createBLEConnection function, and the Bluetooth connection status is monitored by calling the onBLEConnectionStateChange function. In this way, the mini-program can be used to control the establishment of a connection between the mobile terminal and the target terminal through the Bluetooth device, so as to control the target terminal using the mini-program. Use the mini-program to obtain the service attributes of the target terminal and receive notification data sent by the target terminal; when the setting instruction is received through the mini-program, the target terminal is controlled according to the setting instruction; when the firmware upgrade package is received through the mini-program, the target terminal is controlled according to the firmware upgrade package. In this way, by logging into the applet on the mobile terminal and using the applet to control the mobile terminal through the Bluetooth device to establish a connection with the target terminal, the applet can be used to control the target terminal to set parameters and upgrade the version. Using the applet to control the target terminal can shorten the development time and reduce the development cost. In addition, as an embedded lightweight software, the applet can be embedded in a variety of applications to achieve unified management and control of operators and mobile terminals. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the present disclosure or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 is a flowchart of a terminal control method based on a mini-program according to an embodiment of the present disclosure;
[0030] Figure 2 It is a flow chart of a method for controlling a power Beidou timing terminal applet according to an embodiment of the present disclosure;
[0031] Figure 3 This is a schematic diagram of the structure of the applet data transmission according to the embodiment of the present disclosure;
[0032] Figure 4 A flowchart of Bluetooth signal interaction according to an embodiment of the present disclosure;
[0033] Figure 5It is a schematic diagram of the structure of a terminal control device based on a mini-program according to an embodiment of the present disclosure;
[0034] Figure 6 It is a schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.
[0036] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the embodiments of the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0037] Based on the description of the background technology, electricity consumption information collection is one of the key tasks of power services. The meter equipment at the collection site is often affected, resulting in clock drift, which affects the calibration of the time deviation of the electric energy meter at the collection site, thereby reducing the accuracy of the data collected on the master station side. This deviation can be calibrated using the power Beidou timing terminal. The power Beidou timing terminal is based on the Beidou satellite navigation system and has Beidou time synchronization and Beidou positioning functions. Deploying it at the electricity consumption information collection site can provide accurate and autonomous timing services and accurate location information collection services for equipment such as concentrators, thereby improving the accuracy of electricity consumption data on the master station side and effectively improving the digital management and service level of power services.
[0038] In the electric power industry, the electric power Beidou timing terminal is often equipped with a mobile application software (Application, referred to as APP) to realize the interaction between the electric power Beidou timing terminal and the mobile terminal. APP development is more adaptable to terminals with large amounts of data interaction and multiple communication methods.
[0039] The electric power Beidou timing terminal uses RS485 serial port to communicate data with the concentrator. It does not need to interact frequently with the mobile terminal. It only has low interaction requirements such as parameter setting and version upgrades, and has a weak dependence on mobile terminals. Therefore, developing an APP specifically for the electric power Beidou timing terminal will not only extend the development cycle, but also increase unnecessary expenses.
[0040] As mentioned above, how to shorten the development time and reduce the development cost while realizing the control of the target terminal by the mobile terminal has become an important research issue.
[0041] Based on the above description, if Figure 1 As shown, the terminal control method based on the applet proposed in this embodiment includes:
[0042] Step 101, obtain the current network status, determine the target login method based on the current network status, and log in to the mini program on the mobile terminal according to the target login method.
[0043] In specific implementation, a mobile terminal is also called a mobile communication terminal, and a mobile terminal refers to a computer device that can be used on the move. The mobile terminal includes at least one of the following: a mobile phone terminal, a tablet terminal, an electronic watch terminal, and a vehicle-mounted terminal. In this embodiment, the mobile terminal is preferably a mobile phone terminal.
[0044] Determine the target login method based on the current network status, and log in to the mini program on the mobile terminal according to the target login method. For example, if the current network status is good, log in to the mini program on the mobile terminal according to the network login method. If the current network status is abnormal, log in to the mini program on the mobile terminal according to the local login method.
[0045] Step 102: Initialize the Bluetooth adapter of the mobile terminal by calling the openBluetoothAdapter function, and enable the Bluetooth module of the mobile terminal by obtaining Bluetooth authorization.
[0046] Step 103: monitor the state of the Bluetooth adapter by calling the onBluetoothAdapterStateChange function, and monitor that the Bluetooth adapter switches from the on state to the off state when receiving a state switching instruction, then control the Bluetooth adapter to restart.
[0047] Step 104 : Scan the surrounding devices using the Bluetooth module by calling the startBluetoothDevicesDiscovery function, and determine the Bluetooth devices that meet the constraint set from the surrounding devices by calling the getBluetoothDevices function.
[0048] Step 105: store the Bluetooth device in the storage module of the mini program, and render and display the Bluetooth device on the page of the mini program.
[0049] Step 106: determine the target terminal from the peripheral devices based on the received connection instruction, control the mobile terminal to establish a connection with the target terminal by calling the createBLEConnection function, and monitor the Bluetooth connection status by calling the onBLEConnectionStateChange function.
[0050] In specific implementation, the Bluetooth module of the mobile terminal is used to scan the peripheral devices, and the mobile terminal is controlled to establish a connection with the target terminal in the peripheral devices. According to steps 102 to 106, the mobile terminal is controlled to establish a connection with the target terminal.
[0051] 1) The mini program needs to obtain Bluetooth authorization to use the Bluetooth function, call the openBluetoothAdapter function to initialize the Bluetooth adapter, obtain Bluetooth authorization and start the Bluetooth module. After the Bluetooth adapter is initialized, call the onBluetoothAdapterStateChange function to monitor the Bluetooth adapter status. The built-in automatic restart module restarts the Bluetooth adapter and monitors if the adapter status changes from on to off without the user's initiative.
[0052] 2) Scan the surrounding Bluetooth devices, call the startBluetoothDevicesDiscovery function and the getBluetoothDevices function to start the scanning function. A constraint set is built into the function. The constraint set meets the retrieval conditions of the power Beidou timing terminal and can block invalid Bluetooth devices. The Bluetooth devices that meet the constraint set after screening are stored in the mini program storage module and rendered on the mini program page.
[0053] The user selects the target terminal, calls the createBLEConnection function and the onBLEConnectionStateChange function to actively connect to the target terminal, and monitors the Bluetooth connection status after the connection is successful. At this point, the applet completes the connection with the target terminal.
[0054] Among them, during the process of monitoring the Bluetooth connection status, if a connection disconnection error occurs that is not initiated by the user, it is necessary to re-initiate an active connection to the target terminal and monitor the Bluetooth connection status. The mini program based on the IOS system also needs to re-call the service and characteristic interfaces.
[0055] The target terminal is a terminal device controlled by a small program on a mobile terminal. In this embodiment, the target terminal is preferably a power Beidou timing terminal.
[0056] Step 107: Utilize the applet to obtain the service attributes of the target terminal and receive notification data sent by the target terminal.
[0057] In a specific implementation, the service attribute of the target terminal includes at least one of the following: a primary service, a feature, and an attribute of the target terminal.
[0058] Use the mini program to obtain the main services, features, and attributes of the target terminal. The mini program enables the function of receiving notifications to receive binary data returned by the target terminal to the mini program.
[0059] Step 108: In response to determining that a setting instruction is received through the applet, controlling the target terminal according to the setting instruction.
[0060] Step 109: In response to determining that a firmware upgrade package is received through the applet, controlling the target terminal according to the firmware upgrade package.
[0061] During specific implementation, the device information of the target terminal is read, and setting instructions and firmware upgrade packages are issued to achieve control over the target terminal. The applet can be used to control the target terminal for parameter setting and version upgrade.
[0062] Specifically, the applet traverses all features with a read attribute, performs a read operation and establishes a listening value, reads the value, and stores the read device information.
[0063] Through the above embodiment, the current network status is obtained, the target login method is determined based on the current network status, and the mini program is logged in on the mobile terminal according to the target login method. In this way, regardless of whether the current network status is good or abnormal, the mini program can be logged in on the mobile terminal, so as to control the target terminal using the mini program. Based on the received connection instruction, the target terminal is determined from the peripheral device, the mobile terminal is controlled to establish a connection with the target terminal by calling the createBLEConnection function, and the Bluetooth connection status is monitored by calling the onBLEConnectionStateChange function. In this way, the mini program can be used to control the mobile terminal to establish a connection with the target terminal through the Bluetooth device, so as to control the target terminal using the mini program. The service attributes of the target terminal are obtained by using the mini program, and the notification data sent by the target terminal is received; when the setting instruction is received through the mini program, the target terminal is controlled according to the setting instruction; when the firmware upgrade package is received through the mini program, the target terminal is controlled according to the firmware upgrade package. In this way, by logging in to the mini program on the mobile terminal, and using the mini program to control the mobile terminal to establish a connection with the target terminal through the Bluetooth device, the mini program is used to control the target terminal for parameter setting and version upgrade, and the mini program is used to control the target terminal, which can shorten the development time and reduce the development cost. In addition, as an embedded lightweight software, mini programs can be embedded in a variety of applications to achieve unified management and control of operators and mobile terminals.
[0064] In some embodiments, step 101 includes:
[0065] Step 1011, obtaining the current network signal strength, and determining the current network state based on the current network signal strength.
[0066] Step 1012, in response to the current network signal strength being greater than or equal to a preset signal threshold, determining that the current network state is a good state, and logging into the mini program on the mobile terminal according to the network login method.
[0067] Step 1013, in response to the current network signal strength being less than a preset signal threshold, determining that the current network state is an abnormal state, and logging into the mini program on the mobile terminal in a local login manner.
[0068] In specific implementation, due to the particularity of the Beidou timing terminal used in power and electricity information collection scenarios, the mini program restricts users. The mini program is for power personnel, and relevant power personnel can log in with their login account and login password.
[0069] There are two ways to log in to the mini program: network login and local login. Users choose the login method based on the network environment of the power operation site. Individual registration is not allowed. As the applicant, the user submits a login account application to the mini program administrator before the first operation, and the administrator reviews and provides the login account.
[0070] When the network signal strength is greater than or equal to the preset signal threshold, it means that the current network status is good, and you can log in to the mini program on the mobile terminal according to the network login method. When the network signal strength is less than the preset signal threshold, it means that the current network status is abnormal, and you can log in to the mini program on the mobile terminal according to the local login method.
[0071] The mini program provides optional differentiated login methods. For power operation environments with poor network, such as indoor substations, users can choose to log in locally to get rid of dependence on servers. In this case, the mini program can be used normally without a server, and login, control operations, and upgrades do not require the participation of a server. Restrictions are placed on user attributes in terms of login permissions. Only users approved by the management can complete the login with their login account and password and obtain the right to use the mini program.
[0072] Through the above scheme, when the current network status is good, the small program is logged in on the mobile terminal according to the network login method. When the current network status is abnormal, the small program is logged in on the mobile terminal according to the local login method. In this way, regardless of whether the current network status is good or abnormal, the small program can be logged in on the mobile terminal, so as to control the target terminal using the small program, avoiding the situation where the target terminal cannot be controlled due to the current network status being abnormal and the small program cannot be logged in.
[0073] In some embodiments, step 1012 includes:
[0074] Step 1012A, receiving the login account and login password, and using the mini program server to determine whether the login account and the login password meet the preset login conditions.
[0075] Step 1012B, in response to determining that the login account and the login password meet the preset login conditions, obtain the identity authentication code assigned by the mini program server, bind the identity authentication code with the login account and the login password, and log in to the mini program on the mobile terminal.
[0076] In specific implementation, network login method: In a working environment with good network conditions, users can choose the network login method. The user enters the login account and login password, and the mini program server verifies the legitimacy of the login account and login password. If they are legitimate, the user can obtain the unique identity verification code assigned by the server to complete the login. The unique identity verification code is bound to the user's login account and login password, and is generated by the mini program server when the verification passes.
[0077] Step 1013 includes:
[0078] Step 1013A, receiving the login account and login password, and verifying the login account and the login password using the locally pre-stored account directory.
[0079] Step 1013B, in response to determining that the login account and the login password are successfully verified, log in to the mini program on the mobile terminal.
[0080] In specific implementation, local login method: In a working environment with unsatisfactory network conditions, users can choose local login method. Developers generate an account directory in advance according to the deployment of the Beidou timing terminal of the power industry, and integrate the account directory into the applet. After the user enters the login account and password, the applet can initiate self-verification to the account directory, and the user can log in after the verification passes.
[0081] Through the above scheme, when the current network status is good, the login account and login password are verified by the mini program server, so that the mini program can be logged in on the mobile terminal according to the network login method. When the network status is abnormal, the login account and login password are verified by the pre-stored account target, so that the mini program can be logged in on the mobile terminal according to the local login method. In this way, regardless of whether the current network status is good or abnormal, the mini program can be logged in on the mobile terminal, so that the target terminal can be controlled by the mini program.
[0082] In some embodiments, after step 104, the method further includes:
[0083] Step 104A, in response to determining that no Bluetooth device meeting the constraint set is scanned, by setting a timer function, after continuously scanning the surrounding devices for a preset time period, the getBluetoothDevices function is called to determine the Bluetooth device meeting the constraint set from the surrounding devices.
[0084] In the specific implementation, there is a situation where 0 surrounding Bluetooth devices are searched when calling the getBluetoothDevices function. For this problem, set a timer function and continue scanning for about 2s before calling it again. Multiple surrounding Bluetooth devices can be scanned, which can solve the situation where the mini program Bluetooth adapter cannot search for Bluetooth devices during the first scan.
[0085] Through the above scheme, when no Bluetooth device that meets the constraint set is scanned, by setting the timer function, it is possible to continuously scan the surrounding devices for a preset time, thereby scanning the Bluetooth device, avoiding the situation where the mini-program Bluetooth adapter cannot search for the Bluetooth device during the first scan.
[0086] In some embodiments, step 107 includes:
[0087] Step 1071: Obtain the main services, characteristics and attributes of the target terminal by calling the getBLEDeviceCharacteristics function, and use the main services, characteristics and attributes of the target terminal as service attributes.
[0088] Step 1072, enable the notification data receiving function by calling the notifyBLECharacteristicValueChange function, receive the notification data sent by the target terminal, and monitor the received notification data by calling the onBLECharacteristicValueChange function.
[0089] In specific implementation, call the getBLEDeviceCharacteristics function to obtain the main services, characteristics, and properties of the connected target terminal. Each main service's universally unique identifier (Universally Unique Identifier, referred to as UUID) has at least one characteristic UUID, and each characteristic UUID has at least one attribute value. All main services, characteristics, and properties should be implemented in accordance with the provisions of the Bluetooth interaction protocol.
[0090] The applet enables the function of receiving notifications, traverses all characteristics with the notify attribute, calls the notifyBLECharacteristicValueChange function and the onBLECharacteristicValueChange function to enable notify and listen for changes in notification data, and is used to receive binary data returned to the applet by the connected target terminal.
[0091] Through the above scheme, by calling the getBLEDeviceCharacteristics function, the service attributes of the target terminal can be accurately and comprehensively obtained. By calling the notifyBLECharacteristicValueChange function, the notification data receiving function can be enabled, so that the notification data sent by the target terminal can be received, and by calling the onBLECharacteristicValueChange function, the received notification data can be monitored.
[0092] In some embodiments, step 108 includes:
[0093] Step 1081, in response to determining that a setting instruction is received through the applet, convert the setting instruction into a binary data frame.
[0094] Step 1082, writing the binary data frame to the target terminal by calling the writeBLECharacteristicValue function, so as to control the target terminal according to the setting instruction.
[0095] During the specific implementation, the setting instruction is issued: the user selects the parameters set in the interface, the applet obtains the parameters set in the interface and converts them into binary data frames, and writes the binary data frame to the connected target terminal in big-endian format or little-endian format by calling the writeBLECharacteristicValue function to complete the issuance of the setting instruction.
[0096] The setting instructions include: maximum transmission unit setting instruction (MTU), RS485 serial port baud rate setting instruction and timing interval setting instruction.
[0097] MTU is the maximum transmission unit setting instruction. First, call the setBLEMTU function to send the setting instruction. After the setting instruction is sent, the Bluetooth host and the slave negotiate and match the MTU that is most suitable for this Bluetooth connection, and call the onBLEMTUChange function to monitor the current MTU value.
[0098] For RS485 serial port baud rate setting instructions and timing interval setting instructions, the applet integrates the baud rate and timing interval into the protocol data format according to the Bluetooth interaction protocol, and further converts them into binary data frames. The setting instructions can be sent by performing a write operation on the characteristic uuid with the write attribute according to the Bluetooth interaction protocol.
[0099] Through the above scheme, by converting the setting instruction into a binary data frame, it is convenient to write the setting instruction to the target terminal. By calling the writeBLECharacteristicValue function, the binary data frame can be written to the target terminal, thereby realizing the control of the target terminal according to the setting instruction.
[0100] In some embodiments, step 109 includes:
[0101] Step 1091, in response to determining that a firmware upgrade package is received through the applet, obtaining a target file by calling a chooseMessageFile function.
[0102] Step 1092, using the applet manager to read the file information of the target file by calling the getFileSystemManager().readFileSync(tempFilePath) function, and converting the file information into a binary data type file.
[0103] Step 1093: Write the binary data type file to the target terminal according to the Bluetooth interaction protocol, so as to control the target terminal according to the firmware upgrade package.
[0104] In the specific implementation, the number of transferable files is constrained in advance in the mini program, the files in the conversation list are obtained by calling the chooseMessageFile function, and the mini program file manager is called through the getFileSystemManager().readFileSync(tempFilePath) function to further read the file content, file name, and file size, and the read user-selected file content is converted into a binary data type file, and the correct characteristic value UUID is selected and written according to the Bluetooth interaction protocol.
[0105] Through the above scheme, by calling the chooseMessageFile function, the target file can be determined from the firmware upgrade package, so that the target terminal can be upgraded according to the target file. By calling the getFileSystemManager().readFileSync(tempFilePath) function, the file information of the target file can be read, and the file information is converted into a binary data type file, and the binary data type file is written to the target terminal, so as to upgrade the target terminal according to the target file.
[0106] Through the above embodiment, the current network status is obtained, the target login method is determined based on the current network status, and the mini program is logged in on the mobile terminal according to the target login method. In this way, regardless of whether the current network status is good or abnormal, the mini program can be logged in on the mobile terminal, so as to control the target terminal using the mini program. Based on the received connection instruction, the target terminal is determined from the peripheral device, the mobile terminal is controlled to establish a connection with the target terminal by calling the createBLEConnection function, and the Bluetooth connection status is monitored by calling the onBLEConnectionStateChange function. In this way, the mini program can be used to control the mobile terminal to establish a connection with the target terminal through the Bluetooth device, so as to control the target terminal using the mini program. The service attributes of the target terminal are obtained by using the mini program, and the notification data sent by the target terminal is received; when the setting instruction is received through the mini program, the target terminal is controlled according to the setting instruction; when the firmware upgrade package is received through the mini program, the target terminal is controlled according to the firmware upgrade package. In this way, by logging in to the mini program on the mobile terminal, and using the mini program to control the mobile terminal to establish a connection with the target terminal through the Bluetooth device, the mini program is used to control the target terminal for parameter setting and version upgrade, and the mini program is used to control the target terminal, which can shorten the development time and reduce the development cost. In addition, as an embedded lightweight software, mini programs can be embedded in a variety of applications to achieve unified management and control of operators and mobile terminals.
[0107] It should be noted that the embodiments of the present disclosure may be further described in the following manner:
[0108] Figure 2 Flow chart of the method for controlling the electric power Beidou timing terminal applet according to the embodiment of the present disclosure. Figure 2 As shown, the power Beidou timing terminal applet control method includes:
[0109] Step 201, the user selects an appropriate method to log in to the mini program according to the network conditions at the work site.
[0110] Step 202: The Bluetooth module scans surrounding devices, and the mini program renders the Bluetooth devices to the page. The user clicks on the page to select the target terminal, and the mini program completes the connection with the target terminal.
[0111] Step 203, the applet obtains all main services, characteristic values and attributes of the connected target terminal, and monitors all notification functions.
[0112] Step 204, read the device information of the connected target terminal, send the setting instruction and the upgrade package, and realize the control of the target terminal.
[0113] Figure 3 FIG. 1 is a schematic diagram of the structure of the mini-program data transmission in the embodiment of the present disclosure. Figure 3 As shown in the figure, the structure of applet data transmission includes: rendering module, instruction module, execution module, transmission module and receiving module. The details are as follows:
[0114] (1) The rendering module renders the device information and control instructions of the electric power Beidou timing terminal to form a visual interface of the applet. The device information includes: the name, serial number, software version, hardware version, model, and connection status of the electric power Beidou timing terminal; the instruction parameters include: MTU optional parameter, RS485 serial port baud rate optional parameter, and timing interval optional parameter.
[0115] (2) The command module is used to generate downlink commands for controlling the power Beidou timing terminal. The downlink commands include: searching for devices, connecting to Bluetooth, disconnecting Bluetooth, upgrading software, and setting parameters.
[0116] (3) The execution module is composed of multiple encapsulated js functions, which are used to control the operation of the mini program interface. Among them, the js functions include: login function, Bluetooth operation function, data storage and extraction function, data type conversion function, and data verification function.
[0117] (4) The transmission module is responsible for the transmission of command data between the applet and the electric power Beidou timing terminal. The applet transmits data to the electric power Beidou timing terminal according to the Bluetooth interaction protocol.
[0118] (5) The receiving module is used to receive notification messages fed back by the electric power Beidou timing terminal to the mini program. The mini program receives data from the electric power Beidou timing terminal according to the Bluetooth interaction protocol.
[0119] Figure 4 Flow chart of Bluetooth signal interaction in the embodiment of the present disclosure. Figure 4 As shown in the figure, the Bluetooth signal interaction process between the applet and the timing terminal specifically includes:
[0120] (1) The applet encapsulates the control signal according to the Bluetooth interaction protocol and sends it to the electric power Beidou timing terminal. The control signal is a read operation or a write operation and carries the binary data to be sent. The Bluetooth interaction protocol consists of UUID, data exchange format, communication mode, subpacketization mechanism, and verification scheme, which specifies the communication method between the applet and the electric power Beidou timing terminal.
[0121] (2) After the electric power Beidou timing terminal receives the control signal from the mini-program, it performs an error check on the control signal and returns a signal feedback to the mini-program. The signal feedback is a confirmation signal or a completion signal.
[0122] (3) The applet monitors the signal returned by the power Beidou timing terminal to determine whether the control signal is sent successfully. If the sending fails, the applet starts the automatic retransmission mechanism.
[0123] In addition to being applied to the electric power Beidou timing terminal, the processing of the embodiments of the present disclosure can also be applied to other target terminals in the electric power industry that have low interaction requirements with mobile terminals.
[0124] Through the above embodiments, parameter setting, version upgrade and other management of the electric power Beidou timing terminal can be achieved only through Bluetooth. Only by adopting the Bluetooth communication method, the control of the electric power Beidou timing terminal can be completed, and the relevant requirements of the electric power Beidou timing terminal for parameter setting and version upgrade can be met, which greatly reduces the development cost and shortens the development time, and is more suitable for the electric power Beidou timing terminal. At the same time, as an embedded lightweight software, the applet can not only be embedded in mobile clients such as WeChat, but also in the enterprise mobile APP of the power system, so as to realize the unified management and control of operating personnel and the electric power Beidou timing terminal, which is more suitable for the power industry. It is developed in the form of a applet, developed once, and applicable to all platforms.
[0125] It should be noted that the method of the embodiment of the present disclosure can be performed by a single device, such as a computer or a server. The method of the present embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present disclosure, and the multiple devices will interact with each other to complete the described method.
[0126] It should be noted that the above describes some embodiments of the present disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0127] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a terminal control device based on a mini-program.
[0128] refer to Figure 5 , the terminal control device based on the applet comprises:
[0129] The login module 301 is configured to obtain a current network status, determine a target login method based on the current network status, and log in to the mini program on the mobile terminal according to the target login method;
[0130] The initialization module 302 is configured to initialize the Bluetooth adapter of the mobile terminal by calling the openBluetoothAdapter function, and enable the Bluetooth module of the mobile terminal by obtaining Bluetooth authorization;
[0131] The restart module 303 is configured to monitor the state of the Bluetooth adapter by calling the onBluetoothAdapterStateChange function, and control the Bluetooth adapter to restart when it is monitored that the Bluetooth adapter switches from the on state to the off state when receiving the state switching instruction;
[0132] The scanning module 304 is configured to use the Bluetooth module to scan surrounding devices by calling the startBluetoothDevicesDiscovery function, and determine the Bluetooth devices that meet the constraint set from the surrounding devices by calling the getBluetoothDevices function;
[0133] The display module 305 is configured to store the Bluetooth device in the storage module of the mini-program, and render and display the Bluetooth device on the page of the mini-program;
[0134] The connection module 306 is configured to determine a target terminal from the peripheral devices based on the received connection instruction, control the mobile terminal to establish a connection with the target terminal by calling a createBLEConnection function, and monitor the Bluetooth connection state by calling an onBLEConnectionStateChange function;
[0135] The receiving module 307 is configured to obtain the service attributes of the target terminal by using the applet and receive notification data sent by the target terminal;
[0136] A first control module 308 is configured to, in response to determining that a setting instruction is received through the applet, control the target terminal according to the setting instruction;
[0137] The second control module 309 is configured to control the target terminal according to the firmware upgrade package in response to determining that a firmware upgrade package is received through the applet.
[0138] In some embodiments, the login module 301 includes:
[0139] a current network state determining unit, configured to obtain a current network signal strength, and determine a current network state based on the current network signal strength;
[0140] A network login unit is configured to, in response to the current network signal strength being greater than or equal to a preset signal threshold, determine that the current network state is a good state, and log in to the applet on the mobile terminal according to the network login method;
[0141] The local login unit is configured to determine that the current network state is an abnormal state in response to the current network signal strength being less than a preset signal threshold, and log in to the mini program in the mobile terminal in a local login manner.
[0142] In some embodiments, the network login unit includes:
[0143] The first verification subunit is configured to receive a login account and a login password, and use the mini program server to determine whether the login account and the login password meet a preset login condition;
[0144] A network login subunit is configured to, in response to determining that the login account and the login password meet a preset login condition, obtain an identity verification code assigned by the mini-program server, bind the identity verification code with the login account and the login password, and log in the mini-program on the mobile terminal;
[0145] The local login unit includes:
[0146] A second verification subunit is configured to receive a login account and a login password, and verify the login account and the login password using a locally pre-stored account directory;
[0147] The local login subunit is configured to log in the mini-program on the mobile terminal in response to determining that the login account and the login password are successfully verified.
[0148] In some embodiments, after using the Bluetooth module to scan surrounding devices by calling the startBluetoothDevicesDiscovery function, and determining the Bluetooth devices that meet the constraint set from the surrounding devices by calling the getBluetoothDevices function, the apparatus further includes:
[0149] The continuous scanning module is configured to, in response to determining that no Bluetooth device that meets the constraint set is scanned, call the getBluetoothDevices function to determine the Bluetooth device that meets the constraint set from the surrounding devices after continuously scanning the surrounding devices for a preset time by setting a timer function.
[0150] In some embodiments, the receiving module 307 includes:
[0151] The service attribute acquisition unit is configured to acquire the main service, characteristics and attributes of the target terminal by calling the getBLEDeviceCharacteristics function, and use the main service, characteristics and attributes of the target terminal as service attributes;
[0152] The receiving unit is configured to enable the notification data receiving function by calling the notifyBLECharacteristicValueChange function, receive the notification data sent by the target terminal, and monitor the received notification data by calling the onBLECharacteristicValueChange function.
[0153] In some embodiments, the first control module 308 includes:
[0154] a binary data frame conversion unit, configured to, in response to determining that a setting instruction is received through the applet, convert the setting instruction into a binary data frame;
[0155] The first writing unit is configured to write the binary data frame to the target terminal by calling the writeBLECharacteristicValue function, so as to control the target terminal according to the setting instruction.
[0156] In some embodiments, the second control module 309 includes:
[0157] a target file acquisition unit, configured to acquire the target file by calling a chooseMessageFile function in response to determining that a firmware upgrade package is received through the applet;
[0158] A binary data type file conversion unit is configured to read the file information of the target file using the applet manager by calling getFileSystemManager().readFileSync(tempFilePath) function, and convert the file information into a binary data type file;
[0159] The second writing unit is configured to write the binary data type file to the target terminal according to the Bluetooth interaction protocol, so as to control the target terminal according to the firmware upgrade package.
[0160] For the convenience of description, the above device is described by dividing it into various modules according to its functions. Of course, when implementing the present disclosure, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0161] The device of the above embodiment is used to implement the corresponding mini-program-based terminal control method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0162] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments, the present disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the mini-program-based terminal control method described in any of the above embodiments is implemented.
[0163] Figure 6 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.
[0164] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0165] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.
[0166] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0167] The communication interface 1040 is used to connect a communication module (not shown in the figure) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB (Universal Serial Bus), network cable, etc.), or through a wireless mode (such as mobile network, WIFI (Wireless Fidelity), Bluetooth, etc.).
[0168] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).
[0169] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0170] The electronic device of the above-mentioned embodiment is used to implement the corresponding mini-program-based terminal control method in any of the above-mentioned embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0171] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the mini-program-based terminal control method as described in any of the above embodiments.
[0172] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.
[0173] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the terminal control method based on the applet as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0174] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure is limited to these examples. Based on the concept of the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present disclosure as described above, which are not provided in detail for the sake of simplicity.
[0175] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present disclosure difficult to understand, the known power / ground connections to the integrated circuit (IC) chips and other components may or may not be shown in the provided figures. In addition, the device can be shown in the form of a block diagram to avoid making the embodiments of the present disclosure difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the embodiments of the present disclosure will be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). Where specific details (e.g., circuits) are set forth to describe exemplary embodiments of the present disclosure, it is apparent to those skilled in the art that the embodiments of the present disclosure can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0176] Although the present disclosure has been described in conjunction with specific embodiments of the present disclosure, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.
[0177] The embodiments of the present disclosure are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the present disclosure. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present disclosure should be included in the scope of protection of the present disclosure.
Claims
1. A terminal control method based on applet, characterized in that: Applied to a mobile terminal; the method comprises: Acquire a current network status, determine a target login method based on the current network status, and log in to the mini-program on the mobile terminal according to the target login method; Initialize the Bluetooth adapter of the mobile terminal by calling the openBluetoothAdapter function, and enable the Bluetooth module of the mobile terminal by obtaining Bluetooth authorization; The state of the Bluetooth adapter is monitored by calling the onBluetoothAdapterStateChange function, and when the Bluetooth adapter receives a state switching instruction, the Bluetooth adapter is switched from the on state to the off state, and then the Bluetooth adapter is controlled to restart; Scan the surrounding devices using the Bluetooth module by calling the startBluetoothDevicesDiscovery function, and determine the Bluetooth devices that meet the constraint set from the surrounding devices by calling the getBluetoothDevices function; Storing the Bluetooth device in a storage module of the mini-program, and rendering and displaying the Bluetooth device on a page of the mini-program; Determine a target terminal from the peripheral devices based on the received connection instruction, control the mobile terminal to establish a connection with the target terminal by calling the createBLEConnection function, and monitor the Bluetooth connection status by calling the onBLEConnectionStateChange function; Using the applet to obtain the service attributes of the target terminal, and receiving notification data sent by the target terminal; In response to determining that a setting instruction is received through the applet, controlling the target terminal according to the setting instruction; In response to determining that a firmware upgrade package is received through the applet, the target terminal is controlled according to the firmware upgrade package.
2. The method according to claim 1, characterized in that The obtaining of the current network status, determining a target login method based on the current network status, and logging into the mini-program on the mobile terminal according to the target login method includes: Acquire the current network signal strength, and determine the current network status based on the current network signal strength; In response to the current network signal strength being greater than or equal to a preset signal threshold, determining that the current network state is a good state, and logging into the mini-program on the mobile terminal according to a network login method; In response to the current network signal strength being less than a preset signal threshold, it is determined that the current network state is an abnormal state, and the mini-program is logged in at the mobile terminal in a local login manner.
3. The method according to claim 2, characterized in that The method of logging into the mini-program on the mobile terminal in a network login manner includes: Receiving the login account and login password, and using the mini program server to determine whether the login account and the login password meet the preset login conditions; In response to determining that the login account and the login password meet the preset login conditions, obtaining an identity verification code assigned by the mini-program server, binding the identity verification code with the login account and the login password, and logging in to the mini-program on the mobile terminal; The logging into the mini-program on the mobile terminal in a local login manner includes: Receiving the login account and login password, and verifying the login account and the login password using the locally pre-stored account directory; In response to determining that the login account and the login password are successfully verified, the mini program is logged in on the mobile terminal.
4. The method according to claim 1, characterized in that: After using the Bluetooth module to scan surrounding devices by calling the startBluetoothDevicesDiscovery function, and determining the Bluetooth devices that meet the constraint set from the surrounding devices by calling the getBluetoothDevices function, the method further includes: In response to determining that no Bluetooth device meeting the constraint set is scanned, a timer function is set to continuously scan surrounding devices for a preset time period, and then a getBluetoothDevices function is called to determine a Bluetooth device meeting the constraint set from the surrounding devices.
5. The method according to claim 1, characterized in that The using the applet to obtain the service attribute of the target terminal and receiving notification data sent by the target terminal includes: By calling the getBLEDeviceCharacteristics function, the main service, characteristics and attributes of the target terminal are obtained, and the main service, characteristics and attributes of the target terminal are used as service attributes; The notification data receiving function is enabled by calling the notifyBLECharacteristicValueChange function, the notification data sent by the target terminal is received, and the received notification data is monitored by calling the onBLECharacteristicValueChange function.
6. The method according to claim 1, characterized in that In response to determining that a setting instruction is received through the applet, controlling the target terminal according to the setting instruction includes: In response to determining that a setting instruction is received through the applet, converting the setting instruction into a binary data frame; The binary data frame is written to the target terminal by calling the writeBLECharacteristicValue function, so as to control the target terminal according to the setting instruction.
7. The method according to claim 1, characterized in that In response to determining that a firmware upgrade package is received through the applet, controlling the target terminal according to the firmware upgrade package includes: In response to determining that a firmware upgrade package is received through the applet, acquiring a target file by calling a chooseMessageFile function; Read the file information of the target file using the applet manager by calling getFileSystemManager().readFileSync(tempFilePath) function, and convert the file information into a binary data type file; The binary data type file is written to the target terminal according to the Bluetooth interaction protocol, so as to control the target terminal according to the firmware upgrade package.
8. A terminal control device based on applet, characterized in that: include: A login module is configured to obtain a current network state, determine a target login method based on the current network state, and log in to the mini-program on the mobile terminal according to the target login method; An initialization module is configured to initialize the Bluetooth adapter of the mobile terminal by calling an openBluetoothAdapter function, and to enable the Bluetooth module of the mobile terminal by obtaining Bluetooth authorization; A restart module is configured to monitor the state of the Bluetooth adapter by calling the onBluetoothAdapterStateChange function, and control the Bluetooth adapter to restart when it is monitored that the Bluetooth adapter switches from the on state to the off state when receiving a state switching instruction; A scanning module, configured to use the Bluetooth module to scan surrounding devices by calling a startBluetoothDevicesDiscovery function, and determine a Bluetooth device that meets a constraint set from the surrounding devices by calling a getBluetoothDevices function; A display module, configured to store the Bluetooth device in the storage module of the mini-program, and render and display the Bluetooth device on a page of the mini-program; A connection module, configured to determine a target terminal from the peripheral devices based on the received connection instruction, control the mobile terminal to establish a connection with the target terminal by calling a createBLEConnection function, and monitor the Bluetooth connection state by calling an onBLEConnectionStateChange function; A receiving module, configured to obtain the service attributes of the target terminal using the applet, and receive notification data sent by the target terminal; A first control module is configured to, in response to determining that a setting instruction is received through the applet, control the target terminal according to the setting instruction; The second control module is configured to control the target terminal according to the firmware upgrade package in response to determining that a firmware upgrade package is received through the applet.
9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and running on the processor, wherein when the processor executes the program, the method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a computer to execute the method according to any one of claims 1 to 7.