COSM now

COSM becomes
The imp is in the mix and Xively Imp Library

More details tonight any Londoners going? iotlondon events

The API looks much more complex…Hope we get simple examples (with lots of comments!) up here soon.

This seems to be the simplest example

Yeah, that basically looks like the cosm interface. I got the impression that the permanent interface (cosm is considered legacy) required some sort of device registration, etc.

Xively just rocks! You can now set triggers on incoming feeds. The combination of imp+planner+Xively seems to be the perfect solution for custom DIY projects!

If you’re looking for some documentation / sample code, it can be found here.

Xively has also told me there should be a couple sample projects up that use in the imp in the next weeks. When they are posted, they’ll be posted here… I’ll also post them here when I notice them go up.

Can someone post a SIMPLE working example of sending data to xively? I just want to do an analog read on pin1 and send it xively. I am stuck. Not getting the tutorial code from github to work. Just code to send a fixed number or how about the system voltage? Thanks.

I just saw that they transferred my COSM feeds to Xively, so I think it works the same. If you are using Agents, you can try this:
`//Agent: ;

const COSM_FEED_NAME = “Sendtocosm”;
function reportsuccess(response){device.send(“success”, response.statuscode);}
function sendtocosm(value){
local v1=value.tofloat();
local tempv1=value2;
local v2=tempv1.tofloat();
local COSM_DATASTREAM = http.jsonencode({“title”:COSM_FEED_NAME,“version”:“1.0.0”,“datastreams”:[{“id”:“stream0”,“current_value”:v1},{“id”:“stream1”,“current_value”:v2}]});
local req = http.put(“”+ COSM_FEED +".json",
{ “Accept”: "
/*", “X-ApiKey”: COSM_API },



t <- 0;
Errorcode <- 200;
agent.on(“success”, function(msg) {
Errorcode = msg.tointeger();
server.log("Errorcode: " + Errorcode);
function updateteller(){
if (Errorcode == 200){t++};
server.log("DeviceCounter = " + t);
imp.wakeup(10.0, updateteller);
imp.wakeup(0.5, updateteller);
imp.configure(“sendtocosm”, [], []); `

You can have a look here to see what you can get:

I can’t use Xively in anything but “Legacy” mode and they removed access to any useful data about my feeds overnight. Not impressed with their treatment of existing users.

Anyway, what does it mean “If you are using Agents”? How do I do anything with the GitHub code?

I’m completely lost. I tried the sample Imp code on Xively and I got “ERROR: the index ‘http’ does not exist”. I tried looking in the API details, but all it would tell me is that this object only exists on the server.


It means you have to have access to the beta firmware.

crouchingbadger, meet hidden beta.

Actually, it is not hidden, my understanding is that you can email the manufacturing email address for electric imp and ask to be put into the beta program. That will get you the agents at least.

I am also unhappy with the Xively changeover and am making moves to get away from that service, regardless what they say about ‘coming soon’

I’ve written some agent code for making interacting with Xively pretty easy. You can find it over here right now… Xively should have it up on their Github account soon.

This example also requires access to our beta, which you can get by emailing or sending me a message.

Let me know if you have any questions!

@crouchingbadger: I’ll get you setup on the beta so you can start working with this library.

@beardedinventor Thanks, I’ve sent an email.

heavy stuff! I don’t understand anything of your code, but it works.
Is something like that possible for deleting channels?

Probably? I’ll take a look at the Xively API when I get a chance.

If there is anything in specific you want explained I would be more than happy to do so :slight_smile:

I still have troubles with http objects in combination with JSON encoding/decoding and
sendsync() or sendasync().
It is all a bit confusing and can’t find any understandable documentation
I’m from the dBaseIII generation…

an example from your code:

function Xively::Put(feed, ApiKey = Xively.API_KEY){ if (ApiKey == null) ApiKey = Xively.API_KEY;

is Chinese for me…

Lots of the code in the Agent API is in there to make it so that the syntax the developer uses (outside the API) is clean, and easy. Let’s go through these two lines and look at what’s going on:

To start, we need to look at some code a little higher up:

Xively <- { FEED_ID = "FEED_ID" // Replace with your Feed ID API_KEY = "API_KEY" // Replace with your API Key triggers = [] }

What we’re doing here is creating a new object called Xively, and giving it 3 properties: FEED_ID, API_KEY, and triggers. In Squirrel everything is dynamic, so we can add new properties at any point in time… it turns out, we can also add just about anything else, including functions!

The first line of code creates a new function and binds it to the object called Xively we created above (the :: syntax is throwback to C).

function Xively::Put

This lets us call this function with Xively.Put()

The rest of the first line is the function’s parameter list. The first parameter (feed) should be easy enough to understand, the second parameter is a little funky:

function Xively::Put(feed, ApiKey = Xively.API_KEY)

What this line does is create a second optional parameter, with a default value of Xively.API_KEY. In other words, we can call this function two ways:

Xively.Put(feed, ApiKey);

If we call the function with only 1 parameter (feed), it will take the API_KEY you defined in the Xively object above. If you call it with two parameters (feed and APIKey), it will use the ApiKey you gave it instead of the API_KEY defined in the Xively object. This just gives the function a little more flexibility.

Finally, the second line:

if (ApiKey == null) ApiKey = Xively.API_KEY;

This is equivalent to the following:

if (ApiKey == null) { ApiKey = Xively.API_KEY; }

This line just makes sure the developer didn’t accidentally pass in a null API_KEY to the function. If they did, it grabs the default API_KEY from the object created at the top of the agent code.

Hopefully this helped explain a bit of what is going on. Everything I needed to write this code I found in the Squirrel Documentation… it’s kind of awful, but there is a LOT of information in there (if you can make sense of it).

thanks a lot.
alltough I have to take the time to explore all this, I think it will help a lot.
I have given up on the Squirrel documentation, but with this, maybe I’ll give it another shot.

I have given up on the Squirrel documentation

This seems to be a common feeling. Once we sort out the documentation for the imp, we’re hoping to write some Squirrel documentation of our own.

Also - some of the code for Xively may yet change. I wanted to play around with creating “static classes” in Squirrel (which this kind of emulates), but once I go back and look at this, it might make more sense to encapsulate everything in class, and pass in the API_KEY as a constructor argument…

Glad I’m not the only one with problems regarding Squirrel documentation, and I would really help with to documentation “Impsquirrel”.
A “foolproof” angle of view might help…