How does a Cloud Server Ping a Client Device?

58 views
Skip to first unread message

Craig Rettew

unread,
Jul 31, 2015, 3:52:26 PM7/31/15
to API Craft
I'm having trouble understanding how a cloud server sends data to a IoT device. My IoT device can send HTTP requests to the cloud server just fine but how would the server ping the device?

Jack Repenning

unread,
Jul 31, 2015, 5:08:02 PM7/31/15
to api-...@googlegroups.com
On Jul 31, 2015, at 12:52 PM, Craig Rettew <cre...@gmail.com> wrote:

I'm having trouble understanding how a cloud server sends data to a IoT device. My IoT device can send HTTP requests to the cloud server just fine but how would the server ping the device?

It doesn't. There is no "push" in HTTP/1. There are only:

* Pull, the normal case of client sends GET, server returns info.
* Poll, the same thing periodically repeated until something interesting comes back.
* Reverse, where an API service and URLs and what-not are published by the device and used by the server, reversing their normal relationship ("Now *I* am the master!").

I believe this remains true of HTTP/2, as well.

-- 
Jack Repenning
Repenni...@gmail.com

signature.asc

Craig Rettew

unread,
Jul 31, 2015, 5:20:11 PM7/31/15
to API Craft, repenni...@gmail.com
Thanks for the info. So how does a Wemo switch get a command to turn on/off lights? 

Jack Repenning

unread,
Jul 31, 2015, 5:41:33 PM7/31/15
to Craig Rettew, API Craft
On Jul 31, 2015, at 2:20 PM, Craig Rettew <cre...@gmail.com> wrote:

Thanks for the info. So how does a Wemo switch get a command to turn on/off lights? 

I'd guess "poll," as that's how it's usually done. "Pull" only helps one time; "Reverse" requires security, firewall tunnels, server admin, blah blah blah.

-- 
Jack Repenning
Repenni...@gmail.com

signature.asc

Sarthak Ganguly

unread,
Jul 31, 2015, 7:01:51 PM7/31/15
to api-...@googlegroups.com, Craig Rettew
I believe websockets have been designed specifically to handle this. If you implement a websockets connection between your client and server either of them can initiate communication.

--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+...@googlegroups.com.
Visit this group at http://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

Robert Johnson

unread,
Aug 1, 2015, 1:16:37 PM8/1/15
to API Craft
Hi Craig,

Great question. :)

One way to accomplish your goal of sending notifications from the server to the client is to have the client initiate a long-running request to the server. It sends the request and waits a specified time for a response before initiating another request.

Depending on the frequency needs, you can try setting (on the server) the request timeout value to 5 or 20 or 60 minutes. Then when the server has something to "push" it sends a response to the client. This is a different approach compared to a client polling strategy.

Hopefully this helps!

Regards,

Robert


CTO
Cloud 5 Systems, LLC
www.cloud5systems.com

Cloud5 Systems

André Tavares

unread,
Aug 2, 2015, 8:08:51 AM8/2/15
to API Craft
In the browser, there is another way to push events to the client, which is Server-sent Events (SSE). However, my googling didn't return any results regarding if SSE could be used in a "headless" client (i.e. no browser, like your IoT device).

I also would add that, considering the cpu/memory/network/battery limitations that are inherent to "IoT devices", the most important questions is which of the solutions is more efficient for your device (e.g. polling can be very consuming).
Reply all
Reply to author
Forward
0 new messages