Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Keen IO

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.

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 add this library to your project, add #require "KeenIO.class.nut:1.0.0" to the top of your agent code

Class Usage

Constructor: KeenIO(projectID, writeAPIKey)

You instantiate the KeenIO class with your Keen Project ID and Write API Key:


Class Methods

sendEvent(collectionName, eventData[, callback])

Thismethod allows you to send an event to a particular method. 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 asyncronously and the callback will be fired when the request is complete. If the callback function is ommited, the request will be made syncronously, 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 synchronously
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);

getTimestamp(timestamp[, millis])

This 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. 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 Keen library is licensed under the MIT License.