8

I am working on IoT project, and I should keep the embedded device to be connected with a web-service. So, which is better, requesting the webservice every 1 or 2 seconds, or opening a socket with the server to guarantee the real time operations.

Taking into Consideration that working with sockets, may require me to write a lot of bunches of codes, as there's no frameworks for socket over ARM for example.

Thanks

Mostafa Khattab
  • 554
  • 6
  • 18
  • possible duplicate of [Is it better to reuse connections, or renew them for sending data frequently?](http://stackoverflow.com/questions/30244753/is-it-better-to-reuse-connections-or-renew-them-for-sending-data-frequently) or [Which is a larger overhead: Creating a new socket each time or maintaining a single socket for data transfer](http://stackoverflow.com/q/28541889/3081018). – Steffen Ullrich Aug 19 '15 at 09:46
  • Yes, thanks, but states are completely different, the duplicate speaks about 20sec interval, and I speak about 1sec interval. – Mostafa Khattab Aug 19 '15 at 09:48
  • The answers talk about how the best choice depends on resource usage on client and server and latency. They are not specific to 1..2 seconds vs. 30 seconds. Simply put: if you need it faster use a single connection but at the cost of more resources required at the server. – Steffen Ullrich Aug 19 '15 at 09:51
  • Yeah, I got it, thanks for your help – Mostafa Khattab Aug 19 '15 at 10:04
  • @SteffenUllrich: What if it would be 5 seconds? Or 1 min? Would that change the answer? Or if I write uppercase, or if I send xml or html or ... **;-))** – too honest for this site Aug 19 '15 at 12:16
  • @Olaf: uppercase usually increases the latency and needs more resources (especially if combined with a bold font). – Steffen Ullrich Aug 19 '15 at 12:23
  • @SteffenUllrich: Hmm, but bold face makes one a four-star programmer. For the latency: I disagree, as uppercase ASCII has lower values than lower case. And if I use a Heffernan coding, ... – too honest for this site Aug 19 '15 at 12:26

2 Answers2

3

My team and I are currently working on an IOT platform, here are my suggestions:

  1. If your product only report data or status periodically, using a web service to receive the data will work fine, and it's very easy to implement.
  2. If you need to send realtime operations from server to your device, using a long tcp connection is a better choice. There are some good protocol to help you implement this, like MQTT.
  3. For the second case above, requesting a web service to receive realtime operations will work, but it's definitely not a good idea. It will increase your server's load and your device's energy consumption.

After all, you need to make your choice on your product's requirements.

razr
  • 46
  • 4
2

You can use MQTT protocol, its library is available for embedded c as well as for arduino. Also you can choose, Rest/Coap with nodejs as the request will be waiting until node will give response In this both scenario, real time communication can be approached without any socket and refreshing time.

Samrat Das
  • 1,781
  • 1
  • 21
  • 33
  • @Samrat, do you mean rest/coap in nodejs on a client? Mostafa, have you verified whether this answer works well for your embedded device? – minghua May 16 '17 at 06:36
  • 1
    yes, just you have to put time out bit larger in the client side if using rest or coap, then it will create async communication line, and with that you also have to handle network drops. i would say, use mqtt, it is better one – Samrat Das May 16 '17 at 08:13