Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataAPI much slower then MessageAPI?

I'm synchronizing events between the wearable and the smartphone. Since I want that my events are recieved by the phone even if they are disconnected I started using the DataAPI instead of the MessageAPI, but now the "synchronization" takes about 1-2 seconds instead of 0.1-0.5 seconds (perceived timings).

I'm transmitting in case of the messages a string path like "/notification/click" and two bytes of raw data. In case of the DataAPI I use the path "/notification/click/1" and one byte of raw data. Did you see that behavior too? Do you know a trick to fasten that up, except to use the DataAPI only if the device is offline?

If you want to see some code please leave a comment. Since that code has much boilder plate code I did not add it (yet).

like image 758
rekire Avatar asked Nov 01 '22 09:11

rekire


1 Answers

You can check, if you are connected by looking up connected nodes NodeApi.getConnectedNodes() and seeing, if it's not empty. But I don't think this is the best solution.

If you need a both fast and reliable delivery of information, send both a message and set a data item. Add a unique identifier to both, so you can ignore the one, that gets delivered second. This way 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 persist and eventually will make you complete the action. You will need to persist the unique identifiers though to handle following case:

  1. message delivered, action completed,
  2. reboot for whatever reason,
  3. data item eventually delivered, needs to be ignored.
like image 53
gruszczy Avatar answered Nov 12 '22 10:11

gruszczy