Obtain Agent URL


#1

Firstly, can I set out my assumptions on the relationship between models->agents->device

I am assuming that a model is a version of firmware. Agents are attached to a model and each agent has only one associated device.

So many agents will share the same firmware, but an agent will only communicate with with a single device?

Further a device id is connected to the board an IMP card is connected to, not the IMP card itself. So if an IMP card is moved to another board, it will have a different device id?

Please let me know if this is incorrect!

Finally, to my question.

How I can get hold of the agent url so I can communicate between my web app and the agent (and then the device)?

I can only presume it is a manual process to capture the details at production time? (Although I am still using dev cards at the moment.)


#2

Should have posted this in Agents (documents seems to be the default) :frowning:


#3

A model is a program running on your Imp.
An Agent is a program running on the Imp servers (cloud)
A device ID is generated by a chip on your device and is unique (device is the PCB where you put your Imp in)
The difference between Imps is only the MAC address, which is hardcoded

You will find your Agent URL on top of the Agent pane in your IDE


#4

There are a couple other ways to get the Agent URL:

  1. You can call http.agenturl()
  2. If you are blessing devices (ie - building a commercial imp product) you can setup a webhook that gets called each time a device is blinked up that will pass (along with other information) the Agent URL

#5

Thanks. That’s clears a few things up. Is this documented anywhere?

.
Still unanswered - is there a 1-1 between an an agent and a specific device/model? Or can an agent talk to many models (i.e. send me your sensor data, model response with data and id?

Secondly - I can see that the agent URL is available in the IDE, but can it be retrieved programatically? (This may depend on the answer to the question above).


#6
  1. Not sure how useful http.agenturl() this is without some sort of lookup key? (looks like you have to be in the agent to call this?!).

But 2) looks like what I am after.

I would still like to know the cardinality between an agent and a model.

Thank you.


#7

Device:Agent = 1:1

Every device has exactly one agent, and every agent has exactly one device.


#8

Further clarification:

  • A model is an association of both agent and device code. Models are assigned to devices, which get the model’s imp code, and the paired agents will get the model’s agent code.

  • In a commercial environment, you “bless” devices, which permanently associates them with that model. You can then deploy firmware updates to all devices at once.

  • You could make the agent self-register itself with a backend (when it starts, if it’s not registered before, it could collect the device ID and store this with another server along with the agent URL)

  • The blinkup libraries also return the agent URL upon successful blinkup. As beardedinventor noted, you can also get a webhook callback.


#9
- A model is an association of both agent and device code. Models are assigned to devices, which get the model's imp code, and the paired agents will get the model's agent code.

Hugo, just to clarify if I understand this correct: If I have model that is association of agent and device code, does it mean, that is in production all imps use the same agent URL?
I am just trying to understand how should I build communication in production between my web service, electric imp cloud where agent code is running and imp.

If I can get agent URL after successful blinkup using your iOS libraries, that solves my question, because I can pass it as a callback URL for the device and associate it with the user.


#10

No. Every imp/agent gets its own agent URL.

You do get agent URL after successful blinkup using the iOS/android libs, yes.


#11

How can I get agent url of a blessed device. Correct me if I am wrong I presume one can use the test result webhook. And then in the agent code handle the http request to send the agent url in the data to cloud. My doubt is can I handle the testresult event in the agent code?


#12

I don’t think the test result webhook works outside of the factory firmware. Any agent URL it reports will change when the blessed device is first configured by an end-user via BlinkUp.

The best way to get the agent URL is through the BlinkUp SDK immediately after the blessed device has enrolled. The device’s agent URL is returned to the polling call after the device has successfully enrolled. Your BlinkUp app can forward this to your server.

Agent code can always call http.agenturl() of course, but you don’t have a way to associate that with a specific device unless you record device IDs (using, say, the Blessing webook) and send the result from hardware.getdeviceid() when you also send the agent URL. Your server code then looks up the device ID and associates the agent URL with it in the database.

Of course, if the end-user reconfigures the device and you haven’t retained and re-used their original plan ID, they will get a new agent URL. So you’ll have to have the agent phone home its URL and device ID every restart, just in case the URL has changed. Much easier, I think, to do this through your BlinkUp app.