First post on the forum, so just for the quick intro: I am Marcel Sch working from Rotterdam, the Netherlands, on interesting concepts for connected products at The Incredible Machine.
Currently I am working on a multiplayer toy / game: a slot-race track that is controlled over IP.
We’ve made this before with a combination of PHP / Processing / Arduino (http://the-incredible-machine.com/carreramash/), but now I am redoing it with the Imp to replace it all.
I am running into the following issue: If my Agent doesn’t receive any requests for 60 seconds, I want a function to be triggered. Much like the javascript equivalent: setTimeout(function, 1000);
I’ve looked through the Squirrel-lang documentations, but the best example i found was a while-loop that compared a time() > timeout
This is not an option for my case, because I cannot afford my agent to stall for the duration of the timeout.
If you guys can help me out, I will host a international race broadcasted with webcams.
Marcel, that’s really cool! I have some questions about the process… You say on the website “The server registers all mashes by both teams and calculates the car speeds. The track connects to the same server and requests the speeds of the cars and responds whenever a car drove a lap.”
Does the server only speed up a car after each lap or constantly?
As I understand it, the default timeout for a request to an agent actually is 60 seconds, so if you send a request to the agent and it sends to the device, and the device doesn’t respond back to the agent for 60 seconds, the agent will timeout and reply to the initial HTTP request with a timeout error.
I don’t quite understand what you mean by the agent stalling during the timeout.
Wow, you really made me want to hack a slot car track! My nephews would love it.
No, imp.wakeup() really does work just like setTimeout: everything else continues to run. There is a blocking version, imp.sleep().
Cancelling an imp.wakeup() is an often-requested feature, coming soon, but until then you could have a polling function (using imp.wakeup) which runs every second, or every five seconds, checking the timeout <= time() condition (if it’s not so critical that it’s exactly 60 seconds).