Is DataAPI much slower than MessageAPI?

I synchronize events between wearable and smartphone. Since I want my events to be received over the phone, even if they were disabled, I started using DataAPI instead of MessageAPI , but now "synchronization" takes about 1-2 seconds instead of 0.1-0.5 seconds (estimated timings).

In case of messages, I pass a string path, for example, "/ notification / click" and two bytes of raw data. In the case of DataAPI, I use the path "/ notification / click / 1" and one byte of raw data. Have you seen this behavior too? Do you know how to do this, except for using DataAPI only if the device is disconnected?

If you want to see some code, leave a comment. Since this code has a large tile code, I have not added it (yet).

+5
source share
2 answers

You can check if you are connected by looking for connected NodeApi.getConnectedNodes() nodes and see if it is not empty. But I do not think this is the best solution.

If you need both fast and reliable delivery of information, send a message and install the data item. Add a unique identifier to both so you can ignore the one that gets the second. Thus, if you are connected, you will receive a message quickly and later ignore the data item. If you are not connected, the message will be lost, but the data item will be saved and will eventually force you to complete the action. You will need to save unique identifiers, but to handle the following case:

  • message sent, action completed,
  • reboot for any reason
  • the data item that is ultimately supplied must be ignored.
+2
source

yes, in my result, the result of the data API is slower than the api message (several times, two times higher), you can try to increase the speed of your message. api data has a function that can send an object that supports the data size, can exceed 100 KB, but the api message cannot support the data size exceeding 100 KB. use the general interface for sending a message, check the size of the data you want to send, if it exceeds 100 KB, use the data api attribute to send, if not, use the api message. this is my speed up my application

0
source

Source: https://habr.com/ru/post/1213785/


All Articles