Latest Version: 1.0.0
Keen IO is a hosted service that allows you to easily push and query event-based data. This library wraps the Keen IO data collection API.
You can view the library’s source code on GitHub. Click here to see information on the available versions of this library.
Note This library is supported by Electric Imp not by KeenIO. If you find any issues or have a request, please post your findings here.
To include this library in your project, add
#require "KeenIO.class.nut:1.0.0"
at the top of your agent code
You instantiate the KeenIO class with your Project ID and Write API Key for which you’ll need to sign up with Keen IO:
#require "KeenIO.class.nut:1.0.0"
const KEEN_PROJECT_ID = "YOUR PROJECT ID";
const KEEN_WRITE_API_KEY = "YOUR API KEY";
keen <- KeenIO(KEEN_PROJECT_ID, KEEN_WRITE_API_KEY);
The sendEvent() method allows you to send an event to a particular Keen IO collection. It takes the name of the collection you are posting to as a string, and the event data to be pushed. You can also specify a third, optional parameter: a callback function. If you provide a callback, the request will be made asynchronously and the callback will be fired when the request is complete. If the callback function is omitted, the request will be made synchronously and result will be returned. The following example illustrates both modes:
eventData <- {
"location" : {
"lat" : 37.123,
"lon" : -122.123
},
"temp" : 20.4,
"humidity" : 36.7
};
// Send an event sychronously
local result = keen.sendEvent("tempBugs", eventData);
server.log(result.statuscode + ": " + result.body);
// Send an event asynchronously
keen.sendEvent("tempBugs", eventData, function(response) {
server.log(response.statuscode + ": " + response.body);
});
The getTimestamp() method can be used to return a KeenIO-formatted timestamp. The first parameter is a Unix timestamp such as that returned by Squirrel’s time() function. The second parameter is optional: a millisecond value to extend the returned timestamp to that level of granularity. The example below demonstrates how to format your data so Keen can take advantage of the timestamp:
eventData <- {
"keen" : {
"timestamp" : keen.getTimestamp(time())
},
"location" : {
"lat" : 37.123,
"lon" : -122.123
},
"temp" : 20.4,
"humidity" : 36.7
};
keen.sendEvent("tempBugs", eventData);
The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.
Version | Source Code | Notes |
---|---|---|
1.0.0 | GitHub | Initial release |
The Keen library is licensed under the MIT License.