TheThingsArchive / node-app-sdk

The Things Network Application SDK for Node.JS
https://www.thethingsnetwork.org/docs/node-js/
MIT License
41 stars 28 forks source link

How do I use the DataClient correctly? #97

Closed parkmeta closed 4 years ago

parkmeta commented 6 years ago

Hello.

I had a trouble because i create new DataClient instance each time I send downlink. From the sdk code, I noticed that every time I create a DataClient I get a new MQTT connection.

How do I use the DataClient correctly? Should I manually manage the DataClient instance pool?

Also, I think it's a good idea to add a callback as the last parameter to the DataClient.send() function. This callback will be passed as last parameter to this.mqtt.publish() to receive 'MQTT publish' result.

Please give me feedback.

Thx.

johanstokking commented 6 years ago

Should I manually manage the DataClient instance pool?

Yes.

Also, I think it's a good idea to add a callback as the last parameter to the DataClient.send() function. This callback will be passed as last parameter to this.mqtt.publish() to receive 'MQTT publish' result.

That could be useful indeed. Can you create a PR?

parkmeta commented 6 years ago

Okay, I will do as soon as possible.

parkmeta commented 6 years ago

Hi, Thank you for previous answer.

I have more questions.

  1. Can I close(release) AppClient and DataClient? Or don't i need to close the clients?

  2. After i get some TTN clients(AppClient and DataClient), i see below error message for a period of time. Is there a limit on the number of times I can connect to the Discovery server? Also, Is there a recommended time gap between connect and after connect?

14 UNAVAILABLE: Connect Failed

at Object..exports.createStatusError (node_modules/grpc/src/common.js:87:15) at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1188:28) at InterceptingListener.Object..InterceptingListener._callNext (node_modules/grpc/src/client_interceptors.js:564:42) at InterceptingListener.Object..InterceptingListener.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:614:8) at callback (node_modules/grpc/src/client_interceptors.js:841:24)

Thx.

johanstokking commented 6 years ago

Can I close(release) AppClient and DataClient? Or don't i need to close the clients?

You can close them, that probably releases underlying resources, which is a good idea for you and for us.

After i get some TTN clients(AppClient and DataClient), i see below error message for a period of time. Is there a limit on the number of times I can connect to the Discovery server? Also, Is there a recommended time gap between connect and after connect?

We have API throttling indeed. For normal use, this shouldn't become a problem. How many requests are you firing?

parkmeta commented 6 years ago

I create new client 5 times in 10 minutes, about 7 days I will try to manage client pool.