Sharing data between imps using xively and agents

I have been looking for ways to share data between imps running the same code.
Within the electric imp ecosystem, this is not possible at the moment, but you can use an external web service, or your own server, to keep the shared data for you.

I looked at as a means to do that. Ideally you would use triggers to notify other imps of any changes, so there is no need for polling the data feed for new data. However, I did not succeed in creating triggers using the xively API, although it should be possible, as documented on
I either get a 401 Not Authorized or a 500 Internal Server Error response, depending on which API key I use.

As an alternative, I created a solution which uses the feed’s tags to allow each imp to notify other imps. After connecting, each imp adds a tag to the feed with its agent id, which is part of the agent URL. After an imp updates a datastream, it reads the tags, and uses the agent ids to notify other imps of the new data. This works quite well, although the latency is quite large: about a second. So compared with polling, the advantage is not that great.

In my example code, there is a switch on pin1 and a LED on pin2 of each imp. Pressing the switch on any imp will toggle its own LED, and convey the LED state to the other imps. Code is here:

very nice! hide your Xively account credentials from your code :wink:

That looks really good.

It would be great to create triggers on the fly - if you’re getting a return code of 500 it might be something on the Xively side (it could also be bad JSON depending on their implementation). Have you tried reaching out to them at all about the errors?

@takissd oops! thanks for reminding, I forgot that… now fixed it, but gists have revision control, so it’s still there in the first rev. I deleted my key and the feed on xively just to make sure :wink:

@beardedinventor I later only got 401 Not Authorized (it was never 403, that was a typo - fixed that), so it must be a problem with the keys. I did not email support yet, but might as well do that :slight_smile: