Passing data between agents (agent-to-agent)

We are playing with the imp and have been able to make a couple of IoT sensors, type A and type B.
We would like the type A Agent to perform a calculation using the value from the sensor and a value from a Type B sensor.
Can we send or request data between agents, or must one agent make a “web” request to the other agent and then parse the HTML for the data needed ?

Currently you have to pass the data agent to agent (ie there is no internal messagebus). You don’t need to use HTML, though, you can very simply pass the data as JSON and use the agent’s JSON encoder/decoder, eg:

On the processing side (side which combines the data):

`valueA <- 2;

function process(valueB) {
server.log("Sum is "+(valueA+valueB));

http.onrequest(function(req,res) {
if (req.path == “/sensorB”) {
// Extract data and process
res.send(200, “OK”);

On the sending side (sending sensor B’s data):

valueB <- 40;"", {}, http.jsonencode(valueB)).sendasync(function(res) { server.log("Send result "+res.statuscode); });

Here, the data is just an int, however it can be any complex data type with no code change required - tables, arrays, strings, etc.

Things not included here - agent security (see docs on dev site), try/catch block to catch illegal input, etc.

1 Like