Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JS to develop Intelligent Meter Application

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to use JS to develop smart meter applications". In daily operation, I believe many people have doubts about how to use JS to develop smart meter applications. Xiaobian consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to use JS to develop smart meter applications"! Next, please follow the small series to learn together!

configured

1. Preparation (download, installation, environment configuration, project creation, etc.)

This is too simple, needless to say, please refer to the official documentation

The resulting directory structure looks like this. For Android development, it should be very familiar, but for the front end, it is very confusing.

What gradle file, what is this ah, hey, why there is java, I did not choose the JS template? He was very puzzled. Let's not worry about it for now. We're going to have to do it.

2. config.json Permission list configuration (fetch, network, etc.)

In Hongmeng application, if the image tag wants to use https external link resources, it must configure permissions. Similarly, the same is true for fetch interface requests.

During my own development process, I configured the permissions for network requests and network status.

"reqPermissions": [ { "name": "ohos.permission.GET_NETWORK_INFO" }, { "name": "ohos.permission.GET_WIFI_INFO" }, { "name": "ohos.permission.INTERNET", }, ],

3. Offline signature and signature configuration (for real machine debugging)

If you do not need to debug the real machine, you can ignore this step.

please refer to the document

The editor version is different, and the key file used is different. Some are. p12, some are.jks.

If you generate jks, then you may need to convert p12, and the author will turn around and can Baidu itself.

Apply for Developer Certificate and Debug Profile

request.json is as follows:

{ "developerRequest":{ "Applicant":"XXXX", "ApplicationName": "XXXX", "CN": "XXXX", "validYear": "1" }, "provisionRequest": { "debug-info": { "device-ids": [ "" //UDID of the commissioning machine] }, "permissions": { "restricted-permissions": [ "harmonyos.permission.ANSWER_PHONE_CALLS" ] }, "bundle-name":"Your package name", "developer-id": "Your developer ID" } }

Then you generate csr, p12 and this request.json together to send Huawei people, and then they will give you cer and p7b files, you directly import it.

At this point, we have completed the preparation work of the real machine debugging.

The package printed by real machine debugging is hap package. If it is to be put on the shelf, it must be.app file, so we have to import these certificates in the project configuration, etc., as above.

4, Integrated Wear Engine SDK(watch and APP communication)

APP and watch must be integrated with the corresponding SDK to communicate

Add compilation dependency

1. Contact Huawei's interface person to obtain SDK.

2. After extracting the SDK, place the har package in the SDK under the project\entry\ libs directory.

Open the build.gradle file at the application level.

4. Add the following compilation dependency to "dependencies ", and then synchronize.

5. Generate wearable device side signature certificate fingerprint, device detection

The fingerprint and bag name of APP shall be configured on the watch side, and the fingerprint and bag name of watch side shall be configured on the APP side.

please refer to the document

The package name and fingerprint code of the watch side configuration APP are as follows

6. Compile and build HAP or APP

please refer to the document

development

There is nothing to say about development, just the normal front-end set, layout, style, logic. It should be noted that the resolution of the device is 454*454, and the circular screen needs to be kept at a safe distance.

If the watch needs to interact with the mobile APP, JS's ability is relatively weak, and it needs to rely on JAVA to do the transfer.

JAVA code is not written by me, directly copied from the official document, and then let the Android client modify it.

This is what I did on this project, and the list is as follows:

Another thing to note is that JAVA cannot actively send messages to JS, and JS needs to take the initiative. When the mobile phone and watch information are synchronized, user information is needed. Our approach is: after the mobile phone logs in, it will send a user identity information to my watch. The JAVA code on the watch side can receive it, but JS cannot receive it. At this time, my approach is to poll JS on the watch side and ask JAVA for login information. The general approach is setInterval, but I found that setInterval does not work in Hongmeng, I was desperate, and finally I used recursion. That is, during the onShow life cycle, the watch constantly calls PA capabilities (refer to the document). If the user information is obtained, it will be cached locally, stop calling, and then send a fetch request to get the data of the server. This data synchronization is complete.

Speaking of cache, there is also a small pit, this value value, must be a string, originally my res is a string, but directly write, will report an error, must use JSON.stringify() to turn it.

The code to invoke PA capabilities is as follows:

JAVA first registers a CalcInternalAbility for JS to call.

JS calls this method, as follows, value is the return value of JAVA.

debugging

This is mainly about JS debugging.

JS prints debugging information, usually console.log (), but console.info() is recommended in this editor.

Once the program starts to run, the console will keep printing some information, completely do not understand, we want to see our JS code implementation to that link, also can not be very clear to find, recommend my own method.

This way we can clearly see our printed information on the console and know where the code is executed.

At this point, the study of "how to develop smart watch applications with JS" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report