Whilst waiting for the local cloud, and kind of being a reinvent the wheel as a way of learning guy, I decided to write a proxy script to control my Spark from the web.
Now we all know its dead simple to write a proxy to e.g. tweet sensor readings, but how do you control the spark from the web, e.g. tweet “turn on relay 2” and make the spark do it?
The only way I can think of is to get the spark to poll a url listening for instructions, which seems pretty nasty - is that how the spark cloud works or does it do something cleverer?
I would think it uses WebSockets or a standard TCP Socket for its connection from the spark to the cloud, and then the cloud uses HTTP for the client (the computer for example) to the cloud server…
For what you are trying to accomplish, I would run a server with TCP socket connected to the device so you can keep the connection open. Have the cloud do the polling from twitter and then notify the spark…
As far as twitter goes, I am certain that they don’t provide a websocket API. So you might either use your own implementation or use a proxy like :
The Spark Core <–> Cloud connection uses a protocol called Constrained Application Protocol (CoAP). I don’t know much about the nitty-gritty details of CoAP, but I think it maintains a constant connection similar to WebSockets so that the server can push data to the Core instead of polling.
ah right so its like a twitter stream, thanks. explains why sometimes things don’t work so well after its gone to sleep.