Preparing for agent arrival

I’m trying to get an understanding of how agents work in order to ease the changeover…

So lets say I have a simple task which toggles an output when a threshold is reached, and that threshold is configurable by the user through a web page. The user enters a number, presses Submit, and the form POSTs data to a URL. I assume that URL would point to the agent code running on the server, and I assume there will be some way of obtaining that URL. Similar to HTTP In in the planner? I’m also assuming that URL is linked to the account that the IMP was blinked up for. Change the blinkup settings, and the URL will change?

I’m assuming I need to write two pieces of code - agent code, that runs on the server, and device code, that runs on the IMP. I guess the IDE will have some way of defining whether it’s agent or device code?

In this example, I’m assuming the server side code will need to define agent.on() and a device.send() function, but not device.on() or agent.send() since the IMP is only reading data from the web page, not sending anything out.

In the agent code, I write agent.on() to register a function in the IMP code, then I call agent.on() from within the IMP code, not the agent code.

Also in the agent code, I write a function called device.send(), which passes data to the IMP via the function setup in agent.on().

So, the user presses Submit. The data is POSTed to the agent. The agent calls device.send() and the data is sent to the IMP function previously defined in agent.on(). I’m assuming this function on the IMP will be a class that extends InputPort, and defined in imp.configure (similar to the current HTTP in).

Am I correct in my understanding here? Anything I’ve got totally wrong, omitted?

Thanks,
Steve

And yes, I realise this could be done with http.onrequest, but in general terms, is the procedure I’ve outlined how agents work?

That’s all mostly right, yes, except the bit about the interaction with imp.configure() and InputPort – the send()/on() channel is completely independent.

In fact, after having written the documentation for send()/on() and for configure and InputPort/OutputPort, it’s clear the former style of programming is so hopelessly easier to understand and document, that in future the InputPort/OutputPort mechanism will probably be replaced by a Planner API more similar to send()/on(). (Well, we’ll keep InputPorts and OutputPorts so that existing code keeps running, but we should make a better way of doing it for new code.)

Peter

Great, thanks Peter!