Round-robin web access to Imp

I have an Imp project that will be controlled from a publicly accessible website. There’s a possibility that two or more web clients/visitors will attempt to issue commands to the Imp at the same time. What I would like to have is a round-robin access system, so that each time a web client/visitor loads the page, they’re given a minute of exclusive control of the Imp. If a second visitor loads the page while another visitor is in control, they would be queued. When a visitor’s time expires, they’re pushed to the back of the queue, control is transferred to the the next waiting client, and so on. And when visitors leave, they’d be removed from the queue.

I’ve seen this done years ago with mid- to high- end Axis and Sony PTZ IP cameras, but I think it was a Java client + servlet solution, communicating over a separate socket connection. I’d prefer to implement this using something a little more lightweight, and a language I’m more familiar with, like Python, Perl, Ruby, etc. And I’m guessing ajax / javascript on the client side is all I’d need, no plugins.

Is anyone familiar with an existing framework or solution that provides this functionality?


Found what I was looking for… not a framework, but an excellent example of a multi user Python chat server using socketio and javascript on the client side. I got it running quickly, and the code already has handlers for when clients arrive, leave, etc. I just need to add the round-robin stuff myself, but everything else is already done.

Awesome - got any agent code you want to share? :slight_smile:

No secret sauce in my agent code, not dissimilar to your SnackBot agent code. The Imp still acts as if it’s a single-user device. The Python server will have the round-robin code and handle the request bridging to the Imp.

Despite the extra layer, I like the idea of hiding the Imp agent’s public endpoint, since it won’t be (viewable) in the client side code…

I’ll share the Python code once the project is over (it’s for an artist client, the piece is going into a public art gallery for a month, people from all over the world will be manipulating his sculpture thanks to the power of Imp :slight_smile:

Could a user still hijack it by making calls directly to the agent URL, or are you doing a bit of security in the agent?

I’ve done something similar with PHP/MySQL and JQuery Mobile …

With PHP, I’ve hidden the agent URL in the server-side scripting. Also, nothing gets executed with those scripts unless the user is logged-in (PHP SESSION is active). Only one person at a time can be ‘active’ with my multi-user script. The others are waiting in a queue for the ‘active’ person to finish their turn (2 minutes).

So I use 3 states:

  1. lurking. not logged in and not waiting.
  2. logged-in, but not ‘active’ (waiting in the queue).
  3. logged-in and ‘active’ (this person is in control of the imp).
    The PHP script that posts to the imp only executes for the ‘active’ person.

People that view the HTML source will see the JQuery calls to the PHP script that posts to the imp, but not the imp URL. Unless there is a PHP SESSION set for them, they can’t do anything with it.